Esempio n. 1
0
int guide_module_dnat(void)
{
    char action[STRING_LENGTH] = {0};
    char enable_str[STRING_LENGTH] = {0};
    int  enable;
    int  ret = GUIDE_OK;

    DEBUGP("%s: begin\n", __FUNCTION__);
    
    cgiFormString("action", action, sizeof(action));
    if (strcmp(action, "list") == 0)
    {
        ret = guide_dnat_show();
    }
    else if (strcmp(action, "reset") == 0)
    {
        cgiFormString("enable", enable_str, sizeof(enable_str));
        enable = atoi(enable_str);
        ret = guide_dnat_update(enable);
    }
    else
    {
        ret = GUIDE_NO_SUCH_ACTION;
    }   

    DEBUGP("%s: finish, ret = %d\n", __FUNCTION__, ret);
    return ret;
}
Esempio n. 2
0
int cgiMain()
{
	char submit_type[STRING_LENGTH];
	//char cmd[CMD_LENGTH];
	int iserror=0;
    char state[STRING_LENGTH];

	//snprintf(cmd, sizeof(cmd), BACKUP_XMLTMP_CMD);
	//system(cmd);

	cgiFormString("state", state, sizeof(state));
    //if(strcmp(state,"1") == 0)
    //    return 0;
    printf("content-type:text/html\n\n");
    
    cgiFormString("cmd", submit_type, sizeof(submit_type));
	
	if (strcmp(submit_type,"1") == 0 ){//列表显示所有
		send_drop();
	}	
	else if(strcmp(submit_type,"2") == 0 ){//点击添加
		send_ip_drop();
	}
	else if(strcmp(submit_type,"3") == 0){//点击编辑
		send_url_drop();
	}
	else{
		iserror = MGTCGI_PARAM_ERR;
	}
    
	printf("SUCCESS");
	return 0;
}
Esempio n. 3
0
int cgiMain() {
	char username[40];   //用户名
	char value[20];	     //中间值
	long sessionId;      //会话ID
	char actName[20];    //请求动作
	char result[4096];   //请求结果
	char params[500];    //请求参数
	actName[0]= NULL;    //初始化
	result[0] = NULL;    //初始化

	//解决中文乱码
	cgiHeaderContentType("text/html; charset=UTF-8");
	
	/*    获取参数   */
	cgiFormString("username",username,40);
	cgiFormString("sessionId",value,20);
	sessionId = atol(value);
	cgiFormString("actName",actName,20);
	cgiFormString("params",params,500);
	
	/*  检查session有效性   */
	//会话无效
	if(!isSessionValid(sessionId,username)){
		//提示用户未登录或会话已过期
		printf("NLogin");
		return 0;
	}
	//会话有效
	else{
		//更新session访问时间
		updateSessionService(sessionId);
	}
	
	/*    权限验证    */
	//权限不足
	if(!isAuthorityValid(actName,username)){
		//提示权限不足
		printf("NRight");
		return 0;
	}
	
	/*   调用业务层处理请求   */
	//请求处理成功
	if(userServices(params,actName,result)){
		//输出请求结果
		
		printf(result);
		
	}
	//请求处理失败
	else{
		//输出系统出错信息
		printf("actName=%s;result=false",actName);
	}
	
	return 0;
}
int cgiMain()
{
	char submit_type[STRING_LENGTH];
	char cmd[CMD_LENGTH];
	int iserror=0;

	snprintf(cmd, sizeof(cmd), BACKUP_XMLTMP_CMD);
	system(cmd);

	cgiFormString("submit", submit_type, sizeof(submit_type));
	
#if _MGTCGI_DEBUG_GET_
	printf("content-type:text/html\n\n");		
#else
	printf("content-type:application/json\n\n");	
#endif
	system(cmd);

	cgiFormString("submit",submit_type,STRING_LENGTH);
	
	if (strcmp(submit_type,"list") == 0 ){//列表显示所有
		extensiongroups_list_show();
	}	
	else if(strcmp(submit_type,"add") == 0 ){//点击添加
		extensiongroups_add_show();
	}
	else if(strcmp(submit_type,"edit") == 0){//点击编辑
		extensiongroups_edit_show();
	}
	else if(strcmp(submit_type,"addsave") == 0){//添加"确定"
		extensiongroups_add_save();
	}
	else if(strcmp(submit_type,"editsave") == 0){//编辑"确定"
		extensiongroups_edit_save();
	}
	else if(strcmp(submit_type,"remove") == 0){//点击删除
		extensiongroups_remove_save();
	}
	else if(strcmp(submit_type,"move") == 0){//排序
		extensiongroups_move();
	}
	else{
		iserror = MGTCGI_PARAM_ERR;
		goto ERROR_EXIT;
	}
	
	goto CGIC_EXIT;

	ERROR_EXIT:
		printf("{\"iserror\":%d,\"msg\":\"\"}",iserror);
		goto CGIC_EXIT;
	CGIC_EXIT:
		return 0;
}
Esempio n. 5
0
int cgiMain()
{
	char send_cb_string[GL_CALLBACK_MAX_SIZE];
	int send_cb_len;

	linkage_st lnk_st;
	int enable_flag;

	cgiFormResultType cgi_re;
	int res=0;

	cgiHeaderContentType("application/json"); //MIME

	cgi_re = cgiFormInteger(FIELD_LID, &lnk_st.lnk_base.lid, 0);
	cgi_re = cgiFormString(FIELD_LNKNAME, lnk_st.lnk_base.lnkname, NAME_STRING_LEN + 1);
	lnk_st.lnk_base.lnkname[NAME_STRING_LEN] = '\0';
	cgi_re = cgiFormString(FIELD_TRGIEEE, lnk_st.lnk_base.trgieee, IEEE_LEN + 1);
	lnk_st.lnk_base.trgieee[IEEE_LEN] = '\0';
	cgi_re = cgiFormString(FIELD_TRGEP, lnk_st.lnk_base.trgep, 2 + 1);
	lnk_st.lnk_base.trgep[2] = '\0';
	cgi_re = cgiFormString(FIELD_TRGCND, lnk_st.lnk_base.trgcnd, TRIGGER_CONDITION_LEN + 1);
	lnk_st.lnk_base.trgcnd[TRIGGER_CONDITION_LEN] = '\0';
	cgi_re = cgiFormString(FIELD_LNKACT, lnk_st.lnk_base.lnkact, ACTPARA_LEN + 1);
	lnk_st.lnk_base.lnkact[ACTPARA_LEN] = '\0';
	cgi_re = cgiFormInteger(FIELD_ENABLE, &enable_flag, 0);
	lnk_st.lnk_base.enable = (char)enable_flag;

	res = gnerate_per_urlobj(&lnk_st.urlobject, lnk_st.lnk_base.lnkact);
	if(res <0){
		goto all_over;
	}
	res = gnerate_linkage_trgcnd_st(&lnk_st.lnk_condition, lnk_st.lnk_base.trgcnd);
	if(res <0){
		goto all_over;
	}
//	wrtie database
	res = db_init();
	if(res<0){
		goto all_over;
	}
	res = edit_linkage_db(&lnk_st);
	if(res<0){
		goto all_over;
	}
all_over:
	db_close();
    api_response(res, lnk_st.lnk_base.lid, &lnk_st.lnk_base);
    //push to cb_daemon
	if((send_cb_len = cJsonLinkage_callback(send_cb_string, SUBID_EDIT_LINK, res, lnk_st.lnk_base.lid, &lnk_st.lnk_base)) >=0) {
		//if push failed, not handle temporary
		push_to_CBDaemon(send_cb_string, send_cb_len);
	}
	return 0;
}
Esempio n. 6
0
File: set.c Progetto: jhlxz2003/akb
/* DONE */
static int
auth_check()
{
	memset(user, '\0', 36);
	memset(pass, '\0', 36);
	cgiFormString("user", user, 36);
	cgiFormString("passwd", pass, 36);
	if (strcmp(user, usr) == 0&&strcmp(pass, pwd) == 0)
		return 0;
	else
		return -1;
}
Esempio n. 7
0
/***************************************************************************
  Function: cgiMain
  Description: 
  Input:  
  Output: 
  Return: 0 OK, other Error
  Others:  none
***************************************************************************/
int cgiMain()
{
    char account[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1]; //16 + terminating null
	char password[FEATURE_GDGL_PASSWD_MAX_LEN + 1]; //16 + terminating null
	char gateway_id[FEATURE_GDGL_ID_LEN + 1]; //12 + terminating null
	char gateway_alias[FEATURE_GDGL_ACCOUNT_MAX_LEN + 1];
	char gateway_passwd[FEATURE_GDGL_PASSWD_MAX_LEN + 1];
	cgiFormResultType cgi_re;
	int res;

	cgiHeaderContentType("application/json"); //MIME

    // Read ID
    res = read_id(gateway_id);
	if (res != 0) {
		client_admin_response("noid", res, clientAdminResultStr[res]);
		return res;
	}
	
	// Read alias
	res = read_alias(gateway_alias);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // Read password
	res = read_password(gateway_passwd);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // Check account
    cgi_re = cgiFormString("account", account, FEATURE_GDGL_ACCOUNT_MAX_LEN + 1);
	res = check_account(cgi_re, account, gateway_id, gateway_alias);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

	// Check password
	cgi_re = cgiFormString("password", password, FEATURE_GDGL_PASSWD_MAX_LEN + 1);
	res = check_password(cgi_re, password, gateway_passwd);
	if (res != 0) {
		client_admin_response(gateway_id, res, clientAdminResultStr[res]);
		return res;
	}

    // account & password all right	
    client_admin_response(gateway_id, clientAdminSuccess, clientAdminResultStr[clientAdminSuccess]);
	return 0;
}
Esempio n. 8
0
File: set.c Progetto: jhlxz2003/akb
static int
what_action()
{
	char str[16];
	memset(str, 0, 16);
	if (cgiFormString("next", str, 16) == cgiFormSuccess)
		return 1;
	else if (cgiFormString("finish", str, 16) == cgiFormSuccess)
		return 0;
	else
		return 2;
}
Esempio n. 9
0
void CookieSet()
{
    char cname[1024];
    char cvalue[1024];
    /* Must set cookies BEFORE calling cgiHeaderContentType */
    cgiFormString("cname", cname, sizeof(cname));
    cgiFormString("cvalue", cvalue, sizeof(cvalue));
    if (strlen(cname)) {
        /* Cookie lives for one day (or until browser chooses
        	to get rid of it, which may be immediately),
        	and applies only to this script on this site. */
        cgiHeaderCookieSetString(cname, cvalue,
                                 86400, cgiScriptName, SERVER_NAME);
    }
}
Esempio n. 10
0
void Address() {
    char address[241];
    cgiFormString("address", address, 241);
    fprintf(cgiOut, "Address: <PRE>\n");
    cgiHtmlEscape(address);
    fprintf(cgiOut, "</PRE>\n");
}
Esempio n. 11
0
int cgiMain() {
	FILE *fd = fopen(DATAFILE,"w");
	char poststr[MAX_STRING];
	char cmd_str[200] = "gcc -o ./user_home/a.out ";
	int  ret;
	char * cgiHostAddr;
    	cgiHeaderContentType("text/html");
    	fprintf(cgiOut, "<HTML><HEAD>\n");
    	fprintf(cgiOut, "<TITLE>Code Confirm Page</TITLE>\n");
	fprintf(cgiOut, "<link rel=\"stylesheet\" href=\"../remote.css\" type=\"text/css\" /></HEAD>");
    	fprintf(cgiOut, "<BODY>");
	fprintf(cgiOut, "<h1>Welcom to Code Confirm Page</h1>");
	fprintf(cgiOut, "<P>The Code You Submit Is:</p>");
    	cgiFormString("data", poststr, MAX_STRING);
    	fprintf(cgiOut, "<pre>%s</pre>",poststr);
    	fprintf(fd,"%s",poststr);
 	cgiGetenv(&cgiHostAddr, "HOST_ADDR");	
    	fprintf(cgiOut, "<p>Your Host IP = %s</p>",cgiRemoteAddr);
	printf("<hr/>");
	fprintf(cgiOut, "<form action=\"run_handler.cgi\" method=\"get\">");
        fprintf(cgiOut,"<div>");
        fprintf(cgiOut,"<input type=\"submit\" value=\"Compile and Run\">");
        fprintf(cgiOut,"</div>");
        fprintf(cgiOut,"</form>");

    	fprintf(cgiOut, "</BODY>\n");
    	fprintf(cgiOut, "</HTML>\n");
	close(fd);
    	return 0;
}
Esempio n. 12
0
/*
 * Parse out the callback method and
 * add it to the req struct.
 */
