Example #1
0
/*
create table `toplog` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
 UNIQUE top (`date`,`topth`)
) TYPE=MyISAM COMMENT='toplog';
*/
int log_top()
{
	MYSQL s;
	char sqlbuf[500];
	char newtitle[161];
	int i;
	char newts[20];

	mysql_init (&s);

	if (! my_connect_mysql(&s) ){
		return 0;;
	}

	for(i=0;i<topnum;i++){
		
		mysql_escape_string(newtitle, top[i].title, strlen(top[i].title));

		sprintf(sqlbuf,"UPDATE toplog SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND topth='%d';", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, i+1);

		if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
			printf("%s\n", mysql_error(&s));
			continue;
		}
		if( (int)mysql_affected_rows(&s) <= 0 ){
			sprintf(sqlbuf, "INSERT INTO toplog VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
			if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
				printf("%s\n", mysql_error(&s));
				continue;
			}
		}
	}

	mysql_close(&s);

	return 1;
}
Example #2
0
static void writelog(struct bbs_msgbuf *msg)
{
    char header[256];
    struct tm *n;
    struct taglogconfig *pconf;
    char ch;

#if defined(NEWPOSTLOG) || defined(NEWBMLOG)
	if(!postlog_start && mysqlclosetime && time(0)-mysqlclosetime>600)
		opennewpostlog();
#endif

#ifdef NEWBMLOG
	if (msg->mtype == BBSLOG_BM){
		char sqlbuf[512];
		struct _new_bmlog * ppl = (struct _new_bmlog *)( &msg->mtext[1]) ;
		int affect;

		if(!postlog_start)
			return;

		if(ppl->value == 0)
			return;

		msg->mtext[0]=0;

		sprintf(sqlbuf, "UPDATE bmlog SET `log%d`=`log%d`+%d WHERE userid='%s' AND bname='%s' AND month=MONTH(CURDATE()) AND year=YEAR(CURDATE()) ;", ppl->type, ppl->type, ppl->value, msg->userid, ppl->boardname );

		if( mysql_real_query(&s,sqlbuf,strlen(sqlbuf)) || (affect=(int)mysql_affected_rows(&s))<0 ){
			mysql_fail ++;
			bbslog("3system","mysql bmlog error:%s",mysql_error(&s));
			if(mysql_fail > 10)
				closenewpostlog();
			return;
		}

		if(affect <= 0){
			sprintf(sqlbuf, "INSERT INTO bmlog (`id`, `userid`, `bname`, `month`, `year`, `log%d` ) VALUES (NULL, '%s', '%s', MONTH(CURDATE()), YEAR(CURDATE()), '%d' );", ppl->type, msg->userid, ppl->boardname, ppl->value);

			if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
				mysql_fail ++;
				bbslog("3system","mysql bmlog error:%s",mysql_error(&s));
				if(mysql_fail > 10)
					closenewpostlog();
			}else
				mysql_fail = 0;
		}else{
			mysql_fail = 0;
		}

		return;
	}
#endif

