Example #1
0
File: shmctl.c Project: ptt/pttbbs
int main(int argc, char **argv)
{
    int     i = 0;
	
    chdir(BBSHOME);
    initsetproctitle(argc, argv, environ);
    if( argc >= 2 ){
	if( strcmp(argv[1], "init") == 0 ){
	    /* in this case, do NOT run attach_SHM here.
	       because uhash_loader is not run yet.      */
	    return SHMinit(argc - 1, &argv[1]);
	}

	attach_SHM();
	/* shmctl doesn't need resolve_boards() first */
	//resolve_boards();
	resolve_garbage();
	resolve_fcache();
	for( i = 0 ; cmd[i].func != NULL ; ++i )
	    if( strcmp(cmd[i].cmd, argv[1]) == 0 ){
		return cmd[i].func(argc - 1, &argv[1]);
	    }
    }
    if( argc == 1 || cmd[i].func == NULL ){
	/* usage */
	printf("usage: shmctl [command] [options]\n");
	printf("commands:\n");
	for( i = 0 ; cmd[i].func != NULL ; ++i )
	    printf("\t%-15s%s\n", cmd[i].cmd, cmd[i].descript);
    }
    return 0;
}
Example #2
0
/* Jaky and Ptt */
int 
where(char *from)
{
	extern struct FROMCACHE *fcache;
	register int	i , count, j;

	resolve_fcache();
	for (j = 0; j < fcache->top; j++) {
		char           *token = strtok(fcache->domain[j], "&");
		i = 0;
		count = 0;
		while (token) {
			if (strstr(from, token))
				count++;
			token = strtok(NULL, "&");
			i++;
		}
		if (i == count)
			break;
	}
	if (i != count)
		return 0;
	return j;
}
Example #3
0
static void user_login() {
    char ans[4], i;
    char genbuf[200];
    struct tm *ptime, *tmp;
    time_t now;
    int a;
    /*** Heat:廣告詞
	 char *ADV[17] = {
	 "記得唷!! 5/12在台大二活地下室見~~~",
	 "你知道Ptt之夜是什麼嗎? 5/12號就要上演耶 快去問吧!",
	 "5/12 Ptt之夜即將引爆 能不去嗎? 在台大二活地下室咩",
	 "不來就落伍了 啥? 就Ptt之夜啊 很棒的晚會唷 時間:5/12",
	 "差點忘了提醒你 5/12我們有約 就台大二活地下室咩!!",
	 "Ptt是啥 想知嗎? 5/12在台大二活地下室告訴你唷",
	 "來來來....5/12快到台大二活地下室去拿獎品吧~~",
	 "去去去...到台大二活地下室去 就5/12麻 有粉多獎品耶",
	 "喂喂喂 怎還楞在這!!快呼朋引伴大鬧ptt",
	 "Ptt最佳豬腳 換你幹幹看 5/12來吧....*^_^*",
	 "幹什麼幹什麼?? 你怎麼不曉得啥是Ptt之夜..老土唷",
	 "累了嗎? 讓我們來為你來一段精采表演吧.. 5/12 Ptt之夜",
	 "世紀末最屁力的晚會 就在台大二活地下室 5/12不見不散 gogo",
	 "到底誰比較帥(美) 來比比吧 5/12Ptt之夜 一較高下",       
	 "台大二活地下室 5/12 聽說會有一場很棒的晚會唷 Ptt之夜",
	 "台大二活地下室 5/12 你能不來嗎?粉多網友等著你耶",
	 "5/12 台大二活地下室 是各約網友見面的好地方呢",
	 }; 
	 char *ADV[] = {
	 "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!",
	 "欲知詳情請看 PttAct 板!!",
	 }; ***/

    log_usies("ENTER", getenv("RFC931") /* fromhost */ );
    setproctitle("%s: %s", margs, cuser.userid);
    
    /* resolve all cache */
    resolve_garbage();	/* get ptt cache */
    resolve_fcache();
    resolve_boards();
    
    /* 初始化 uinfo、flag、mode */
    setup_utmp(LOGIN);
    mysrand();		/* 初始化: random number 增加user跟時間的差異 */
    currmode = MODE_STARTED;
    enter_uflag = cuser.uflag;

    /* get local time */
    time(&now);
    ptime = localtime(&now);
    tmp = localtime(&cuser.lastlogin);
    
    if((a = utmpshm->number) > fcache->max_user) {
	sem_init(FROMSEM_KEY, &fcache_semid);
	sem_lock(SEM_ENTER, fcache_semid);
	fcache->max_user = a;
	fcache->max_time = now;
	sem_lock(SEM_LEAVE, fcache_semid);
    }
#ifdef INITIAL_SETUP
    if(!getbnum(DEFAULT_BOARD)) {
	strcpy(currboard, "尚未選定");
    } else
#endif
    {
	brc_initial(DEFAULT_BOARD);
	set_board();
    }

    /* 畫面處理開始 */
    if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)))
	do_aloha("<<上站通知>> -- 我來啦!");
    if(ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) {
	more("etc/Welcome_birth", NA);
	currutmp->birth = 1;
    } else {
	more("etc/Welcome_login", NA);
//	pressanykey();
//    more("etc/CSIE_Week", NA);
	currutmp->birth = 0;
    }
    
    if(cuser.userlevel) {	/* not guest */
	move(t_lines - 4, 0);
	prints("      歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站,"
	       "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n"
	       "     我記得那天是 \033[1;33m%s\033[0;37m。\n",
	       ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin));
	currutmp->mind=rand()%8;  /* 初始心情 */
	pressanykey();
 	
	if(currutmp->birth && tmp->tm_mday != ptime->tm_mday) {
	    more("etc/birth.post", YEA);
	    brc_initial("WhoAmI");
	    set_board();
	    do_post();
	}
	setuserfile(genbuf, str_badlogin);
	if(more(genbuf, NA) != -1) {
	    getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]",
		    ans, 3, LCECHO);
	    if(*ans != 'n')
		unlink(genbuf);
	}
	check_register();
	strncpy(cuser.lasthost, fromhost, 16);
	cuser.lasthost[15] = '\0';
	restore_backup();
    } else if(!strcmp(cuser.userid, STR_GUEST)) {
	char *nick[13] = {
	    "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚",
	    "樹葉", "浮萍", "鞋子", "潛水艇", "魔王",
	    "鐵罐", "考卷", "大美女"};
	char *name[13] = {
	    "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚",
	    "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢",
	    "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲"};
	char *addr[13] = {
	    "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁",
	    "遠方", "原本海", "NIKE", "蘇聯", "男八618室",
	    "愛之味", "天上", "藍色珊瑚礁"};
	i = login_start_time % 13;
	sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]);
	sprintf(currutmp->username, cuser.username);
	sprintf(cuser.realname, name[(int)i]);
	sprintf(currutmp->realname, cuser.realname);
	sprintf(cuser.address, addr[(int)i]);
	cuser.sex = i % 8;
	currutmp->pager = 2;
	pressanykey();
    } else
	pressanykey();
    
    if(!PERM_HIDE(currutmp))
	cuser.lastlogin = login_start_time;
    
    reload_money();
    passwd_update(usernum, &cuser);
    
    for(i = 0; i < NUMVIEWFILE; i++)
	if((cuser.loginview >> i) & 1)
	    more(loginview_file[(int)i][0], YEA);
	
	
}
Example #4
0
static void
user_login()
{
	char		genbuf    [200];
	struct tm      *ptime, *tmp;
	time_t		now = time(0);
	int		a;

	extern struct FROMCACHE *fcache;
	extern int	fcache_semid;

	log_usies("ENTER", fromhost);
	setproctitle("%s: %s", cuser.userid, fromhost);

	/* ------------------------ */
	/* 初始化 uinfo、flag、mode */
	/* ------------------------ */

	setup_utmp(LOGIN);
	currmode = MODE_STARTED;
	enter_uflag = cuser.uflag;

	/* get local time */
	tmp = localtime(&cuser.lastlogin);

	update_data();		/* wildcat: update user data */
	/* Ptt check 同時上線人數 */
	resolve_fcache();
	resolve_utmp();

	if ((a = utmpshm->number) > fcache->max_user) {
		sem_init(FROMSEM_KEY, &fcache_semid);
		sem_lock(SEM_ENTER, fcache_semid);
		fcache->max_user = a;
		fcache->max_time = now;
		sem_lock(SEM_LEAVE, fcache_semid);
	}
#ifdef  INITIAL_SETUP
	if (getbnum(DEFAULT_BOARD) == 0) {
		strcpy(currboard, "尚未選定");
	} else
#endif

	{
		brc_initial(DEFAULT_BOARD);
		set_board();
	}

	/* ------------ */
	/* 畫面處理開始 */
	/* ------------ */

	if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) {
		char		buf       [256];
		time_t		now;

		time(&now);
		sprintf(buf, "<<上站通知>> -- 我來囉! - %s", Etime(&now));
		do_aloha(buf);
	}
	time(&now);
	ptime = localtime(&now);