int parseCallback(struct extRequest *req) {
  int return_status = 0;
  int callbackLength = 0;
  if(cgiFormStringSpaceNeeded(CALLBACK_PARAM_NAME, &callbackLength) == cgiFormSuccess) {
    if(callbackLength > 0) {
      req->callback = (char*)malloc(sizeof(char)*callbackLength);
      if(cgiFormString(CALLBACK_PARAM_NAME, req->callback, callbackLength) == cgiFormSuccess) {
        return_status = 1;
      } else {
        free(req->callback);
      }
    } 
  }

  /*
   * Set req->callback to NULL
   * so that it's not printed
   * in curl.c
   */
  if(!return_status) {
    req->callback = NULL;
  }

  return return_status;
  
}
Esempio n. 13
0
int cgiMain()
{
	int res=0;
	char rfid[IEEE_LEN+1]={0};
	int operatortype;
	int duration;

	char send_string[RF_RESPOND_TO_API_MAX_LEN]={0};

	char respond_string[RF_RESPOND_TO_API_MAX_LEN]={0};

	cgiFormResultType cgi_re;
	cgiHeaderContentType("application/json"); //MIME

	//获取rfid,state
	cgi_re = cgiFormString("rfid", rfid, IEEE_LEN + 1);
	cgi_re = cgiFormInteger("operatortype", &operatortype, -1);
	cgi_re = cgiFormInteger("param1", &duration, -1);
	rfid[IEEE_LEN]= '\0';

	//communication with RF_Daemon
	snprintf(send_string, RF_RESPOND_TO_API_MAX_LEN, "{\n	\"api\": \"RFWarningDevOperation\",\n	\"rfid\": \"%s\",\n	\"operatortype\": %d,\n	\"param1\": %d\n}", rfid,operatortype,duration);
	RF_DEBUG("%s\n", send_string);
	res = communicateWithRF(send_string, strlen(send_string)+1, respond_string);
//	if(res !=0) {
		fprintf(cgiOut,"{\n	\"status\": %d\n}\n", res);
//	}
//	fprintf(cgiOut, "%s\n", respond_string);

	return 0;
}
Esempio n. 14
0
int cgiMain()
{
	int i,n;
	int ret;
	char id_buf[10];
	char inputStr[2][VALUE_SIZE];
	char switch_buf[5];
	char enable_buf[5];
	char cmd[BUF_SIZE];
	char dev_name[DEVNAME_SIZE];

	memset(dev_name,0,sizeof(dev_name));
	memset(id_buf,0,sizeof(id_buf));
	memset(inputStr,0,sizeof(inputStr));
	memset(switch_buf,0,sizeof(switch_buf));
	memset(enable_buf,0,sizeof(enable_buf));
    sqlite3 *db;
	/* *.db must be under the root directory of web server,
	 * and the directory mode of *.db must be 777*/
	ret = sqlite3_open("data/devices.db",&db);
	if(ret != SQLITE_OK)
	{
		fputs(sqlite3_errmsg(db),stderr);
		fputs("\n",stderr);
		exit(1);
	}
	/* cgic header */
    cgiHeaderContentType("text/plain");
	cgiFormString("hub_id",id_buf,10);
	cgiFormString("inputVal",inputStr[0],20);
	cgiFormString("inputVal2",inputStr[1],20);
	cgiFormString("switch_opt",switch_buf,5);
	cgiFormString("enableBox",enable_buf,5);
	int hub_id=atoi(id_buf);
	n=sheet_row_modify(db,"temp_tb",hub_id,inputStr,switch_buf,enable_buf);
	/*update sheet*/
	if(n==0)
	{
		dev_getNameByHub(db,hub_id,dev_name);
		sheet_row_show(db,"temp_tb",hub_id,dev_name);
	}
	else
		printf("-1");
//	printf("1|hello|world|hi|hi|hi&");
	sqlite3_close(db);
	return 0;
}
int cgiParser() {
	    //request call=status
	    if(!memscmp(query,"status") && uid > 0){
	        id=status();
		if(id < 0) { 
			return FALSE;
		} 

		len=snprintf(query,BLOCK-1,"<check><place>%d</place></check>",id);
		if ( id == 0 ) place_list();
	        cgiWrite(query,len); 

	    //request call=list
	    } else if(!memscmp(query,"getplace") && uid > 0){
		place_list();
	    //request call=getuser
	    } else if(!memscmp(query,"getuser") && uid > 0){
		get_user();
	    //request call=getmsg
	    } else if(!memscmp(query,"getmsg") && uid > 0){
		place_get_message();
	    //request call=fresh
	    } else if(!memscmp(query,"fresh") && uid > 0){
		get_user();
		if(uid>0) place_get_message();
	    //request call=addmsg
	    } else if(!memscmp(query,"addmsg") && !cgiFormString ("msg",query,150) && uid > 0){
		if(!memcmp(query,"/MSG ",5)) {
			place_add_private(query+5);
		} else {
			place_add_message(query);
		}
	    //request call=join
	    } else if(!memscmp(query,"join")  && !cgiFormString ("place",query,3) && uid > 0){
		id=atoi(query);
	        user_join(id);
                cgiWriteStr("<action>join</action>");
		cgiprintf("<place_id>%s</place_id>",query); 
	    //request call=logout
	    } else if(!memscmp(query,"logout") ){
		LOGOUT
		return FALSE;	
	    //request call=login
            } else if(!memscmp(query,"login")  && !cgiFormString ("login",REG_LOGIN,REG_LOGIN_SIZE)  && !cgiFormString ("password",REG_PASS,REG_PASS_SIZE)){
Esempio n. 16
0
void extensions_list_show(void)
{
	int size=0,index=0,index_end=0;
	char page_str[DIGITAL_LENGTH];
	char pagesize_str[DIGITAL_LENGTH];
	int total=0,iserror=0,result=0;
	struct mgtcgi_xml_extensions *extensions = NULL;

	cgiFormString("page",page_str,STRING_LENGTH);
	cgiFormString("pagesize",pagesize_str,STRING_LENGTH);

	
	get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&extensions,&size);
 	if ( NULL == extensions){
		iserror = MGTCGI_READ_FILE_ERR;
		goto ERROR_EXIT;
	}
	
	total = extensions->num;
	result = get_page_turn_index(page_str, pagesize_str, total, &index, &index_end);
	if (result != 0){
		iserror = result;
		goto ERROR_EXIT;
	}
	
	printf("{\"data\":[");
	for (; index < index_end ;){
		printf("{\"name\":\"%s\",\"value\":\"%s\",\"comment\":\"%s\"}",\
			extensions->pinfo[index].name,extensions->pinfo[index].value,extensions->pinfo[index].comment);
		index++;
		if (index < index_end)
			printf(",");
		else
			break;
	}
		printf("],\"total\":%d,\"iserror\":0,\"msg\":\"\"}",total);
		goto FREE_EXIT;
	ERROR_EXIT:
		printf("{\"iserror\":%d,\"msg\":\"\"}",iserror);
		goto FREE_EXIT;
	FREE_EXIT:
		free_xml_node((void*)&extensions);
		return;
}
Esempio n. 17
0
File: set.c Progetto: jhlxz2003/akb
static int
check_from()
{
	char str[4];
	memset(str, 0, 4);
	if (cgiFormString("cstage", str, 4) == cgiFormSuccess)
		return atoi(str);
	else
		return -1;
}
Esempio n. 18
0
int
cgiMain()
{ 
	cgiHeaderContentType("text/html");
	
	int serverside = 0;
	cgiFormInteger("serverside", &serverside, 0);
	
	char function_call[50];
	int callback = 0;
	if (cgiFormString("function_call", &function_call[0], 50) == cgiFormSuccess)
		callback = 1;
	
	if(serverside) {
		/* Initialise the SEE library */
		SEE_init();
		
		/* Initialise an interpreter */
		SEE_interpreter_init(&g_interp_storage);
		g_interp = &g_interp_storage;
	
		/* Bring our native functions into the interpreter */
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "println", g_println, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "include", g_include, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "version", g_version, 1, 0);
		
		/* evaluate bootstrapping code, and then script, then transform events */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/serverside.js");
		evaluate_file(g_interp, &g_result, cgiPathTranslated);
		
		/* this is dangerous lol.  should check to make sure the callback is a function */
		if(callback)
			evaluate_string(g_interp, &g_result, function_call);
		
		/* this converts elements with onclick event attributes into links */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/transform.js");
		evaluate_string(g_interp, &g_result, "document.render();");
		
	} else {
		
		fprintf(cgiOut, "<html>\n<head>\n");
		fprintf(cgiOut, "<script type = \"text/javascript\">\n");
		fprintf(cgiOut, "function boot() {\n");
		print_file("/Users/alan/working/golf/boot/clientside.js");
		print_file(cgiPathTranslated);
		fprintf(cgiOut, "\n}\n");
		fprintf(cgiOut, "</script>\n</head>\n");
		fprintf(cgiOut, "<body onload = \"boot();\">\n");
		fprintf(cgiOut, "</body>\n</html>");
		
	}
	
	return EXIT_SUCCESS;
}
Esempio n. 19
0
static int get_end_time(int group_idx,pwctrl_time *time)
{
	char value[12];
	char name[10];
	memset(name,0,sizeof(name));
	sprintf(name,"endtime%d",group_idx);

	cgiFormString(name, value, 12);
	sscanf (value, "%d:%d:%d", &time->hour,&time->minute,&time->second);
	
	return 0;
}
Esempio n. 20
0
void
CookieSet ()
{
    char *cname;
    char *cvalue;
    /* Must set cookies BEFORE calling
       cgiHeaderContentType */
    cname = strdup ("Teest");
    cvalue = strdup ("TVaaaluue");
    if (strlen (cname)) {
        /* Cookie lives for one day (or until
           browser chooses to get rid of it, which
           may be immediately), and applies only to
           this script on this site. */
        cgiHeaderCookieSetString (cname, cvalue, 86400, cgiScriptName,
                                  cgiServerName);
        cgiFormString ("cname", cname, sizeof (cname));
        cgiFormString ("cvalue", cvalue, sizeof (cvalue));

    }
}
Esempio n. 21
0
void Cookies()
{
    char **array, **arrayStep;
    char cname[1024], cvalue[1024];
    fprintf(cgiOut, "Cookies Submitted On This Call, With Values (Many Browsers NEVER Submit Cookies):<p>\n");
    if (cgiCookies(&array) != cgiFormSuccess) {
        return;
    }
    arrayStep = array;
    fprintf(cgiOut, "<table border=1>\n");
    fprintf(cgiOut, "<tr><th>Cookie<th>Value</tr>\n");
    while (*arrayStep) {
        char value[1024];
        fprintf(cgiOut, "<tr>");
        fprintf(cgiOut, "<td>");
        cgiHtmlEscape(*arrayStep);
        fprintf(cgiOut, "<td>");
        cgiCookieString(*arrayStep, value, sizeof(value));
        cgiHtmlEscape(value);
        fprintf(cgiOut, "\n");
        arrayStep++;
    }
    fprintf(cgiOut, "</table>\n");
    cgiFormString("cname", cname, sizeof(cname));
    cgiFormString("cvalue", cvalue, sizeof(cvalue));
    if (strlen(cname)) {
        fprintf(cgiOut, "New Cookie Set On This Call:<p>\n");
        fprintf(cgiOut, "Name: ");
        cgiHtmlEscape(cname);
        fprintf(cgiOut, "Value: ");
        cgiHtmlEscape(cvalue);
        fprintf(cgiOut, "<p>\n");
        fprintf(cgiOut, "If your browser accepts cookies (many do not), this new cookie should appear in the above list the next time the form is submitted.<p>\n");
    }
    cgiStringArrayFree(array);
}
Esempio n. 22
0
int cgiMain() {
  int ret;
  FILE *fp = NULL;
  static char templ[41];
  static char title[41];

  if (! (cgiFormString("templ", templ, sizeof(templ)) == cgiFormSuccess))
    int_error("Error getting >templ< from calling URL");

  if (strcmp(templ, "help") == 0) {
    snprintf(title, sizeof(title), "%s", "Help and additional Information");

    if (! (fp = fopen(HELP_TEMPL, "r")))
      int_error("Error can't open help file");
  }

  else if (strcmp(templ, "index") == 0) {
    snprintf(title, sizeof(title), "%s", "Index");

    if (! (fp = fopen(INDEX_TEMPL, "r")))
      int_error("Error can't open index file");
  }

  else if (strcmp(templ, "policy") == 0) {
    snprintf(title, sizeof(title), "%s", "CA Policy");

    if (! (fp = fopen(POLICY_TEMPL, "r")))
      int_error("Error can't open policy file");
  }

  else  {
    int_error("Error unknown template file");
  }

/* -------------------------------------------------------------------------- *
 * start the html output                                                      *
 * ---------------------------------------------------------------------------*/
  pagehead(title);

  for(;;) {
    ret = getc(fp);
    if(ret == EOF) break;
    fprintf(cgiOut, "%c", ret);
  }
  pagefoot();
  fclose(fp);
  return 0;
}
void extensiongroups_remove_save(void)
{
	int size,ret_value=0,iserror=0;
	char name[STRING_LENGTH]={"bb1"};
	//与之关联的结构定义
	struct mgtcgi_xml_http_dir_policys *httpdirpolicys = NULL;	

	cgiFormString("name",name,STRING_LENGTH);


	/******************************参数检查*****************************/
	if(strlen(name) < STRING_LITTLE_LENGTH){
		iserror = MGTCGI_PARAM_ERR;
		goto ERROR_EXIT;
	}

	get_xml_node(MGTCGI_XMLTMP, MGTCGI_TYPE_HTTP_DIR_POLICYS,(void**)&httpdirpolicys,&size);
	if ( NULL == httpdirpolicys){
		iserror = MGTCGI_READ_FILE_ERR;
		goto ERROR_EXIT;
	}

	//HTTPS_DIR策略检查
	ret_value = httpdir_policy_name_check(httpdirpolicys, name, name, 1);
	if (0 != ret_value){
		if (1 == ret_value){
			iserror = MGTCGI_USED_ERR;
			goto ERROR_EXIT;
		}
		else{
			iserror = MGTCGI_PARAM_ERR;
			goto ERROR_EXIT;

		}
	}

	/*************************释放内存,调用保存函数*************************/
	ret_value = groups_remove_save(MGTCGI_TYPE_EXTENSION_GROUP,name);

		goto FREE_EXIT;
	ERROR_EXIT:
		printf("{\"iserror\":%d,\"msg\":\"\"}",iserror);
		goto FREE_EXIT;
	FREE_EXIT:
		free_xml_node((void*)&httpdirpolicys);
		return;
}
Esempio n. 24
0
/*
 * Determine the URL to send data to.
 */