#ifdef NEWPOSTLOG
	if (msg->mtype == BBSLOG_POST && postlog_start){

		char newtitle[161];
		char sqlbuf[512];
		struct _new_postlog * ppl = (struct _new_postlog *) ( &msg->mtext[1]) ;
		char newts[20];

		msg->mtext[0]=0;

		mysql_escape_string(newtitle, ppl->title, strlen(ppl->title));

#ifdef NEWSMTH
		sprintf(sqlbuf, "INSERT INTO postlog (`id`, `userid`, `bname`, `title`, `time`, `threadid`, `articleid`, `ip`) VALUES (NULL, '%s', '%s', '%s', '%s', '%d', '%d', '%s');", msg->userid, ppl->boardname, newtitle, tt2timestamp(msg->msgtime, newts), ppl->threadid, ppl->articleid, ppl->ip );
#else
		sprintf(sqlbuf, "INSERT INTO postlog (`id`, `userid`, `bname`, `title`, `time`, `threadid`, `articleid`) VALUES (NULL, '%s', '%s', '%s', '%s', '%d', '%d');", msg->userid, ppl->boardname, newtitle, tt2timestamp(msg->msgtime, newts), ppl->threadid, ppl->articleid );
#endif

		if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){
			mysql_fail ++;
			bbslog("3system","mysql postlog error:%s",mysql_error(&s));
			if(mysql_fail > 10)
				closenewpostlog();
		}else{
			mysql_fail = 0;

			return;
		}
	}

	if (msg->mtype == BBSLOG_POST){
		struct _new_postlog * ppl = (struct _new_postlog *) ( &msg->mtext[1]) ;

		msg->mtype = BBSLOG_USER;

    	if ((msg->mtype < 0) || (msg->mtype > sizeof(logconfig) / sizeof(struct taglogconfig)))
        	return;
    	pconf = &logconfig[msg->mtype-1];

    	if (pconf->fd<0) return;
    	n = localtime(&msg->msgtime);

    	snprintf(header, 256, "[%02u/%02u %02u:%02u:%02u %5lu %lu] %s post '%s' on '%s'\n", n->tm_mon + 1, n->tm_mday, n->tm_hour, n->tm_min, n->tm_sec, (long int) msg->pid, msg->mtype, msg->userid, ppl->title, ppl->boardname);
    	if (pconf->buf) {
        	if ((int) (pconf->bufptr + strlen(header)) <= pconf->bufsize) {
            	strcpy(&pconf->buf[pconf->bufptr], header);
            	pconf->bufptr += strlen(header);
            	return;
        	}
    	}

/*目前log还是分散的,就先lock,seek吧*/
        writew_lock(pconf->fd, 0, SEEK_SET, 0);
    	lseek(pconf->fd, 0, SEEK_END);

    	if (pconf->buf && pconf->bufptr) {
        	write(pconf->fd, pconf->buf, pconf->bufptr);
        	pconf->bufptr = 0;
    	}
        un_lock(pconf->fd, 0, SEEK_SET, 0);

		return;
	}

#endif

    if ((msg->mtype < 0) || (msg->mtype > sizeof(logconfig) / sizeof(struct taglogconfig)))
        return;
    pconf = &logconfig[msg->mtype-1];

    if (pconf->fd<0) return;
    n = localtime(&msg->msgtime);

    ch=msg->mtext[0];
    msg->mtext[0]=0;
    snprintf(header, 256, "[%d-%02u-%02u %02u:%02u:%02u %5lu %lu] %s %c%s", n->tm_year + 1900, n->tm_mon + 1, n->tm_mday, n->tm_hour, n->tm_min, n->tm_sec, (long int) msg->pid, msg->mtype, msg->userid,ch,&msg->mtext[1]);
    if (pconf->buf) {
        if ((int) (pconf->bufptr + strlen(header)) <= pconf->bufsize) {
            strcpy(&pconf->buf[pconf->bufptr], header);
            pconf->bufptr += strlen(header);
            return;
        }
    }

