Exemple #1
0
int
do_del(char *board, char *file)
{
	FILE *fp;
	int num = 0, filetime;
	char path[256], buf[256], dir[256], *id = currentuser.userid;
	struct fileheader f;
	filetime = atoi(file + 2);
	sprintf(dir, "boards/%s/.DIR", board);
	sprintf(path, "boards/%s/%s", board, file);
	fp = fopen(dir, "r");
	if (fp == 0)
		http_fatal("错误的参数");
	while (1) {
		if (fread(&f, sizeof (struct fileheader), 1, fp) <= 0)
			break;
		if (f.filetime == filetime) {
			del_record(dir, sizeof (struct fileheader), num);
			cancelpost(board, id, &f, !strcmp(id, f.owner));
			updatelastpost(board);
			fclose(fp);
			printf("<tr><td>%s  <td>标题:%s <td>删除成功.\n",
			       fh2owner(&f), nohtml(f.title));
			snprintf(buf, 256, "%s del %s %s %s",
				 currentuser.userid, board, fh2owner(&f),
				 f.title);
			newtrace(buf);
			return 0;
		}
		num++;
	}
	fclose(fp);
	printf("<tr><td><td>%s<td>文件不存在.\n", file);
	return -1;
}
Exemple #2
0
int
do_set(char *dirptr, int size, char *file, int flag, char *board)
{
	char path[256], buf[256];
	struct fileheader *f;
	int om, og, nm, ng, filetime;
	int start;
	int total = size / sizeof(struct fileheader);
	filetime = atoi(file + 2);
	sprintf(path, "boards/%s/%s", board, file);

	start = Search_Bin(dirptr, filetime,0 , total - 1);
	if (start >= 0) {
		f = (struct fileheader*)(dirptr + start * sizeof(struct fileheader));
		om = f->accessed & FH_MARKED;
		og = f->accessed & FH_DIGEST;
		f->accessed |= flag;
		if (flag == 0) 
			f->accessed = 0;
		nm = f->accessed & FH_MARKED;
		ng = f->accessed & FH_DIGEST;
		printf("<tr><td>%s<td>标题:%s<td>标记成功.\n",
		       fh2owner(f), nohtml(f->title));
		buf[0] = 0;
		if ((!om) && (nm))
			snprintf(buf, 256, "%s mark %s %s %s",
				 currentuser.userid, board,
				 fh2owner(f), f->title);
		if ((om) && (!nm))
			snprintf(buf, 256, "%s unmark %s %s %s",
				 currentuser.userid, board,
				 fh2owner(f), f->title);
		if ((!og) && (ng))
			snprintf(buf, 256, "%s digest %s %s %s",
				 currentuser.userid, board,
				 fh2owner(f), f->title);
		if ((og) && (!ng))
			snprintf(buf, 256, "%s undigest %s %s %s",
				 currentuser.userid, board,
				 fh2owner(f), f->title);
		if (buf[0] != 0)
			newtrace(buf);
		return 0;
	}
	printf("<td><td><td>%s<td>文件不存在.\n", file);
	return -1;
}
Exemple #3
0
int
bbslogout_main()
{
	struct userec *tmp;
	int st;
	char buf[50];
	int uid;
	html_header(1);
	//modified by safari@20091222
	if (!loginok) {
		redirect(FIRST_PAGE);
		http_quit();
		//http_fatal("你没有登录");
	}
	if (isguest)
		http_fatal("guest不带注销的");
	tmp = getuser(currentuser.userid);
	currentuser.numposts = tmp->numposts;
	currentuser.userlevel = tmp->userlevel;
	currentuser.numlogins = tmp->numlogins;
	currentuser.stay = tmp->stay;
	if (now_t > w_info->login_start_time) {
		st = now_t - w_info->login_start_time;
		if (st > 86400)
			errlog("Strange long stay time,%d!, logout, %s", st, currentuser.userid);
		else {
			currentuser.stay += st;
			sprintf(buf, "%s exitbbs %d", currentuser.userid, st);
			newtrace(buf);
		}
	}
	save_user_data(&currentuser);
	uid = u_info->uid;
	remove_uindex(u_info->uid, utmpent);
	bzero(u_info, sizeof (struct user_info));
	if ((currentuser.userlevel & PERM_BOARDS) && count_uindex(uid)==0)
		setbmstatus(&currentuser, 0);
	redirect(FIRST_PAGE);
	return 0;
}
Exemple #4
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;
}
Exemple #5
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);
		}
	}
Trace *
read_trace (Dbptr db, double tstart, double tend)

{
    char fname[1024];
    char dtype[8];
    char segtype[8];
    long foff, nsamp;
    void *data;
    Trace *trace;
    double time, samprate;
    double calib, calper;
    double ts, te;
    int size;
    int i, ret;

    if (dbextfile (db, "wfdisc", fname) < 1) {
        fprintf (stderr, "read_trace: Unable to find input file '%s'\n",
                 fname);
        return (NULL);
    }
    dbgetv (db, 0, "time", &time, "samprate", &samprate,
            "nsamp", &nsamp, "datatype", dtype,
            "segtype", segtype, "foff", &foff,
            "calib", &calib, "calper", &calper, NULL);

    data = NULL;
    ret = trgetwf (db, NULL, (Trsample **) &data, 0, tstart, tend,
                   &ts, &te, &nsamp, 0, 0);
    size = 4;

    switch (ret) {
    default:
    case 0:
        if (ret < 0) data = NULL;
        if (ts == 0.0 && te == 0.0) data = NULL;
        break;

    case -9: /* no data */
        clear_register (0);
        data = NULL;
        break;

    case -1:
    case -2:
    case -3:
    case -5:
    case -6:
    case -7:
    case -8:
        complain (0,
                  "read_trace: trgetwf() error.\n");
        return (NULL);
    }

    if (data == (void *) -1) {
        data = NULL;
    }

    if (data == (void *) -2) {
        clear_register (0);
        data = NULL;
    }
    trace = newtrace();
    if (trace == NULL) {
        fprintf (stderr, "read_trace: newtrace() error.\n");
        my_free (data);
        return (NULL);
    }
    trace->scv = NULL;
    trace->tstart = ts;
    trace->dt = 1.0/samprate;
    trace->nsamps = nsamp;
    trace->calib = calib;
    trace->calper = calper;
    strcpy (trace->rawdata_format, "t4");
    strcpy (trace->rawdata_type, segtype);
    strcpy (trace->input_units, "");
    strcpy (trace->output_units, "");
    trace->data = NULL;
    trace->data_free = NULL;
    trace->data_malloc = 0;
    trace->raw_data = data;
    trace->rawdata_free = data;
    if (data) trace->rawdata_malloc = nsamp*size;
    else trace->rawdata_malloc = 0;
    trace->prev = NULL;
    trace->next = NULL;
    for (i=0; i<trace->nsamps; i++) if (((float *)data)[i] < 0.9e30) break;
    if (i >= trace->nsamps) {
        trace->nsamps = 0;
        trace->raw_data = NULL;
        trace->rawdata_free = NULL;
        free (data);
    } else {
        if (data) {
            trace = (Trace *) SCV_trace_fixgaps (trace, "segment");
        }
    }
    return (trace);
}