コード例 #1
0
ファイル: record.c プロジェクト: OmniBus/hkday-pttbbs
int
substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent)
{
    fileheader_t    hdr;
    char            fname[PATHLEN];
    int             num = 0;

    /* rocker.011018: 串接模式用reference增進效率 */
    if (!(fhdr->filemode & FILE_BOTTOM) &&  (fhdr->multi.refer.flag) &&
	    (num = fhdr->multi.refer.ref)){
	setdirpath(fname, direct, FN_DIR);
	get_record(fname, &hdr, sizeof(hdr), num);
	if (strcmp(hdr.filename, fhdr->filename)) {
	    if((num = getindex_m(fname, fhdr, num, 1))>0) {
		substitute_record(fname, fhdr, sizeof(*fhdr), num);
	    }
	}
	else if(num>0) {
	    fhdr->multi.money = hdr.multi.money;
	    substitute_record(fname, fhdr, sizeof(*fhdr), num);
	}
	fhdr->multi.refer.flag = 1;
	fhdr->multi.refer.ref = num; // Ptt: update now!
    }
    substitute_record(direct, fhdr, sizeof(*fhdr), ent);
    return num;
}
コード例 #2
0
ファイル: userinfo.c プロジェクト: miminus/bmybbs
// username�û���֤ʧ�ܵĴ�����������û�������Ŀǰ��δʹ������������� added by interma@BMY 2005.5.16
void register_fail(char *userid)
{
	int id;
	strcpy(genbuf, userid);
	id = getuser(genbuf);

	if (lookupuser.userid[0] == '\0' || !strcmp(lookupuser.userid, "SYSOP")) {
		return;
	}

	sprintf(genbuf, "mail/%c/%s", mytoupper(lookupuser.userid[0]),
		lookupuser.userid);
	deltree(genbuf);
	sprintf(genbuf, "home/%c/%s", mytoupper(lookupuser.userid[0]),
		lookupuser.userid);
	deltree(genbuf);
	lookupuser.userlevel = 0;
	strcpy(lookupuser.address, "");
	strcpy(lookupuser.username, "");
	strcpy(lookupuser.realname, "");
	strcpy(lookupuser.ip, "");
	strcpy(lookupuser.realmail, "");
	lookupuser.userid[0] = '\0';
	substitute_record(PASSFILE, &lookupuser, sizeof (lookupuser), id);
	setuserid(id, lookupuser.userid);
}
コード例 #3
0
ファイル: mod_article.c プロジェクト: chage/formosa
static int get_only_postno(const char *dotdir, int fd, FILEHEADER *fhr)
{
	char finfo[PATHLEN];
	INFOHEADER info;

	if (get_last_info(dotdir, fd, &info, FALSE) == -1) {
		bbslog("ERROR", "Getting INFO_REC.");
		fprintf(stderr, "ERROR: Getting INFO_REC.");
		return -1;
	}

	if (++info.last_postno > BRC_REALMAXNUM)
		info.last_postno = 1;	/* reset the postno. */

	fhr->postno = info.last_postno;
	info.last_mtime  = fhr->mtime;
	strcpy(info.last_filename, fhr->filename);

	setdotfile(finfo, dotdir, INFO_REC);
	if (substitute_record(finfo, &info, IH_SIZE, 1) == -1) {
		bbslog("ERROR", "Updating INFO_REC. (%s)", finfo);
		fprintf(stderr, "ERROR: Updating INFO_REC. (%s)", finfo);
		return -1;
	}

	return 0;
}
コード例 #4
0
ファイル: mbbsd.c プロジェクト: yrchen/Athena
void 
u_exit(char *mode)
{
	extern void	auto_backup();	/* 編輯器自動備份 */
	userec		xuser;
	int		diff = (time(0) - login_start_time) / 60;

	rec_get(fn_passwd, &xuser, sizeof(xuser), usernum);
	auto_backup();
	setflags(PAGER_FLAG, currutmp->pager != 1);
	setflags(CLOAK_FLAG, currutmp->invisible);
	xuser.pager = currutmp->pager;	/* 記錄pager狀態, add by wisely */
	xuser.invisible = currutmp->invisible;	/* 紀錄隱形狀態 by wildcat */
	xuser.totaltime += time(0) - update_time;
	xuser.numposts = cuser.numposts;
	xuser.feeling[4] = '\0';

	if (!HAS_PERM(PERM_DENYPOST) && !currutmp->invisible) {
		char		buf       [256];
		time_t		now;

		time(&now);
		sprintf(buf, "<<下站通知>> -- 我走囉! - %s", Etime(&now));
		do_aloha(buf);
	}
	purge_utmp(currutmp);
	if (!diff && cuser.numlogins > 1 && strcmp(cuser.userid, STR_GUEST))
		xuser.numlogins = --cuser.numlogins;	/* Leeym 上站停留時間限制式 */
	substitute_record(fn_passwd, &xuser, sizeof(userec), usernum);
	log_usies(mode, NULL);
}
コード例 #5
0
ファイル: loginplan.c プロジェクト: yrchen/Athena
static int
habit_feeling()
{
  getdata(b_lines ,0,"今天的心情如何呢?", cuser.feeling, 5 ,DOECHO,cuser.feeling);
  cuser.feeling[4] = '\0';
  strcpy(currutmp->feeling, cuser.feeling);
  substitute_record(fn_passwd, &cuser, sizeof(userec), usernum);
}
コード例 #6
0
ファイル: mod_article.c プロジェクト: chage/formosa
/*
 * sync_threadfiles
 * if a .DIR entry has been updated, this function will make all changes
 * in respective thread files, updating fields that are common to both
 * .DIR & .THREADxxxx files
 * fhr - file header of the entry just modified
 * ent - which entry in .DIR is this file header
 *
 * return: 0 - success,
 *		  -1 - fail
 */
