Пример #1
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;
}
Пример #2
0
int control_process() {
	char* buffer = NULL;

	// 检查用户是否按下了按钮
	if (cgiFormSubmitClicked("led1") == cgiFormSuccess) {
		// 调用 led 1 控制代码
		control_led(0);
	} else if (cgiFormSubmitClicked("led2") == cgiFormSuccess) {
		// 调用 led 2 控制代码
		control_led(1);
	} else if (cgiFormSubmitClicked("logout") == cgiFormSuccess) {
		// 退出登录
		session_destroy();
		cgiHeaderLocation(cgiScriptName);
		return 0;
	}

	// 输出 ContentType header
	// 作为 CGI 程序必须输出这个 header,否则会导致 500 错误
	fprintf(cgiOut, "Pragma: no-cache\n");
	cgiHeaderContentType("text/html");

	buffer = read_template(g_control_template);
	if (buffer == NULL) {
		fprintf(cgiOut, "Warning: Can't read template file: %s.<br />\n",
				g_control_template);
		return -1;
	}

	fprintf(cgiOut, "%s", buffer);
	free(buffer);

	return 0;
}
Пример #3
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;
}
Пример #4
0
/*
 * api:	http://192.168.1.227/cgi-bin/rest/network/CallUploadDataProgram.cgi?datatype=1
 * */
