Example #1
0
int check_if_ok()
{
        if(user_perm(&currentuser, PERM_LOGINOK))
                http_fatal("您已经通过本站的身份认证, 无需再次填写注册单.");
        if(has_fill_form())
                http_fatal("目前站长尚未处理您的注册单,请耐心等待.");
}
Example #2
0
static int my_inode_unlink(struct inode *dir,struct dentry *dentry){
	if(current->cred->uid.val==0){
		return 0;
	}
	if(user_perm(current->cred->uid.val)!=MY_CRTDEL){
		return -EPERM;
	}
	else
		return 0;

}
Example #3
0
static int my_inode_create(struct inode *inode,struct dentry *dentry,umode_t mode){
	if(current->cred->uid.val==0){
		return 0;
	}
	
	if(user_perm(current->cred->uid.val)!=MY_CRTDEL){
		return -EPERM;
	}
	else
		return 0;
}
Example #4
0
static int my_inode_perm(struct inode *inode,int mask){
	
	int uid=current->cred->uid.val;
	int perm=user_perm(uid);

	if(current->cred->uid.val==0){
		return 0;
	}
	else if(perm<0){
		return -EPERM;
	}	

	else if(perm==MY_READ && (mask & MAY_WRITE)){
		return -EPERM;
	}
	else
		return 0;
}
Example #5
0
int
bbsupload_main()
{
	char *ptr;
	char userattachpath[256];
	int totalsize;

	html_header(1);
	printf("<body><center><div class=swidth style=\"text-align:left\">");
	if (!loginok || isguest)
		http_fatal("请先登录");
	if (!user_perm(currentuser, PERM_POST))
		http_fatal("缺乏 POST 权限");

	snprintf(userattachpath, sizeof (userattachpath), PATHUSERATTACH "/%s",
		 currentuser->userid);
	mkdir(userattachpath, 0760);

	ptr = getparm("del");
	if (*ptr) {
		upload_do_del(userattachpath, ptr);
		totalsize = upload_getpathsize(userattachpath, 1);
		if (totalsize < MAXATTACHSIZE)
			printuploadform();
		showfile(MY_BBS_HOME "/wwwtmp/googleanalytics");
		printf("</body></html>");
		return 0;
	}

	totalsize = upload_getpathsize(userattachpath, 0);
	if (totalsize < 0)
		http_fatal("无法检测目录大小");

	totalsize = save_attach(userattachpath, totalsize);

	/* Cleanup. */
	totalsize = upload_getpathsize(userattachpath, 1);
	if (totalsize < MAXATTACHSIZE)
		printuploadform();
	printf("</div></center>");
	showfile(MY_BBS_HOME "/wwwtmp/googleanalytics");
	printf("</body></html>");
	return 0;
}
Example #6
0
int
bbslogin_main()
{
	int n, t;
	time_t dtime;
	char filename[128], buf[256], id[20], pw[20], url[10], *ub = FIRST_PAGE; // main_page[STRLEN];
	struct userec *x;
	int ipmask;
	html_header(3);
	strsncpy(id, getparm("id"), 13);
	strsncpy(pw, getparm("pw"), 13);
	strsncpy(url, getparm("url"), 3);
	ipmask = atoi(getparm("ipmask"));

	if (loginok && strcasecmp(id, currentuser.userid) && !isguest) {
		http_fatal
		    ("系统检测到目前你的计算机上已经登录有一个帐号 %s,请先退出.(选择正常logout)",
		     currentuser.userid);
	}
	if (!strcmp(id, "")) {
		strcpy(id, "guest");
	}
	x = getuser(id);
	if (x == 0) {
		printf("%s<br>", id);
		http_fatal("错误的使用者帐号");
	}
	strcpy(id, x->userid);
	if (strcasecmp(id, "guest")) {
		if (checkbansite(fromhost)) {
			http_fatal
			    ("对不起, 本站不欢迎来自 [%s] 的登录. <br>若有疑问, 请与SYSOP联系.",
			     fromhost);
		}
		if (userbansite(x->userid, fromhost))
			http_fatal("本ID已设置禁止从%s登录", fromhost);
		if (!checkpasswd(x->passwd, pw)) {
			logattempt(x->userid, fromhost, "WWW", now_t);
			http_fatal("密码错误");
		}
		if (!user_perm(x, PERM_BASIC))
			http_fatal
			    ("此帐号已被停机, 若有疑问, 请用其他帐号在sysop版询问.");
		if (file_has_word(MY_BBS_HOME "/etc/prisonor", x->userid))
			http_fatal("安心改造,不要胡闹");
		if (x->dietime)
			http_fatal("死了?还要做什么? :)");
		t = x->lastlogin;
		x->lastlogin = now_t;
		if (abs(t - now_t) < 20) {
			http_fatal("两次登录间隔过密!");
		}

		dtime = t - 4 * 3600;
		t = localtime(&dtime)->tm_mday;
		dtime = now_t - 4 * 3600;
		if (t < localtime(&dtime)->tm_mday && x->numdays < 800)
			x->numdays++;
		x->numlogins++;
		strsncpy(x->lasthost, fromhost, 16);
		save_user_data(x);
		currentuser = *x;
	}
	sprintf(buf, "%s enter %s www", x->userid, fromhost);
	newtrace(buf);
	n = 0;
	if (loginok && isguest) {
		bzero(u_info, sizeof (struct user_info));
	}
	if (strcasecmp(id, "guest")) {
		sethomepath(filename, x->userid);
		mkdir(filename, 0755);

		strsncpy(buf, getparm("style"), 3);
		wwwstylenum = -1;
		if (isdigit(buf[0]))
			wwwstylenum = atoi(buf);
		if ((wwwstylenum > NWWWSTYLE || wwwstylenum < 0))
			if (!readuservalue
			    (x->userid, "wwwstyle", buf, sizeof (buf)))
				    wwwstylenum = atoi(buf);
		if (wwwstylenum < 0 || wwwstylenum >= NWWWSTYLE)
			wwwstylenum = 1;
		currstyle = &wwwstyle[wwwstylenum];
	} else {
		wwwstylenum = 1;
		currstyle = &wwwstyle[wwwstylenum];

	}

	ub = wwwlogin(x, ipmask);
	if (!strcmp(url, "1")) 
		/*printf("<link href=\"images/@byron.css\" rel=stylesheet type=\"text/css\">\n
			<frameset cols=135,* frameSpacing=0 frameborder=no id=fs0>\n
			<frame src=\"%sbbsleft?t=%ld\" name=f2 frameborder=no scrolling=no>\n
			<frameset id=fs1 rows=0,*,18 frameSpacing=0 frameborder=no border=0>\n
			<frame scrolling=no name=fmsg src=\"%sbbsmsg\">\n
			<frame name=f3 src=\"%sbbsfoot\">\n
			<frame scrolling=no name=f4 src=\"%sbbsfoot.htm\">\n
			</frameset>\n
			</frameset>\n", ub, now_t, ub, ub, ub);*/			//add by mintbaggio 040411 for new www

	//	html_header(3);

		printf
		    ("<script>opener.parent.f2.location.href=\"%sbbsleft?t=%ld\";\n"
		     "opener.parent.fmsg.location.href=\"%sbbsgetmsg\";\n"
		     //"opener.parent.f4.location.href=\"%sbbsfoot\";\n"
		     "a=window.opener.location.href;\n" "l=a.length;\n"
		     "t=a.indexOf('/" SMAGIC "',1);\n" "t=a.indexOf('/',t+1);\n"
		     "nu=\"%s\"+a.substring(t+1,l);\n"
		     "window.opener.location.href=nu;window.close();</script>",
		     ub, now_t, ub, ub, ub);

		
	//}
	else
		redirect(ub);
	//else {
	//	print_session_string(ub);
	//	html_header(3);
	//	
	//	sprintf(main_page, "/%s/", SMAGIC);
	//	redirect(main_page);
	//}
	http_quit();
	return 0;
}
Example #7
0
char *
wwwlogin(struct userec *user, int ipmask)
{
	FILE *fp, *fp1;
	int n, dolog = 0, st, clubnum, uid, i, nsearch;
	struct user_info *u;
	char ULIST[STRLEN];
	char genbuf[256], *urlbase, fname[80];
	uid = getusernum(user->userid) + 1;

	if ((urlbase = check_multi(user->userid, uid)))
		return urlbase;

	if (strcasecmp(user->userid, "guest") && count_uindex(uid) >= 3)
		http_fatal("您已经登录了三个帐号,不能再登录了");
//      如果要限制WWW登录窗口数 就打开这个注释. lepton

	gethostname(genbuf, 256);
	sprintf(ULIST, MY_BBS_HOME "/%s.%s", ULIST_BASE, genbuf);

	fp = fopen(ULIST, "a");
	flock(fileno(fp), LOCK_EX);
	nsearch = NSEARCH;
	//if (strcasecmp(user->userid, "guest"))
	//      nsearch = MAXACTIVE / 4;
	for (i = 0, n = iphash(fromhost) * (MAXACTIVE / NHASH); i < nsearch;
	     i++, n++) {
		if (n >= MAXACTIVE)
			n = 0;
		u = &(shm_utmp->uinfo[n]);
		if (u->active && u->pid == 1
		    && ((now_t - u->lasttime) > 20 * 60 || u->wwwinfo.iskicked)) {
			st = u->lasttime - u->wwwinfo.login_start_time;
			if (st > 86400) {
				errlog("Strange long stay time,%d!, drop %s",
				       st, u->userid);
				st = 86400;
			}
			sprintf(genbuf, "%s drop %d www", u->userid, st);
			newtrace(genbuf);
			remove_uindex(u->uid, n + 1);
			bzero(u, sizeof (struct user_info));
		}
		if (!dolog && u->active == 0) {
			u_info = u;
			bzero(u, sizeof (struct user_info));
			u->active = 1;
			u->uid = uid;
			u->pid = 1;
			//u->pid = thispid;			//modify by mintbaggio@BMY for kill www user
			u->mode = LOGIN;
			if (strcasecmp(user->userid, "guest"))
				u_info->unreadmsg = get_unreadmsg(user->userid);
			else
				u_info->unreadmsg = 0;
			u->userlevel = user->userlevel;
			u->lasttime = now_t;
			u->curboard = 0;
			if (user_perm(user, PERM_LOGINCLOAK) &&
			    (user->flags[0] & CLOAK_FLAG))
				u->invisible = YEA;
			u->pager = 0;
			if (user->userdefine & DEF_FRIENDCALL)
				u->pager |= FRIEND_PAGER;
			if (user->flags[0] & PAGER_FLAG) {
				u->pager |= ALL_PAGER;
				u->pager |= FRIEND_PAGER;
			}
			if (user->userdefine & DEF_FRIENDMSG)
				u->pager |= FRIENDMSG_PAGER;
			if (user->userdefine & DEF_ALLMSG) {
				u->pager |= ALLMSG_PAGER;
				u->pager |= FRIENDMSG_PAGER;
			}
			strsncpy(u->from, fromhost, 24);
			strsncpy(u->username, user->username, NAMELEN);
			strsncpy(u->userid, user->userid, IDLEN + 1);
			getrandomstr(u->sessionid);
			if (strcasecmp(user->userid, "guest"))
				initfriends(u);
			else
				memset(u->friend, 0, sizeof (u->friend));
			urlbase = makeurlbase(n);
			w_info = &(u_info->wwwinfo);
			w_info->login_start_time = now_t;
			w_info->ipmask = ipmask;
			if (strcasecmp(user->userid, "guest")) {
				sethomefile(fname, user->userid, "clubrights");
				if ((fp1 = fopen(fname, "r")) == NULL) {
					memset(u_info->clubrights, 0,
					       4 * sizeof (int));
				} else {
					while (fgets(genbuf, STRLEN, fp1) !=
					       NULL) {
						clubnum = atoi(genbuf);
						u_info->clubrights[clubnum /
								   32] |=
						    (1 << clubnum % 32);
					}
					fclose(fp1);
				}

				set_my_cookie();
			} else {
				memset(u_info->clubrights, 0, 4 * sizeof (int));
				w_info->t_lines = 20;
				w_info->att_mode = 0;
				w_info->doc_mode = 1;
			}
			dolog = 1;
			add_uindex(u->uid, n + 1);
		}
	}
Example #8
0
int wmllogin(char * buf)
{
	char id[IDLEN + 2], pw[20];
	struct userec *x;
	struct user_info * uol[MULTI_LOGINS];
	char buf2[256], filename[256];
	int i, kick;
	page_init(NULL);
	strncpy(id, getparm("id"), IDLEN + 1);
	strncpy(pw, getparm("pw"), 19);
	if (!*pw)
	{
		strncpy(pw, getparm("pw2"), 19);
	}
	kick = atoi(getparm("kick")) - 1;
	if (!strcasecmp(id, "SYSOP"))
	{
		strcpy (buf, "用户SYSOP登录受限。");
		return -65536;
	}
	if(file_has_word(".bad_host", fromhost)) 
	{
		sprintf (buf, "对不起, 本站不欢迎来自 [%s] 的登录。 若有疑问, 请与SYSOP联系,", fromhost);
		return -256;
	}
	if(loginok && strcasecmp(id, currentuser.userid)) 
	{
		sprintf (buf, "系统检测到目前你的计算机上已经登录有一个帐号 %s,请先退出。", currentuser.userid);
		return 1;
	}
	x = getuser(id);
	if (!x)
	{
		strcpy (buf, "错误的使用者帐号");
		return -1;
	}
	sprintf(buf2, "home/%c/%s/badhost", toupper(x->userid[0]), x->userid);
	if(bad_host(fromhost,buf2)) 
	{
		sprintf (buf, "对不起,此帐号已被设定为不可从 [%s] 登录本站。",fromhost);
		return -257;
	}
	if(strcasecmp(id, "guest")) 
	{
		if(!checkpasswd(x->passwd, pw)) 
		{
			if(*pw)
			{
				sleep(2);
				getdatestring (time(0), NA);
				sprintf(buf2, "%-12.12s  %-30s %s[Wap]\n",id, datestring, fromhost);
				sprintf(filename, "home/%c/%s/logins.bad", toupper(x->userid[0]), x->userid);
				f_append(filename, buf2);
			}
			sprintf (buf, "密码错误");
			return -2;
		}
		if (check_login_limit(x))
		{
			strcpy (buf, "此ID在24小时内上站次数过多,请稍候再来。");
			return -4;
		}
		if(!user_perm(x, PERM_BASIC))
		{
			strcpy (buf, "此帐号已被停机。若有疑问,请用其他帐号在sysop版询问。");
			return -5;
		}
		if (check_multi_d(x, uol, kick))
		{
			wml_httpheader();
			wml_head();
			printf ("<card title=\"登录 -- %s\">", BBSNAME);
			printf ("<p>用户%s已经在本站登录了%d个线程,你需要踢掉一个才能登录。<br />", x->userid, MULTI_LOGINS);
			for (i = 0; i < MULTI_LOGINS; i++)
			{
				printf ("#%d %s %s%s 发呆%d分<br />", i, uol[i]->from, uol[i]->mode >= 20000 ? "@" : "", ModeType(uol[i]->mode >= 20000 ? uol[i]->mode - 20000 : uol[i]->mode), (time(0) - uol[i]->idle_time) / 60);
			}
			printf ("踢掉哪个:<select name=\"inp_kick\">");
			for (i = 0; i < MULTI_LOGINS; i++)
			{
				printf ("<option value=\"%d\">%d</option>", i + 1, i + 1);
			}
			printf ("</select><br />");
			printf ("您的密码:<input type=\"password\" maxlength=\"8\" name=\"inp_pw\" /><br />");
			printf ("<anchor><go href=\"login.wml?id=%s\" method=\"post\"><postfield name=\"pw\" value=\"$(inp_pw)\" /><postfield name=\"kick\" value=\"$(inp_kick)\" /></go>登录</anchor></p>", x->userid);
			return 0;
		}
		x->lastlogin = time(0);
    x->numlogins++;
    strsncpy(x->lasthost, fromhost, 17);
    save_user_data(x);
    currentuser = *x;
	}
	report("WapEnter");
	int iutmpnum, iutmpkey;
	if (!wwwlogin(x, &iutmpnum, &iutmpkey))//0 : succeed
	{
		encodingtest();
		sprintf(buf2, "%d", iutmpnum);
		headerCookie("utmpnum", buf2);
		sprintf(buf2, "%d", iutmpkey);
		headerCookie("utmpkey", buf2);
		headerCookie("utmpuserid", currentuser.userid);
		wml_httpheader();
	}
	else
	{
		strcpy (buf, "抱歉,登录人数太多,请稍候再来:(");
		return -65537;
	}
	sprintf (buf, "用户 %s 登录成功。", x->userid);
	wml_head();
	printf ("<card title=\"登录 -- %s\" ontimer=\"%s\">", BBSNAME, "bbsboa.wml");
	printf ("<timer value=\"50\" />");
	printf ("<p>");
	w_hprintf(buf);
	printf ("</p>");
	printf ("<p>跳转中……</p>");
	printf ("<p><anchor><go href=\"%s\" />如果不能自动跳转,请使用此链接。</anchor></p>", "bbsboa.wml");
	return 0;
}
Example #9
0
int
bbslpassport_main()
{
	int uid, infochanged = 0;
	char id[IDLEN + 1], pw[PASSLEN], site[256], md5pass[MD5LEN], buf[384];
	struct userec *x, tmpu;
	time_t t, dtime;
	html_header(3);
	strsncpy(id, strtrim(getparm("id")), IDLEN + 1);
	strsncpy(pw, getparm("pw"), PASSLEN);
	strsncpy(site, getparm("site"), 256);

	if (!id[0])
		http_fatal("请输入帐号");
	if (!site[0])
		http_fatal("no...");
	if (key_fail)
		http_fatal("内部错误, 联系维护!\n");
	if ((uid = getuser(id, &x)) <= 0) {
		printf("%s<br>", id);
		http_fatal("错误的使用者帐号");
	}
	strcpy(id, x->userid);
	if (!strcasecmp(id, "guest"))
		http_fatal("错误的使用者帐号");

	if (checkbansite(fromhost)) {
		http_fatal
		    ("对不起, 本站不欢迎来自 [%s] 的登录. <br>若有疑问, 请与SYSOP联系.",
		     fromhost);
	}
	if (userbansite(x->userid, fromhost))
		http_fatal("本ID已设置禁止从%s登录", fromhost);
	if (!checkpasswd(x->passwd, x->salt, pw)) {
		logattempt(x->userid, fromhost, "PASSPORT", now_t);
		http_fatal
		    ("密码错误,如有疑问请联系站务组,提供注册资料找回密码");
	}
#if 0
	if (!user_perm(x, PERM_BASIC))
		http_fatal
		    ("由于本帐号名称不符合帐号管理办法,已经被管理员禁止继续上站。<br>请用其他帐号登录在 <font color=red>"
		     DEFAULTBOARD "</font> 版询问.");
	if (file_has_word(MY_BBS_HOME "/etc/prisonor", x->userid)) {
		if (x->inprison == 0) {
			memcpy(&tmpu, x, sizeof (tmpu));
			tmpu.inprison = 1;
			tmpu.dieday = 2;
			updateuserec(&tmpu, 0);
		}
		http_fatal("安心改造,不要胡闹");
	}
	if (x->dieday)
		http_fatal("死了?还要做什么? :)");
#endif
	t = x->lastlogin;
	memcpy(&tmpu, x, sizeof (tmpu));
	if (tmpu.salt == 0) {
		tmpu.salt = getsalt_md5();
		genpasswd(md5pass, tmpu.salt, pw);
		memcpy(tmpu.passwd, md5pass, MD5LEN);
		infochanged = 1;
	}
#if 1
	if (count_uindex(uid) == 0) {
		if (now_t - t > 1800)
			tmpu.numlogins++;
		infochanged = 1;
		tmpu.lastlogin = now_t;
		dtime = t - 4 * 3600;
		t = localtime(&dtime)->tm_mday;
		dtime = now_t - 4 * 3600;
		if (t < localtime(&dtime)->tm_mday && x->numdays < 60000) {
			tmpu.numdays++;
		}
	}
#endif
	if (abs(t - now_t) < 20) {
		http_fatal("两次登录间隔过密!");
	}

	if (x->lasthost != from_addr.s_addr) {
		tmpu.lasthost = from_addr.s_addr;
		infochanged = 1;
	}
	if (infochanged)
		updateuserec(&tmpu, 0);
	tracelog("%s enter %s passport %d %s", x->userid, fromhost, infochanged,
		 getsenv("HTTP_X_FORWARDED_FOR"));
	printf
	    ("<script>exDate = new Date; exDate.setMonth(exDate.getMonth()+9);"
	     "document.cookie='pp=%s;path=/;expires=' + exDate.toGMTString();</script>",
	     des3_encode(id, 0));
	snprintf(buf, sizeof (buf), "http://%s?q=%s", site, des3_encode(id, 1));
	redirect(buf);
	http_quit();
	return 0;
}
Example #10
0
int
bbslogin_main()
{
	int n, t, infochanged = 0;
	time_t dtime;
	char filename[128], buf[256], id[20], pw[PASSLEN], url[10], *ub =
	    FIRST_PAGE;
	char *ptr;
	char md5pass[MD5LEN];
	struct userec *x, tmpu;
	int ipmask;
	int uid;
	html_header(3);

	if (loginok && !isguest) {
		sprintf(buf, "/" SMAGIC "/?t=%d", (int) now_t);
		redirect(buf);
	}

	strsncpy(id, strtrim(getparm("id")), 13);
	strsncpy(pw, getparm("pw"), PASSLEN);
	strsncpy(url, getparm("url"), 3);
	ipmask = atoi(getparm("ipmask"));
	if (!id[0]) {
		strcpy(id, "guest");
		ipmask = 8;
	}
	if (!strcmp(MY_BBS_ID, "YTHT") && !strcmp(id, "guest")) {
		http_fatal("请输入用户名和密码以登录。");
	}
	if (strcmp(id, "guest")) {
		ipmask = extandipmask(ipmask, getparm("lastip1"), realfromhost);
		ipmask = extandipmask(ipmask, getparm("lastip2"), realfromhost);
	}
	if ((uid = getuser(id, &x)) <= 0) {
		printf("%s<br>", id);
		http_fatal("错误的使用者帐号");
	}
	strcpy(id, x->userid);
	if (strcasecmp(id, "guest")) {
		if (checkbansite(realfromhost)) {
			http_fatal
			    ("对不起, 本站不欢迎来自 [%s] 的登录. <br>若有疑问, 请与SYSOP联系.",
			     realfromhost);
		}
		if (userbansite(x->userid, realfromhost))
			http_fatal("本ID已设置禁止从%s登录", realfromhost);
		if (!checkpasswd(x->passwd, x->salt, pw)) {
			logattempt(x->userid, realfromhost, "WWW", now_t);
			http_fatal
			    ("密码错误,如有疑问请联系站务组,提供注册资料找回密码");
		}
		if (!user_perm(x, PERM_BASIC))
			http_fatal
			    ("由于本帐号名称不符合帐号管理办法,已经被管理员禁止继续上站。<br>请用其他帐号登录在 <font color=red>"
			     DEFAULTBOARD "</font> 版询问.");
		if (file_has_word(MY_BBS_HOME "/etc/prisonor", x->userid)) {
			if (x->inprison == 0) {
				memcpy(&tmpu, x, sizeof (tmpu));
				tmpu.inprison = 1;
				tmpu.dieday = 2;
				updateuserec(&tmpu, 0);
			}
			http_fatal("安心改造,不要胡闹");
		}
		if (x->dieday)
			http_fatal("死了?还要做什么? :)");
		t = x->lastlogin;
		memcpy(&tmpu, x, sizeof (tmpu));
		if (tmpu.salt == 0) {
			tmpu.salt = getsalt_md5();
			genpasswd(md5pass, tmpu.salt, pw);
			memcpy(tmpu.passwd, md5pass, MD5LEN);
			infochanged = 1;
		}
		if (count_uindex(uid) == 0) {
			if (now_t - t > 1800)
				tmpu.numlogins++;
			infochanged = 1;
			tmpu.lastlogin = now_t;
			dtime = t - 4 * 3600;
			t = localtime(&dtime)->tm_mday;
			dtime = now_t - 4 * 3600;
			if (t < localtime(&dtime)->tm_mday
			    && x->numdays < 60000) {
				tmpu.numdays++;
			}
		}
		if (abs(t - now_t) < 5) {
			http_fatal("两次登录间隔过密!");
		}

		if (x->lasthost != from_addr.s_addr) {
			tmpu.lasthost = from_addr.s_addr;
			infochanged = 1;
		}
		if (infochanged)
			updateuserec(&tmpu, 0);
		currentuser = x;
	}
	ptr = getsenv("HTTP_X_FORWARDED_FOR");
	tracelog("%s enter %s www %d %s", x->userid, realfromhost, infochanged,
		 ptr);
	n = 0;
	if (loginok && isguest) {
		u_info->wwwinfo.iskicked = 1;
	}
	if (strcasecmp(id, "guest")) {
		sethomepath(filename, x->userid);
		mkdir(filename, 0755);

		strsncpy(buf, getparm("style"), 3);
		wwwstylenum = -1;
		if (isdigit(buf[0]))
			wwwstylenum = atoi(buf);
		if ((wwwstylenum > NWWWSTYLE || wwwstylenum < 0))
			if (!readuservalue
			    (x->userid, "wwwstyle", buf, sizeof (buf)))
				wwwstylenum = atoi(buf);
		if (wwwstylenum < 0 || wwwstylenum >= NWWWSTYLE)
			wwwstylenum = 1;
		currstyle = &wwwstyle[wwwstylenum];
	} else {
		wwwstylenum = 1;
		currstyle = &wwwstyle[wwwstylenum];

	}
	ub = wwwlogin(x, ipmask);
#ifdef USESESSIONCOOKIE
	{
		extern char sessionCookie[];
		printf
		    ("<script>document.cookie='SESSION=%s; path=/';</script>",
		     urlencode(sessionCookie));
	}
#endif
	if (!strcmp(url, "1")) {
#if 1
		printf
		    ("<script>\n"
		     "function URLencode(sStr) {\n"
		     "return escape(sStr).replace(/\\+/g, '%%2C').replace(/\\\"/g,'%%22').replace(/\\'/g, '%%27');\n"
		     "}\n"
		     "a=window.opener.location.href;\n" "l=a.length;\n"
		     "t=a.indexOf('/" SMAGIC "',1);\n" "t=a.indexOf('/',t+1);\n"
		     //"nu=\"%s\"+\"?t=%ld&b=\"+URLencode(a.substring(t+1,l));\n"
		     "nu=\"%s\"+\"?t=%ld&b=\"+a.substring(t+1,l);\n"
		     "opener.top.location.href=nu;window.close();</script>",
		     ub, now_t);
#else
		printf
		    ("<script>opener.top.location.href='%s?t=%d';window.close();</script>",
		     ub, now_t);
#endif
	} else {
		char buf[256];
		if (strcmp(x->userid, "guest") && shouldbroadcast(uid))
			sprintf(buf, "%s?t=%d&b=ooo", ub, (int) now_t);
		else
			sprintf(buf, "%s?t=%d", ub, (int) now_t);
		redirect(buf);
	}
	http_quit();
	return 0;
}
Example #11
0
char *
wwwlogin(struct userec *user, int ipmask)
{
	FILE *fp1;
	int fd;
	int n, uid;
	struct user_info u;
	char *urlbase, fname[80];
	char buf[20];
	uid = getuser(user->userid, NULL);
	fd = open(MY_BBS_HOME "/" ULIST_BASE "." MY_BBS_DOMAIN, O_WRONLY);
	flock(fd, LOCK_EX);

	if ((urlbase = check_multi(user->userid, uid))) {
		flock(fd, LOCK_UN);
		close(fd);
		return urlbase;
	}

	if (strcasecmp(user->userid, "guest") && count_uindex(uid) >= 3) {
		flock(fd, LOCK_UN);
		close(fd);
		http_fatal("您已经登录了三个帐号,不能再登录了");
	}
	bzero(&u, sizeof (struct user_info));
	u.active = 1;
	u.uid = uid;
	u.pid = 1;
	u.mode = LOGIN;
	u.userlevel = user->userlevel;
	u.lasttime = now_t;
	u.curboard = 0;
	if (user_perm(user, PERM_LOGINCLOAK) && (user->flags[0] & CLOAK_FLAG))
		u.invisible = YEA;
	u.pager = 0;
	if (user->userdefine & DEF_FRIENDCALL)
		u.pager |= FRIEND_PAGER;
	if (user->flags[0] & PAGER_FLAG) {
		u.pager |= ALL_PAGER;
		u.pager |= FRIEND_PAGER;
	}
	if (user->userdefine & DEF_FRIENDMSG)
		u.pager |= FRIENDMSG_PAGER;
	if (user->userdefine & DEF_ALLMSG) {
		u.pager |= ALLMSG_PAGER;
		u.pager |= FRIENDMSG_PAGER;
	}
	strsncpy(u.from, fromhost, sizeof (u.from));
	u.fromIP = from_addr.s_addr;
	strsncpy(u.username, user->username, NAMELEN);
	strsncpy(u.userid, user->userid, IDLEN + 1);
	getrandomstr(u.sessionid);
	n = utmp_login(&u);
	if (n > MAXACTIVERUN || n <= 0) {
		flock(fd, LOCK_UN);
		close(fd);
		http_fatal
		    ("抱歉,目前在线用户数已达上限%d,无法登录。请稍后再来。",
		     MAXACTIVERUN);
	}
	flock(fd, LOCK_UN);
	close(fd);
	n--;
	urlbase = makeurlbase(n, uid);
	u_info = &(shm_utmp->uinfo[n]);
	w_info = &(u_info->wwwinfo);
	w_info->login_start_time = now_t;
	w_info->ipmask = ipmask;
	if (strcasecmp(user->userid, "guest")) {
		u_info->unreadmsg = get_unreadcount(user->userid);
		initfriends(u_info);
		sethomefile(fname, user->userid, "clubrights");
		if ((fp1 = fopen(fname, "r")) == NULL) {
			memset(u_info->clubrights, 0, CLUB_SIZE * sizeof (int));
		} else {
			fread(&(u_info->clubrights), sizeof (int), CLUB_SIZE,
			      fp1);
			fclose(fp1);
		}
		if (readuservalue(user->userid, "signature", buf, sizeof (buf))
		    >= 0)
			u_info->signature = atoi(buf);
		w_info->edit_mode = 1;
		set_my_cookie();
	} else {
		u_info->unreadmsg = 0;
		memset(u_info->friend, 0, sizeof (u.friend));
		memset(u_info->clubrights, 0, CLUB_SIZE * sizeof (int));
		w_info->t_lines = 20;
		w_info->att_mode = 0;
		w_info->doc_mode = 1;
	}

	if ((user->userlevel & PERM_BOARDS))
		setbmstatus(user, 1);
	return urlbase;
}