Esempio n. 1
0
File: online.c Progetto: fbbs/fbbs
static const char *get_host(const online_user_info_t *ip,
		const struct userec *user)
{
	const char *host;
	if (HAS_PERM(PERM_OCHAT)) {
		host = ip->host;
	} else {
		if (HAS_DEFINE(user->userdefine, DEF_NOTHIDEIP))
			host = mask_host(ip->host);
		else
			host = "......";
	}
	return host;
}
Esempio n. 2
0
static void override_info(void)
{
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, "friends");
	mmap_t m;
	m.oflag = O_RDONLY;
	if (mmap_open(file, &m) < 0)
		return;
	hash_t ht;
	if (hash_create(&ht, 0, NULL) < 0) {
		mmap_close(&m);
		return;
	}
	int count = m.size / sizeof(override_t);
	if (count > 0) {
		override_t *ov = m.ptr;
		for (int i = 0; i < count; i++) {
			hash_set(&ht, ov->id, HASH_KEY_STRING, ov->id);
			ov++;
		}
		time_t now = time(NULL);
		struct user_info *uinfo = utmpshm->uinfo;
		struct userec *user;
		const char *ip;
		int idle;
		for (int i = 0; i < MAXACTIVE; ++i) {
			if (uinfo->active
					&& !(uinfo->invisible && !HAS_PERM(PERM_SEECLOAK))
					&& hash_get(&ht, uinfo->userid, HASH_KEY_STRING)) {
				user = uidshm->passwd + (uinfo->uid - 1);
				if (HAS_DEFINE(user->userdefine, DEF_NOTHIDEIP))
					ip = mask_host(uinfo->from);
				else
					ip = "......";
				if (uinfo->mode == BBSNET)
					idle = 0;
				else
					idle = (now - uinfo->idle_time) / 60;
				printf("<ov id='%s' action='%s' idle='%d' ip='%s'>",
						uinfo->userid, mode_type(uinfo->mode), idle, ip);
				xml_fputs(uinfo->username, stdout);
				printf("</ov>");
			}
			uinfo++;
		}
	}
	hash_destroy(&ht);
	mmap_close(&m);
}
Esempio n. 3
0
File: friend.c Progetto: fbbs/fbbs
static void show_sessions_of_friends(void)
{
	db_res_t *res = session_get_followed();
	if (!res)
		return;

	fb_time_t now = fb_time();
	for (int i = 0; i < db_res_rows(res); ++i) {
		bool visible = db_get_bool(res, i, 3);
		if (!visible && !HAS_PERM(PERM_SEECLOAK))
			continue;

		session_id_t sid = db_get_session_id(res, i, 0);
		const char *uname = db_get_value(res, i, 2);
		const char *ip = db_get_value(res, i, 4);
		fb_time_t refresh = session_get_idle(sid);
		int status = get_user_status(sid);

		struct userec user;
		getuserec(uname, &user);

		int idle;
		if (refresh < 1 || status == ST_BBSNET)
			idle = 0;
		else
			idle = (now - refresh) / 60;

		if (HAS_DEFINE(user.userdefine, DEF_NOTHIDEIP))
			ip = mask_host(ip);
		else
			ip = "......";

		printf("<ov id='%s' action='%s' idle='%d' ip='%s'>",
				uname, session_status_descr(status), idle, ip);
		xml_fputs(user.username);
		printf("</ov>");
	}
	db_clear(res);
}
Esempio n. 4
0
int bbssnd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	if (parse_post_data() < 0)
		return BBS_EINVAL;
	int bid = strtol(getparm("bid"), NULL, 10);
	struct boardheader *bp = getbcache2(bid);
	if (bp == NULL || !haspostperm(&currentuser, bp))
		return BBS_ENOBRD;
	if (bp->flag & BOARD_DIR_FLAG)
		return BBS_EINVAL;

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

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

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

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

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

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

	snprintf(buf, sizeof(buf), "doc?board=%s", bp->filename);
	http_header();
	refreshto(1, buf);
	printf("</head>\n<body>发表成功,1秒钟后自动转到<a href='%s'>版面</a>\n"
			"</body>\n</html>\n", buf);
	return 0;
}
Esempio n. 5
0
static int edit_article(const char *file, const char *content, const char *ip)
{
	if (file == NULL || content == NULL || ip == NULL)
		return BBS_EINTNL;
	int fd = open(file, O_RDWR);
	if (fd < 0)
		return BBS_EINTNL;
	fb_flock(fd, LOCK_EX);
	char buf[4096];
	ssize_t bytes = read(fd, buf, sizeof(buf));
	if (bytes >= 0) {
		// skip header.
		char *ptr = buf, *e = buf + bytes;
		int n = 3;
		while (ptr != e && n >= 0) {
			if (*ptr == '\n')
				--n;
			++ptr;
		}
		int begin = ptr - buf;

		if (bytes == sizeof(buf)) {
			lseek(fd, -sizeof(buf), SEEK_END);
			bytes = read(fd, buf, sizeof(buf));
			if (bytes < sizeof(buf)) {
				fb_flock(fd, LOCK_UN);
				restart_close(fd);
				return BBS_EINTNL;
			}
			e = buf + bytes;
		}
		ptr = e - 2; // skip last '\n'
		while (ptr >= buf && *ptr != '\n')
			--ptr;
		if (ptr >= buf) {
			if (!strncmp(ptr + 1, "\033[m\033[1;36m※ 修改", 17)) {
				e = ptr + 1;
				--ptr;
				while (ptr >= buf && *ptr != '\n')
					--ptr;
			}
		}

		lseek(fd, begin, SEEK_SET);
		size_t len = strlen(content);
		size_t size = begin + len;
		int ret = safer_write(fd, content, len);
		if (ret == 0 && ptr != e)
			ret = safer_write(fd, ptr, e - ptr);
		len = snprintf(buf, sizeof(buf), "\033[m\033[1;36m※ 修改:·%s 于 "
				"%22.22s·HTTP [FROM: %-.20s]\033[m\n", currentuser.userid,
				getdatestring(time(NULL), DATE_ZH), mask_host(ip));
		if (ret == 0)
			ret = safer_write(fd, buf, len);
		size += (e - ptr) + len;
		ftruncate(fd, size);
		fb_flock(fd, LOCK_UN);
		restart_close(fd);
		if (ret == 0)
			return 0;
		return BBS_EINTNL;
	}
	return BBS_EINTNL;	
}
Esempio n. 6
0
File: talk.c Progetto: icewwn/fbbs-1
int tui_query_result(const char *userid)
{
	struct userec user;
	int unum = getuserec(userid, &user);
	if (!unum)
		return -1;

	screen_move(0, 0);
	screen_clrtobot();

	int color = 2;
	if (HAS_DEFINE(user.userdefine, DEF_COLOREDSEX))
		color = (user.gender == 'F') ? 5 : 6;
	char horo[32] = "";
	if (HAS_DEFINE(user.userdefine, DEF_S_HOROSCOPE)
			&& strcasecmp(user.userid, "guest") != 0) {
		snprintf(horo, sizeof(horo), "[\033[1;3%dm%s\033[m] ",
				color, horoscope(user.birthmonth, user.birthday));
	}
	//% prints("\033[0;1;37m%s \033[m(\033[1;33m%s\033[m) 共上站 \033[1;32m%d\033[m "
	prints("\033[0;1;37m%s \033[m(\033[1;33m%s\033[m) \xb9\xb2\xc9\xcf\xd5\xbe \033[1;32m%d\033[m "
			//% "次  %s\n", user.userid, user.username, user.numlogins, horo);
			"\xb4\xce  %s\n", user.userid, user.username, user.numlogins, horo);

	bool self = !strcmp(currentuser.userid, user.userid);
	const char *host;
	if (user.lasthost[0] == '\0') {
		//% host = "(不详)";
		host = "(\xb2\xbb\xcf\xea)";
	} else {
		if (self || HAS_PERM2(PERM_OCHAT, &currentuser))
			host = user.lasthost;
		else 
			host = mask_host(user.lasthost);
	}
	//% prints("进站 [\033[1;32m%s\033[m] %s[\033[1;32m%s\033[m]\n",
	prints("\xbd\xf8\xd5\xbe [\033[1;32m%s\033[m] %s[\033[1;32m%s\033[m]\n",
			format_time(user.lastlogin, TIME_FORMAT_ZH),
			//% strlen(host) > IPADDR_OMIT_THRES ? "" : "来自 ", host);
			strlen(host) > IPADDR_OMIT_THRES ? "" : "\xc0\xb4\xd7\xd4 ", host);

	user_id_t uid = get_user_id(userid);
	session_basic_info_t *res = get_sessions(uid);

	bool any_session_visible = false;
	for (int i = 0; i < (res ? session_basic_info_count(res) : 0); ++i) {
		if (HAS_PERM(PERM_SEECLOAK) || session_basic_info_visible(res, i)) {
			any_session_visible = true;
			break;
		}
	}

	if (any_session_visible) {
		//% prints("在线 [\033[1;32m讯息器:(\033[36m%s\033[32m)\033[m] ",
		prints("\xd4\xda\xcf\xdf [\033[1;32m\xd1\xb6\xcf\xa2\xc6\xf7:(\033[36m%s\033[32m)\033[m] ",
				//% "打开");
				"\xb4\xf2\xbf\xaa");
	} else {
		fb_time_t t = user.lastlogout;
		if (user.lastlogout < user.lastlogin)
			t = ((fb_time() - user.lastlogin) / 120) % 47 + 1 + user.lastlogin;
		//% prints("离站 [\033[1;32m%s\033[m] ", format_time(t, TIME_FORMAT_ZH));
		prints("\xc0\xeb\xd5\xbe [\033[1;32m%s\033[m] ", format_time(t, TIME_FORMAT_ZH));
	}

	char path[HOMELEN];
	snprintf(path, sizeof(path), "mail/%c/%s/%s",
			toupper(user.userid[0]), user.userid, DOT_DIR);
	int perf = countperf(&user);
	//% prints("表现值 "
	prints("\xb1\xed\xcf\xd6\xd6\xb5 "
#ifdef SHOW_PERF
			"%d(\033[1;33m%s\033[m)"
#else
			"[\033[1;33m%s\033[m]"
#endif
			//% " 信箱 [\033[1;5;32m%2s\033[m]\n"
			" \xd0\xc5\xcf\xe4 [\033[1;5;32m%2s\033[m]\n"
#ifdef SHOW_PERF
			, perf
#endif
			//% , cperf(perf), (check_query_mail(path) == 1) ? "信" : "  ");
			, cperf(perf), (check_query_mail(path) == 1) ? "\xd0\xc5" : "  ");

	int exp = countexp(&user);

	uinfo_t u;
	uinfo_load(user.userid, &u);

#ifdef ENABLE_BANK
	//% prints("贡献 [\033[1;32m%d\033[m", TO_YUAN_INT(u.contrib));
	prints("\xb9\xb1\xcf\xd7 [\033[1;32m%d\033[m", TO_YUAN_INT(u.contrib));
	if (self || HAS_PERM2(PERM_OCHAT, &currentuser)) {
		prints("/\033[1;33m%d\033[m", TO_YUAN_INT(u.money));
	}
	{
		char rank_buf[8];
		snprintf(rank_buf, sizeof(rank_buf), "%.1f%%", PERCENT_RANK(u.rank));
		prints("](%s) ", rank_buf);
	}

#endif

#ifdef ALLOWGAME
	//% prints("存贷款 [\033[1;32m%d\033[m/\033[1;32m%d\033[m]"
	prints("\xb4\xe6\xb4\xfb\xbf\xee [\033[1;32m%d\033[m/\033[1;32m%d\033[m]"
			//% "(\033[1;33m%s\033[m) 经验值 [\033[1;32m%d\033[m]\n",
			"(\033[1;33m%s\033[m) \xbe\xad\xd1\xe9\xd6\xb5 [\033[1;32m%d\033[m]\n",
			user.money, user.bet, cmoney(user.money - user.bet), exp);
	//% prints("发文 [\033[1;32m%d\033[m] 奖章 [\033[1;32m%d\033[m]"
	prints("\xb7\xa2\xce\xc4 [\033[1;32m%d\033[m] \xbd\xb1\xd5\xc2 [\033[1;32m%d\033[m]"
			//% "(\033[1;33m%s\033[m) 生命力 [\033[1;32m%d\033[m]\n",
			"(\033[1;33m%s\033[m) \xc9\xfa\xc3\xfc\xc1\xa6 [\033[1;32m%d\033[m]\n",
			user.numposts, user.nummedals, cnummedals(user.nummedals),
			compute_user_value(&user));
#else
	//% prints("发文 [\033[1;32m%d\033[m] ", user.numposts);
	prints("\xb7\xa2\xce\xc4 [\033[1;32m%d\033[m] ", user.numposts);
	//% prints("经验值 [\033[1;33m%-10s\033[m]", cexpstr(exp));
	prints("\xbe\xad\xd1\xe9\xd6\xb5 [\033[1;33m%-10s\033[m]", cexpstr(exp));
#ifdef SHOWEXP
	prints("(%d)", exp);
#endif
	//% prints(" 生命力 [\033[1;32m%d\033[m]\n", compute_user_value(&user));
	prints(" \xc9\xfa\xc3\xfc\xc1\xa6 [\033[1;32m%d\033[m]\n", compute_user_value(&user));
#endif

	char buf[160];
	show_position(&user, buf, sizeof(buf), u.title);
	//% prints("身份 %s\n", buf);
	prints("\xc9\xed\xb7\xdd %s\n", buf);
	
	uinfo_free(&u);

	if (any_session_visible)
		show_statuses(res);
	session_basic_info_clear(res);

	show_user_plan(userid);
	return 0;
}