int cgiMain()
{
	cgiFormResultType cgi_re;
	int res=0;
	int datatype;
	char cmdstring[100] = {0};

	cgiHeaderContentType("application/json"); //MIME
	cgi_re = cgiFormInteger("datatype", &datatype, -1);

	if(datatype ==-1)
		snprintf(cmdstring, sizeof(cmdstring), "%s", "/gl/bin/BaseDataUpload");
	else
		snprintf(cmdstring, sizeof(cmdstring), "%s %d", "/gl/bin/BaseDataUpload", datatype);

    fflush(stdout);
    pid_t	pid;
	if ((pid = fork()) > 0) {						//parent process
	}
	else
	{												//child process
		//重定向输入输出流
		freopen("/dev/null", "r", stdin);
		freopen("/dev/null", "w", stdout);
		freopen("/dev/null", "w", stderr);
		system(cmdstring);
		exit(0);
	}
	res =0;
	api_response(res, datatype, cmdstring);
	return 0;
}
Пример #5
0
int cgiMain() {
#ifdef DEBUG
    LoadEnvironment();
#endif /* DEBUG */
    /* Load a previously saved CGI scenario if that button
    	has been pressed. */
    if (cgiFormSubmitClicked("loadenvironment") == cgiFormSuccess) {
        LoadEnvironment();
    }
    /* Set any new cookie requested. Must be done *before*
    	outputting the content type. */
    CookieSet();
    /* Send the content type, letting the browser know this is HTML */
    cgiHeaderContentType("text/html");
    /* Top of the page */
    fprintf(cgiOut, "<HTML><HEAD>\n");
    fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
    fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");
    /* If a submit button has already been clicked, act on the
    	submission of the form. */
    if ((cgiFormSubmitClicked("testcgic") == cgiFormSuccess) ||
            cgiFormSubmitClicked("saveenvironment") == cgiFormSuccess)
    {
        HandleSubmit();
        fprintf(cgiOut, "<hr>\n");
    }
    /* Now show the form */
    ShowForm();
    /* Finish up the page */
    fprintf(cgiOut, "</BODY></HTML>\n");
    return 0;
}
Пример #6
0
void htmlHeader(char *title) {
  cgiHeaderContentType("text/html");
  fprintf(cgiOut,"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'> \r\n");
  fprintf(cgiOut,"<html><head>\r\n");
  fprintf(cgiOut,"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\r\n\r\n");
  fprintf(cgiOut,"<TITLE>%s</TITLE></HEAD>",title);
}
Пример #7
0
Файл: test.c Проект: xinzou/cweb
int cgiMain() {
	cgiHeaderContentType("text/html;charset=gbk");
	int n, f;
	char txt1[32], txt2[32];
	TMPL_varlist *mainlist, *vl;
	TMPL_loop *loop;
	TMPL_loop *persons;
	loop = 0;
	f = 1;
	for (n = 1; n < 11; n++) {
		sprintf(txt1, "%d", n);
		sprintf(txt2, "%d", f *= n);
		vl = TMPL_add_var(0, "n", txt1, "nfact", txt2, 0);
		loop = TMPL_add_varlist(loop, vl);
	}

	for (n = 10; n < 21; n++) {
		sprintf(txt1, "%d", n);
		sprintf(txt2, "%d", f *= n);
		vl = TMPL_add_var(0, "n1", txt1, "nfact1", txt2, "aa", "mmmm", 0);
		persons = TMPL_add_varlist(persons, vl);
	}

	mainlist = TMPL_add_var(0, "title", "10 factorials", 0);
	mainlist = TMPL_add_loop(mainlist, "fact", loop);
	mainlist = TMPL_add_loop(mainlist, "person", persons);
	TMPL_write("../resource/template/p1.html", 0, 0, mainlist, stdout, stderr);
	TMPL_free_varlist(mainlist);
	return 0;
}
Пример #8
0
int cgiMain(void){
    cgiFilePtr file;
    int targetFile;
    mode_t  mode;
    char name[128];
    char fileNameOnServer[64];
    char contentType[1024];
    char buffer[BufferLen];
    char *tmpStr=NULL;
    int size;
    int got,t;
    cgiHeaderContentType("text/html");
    //取得html页面中file元素的值,应该是文件在客户机上的路径名
    if (cgiFormFileName("file", name, sizeof(name)) !=cgiFormSuccess) {
        fprintf(stderr,"could not retrieve filename\n");
        goto FAIL;
    }  
    cgiFormFileSize("file", &size);
    //取得文件类型,不过本例中并未使用
    cgiFormFileContentType("file", contentType, sizeof(contentType));
    //目前文件存在于系统临时文件夹中,通常为/tmp,通过该命令打开临时文件。临时文件的名字与用户文件的名字不同,所以不能通过路径/tmp/userfilename的方式获得文件
    if (cgiFormFileOpen("file", &file) != cgiFormSuccess) {
        fprintf(stderr,"could not open the file\n");
        goto FAIL;
    }
    t=-1; 
    //从路径名解析出用户文件名
    while(1){
        tmpStr=strstr(name+t+1,"\\");
        if(NULL==tmpStr)
            tmpStr=strstr(name+t+1,"/");//if "\\" is not path separator, try "/"
        if(NULL!=tmpStr)
            t=(int)(tmpStr-name);
        else
            break;
    } 
    strcpy(fileNameOnServer,"/app/update/");
    strcat(fileNameOnServer,name+t+1);
    mode=S_IRWXU|S_IRGRP|S_IROTH;    
    //在当前目录下建立新的文件,第一个参数实际上是路径名,此处的含义是在cgi程序所在的目录(当前目录))建立新文件    
    targetFile=open(fileNameOnServer,O_RDWR|O_CREAT|O_TRUNC|O_APPEND,mode);
    if(targetFile<0){
        fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer);
        goto FAIL;
    }
    //从系统临时文件中读出文件内容,并放到刚创建的目标文件中 
    while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){
        if(got>0)
            write(targetFile,buffer,got);    
    }
    cgiFormFileClose(file);
    close(targetFile);
    goto END; 
FAIL:
    fprintf(stderr,"Failed to upload");
    return 1;
