This commit is contained in:
dongxiancun 2019-07-03 19:27:52 +08:00
commit 122fd2d982
8 changed files with 200 additions and 342 deletions

View File

@ -27,7 +27,7 @@ VPATH = ../user/configm/config-server
# set the source file, don't used .o because of ... # set the source file, don't used .o because of ...
COMMON_SRCS = configserver.c ipconfig/ipconfig.c ipconfig/parsefile.c authfree_config/authfree.c localportal_config/localportal.c userlock_config/userlock.c COMMON_SRCS = configserver.c ipconfig/ipconfig.c ipconfig/parsefile.c authfree_config/authfree.c localportal_config/localportal.c userlock_config/userlock.c jumppage_config/jumppage.c
# MRS Board Source Files # MRS Board Source Files
PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_LINUX_SRCS = $(COMMON_SRCS)

View File

@ -0,0 +1,22 @@
#ifndef JUMPPAGE_H_
#define JUMPPAGE_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include "../../../../common/rpc/rpc_common.h"
/*系统管理模块将数据内容(URL地址发送给web server */
ret_code jumppage_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
#endif

View File

@ -4,7 +4,7 @@
#define IFCONFIG_PATH "/etc/network/interfaces" #define IFCONFIG_PATH "/etc/network/interfaces"
#define IF_BUFF_LEN 128 #define IF_BUFF_LEN 128
void set_if_config(char *if_name, char *conf_name, char *conf_buff); void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff);
void del_if_config(char *if_name, char *conf_buff); void ip_conf_file_del(char *if_name, char *conf_buff);
#endif #endif

View File

@ -51,13 +51,13 @@ void ip_save_file(ip_config_t *ip_conf, uint config_type)
sprintf(mask_buff, "netmask %s\n", inet_ntoa(netmask)); sprintf(mask_buff, "netmask %s\n", inet_ntoa(netmask));
rpc_log_info("%s %s",addr_buff, mask_buff); rpc_log_info("%s %s",addr_buff, mask_buff);
set_if_config(ip_conf->ifname, addr_name, addr_buff); ip_conf_file_set(ip_conf->ifname, addr_name, addr_buff);
set_if_config(ip_conf->ifname, mask_name, mask_buff); ip_conf_file_set(ip_conf->ifname, mask_name, mask_buff);
} }
else if(config_type == CM_CONFIG_DEL) else if(config_type == CM_CONFIG_DEL)
{ {
del_if_config(ip_conf->ifname, addr_name); ip_conf_file_del(ip_conf->ifname, addr_name);
del_if_config(ip_conf->ifname, mask_name); ip_conf_file_del(ip_conf->ifname, mask_name);
} }
} }

View File

