Exemplo n.º 1
0
int bbsmybrd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	int type = strtol(getparm("type"), NULL, 10);
	if (type != 0)
		return read_submit();

	// Read '.goodbrd'.
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, ".goodbrd");
	mmap_t m;
	m.oflag = O_RDONLY;
	if (mmap_open(file, &m) < 0)
		return BBS_ENOFILE;
	struct goodbrdheader *iter, *end;
	int num = m.size / sizeof(struct goodbrdheader);
	if (num > GOOD_BRC_NUM)
		num = GOOD_BRC_NUM;
	end = (struct goodbrdheader *)m.ptr + num;

	// Print 'bid's of favorite boards.
	xml_header("bbs");
	printf("<bbsmybrd ");
	print_session();
	printf(" limit='%d'>", GOOD_BRC_NUM);
	for (iter = m.ptr; iter != end; iter++) {
		if (!gbrd_is_custom_dir(iter))
			printf("<my bid='%d'/>", iter->pos + 1);
	}
	mmap_close(&m);

	// Print all boards available.
	struct boardheader *b;
	for (int i = 0; i < MAXBOARD; i++) {
		b = bcache + i;
		if (b->filename[0] <= 0x20 || b->filename[0] > 'z')
			continue;
		if (!hasreadperm(&currentuser, b))
			continue;
		printf("<mbrd bid='%d' desc='%s' %s/>", i + 1, b->title + 11,
				is_board_dir(b) ? "dir='1'" : "");
	}
	printf("</bbsmybrd>");
	return 0;	
}
Exemplo n.º 2
0
void regmail_send(struct userec *trec, char* mail) {
	time_t code;
	FILE *fout, *dp, *mailp;
	char buf[RNDPASSLEN + 1];
	char mailuser[25], mailpass[25];
	sprintf(buf, "%s", (char *) genrandpwd((int) getpid()));
	sethomefile(genbuf, trec->userid, ".regpass");
	if ((dp = fopen(genbuf, "w")) == NULL)
		return;
	dp = fopen(genbuf, "w+");
	fprintf(dp, "%s\n", buf);
	fprintf(dp, "%s\n", mail);
	fclose(dp);

	code = time(0);
	sprintf(genbuf, "%s -f %s.bbs@%s %s", MTA, trec->userid, BBSHOST, mail);
	fout = popen(genbuf, "w");
	if (fout != NULL) {
		fprintf(fout, "Reply-To: SYSOP.bbs@%s\n", BBSHOST);
		fprintf(fout, "From: SYSOP.bbs@%s\n", BBSHOST);
		fprintf(fout, "To: %s\n", mail);
		fprintf(fout, "Subject: %s@%s mail check.\n", trec->userid, BBSID);
		fprintf(fout, "X-Purpose: %s registration mail.\n", BBSNAME);
		fprintf(fout, "\n");
		fprintf(fout, "[����]\n");
		fprintf(fout, "BBS λַ         : %s (%s)\n", BBSHOST, BBSIP);
		fprintf(fout, "��ע��� BBS ID  : %s\n", trec->userid);
		fprintf(fout, "��������         : %s", ctime(&trec->firstlogin));
		fprintf(fout, "������Դ         : %s\n", fromhost);
		fprintf(fout, "��֤��           : %s (��ע���Сд)\n", buf);
		fprintf(fout, "��֤�ŷ�������   : %s\n", ctime(&code));

		fprintf(fout, "[English]\n");
		fprintf(fout, "BBS LOCATION     : %s (%s)\n", BBSHOST, BBSIP);
		fprintf(fout, "YOUR BBS USER ID : %s\n", trec->userid);
		fprintf(fout, "APPLICATION DATE : %s", ctime(&trec->firstlogin));
		fprintf(fout, "LOGIN HOST       : %s\n", fromhost);
		fprintf(fout, "YOUR NICK NAME   : %s\n", trec->username);
		fprintf(fout, "VALID CODE       : %s (case sensitive)\n", buf);
		fprintf(fout, "THIS MAIL SENT ON: %s\n", ctime(&code));

		fprintf(fout, ".\n");
		fclose(fout);
	}

}
Exemplo n.º 3
0
int
postInvite(char *userid, char *inviter)
{
	struct userec *x, tmpu;
	char buf[256];
	FILE *fp;
	if (getuser(inviter, &x) <= 0)
		return -1;
	loadfriend(userid);
	if (friendnum < MAXFRIENDS - 1) {
		strsncpy(fff[friendnum].id, x->userid, sizeof (fff[0].id));
		strsncpy(fff[friendnum].exp, inviter, sizeof (fff[0].exp));
		friendnum++;
		sethomefile(buf, userid, "friends");
		fp = fopen(buf, "w");
		fwrite(fff, sizeof (struct override), friendnum, fp);
		fclose(fp);
	}
Exemplo n.º 4
0
static void
insertToFile(struct edit *edit)
{
	struct textLine *ln;
	char ans[3], *ptr, filename[STRLEN];
	int n, full = 0;
	FILE *fp;
	for (ln = edit->firstline; ln && !ln->selected; ln = ln->next) ;
	if (!ln) {
		ln = edit->firstline;
		full = 1;
		ptr = "把整篇文章写入剪贴簿第几页? (0-7) (Q 取消) [0]: ";
	} else
		ptr = "把标记块写入剪贴簿第几页? (0-7) (Q 取消) [0]: ";
	getdata(t_lines - 1, 0, ptr, ans, 2, DOECHO, YEA);
	if (ans[0] == 'Q')
		return;
	n = atoi(ans);
	if (n < 0 || n > 7)
		return;
	tracelog("user %s ip %s insert to clip %d", currentuser->userid,
			realfromhost, n);
	ans[0] = n + '0';
	ans[1] = 0;
	sethomefile(filename, currentuser->userid, "clip_");
	strcat(filename, ans);
	fp = fopen(filename, "w");
	if (!fp) {
		move(t_lines - 1, 0);
		prints("无法打开剪贴簿第 %s 页!\t\t\t", ans);
		igetkey();
		return;
	}
	while (ln && (full || ln->selected)) {
		fwrite(ln->text, 1, ln->len, fp);
		if (ln->br)
			fputc('\n', fp);
		ln = ln->next;
	}
	fclose(fp);
	move(t_lines - 1, 0);
	prints("已写入剪贴簿第 %s 页。\t\t\t", ans);
	igetkey();
}
Exemplo n.º 5
0
Arquivo: user.c Projeto: wtj/formosa
/*******************************************************************
 *	update user passwd file
 *	
 *******************************************************************/
void 
UpdateUserRec(int action, USEREC * curuser, BOARDHEADER * board)
{
	FILE *fp;
	char pathRec[PATHLEN];

	if (!strcmp(curuser->userid, "guest")
#ifdef NSYSUBBS
	|| !strcmp(curuser->userid, "supertomcat")
#endif	
	)
		return;

	if (difftime(request_rec->atime, curuser->lastlogin) > (double) RELOGIN_INTERVAL)
	{
		curuser->numlogins++;
		if (curuser->userlevel < PERM_NORMAL)
			curuser->userlevel++;
	}

	if (curuser->userlevel < 0 || curuser->userlevel > PERM_SYSOP)	/* debug */
		curuser->userlevel = PERM_NORMAL;

	if (action == PostSend && !(board->brdtype & BRD_NOPOSTNUM))
		curuser->numposts++;

	curuser->lastlogin = request_rec->atime;
	curuser->lastctype = CTYPE_WEBBBS;
	xstrncpy(curuser->lasthost, request_rec->fromhost, HOSTLEN);
	update_passwd(curuser);

	sethomefile(pathRec, curuser->userid, UFNAME_RECORDS);
	if ((fp = fopen(pathRec, "a")) != NULL)
	{
		fprintf(fp, "%s %s", request_rec->fromhost, ctime(&(request_rec->atime)));
		fclose(fp);
	}

#if 0
	log_visitor(curuser->userid, request_rec->fromhost, request_rec->atime,
		    CTYPE_WEBBBS, FALSE);
#endif

}
Exemplo n.º 6
0
static int
_iter_paste_tag(void *item, void *optarg) {
    char buf[PATHLEN];
    char title[TTLEN + 1] = "◇  ";
    fileheader_t *fhdr = (fileheader_t*) item;
    _iter_paste_tag_param *param = (_iter_paste_tag_param*) optarg;

    param->item ++;
    // XXX many process crashed here as fhdr.filename[0] == 0
    // let's workaround it? or trace?
    if (!fhdr->filename[0])
    {
        grayout(0, b_lines-2, GRAYOUT_DARK);
        move(b_lines-1, 0); clrtobot();
        prints("處理 #%d 項發生錯誤。 請把你剛剛進行的完整步驟貼到 "
                BN_BUGREPORT " 板。\n", param->item);
        vmsg("忽略錯誤並繼續進行。");
        return 0;
    }

    if (!FindTaggedItem(fhdr))
        return 0;

    if (TagBoard == 0)
        sethomefile(buf, cuser.userid, fhdr->filename);
    else {
        setbfile(buf, param->bh->brdname, fhdr->filename);
    }

    if (!dashf(buf))
        return 0;

    strlcpy(title + 3, fhdr->title, sizeof(title) - 3);
    a_copyitem(buf, title, 0, 0);
    if (param->mode) {
        param->mode--;
        a_pasteitem(param->pm, 0);
    } else
        a_appenditem(param->pm, 0);

    param->copied++;
    RemoveTagItem(fhdr);
    return IsEmptyTagList();
}
Exemplo n.º 7
0
Arquivo: dark.c Projeto: yrchen/Athena
change_record(char c)
{
 int a[3];
 char genbuf[250];
 FILE *fs;
 
// sprintf(genbuf, BBSHOME "/home/%s/.dark", currutmp->userid);
 sethomefile(genbuf, currutmp->userid, ".dark");
 if(fs=fopen(genbuf, "r")) {
   fscanf(fs, "%d %d %d", &a[0], &a[1], &a[2]);
   fclose(fs); 
 } else a[0]=a[1]=a[2]=0;
 a[c]++;

 if(fs=fopen(genbuf, "w")) {
   fprintf(fs, "%d %d %d", a[0], a[1], a[2]);
   fclose(fs); 
 } else pressanykey("資料寫入有誤..請通知站長.. :)");
}
Exemplo n.º 8
0
int load_key(char * fn)
{
    FILE* fp;
    char fname[STRLEN];
    struct stat st;
    release_key();
    if (fn==NULL)
        sethomefile(fname, getCurrentUser()->userid, "definekey");
    else
        strcpy(fname, fn);
    stat(fname, &st);
    fp=fopen(fname, "rb");
    if (fp==NULL) return -1;
    keymem_total = st.st_size/sizeof(struct key_struct);
    keymem = malloc(MAX_KEY_DEFINE*sizeof(struct key_struct));
    fread(keymem, st.st_size, 1, fp);
    fclose(fp);
    return 0;
}
Exemplo n.º 9
0
static int bcmd_zap(int ent, struct BoardList *bent, char *direct)
{
	if (curuser.userlevel)	/* guest cannot zap board */
	{
		if (bent->bhr)
		{
			if (ZapRC_ValidBid(bent->bhr->bid))
			{
				if (ZapRC_IsZapped(bent->bhr->bid, bent->bhr->ctime))
					ZapRC_DoUnZap(bent->bhr->bid);
				else
					ZapRC_DoZap(bent->bhr->bid);
				sethomefile(genbuf, curuser.userid, UFNAME_ZAPRC);
				ZapRC_Update(genbuf);
				return C_LINE;
			}
		}
	}
	return C_NONE;
}
Exemplo n.º 10
0
void create_favboard(char *userid)
{
    FILE *fp;
    char goodbrdfile[256];
    char buf[256];
    char *tmp;
	int i=0;

	bzero(favbrd_list, sizeof(struct favbrd_struct)*FAVBOARDNUM);

    favbrd_list_t = 1;
    favbrd_list[0].father = -1;

    sethomefile(goodbrdfile, userid, ".goodbrd");
    if ((fp = fopen(goodbrdfile, "r")) == NULL) {
        return;
    }

    while (!feof(fp)) {
        int k = 0;

        if (i == MAXBOARDPERDIR)
            break;
	bzero(buf,256);
        fgets(buf, 30, fp);
        if (tmp = strstr(buf, "\n"))
            *tmp = 0;
	if(*buf==0) break;
	puts(buf);
        k = getbid(buf, NULL);
        if (k) {
            favbrd_list[0].bid[i] = k - 1;
            i++;
        }
    }
    fclose(fp);
    //unlink(goodbrdfile);
	favbrd_list[0].bnum = i;
    if (favbrd_list_t)
        my_save_favboard(userid);
}
Exemplo n.º 11
0
void 
setup_utmp(int mode)
{
	user_info	uinfo;
	char		buf       [80];

	memset(&uinfo, 0, sizeof(uinfo));
	uinfo.pid = currpid = getpid();
	uinfo.uid = searchuser(cuser.userid);
	uinfo.mode = currstat = mode;
	uinfo.msgcount = 0;
	if (cuser.userlevel & PERM_BM)
		check_BM();	/* Ptt 自動取下離職板主權力 */
	uinfo.userlevel = cuser.userlevel;
	uinfo.lastact = time(NULL);

	strcpy(uinfo.userid, cuser.userid);
	strcpy(uinfo.realname, cuser.realname);
	strcpy(uinfo.username, cuser.username);
	strcpy(uinfo.feeling, cuser.feeling);
	strncpy(uinfo.from, fromhost, 23);
	uinfo.invisible = cuser.invisible % 2;
	uinfo.pager = cuser.pager % 5;
	uinfo.brc_id = 0;
	uinfo.sex = cuser.sex;

	/* Ptt WHERE */

#ifdef WHERE
	uinfo.from_alias = where(fromhost);
#else
	uinfo.from_alias = 0;
#endif
	sethomefile(buf, cuser.userid, "remoteuser");

	if (enter_uflag & CLOAK_FLAG)
		uinfo.invisible = YEA;

	getnewutmpent(&uinfo);
	friend_load();
}
Exemplo n.º 12
0
Arquivo: post.c Projeto: fbbs/fbbs
static void read_signature_legacy(const char *uname, int offset, char *buffer,
		size_t size)
{
	char *out = buffer;
	size_t remain = size;
	strappend(&out, &remain, "\n--\n");
	if (offset <= 0)
		return;

	char file[HOMELEN];
	sethomefile(file, uname, "signatures");
	FILE *fp = fopen(file, "r");
	if (!fp)
		return;

	char buf[256];
	for (int i = (offset - 1) * MAXSIGLINES; i > 0; --i) {
		if (!fgets(buf, sizeof(buf), fp)) {
			fclose(fp);
			return;
		}
	}

	int blank = 0;
	for (int i = 0; i < MAXSIGLINES; ++i) {
		if (!fgets(buf, sizeof(buf), fp))
			break;
		if (buf[0] == '\n' || streq(buf, "\r\n")) {
			++blank;
		} else {
			while (blank-- > 0)
				strappend(&out, &remain, "\n");
			blank = 0;
			//% ":·" "·[FROM:"
			if (!strstr(buf, ":\xa1\xa4"BBSNAME" "BBSHOST"\xa1\xa4[FROM:"))
				strappend(&out, &remain, buf);
		}
	}
	fclose(fp);
}
Exemplo n.º 13
0
static void logattempt(char *uid, char type) {
    char fname[40];
    int fd, len;
    char genbuf[200];
    
    sprintf(genbuf, "%c%-12s[%s] %s@%s\n", type, uid,
	    Cdate(&login_start_time), remoteusername, fromhost);
    len = strlen(genbuf);
    if((fd = open(str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) {
	write(fd, genbuf, len);
	close(fd);
    }
    if(type == '-') {
	sprintf(genbuf, "[%s] %s\n", Cdate(&login_start_time), fromhost);
	len = strlen(genbuf);
	sethomefile(fname, uid, str_badlogin);
	if((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) {
	    write(fd, genbuf, len);
	    close(fd);
	}
    }
}
Exemplo n.º 14
0
/*
 * include signature: support multiple signatures
 */
static void do_article_sig(const char *wfile)
{
	int sig_no = 0, avalsig = 0, i;		/* default: don't include signature */
	FILE *fpr;
	static BOOL shownote = TRUE;

	if (curuser.flags[0] & SIG_FLAG)
	{
		if (shownote)
		{
			outs(_msg_no_use_sig);
			getkey();
			shownote = FALSE;
		}
		return;
	}

	sethomefile(genbuf, curuser.userid, UFNAME_SIGNATURES);
	if (!get_num_records(genbuf, sizeof(char)))
		return;
	if ((fpr = fopen(genbuf, "r")) == NULL)
		return;

	outs("\n");
	for (i = 0; i < (MAX_SIG_LINES * MAX_SIG_NUM) && fgets(genbuf, sizeof(genbuf), fpr); i++)
	{
		if (i % MAX_SIG_LINES == 0)
			prints("[%s #%d]\n", _msg_signature, ++avalsig);
		outs(genbuf);
	}
	fclose(fpr);
	prints("\n%s(1-%d,0:%s) ? [1]: ", _msg_include_which_sig, MAX_SIG_NUM, _msg_no_include_sig);

	sig_no = (getkey() - '0');
	if (sig_no > avalsig || sig_no < 0)
		sig_no = 1;
	if (sig_no != 0)
		include_sig(curuser.userid, wfile, sig_no);
}
Exemplo n.º 15
0
int
readmybrd(char *userid)
{
	char file[200];
	FILE *fp;
	int l;
	mybrdnum = 0;
	sethomefile(file, currentuser.userid, ".goodbrd");
	fp = fopen(file, "r");
	if (fp) {
		while (fgets(mybrd[mybrdnum], sizeof (mybrd[0]), fp) != NULL) {
			l = strlen(mybrd[mybrdnum]);
			if (mybrd[mybrdnum][l - 1] == '\n')
				mybrd[mybrdnum][l - 1] = 0;
			mybrdnum++;
			if (mybrdnum >= GOOD_BRC_NUM)
				break;
		}
		fclose(fp);
	}
	return 0;
}
Exemplo n.º 16
0
//#ifdef MAILCHECK
//#ifdef CODE_VALID
char *genrandpwd(int seed) {
	char panel[]=
			"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char *result;
	int i, rnd;

	result = (char *) malloc(RNDPASSLEN + 1);
	srand((unsigned) (time(0) * seed));
	memset(result, 0, RNDPASSLEN + 1);
	for (i = 0; i < RNDPASSLEN; i++) {
		rnd = rand() % sizeof(panel);
		if (panel[rnd] == '\0') {
			i--;
			continue;
		}
		result[i] = panel[rnd];
	}
	sethomefile(genbuf, currentuser.userid, ".regpass");
	unlink(genbuf);
	file_append(genbuf, result);
	return ((char *) result);
}
Exemplo n.º 17
0
int
read_submit()
{
	int i;
	char buf1[200];
	FILE *fp;
	struct boardmem *x;
	mybrdnum = 0;
	if (!strcmp(getparm("confirm1"), ""))
		http_fatal("参数错误");
	for (i = 0; i < parm_num; i++) {
		if (!strcasecmp(parm_val[i], "on")) {
			if (ismybrd(parm_name[i]))
				continue;
			if (mybrdnum >= GOOD_BRC_NUM)
				http_fatal("您试图预定超过%d个讨论区",
					   GOOD_BRC_NUM);
			if (!(x = getboard(parm_name[i]))) {
				printf("警告: 无法预定'%s'讨论区<br>\n",
				       nohtml(parm_name[i]));
				continue;
			}
			strsncpy(mybrd[mybrdnum], parm_name[i],
				 sizeof (mybrd[0]));
			mybrdnum++;
		}
	}
	sethomefile(buf1, currentuser.userid, ".goodbrd");
	fp = fopen(buf1, "w");
	for (i = 0; i < mybrdnum; i++)
		fprintf(fp, "%s\n", mybrd[i]);
	fclose(fp);
	saveuservalue(currentuser.userid, "mybrdmode", getparm("mybrdmode"));
	printf
	    ("<script>top.f2.location='bbsleft?t=%ld'</script>修改预定讨论区成功,您现在一共预定了%d个讨论区:<hr>\n",
	     now_t, mybrdnum);
	printf("[<a href='javascript:history.go(-2)'>返回</a>]");
	return 0;
}
Exemplo n.º 18
0
int bbsfdel_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	char *user = getparm("u");
	if (*user != '\0') {
		char file[HOMELEN];
		sethomefile(file, currentuser.userid, "friends");
		record_t r;
		if (record_open(file, O_RDWR, &r) < 0)
			return BBS_EINTNL;
		override_t key;
		strlcpy(key.id, user, sizeof(key.id));
		override_t *ptr =
				record_search(&r, &key, sizeof(key), lsearch, cmp_override);
		if (ptr != NULL)
			record_delete(&r, ptr, sizeof(*ptr));
		record_close(&r);
	}
	printf("Location: fall\n\n");
	return 0;
}
Exemplo n.º 19
0
static event_t *
ReadEvent(int today)
{
    FILE           *fp;
    char            buf[PATHLEN];
    event_t  head;

    head.next = NULL;
    sethomefile(buf, cuser.userid, "calendar");
    fp = fopen(buf, "r");
    if (fp) {
	while (fgets(buf, sizeof(buf), fp)) {
	    char           *date, *color, *content;
	    event_t        *t;
	    char *strtok_pos;

	    if (buf[0] == '#')
		continue;

	    date = strtok_r(buf, " \t\n", &strtok_pos);
	    color = strtok_r(NULL, " \t\n", &strtok_pos);
	    content = strtok_r(NULL, "\n", &strtok_pos);
	    if (!date || !color || !content)
		continue;

	    t = malloc(sizeof(event_t));
	    if (ParseEventDate(date, t) || t->days < today) {
		free(t);
		continue;
	    }
	    t->color = ParseColor(color) + 30;
	    for (; *content == ' ' || *content == '\t'; content++);
	    t->content = strdup(content);
	    InsertEvent(&head, t);
	}
	fclose(fp);
    }
    return head.next;
}
Exemplo n.º 20
0
static void create_userdata(olduserec * olduser)
{
    struct userdata ud;
    char datafile[256];
    int fd;
    struct stat st;

    bzero(&ud, sizeof(ud));
    memcpy(ud.userid, olduser->userid, sizeof(ud.userid));
    memcpy(ud.realemail, olduser->reginfo, sizeof(ud.realemail));
    memcpy(ud.realname, olduser->realname, sizeof(ud.realname));
    memcpy(ud.address, olduser->address, sizeof(ud.address));
    memcpy(ud.email, olduser->email, sizeof(ud.email));
#ifdef HAVE_BIRTHDAY
    ud.gender = olduser->gender;
    ud.birthyear = olduser->birthyear;
    ud.birthmonth = olduser->birthmonth;
    ud.birthday = olduser->birthday;
#endif

    sethomepath(datafile, olduser->userid);
    if (stat(datafile, &st) == -1) {
        fprintf(stderr, "Warning: %s's home directory not found.\n", olduser->userid);
        fprintf(stderr, "         Creating it.\n");
        if (mkdir(datafile, 0755) == -1)
            return;
    } else {
        if (!(st.st_mode & S_IFDIR))
            return;
    }
    sethomefile(datafile, olduser->userid, USERDATA);
    if ((fd = open(datafile, O_WRONLY | O_CREAT, 0644)) < 0) {
        fprintf(stderr, "open %s failed.\n", datafile);
        return;
    }
    if (write(fd, &ud, sizeof(ud)) < 0)
        fprintf(stderr, "write %s failed.\n", datafile);
    close(fd);
}
Exemplo n.º 21
0
Arquivo: utmp.c Projeto: wyat/kbs
int getfriendstr(struct userec* user,struct user_info* puinfo,session_t * session)
{
    int nf;
    int i;
    struct friends *friendsdata;
    char buf[60];

    puinfo->friendsnum=0;
    if (session->topfriend != NULL) {
        free(session->topfriend);
        session->topfriend = NULL;
    }
    sethomefile(buf, user->userid, "friends");
    nf = get_num_records(buf, sizeof(struct friends));
    if (nf <= 0)
        return 0;
    if (nf>MAXFRIENDS)
        nf=MAXFRIENDS;
    friendsdata = (struct friends *) calloc(nf,sizeof(struct friends));
    get_records(buf, friendsdata, sizeof(struct friends), 1, nf);
    for (i = 0; i < nf; i++) {
        friendsdata[i].id[IDLEN] = 0;
        friendsdata[i].exp[LEN_FRIEND_EXP-1] = 0;
        if (id_invalid(friendsdata[i].id)||(searchuser(friendsdata[i].id)==0)) {
            memcpy(&friendsdata[i], &friendsdata[nf - 1], sizeof(struct friends));
            nf--;
        }
    }
    qsort(friendsdata, nf, sizeof(friendsdata[0]), cmpfuid);      /*For Bi_Search */
    session->topfriend = (struct friends_info *) calloc(nf,sizeof(struct friends_info));
    for (i = 0; i < nf; i++) {
        puinfo->friends_uid[i] = searchuser(friendsdata[i].id);
        strcpy(session->topfriend[i].exp, friendsdata[i].exp);
    }
    free(friendsdata);
    puinfo->friendsnum=nf;
    return 0;
}
Exemplo n.º 22
0
Arquivo: chat.c Projeto: wyat/kbs
void call_listen(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1997.11.28 */
    char path[40];
    char uident[IDLEN + 1];
    char ignoreuser[IDLEN + 1];
    int nIdx;

    if (!*arg) {
        printchatline(pthis, "*** 请输入用户的ID ***");
    } else if (!strcasecmp(arg, getCurrentUser()->userid))
        printchatline(pthis, "*** 这是你自己的ID ***");
    else {
        strncpy(uident, arg, IDLEN + 1);
        uident[IDLEN] = 0;
        if (!searchuser(uident))
            /* change getuser -> searchuser, by dong, 1999.10.26 */
            printchatline(pthis, "*** 没有这个ID ***");
        else {
            sethomefile(path, getCurrentUser()->userid, "/ignores");
            nIdx =
                search_record(path, ignoreuser, IDLEN + 1,
                              (RECORD_FUNC_ARG) cmpinames, uident);
            if (nIdx <= 0)
                printchatline(pthis,
                              "*** 该用户的聊天讯息没有被忽略啊 ***");
            else if (delete_record(path, IDLEN + 1, nIdx, NULL, NULL) == 0) {
                bbslog("user", "listen %s", uident);
                printchatline(pthis,
                              "*** 已恢复对该用户聊天讯息的接收 ***");
                sprintf(uident, "/listen %s\n", uident);
                chat_send(pthis, uident);
            } else {
                bbslog("3error", "listen %s failed", uident);
                printchatline(pthis, "*** system error ***");
            }
        }
    }
}
Exemplo n.º 23
0
// Recover user's talk log from abnormal exit.
void tlog_recover(void)
{
	char buf[256];

	sethomefile(buf, currentuser.userid, "talk_log");
	if (strcasecmp(currentuser.userid, "guest") == 0 || !dashf(buf))
		return;

	screen_clear();
	genbuf[0] = '\0';
	//% getdata(0, 0, "\033[1;32m您有一个不正常断线所留下来的聊天记录, "
	getdata(0, 0, "\033[1;32m\xc4\xfa\xd3\xd0\xd2\xbb\xb8\xf6\xb2\xbb\xd5\xfd\xb3\xa3\xb6\xcf\xcf\xdf\xcb\xf9\xc1\xf4\xcf\xc2\xc0\xb4\xb5\xc4\xc1\xc4\xcc\xec\xbc\xc7\xc2\xbc, "
			//% "您要 .. (M) 寄回信箱 (Q) 算了?[Q]:\033[m",
			"\xc4\xfa\xd2\xaa .. (M) \xbc\xc4\xbb\xd8\xd0\xc5\xcf\xe4 (Q) \xcb\xe3\xc1\xcb\xa3\xbf[Q]\xa3\xba\033[m",
			genbuf, 2, DOECHO, YEA);

	if (genbuf[0] == 'M' || genbuf[0] == 'm') {
		//% mail_file(buf, currentuser.userid, "聊天记录");
		mail_file(buf, currentuser.userid, "\xc1\xc4\xcc\xec\xbc\xc7\xc2\xbc");
	}
	unlink(buf);
	return;
}
Exemplo n.º 24
0
int
bbsbrdadd_main()
{
    FILE *fp;
    char file[200], board[200];
    int i;
    html_header(1);
    changemode(ZAP);
    strsncpy(board, getparm("B"), 32);
    if (!board[0])
        strsncpy(board, getparm("board"), 32);
    if (!loginok)
        http_fatal("超时或未登录,请重新login");
    readmybrd(currentuser.userid);
    if (mybrdnum >= GOOD_BRC_NUM)
        http_fatal("您预定讨论区数目已达上限,不能增加预定");
    if (ismybrd(board))
        http_fatal("你已经预定了这个讨论区");
    if (!getboard(board))
        http_fatal("此讨论区不存在");
    strcpy(mybrd[mybrdnum], board);
    mybrdnum++;
    sethomefile(file, currentuser.userid, ".goodbrd");
    fp = fopen(file, "w");
    if (fp) {
        for (i = 0; i < mybrdnum; i++)
            fprintf(fp, "%s\n", mybrd[i]);
        fclose(fp);
    } else
        http_fatal("Can't save");
    //printf("<script>top.f2.location='bbsleft?t=%d'</script>\n", now_t);
    printf("<script>top.f2.location.reload();</script>\n");
    printf
    ("预定讨论区成功<br><a href='javascript:history.go(-1)'>快速返回</a>");
    http_quit();
    return 0;
}
Exemplo n.º 25
0
static int load_zapbuf(choose_board_t *cbrd)
{
	if (cbrd->zapbuf == NULL) {
		cbrd->zapbuf = malloc(sizeof(*cbrd->zapbuf) * MAXBOARD);
		if (cbrd->zapbuf == NULL)
			return -1;
	} else {
		return 0;
	}

	char file[HOMELEN];
	sethomefile(file, currentuser.userid, ".lastread");
	int n = 0;
	int fd = open(file, O_RDONLY, 0600);
	if (fd >= 0) {
		n = read(fd, cbrd->zapbuf, sizeof(*cbrd->zapbuf) * numboards);
		restart_close(fd);
	}
	int i;
	for (i = n / sizeof(*cbrd->zapbuf); i < MAXBOARD; ++i) {
		cbrd->zapbuf[i] = 1;
	}
	return 0;
}
Exemplo n.º 26
0
static int init_clock_data()
{
	FILE *fp;
	char fname[STRLEN];
	struct stat st;

	sethomefile(fname,getCurrentUser()->userid,"clock.data");
	stat(fname,&st);
	if((fp=fopen(fname,"rb"))==NULL){
		return default_clock_data();
	}
	if(st.st_size > MAX_CLOCK_DEF * sizeof(struct clock_struct) ){
		fclose(fp);
		return default_clock_data();
	}
	clock_total = st.st_size/sizeof(struct clock_struct);
	if(clock_total < 1){
		fclose(fp);
		return default_clock_data();
	}
	fread(clock_data,st.st_size,1,fp);
	fclose(fp);
	return 1;
}
Exemplo n.º 27
0
static void
SearchCrime()
{
    char uident[IDLEN + 1], buf[256];
    time_t currTime, ActiveTime;
    mcUserInfo *mcuInfo;
    int day, hour, minute;

    nomoney_show_stat("档案室");
    if (!getOkUser("\n请选择查询的档案:", uident, 6, 4)) {
        move(8, 4);
        prints("查无此人");
        pressanykey();
        return;
    }

    sethomefile(buf, uident, "mc.save");
    if (!file_exist(buf))
        initData(1, buf);
    if((mcuInfo = loadData(buf, sizeof (mcUserInfo))) == (void*)-1)
        return;

    ActiveTime = mcuInfo->lastActiveTime;
    currTime = time(NULL);
    if (currTime > ActiveTime) {
        day = (currTime - ActiveTime) / 86400;
        hour = (currTime - ActiveTime) % 86400 / 3600;
        minute = (currTime - ActiveTime) % 3600 / 60 + 1;
        move(9, 1);
        prints("    此人上次犯案是在%d天%d小时%d分钟以前。", day, hour,
               minute);
    }
    unloadData(mcuInfo, sizeof (mcUserInfo));
    pressanykey();
    return;
}
Exemplo n.º 28
0
int save_import_path(char **i_path,char **i_title,time_t* i_path_time, session_t* session)
{
    FILE *fn;
    int i;
    char buf[MAXPATH];

    sethomefile(buf, session->currentuser->userid, "BMpath");
    fn = fopen(buf, "wt");
    if (fn) {
        struct stat st;

        for (i = 0; i < ANNPATH_NUM; i++) {
            fputs(i_path[i], fn);
            fputs("\n", fn);
            fputs(i_title[i], fn);
            fputs("\n", fn);
        }
        fstat(fileno(fn), &st);
        fclose(fn);
        * i_path_time = st.st_mtime;
        return 0;
    }
    return -1;
}
Exemplo n.º 29
0
int
bbsqry_main()
{
	FILE *fp;
	char userid[14], filename[80], buf[512];
	struct userec *x;
	int tmp2;
	struct in_addr in;
	html_header(1);
	check_msg();
	changemode(QUERY);
	strsncpy(userid, getparm("U"), 13);
	if (!userid[0])
		strsncpy(userid, getparm("userid"), 13);
	printf("<body><center>");
	printf("%s -- 查询网友<hr>\n", BBSNAME);
	if (userid[0] == 0) {
		printf("<form name=qry action=bbsqry>\n");
		printf
		    ("请输入用户名: <input name=userid maxlength=12 size=12>\n");
		printf("<input type=submit value=查询用户>\n");
		printf("</form><hr>\n");
		printf("<script>document.qry.userid.focus();</script>");
		http_quit();
	}
	if (getuser(userid, &x) <= 0) {
		printf("不可能,肯定是你敲错了,根本没这人啊");
		printf("<p><a href=javascript:history.go(-1)>快速返回</a>");
		http_quit();
	}
	printf("</center><pre>\n");
	if (x->mypic) {
		printf("<table align=left><tr><td><center>");
		printmypic(x->userid);
		printf("</center></td></tr></table>");
	}
	printf("<b><font size=+1>%s</font></b> (<font class=gre>%s</font>) "
	       "共上站 <font class=gre>%d</font> 次,"
	       "发表文章 <font class=gre>%d</font> 篇\n",
	       x->userid, x->username, x->numlogins, x->numposts);
//      show_special(x->userid);

	in.s_addr = x->lasthost & 0x0000ffff;
	printf
	    ("上次在 <font color=green>%s</font> 从 <font color=green>%s</font> 到本站一游。<br>",
	     Ctime(x->lastlogin), inet_ntoa(in));
	mails(userid, &tmp2);
	printf("信箱:[<font color=green>%s</font>],", tmp2 ? "⊙" : "  ");
	if (!strcasecmp(x->userid, currentuser->userid)) {
		printf
		    ("经验值:[<font color=green>%d</font>](<font color=olive>%s</font>) ",
		     countexp(x), cuserexp(countexp(x)));
		printf
		    ("表现值:[<font color=green>%d</font>](<font color=olive>%s</font>) ",
		     countperf(x), cperf(countperf(x)));
	}
	if (x->dieday) {
		printf
		    ("<br>已经离开了人世,呜呜...<br>还有 [<b>%d</b>] 天就要转世投胎了<br>",
		     countlife(x));
	} else {
		printf("生命力:[<font color=red>%d</font>]。<br>",
		       countlife(x));
		if (x->userlevel & PERM_BOARDS) {
			int i;
			printf("担任版务:");
			for (i = 0; i < MAXBOARD && i < shm_bcache->number; i++)
				bm_printboard(&shm_bcache->bcache[i],
					      x->userid);
			printf("<br>");
		}
		if (!show_onlinestate(userid)) {
			printf
			    ("目前不在站上, 上次离站时间 [<font color=blue>%s</font>]\n\n",
			     (x->lastlogout >=
			      x->lastlogin) ? Ctime(x->
						    lastlogout) :
			     "因在线上或不正常断线不详");
		}
	}
	printf("\n");
	printf("</pre><table width=100%%><tr><td>");
	sethomefile(filename, x->userid, "plans");
	fp = fopen(filename, "r");
	sprintf(filename, "00%s-plan", x->userid);
	fdisplay_attach(NULL, NULL, NULL, NULL);
	if (fp) {
		while (1) {
			if (fgets(buf, 256, fp) == 0)
				break;
			if (!strncmp(buf, "begin 644 ", 10)) {
				errlog("old attach %s", filename);
				fdisplay_attach(stdout, fp, buf, filename);
				continue;
			}
			fhhprintf(stdout, "%s", buf);
		}
		fclose(fp);
	} else {
		printf("<font color=teal>没有个人说明档</font><br>");
	}

	printf("</td></tr></table>");
	printf
	    ("<br><br><a href=bbspstmail?userid=%s&title=没主题>[书灯絮语]</a> ",
	     x->userid);
	printf("<a href=bbssendmsg?destid=%s>[发送讯息]</a> ", x->userid);
	printf("<a href=bbsfadd?userid=%s>[加入好友]</a> ", x->userid);
	printf("<a href=bbsfdel?userid=%s>[删除好友]</a> ", x->userid);
	if (x->userlevel & PERM_SPECIAL8) {
		printf
		    ("<a href=bbs0an?path=/groups/GROUP_0/Personal_Corpus/%c/%s>[个人文集]</a> ",
		     mytoupper(x->userid[0]), x->userid);
	}
	sethomefile(filename, x->userid, "B/config");
	if (file_isfile(filename)) {
		printf
		    ("<a href=blog?U=%s>[Blog]</a>", x->userid);
	}
	printf("<hr>");
	printf("<center><form name=qry action=bbsqry>\n");
	printf("请输入用户名: <input name=userid maxlength=12 size=12>\n");
	printf("<input type=submit value=查询用户>\n");
	printf("</form><hr>\n");
	printf("</body>\n");
	http_quit();
	return 0;
}
Exemplo n.º 30
0
// Handle giveupBBS(戒网) transactions.
// Return expiration date (in days from epoch).
// TODO: Better rewrite it..
int chk_giveupbbs(void)
{
	int i, j, tmpcount, tmpid, sflag[10][2];
	FILE *fn;
	int lcount = 0;
	char buf[NAME_MAX];
	int recover = 0;

	sethomefile(buf, currentuser.userid, "giveupBBS");
	fn = fopen(buf, "r");
	if (fn) {
		struct userec tmpuserec;
		memcpy(tmpuserec.userid, currentuser.userid, sizeof(tmpuserec.userid));
		tmpid = getuserec(tmpuserec.userid, &tmpuserec);
		while (!feof(fn)) {
			if (fscanf(fn, "%d %d", &i, &j) <= 0)
				break;
			sflag[lcount][0] = i;
			sflag[lcount][1] = j;
			lcount++;
		}
		tmpcount = lcount;
		fclose(fn);
		for (i = 0; i < lcount; i++) {
			if(sflag[i][0] == 1)
				recover = sflag[i][1];
			if (sflag[i][1] <= time(NULL) / 3600 / 24) {
				tmpcount--;
				switch (sflag[i][0]) {
					case 1:
						tmpuserec.userlevel |= PERM_LOGIN;
						recover = 0;
						break;
					case 2:
						tmpuserec.userlevel |= PERM_POST;
						break;
					case 3:
						tmpuserec.userlevel |= PERM_TALK;
						break;
					case 4:
						tmpuserec.userlevel |= PERM_MAIL;
						break;
				}
				sflag[i][1] = 0;
			}
			
		}
		if (tmpuserec.flags[0] & GIVEUPBBS_FLAG && tmpcount == 0)
			tmpuserec.flags[0] &= ~GIVEUPBBS_FLAG;
		substitut_record(PASSFILE, &tmpuserec, sizeof(struct userec),
				tmpid);
		if (tmpcount == 0)
			unlink(buf);
		else {
			fn = fopen(buf, "w");
			if (fn) {
				for (i = 0; i < lcount; i++)
					if (sflag[i][1] > 0)
						fprintf(fn, "%d %d\n", sflag[i][0], sflag[i][1]);
				fclose(fn);
			}
		}
	}
	return recover;
}