END:    
    printf("File \"%s\" has been uploaded",fileNameOnServer);
    return 0;
}
Пример #9
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;
}
Пример #10
0
int cgiMain() {
	//cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiWriteEnvironment("./capcgi.dat");
	cgiHeaderContentType("text/html");
	fprintf(cgiOut, "<title>Captured</title>\n");
	fprintf(cgiOut, "<h1>Captured</h1>\n");
	fprintf(cgiOut, "Your form submission was captured for use in\n");
	fprintf(cgiOut, "debugging CGI code.\n");
	return 0;
}
Пример #11
0
int cgiMain(void)
{
	char *ip;
	ip = (char *) calloc(32, sizeof(char));

	//初始化
	NET_DVR_Init();

	NET_DVR_SetLogToFile(3,"./sdkLog");

	//设置链接时间与重连时间
	NET_DVR_SetConnectTime(2000,1);
	NET_DVR_SetReconnect(10000,true);

	//注册设备
	LONG lUserID;
	NET_DVR_DEVICEINFO_V30 struDevice;
	//strcpy(ip,GetIP());
	lUserID = NET_DVR_Login_V30("192.168.1.64""",8000,"admin","12345",&struDevice);
	if(lUserID < 0)
	{
		printf("Login in ERROR:%d\n",NET_DVR_GetLastError());
		NET_DVR_Cleanup();
		return 1;
	}
	printf("login success!\n");
	free(ip);
	
	cgiHeaderContentType("Text/html");
	//while(1){
		if(cgiFormSubmitClicked("reboot") == cgiFormSuccess)
		{
			TestRebootDVR(lUserID);
		}

		if(cgiFormSubmitClicked("Alarm") == cgiFormSuccess)
		{
			if(Demo_Alarm() == HPR_ERROR)
				goto EXIT;
		}
		
		if(cgiFormSubmitClicked("record") == cgiFormSuccess)
		{
			if(record() == HPR_ERROR)
				goto EXIT;
		}
	//}
	
EXIT:
	NET_DVR_Logout_V30(lUserID);
	NET_DVR_Cleanup();

	return 0;
}
Пример #12
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;
}
Пример #13
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;
}
Пример #14
0
int cgiMain() {
	cgiHeaderContentType("text/html;charset=gbk");
	user *user1 = lw_new(user_klass);
	user_set_username(user1, "macro chen");
	user_set_pwd(user1, "111111");
	user_set_salt(user1, "aabbcc");
	fprintf(cgiOut, "%s , %s , %s \n", user_get_username(user1),
			user_get_pwd(user1), user_get_salt(user1));
	lw_destory(user1);
	return 0;
}
Пример #15
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;
}
Пример #16
0
int cgiMain()
{
	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html");
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>Robot SetName</TITLE></HEAD>\n");
         
	if ((cgiFormSubmitClicked("send") == cgiFormSuccess)) {
            handlePlainText();
	}

	fprintf(cgiOut, "</BODY></HTML>\n");
	return 0;
}
Пример #17
0
void LoadEnvironment()
{
    if (cgiReadEnvironment(SAVED_ENVIRONMENT) !=
            cgiEnvironmentSuccess)
    {
        cgiHeaderContentType("text/html");
        fprintf(cgiOut, "<head>Error</head>\n");
        fprintf(cgiOut, "<body><h1>Error</h1>\n");
        fprintf(cgiOut, "cgiReadEnvironment failed. Most "
                "likely you have not saved an environment "
                "yet.\n");
        exit(0);
    }
    /* OK, return now and show the results of the saved environment */
}
Пример #18
0
int doPostReq(struct extRequest *req) {

  cgiHeaderContentType("text/json");

  CURL *curl;
  CURLcode res;

  struct curl_httppost *formpost=NULL;
  struct curl_httppost *lastptr=NULL;

  curl_global_init(CURL_GLOBAL_ALL);

  int i;
  for(i = 0; i < req->numargs; i++) {
    curl_formadd(&formpost,
                 &lastptr,
                 CURLFORM_COPYNAME, req->args[i]->argName,
                 CURLFORM_COPYCONTENTS, req->args[i]->argVal,
                 CURLFORM_END);
  }

  curl = curl_easy_init();

  if(curl) {

    curl_easy_setopt(curl, CURLOPT_URL, req->url);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);

    if(req->callback != NULL) {
      fprintf(cgiOut, "%s(", req->callback);
    }

    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    curl_formfree(formpost);

    if(req->callback != NULL) {
      fprintf(cgiOut, ");");
    }

    return 1;

  } else {

    return 0;
  }
}
Пример #19
0
void pagehead(char* title, char *session, FILE *out) {

  char res_page[81] = "";
  if(out == NULL) out = cgiOut;

/* -------------------------------------------------------------------------- *
 * start the head output                                                      *
 * ---------------------------------------------------------------------------*/

  if(out == cgiOut) cgiHeaderContentType("text/html; charset=UTF-8");
  fprintf(out, "<html>\n");
  fprintf(out, "<head>\n");
  fprintf(out, "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/style.css\" media=\"screen\" />\n");

  if(session != NULL && out == cgiOut) {
    /* here goes the html redirect code to point to the results file */
    snprintf(res_page, sizeof(res_page), "session-%s.htm", session);
    fprintf(out, "<meta http-equiv=\"refresh\"");
    fprintf(out, "content=\"1; url=%s/%s\">\n", RESULTS_DIR, res_page);
  }

  fprintf(out, "<meta name=\"Title\" content=\"INOVASC - %s\" />\n", title);
  fprintf(out, "<meta name=\"Description\" content=\"INOVASC - OpenVAS security scanner web client\" />\n");
  fprintf(out, "<meta name=\"Keywords\" content=\"OpenVAS, vulnerability assessment, scanner, audit, compliance\" />\n");
  fprintf(out, "<title>INOVASC - %s</title>\n", title);
  fprintf(out, "</head>\n");

  fprintf(out, "<body>\n");
  fprintf(out, "<div id=\"wrapper\">\n");
  fprintf(out, "<div id=\"banner\">\n");
  fprintf(out, "<h1>INOVASC - %s</h1>\n", title);
  fprintf(out, "<h2>Web-based System Vulnerability Assessment with OpenVAS</h2>\n");
  fprintf(out, "</div>\n");

  fprintf(out, "<div id=\"vmenu\">\n");
  fprintf(out, "<ul>\n");
  fprintf(out, "<li><a href=\"%s\" class=\"selected\"><span>Home</span></a></li>\n", HOMELINK);
  fprintf(out, "<li><a href=\"%s/cgi-bin/scantemplates.cgi\"><span>Scan Templates</span></a></li>\n", HOMELINK);
  fprintf(out, "<li><a href=\"%s/cgi-bin/scanlogin.cgi\"><span>Direct Scan</span></a></li>\n", HOMELINK);
  fprintf(out, "<li><a href=\"%s/cgi-bin/scanresults.cgi\"><span>List existing Results</span></a></li>\n", HOMELINK);
  fprintf(out, "<li><a href=\"%s/cgi-bin/help.cgi\"><span>Help</span></a></li>\n", HOMELINK);
  fprintf(out, "<li><a href=\"%s/cgi-bin/about.cgi\"><span>About</span></a></li>\n", HOMELINK);
  fprintf(out, "</ul>\n");
  fprintf(out, "</div>\n");

  fprintf(out, "<div id=\"content\">\n");
}
Пример #20
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;
}
Пример #21
0
int cgiMain() 
{
	afreshOrient("cgi.txt", "a", stdout); //test
	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html");

	/* If a submit button has already been clicked, act on the 
		submission of the form. */
	if (cgiFormSubmitClicked("uploadSubmit") == cgiFormSuccess) {
		if(UiReturn(UploadFile()) != SUCCESS)
			exit(EFAILED);
	} else if (cgiFormSubmitClicked("rebootSubmit") == cgiFormSuccess) {
		my_reboot();
	}

	exit(SUCCESS);
}
Пример #22
0
int cgiMain() {
	int sensor_num,sensor_idx;
	int i,j,k;
	char name[81];
	light_sensor *p_sensor ;

	cgiFormInteger("sensor_num", &sensor_num, 0);
	
	if(sensor_num > 100) sensor_num = 100;

	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	if(0 == sensor_num)
	{
		fprintf(cgiOut, "<p>数据出错,退出!!</p>\n");
		OutBodyEnd();	
		return 0;
	}
	else
	{
		pwsw_h.sensor_num= sensor_num;

		for(i=0;i<sensor_num;i++)
		{
			p_sensor = &pwsw_h.sensor[i];
			p_sensor->lux = get_lux(i+1);
			p_sensor->voltage = get_voltage(i+1);
		}
	}

	save_to_xml_file();
	fprintf(cgiOut, "<p>保存成功,请返回!</p>\n");
	fprintf(cgiOut, "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n");

	OutBodyEnd();

	return 0;
}
Пример #23
0
int cgiMain() 
{


	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html;charset=gb2312");
	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>NC600 Web Server</TITLE>\n");
	print_css();
	print_backgrounf();
	fprintf(cgiOut,	"</HEAD><BODY>\n");
	get_user(name, passwd);

	if(cgiFormSubmitClicked("host") == cgiFormSuccess)
	{
		char o_name[16]="", o_passwd[16]="", n_name[16]="", n_passwd[16]="", nck_passwd[16]="";
		getformstrchar("name", o_name, 16);
		getformstrchar("passwd", o_passwd, 16);
		getformstrchar("n_name", n_name, 16);
		getformstrchar("n_passwd", n_passwd, 16);
		getformstrchar("nck_passwd", nck_passwd, 16);
		printf("[%s]\t[%s]\t[%s]\t[%s]\t[%s]\n", o_name, o_passwd, n_name, n_passwd, nck_passwd);		
		printf("[%s]\t[%s]\t[%s]\n", name, passwd, (char*)crypt(o_passwd, "NC600"));
		if((strcmp(name, o_name) == 0) && (strcmp(passwd, (char*)crypt(o_passwd, "NC600")) == 0) && (strcmp(n_passwd, nck_passwd) == 0))
		{
				set_user(n_name, n_passwd);		
				get_user(name, passwd);
				fprintf(cgiOut, "<script type=\"text/javascript\">\n");
				fprintf(cgiOut, "window.alert(\"口令修改成功!\");\n");
				fprintf(cgiOut, "</script>\n");
		}
		else
		{
				fprintf(cgiOut, "<script type=\"text/javascript\">\n");
				fprintf(cgiOut, "window.alert(\"口令修改失败!\");\n");
				fprintf(cgiOut, "</script>\n");
		}

	}
	ShowForm();
	fprintf(cgiOut, "</BODY></HTML>\n");
	
	return 0;
}
Пример #24
0
void gen_page(const char * fname) {
    if (fname == NULL) return;

    static const char *src_path = "/www/sysuh3c-cgi";
    char fullpath[128] = {0};
    snprintf(fullpath, sizeof(fullpath), "%s/%s", src_path, fname);

    FILE * fp = fopen(fullpath, "r");
    if (fp == NULL) return;

    char buf[256] = {0};
    cgiHeaderContentType("text/html");
    while (fgets(buf, sizeof(buf), fp)) {
        fprintf(cgiOut, "%s", buf);
    }

    fclose(fp);
}
Пример #25
0
 int cgiMain()
{
	 char *filename = "ip_config.conf";
	 char ip[16];
	 unsigned short portt = 8887;
	 int fd;
	 int readnd = 0;
	 char buffer[512];
	 getip(filename, ip);
	 fd = tcp_init_client(ip, portt);


	 int passed, conditioner, mode;
	 struct replay_packet * replay;

	 struct common_packet request;

	 request.head.len = sizeof(request.data);
	 request.head.encrpyt = ENCRPYT_NO;

	 request.head.ki = KI_AIRCONDITIONER;

	 cgiHeaderContentType("text/html");
	 cgiFormInteger("conditioner", &conditioner, 0);
	 cgiFormInteger("mode", &mode, 0);
	 cgiFormInteger("passed", &passed, 0);
	 request.head.ttl = conditioner;
	 request.head.mo = mode;
	 request.head.extent = passed;

	 writen(fd, (void *)&request, sizeof(struct register_struct));
	 readnd = readn(fd, (void *)buffer, sizeof(struct replay_packet));
	 replay = (struct replay_packet *)buffer;

	 if (readnd == sizeof(struct replay_packet)) {
	 	if (replay->head.ki == KI_REPLAY) {
	 			fprintf(cgiOut, "conditioner=%d;statuss=%d", conditioner, replay->data);
	 	}
	 }
	 tcp_close(fd);
	 return 0;
}
Пример #26
0
int cgiMain()
{
	linkage_base_st *base_all_list;
	int total_num =0;
	int res=0;

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

	res = db_init();
	if(res<0){
		goto all_over;
	}
	res = get_linkage_base_all_list_db(&base_all_list, &total_num);
	if(res<0){
		goto all_over;
	}
all_over:
	db_close();
    api_response(res, total_num, base_all_list);
	return 0;
}
Пример #27
0
//        { 'robot' = [ {'name' : 'Bruce'}  ] }
int cgiMain()
{
	char name[128];
        int rtn;

	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html");
//	fprintf(cgiOut, "<HTML><HEAD>\n");
//	fprintf(cgiOut, "<TITLE>Robot GetName</TITLE></HEAD>\n");

	memset(name, '\0', sizeof(name));
	rtn = getName(name);
	if (rtn == 0) {
                char str[128];
                sprintf(str, "{\"name\":\"%s\"}", name);
	        fprintf(cgiOut, "%s", str);
	        //fprintf(cgiOut, "<BODY><H1>Name: %s</H1>\n", name);
        }
	//fprintf(cgiOut, "</BODY></HTML>\n");
	return 0;
}
Пример #28
0
int cgiMain() {
#if DEBUG
	/* Load a saved CGI scenario if we're debugging */
	cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");
#endif
	cgiHeaderContentType("text/html");
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");
	Name();
	Address();
	Hungry();
	Temperature();
	Frogs();
	Color();
	Flavors();
	NonExButtons();
	RadioButtons();
	fprintf(cgiOut, "</BODY></HTML>\n");
	return 0;
}
Пример #29
0
void pagehead(char* title) {
   cgiHeaderContentType("text/html; charset=UTF-8");
   fprintf(cgiOut, "<!DOCTYPE html>");
   fprintf(cgiOut, "<html>\n");
   fprintf(cgiOut, "<head>\n");
   fprintf(cgiOut, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n");
   fprintf(cgiOut, "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/style.css\" />\n");
   fprintf(cgiOut, "<meta name=\"Title\" content=\"WebCert - %s\" />\n", title);
   fprintf(cgiOut, "<meta name=\"Description\" content=\"WebCert Digital Certificate Management\" />\n");
   fprintf(cgiOut, "<meta name=\"Keywords\" content=\"SSL, HTTPS, TLS, certificate, x509\" />\n");
   fprintf(cgiOut, "<title>WebCert - %s</title>\n", title);
   fprintf(cgiOut, "<script src=\"../webcert.js\" type=\"text/javascript\"></script>\n");
   fprintf(cgiOut, "</head>\n");

   fprintf(cgiOut, "<body>\n");
   fprintf(cgiOut, "<div id=\"banner\">\n");
   fprintf(cgiOut, "<h1>WebCert - %s</h1>\n", title);
   fprintf(cgiOut, "<h2>Web-based Digital Certificate Management</h2>\n");
   fprintf(cgiOut, "</div>\n");

   fprintf(cgiOut, "<div id=\"vmenu\">\n");
   fprintf(cgiOut, "<ul>\n");
   fprintf(cgiOut, "<li><a href=\"showhtml.cgi?templ=index\" class=\"selected\"><span>Home</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"buildrequest.cgi\" class=\"selected\"><span>Create CSR</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"certrequest.cgi\"><span>Verify CSR</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"certstore.cgi\"><span>List Certs</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"certsearch.cgi\"><span>Search Cert</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"certvalidate.cgi\"><span>Verify Cert</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"p12convert.cgi\"><span>P12 Convert</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"keycompare.cgi\"><span>Key Check</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"getcert.cgi?cfilename=cacert.pem\"><span>CA Cert</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"showhtml.cgi?templ=help\"><span>Help</span></a></li>\n");
   fprintf(cgiOut, "<li><a href=\"showhtml.cgi?templ=policy\"><span>About</span></a></li>\n");
   fprintf(cgiOut, "</ul>\n");
   fprintf(cgiOut, "</div>\n");

   fprintf(cgiOut, "<div id=\"wrapper\">\n");
   fprintf(cgiOut, "<div id=\"content\">\n");
}
Пример #30
0
int cgiMain()
{
	char MQ2[BUF_SIZE];
	char enable[BUF_SIZE];	
	memset(MQ2,0,sizeof(MQ2));
	memset(enable,0,sizeof(enable));

    cgiHeaderContentType("text/plain");
  /* open database */ 
  	sqlite3 *db;
	int ret = sqlite3_open("data/currdev.db",&db);
	if(ret != SQLITE_OK)
	{
		fputs(sqlite3_errmsg(db),stderr);
		fputs("\n",stderr);
		exit(1);
	}
	int n = dev_getMQ2(db,MQ2,enable);

	printf("%s",MQ2,enable);
	return 0;
}