int sync_threadfiles(FILEHEADER *fhr, char *direct)
{
 	FILEHEADER filehdr;
	THRHEADHEADER thrhead, *p_thrhead=(THRHEADHEADER *)&filehdr;
	THRPOSTHEADER thrpost, *p_thrpost=(THRPOSTHEADER *)&filehdr;
 	char path[STRLEN];
 	int index;

	/* make working copy of header structure */
	memcpy( &filehdr, fhr, FH_SIZE );

 	/* update .THREADHEAD */
	strcpy( path, direct );
	*( strrchr(path,'/')+1 ) = '\0';
 	strcat( path, THREAD_HEAD_REC );
 	index = fhr->thrheadpos + 1;
 	if( get_record( path, &thrhead, THRHEADHDR_SIZE, index ) == -1 )
		return (-1);

	p_thrhead->numfollow = thrhead.numfollow;
 	p_thrhead->thrpostpos = thrhead.thrpostpos;
	p_thrhead->thrheadpos = thrhead.thrheadpos;
	p_thrhead->thrpostidx = thrhead.thrpostidx;

 	if( substitute_record( path, p_thrhead, THRHEADHDR_SIZE, index ) == -1 )
		return (-1);

 	/* update .THREADPOST */
	*( strrchr(path,'/')+1 ) = '\0';
	strcpy( path, THREAD_REC );
 	index = thrhead.thrpostpos + fhr->thrpostidx + 1;
	if( get_record( path, &thrpost, THRPOSTHDR_SIZE, index ) == -1 )
		return (-1);

	p_thrpost->lastfollowidx = thrpost.lastfollowidx;
	p_thrpost->nextfollowidx = thrpost.nextfollowidx;
	p_thrpost->nextpostidx   = thrpost.nextpostidx;
	p_thrpost->thrheadpos	 = thrpost.thrheadpos;
	p_thrpost->thrpostidx	 = thrpost.thrpostidx;

 	if( substitute_record( path, p_thrpost, THRPOSTHDR_SIZE, index ) == -1 )
		return (-1);

	return 0;
}
コード例 #7
0
ファイル: userinfo.c プロジェクト: madoldman/inankai_bbs
int user_switchcase()
{
        char newuserid[IDLEN+2];
        modify_user_mode(USERDEF);
        clear();
        if (count_user( )>1)
        {
                move(1,0);
                prints("��Ŀǰ��login��ֹһ��,���˳�����login������һ��\n");
                pressreturn();
                clear();
                return 1;
        }
        if(HAS_PERM(PERM_BOARDS)){
                move(1,0);
                prints("�Բ���Ŀǰ��֧�ְ����޸��û�����Сд��������ϵ����������Ա,\n");
                prints("�������а���Ȼ������޸ģ���������������");
                pressreturn();
                clear();
                return 1;
        }
        getdata(0, 0, "�������µ��ʺ����� (Enter User ID): ",
                        newuserid, IDLEN + 1, DOECHO, YEA);
        if(newuserid[0] == '\0'){
                clear();
                return 0;
        }
        if(!strcmp(currentuser.userid, newuserid)){
                clear();
                return 0;
        }
        if(strcasecmp(currentuser.userid, newuserid)){
               move(1,0);
                prints("�µ��ʺ����ƺ�ԭ���ʺŲ�ͬ������ܸı��ʺŵĴ�Сд��");
                pressreturn();
                clear();
                return 1;
        }
		if(HAS_PERM(PERM_PERSONAL))
	        dig_user_switchcase(newuserid);
		sprintf(genbuf,"mv %s/home/%C/%s %s/home/%C/%s",
				BBSHOME, toupper(currentuser.userid[0]),currentuser.userid,
				BBSHOME, toupper(newuserid[0]), newuserid);
		system(genbuf);
		sprintf(genbuf,"mv %s/mail/%C/%s %s/mail/%C/%s",
				BBSHOME, toupper(currentuser.userid[0]),currentuser.userid,
				BBSHOME, toupper(newuserid[0]), newuserid);
		system(genbuf);
        strcpy(currentuser.userid, newuserid);
        strcpy(uinfo.userid, newuserid);
        substitute_record(PASSFILE, &currentuser, sizeof(currentuser), usernum);
        move(5,10);
        prints("�޸��ʺŴ�Сд�ɹ���");
        pressreturn();
        return 0;
}
コード例 #8
0
ファイル: vote.c プロジェクト: phoenixgao/fdubbs
//���ð���ͶƱ�ı�־,           
//bname:������,flag�����־
//1:����ͶƱ,0:�ر�ͶƱ ����ֵ:��..
int setvoteflag(char *bname, int flag) {
	int pos;
	struct boardheader fh;

	pos = search_record(BOARDS, &fh, sizeof(fh), cmpbnames, bname);
	if (flag == 0)
		fh.flag = fh.flag & ~BOARD_VOTE_FLAG;
	else
		fh.flag = fh.flag | BOARD_VOTE_FLAG;
	if (substitute_record(BOARDS, &fh, sizeof(fh), pos) == -1)
		prints("Error updating BOARDS file...\n");
}
コード例 #9
0
ファイル: announce.c プロジェクト: Fdhvdu/pttbbs
static void
a_moveitem(menu_t * pm)
{
    fileheader_t   *tmp;
    char            newnum[5];
    int             num, max, min;
    char            buf[PATHLEN];
    int             fail;

    snprintf(buf, sizeof(buf), "請輸入第 %d 選項的新次序:", pm->now + 1);
    if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO))
	return;
    num = (newnum[0] == '$') ? A_INVALID_PAGE : atoi(newnum) - 1;
    if (num >= pm->num)
	num = pm->num - 1;
    else if (num < 0)
	num = 0;
    setadir(buf, pm->path);
    min = num < pm->now ? num : pm->now;
    max = num > pm->now ? num : pm->now;
    tmp = (fileheader_t *) calloc(max + 1, FHSZ);

    fail = 0;
    if (get_records(buf, tmp, FHSZ, 1, min) != min)
	fail = 1;
    if (num > pm->now) {
	if (get_records(buf, &tmp[min], FHSZ, pm->now + 2, max - min) != max - min)
	    fail = 1;
	if (get_records(buf, &tmp[max], FHSZ, pm->now + 1, 1) != 1)
	    fail = 1;
    } else {
	if (get_records(buf, &tmp[min], FHSZ, pm->now + 1, 1) != 1)
	    fail = 1;
	if (get_records(buf, &tmp[min + 1], FHSZ, num + 1, max - min) != max - min)
	    fail = 1;
    }
    if (!fail)
	substitute_record(buf, tmp, FHSZ * (max + 1), 1);
    pm->now = num;
    free(tmp);
}
コード例 #10
0
ファイル: mbbsd.c プロジェクト: yrchen/Athena
static void 
write_request()
{
	time_t		now;
	/* Half-hour remind  */
	if (*currmsg) {
		outmsg(currmsg);
		bell();
		*currmsg = 0;
		return;
	}
	time(&now);

#ifdef  LINUX
	signal(SIGUSR2, write_request);
#endif

	update_data();
	++cuser.receivemsg;
	substitute_record(fn_passwd, &cuser, sizeof(userec), usernum);
	bell();
	show_last_call_in();
	/* wildcat patch : 看不到水球??!! */
	currutmp->msgcount--;
	memcpy(&oldmsg[no_oldmsg], &currutmp->msgs[0], sizeof(msgque));
	no_oldmsg++;
	no_oldmsg %= MAX_REVIEW;
	if (oldmsg_count < MAX_REVIEW)
		oldmsg_count++;
	if (watermode) {
		if (watermode < oldmsg_count)
			watermode++;
		t_display_new(0);
	}
	refresh();
	currutmp->msgcount = 0;
}
コード例 #11
0
ファイル: shmctl.c プロジェクト: ptt/pttbbs
static void update_brd(int i) {
    if(substitute_record(BBSHOME "/" FN_BOARD, &bcache[i],sizeof(boardheader_t),i+1) < 0) {
	printf("\n! CANNOT WRITE: " BBSHOME "/" FN_BOARD "\n");
	exit(0);
    }
}
コード例 #12
0
ファイル: inndBM.c プロジェクト: OmniBus/hkday-pttbbs
int main(int argc, char **argv)
{
    int i,serverid=0;
    FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w");
    char buf[256],serverstr[30]="";
    chdir(BBSHOME "/innd");
    attach_SHM();
    resolve_boards();
    memset(istran,0,sizeof(int)*MAX_BOARD);
    load_server();
    load_newsfeeds();

    for(i=0;i<feedcount;i++)
	{
	  if(strcasecmp(serverstr,feedline[i].server))
	   {
	     if(get_server(feedline[i].server)==-1) continue;
	     if(fp) {
			fclose(fp);	
                        dobbsnnrp(serverstr,serverid,fpscript);
		    }
	     strcpy(serverstr,feedline[i].server);
	     serverid=get_server(feedline[i].server);
	     sprintf(buf,INNDHOME"/active/%s.auto.active",serverstr);
	     fp=fopen(buf,"w");
	   }
          if(fp)
             fprintf(fp,"%-35s 0000000000 0000000000 y\r\n",feedline[i].group);
	}
    if(fp) 
    {
      dobbsnnrp(serverstr,serverid,fpscript);
      fclose(fp);
    }
    if(fpscript)
     {
	fclose(fpscript);
	chmod(INND_SCRIPT,0744);
     }

    // 重設轉信與不轉信板標記
    int total = num_boards();
    for(i=0;i<total;i++)
     {
       if(bcache[i].brdname[0]=='\0' ||
	   (bcache[i].brdattr & BRD_GROUPBOARD) ) continue;
       if((bcache[i].brdattr & BRD_NOTRAN )&& istran[i])
         {
	   while(SHM->Bbusystate) {safe_sleep(1);}
  	   SHM->Bbusystate = 1;
           bcache[i].brdattr = bcache[i].brdattr & ~BRD_NOTRAN;
           strncpy(bcache[i].title + 5, "●", 2);
	   SHM->Bbusystate = 0;

           substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
	 }
       else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i]) 
         {
	   while(SHM->Bbusystate) {safe_sleep(1);}
           SHM->Bbusystate = 1;
           bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN;
           strncpy(bcache[i].title + 5, "◎", 2);
           SHM->Bbusystate = 0;
           substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
	 }

     }
    return 0;
}
コード例 #13
0
ファイル: chlevel.c プロジェクト: xingskycn/kbs
main()
{
    FILE *rec;
    int i = 0;
    struct userec user;
    unsigned int perm;

    rec = fopen(BBSHOME "/.PASSWDS", "rb");
    if(NULL==rec) {
	    printf("Can not open .PASSWDS");
	    return 0;
    }

    printf("\033[1;31;5mUserLevel Records Transfering...\n\033[m");

    while (1) {
        if (fread(&user, sizeof(user), 1, rec) <= 0)
            break;
        i++;
        if (user.numlogins <= 0)
            continue;
        printf("%d %s\t\n", i, user.userid);
        perm = user.userlevel;
        user.userlevel = PERM_BASIC;
        user.userlevel |= PERM_CHAT;
        user.userlevel |= PERM_PAGE;
        user.userlevel |= PERM_POST;
        user.userlevel |= PERM_LOGINOK;

        if (perm & PERM_CLOAK)
            user.userlevel |= PERM_CLOAK;
        if (perm & PERM_SEECLOAK)
            user.userlevel |= PERM_SEECLOAK;
        if (perm & PERM_XEMPT)
            user.userlevel |= PERM_XEMPT;
        if (perm & PERM_BOARDS)
            user.userlevel |= PERM_BOARDS;
        if (perm & PERM_ACCOUNTS)
            user.userlevel |= PERM_ACCOUNTS;
        if (perm & PERM_CHATCLOAK)
            user.userlevel |= PERM_CHATCLOAK;
        if (perm & PERM_SYSOP) {
            user.userlevel |= PERM_SYSOP;
            user.userlevel |= PERM_ADMIN;
        }
	if (perm & PERM_HORNOR) 
	    user.userlevel &=~PERM_HORNOR;
        if (perm & PERM_POSTMASK)
            user.userlevel |= PERM_POSTMASK;
        if (perm & PERM_ANNOUNCE)
            user.userlevel |= PERM_ANNOUNCE;
        if (perm & PERM_OBOARDS)
            user.userlevel |= PERM_OBOARDS;
        if (perm & PERM_ACBOARD)
            user.userlevel |= PERM_ACBOARD;
        if (perm & PERM_NOZAP)
            user.userlevel |= PERM_NOZAP;
	if (perm & PERM_JURY)
	    user.userlevel &=~PERM_JURY;
	user.userdefine[0] = -1;
	user.userdefine[1] = -1;
#ifdef HAVE_WFORUM
	SET_UNDEFINE(&user,DEF_SHOWREALUSERDATA);
#endif
        user.flags = CURSOR_FLAG;
        user.flags |= PAGER_FLAG;
        user.title = 0;
/*	
        user.userdefine |= DEF_ALLMSG;
        user.userdefine |= DEF_FRIENDMSG;
        user.userdefine |= DEF_SOUNDMSG;
        user.userdefine &= ~DEF_MAILMSG;
*/
        substitute_record(BBSHOME "/.PASSWDS", &user, sizeof(user), i, NULL, NULL);
    }
    printf("\n\033[1m%d \033[32mUsers Attribute Tranfered...\033[m\n", i);
    fclose(rec);
}
コード例 #14
0
ファイル: mod_article.c プロジェクト: chage/formosa
/*
 * postno is for readrc mechanism
 * It reads the last postno information from INFO_REC
 * If failed, scan all .DIR file to find the last postno.
 * and write it back to INFO_REC.
 */