#ifdef CAMERA
	film_out(FILM_LOGIN, 0);
#else
	more("etc/Welcome_login", NA);
#endif

#if 0
	/* wildcat : 搬家通知用 */
	if (belong(BBSHOME "/etc/oldip", fromhost)) {
		more(BBSHOME "/etc/removal");
		abort_bbs();
	}
#endif

	if ((cuser.day == ptime->tm_mday) && (cuser.month == (ptime->tm_mon + 1)))
		currutmp->birth = 1;
	else
		currutmp->birth = 0;

	if (cuser.userlevel) {	/* not guest */
		move(t_lines - 3, 0);
		prints("      歡迎您第 %d 度拜訪本站,\
上次您是從 %s 連往本站,\n\
     我記得那天是 %s。\n",
		       ++cuser.numlogins, cuser.lasthost,
		       Etime(&cuser.lastlogin));
		pressanykey(NULL);


		/* Ptt */
		if (currutmp->birth == 1) {
#ifdef CAMERA
			film_out(FILM_WEL_BIRTH, 0);
#else
			more("etc/Welcome_birth", YEA);
#endif
			brc_initial("Greeting");
			set_board();
			do_post();
		}
		sethomefile(genbuf, cuser.userid, str_badlogin);
		if (more(genbuf, NA) != -1) {
			if (getans2(b_lines, 0, "您要刪除以上錯誤嘗試的記錄嗎?", 0, 2, 'y') != 'n')
				unlink(genbuf);
		}
		check_register();
		strncpy(cuser.lasthost, fromhost, 24);
		substitute_record(fn_passwd, &cuser, sizeof(cuser), usernum);
		cuser.lasthost[23] = '\0';
		restore_backup();
	}