int parseURL(struct extRequest *req) {

  int return_status = 0;
  int urlLength = 0;

  if(cgiFormStringSpaceNeeded(URL_PARAM_NAME, &urlLength) == cgiFormSuccess) {
    if(urlLength > 0) {
      req->url = (char*)malloc(sizeof(char)*urlLength);
      if(cgiFormString(URL_PARAM_NAME, req->url, urlLength) == cgiFormSuccess) {
        /* Success */
        return_status = 1;
      } else {
        free(req->url);
      }
    } 
  }

  return return_status;
}
Esempio n. 25
0
int guide_module_wan(void)
{
    char action[STRING_LENGTH] = {0};
    int  ret = GUIDE_OK;

    DEBUGP("%s: begin\n", __FUNCTION__);
    
    cgiFormString("action", action, sizeof(action));
    if (strcmp(action, "list") == 0)
    {
        ret = guide_wan_show();
    }
    else
    {
        ret = GUIDE_NO_SUCH_ACTION;
    }   

    DEBUGP("%s: finish, ret = %d\n", __FUNCTION__, ret);
    return ret;
}
Esempio n. 26
0
void setFieldValue(base *self, char *field_name, int not_form, void *value,
		field_type type, field_mark mark) {
	int length = 0;
	int name_length = strlen(field_name);
	if (not_form) {
		length = strlen(value);
	} else {
		cgiFormStringSpaceNeeded(field_name, &length);
	}
	self->form_datas[self->current] = (form_data*) malloc(sizeof(form_data));
	self->form_datas[self->current]->field_type = type;
	self->form_datas[self->current]->field_mark = mark;
	self->form_datas[self->current]->field_value = (char *) malloc(
			sizeof(char) * (length + 1));
	self->form_datas[self->current]->field_value_length = length;
	//fprintf(cgiOut, "%s length %ld", field_name, strlen(field_name));
	self->form_datas[self->current]->field_name = (char *) malloc(
			sizeof(char) * (name_length + 1));
	strncpy(self->form_datas[self->current]->field_name, field_name,
			name_length + 1);
	self->form_datas[self->current]->field_name_length = name_length;
	if (not_form) {
		strcpy(self->form_datas[self->current]->field_value, value);
	} else {
		cgiFormString(field_name, self->form_datas[self->current]->field_value,
				length);
	}
	self->field_tables[self->current] = (char *) malloc(
			sizeof(char) * (strlen(field_name) + 10));
	strncpy(self->field_tables[self->current], field_name,
			strlen(field_name) + 1);
#ifdef DEBUG
	fprintf(cgiOut, " <h1>file = %s , %s = %s , origin = %s</h1>",
			__FILE__,
			self->field_tables[self->current],
			self->form_datas[self->current]->field_name,
			field_name
	);
#endif
	self->current++;
}
Esempio n. 27
0
void RadioButtons() {
	int ageChoice;
	char ageText[10];
	/* Approach #1: check for one of several valid responses. 
		Good if there are a short list of possible button values and
		you wish to enumerate them. */
	cgiFormRadio("age", ages, 4, &ageChoice, 0);

	fprintf(cgiOut, "Age of Truck: %s (method #1)<BR>\n", 
		ages[ageChoice]);

	/* Approach #2: just get the string. Good
		if the information is not critical or if you wish
		to verify it in some other way. Note that if
		the information is numeric, cgiFormInteger,
		cgiFormDouble, and related functions may be
		used instead of cgiFormString. */	
	cgiFormString("age", ageText, 10);

	fprintf(cgiOut, "Age of Truck: %s (method #2)<BR>\n", ageText);
}
Esempio n. 28
0
void send_ip_drop(void)
{
    char cmd[CMD_LENGTH] = {0};
    int ret = 0;
    char addr[17] = {0};
    FILE	*pp;

    cgiFormString("ip",addr,sizeof(addr));
    
	snprintf(cmd, sizeof(cmd), "/usr/local/sbin/nf-hipac -I GLOBALIP0 --source %s -d 0.0.0.0/0 -j DROP 2>/dev/nul\n",addr);
    snprintf(cmd,sizeof(cmd), "echo %s >> /flash/etc/check.sh", cmd);
    
	pp = popen(cmd, "r");
    if (pp == NULL)
    {
        return;
    }
    pclose(pp);
    
    return ;
}
Esempio n. 29
0
/*
 * Iterate through the passed name=value pairs
 * and construct extArg structs for each of them.
 *
 * Add them to the array of extArg structs inside
 * the req struct 
 */
