📄 ftp.c
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <getopt.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/config.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "cgivars.h"
#include "htmllib.h"
#include "config_phase.h"
#include "sysconf.h"
#define DEBUG 0
#define ID_FTPSERADD 45
#define ID_FTPPORT 46
#define ID_FTPUSNM 47
#define ID_FTPPSWD 48
#define ID_FTPMODE 49
static config_item ** items;
static int config_list[] = {45,46,47,48,49};
static char *config_name[] = {"FTPSERADD","FTPPORT","FTPUSNM","FTPPSWD","FTPMODE"};
char java[] =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
<HTML><HEAD>
<META http-equiv=Expires content=\"Tue, 1 Jan 1980 2:00:00 GMT\">
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=\"no-cache,must revalidate\">
<META http-equiv=Content-Type content=\"text/html; charset=gb2312\">
<STYLE type=text/css>BODY {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
TD {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
FORM {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
OPTION {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
TEXTAREA {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
P {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
OL {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
INPUT {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
SELECT {
FONT-SIZE: 10pt; FONT-FAMILY: Arial
}
.style1 {
FONT-WEIGHT: bold; FONT-SIZE: 14pt
}
</STYLE>
<META content=\"MSHTML 6.00.6000.16414\" name=GENERATOR></HEAD>";
void ftp(char **postvars, int form_method)
{
int config_num = sizeof(config_list)/sizeof(int);
int i;
int r_fd, w_fd;
int temp_int;
char *temp_string;
//r_fd = open_read_fifo();
items = init_config_item(items, config_num, config_list);
printf("%s\n", java);
// If we got post, write it into flash
if(form_method == POST)
{
GetConfValues(config_list, items, config_num);
if(SaveConfig(postvars, items, config_list, config_name, config_num))
{/*
w_fd = open_write_fifo();
notify_config(w_fd);
close_write_fifo(w_fd);
read_fifo(r_fd);
*/
}
}
GetConfValues(config_list, items, config_num);
printf("<BODY leftMargin=30 topMargin=24 rightMargin=30><P class=style1>FTP服务</P>\n");
printf("<TABLE width=\"100%\"><TBODY><TR><TD><FORM name=ftp action=\"/ftp.cgi\" method=post target=msgFrame>\n");
printf("<TABLE style=\"BORDER-COLLAPSE: collapse\" borderColor=#dae3eb cellSpacing=0 cellPadding=0 width=\"100%\" border=1>\n");
printf("<TBODY><TR bgColor=#cccccc><TD colSpan=2><STRONG>FTP设置</STRONG></TD></TR>\n");
printf("<TR><TD noWrap width=\"40%\">FTP服务器地址</TD>\n");
//ID_FTPSERADD
if(temp_string = getdata(ID_FTPSERADD, items, config_num))
printf("<TD> <INPUT size=25 name=FTPSERADD value=%s></TD></TR>\n", temp_string);
else
printf("<TD> <INPUT size=25 name=FTPSERADD></TD></TR>\n");
//ID_FTPPORT
if(temp_string = getdata(ID_FTPPORT, items, config_num))
printf("<TR><TD noWrap width=\"40%\">FTP服务器端口</TD> <TD> <INPUT size=25 name=FTPPORT value=%s ></TD></TR>\n", temp_string);
else
printf("<TR><TD noWrap width=\"40%\">FTP服务器端口</TD> <TD> <INPUT size=25 name=FTPPORT></TD></TR>\n");
//ID_FTPUSNM
if(temp_string = getdata(ID_FTPUSNM, items, config_num))
printf("<TR><TD>帐号</TD><TD> <INPUT maxLength=32 name=FTPUSNM value=%s></TD></TR>\n", temp_string);
else
printf("<TR><TD>帐号</TD><TD> <INPUT maxLength=32 name=FTPUSNM></TD></TR>\n");
//ID_FTPPSWD
if(temp_string = getdata(ID_FTPPSWD, items, config_num))
printf("<TR><TD>密码</TD><TD> <INPUT type=password maxLength=32 name=FTPPSWD value=%s></TD></TR>\n", temp_string);
else
printf("<TR><TD>密码</TD><TD> <INPUT type=password maxLength=32 name=FTPPSWD></TD></TR>\n");
//ID_FTPMODE
printf("<TR><TD>连接模式</TD><TD> <SELECT name=FTPMODE>\n");
if(temp_string = getdata(ID_FTPMODE, items, config_num))
{
temp_int = atoi(temp_string);
if( 1 == temp_int )
{
printf("<OPTION value=\"1\" selected>Port</OPTION>\n");
printf("<OPTION value=\"0\">Passive</OPTION></SELECT> (通常情况下选择Port模式) </TD></TR>\n");
}
else
{
printf("<OPTION value=\"1\">Port</OPTION>\n");
printf("<OPTION value=\"0\" selected>Passive</OPTION></SELECT> (通常情况下选择Port模式) </TD></TR>\n");
}
}
printf("</TBODY></TABLE><DIV align=left><INPUT type=submit value=应用> <INPUT type=reset value=清除> </DIV>\n");
printf("</FORM></TD></TR><TR><TD></TD></TR></TBODY></TABLE></BODY></HTML>\n");
free_config_item(items, config_num);
//close_read_fifo();
}
////////////////////////////////////////////////////////////////////////////
// Function: main
////////////////////////////////////////////////////////////////////////////
int main(void)
{
char **postvars = NULL; // POST request data repository
char **getvars = NULL; // GET request data repository
int form_method; // POST = 1, GET = 0
// CGI part start here
adminCheck();
form_method = getRequestMethod();
if(form_method == POST)
{
// getvars = getGETvars();
postvars = getPOSTvars();
}
else if(form_method == GET)
{
getvars = getGETvars();
}
// CGI start here, set COM port
ftp(postvars, form_method);
//htmlFooter();
cleanUp(form_method, getvars, postvars);
fflush(stdout);
exit(0);
} // end of main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -