Beispiel #1
0
int bbspwd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	parse_post_data();
	xml_header("bbs");
	printf("<bbspwd ");
	print_session();
	char *pw1 = getparm("pw1");
	if (*pw1 == '\0') {
		printf(" i='i'></bbspwd>");
		return 0;
	}
	printf(">", stdout);
	char *pw2 = getparm("pw2");
	char *pw3 = getparm("pw3");
	switch (set_password(pw1, pw2, pw3)) {
		case BBS_EWPSWD:
			printf("ÃÜÂë´íÎó");
			break;
		case BBS_EINVAL:
			printf("ÐÂÃÜÂ벻ƥÅä »ò ÐÂÃÜÂëÌ«¶Ì");
			break;
		default:
			break;
	}
	printf("</bbspwd>");
	return 0;
}
Beispiel #2
0
static int edit_user_file(const char *file, const char *desc, const char *submit)
{
	if (!loginok)
		return BBS_ELGNREQ;
	char buf[HOMELEN];
	sethomefile(buf, currentuser.userid, file);
	parse_post_data();
	char *text = getparm("text");
	if (*text != '\0') {
		int fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0644);
		if (fd < 0)
			return BBS_EINTNL;
		fb_flock(fd, LOCK_EX);
		safer_write(fd, text, strlen(text));
		fb_flock(fd, LOCK_UN);
		close(fd);
		xml_header("bbs");
		printf("<bbseufile ");
		print_session();
		printf(" desc='%s'></bbseufile>", desc);
	} else {
		xml_header("bbs");
		printf("<bbseufile ");
		print_session();
		printf(" desc='%s' submit='%s'>", desc, submit);
		xml_printfile(buf, stdout);
		printf("</bbseufile>");
	}
	return 0;
}
Beispiel #3
0
int bbsinfo_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	parse_post_data();
	char *type = getparm("type");
	xml_header("bbs");
	if (*type != '\0') {
		printf("<bbsinfo ");
		print_session();
		printf(">%s</bbsinfo>", check_info());
	} else {
		printf("<bbsinfo post='%d' login='******' stay='%d' "
				"since='%s' host='%s' year='%d' month='%d' "
				"day='%d' gender='%c' ", currentuser.numposts,
				currentuser.numlogins, currentuser.stay / 60,
				getdatestring(currentuser.firstlogin, DATE_XML),
				currentuser.lasthost, currentuser.birthyear,
				currentuser.birthmonth, currentuser.birthday,
				currentuser.gender);
		print_session();
		printf(" last='%s'><nick>",
				getdatestring(currentuser.lastlogin, DATE_XML));
		xml_fputs(currentuser.username, stdout);
		printf("</nick></bbsinfo>");
	}
	return 0;
}
Beispiel #4
0
int main(void)
{
	int len;
	char *lenstr,poststr[512];
	char *player_id, *server_id;
	int can_share = 1;

	init_db((char *)"127.0.0.1", 3306, (char *)"pay", (char *)"root", (char *)"123456");

	printf("Content-Type:text/html\n\n");
	lenstr=getenv("CONTENT_LENGTH");
	if(lenstr == NULL) {
		printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
		return (0);
	}
	len=atoi(lenstr) + 1;
	if (len >= 512)
		return (0);
	
	fgets(poststr,len,stdin);
	parse_post_data(poststr, len);
	server_id = get_value((char *)"server_id");
	player_id = get_value((char *)"player_id");
	if (!server_id || !player_id)
		return (0);	
	
	MYSQL_RES *res = NULL;
	MYSQL_ROW row;	
	char sql[256];

	sprintf(sql, "select last_share_time, share_times, pay_times from share where server_id = %s and player_id = %s", server_id, player_id);
	res = query(sql, 1, NULL);
	if (!res) {
		send_no_record();
		goto done;
	}
	row = fetch_row(res);
	if (!row) {
		send_no_record();
		goto done;
	}


	if (!check_can_share(row)) {
		can_share = 0;
	}

	printf("[%d, %s, %s]", can_share, row[1], row[2]);
	
done:
	if (res)
		free_query(res);
	fflush(stdout);
	close_db();		
	return 0;
}
Beispiel #5
0
int web_buy_prop(void)
{
	int item = strtol(web_get_param("item"), NULL, 10);
	if (item <= 0)
		return BBS_EINVAL;

	parse_post_data();

	switch (item) {
		case PROP_TITLE_30DAYS:
		case PROP_TITLE_90DAYS:
		case PROP_TITLE_180DAYS:
		case PROP_TITLE_1YEAR:
			return buy_title(item, web_get_param("title"));
		default:
			return BBS_EINVAL;
	}
}
Beispiel #6
0
int main(void)
{
	int len;
	char *lenstr,poststr[512];
	int open_id;
	char *key;
	
	init_db((char *)"127.0.0.1", 3306, (char *)"sanguo", (char *)"root", (char *)"123456");
	
	printf("Content-Type:text/html\n\n");
//        printf("<HTML>\n");
//        printf("<HEAD>\n<TITLE >ost Method</TITLE>\n</HEAD>\n");
//        printf("<BODY>\n");
	lenstr=getenv("CONTENT_LENGTH");
	if(lenstr == NULL) {
		printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
		return (0);
	}
	len=atoi(lenstr) + 1;
	if (len >= 512)
		return (0);
	
	fgets(poststr,len,stdin);
	parse_post_data(poststr, len);
	key = get_value((char *)"key");
	open_id = atoi(get_value((char *)"open_id"));				
	
	if (!key || open_id == 0) {
		printf("{\"result\":1,\n");
		goto done;
	}
	
	if (check_key_valid(open_id, key) == 0)
		printf("{\"result\":0,\n");
	else
		printf("{\"result\":1,\n");
//        printf("</BODY>\n");
//        printf("</HTML>\n");
done:	
	fflush(stdout);
	close_db();		
	return 0;
}
Beispiel #7
0
int bbssnd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	if (parse_post_data() < 0)
		return BBS_EINVAL;
	int bid = strtol(getparm("bid"), NULL, 10);
	struct boardheader *bp = getbcache2(bid);
	if (bp == NULL || !haspostperm(&currentuser, bp))
		return BBS_ENOBRD;
	if (bp->flag & BOARD_DIR_FLAG)
		return BBS_EINVAL;

	bool isedit = (*(getparm("e")) == '1');
	unsigned int fid;
	struct fileheader fh;
	char *f = getparm("f");
	bool reply = !(*f == '\0');
	if (reply) {
		fid = strtoul(f, NULL, 10);
		if (!bbscon_search(bp, fid, 0, &fh))
			return BBS_ENOFILE;
		if (!isedit && fh.accessed[0] & FILE_NOREPLY)
			return BBS_EPST;
		if (isedit && !chkBM(bp, &currentuser)
				&& strcmp(fh.owner, currentuser.userid))
			return BBS_EACCES;
	}

	char title[sizeof(fh.title)];
	if (!isedit) {
		strlcpy(title, getparm("title"), sizeof(title));
		printable_filter(title);
		if (*title == '\0')
			return BBS_EINVAL;
	}