int parseArguments(struct extRequest *req) {

  char **array, **arrayStep;
  if (cgiFormEntries(&array) != cgiFormSuccess) {
    return 0;
  }

  int num_args = countArguments();
  int arg_num = 0;

  req->numargs = num_args;
  /* make req->args big enough to hold all the extArg structs */
  req->args = (struct extArg **)malloc(sizeof(struct extArg)*num_args);

  arrayStep = array;
  int val_size = 0;
  char *val;
  while (*arrayStep) {

    /* If the name is not a URL, method, or callback, we need to add it */
    if(strcmp(*arrayStep, URL_PARAM_NAME) != 0 &&
       strcmp(*arrayStep, CALLBACK_PARAM_NAME) != 0) {

      /* Get the length of the passed string so our buffer is big enough. */
      cgiFormStringSpaceNeeded(*arrayStep, &val_size);
      val = (char*)malloc(sizeof(char)*val_size);
      cgiFormString(*arrayStep, val, val_size);
      req->args[arg_num++] = makeArg(*arrayStep, val);

      /* The val has been passed to makeArg, so free it */
      free(val);

    }
    arrayStep++;
  }
  cgiStringArrayFree(array);

  return 1;
}
Esempio n. 30
0
void extensions_edit_show(void)
{

	int size=0,index=0,iserror=0;
	char name[STRING_LENGTH];
	struct mgtcgi_xml_extensions *extensions = NULL;

	cgiFormString("name",name,STRING_LENGTH);
	
	if (strlen(name) < 1){
		iserror = MGTCGI_PARAM_ERR;
		goto ERROR_EXIT;
	}
	
	get_xml_node(MGTCGI_XMLTMP,MGTCGI_TYPE_EXTENSIONS,(void**)&extensions,&size);
	if ( NULL == extensions){
		iserror = MGTCGI_READ_FILE_ERR;
		goto ERROR_EXIT;
	}

	printf("{\"data\":[");
	for (index = 0; index < extensions->num ; index++){
		if (strcmp(name,extensions->pinfo[index].name) == 0){
			printf("{\"name\":\"%s\",\"comment\":\"%s\"}",\
				extensions->pinfo[index].name,extensions->pinfo[index].comment);
			break;
		}

	}
		printf("],\"iserror\":0,\"msg\":\"\"}");
		goto FREE_EXIT;
	ERROR_EXIT:
		printf("{\"iserror\":%d,\"msg\":\"\"}",iserror);
		goto FREE_EXIT;
	FREE_EXIT:
		free_xml_node((void*)&extensions);
		return;
}