@ -9,258 +9,52 @@
#include "parsefile.h" #include "parsefile.h"
#include "rpc.h" #include "rpc.h"
#if 0 /* 缓存字符串保存到配置文件中 */
/* int conf_file_write(char *conf_path, char *sum_buf)
*
*1 2 3
*==
*/
void read_config(char *conf_path,char *conf_name,char *config_buff)
{ {
char config_linebuf[256];
char line_name[40];
char exchange_buf[256];
char *config_sign = "=";
char *leave_line;
FILE *f;
f = fopen(conf_path,"r");
if(f == NULL)
{
printf("OPEN CONFIG FALID/n");
return 0;
}
fseek(f,0,SEEK_SET);
while(fgets(config_linebuf,256,f) != NULL)
{
if(strlen(config_linebuf) < 3) //判断是否是空行
{
continue;
}
if (config_linebuf[strlen(config_linebuf)-1] == 10) //去除最后一位是/n的情况
{
memset(exchange_buf,0,sizeof(exchange_buf));
strncpy(exchange_buf,config_linebuf,strlen(config_linebuf)-1);
memset(config_linebuf,0,sizeof(config_linebuf));
strcpy(config_linebuf,exchange_buf);
}
memset(line_name,0,sizeof(line_name));
leave_line = strstr(config_linebuf,config_sign);
if(leave_line == NULL) //去除无"="的情况
{
continue;
}
int leave_num = leave_line - config_linebuf;
strncpy(line_name,config_linebuf,leave_num);
if(strcmp(line_name,conf_name) ==0)
{
strncpy(config_buff,config_linebuf+(leave_num+1),strlen(config_linebuf)-leave_num-1);
break;
}
if(fgetc(f)==EOF)
{
break;
}
fseek(f,-1,SEEK_CUR);
memset(config_linebuf,0,sizeof(config_linebuf));
}
fclose(f);
}
/*
*
*
*1 2 3
*
*/
void add_set_config(char *conf_path,char *conf_name,char *config_buff)
{
char config_linebuf[256];
char line_name[40];
char *config_sign = "=";
char *leave_line;
int alter_sign = 0;
FILE *f;
f = fopen(conf_path,"r+");
if(f == NULL)
{
printf("OPEN CONFIG FALID/n");
return 0;
}
fseek(f,0,SEEK_END);
long congig_lenth = ftell(f);
int configbuf_lenth = strlen(config_buff);
configbuf_lenth = configbuf_lenth + 5;
char sum_buf[congig_lenth+configbuf_lenth];
memset(sum_buf,0,sizeof(sum_buf));
fseek(f,0,SEEK_SET);
while(fgets(config_linebuf,256,f) != NULL)
{
if(strlen(config_linebuf) < 3) //判断是否是空行
{
strcat(sum_buf,config_linebuf);
continue;
}
leave_line = NULL;
leave_line = strstr(config_linebuf,config_sign);
if(leave_line == NULL) //去除无"="的情况
{
strcat(sum_buf,config_linebuf);
continue;
}
int leave_num = leave_line - config_linebuf;
memset(line_name,0,sizeof(line_name));
strncpy(line_name,config_linebuf,leave_num);
if(strcmp(line_name,conf_name) ==0)
{
strcat(sum_buf,config_buff);
strcat(sum_buf,"/n");
alter_sign = 1;
}
else
{
strcat(sum_buf,config_linebuf);
}
if(fgetc(f)==EOF)
{
break;
}
fseek(f,-1,SEEK_CUR);
memset(config_linebuf,0,sizeof(config_linebuf));
}
if(alter_sign == 0)
{
strcat(sum_buf,config_buff);
strcat(sum_buf,"/n");
}
printf("---sum_buf---->%s<----------/n",sum_buf);
remove(conf_path);
fclose(f);
FILE *fp; FILE *fp;
fp = fopen(conf_path,"w+"); fp = fopen(conf_path,"w+");
if(fp == NULL) if(fp == NULL)
{
printf("OPEN CONFIG FALID/n");
return 2;
}
fseek(fp,0,SEEK_SET);
fputs(sum_buf,fp);
fclose(fp);
}
/*
*
*
*1
*
*/
void del_if_config(char *conf_name)
{
char *conf_path = "/etc/network/interface";
char config_linebuf[256];
char line_name[40];
char *config_sign = "=";
char *leave_line;
FILE *f;
f = fopen(conf_path,"r+");
if(f == NULL)
{
printf("OPEN CONFIG FALID/n");
return 0;
}
fseek(f,0,SEEK_END);
long congig_lenth = ftell(f);
char sum_buf[congig_lenth+2];
memset(sum_buf,0,sizeof(sum_buf));
fseek(f,0,SEEK_SET);
while(fgets(config_linebuf,256,f) != NULL)
{
if(strlen(config_linebuf) < 3) //判断是否是空行
{
strcat(sum_buf,config_linebuf);
continue;
}
leave_line = NULL;
leave_line = strstr(config_linebuf,config_sign);
if(leave_line == NULL) //去除无"="的情况
{
strcat(sum_buf,config_linebuf);
continue;
}
int leave_num = leave_line - config_linebuf;
memset(line_name,0,sizeof(line_name));
strncpy(line_name,config_linebuf,leave_num);
if(strcmp(line_name,conf_name) !=0)
{
strcat(sum_buf,config_linebuf);
}
if(fgetc(f)==EOF)
{
break;
}
fseek(f,-1,SEEK_CUR);
memset(config_linebuf,0,sizeof(config_linebuf));
}
printf("---sum_buf---->%s<----------/n",sum_buf);
remove(conf_path);
fclose(f);
FILE *fp;
fp = fopen(conf_path,"w+");
if(fp == NULL)
{
printf("OPEN CONFIG FALID/n");
return 2;
}
fseek(fp,0,SEEK_SET);
fputs(sum_buf,fp);
fclose(fp);
}
#endif
/*
*
*
*1 2 3
*
*/
void set_if_config(char *if_name, char *conf_name, char *conf_buff)
{
char *conf_path = IFCONFIG_PATH;
char config_linebuf[IF_BUFF_LEN];
char static_name[IF_BUFF_LEN] = {0};
char iface_str[IF_BUFF_LEN] = {0};
char auto_str[IF_BUFF_LEN] = {0};
char *auto_line = NULL;
char *iface_line = NULL;
char *config_line = NULL;
boolean next_flag = FALSE;
FILE *f;
f = fopen(conf_path,"r+");
if(f == NULL)
{ {
rpc_log_error("OPEN CONFIG FALID\n"); rpc_log_error("OPEN CONFIG FALID\n");
return; return RET_ERR;
}
fseek(fp,0,SEEK_SET);
fputs(sum_buf,fp);
fclose(fp);
return RET_OK;
}
/* 设置指定配置块中的配置 */
int conf_value_in_block_set(char *conf_path,
char *start_str, char *end_str,
char *conf_name, char *conf_buff)
{
char config_linebuf[IF_BUFF_LEN];
int configbuf_lenth = strlen(conf_buff) + 5;
long config_lenth = 0;
boolean next_flag = FALSE;
char *start_line = NULL;
char *config_line = NULL;
FILE *f;
f = fopen(conf_path,"r+");
if(f == NULL)
{
rpc_log_error("OPEN CONFIG %s FALID\n", conf_path);
return RET_ERR;
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
long config_lenth = ftell(f); config_lenth = ftell(f);
int configbuf_lenth = strlen(conf_buff);
configbuf_lenth = configbuf_lenth + 5;
char sum_buf[config_lenth + configbuf_lenth]; char sum_buf[config_lenth + configbuf_lenth];
memset(sum_buf, 0, sizeof(sum_buf)); memset(sum_buf, 0, sizeof(sum_buf));
fseek(f,0,SEEK_SET);
sprintf(auto_str, "auto %s", if_name); fseek(f, 0, SEEK_SET);
sprintf(iface_str, "iface %s inet", if_name);
sprintf(static_name, "iface %s inet static\n", if_name);
memset(config_linebuf, 0, sizeof(config_linebuf)); memset(config_linebuf, 0, sizeof(config_linebuf));
@ -280,21 +74,17 @@ void set_if_config(char *if_name, char *conf_name, char *conf_buff)
goto next_while; goto next_while;
} }
/* 没有找到接口配置块,则继续循环 */ /* 没有找到配置块,则继续循环 */
if(auto_line == NULL) if(start_line == NULL)
{ {
auto_line = strstr(config_linebuf, auto_str); start_line = strstr(config_linebuf, start_str);
strcat(sum_buf, config_linebuf); strcat(sum_buf, config_linebuf);
goto next_while; goto next_while;
} }
/* 已经是下一个接口了*/ /* 配置块结束 */
if(strstr(config_linebuf, "auto")) if(strstr(config_linebuf, end_str))
{ {
if(iface_line == NULL)
{
strcat(sum_buf, static_name);
}
if(config_line == NULL) if(config_line == NULL)
{ {
strcat(sum_buf, conf_buff); strcat(sum_buf, conf_buff);
@ -306,21 +96,11 @@ void set_if_config(char *if_name, char *conf_name, char *conf_buff)
goto next_while; goto next_while;
} }
/* 找到接口IP配置方式 */
if(iface_line == NULL)
{
iface_line = strstr(config_linebuf, iface_str);
if(iface_line)
{
strcat(sum_buf, static_name);
goto next_while;
}
}
/* 找到配置行 */
if(config_line == NULL) if(config_line == NULL)
{ {
config_line = strstr(config_linebuf, conf_name); config_line = strstr(config_linebuf, conf_name);
/* 找到配置行 */
if(config_line) if(config_line)
{ {
next_flag = TRUE; next_flag = TRUE;
@ -342,76 +122,58 @@ next_while:
memset(config_linebuf, 0, sizeof(config_linebuf)); memset(config_linebuf, 0, sizeof(config_linebuf));
} }
/* 整个配置块都没有,则新创建该配置块 */
if( next_flag == FALSE ) if( next_flag == FALSE )
{ {
if(auto_line == NULL) if(start_line == NULL)
{ {
strcat(sum_buf, auto_str); strcat(sum_buf, start_str);
strcat(sum_buf, "\n"); strcat(sum_buf, "\n");
} }
if(iface_line == NULL)
{
strcat(sum_buf, static_name);
}
if(config_line == NULL) if(config_line == NULL)
{ {
strcat(sum_buf, conf_buff); strcat(sum_buf, conf_buff);
} }
} }
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
remove(conf_path); remove(conf_path);
fclose(f); fclose(f);
FILE *fp; rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
fp = fopen(conf_path,"w+");
if(fp == NULL)
{
rpc_log_error("OPEN CONFIG FALID\n");
return;
}
fseek(fp,0,SEEK_SET);
fputs(sum_buf,fp);
fclose(fp);
return; return conf_file_write(conf_path, sum_buf);
} }
/* 删除指定配置块中的配置 */
/* int conf_value_in_block_del(char *conf_path, char *start_str,
* char *end_str, char *conf_buff)
*
*1
*
*/
void del_if_config(char *if_name, char *conf_buff)
{ {
char *conf_path = IFCONFIG_PATH;
char config_linebuf[IF_BUFF_LEN]; char config_linebuf[IF_BUFF_LEN];
char auto_str[IF_BUFF_LEN] = {0}; int configbuf_lenth = strlen(conf_buff) + 5;
long congig_lenth = 0;
boolean next_flag = FALSE; boolean next_flag = FALSE;
char *auto_line = NULL; char *start_line = NULL;
FILE *f; FILE *f = fopen(conf_path, "r+");
f = fopen(conf_path,"r+");
if(f == NULL) if(f == NULL)
{ {
printf("OPEN CONFIG FALID\n"); printf("OPEN CONFIG FALID\n");
return; return RET_ERR;
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
long congig_lenth = ftell(f); congig_lenth = ftell(f);
int configbuf_lenth = strlen(conf_buff);
configbuf_lenth = configbuf_lenth + 5;
char sum_buf[congig_lenth + configbuf_lenth]; char sum_buf[congig_lenth + configbuf_lenth];
memset(sum_buf, 0, sizeof(sum_buf)); memset(sum_buf, 0, sizeof(sum_buf));
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
sprintf(auto_str, "auto %s", if_name); memset(config_linebuf, 0, sizeof(config_linebuf));
while(fgets(config_linebuf, IF_BUFF_LEN,f) != NULL) while(fgets(config_linebuf, IF_BUFF_LEN,f) != NULL)
{ {
@ -430,15 +192,15 @@ void del_if_config(char *if_name, char *conf_buff)
} }
/* 没有找到接口配置块,则继续循环 */ /* 没有找到接口配置块,则继续循环 */
if(auto_line == NULL) if(start_line == NULL)
{ {
auto_line = strstr(config_linebuf, auto_str); start_line = strstr(config_linebuf, start_str);
strcat(sum_buf, config_linebuf); strcat(sum_buf, config_linebuf);
goto next_while; goto next_while;
} }
/* 已经是下一个接口了, 则表示无法找到*/ /* 已经是下一个接口了, 则表示无法找到*/
if(strstr(config_linebuf, "auto")) if(strstr(config_linebuf, end_str))
{ {
strcat(sum_buf, config_linebuf); strcat(sum_buf, config_linebuf);
next_flag = TRUE; next_flag = TRUE;
@ -466,20 +228,54 @@ void del_if_config(char *if_name, char *conf_buff)
memset(config_linebuf, 0, sizeof(config_linebuf)); memset(config_linebuf, 0, sizeof(config_linebuf));
} }
printf("---sum_buf---->%s<----------/n",sum_buf);
remove(conf_path); remove(conf_path);
fclose(f); fclose(f);
FILE *fp; rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
fp = fopen(conf_path,"w+");
if(fp == NULL) return conf_file_write(conf_path, sum_buf);
}
/*
*
*
*1 2 3
*
*/
void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff)
{ {
printf("OPEN CONFIG FALID/n"); char auto_str[IF_BUFF_LEN] = {0};
char iface_str[IF_BUFF_LEN] = {0};
char static_name[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
sprintf(iface_str, "iface %s inet", if_name);
sprintf(static_name, "iface %s inet static\n", if_name);
conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", iface_str, static_name);
conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff);
return; return;
} }
fseek(fp,0,SEEK_SET);
fputs(sum_buf,fp);
fclose(fp); /*
*
*
*1
*
*/
void ip_conf_file_del(char *if_name, char *conf_buff)
{
char auto_str[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
conf_value_in_block_del(IFCONFIG_PATH, auto_str, "auto", conf_buff);
return;
} }

View File

@ -0,0 +1,38 @@
#include "../../../../common/rpc/rpc.h"
#include "../include/parsefile.h"
#include "../include/configm.h"
#include "../../../netlink_uapi/libnetlinku.h"
#include "../include/jumppage.h"
#include <cjson/cJSON.h>
#include "../../../../../Common/s2j/s2j.h"
#include "../../../../../Common/commuapinl.h"
/*全局变量,存放用户跳转的页面 */
char *jumpurl;
/*初始化 */
char *jumpurl = NULL;
/*系统管理模块将数据内容(URL地址发送给web server */
ret_code jumppage_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
char *struct_jumppage;
struct_jumppage = (char *)input;
rpc_log_info("jumppage configure: url: %s\n",
struct_jumppage);
/*将配置信息发送到web server */
/*把本地Portal server的配置信息存入全局变量 */
jumpurl = struct_jumppage;
return RET_OK;
}

View File

@ -75,7 +75,7 @@ ret_code userlock_config_proc(uint source, uint config_type,
userlock_configure_t *struct_userlock; userlock_configure_t *struct_userlock;
struct_userlock = (userlock_configure_t *)input; struct_userlock = (userlock_configure_t *)input;
rpc_log_info("userlock configure: 登录时间: %d 用户认证失败次数: %d 用户认证的时间范围: %d 用户锁定时间: %d\n", rpc_log_info("userlock configure: 登录时间: %d 用户认证失败次数: %d 用户认证的时间范围: %d 用户锁定时间: %ld\n",
struct_userlock->logintime, struct_userlock->failcount, struct_userlock->logintime, struct_userlock->failcount,
struct_userlock->timehorizon, struct_userlock->locktime); struct_userlock->timehorizon, struct_userlock->locktime);

View File

@ -40,9 +40,11 @@
## **编译方法** ## **编译方法**
#### 1. 从仓库获取最新代码 #### 1. 从仓库获取最新代码
<code>git clone git@git.komect.net:ISG/secogateway.git</code> <code>git clone --recursive git@git.komect.net:ISG/secogateway.git
git submodule update --init --recursive</code>
<code>git pull</code> <code>git submodule update --init --recursive
git pull</code>
#### 2. 安装必要软件(UBuntu) #### 2. 安装必要软件(UBuntu)
<code>sudo ./fsl-qoriq-glibc-x86_64-fsl-toolchain-aarch64-toolchain-2.4.1.sh <code>sudo ./fsl-qoriq-glibc-x86_64-fsl-toolchain-aarch64-toolchain-2.4.1.sh