嵌入式Linux web配置示例

2019-07-12 22:39发布

嵌入式web配置示例 index.html 嵌入式网页配置示例

嵌入式网页配置示例

请输入密码:

read.c #include #include #include #include #include "libini.h" char local_mac[32] = "00:01:02:03:04:05"; char local_ip[32] = "0.0.0.0"; char yealink_report_server[32] = "0.0.0.0"; char server_ip[32] = "0.0.0.0"; char number[32] = "0000"; char password[32] = "0000"; void read_rclocal(void) { FILE *fp; // fp = fopen("./cgi-bin/rc.local", "rt"); fp = fopen("/home/bin/rc.local", "rt"); if (fp != NULL) { char buffer[256]; memset(buffer, 0, sizeof(buffer)); fread(buffer, 1, sizeof(buffer), fp); //printf("buffer = %s ", buffer); { // 读mac地址 char *p; char *p2; p = strtok(buffer, " "); //printf("p = %s ", p); p = strtok(NULL, " "); //printf("p = %s ", p); // mac地址行 p2 = strtok(p, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); if (p2 != NULL && local_mac != NULL) { memset(local_mac, 0, sizeof(local_mac)); strcpy(local_mac, p2); //printf("local_mac = %s ", local_mac); } } { // 读local_ip char *p; char *p2; memset(buffer, 0, sizeof(buffer)); fseek(fp, 0, SEEK_SET); fread(buffer, 1, sizeof(buffer), fp); //printf("buffer = %s ", buffer); p = strtok(buffer, " "); //printf("p = %s ", p); p = strtok(NULL, " "); //printf("p = %s ", p); p = strtok(NULL, " "); //printf("p = %s ", p); p2 = strtok(p, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); p2 = strtok(NULL, " "); //printf("p2 = %s ", p2); if (p2 != NULL && local_ip != NULL) { memset(local_ip, 0, sizeof(local_ip)); strcpy(local_ip, p2); //printf("local_ip = %s ", local_ip); } } fclose(fp); fp = NULL; } } void read_ini(void) { INI *pini; pini = ini_open("/home/bin/sdp_config.ini"); if (!pini) { printf("load config faild. "); return; } //printf("length:%d ", pini->length); ini_set(pini, "system@local_ip", local_ip); //printf("local_ip = %s ", local_ip); ini_get(pini, "system@yealink_report_server", yealink_report_server); //printf("yealink_report_server = %s ", yealink_report_server); ini_get(pini, "phone@server_ip", server_ip); //printf("server_ip = %s ", server_ip); ini_get(pini, "phone@number", number); //printf("number = %s ", number); ini_get(pini, "phone@password", password); //printf("password = %s ", password); ini_save(pini); ini_close(pini); } void web_page(void) { // html page. // printf("Content-type:text/html;charset=gb2312 "); printf("Content-type:text/html;charset=utf8 "); printf(""); printf(""); printf("配置页面"); printf(""); printf(""); printf(""); printf("

"); printf("

配置界面

"); printf(" "); printf("
"); printf("本 机MAC:", local_mac); printf(" "); printf("本 机 IP:", local_ip); printf(" "); printf("调度台IP:", yealink_report_server); printf(" "); printf("服务器IP:", server_ip); printf(" "); printf("电话号码:", number); printf(" "); printf("密 码:", password); printf(" "); printf(" "); printf(" "); printf("
"); printf("

"); printf(""); printf(""); } int main(int argc, char *argv[]) { read_rclocal(); read_ini(); web_page(); return 0; }

write.c #include #include #include #include "libini.h" char local_mac[32] = "00:01:02:03:04:05"; char local_ip[32] = "0.0.0.0"; char yealink_report_server[32] = "0.0.0.0"; char server_ip[32] = "0.0.0.0"; char number[32] = "0000"; char password[32] = "0000"; char buf[256]; void write_rclocal(void) { FILE *fp; // fp = fopen("./cgi-bin/rc.local", "rt"); fp = fopen("/home/bin/rc.local", "wt"); if (fp != NULL) { char buffer[256]; memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "#!/bin/sh ifconfig eth0 hw ether %s ifconfig eth0 %s up ifconfig lo 127.0.0.1 up hostname %s ", local_mac, local_ip, local_ip); fwrite(buffer, 1, strlen(buffer), fp); fclose(fp); fp = NULL; } } // URL解密 void urldecode(char *p) { register i=0; if (p != NULL) { while(*(p+i)) { if ((*p=*(p+i)) == '%') { *p = *(p+i+1) >= 'A' ? ((*(p+i+1) & 0XDF) - 'A') + 10 : (*(p+i+1) - '0'); *p = (*p) * 16; *p += *(p+i+2) >= 'A' ? ((*(p+i+2)&0XDF) - 'A') + 10 : (*(p+i+2) - '0'); i+=2; } else if (*(p+i)=='+') { *p=' '; } p++; } *p='