#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("
");
printf("");
printf("");
}
int main(int argc, char *argv[])
{
read_rclocal();
read_ini();
web_page();
return 0;
}