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;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	int     uid;
	set_max_load(argv[0]);

	uid = getuid();

	if (uid == BBSUID)
	{	/* bbs uid */

#ifdef USE_UTMP
		struct utmp *whee;
#endif
#ifdef USE_UTMPX

		struct utmpx *whee;
#endif

		char    hid[17];
		/* load control for BBS */
		/*#ifdef LOAD_LIMIT */
		{
			double  cpu_load[3];
			int     load;
			get_load(cpu_load);
			load = cpu_load[0];
			printf("BBS ×î½ü (1,10,15) ·ÖÖÓµÄƽ¾ù¸ººÉ·Ö±ðΪ %.2f, %.2f, %.2f (Ä¿Ç°ÉÏÏÞ = %d).\n\n",
			       cpu_load[0], cpu_load[1], cpu_load[2], max_load);

			if (load < 0 || load > max_load)
			{
				printf("ºÜ±§Ç¸,Ŀǰϵͳ¸ººÉ¹ýÖØ, ÇëÉÔááÔÙÀ´\n");
				sleep(load);
				exit(-1);
			}
		}
		/*#endif*/
		/* ppfoong */
		{
			char    buf[256];
			FILE   *fp;
			if ((fp = fopen("NOLOGIN", "r")) != NULL)
			{
				while (fgets(buf, 256, fp) != NULL)
					printf(buf);
				fclose(fp);
				sleep(3);
				exit(-1);
			}
		}
		RF_DEBUG("Before invis....");
		whee = invis();

		RF_DEBUG("Before Chroot....");

#ifdef BBSRF_CHROOT

		sprintf(bbs_prog_path, "/bin/bbs", BBSHOME);
		if (chroot(BBSHOME) != 0)
		{
			printf("Cannot chroot, exit!\n");
			exit(-1);
		}
#else
		sprintf(bbs_prog_path, "%s/bin/bbs", BBSHOME);
#endif

		RF_DEBUG("Before setuid....");
		setuid(uid);

		if (whee)
		{
			char    ttybuf[16];
			char   *tp;
			RF_DEBUG("Before ttyname (whee)....");
			tp = ttyname(0);
			strcpy(ttybuf, (tp == NULL) ? "/dev/ttyp0" : tp);

			if (whee->ut_host[0])
				strncpy(hid, whee->ut_host, 16);
			else
#ifdef SYSV

			{
				struct utsname name;
				if (uname(&name) >= 0)
					strcpy(hid, name.nodename);
				else
					strcpy(hid, "localhost");
			}
#else
				gethostname(hid, 16);
#endif

			hid[16] = '\0';

			if (check_ban_site(hid))
				exit(-1);
			RF_DEBUG("Before execl (whee)....");

			execl(bbs_prog_path, "bbs", "h", hid, ttybuf, NULL);
		}
		else
		{
			RF_DEBUG("Before execl (not whee)....");
			execl(bbs_prog_path, "bbs", "h", "unknown", "notty", NULL);
		}

		printf("execl failed\n");
		exit(-1);
	}
	setuid(uid);
	printf("UID DOES NOT MATCH\n");
	exit(-1);
	return -1;
}