// TODO: ...
#ifdef SPARC
		if(abs(time(0) - *(int*)(u_info->from+34))<6) { //modified from 36 to 34 for sparc solaris by roly 02.02.28
			*(int*)(u_info->from+34)=time(0); //modified from 36 to 34 for sparc solaris by roly 02.02.28
			return BBS_EPFREQ;
		}
		*(int*)(u_info->from+34)=time(0);//modified from 36 to 34 for sparc solaris by roly 02.02.28
#else
		if(abs(time(0) - *(int*)(u_info->from+36))<6) { //modified from 36 to 34 for sparc solaris by roly 02.02.28
			*(int*)(u_info->from+36)=time(0); //modified from 36 to 34 for sparc solaris by roly 02.02.28
			return BBS_EPFREQ;
		}
		*(int*)(u_info->from+36)=time(0);//modified from 36 to 34 for sparc solaris by roly 02.02.28
#endif

	if (isedit) {
		char file[HOMELEN];
		setbfile(file, bp->filename, fh.filename);
		if (edit_article(file, getparm("text"), mask_host(fromhost)) < 0)
			return BBS_EINTNL;
	} else {
		post_request_t pr = { .autopost = false, .crosspost = false,
			.userid = NULL, .nick = NULL, .user = &currentuser,
			.bp = bp, .title = title, .content = getparm("text"),
			.sig = strtol(getparm("sig"), NULL, 0), .ip = mask_host(fromhost),
			.o_fp = reply ? &fh : NULL, .noreply = false, .mmark = false };
		if (do_post_article(&pr) < 0)
			return BBS_EINTNL;
	}

	if (!isedit && !junkboard(bp)) {
		currentuser.numposts++;
		save_user_data(&currentuser);
	}

	char buf[sizeof(fh.title) + sizeof(bp->filename)];
	snprintf(buf, sizeof(buf), "%sed '%s' on %s", isedit ? "edit" : "post",
			title, bp->filename);
	report(buf, currentuser.userid);

	snprintf(buf, sizeof(buf), "doc?board=%s", bp->filename);
	http_header();
	refreshto(1, buf);
	printf("</head>\n<body>发表成功,1秒钟后自动转到<a href='%s'>版面</a>\n"
			"</body>\n</html>\n", buf);
	return 0;
}
Beispiel #8
0
int main(void)
{
        int len;
        char *lenstr,poststr[512];
		int open_id;
		time_t tm;
		int status;
		char *name;

		time(&tm);		
		
		init_db((char *)"127.0.0.1", 3306, (char *)"sanguo", (char *)"root", (char *)"123456");
		
        printf("Content-Type:text/html\n\n");
//        printf("<HTML>\n");
//        printf("<HEAD>\n<TITLE >ost Method</TITLE>\n</HEAD>\n");
//        printf("<BODY>\n");
        lenstr=getenv("CONTENT_LENGTH");
        if(lenstr == NULL) {
                printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
				return (0);
		}
		len=atoi(lenstr) + 1;
		if (len >= 512)
			return (0);
				
		fgets(poststr,len,stdin);
		parse_post_data(poststr, len);
		name = get_value((char *)"username");		

		if (!name) {
			printf("{\"result\":1,\n");
			printf("\"openid\":\"\",\n");
			printf("\"key\":\"\",\n");
			printf("\"timestamp\":\"\",\n");
			printf("\"username\":\"\",\n");
			printf("\"password\":\"\",\n");
			printf("\"guest\":\"\",\n");
			printf("\"msg\":\"\"}\n");
			goto done;		
		}

		time(&tm);

		open_id = query_open_id_and_status(name, &status);
		if (open_id > 0)
			printf("{\"result\":0,\n");
		else
			printf("{\"result\":1,\n");
		printf("\"openid\":\"%d\",\n", open_id);
//		printf("\"key\":\"e130773fc8b6be8b60119ca2d02b9af3\",\n");
		tm += open_id;
		
		printf("\"key\":\"%c%c%c%c%c%c%c%c\",\n", key_char[tm & 0xf], key_char[(tm >> 4) & 0xf],
			key_char[(tm >> 8) & 0xf], key_char[(tm >> 12) & 0xf], key_char[(tm >> 16) & 0xf],
			key_char[(tm >> 20) & 0xf], key_char[(tm >> 24) & 0xf], key_char[(tm >> 28) & 0xf]);
		
		printf("\"timestamp\":\"1356616013\",\n");
		printf("\"username\":\"%s\",\n", name);
		printf("\"password\":\"123456\",\n");
		printf("\"guest\":\"%d\",\n", status);
		printf("\"msg\":\"\"}\n");

//        printf("</BODY>\n");
//        printf("</HTML>\n");
done:	
		fflush(stdout);
		close_db();		
		return 0;
}
Beispiel #9
0
int bbslogin_main(void)
{
	char fname[STRLEN];
	char buf[256], id[IDLEN + 1], pw[PASSLEN];
	struct userec user;

	if (parse_post_data() < 0)
		return BBS_EINVAL;
	strlcpy(id, getparm("id"), sizeof(id));
	if (*id == '\0')
		return login_screen();
	strlcpy(pw, getparm("pw"), sizeof(pw));
	if (loginok && !strcasecmp(id, currentuser.userid)) {
		const char *ref = get_login_referer();
		printf("Location: %s\n\n", ref);
		return 0;
	}
	if (getuserec(id, &user) == 0)
		return BBS_ENOUSR;

	user.numlogins++;
	if (strcasecmp(id, "guest")) {
		int total;
		time_t stay, recent, now, t;
		if (!checkpasswd(user.passwd, pw)) {
			sprintf(buf, "%-12.12s %s @%s\n", user.userid,
					getdatestring(time(NULL), DATE_ZH), fromhost);
			sethomefile(fname, user.userid, "logins.bad"); 
			file_append(fname, buf);
			file_append("logins.bad", buf);
			return BBS_EWPSWD;
		}

		total = check_multi(&user);
		if (!HAS_PERM2(PERM_SYSOPS, &user) && total >= 2)
			return BBS_ELGNQE;

		if (!HAS_PERM2(PERM_LOGIN, &user))
			return BBS_EACCES;

		now = time(NULL);
		// Do not count frequent logins.
		if (now - user.lastlogin < 20 * 60
				&& user.numlogins >= 100)
			user.numlogins--;
		if (total > 1) {
			recent = user.lastlogout;
			if (user.lastlogin > recent)
				recent = user.lastlogin;
			stay = now - recent;
			if (stay < 0)
				stay = 0;
		} else {
			stay = 0;
		}
		t = user.lastlogin;
		user.lastlogin = now;
		user.stay += stay;
#ifdef CHECK_FREQUENTLOGIN
		if (!HAS_PERM(PERM_SYSOPS)
				&& abs(t - time(NULL)) < 10) {
			report("Too Frequent", user.userid);
			return BBS_ELFREQ;
		}
#endif
		strlcpy(user.lasthost, fromhost, sizeof(user.lasthost));
		save_user_data(&user);
		currentuser = user;
	}

	log_usies("ENTER", fromhost, &user);
	if (!loginok && strcasecmp(id, "guest"))
		wwwlogin(&user, getparm("ref"));
	return 0;
}
Beispiel #10
0
/***************************************************************************
 * Function Name: cfe_web_bg_process
 * Description  : This function processes an HTTP request on a socket.
 * Returns      : None.
 ***************************************************************************/