int get_last_info(const char *dotdir, int fd, INFOHEADER *info, int force)
{
	char finfo[PATHLEN];

	setdotfile(finfo, dotdir, INFO_REC);
	if (force || (get_record(finfo, info, IH_SIZE, 1) != 0)) {
		int i, nr, myfd;
		FILEHEADER lastf, fhtmp;
		time_t lastmtime = 0, mtime;

		if (!dotdir && !fd)
			return -1;

		if (!fd) {
			myfd = open(dotdir, O_RDWR | O_CREAT, 0644);
			if (myfd == -1)
				return -1;
			if (myflock(myfd, LOCK_EX)) {
				close(myfd);
				return -1;
			}
		} else {
			myfd = fd;
		}

		nr = get_num_records_byfd(myfd, FH_SIZE);
		for (i = 1; i <= nr; ++i) {
			if (get_record_byfd(myfd, &fhtmp, FH_SIZE, i) == 0) {
				if (fhtmp.accessed & FILE_DELE)
					continue;

				if (fhtmp.mtime)
					mtime = fhtmp.mtime;
				else if (fhtmp.filename[0] == 'M')
					mtime = strtol(fhtmp.filename + 2, NULL, 10);
				else
					mtime = 0;

				if (mtime > lastmtime) {
					memcpy(&lastf, &fhtmp, FH_SIZE);
					lastmtime = mtime;
				}
			} else {
				break;
			}
		}

		if (!fd) {
			flock(myfd, LOCK_UN);
			close(myfd);
		}

		if (i <= nr)
			return -1;

		memset(info, 0, IH_SIZE);
		if (lastmtime) {
			info->last_postno = lastf.postno;
			info->last_mtime  = lastf.mtime;
			strcpy(info->last_filename, lastf.filename);
		} else {
			/* There is no article yet. */
			info->last_postno = 0;
			info->last_mtime = 0;
			strcpy(info->last_filename, "M.000000000.A");
		}
		if (substitute_record(finfo, info, IH_SIZE, 1) == -1)
			return -1;
	}

	return 0;
}
コード例 #15
0
ファイル: userinfo.c プロジェクト: madoldman/inankai_bbs
int uinfo_query(struct userec *u, int real, int unum)
{
	struct userec newinfo;
	char    ans[3], buf[STRLEN], genbuf[128];
	char    src[STRLEN], dst[STRLEN];
	int     i, fail = 0 ;
#ifdef MAILCHANGED

	int    netty_check = 0;
#endif

	time_t  now;
	struct tm *tmnow;
	memcpy(&newinfo, u, sizeof(currentuser));
	getdata(t_lines - 1, 0, real ?
	        "��ѡ�� (0)���� (1)�޸����� (2)�趨���� (3) �� ID ==> [0]" :
	        "��ѡ�� (0)���� (1)�޸����� (2)�趨���� (3) ѡǩ���� ==> [0]",
	        ans, 2, DOECHO, YEA);
	clear();
	refresh();
	now = time(0);
	tmnow = localtime(&now);

	i = 3;
	move(i++, 0);
	if (ans[0] != '3' || real)
		prints("ʹ���ߴ���: %s\n", u->userid);
	switch (ans[0])
	{
	case '1':
		move(1, 0);
		prints("�������޸�,ֱ�Ӱ� <ENTER> ����ʹ�� [] �ڵ����ϡ�\n");
		sprintf(genbuf, "�dz� [%s]: ", u->username);
		getdata(i++, 0, genbuf, buf, NAMELEN, DOECHO, YEA);
		if (buf[0])
			strncpy(newinfo.username, buf, NAMELEN);

		sprintf(genbuf, "��ʵ���� [%s]: ", u->realname);
		getdata(i++, 0, genbuf, buf, NAMELEN, DOECHO, YEA);
		if (buf[0])
			strncpy(newinfo.realname, buf, NAMELEN);

		sprintf(genbuf, "��ס��ַ [%s]: ", u->address);
		getdata(i++, 0, genbuf, buf, STRLEN - 10, DOECHO, YEA);
		if (buf[0])
			strncpy(newinfo.address, buf, NAMELEN);

		sprintf(genbuf, "�������� [%s]: ", u->email);
		getdata(i++, 0, genbuf, buf, 48, DOECHO, YEA);
		if (buf[0])
		{
#ifdef MAILCHECK
#ifdef MAILCHANGED
			if(u->uid == usernum)
				netty_check = 1;
#endif
#endif

			strncpy(newinfo.email, buf, 48);
		}

		sprintf(genbuf, "�ն˻���̬ [%s]: ", u->termtype);
		getdata(i++, 0, genbuf, buf, 16, DOECHO, YEA);
		if (buf[0])
			strncpy(newinfo.termtype, buf, 16);

		sprintf(genbuf, "������ [%d]: ", u->birthyear + 1900);
		getdata(i++, 0, genbuf, buf, 5, DOECHO, YEA);
		if (   buf[0] && atoi(buf) > 1920 && atoi(buf) < 1998)
			newinfo.birthyear = atoi(buf) - 1900;

		sprintf(genbuf, "������ [%d]: ", u->birthmonth);
		getdata(i++, 0, genbuf, buf, 3, DOECHO, YEA);
		if (buf[0] && atoi(buf) >= 1 && atoi(buf) <= 12)
			newinfo.birthmonth = atoi(buf);

		sprintf(genbuf, "������ [%d]: ", u->birthday);
		getdata(i++, 0, genbuf, buf, 3, DOECHO, YEA);
		if (buf[0] && atoi(buf) >= 1 && atoi(buf) <= 31)
			newinfo.birthday = atoi(buf);

		sprintf(genbuf, "�Ա�(M.��)(F.Ů) [%c]: ", u->gender);
		getdata(i++, 0, genbuf, buf, 2, DOECHO, YEA);
		if (buf[0])
		{
			if (strchr("MmFf", buf[0]))
				newinfo.gender = toupper(buf[0]);
		}

		if (real)
			uinfo_change1(i,u,&newinfo);
		break;
	case '2':
		if (!real)
		{
			getdata(i++, 0, "������ԭ����: ", buf, PASSLEN, NOECHO, YEA);
			if (*buf == '\0' || !checkpasswd(u->passwd, buf))
			{
				prints("\n\n�ܱ�Ǹ, ����������벻��ȷ��\n");
				fail++;
				break;
			}
		}
		getdata(i++, 0, "���趨������: ", buf, PASSLEN, NOECHO, YEA);
		if (buf[0] == '\0')
		{
			prints("\n\n�����趨ȡ��, ����ʹ�þ�����\n");
			fail++;
			break;
		}
		strncpy(genbuf, buf, PASSLEN);
		getdata(i++, 0, "����������������: ", buf, PASSLEN, NOECHO, YEA);
		if (strncmp(buf, genbuf, PASSLEN))
		{
			prints("\n\n������ȷ��ʧ��, �޷��趨�����롣\n");
			fail++;
			break;
		}
		buf[8] = '\0';
		strncpy(newinfo.passwd, genpasswd(buf), ENCPASSLEN);
		break;
	case '3':
		if (!real)
		{
			sprintf(genbuf, "Ŀǰʹ��ǩ���� [%d]: ", u->signature);
			getdata(i++, 0, genbuf, buf, 16, DOECHO, YEA);
			if (atoi(buf) > 0)
				newinfo.signature = atoi(buf);
		}
		else
		{
			struct user_info uin;
			extern int t_cmpuids();
			if(t_search_ulist(&uin, t_cmpuids, unum, NA, NA)!=0)
			{
				prints("\n�Բ��𣬸��û�Ŀǰ�������ϡ�");
				fail++;
			}
			else if(!strcmp(lookupuser.userid,"SYSOP"))
			{
				prints("\n�Բ����㲻�����޸� SYSOP �� ID��");
				fail++;
			}
			else
			{
				getdata(i++,0,"�µ�ʹ���ߴ���: ",genbuf,IDLEN+1,DOECHO, YEA);
				if (*genbuf != '\0')
				{
					if (getuser(genbuf))
					{
						prints("\n�Բ���! �Ѿ���ͬ�� ID ��ʹ����\n");
						fail++;
					}
					else
					{
						strncpy(newinfo.userid, genbuf, IDLEN + 2);
					}
				}
				else
					fail ++;
			}
		}
		break;
	default:
		clear();
		return 0;
	}
	if (fail != 0)
	{
		pressreturn();
		clear();
		return 0;
	}
	if (askyn("ȷ��Ҫ�ı���", NA, YEA) == YEA)
	{
		if (real)
		{
			char    secu[STRLEN];
			sprintf(secu, "�޸� %s �Ļ������ϻ����롣", u->userid);
			securityreport1(secu);
		}
		if (strcmp(u->userid, newinfo.userid))
		{
			sprintf(src, "mail/%c/%s", toupper(u->userid[0]), u->userid);
			sprintf(dst, "mail/%c/%s", toupper(newinfo.userid[0]), newinfo.userid);
			rename(src, dst);
			sethomepath(src, u->userid);
			sethomepath(dst, newinfo.userid);
			rename(src, dst);
			sethomefile(src, u->userid, "register");
			unlink(src);
			sethomefile(src, u->userid, "register.old");
			unlink(src);
			setuserid(unum, newinfo.userid);
		}
		if(!strcmp(u->userid, currentuser.userid))
		{
			extern int WishNum;
			strncpy(uinfo.username,newinfo.username,NAMELEN);
			WishNum = 9999;
		}
#ifdef MAILCHECK
#ifdef MAILCHANGED
		if ((netty_check == 1)&&!HAS_PERM(PERM_SYSOP))
		{
			sprintf(genbuf, "%s", BBSHOST);
			if ( (!strstr(newinfo.email, genbuf)) &&
			        (!invalidaddr(newinfo.email)) &&
			        (!invalid_email(newinfo.email)))
			{
				strcpy(u->email, newinfo.email);
				send_regmail(u);
			}
			else
			{
				move(t_lines - 5, 0);
				prints("\n������ĵ����ʼ���ַ ��%s��\n",newinfo.email);
				prints("ˡ���ܱ�վ���ϣ�ϵͳ����Ͷ��ע���ţ������������...\n");
				pressanykey();
				return 0;
			}
		}
#endif
#endif
		memcpy(u, &newinfo, (size_t)sizeof(currentuser));
#ifdef MAILCHECK
#ifdef MAILCHANGED

		if ((netty_check == 1)&&!HAS_PERM(PERM_SYSOP))
		{
			newinfo.userlevel &= ~(PERM_LOGINOK | PERM_PAGE | PERM_MESSAGE);
			sethomefile(src, newinfo.userid, "register");
			sethomefile(dst, newinfo.userid, "register.old");
			rename(src, dst);
		}
#endif
#endif
		substitute_record(PASSFILE, &newinfo, sizeof(newinfo), unum);
	}
	clear();
	return 0;
}
コード例 #16
0
ファイル: announce.c プロジェクト: Fdhvdu/pttbbs
int
a_menu_rec(const char *maintitle, const char *path,
	int lastlevel, int lastbid,
	char *trans_buffer,
	a_menu_session_t *sess,
	const int *preselect,
	// we don't change root's value (but may change root pointer)
	// we may   change parent's value (but never change parent pointer)
	const menu_t *root, menu_t* const parent)
{
    menu_t          me = {0};
    char            fname[PATHLEN];
    int             ch, returnvalue = FULLUPDATE;

    assert(sess);

    // prevent deep resursive directories
    if (strlen(path) + FNLEN >= PATHLEN)
    {
	// it is not save to enter such directory.
	return returnvalue;
    }

    if(trans_buffer)
	trans_buffer[0] = '\0';

    if (parent)
    {
	parent->next = &me;
    } else {
	assert(root == NULL);
	root = &me;
    }

    me.header_size = p_lines;
    me.header = (fileheader_t *) calloc(me.header_size, FHSZ);
    me.path = path;
    strlcpy(me.mtitle, maintitle, sizeof(me.mtitle));
    setadir(fname, me.path);
    me.num = get_num_records(fname, FHSZ);
    me.bid = lastbid;

    /* 精華區-tree 中部份結構屬於 cuser ==> BM */

    if (!(me.level = lastlevel)) {
	char           *ptr;

	// warning: this is only valid for me.level.
	// is_uBM should not do anything except returning test result:
	// for ex, setting user BM permission automatically.
	// such extra behavior will result in any sub-op to have PERM_BM
	// ability, which leads to entering BM board without authority.
	// Thanks to mtdas@ptt for reporting this exploit.
	if (HasBasicUserPerm(PERM_LOGINOK) &&
            !HasUserPerm(PERM_NOCITIZEN) &&
            (ptr = strrchr(me.mtitle, '[')))
	    me.level = is_uBM(ptr + 1, cuser.userid);
    }
    me.page = A_INVALID_PAGE;

    if (preselect && !*preselect)
	preselect = NULL;

    me.now = preselect ? (*preselect -1) : 0;

    for (;;) {
	if (me.now >= me.num)
	    me.now = me.num - 1;
	if (me.now < 0)
	    me.now = 0;

	if (me.now < me.page || me.now >= me.page + me.header_size) {
	    me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ?
				(p_lines / 2) : (me.now % p_lines));
	    if (!a_showmenu(&me))
	    {
		// some directories are invalid, restart!
		sess->bReturnToRoot = 1;
		break;
	    }
	}

	if (preselect && *preselect && preselect[1])
	{
	    // if this is not the last preselect entry, enter it
	    ch = KEY_ENTER;
	} else {
	    ch = cursor_key(2 + me.now - me.page, 0);
	}

	if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
	    break;

	// TODO maybe we should let 1-9=simple search and z=tree-search
	// TODO or let 'z' prefix means 'back to root'
	if ((ch >= '1' && ch <= '9') || (ch == 'z' || ch == 'Z')) {
	    int n = a_multi_search_num(ch, sess);
	    me.page = A_INVALID_PAGE;
	    if (n > 0)
	    {
		// simple (single) selection
		me.now = n-1;
		me.page = 10000; // I don't know what's the magic value 10000...
	    }
	    else if (n == 0 && sess->z_indexes[0] == 0)
	    {
		// empty/invalid input
	    }
	    else
	    {
		// n == 0 with multiple selects
		preselect = sess->z_indexes;
		if (*preselect < 0)
		{
		    // return to root first?
		    if (parent)
		    {
			sess->bReturnToRoot = 1;
			return DONOTHING;
		    }

		    // already in root
		    preselect ++;
		}

		// handle first preselect (maybe zero due to previous 'already in root')
		if (*preselect > 0)
		    me.now = *preselect - 1;
		else
		    preselect = NULL;
	    }
	    continue;
	}
	switch (ch) {
	case KEY_UP:
	case 'k':
	    if (--me.now < 0)
		me.now = me.num - 1;
	    break;

	case KEY_DOWN:
	case 'j':
	    if (++me.now >= me.num)
		me.now = 0;
	    break;

	case KEY_PGUP:
	case Ctrl('B'):
	    if (me.now >= p_lines)
		me.now -= p_lines;
	    else if (me.now > 0)
		me.now = 0;
	    else
		me.now = me.num - 1;
	    break;

	case ' ':
	case KEY_PGDN:
	case Ctrl('F'):
	    if (me.now < me.num - p_lines)
		me.now += p_lines;
	    else if (me.now < me.num - 1)
		me.now = me.num - 1;
	    else
		me.now = 0;
	    break;

	case KEY_HOME:
	case '0':
	    me.now = 0;
	    break;
	case KEY_END:
	case '$':
	    me.now = me.num - 1;
	    break;

	case '?':
	case '/':
	    if(me.num) {
		me.now = a_searchtitle(&me, ch == '?');
		me.page = A_INVALID_PAGE;
	    }
	    break;
	case 'h':
	    a_showhelp(me.level);
	    me.page = A_INVALID_PAGE;
	    break;

	case Ctrl('W'):
	    a_where_am_i(root, me.now, me.header[me.now - me.page].title);
	    vmsg(NULL);
	    me.page = A_INVALID_PAGE;
	    break;

	case 'e':
	case 'E':
	    snprintf(fname, sizeof(fname),
		     "%s/%s", path, me.header[me.now - me.page].filename);
	    if (dashf(fname) && me.level >= MANAGER) {
		int edflags = 0;
		*quote_file = 0;

# ifdef BN_BBSMOVIE
		if (me.bid && strcmp(getbcache(me.bid)->brdname,
			    BN_BBSMOVIE) == 0)
		{
		    edflags |= EDITFLAG_UPLOAD;
		    edflags |= EDITFLAG_ALLOWLARGE;
		}
# endif // BN_BBSMOVIE

		if (vedit2(fname, NA, NULL, edflags) != -1) {
		    char            fpath[PATHLEN];
		    fileheader_t    fhdr;
		    strlcpy(fpath, path, sizeof(fpath));
		    stampfile(fpath, &fhdr);
		    unlink(fpath);
		    strlcpy(fhdr.filename,
			    me.header[me.now - me.page].filename,
			    sizeof(fhdr.filename));
		    strlcpy(me.header[me.now - me.page].owner,
			    cuser.userid,
			    sizeof(me.header[me.now - me.page].owner));
		    setadir(fpath, path);
		    substitute_record(fpath, me.header + me.now - me.page,
				      sizeof(fhdr), me.now + 1);

		}
		me.page = A_INVALID_PAGE;
	    }
	    break;

	case 't':
	case 'c':
	    if (me.now < me.num) {
		if (!isvisible_man(&me))
		    break;

		snprintf(fname, sizeof(fname), "%s/%s", path,
			 me.header[me.now - me.page].filename);

		/* XXX: dirty fix
		   應該要改成如果發現該目錄裡面有隱形目錄的話才拒絕.
		   不過這樣的話須要整個搜一遍, 而且目前判斷該資料是目錄
		   還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b
		   須等該資料寫入 .DIR 內再 implement才有效率.
		 */
		if( !me.level && !HasUserPerm(PERM_SYSOP) &&
		    (me.bid==0 || !is_BM_cache(me.bid)) && dashd(fname) )
		    vmsg("只有板主才可以拷貝目錄唷!");
		else
		    a_copyitem(fname, me.header[me.now - me.page].title, 0, 1);
		me.page = A_INVALID_PAGE;
		/* move down */
		if (++me.now >= me.num)
		    me.now = 0;
		break;
	    }
	case KEY_ENTER:
	case KEY_RIGHT:
	case 'r':
	    if (me.now >= me.num || me.now < 0)
	    {
		preselect = NULL;
		continue;
	    }
	    else
	    {
		fileheader_t   *fhdr = &me.header[me.now - me.page];
		const int *newselect = preselect ? preselect+1 : NULL;
		preselect = NULL;

		if (!isvisible_man(&me))
		    break;
#ifdef DEBUG
		vmsgf("%s/%s", &path[11], fhdr->filename);;
#endif
		snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename);
		if (dashf(fname)) {
		    int             more_result;

		    while ((more_result = more(fname, YEA))) {
			/* Ptt 範本精靈 plugin */
			if (trans_buffer &&
				(currstat == EDITEXP || currstat == OSONG)) {
			    char            ans[4];

			    move(22, 0);
			    clrtoeol();
			    getdata(22, 1,
				    currstat == EDITEXP ?
				    "要把範例加入到文章內嗎?[y/N]" :
				    "確定要選這篇嗎?[y/N]",
				    ans, sizeof(ans), LCECHO);
			    if (ans[0] == 'y') {
				strlcpy(trans_buffer, fname, PATHLEN);
				sess->bReturnToRoot = 1;
				if (currstat == OSONG) {
				    log_filef(FN_USSONG, LOG_CREAT, "%s\n", fhdr->title);
				}
				free(me.header);
				return FULLUPDATE;
			    }
			}
			if (more_result == READ_PREV) {
			    if (--me.now < 0) {
				me.now = 0;
				break;
			    }
			} else if (more_result == READ_NEXT) {
			    if (++me.now >= me.num) {
				me.now = me.num - 1;
				break;
			    }
			    /* we only load me.header_size pages */
			    if (me.now - me.page >= me.header_size)
				break;
			} else
			    break;
			if (!isvisible_man(&me))
			    break;
			snprintf(fname, sizeof(fname), "%s/%s", path,
				 me.header[me.now - me.page].filename);
			if (!dashf(fname))
			    break;
		    }
		} else if (dashd(fname)) {
		    returnvalue = a_menu_rec(me.header[me.now - me.page].title, fname,
			    me.level, me.bid, trans_buffer,
			    sess, newselect, root, &me);

		    if (returnvalue == DONOTHING)
		    {
			// DONOTHING will only be caused by previous a_multi_search_num + preselect.
			assert(sess->bReturnToRoot);

			if (!parent)
			{
			    // we've reached root menu!
			    assert(sess->z_indexes[0] == -1);
			    sess->bReturnToRoot = 0;
			    returnvalue = FULLUPDATE;
			    preselect = sess->z_indexes+1;  // skip first 'return to root'
			    if (*preselect > 0)
				me.now = *preselect-1;
			}
		    } else  {
			returnvalue = FULLUPDATE;
		    }

		    me.next = NULL;
		    /* Ptt  強力跳出recursive */
		    if (sess->bReturnToRoot) {
			free(me.header);
			return returnvalue;
		    }
		}
		me.page = A_INVALID_PAGE;
	    }
	    break;

	case 'F':
	case 'U':
	    if (me.now < me.num) {
                fileheader_t   *fhdr = &me.header[me.now - me.page];
                if (!isvisible_man(&me))
                    break;
		snprintf(fname, sizeof(fname),
			 "%s/%s", path, fhdr->filename);
		if (HasBasicUserPerm(PERM_LOGINOK) && dashf(fname)) {
		    a_forward(path, fhdr, ch /* == 'U' */ );
		    /* By CharlieL */
		} else
		    vmsg("無法轉寄此項目");
		me.page = A_INVALID_PAGE;
	    }

	    break;

	}

	if (me.level >= MANAGER) {
	    switch (ch) {
	    case 'n':
		a_newitem(&me, ADDITEM);
		me.page = A_INVALID_PAGE;
		break;
	    case 'g':
		a_newitem(&me, ADDGROUP);
		me.page = A_INVALID_PAGE;
		break;
	    case 'p':
		a_pasteitem(&me, 1);
		me.page = A_INVALID_PAGE;
		break;
	    case 'f':
		a_editsign(&me);
		me.page = A_INVALID_PAGE;
		break;
	    case Ctrl('P'):
		a_pastetagpost(&me, -1);
		returnvalue = DIRCHANGED;
		me.page = A_INVALID_PAGE;
		break;
	    case Ctrl('A'):
		a_pastetagpost(&me, 1);
		returnvalue = DIRCHANGED;
		me.page = A_INVALID_PAGE;
		break;
	    case 'a':
		a_appenditem(&me, 1);
		me.page = A_INVALID_PAGE;
		break;
	    }

	    if (me.num)
		switch (ch) {
		case 'm':
		    a_moveitem(&me);
		    me.page = A_INVALID_PAGE;
		    break;

		case 'D':
		    /* Ptt me.page = -1; */
		    a_delrange(&me, sess->backup_dir);
		    me.page = A_INVALID_PAGE;
		    break;
		case 'd':
		    a_delete(&me, sess->backup_dir);
		    me.page = A_INVALID_PAGE;
		    break;
		case 'H':
		    a_hideitem(&me);
		    me.page = A_INVALID_PAGE;
		    break;
		case 'T':
		    a_newtitle(&me);
		    me.page = A_INVALID_PAGE;
		    break;
#ifdef CHESSCOUNTRY
		case 'L':
		    a_setchesslist(&me);
		    break;
#endif
		}
	}
	if (me.level >= SYSOP) {
	    switch (ch) {
	    case 'N':
		a_showname(&me);
		me.page = A_INVALID_PAGE;
		break;
	    }
	}
    }
    free(me.header);
    return returnvalue;
}
コード例 #17
0
ファイル: maintain.c プロジェクト: madoldman/inankai_bbs
int scan_register_form(char* regfile)
{
    static char *field[] = {"usernum", "userid", "realname", "dept",
                            "addr", "phone", "regip", NULL
                           };
    static char *finfo[] = {"帐号位置", "申请帐号", "真实姓名", "学校系级",
                            "目前住址", "连络电话", "注册ip  ", NULL
                           };
    static char *reason[] = {"请确实填写真实姓名(不可使用拼音).",
                             "请详填学校院系与年级 (注明系和年级或者工作单位和工作部门).",
                             "请填写完整的住址资料 (完整详细,能够通信).",
                             "请详填连络电话 (固定电话需填写区号).",
                             "请勿穿梭注册.",
                             "请如实详细填写注册申请表.",
                             "请用中文填写申请表.",
                             "同一个用户注册了过多ID.", NULL
                            };
    struct userec uinfo;
    FILE   *fn, *fout, *freg;
    char    fdata[7][STRLEN];
    char    fname[STRLEN], buf[STRLEN];
    char    ans[5], *ptr, *uid;
    int     n, unum;
    uid = currentuser.userid;
    char numofreason[2];//tdhlshx for refuse.
    int total;
    int iis;
    int realnumofrea[8];//add end

    stand_title("依序设定所有新注册资料");
    sprintf(fname, "%s.tmp", regfile);
    move(2, 0);
    if (dashf(fname))
    {
        move(1, 0);
        prints("其他 SYSOP 正在查看注册申请单, 请检查使用者状态.\n");
        getdata(2, 0, "你确定没有其他 SYSOP 在审核注册单吗 ? [y/N]: ", ans, 2, DOECHO, YEA);
        if (ans[0] == 'Y' || ans[0] == 'y')
            f_cp(fname, regfile, O_APPEND);
        else
        {
            pressreturn();
            return -1;
        }
    }
    rename(regfile, fname);
    if ((fn = fopen(fname, "r")) == NULL)
    {
        move(2, 0);//请管理员输入未通过原因:
        prints("系统错误, 无法读取注册资料档: %s\n", fname);
        pressreturn();
        return -1;
    }
    memset(fdata, 0, sizeof(fdata));
    while (fgets(genbuf, STRLEN, fn) != NULL)
    {
        if ((ptr = (char *) strstr(genbuf, ": ")) != NULL)
        {
            *ptr = '\0';
            for (n = 0; field[n] != NULL; n++)
            {
                if (strcmp(genbuf, field[n]) == 0)
                {
                    strcpy(fdata[n], ptr + 2);
                    if ((ptr = (char *) strchr(fdata[n], '\n')) != NULL)
                        *ptr = '\0';
                }
            }
        }
        else if ((unum = getuser(fdata[1])) == 0)
        {
            move(2, 0);
            clrtobot();
            prints("系统错误, 查无此帐号.\n\n");
            for (n = 0; field[n] != NULL; n++)
                prints("%s     : %s\n", finfo[n], fdata[n]);
            pressreturn();
            memset(fdata, 0, sizeof(fdata));
        }
        else
        {
            memcpy(&uinfo, &lookupuser, sizeof(uinfo));
            move(1, 0);
            prints("帐号位置     : %d\n", unum);
            disply_userinfo(&uinfo);
            move(15, 0);
            printdash(NULL);
            for (n = 0; field[n] != NULL; n++)
                prints("%s     : %s\n", finfo[n], fdata[n]);
            if (uinfo.userlevel & PERM_LOGINOK)
            {
                move(t_lines - 1, 0);
                prints("此帐号不需再填写注册单.\n");
                igetkey();
                ans[0] = 'D';
            }
            else
            {
                getdata(t_lines - 1, 0, "是否接受此资料 (Y/N/Q/Del/Skip)? [S]: ",
                        ans, 3, DOECHO, YEA);
            }
            move(1, 0);
            clrtobot();
            switch (ans[0])
            {
            case 'D':
            case 'd':
                break;
            case 'Y':
            case 'y':
                prints("以下使用者资料已经更新:\n");
                n = strlen(fdata[5]);
                if (n + strlen(fdata[3]) > 60)
                {
                    if (n > 40)
                        fdata[5][n = 40] = '\0';
                    fdata[3][60 - n] = '\0';
                }
                strncpy(uinfo.realname, fdata[2], NAMELEN);
                strncpy(uinfo.address, fdata[4], NAMELEN);
                sprintf(genbuf, "%s$%s@%s", fdata[3], fdata[5], uid);
                genbuf[STRLEN - 16] = '\0';
                strncpy(uinfo.reginfo, genbuf, STRLEN - 17);
#ifdef ALLOWGAME

                uinfo.money = 1000;
#endif

                uinfo.lastjustify = time(0);
                substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
                sethomefile(buf, uinfo.userid, "register");
                if (dashf(buf))
                {
                    sethomefile(genbuf, uinfo.userid, "register.old");
                    rename(buf, genbuf);
                }
                if ((fout = fopen(buf, "w")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(fout, "%s: %s\n", field[n], fdata[n]);
                    n = time(NULL);
                    getdatestring(n,NA);
                    fprintf(fout, "Date: %s\n", datestring);
                    fprintf(fout, "Approved: %s\n", uid);
                    fclose(fout);
                }
                mail_file("etc/s_fill", uinfo.userid, "恭禧你,你已经完成注册。");
                mail_file("etc/fornewcomers",uinfo.userid,"欢迎加入 "BBSNAME" 大家庭");//tdhlshx 新手FAQ信件
                sethomefile(buf, uinfo.userid, "mailcheck");
                unlink(buf);
                sprintf(genbuf, "让 %s 通过身份确认.", uinfo.userid);
                securityreport4(genbuf);
                break;
            case 'Q':
            case 'q':
                if ((freg = fopen(regfile, "a")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(freg, "%s: %s\n", field[n], fdata[n]);
                    fprintf(freg, "----\n");
                    while (fgets(genbuf, STRLEN, fn) != NULL)
                        fputs(genbuf, freg);
                    fclose(freg);
                }
                break;
            case 'N':
            case 'n':
                for(total=0; total<8; total++)
                    realnumofrea[total]=0;
                for (n = 0; field[n] != NULL; n++)
                    prints("%s: %s\n", finfo[n], fdata[n]);
                printdash(NULL);
                move(9, 0);
                prints("请依次输入退回申请表原因的序号并回车确认,直接回车结束.\n\n");
                //	prints("请选择/输入退回申请表原因, 按 <enter> 取消.\n\n");
                for (n = 0; reason[n] != NULL; n++)
                    prints("%d) %s\n", n, reason[n]);
                getdata(12+n,0,"退回原因:",numofreason,2,DOECHO,YEA);
                //	getdata(12 + n, 0, "退回原因: ", buf, 60, DOECHO, YEA);
                if(numofreason[0]!='\0'&&numofreason[0]>='0'&&numofreason[0]<='7')
                {
                    total=atoi(numofreason);
                    realnumofrea[total]=1;
                    move(14+n,0);
                    prints("您已经选择的理由有:\n%d  ",total);
                }
                while(numofreason[0]!='\0')
                {
                    getdata(12+n,0,"退回原因:",numofreason,2,DOECHO,YEA);
                    if(numofreason[0]>='0'&&numofreason[0]<='7')
                    {
                        total=atoi(numofreason);
                        if(realnumofrea[total]==0)
                            realnumofrea[total]=1;
                        else
                            realnumofrea[total]=0;
                        move(14+n,0);
                        clrtobot();
                        prints("您已经选择的理由有:\n");
                        for(iis=0; iis<8; iis++)
                        {
                            if(realnumofrea[iis]==1)
                                prints("%d  ",iis);
                        }
                    }
                }
                system("cp /home/bbs/etc/f_fill  /home/bbs/tmp/fletter");
                char FL[STRLEN];
                sprintf(FL,"/home/bbs/tmp/fletter");
                FILE * fail=fopen(FL,"a");
                if(fail==NULL)
                {
                    prints("Error,创建临时文件错误.请与系统维护联系或再次尝试!");
                    pressanykey();
                    return -1;
                }

                {
                    fprintf(fail,"\n\n您被拒绝注册的原因大概如下:\n");
                    for(total=0; total<8; total++)
                    {
                        if(realnumofrea[total]==1)
                        {
                            strcpy(buf,reason[total]);
                            fprintf(fail,"\n%s",buf);
                        }
                    }
                    sprintf(genbuf,"很抱歉的告诉您,您这次注册失败.:(");
                    strncpy(uinfo.address, genbuf, NAMELEN);
                    substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
                    fclose(fail);
                    mail_file(FL,uinfo.userid, uinfo.address);
                    system("rm -f /home/bbs/tmp/fletter");

                }
                break;
            /*if (buf[0] != '\0') {
            if (buf[0] >= '0' && buf[0] < '0' + n) {
            	strcpy(buf, reason[buf[0] - '0']);
            }
            sprintf(genbuf, "<注册失败> - %s", buf);
            strncpy(uinfo.address, genbuf, NAMELEN);
            substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
            mail_file("etc/f_fill", uinfo.userid, uinfo.address);*/
            /* user_display( &uinfo, 1 ); */
            /* pressreturn(); */
            /*	break;
            }
            move(10, 0);
            clrtobot();
            prints("取消退回此注册申请表.\n");*/
            /* run default -- put back to regfile */
            default:
                if ((freg = fopen(regfile, "a")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(freg, "%s: %s\n", field[n], fdata[n]);
                    fprintf(freg, "----\n");
                    fclose(freg);
                }
            }
            memset(fdata, 0, sizeof(fdata));
        }
    }
    fclose(fn);
    unlink(fname);
    return (0);
}
コード例 #18
0
ファイル: vote.c プロジェクト: phoenixgao/fdubbs
int b_notes_edit()
{
	char buf[STRLEN], buf2[STRLEN];
	char ans[4];
	int aborted;
	int notetype;

	if (!chkBM(currbp, &currentuser))
		return 0;
	clear();
	move(0, 0);
	prints("�趨��\n\n  (1)һ�㱸��¼\n  (2)���ܱ���¼\n");
	prints("  (3)����ǰ׺��\n  (4)�Ƿ�ǿ��ʹ��ǰ׺\n");
	while (1) {
		getdata(7, 0,"��ǰѡ��[1](0~4): ", ans, 2, DOECHO, YEA);
		if (ans[0] == '0')
		return FULLUPDATE;
		if (ans[0] == '\0')
		strcpy(ans, "1");
		if (ans[0] >= '1' && ans[0] <= '4' )
		break;
	}
	makevdir(currboard); //��������¼Ŀ¼
	notetype = ans[0] - '0';
	if (notetype == 2) {
		setvfile(buf, currboard, "secnotes");
	} else if (notetype == 3) {
		setvfile(buf, currboard, "prefix");
	} else if (notetype == 1) {
		setvfile(buf, currboard, "notes");
	} else if (notetype == 4 ) {
		int pos;
		struct boardheader fh;
		pos = search_record(BOARDS, &fh, sizeof(fh), cmpbnames, currboard);

		if (askyn("�Ƿ�ǿ��ʹ��ǰ׺��", (fh.flag & BOARD_PREFIX_FLAG)?YEA:NA,NA)) {
			fh.flag |= BOARD_PREFIX_FLAG;
		} else {
			fh.flag &= ~BOARD_PREFIX_FLAG;
		}
		substitute_record(BOARDS, &fh, sizeof(fh), pos);
		return FULLUPDATE;
	}
	sprintf(buf2, "(E)�༭ (D)ɾ�� %4s? [E]: ",
			(notetype == 3)?"����ǰ׺��":(notetype == 1) ? "һ�㱸��¼" : "���ܱ���¼");
	getdata(8, 0, buf2, ans, 2, DOECHO, YEA); //ѯ�ʱ༭����ɾ��
	if (ans[0] == 'D' || ans[0] == 'd') { //ɾ������¼
		move(9, 0);
		sprintf(buf2, "���Ҫɾ��ô��");
		if (askyn(buf2, NA, NA)) {
			move(10, 0);
			prints("�Ѿ�ɾ��...\n");
			pressanykey();
			unlink(buf);
			aborted = 1;
		} else
		aborted = -1;
	} else
	aborted = vedit(buf, NA, YEA); //�༭����¼
	if (aborted == -1) {
		pressreturn();
	} else {
		if (notetype == 1)
		setvfile(buf, currboard, "noterec");
		else
		setvfile(buf, currboard, "notespasswd");
		unlink(buf);
	}

	return FULLUPDATE;
}
コード例 #19
0
ファイル: ucache.c プロジェクト: phoenixgao/fdubbs
// Flushes cache for all users to PASSFILE.
int flush_ucache(void)
{
	return substitute_record(PASSFILE, uidshm->passwd,
			sizeof(uidshm->passwd), 1);
}
コード例 #20
0
ファイル: mbbsd.c プロジェクト: yrchen/Athena
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();
	}
コード例 #21
0
ファイル: userinfo.c プロジェクト: miminus/bmybbs
// ��username�û�ͨ����֤�� added by interma@BMY 2005.5.12
static void register_success(int usernum, char *userid, char *realname, char *dept, 
char *addr, char *phone, char *assoc, char *email)
{
	struct userec uinfo;
	FILE *fout, *fn;
	char buf[STRLEN];
	int n;

	//int id = getuser(userid);
	usernum = getuser(userid);

	setuserfile(genbuf, "mailcheck");
	if ((fn = fopen(genbuf, "w")) == NULL) {
		fclose(fn);
		return;
	}
	fprintf(fn, "usernum: %d\n", usernum);
	fclose(fn);

	memcpy(&uinfo, &lookupuser, sizeof (uinfo));

			strsncpy(uinfo.userid, userid,
				 sizeof (uinfo.userid));
			strsncpy(uinfo.realname, realname,
				 sizeof (uinfo.realname));
			strsncpy(uinfo.address, addr,
				 sizeof (uinfo.address));
			sprintf(genbuf, "%s$%s@%s", dept, phone, userid);
			strsncpy(uinfo.realmail, genbuf,
				 sizeof (uinfo.realmail));

			strsncpy(uinfo.email, email, sizeof (uinfo.email));

			uinfo.userlevel |= PERM_DEFAULT;	// by ylsdd
			substitute_record(PASSFILE, &uinfo, sizeof (struct userec), usernum);

			sethomefile(buf, uinfo.userid, "sucessreg");
			if ((fout = fopen(buf, "w")) != NULL) {
				fprintf(fout, "\n");
				fclose(fout);
			}

			sethomefile(buf, uinfo.userid, "register");
	
			if ((fout = fopen(buf, "w")) != NULL) 
			{
				
				fprintf(fout, "%s: %d\n", "usernum", usernum);
				fprintf(fout, "%s: %s\n", "userid", userid);
				fprintf(fout, "%s: %s\n", "realname", realname);
				fprintf(fout, "%s: %s\n", "dept", dept);
				fprintf(fout, "%s: %s\n", "addr", addr);
				fprintf(fout, "%s: %s\n", "phone", phone);
				fprintf(fout, "%s: %s\n", "assoc", assoc);

				n = time(NULL);
				fprintf(fout, "Date: %s",
					ctime((time_t *) & n));
				fprintf(fout, "Approved: %s\n", userid);
				fclose(fout);
			}

			mail_file("etc/s_fill", uinfo.userid,
				  "������ͨ�������֤"); // ����ط��и�覴ã����Ƿ�����Ϊ����

			mail_file("etc/s_fill2", uinfo.userid,
				  "��ӭ����" MY_BBS_NAME "���ͥ");
			sethomefile(buf, uinfo.userid, "mailcheck");
			unlink(buf);
			sprintf(genbuf, "�� %s ͨ�����ȷ��.", uinfo.userid);
			securityreport(genbuf, genbuf);

	return ;
}
コード例 #22
0
ファイル: toplazyBM.c プロジェクト: clkao/pttbbs
int main(int argc, char *argv[])
{
    int bmid, i, j=0;
    FILE *inf, *firef;
    time4_t now=time(NULL); 
    attach_SHM();
    resolve_boards();

    if(passwd_init())
	exit(1);      

    memcpy(allbrd,bcache,numboards*sizeof(boardheader_t));

    /* write out the target file */
    inf   = fopen(OUTFILE, "w+");
    if (inf == NULL) {
	printf("open file error : %s\n", OUTFILE);
	exit(1);
    }

    firef = fopen(FIREFILE, "w+");
    if (firef == NULL) {
	printf("open file error : %s\n", FIREFILE);
	exit(1);
    }

    fprintf(inf, "警告: 板主若超過(不包含) %d天未上站,將予於免職\n",
            LAZY_BM_LIMIT_DAYS);
    fprintf(inf,
	    "看板名稱                                           "
	    "    板主        幾天沒來啦\n"
	    "---------------------------------------------------"
	    "--------------------------\n");

    fprintf(firef, "免職板主\n");
    fprintf(firef,
	    "看板名稱                                           "
	    "    板主        幾天沒來啦\n"
	    "---------------------------------------------------"
	    "--------------------------\n"); 


    j = 0;
    for (i = 0; i < numboards; i++) {
	char *p, bmbuf[IDLEN * 3 + 3];
	int   index = 0, flag = 0, k, n;
	userec_t xuser;
	p = allbrd[i].BM;

	if (*p == '[') p++;
	if (allbrd[i].brdname[0] == '\0' ||
		!isalpha(allbrd[i].brdname[0])
	   ) continue;

	p = strtok(p,"/ ]");
	for(index=0; p && index<5; index++) {
	    int diff;
	    // XXX what if bmid is invalid?
	    if(!p[0] || (bmid = passwd_load_user(p, &xuser)) < 1) {
		index--;
		p=strtok(NULL,"/ ]");
		continue;
	    }
	    strlcpy(bms[index].bmname, p, sizeof(bms[index].bmname));
	    bms[index].flag = 0;

	    diff = now - xuser.lastlogin;
	    if (diff < 0)
		diff = 0;

	    if (diff >= 45 * 86400
		    && !(xuser.userlevel & PERM_SYSOPHIDE)
		    && !(xuser.userlevel & PERM_SYSOP)) {
		strlcpy(lostbms[j].bmname, p, sizeof(bms[index].bmname));
		lostbms[j].title = allbrd[i].brdname;
		lostbms[j].ctitle = allbrd[i].title;
		lostbms[j].lostdays = diff / 86400;

		//超過 LAZY_BM_LIMIT_DAYS 天 免職
		if (lostbms[j].lostdays > LAZY_BM_LIMIT_DAYS) {
		    xuser.userlevel &= ~PERM_BM;
		    bms[index].flag = 1;
		    flag = 1;
                    // NOTE: 好像不改也無所謂,目前拔 BM 是自動的。
		    passwd_update(bmid, &xuser);
		}
		j++;
	    }
	    p = strtok(NULL,"/ ]");
	}

	if (flag == 1) {
            boardheader_t *bp = getbcache(i+1);

            // 確認我們沒搞錯 cache. 如果 cache 炸了就別用了
            if (strcmp(bp->brdname, allbrd[i].brdname) != 0) {
                printf("ERROR: unmatched cache!!! (%s - %s)\n",
                        bp->brdname, allbrd[i].brdname);
                bp = NULL;
                exit(1);
                // sync to latest
                memcpy(&allbrd[i], bp, sizeof(boardheader_t));
            }

	    bmbuf[0] = '\0';
	    for (k = 0, n = 0; k < index; k++) {
		if (!bms[k].flag) {
		    if (n++ != 0) strcat(bmbuf, "/");
		    strcat(bmbuf, bms[k].bmname);
		}
	    }
	    strcpy(allbrd[i].BM, bmbuf);
            printf("board %s: %s -> %s\n",
                    allbrd[i].brdname, bp->BM, allbrd[i].BM);
            strcpy(bp->BM, allbrd[i].BM);
	    if (substitute_record(BBSHOME"/"FN_BOARD, &allbrd[i], 
			sizeof(boardheader_t), i+1) == -1) {
		printf("Update Board Failed: %s\n", allbrd[i].brdname);
	    }
	    reset_board(i+1);
	}
    }
    qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp);

    //write to the etc/toplazyBM
    for (i = 0; i < j; i++) {
	if (lostbms[i].lostdays > LAZY_BM_LIMIT_DAYS) {
	    fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n",
		    IDLEN, IDLEN, lostbms[i].title, BTLEN-10,
		    BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN,
		    lostbms[i].bmname,lostbms[i].lostdays);
	} else {
	    fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n",
		    IDLEN, IDLEN, lostbms[i].title, BTLEN-10,
		    BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN,
		    lostbms[i].bmname,lostbms[i].lostdays);
	}
    }
    fclose(inf);
    fclose(firef);

    //printf("Total %d boards.\n", count);

    //mail to the users
    for (i=0; i<j; i++) {
	fileheader_t mymail;
	char	genbuf[200];
	int	lostdays;

	lostdays = lostbms[i].lostdays;

	if (lostdays != LAZY_BM_LIMIT_DAYS/2 &&
            lostdays != LAZY_BM_LIMIT_DAYS*2/3 &&
            lostdays != LAZY_BM_LIMIT_DAYS*5/6 &&
            lostdays <= LAZY_BM_LIMIT_DAYS)
	    continue;

	sprintf(genbuf, BBSHOME "/home/%c/%s", 
		lostbms[i].bmname[0], lostbms[i].bmname);
	stampfile(genbuf, &mymail);

	strcpy(mymail.owner, "[" BBSMNAME "警察局]");
	if (lostdays <= LAZY_BM_LIMIT_DAYS)
	    sprintf(mymail.title,
		    ANSI_COLOR(32) "版主通知" ANSI_RESET " %s版版主%s",
		    lostbms[i].title, lostbms[i].bmname);
	else
	    sprintf(mymail.title,
		    ANSI_COLOR(32) "版主自動免職通知" ANSI_RESET " %s 版主 %s",
		    lostbms[i].title, lostbms[i].bmname);

	unlink(genbuf);
	if (lostdays <= LAZY_BM_LIMIT_DAYS)
	    Link(OUTFILE, genbuf);
	else
	    Link(FIREFILE, genbuf);

	sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", 
		lostbms[i].bmname[0], lostbms[i].bmname);
	append_record(genbuf, &mymail, sizeof(mymail)); 	
    }
    return 0;
}