/*目前log还是分散的,就先lock,seek吧*/
    writew_lock(pconf->fd, 0, SEEK_SET, 0);
    lseek(pconf->fd, 0, SEEK_END);

    if (pconf->buf && pconf->bufptr) {
        write(pconf->fd, pconf->buf, pconf->bufptr);
        pconf->bufptr = 0;
    }
    un_lock(pconf->fd, 0, SEEK_SET, 0);
}
Example #3
0
int add_pc_comments(struct pc_comments *pn)
{
    MYSQL s;
    char *sql;
    char *newbody;
    char newhostname[41];
    char newsubject[401];
    char newts[20];
    char newts1[20];

    newhostname[0]=0;
    newsubject[0]=0;
    newts[0]=0;
    newts1[0]=0;

    if (pn->body) {
        newbody = (char *)malloc(strlen(pn->body)*2 + 1);
        if (! newbody)
            return 0;
    } else
        newbody = NULL;

    sql = (char *)malloc((pn->body ? (strlen(pn->body) * 2) : 0) + 800);
    if (! sql) {
        if (pn->body)
            free(newbody);
        return 0;
    }

    mysql_init(&s);
    if (! my_connect_mysql_blog(&s)) {
        mysql_report_error(&s);
        if (pn->body)
            free(newbody);
        free(sql);
        return 0;
    }

    mysql_escape_string(newhostname, pn->hostname, strlen(pn->hostname));
    mysql_escape_string(newsubject, pn->subject, strlen(pn->subject));
    if (pn->body)
        mysql_escape_string(newbody, pn->body, strlen(pn->body));

    if (pn->cid <= 0)
        sprintf(sql,"INSERT INTO comments VALUES (NULL, %lu, %d, '%s', '%s', '%s', '%s', '%s', '%s', 0 , 0 );",pn->nid, pn->uid, newhostname, pn->username, newsubject, tt2timestamp(pn->created,newts), tt2timestamp(pn->changed, newts1), pn->body?newbody:"");
    else
        sprintf(sql,"UPDATE comments SET nid=%lu, uid=%d, hostname='%s', username='******', subject='%s', created='%s', changed='%s', body='%s' WHERE cid=%lu ;",pn->nid, pn->uid, newhostname, pn->username, newsubject, tt2timestamp(pn->created,newts), tt2timestamp(pn->changed, newts1), pn->body?newbody:"", pn->cid);

    if (mysql_real_query(&s, sql, strlen(sql))) {
        mysql_report_error(&s);
        mysql_close(&s);
        if (pn->body)
            free(newbody);
        free(sql);
        return 0;
    }

    if (pn->cid <= 0) {
        sprintf(sql,"UPDATE nodes SET changed=changed,commentcount=commentcount+1 WHERE nid=%lu",pn->nid);
        mysql_real_query(&s, sql, strlen(sql));
    }

    mysql_close(&s);
    if (pn->body)
        free(newbody);
    free(sql);

    return 1;
}
Example #4
0
int add_pc_nodes(struct pc_nodes *pn)
{
    MYSQL s;
    char *ql;
    char *newbody=NULL;
    char newsource[21];
    char newhostname[41];
    char newsubject[401];
    char newts[20];
    char newts1[20];

    newsource[0]=0;
    newhostname[0]=0;
    newsubject[0]=0;
    newts[0]=0;
    newts1[0]=0;

    if (pn->body) {
        newbody = (char *)malloc(strlen(pn->body) * 2 + 1);
        if (! newbody)
            return 0;
    }

    ql = (char *)malloc((pn->body?(strlen(pn->body) * 2):0) + 800);
    if (! ql) {
        if (pn->body)
            free(newbody);
        return 0;
    }
    bzero(ql, pn->body?(strlen(pn->body)*2):0 + 800);

    mysql_init(&s);
    if (! my_connect_mysql_blog(&s)) {
        mysql_report_error(&s);
        if (pn->body)
            free(newbody);
        free(ql);
        return 0;
    }

    mysql_escape_string(newsource, pn->source, strlen(pn->source));
    mysql_escape_string(newhostname, pn->hostname, strlen(pn->hostname));
    mysql_escape_string(newsubject, pn->subject, strlen(pn->subject));
    if (pn->body)
        mysql_escape_string(newbody, pn->body, strlen(pn->body));

    if (pn->nid <= 0) {
        if (pn->access == 0) {
            sprintf(ql,"UPDATE users SET `createtime` = `createtime` , modifytime = '%s' , nodescount = nodescount + 1 WHERE uid=%d ;",tt2timestamp(pn->changed,newts),pn->uid);
            mysql_real_query(&s, ql, strlen(ql));
        }
        sprintf(ql,"INSERT INTO `nodes` (  `pid` , `tid` , `type` , `recuser` , `emote` , `hostname` , `changed` , `created` , `uid` , `comment` , `commentcount` , `subject` , `body` , `access` , `visitcount` , `htmltag`,`trackback` ,`trackbackcount`,`nodetype`) VALUES ( %lu , 0 , %d , '%s', 0 ,  '%s', '%s' , '%s' , %d , %d , %lu , '%s', '%s', %d , %d , 0 , 1 , 0 , 0 );",pn->pid, pn->type, newsource, newhostname, tt2timestamp(pn->changed,newts), tt2timestamp(pn->created, newts1), pn->uid, pn->comment, pn->commentcount, newsubject, pn->body?newbody:"", pn->access, pn->visitcount);
    } else {
        sprintf(ql,"UPDATE nodes SET pid=%lu, type=%d, source='%s', hostname='%s', uid=%d, comment=%d, commentcount=%ld, subject='%s', body='%s', access=%d, visitcount=%d WHERE nodetype = 0 AND nid=%lu ;",pn->pid, pn->type, newsource, newhostname, pn->uid, pn->comment, pn->commentcount, newsubject, pn->body?newbody:"", pn->access, pn->visitcount, pn->nid);
    }

    if (mysql_real_query(&s, ql, strlen(ql))) {
        mysql_report_error(&s);
        mysql_close(&s);
        if (pn->body)
            free(newbody);
        free(ql);
        return 0;
    }

    mysql_close(&s);
    if (pn->body)
        free(newbody);
    free(ql);

    return 1;
}
Example #5
0
int add_pc_users(struct pc_users *pn)
{
    MYSQL s;
    char sql[600];
    char newtheme[21];
    char newdesc[401];
    char newts[20];
    char newcorp[81];

    newtheme[0]=0;
    newdesc[0]=0;
    newts[0]=0;
    newcorp[0]=0;

    mysql_init(&s);
    if (! my_connect_mysql_blog(&s)) {
        mysql_report_error(&s);
        return 0;
    }

    mysql_escape_string(newtheme, pn->theme, strlen(pn->theme));
    mysql_escape_string(newcorp, pn->corpusname, strlen(pn->corpusname));
    mysql_escape_string(newdesc, pn->description, strlen(pn->description));

    if (pn->uid <= 0)
        sprintf(sql,"INSERT INTO `users` ( `uid` , `username` , `corpusname` , `description` , `theme` , `nodelimit` , `dirlimit` , `createtime` , `style` , `backimage` , `visitcount` , `nodescount` , `logoimage` , `modifytime` , `links` , `htmleditor` , `indexnodechars` , `indexnodes` , `useremail` , `favmode` , `updatetime` , `userinfor` , `pctype` ,`defaulttopic`) VALUES ('', '%s', '%s', '%s' , 'others', %d, %d, NOW( ) , '0', '' , '0', '0', '' , NOW( ) , '', '1', '600', '5', '', '0', NOW( ) , '' , '0' , '其他类别');",pn->username, newcorp, newdesc, pn->nodelimit, pn->dirlimit);
    else
        sprintf(sql,"UPDATE users SET description='%s', corpusname='%s', theme='%s', nodelimit=%d, dirlimit=%d, createtime='%s' WHERE uid=%u AND username='******' ;",newdesc, newcorp, newtheme, pn->nodelimit, pn->dirlimit, tt2timestamp(pn->createtime,newts), pn->uid, pn->username);


    if (mysql_real_query(&s, sql, strlen(sql))) {
        mysql_report_error(&s);
        mysql_close(&s);
        return 0;
    }

    sprintf(sql,"UPDATE newapply SET `apptime` = `apptime` , manager = '%s' , management = 0 WHERE username = '******' ;", getCurrentUser()->userid , pn->username);
    if (mysql_real_query(&s, sql, strlen(sql))) {
        mysql_report_error(&s);
        mysql_close(&s);
        return 0;
    }

    mysql_close(&s);

    return 1;
}
Example #6
0
int pc_logs(struct pc_logs *pn)
{
    MYSQL s;
    char sql[600];
    char newhostname[21];
    char newaction[101];
    char newcomment[201];
    char newts[20];

    newhostname[0]=0;
    newaction[0]=0;
    newcomment[0]=0;
    newts[0] = 0;

    mysql_init(&s);
    if (! my_connect_mysql_blog(&s)) {
        mysql_report_error(&s);
        return 0;
    }

    mysql_escape_string(newhostname, pn->hostname, strlen(pn->hostname));
    mysql_escape_string(newaction, pn->action, strlen(pn->action));
    mysql_escape_string(newcomment, pn->comment, strlen(pn->comment));

    sprintf(sql,"INSERT INTO logs VALUES (NULL, '%s', '%s', '%s', '%s' , '%s' , '%s', '%s' );",pn->username, newhostname,newaction, pn->pri_id, pn->sec_id, newcomment, tt2timestamp(pn->logtime,newts));

    if (mysql_real_query(&s, sql, strlen(sql))) {
        mysql_report_error(&s);
        mysql_close(&s);
        return 0;
    }

    mysql_close(&s);

    return 1;
}
Example #7
0
/*
create table `toplog` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
 UNIQUE top (`date`,`topth`)
) TYPE=MyISAM COMMENT='toplog';

create table `toplog_all` (
 `id` int unsigned NOT NULL auto_increment,
 `userid` char(15) NOT NULL default '',
 `bname` char(31) NOT NULL default '',
 `title` char(81) NOT NULL default '',
 `time` timestamp NOT NULL,
 `date` date NOT NULL,
 `topth` int NOT NULL default '1',
 `count` int NOT NULL default '0',
 `threadid` int unsigned NOT NULL default '0',
 PRIMARY KEY (`id`),
 KEY userid (`userid`),
 KEY bname(`bname`, `threadid`),
 KEY date(`date`),
) TYPE=MyISAM COMMENT='toplog_all';
*/
int log_top()
{
    MYSQL s;
    char sqlbuf[500];
    char newtitle[161];
    int i;
    char newts[20];
    time_t now;
    struct tm ptime;

    mysql_init(&s);

    if (! my_connect_mysql(&s)) {
        return 0;;
    }

    for (i=0;i<topnum;i++) {

        mysql_escape_string(newtitle, top[i].title, strlen(top[i].title));

#ifdef NEWSMTH
        MYSQL_RES *res;
        MYSQL_ROW row;
        sprintf(sqlbuf, "SELECT id FROM toplog_all WHERE date=CURDATE() AND bname='%s' AND threadid=%d; ", top[i].board, top[i].groupid);
        if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
            printf("%s\n", mysql_error(&s));
        } else {
            res = mysql_store_result(&s);
            row = mysql_fetch_row(res);
            if (row==NULL) {
                char title[STRLEN],file[STRLEN];
                // auto post top10 to ShiDa
                sprintf(title, "[%s] %s", top[i].board,top[i].title);
                sprintf(file, "boards/%s/%s", top[i].board,top[i].filename);
                post_file(NULL, "", file , "ShiDa", title, 0, 1, getSession());
                // insert into toplog_all
                sprintf(sqlbuf, "INSERT INTO toplog_all VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
                if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                    printf("%s\n", mysql_error(&s));
                }
            } else {
                // update toplog_all
                sprintf(sqlbuf,"UPDATE toplog_all SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND bname='%s' AND threadid=%d;;", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, top[i].board, top[i].groupid);
                if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                    printf("%s\n", mysql_error(&s));
                }
            }
        }
        time(&now);
        ptime = *localtime(&now);
        if (ptime.tm_hour == 23) {
            total_post_top10(top[i].groupid,top[i].board,top[i].title);
        }
#endif

        sprintf(sqlbuf,"UPDATE toplog SET userid='%s',bname='%s',title='%s',count='%d',time='%s',threadid='%d' WHERE date=CURDATE() AND topth='%d';", top[i].userid, top[i].board, newtitle, top[i].number, tt2timestamp(top[i].date,newts), top[i].groupid, i+1);

        if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
            printf("%s\n", mysql_error(&s));
            continue;
        }
        if ((int)mysql_affected_rows(&s) <= 0) {
            sprintf(sqlbuf, "INSERT INTO toplog VALUES (NULL,'%s','%s','%s','%s',CURDATE(),'%d','%d','%d');",top[i].userid, top[i].board, newtitle, tt2timestamp(top[i].date,newts), i+1, top[i].number, top[i].groupid);
            if (mysql_real_query(&s, sqlbuf, strlen(sqlbuf))) {
                printf("%s\n", mysql_error(&s));
                continue;
            }
        }
    }

    mysql_close(&s);

    return 1;
}