static void cfe_web_bg_process(PSOCKET_INFO si)
{
    char post_subst[] = {UPLOAD_FATAL, '\0'};
    char *post_substs[] = {post_subst};
    int close_tcp = 0;

    switch( si->state )
    {
    case HTTP_READ_FIRST_HDR:
        if( read_first_hdr( si->s, si->web_first_buf,
            sizeof(si->web_first_buf), &si->web_buf_idx, &close_tcp ) == 0 )
        {
            /* Not all of the first header has been read yet. Try again later.*/
            break;
        }

        /* The first header has been read. */
        si->state = HTTP_READ_REMAINING_HDRS;

        /* fall thru */

    case HTTP_READ_REMAINING_HDRS:
        if( read_remaining_hdrs( si->s, si->web_buf, sizeof(si->web_buf),
            &si->web_buf_idx, &close_tcp, &si->post_content_length ) )
        {
            if( g_processing_cmd == 0 )
            {
                char *method = NULL;
                char *path = NULL;
                char *ptr = (char *) si->web_first_buf;

                method = gettoken(&ptr);
                if( method )
                    path = gettoken(&ptr);

                /* Process the HTTP request. Only GET and POST are supported. */
                if( method && path )
                {
                    if( !strcmpi( method, "get" ) )
                    {
                        send_page( si->s, path, 1, NULL, 0 );
                        close_tcp = 1;
                    }
                    else
                    {
                        if( !strcmpi( method, "post" ) )
                        {
                            if( g_post_data_in_progress == 0 )
                            {
                                g_post_data_in_progress = 1;
                                si->state = HTTP_READ_POST_DATA;
                            }
                            else
                            {
                                send_error( si->s, 501, "Upload Busy",
                                    (char*) 0,
                                    "An image is already being uploaded." );
                                close_tcp = 1;
                            }
                        }
                        else
                        {
                            send_error( si->s, 501, "Not Implemented",
                                (char*) 0,
                                "That method is not implemented." );
                            close_tcp  = 1;
                        }
                    }
                }
                else
                {
                    send_error( si->s, 400, "Bad Request", (char *) 0,
                        "Can't parse request." );
                    close_tcp  = 1;
                }
            }
            else
            {
                /* A download and flash image command is being executed from
                 * the serial port console.
                 */
                send_error( si->s, 400, "Bad Request", (char *) 0,
                    "Console command is in progress." );
                close_tcp  = 1;
            }
        }

        if( si->state != HTTP_READ_POST_DATA )
            break;

    case HTTP_READ_POST_DATA:
        /* Read the post data, which contains an image to flash, into low
         * memory.
         */
        if( (post_subst[0] = read_post_data( si->s, POST_DATA_START,
            si->post_content_length, &g_post_data_idx )) == UPLOAD_OK )
        {
            /* Verify that the post data is a valid image to flash. */
            post_subst[0] = parse_post_data( si->s, POST_DATA_START,
                g_post_data_idx, (unsigned char **) &g_image_start, &g_image_len,
                &g_image_format );
        }

        switch( post_subst[0] )
        {
        case UPLOAD_PENDING:
            break;

        case UPLOAD_TCP_ERROR:
            close_tcp = 1;
            g_post_data_in_progress = 0;
            g_post_data_idx = 0;
            break;

        case UPLOAD_OK:
            /* Notify foreground to abort the console input so it can
             * write the image to flash memory.
             */
            g_console_abort = 1;

            send_page(si->s, "/uploadinfo.html", 0, post_substs, 1);
            close_tcp = 1;
            g_post_data_idx = 0;
            break;

        default:
            /* The image was downloaded OK but there was a problem with it
             * so it could not be written to flash memory.
             */
            send_page(si->s, "/uploadinfo.html", 0, post_substs, 1);
            close_tcp = 1;
            g_post_data_in_progress = 0;
            g_post_data_idx = 0;
            break;
        }
        break;
    }

    /* Close the socket if the HTTP transaction is done. */
    if( close_tcp )
    {
        POLL();
        tcp_close(si->s);
        si->s = SOCKET_CLOSED;
        si->state = HTTP_READ_FIRST_HDR;
        si->web_buf_idx = 0;
        si->post_content_length = 0;
    }
} /* cfe_web_poll */
Beispiel #11
0
int main(int argc, char *argv[])
{
        int len;
        char *lenstr,poststr[512];
		int server_id;
		int player_id;
		char *content;

		const int page_size = 20;  //每页20条
		int total_page;   //页数
		int cur_page;    //请求的页数
		int total_count;   //总共的记录数
		int start_pos = 0;

		server_id = atoi(basename(argv[0]));
/*
		len = 0;
		for (;;) {
			if (len != 0)
				break;
			else
				sleep(1);
		}
*/
		init_db((char *)"127.0.0.1", 3306, (char *)"sanguo", (char *)"root", (char *)"123456");

        printf("Content-Type:text/html\n\n");
        lenstr=getenv("CONTENT_LENGTH");
        if(lenstr == NULL) {
                printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
				return (0);
		}
		len=atoi(lenstr) + 1;
		if (len >= 512)
			return (0);

		fgets(poststr,len,stdin);
		parse_post_data(poststr, len);
		player_id = atoi(get_value((char *)"userid"));
		cur_page = atoi(get_value((char *)"page")) - 1;

		if (cur_page < 0)
			cur_page = 0;
		start_pos = cur_page * page_size;

//		server_id = 15;
//		player_id = 36;
		char sql[512];
		MYSQL_RES *res = NULL;
		MYSQL_ROW row;	
		
		sprintf(sql, "select * from question where server_id = %d and player_id = %d", server_id, player_id);
				
		res = stored_query(sql);	

		total_count = mysql_num_rows(res);
		total_page = total_count / page_size + 1;

		printf("[{\"tp\":%d,\"pn\":%d}", total_page, cur_page + 1);
		
		mysql_data_seek(res, start_pos);
		for (int i = start_pos; i < total_count; ++i) {
			row = fetch_row(res);

			printf(",{\"qc\":\"%s\",\"rc\":\"%s\",\"qs\":%s,\"qt\":\"%s\",\"rt\":\"%s\",\"rn\":\"%s\",\"qtp\":%s}",
				row[2], row[6] ? row[6] : "",
				row[5], row[3],
				row[7] ? row[7] : "",
				row[8] ? row[8] : "",
				row[4]);
			
			if (!row)
				break;
		}
		printf("]");
		free_query(res);		
done:	
		fflush(stdout);
		close_db();		
		return 0;
}
Beispiel #12
0
int main(void)
{
	int len;
	char *lenstr,poststr[512];
	char *player_id, *server_id, *token;

	setenv("http_proxy", "127.0.0.1:8087", 1);
	setenv("https_proxy", "127.0.0.1:8087", 1);	

	init_db((char *)"127.0.0.1", 3306, (char *)"pay", (char *)"root", (char *)"123456");

	printf("Content-Type:text/html\n\n");
/*	
	lenstr=getenv("CONTENT_LENGTH");
	if(lenstr == NULL) {
		printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
		return (0);
	}
	len=atoi(lenstr) + 1;
	if (len >= 512)
		return (0);
	
	fgets(poststr,len,stdin);
	parse_post_data(poststr, len);

	len = 10;
	for (; len == 10;)
		sleep(2);
*/	
	lenstr = getenv("QUERY_STRING");
	if(lenstr == NULL) {
		printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
		return (0);
	}
	len = strlen(lenstr) + 1;
	parse_post_data(lenstr, len);	
	
	server_id = get_value((char *)"server_id");
	player_id = get_value((char *)"player_id");
	token = get_value((char *)"token");	
	if (!server_id || !player_id || !token)
		return (0);	

//	server_id = "15";
//	player_id = "15";
//	token = "AAACEdEose0cBAKedvUNeBVZAlpbsjUo4r2LHmR3K56gGFbJ4Gwp6PWVEp5wte4X4IdLK5YHziYabuXHCZCoXhzqmSZCKrsiZCLgOb1yjddnI2MyiZBmFK";

	g_data.server_id = server_id;
	g_data.player_id = player_id;
	g_data.times = 0;
	
	MYSQL_RES *res = NULL;
	MYSQL_ROW row;	
	char sql[256];

	sprintf(sql, "select last_share_time, share_times from share where server_id = \"%s\" and player_id = \"%s\"", server_id, player_id);
	res = query(sql, 1, NULL);
	if (!res) {
		send_facebook_share(token, share_msg[0], &g_data);
		goto done;
	}
	row = fetch_row(res);
	if (!row) {
		send_facebook_share(token, share_msg[0], &g_data);		
		goto done;
	}

	if (!check_can_share(row)) {
		send_fail();
		goto done;
	}
	g_data.times = atoi(row[1]);

	free_query(res);
	res = NULL;

	send_facebook_share(token, share_msg[g_data.times], &g_data);		

//	ret = atoi(row[0]);
	
	
done:
	if (res)
		free_query(res);
	fflush(stdout);
	close_db();		
	return 0;
}
Beispiel #13
0
int main(int argc, char *argv[])
{
        int len;
        char *lenstr,poststr[512];
		int server_id;
		int player_id;
		int type;		
		char *content;

		server_id = atoi(basename(argv[0]));
/*
		len = 0;
		for (;;) {
			if (len != 0)
				break;
			else
				sleep(1);
		}
*/
		init_db((char *)"127.0.0.1", 3306, (char *)"sanguo", (char *)"root", (char *)"123456");
		
        printf("Content-Type:text/html\n\n");
//        printf("<HTML>\n");
//        printf("<HEAD>\n<TITLE >ost Method</TITLE>\n</HEAD>\n");
//        printf("<BODY>\n");
        lenstr=getenv("CONTENT_LENGTH");
        if(lenstr == NULL) {
                printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
				return (0);
		}
		len=atoi(lenstr) + 1;
		if (len >= 512)
			return (0);

		fgets(poststr,len,stdin);
		parse_post_data(poststr, len);
//		server_id = atoi(get_value((char *)"serverid"));
		player_id = atoi(get_value((char *)"userid"));
		type = atoi(get_value((char *)"type"));
		content = get_value((char *)"question");

		char sql[512];
		char *p = sql;
		uint64_t effect = 0;
		
		len = sprintf(sql, "insert into question set question_state = 0, player_id = %d, server_id = %d, question_type = %d, question_time = now(), question_content = ", player_id, server_id, type);
		p = sql + len;
		*p++ = '\'';
		p += escape_string(p, content, strlen(content));
		*p++ = '\'';
		*p++ = '\0';		
				
		query(sql, 1, &effect);	
		if (effect != 1) {
			printf("{\"msg\":[1,\"fail\"]}");
			goto done;
		}
		printf("0");
		
//        printf("</BODY>\n");
//        printf("</HTML>\n");
done:	
		fflush(stdout);
		close_db();		
		return 0;
}
Beispiel #14
0
request::request(const int id, const std::string& r)
{
    m_error = 0;
    m_error_text = "";

    m_method = "";
    m_path = "";
    m_host = "";
    m_identifier = "";
    m_if_modified_since = 0;
    m_port = 80;

    m_request_lines = sammy::utils::split_string(r, '\n');

    if(m_request_lines.size() == 0)
    {
        m_error = 1;
        m_error_text = "Request data empty.";

        return;
    }
    
    parse_header();

    for(unsigned int i = 1; i < m_request_lines.size(); ++i)
    {
        // Find the line type of the request, to route it to the correct parse function
        const auto& current_line = m_request_lines.at(i);
        const auto colon_pos = current_line.find(": ");
        if(colon_pos == std::string::npos)
        {
            continue;
        }

        const std::string line_type = current_line.substr(0, colon_pos);
        const std::string line_data = current_line.substr(colon_pos + 2);

        if(line_type == "Host")
        {
            parse_host(line_data);

            continue;
        }

        if(line_type == "Cookie")
        {
            parse_cookies(line_data);

            continue;
        }

        if(line_type == "Referer")
        {
            parse_referer(line_data);

            continue;
        }

        if(line_type == "If-Modified-Since")
        {
            parse_if_modified_since(line_data);

            continue;
        }
    }    

    parse_post_data();
    
    if(m_method.size() == 0 || m_path.size() == 0 || m_host.size() == 0)
    {
        m_error = 1;
        m_error_text = "Method, path or host empty.";

        return;
    }

    m_identifier = sammy::utils::sha256(std::to_string(id));
}
Beispiel #15
0
// TODO: Handle user-defined directories.
static int read_submit(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	if (parse_post_data() < 0)
		return BBS_EINVAL;

	// Read parameters.
	bool boards[MAXBOARD] = {0};
	int num = 0;
	for (int i = 0; i < param_num; i++) {
		if (!strcasecmp(param_val[i], "on")) {
			int bid = strtol(param_name[i], NULL, 10);
			if (bid > 0 && bid <= MAXBOARD
					&& hasreadperm(&currentuser, bcache + bid - 1)) {
				boards[bid - 1] = true;
				++num;
			}
		}
	}
	if (num > GOOD_BRC_NUM)
		return BBS_EBRDQE;
	if (num <= 0)
		return BBS_EINVAL;

	// Read '.goodbrd'.
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, ".goodbrd");
	mmap_t m;
	m.oflag = O_RDWR;
	if (mmap_open(file, &m) < 0)
		return BBS_ENOFILE; // TODO: empty?
	if (mmap_truncate(&m, num * sizeof(struct goodbrdheader)) < 0) {
		return BBS_EINTNL;
	}
	struct goodbrdheader *iter, *end;
	end = (struct goodbrdheader *)m.ptr + num;

	// Remove deselected boards.
	struct goodbrdheader *dst = m.ptr;
	int id = 0;
	for (iter = m.ptr; iter != end; ++iter) {
		if (boards[iter->pos] == true) {
			boards[iter->pos] = false;
			id++;
			if (iter != dst) {
				iter->id = id;
				iter->pid = 0;
				*dst = *iter;
			}
			++dst;
		}
	}

	// Write out newly selected boards.
	for (int i = 0; i < MAXBOARD; ++i) {
		if (boards[i] == true) {
			id++;
			if (id > GOOD_BRC_NUM)
				break;
			dst->id = num;
			dst->pid = 0;
			dst->pos = i;
			dst->flag = bcache[i].flag;
			strlcpy(dst->filename, bcache[i].filename, sizeof(dst->filename));
			strlcpy(dst->title, bcache[i].title, sizeof(dst->title));
			++dst;
		}
	}
	mmap_close(&m);
	xml_header("bbs");
	printf("<bbsmybrd ");
	print_session();
	printf(" limit='%d' selected='%d'></bbsmybrd>", GOOD_BRC_NUM, num);
	return 0;
}
Beispiel #16
0
int main(void)
{
	int len;
	char *lenstr,poststr[512];
	char *player_id, *server_id, *pay_id;
	int n_pay_id;
	int n_pay_times;
	int can_share = 1;
	uint64_t effect = 0;
	MYSQL_RES *res = NULL;
	MYSQL_ROW row;	
	char sql[256];
/*
	len = 10;
	for (;;) {
		if (len != 10)
			break;
		sleep(2);
	}
*/
	
	init_db((char *)"127.0.0.1", 3306, (char *)"pay", (char *)"root", (char *)"123456");

	printf("Content-Type:text/html\n\n");
	lenstr=getenv("CONTENT_LENGTH");
	if(lenstr == NULL) {
		printf("<DIV STYLE=\"COLOR:RED\">Errorarameters should be entered!</DIV>\n");
		return (0);
	}
	len=atoi(lenstr) + 1;
	if (len >= 512)
		return (0);
	
	fgets(poststr,len,stdin);
	parse_post_data(poststr, len);
	server_id = get_value((char *)"server_id");
	player_id = get_value((char *)"player_id");
	pay_id = get_value((char *)"pay_id");	
	if (!server_id || !player_id || !pay_id)
		return (0);	


	sprintf(sql, "select share_times, pay_times from share where server_id = %s and player_id = %s", server_id, player_id);
	res = query(sql, 1, NULL);
	if (!res) {
		send_fail();
		goto done;
	}
	row = fetch_row(res);
	if (!row) {
		send_fail();
		goto done;
	}

	n_pay_id = atoi(pay_id);
	if (!check_can_get_share_pay(row, n_pay_id)) {
		send_fail();
		goto done;
	}

	n_pay_times = atoi(row[1]);
	n_pay_times |= (1 << n_pay_id);

	free_query(res);
	res = NULL;
	
	sprintf(sql, "update `share` set `pay_times` = %d where `server_id` = %s and `player_id` = %s",
		n_pay_times, server_id, player_id);
	
	query(sql, 1, &effect);

	if (effect != 1) {
		send_fail();
		goto done;
	}
	
	send_success(n_pay_id);
	send_charge_gold_req(atoi(player_id), get_gold[n_pay_id], 0, (char *)"share reward", (char *)"127.0.0.1", (char *)"3008");
	
done:
	if (res)
		free_query(res);
	fflush(stdout);
	close_db();		
	return 0;
}