📄 ddns_cgi.c
字号:
#ifndef _DDNS_CGI_C_
#define _DDNS_CGI_C_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "ddns.h"
#include "parser.h"
#include "system.h"
#include "wan.h"
static ddns_conf *pConf,conf;
#define DNS_MESSAGE_CONF "/var/ddns.message"
#ifdef _MULTI_PPPOE_
static MULTI_PPPOE_CONF mpoe_conf;
static int wan_type;
#endif
static int poe_account_index;
static enum{
CHANGE_ACCOUNT,
SAVE
}which_submit;
#ifdef _MULTI_PPPOE_
static int r2t_poe_account_list(char buf[CGI_BUF_LEN],char **buf1)
{
int i;
if(wan_type == CONNECTION_MULTI_PPPOE){
strcpy(buf,str_poe_ac_list_head);
for(i=0;i<MAX_PPPOE_ACCOUNT;i++){
if(i == poe_account_index){
strcat(buf,option_sl);
}
else{
strcat(buf,option_s);
}
strcat(buf,mpoe_conf.account[i].poe_ac_name);
strcat(buf,option_e);
}
strcat(buf,str_poe_ac_list_tail);
}
return 0;
}
#endif
static int r2t_ddns_name(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,pConf->ddns_user);
return 0;
}
static int r2t_ddns_pwd(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,pConf->ddns_pwd);
return 0;
}
static int r2t_user_domain(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,pConf->user_domain);
if(!strcmp(buf, "www") ){
*buf = '\0';
}
return 0;
}
static int r2t_dyn_domain(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,pConf->dyn_domain);
return 0;
}
static int r2t_tl_domain(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,pConf->tl_domain);
return 0;
}
static int r2t_ddns_message(char buf[CGI_BUF_LEN],char **buf1)
{
FILE *fp;
struct stat stat_f;
if(stat(DNS_MESSAGE_CONF,&stat_f)<0)
return 1;
if(stat_f.st_size==0)
return 0;
fp=fopen(DNS_MESSAGE_CONF,"rt");
if(!fp)
return DDNS_ReadConfErr;
fread(buf,1,stat_f.st_size,fp);
buf[strlen(buf)]=0;
fclose(fp);
return 0;
}
static int r2t_message(char buf[CGI_BUF_LEN],char **buf1)
{
set_err_msg(buf,buf1);
return 0;
}
#if _MULTI_PPPOE_
static int r2t_poe_ac_value(char buf[CGI_BUF_LEN],char **buf1)
{
strcpy(buf,mpoe_conf.account[poe_account_index].poe_ac_name);
return 0;
}
#endif
static int t2r_ddns_name(const char *value,int index)
{
if(strlen(value) > DDNS_MaxNameLen || !*value){
setbit(glb_errlog,MSG1_DDNS);
}
else{
strncpy(pConf->ddns_user,value,DDNS_MaxNameLen);
pConf->ddns_user[DDNS_MaxNameLen] = '\0';
}
return 0;
}
static int t2r_ddns_pwd(const char *value,int index)
{
strncpy(pConf->ddns_pwd,value,DDNS_MaxPassLen);
pConf->ddns_pwd[DDNS_MaxPassLen] = '\0';
return 0;
}
static int t2r_user_domain(const char *value,int index)
{
if(strlen(value) > DDNS_MaxUserDmLen || !*value){
setbit(glb_errlog,MSG1_DDNS);
}
else{
strncpy(pConf->user_domain,value,DDNS_MaxUserDmLen);
pConf->user_domain[DDNS_MaxUserDmLen] = '\0';
}
return 0;
}
static int t2r_dyn_domain(const char *value,int index)
{
if(strlen(value) > DDNS_MaxDynDmLen || !*value){
setbit(glb_errlog,MSG1_DDNS);
}
else{
strncpy(pConf->dyn_domain,value,DDNS_MaxDynDmLen);
pConf->dyn_domain[DDNS_MaxDynDmLen] = '\0';
}
return 0;
}
static int t2r_tl_domain(const char *value,int index)
{
if(strlen(value) > DDNS_MaxTlDmLen || !*value){
setbit(glb_errlog,MSG1_DDNS);
}
else{
strncpy(pConf->tl_domain,value,DDNS_MaxTlDmLen);
pConf->tl_domain[DDNS_MaxTlDmLen] = '\0';
}
return 0;
}
static int t2r_save(const char *value,int index)
{
which_submit=SAVE;
return 0;
}
static int t2r_help(const char *value,int index)
{
return 0;
}
static int t2r_message(const char *value,int index)
{
return 0;
}
#if 0
static int t2r_poe_ac_value(const char *value,int index)
{
int i;
if(*value,int index){
for(i=0;*value,int index&&i<MAX_PPPOE_ACCOUNT;i++){
if(!strcmp(value,mpoe_conf.account[i].poe_ac_name)){
poe_account_index = i;
break;
}
}
}
return 0;
}
#endif
int ddns_main(void)
{
LIST *hd=NULL;
int ccode;
memset(glb_errlog,0,sizeof(glb_errlog));
memset(&conf,0,sizeof(conf));
which_submit = CHANGE_ACCOUNT;
#ifdef _MULTI_PPPOE_
memset(&mpoe_conf, 0, sizeof(MULTI_PPPOE_CONF));
if((wan_type=get_wan_type())==CONNECTION_MULTI_PPPOE){
poe_account_index=0;
ReadMultiPPPoESettings(&mpoe_conf);
}else
#endif
{
poe_account_index=-1;
}
ReadDDNSConf(&conf,poe_account_index);
pConf=&conf;
if (strcmp(REQUEST_METHOD,POST) == 0){
hd=cgi_input_parse();
if(!hd){
cgi_err("","");
}
if(!do_cgi_t2r(hd,key_fun_tab)){
if(ErrlogIsSetted()){
if(isset(glb_errlog,MSG1_DDNS)){
char *msg=get_err_msg(MSG1_DDNS);
fmt_err_msg(msg);
}
if(isset(glb_errlog,MSG2_DDNS)){
char *msg=get_err_msg(MSG2_DDNS);
fmt_err_msg(msg);
}
if(isset(glb_errlog,MSG3_DDNS)){
char *msg=get_err_msg(MSG3_DDNS);
fmt_err_msg(msg);
}
}
else{
if(which_submit==SAVE){
ccode=SaveDDNSConf(&conf,poe_account_index);
WriteConfToFlash();
}else if(which_submit==CHANGE_ACCOUNT){
ReadDDNSConf(&conf,poe_account_index);
}
}
}
list_clear(hd);
}
return html_parser("ddns.htm",key_fun_tab);
}
#endif /* _DDNS_CGI_C_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -