Beispiel #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;
}
Beispiel #2
0
int my_after_post(struct fileheader *fh, char *boardname)
{
	char buf[256];
	int fd, err = 0, nowid = 0;

	if (!strncmp(fh->title, "Re:", 3)) {
		strncpy(fh->title, fh->title + 4, STRLEN);
	}
	setbfile(buf, boardname, DOT_DIR);

	if ((fd = open(buf, O_WRONLY | O_CREAT, 0664)) == -1) {
		err = 1;
	}

	if (!err) {
        writew_lock(fd, 0, SEEK_SET, 0);
		nowid = get_nextid(boardname);
		fh->id = nowid;
		fh->groupid = fh->id;
		fh->reid = fh->id;
#ifdef HAVE_REPLY_COUNT
		fh->replycount = 1;
#endif /* HAVE_REPLY_COUNT */
		set_posttime(fh);
		lseek(fd, 0, SEEK_END);
		if (safewrite(fd, fh, sizeof(fileheader)) == -1) {
			err = 1;
		}
        un_lock(fd, 0, SEEK_SET, 0);
		close(fd);
	}
	if (err) {
		setbfile(buf, boardname, fh->filename);
		unlink(buf);
		return 1;
	}
	updatelastpost(boardname);

	if (fh->id == fh->groupid)
		setboardorigin(boardname, 1);
	setboardtitle(boardname, 1);
	return 0;
}
Beispiel #3
0
int
get_mail(char *host, char *oboard, char *iboard)
{
	int fd;
	FILE *fp0;
	int i;
	struct sockaddr_in xs;
	struct hostent *he;
	char dir[80], file[80], buf[256], brk[80];
//      file: 本地文件名, buf: 临时变量, brk: 分隔符.

	servernow = host;

	do_log("gethostbyname %s", host);
	bzero((char *) &xs, sizeof (xs));
	xs.sin_family = AF_INET;
	if ((he = gethostbyname(host)) != NULL)
		bcopy(he->h_addr, (char *) &xs.sin_addr, he->h_length);
	else
		xs.sin_addr.s_addr = inet_addr(host);
	xs.sin_port = htons(PORT);
	do_log("connecting %s", host);
	fd = socket(AF_INET, SOCK_STREAM, 0);
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
	if (connect(fd, (struct sockaddr *) &xs, sizeof (xs)) < 0) {
		fd_set fds;
		struct timeval timeout;
		timeout.tv_sec = 10;
		timeout.tv_usec = 0;
		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		if (select(fd + 1, NULL, &fds, NULL, &timeout) <= 0) {
			do_log("can't connect to %s", host);
			close(fd);
			return;
		}
		if (connect(fd, (struct sockaddr *) &xs, sizeof (xs)) < 0) {
			do_log("can't connect to %s", host);
			close(fd);
			return;
		}
	}
	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
	do_log("connected %s", host);
	fp0 = fdopen(fd, "r+");
	if (fgets(brk, 80, fp0) == 0)
		goto E;
	if (strlen(brk) < 10)
		goto E;
	fprintf(fp0, "select * from %s where dt < %d\n", oboard,
		time(0) - last);
	fflush(fp0);
	do_log("SEND request %s %d", oboard, time(0) - last);
	while (1) {
		FILE *fp;
		int t;
		struct fileheader x;
		char owner[256];
		bzero(&x, sizeof (x));
		do_log("reading...");
		if (fgets(x.title, sizeof (x.title), fp0) == 0)
			break;
		if (fgets(owner, sizeof (owner), fp0) == 0)
			break;
		fh_setowner(&x, owner, 0);
		check_str(x.title);
		check_str(x.owner);
		removetailspace(x.title);
		do_log("%s", x.title);
		sprintf(file, "boards/%s/", iboard);
		t = trycreatefile(file, "M.%d.A", time(NULL), 100);
		x.filetime = t;
		do_log(file);
		do_log(fh2fname(&x));
		fp = fopen(file, "w");
		while (1) {
			if (fgets(buf, 255, fp0) == 0)
				break;
			if (!strcmp(buf, brk))
				break;
			fprintf(fp, "%s", buf);
		}
		fclose(fp);
		if (!valid_user(x.owner)) {
			unlink(file);
			do_log("bad user: %s", x.owner);
			continue;
		}
		fh_find_thread(&x, iboard);
		sprintf(dir, "boards/%s/.DIR", iboard);
		fd = open(dir, O_WRONLY | O_APPEND | O_CREAT, 0660);
		write(fd, &x, sizeof (x));
		close(fd);
		do_log("updatelastpost %s", iboard);
		updatelastpost(iboard);
	};
      E:fclose(fp0);
	close(fd);
	do_log("done");
}