Ejemplo n.º 1
0
/*
 * Function used to setup a tmp table for
 * displaying results (binary search)
 */
static tbl_p setup_tmp_table(page_p page, schema_p s){

	char 				tmp_name[30] = "tmp_tbl__";
	schema_p			res_sch;
	record				rec;

	if(page == NULL || s == NULL)
	{
		exit(1);
	}

	strcat (tmp_name, s->name);

	res_sch = copy_schema ( s, tmp_name );

	rec = new_record ( s );

	get_page_record(page, rec, s);

	put_record_info (DEBUG, rec, s);

	append_record ( rec, res_sch );

	// Print debug info
	put_pager_profiler_info(INFO);

	return res_sch->tbl;
}
Ejemplo n.º 2
0
Archivo: post.c Proyecto: Fdhvdu/pttbbs
void keeplog(FILE *fin, char *board, char *title, char *owner) {
    fileheader_t fhdr;
    char genbuf[256], buf[512];
    FILE *fout;
    int bid;
    
    sprintf(genbuf, BBSHOME "/boards/%c/%s", board[0], board);
    stampfile(genbuf, &fhdr);
    
    if(!(fout = fopen(genbuf, "w"))) {
	perror(genbuf);
	return;
    }
    
    while(fgets(buf, 512, fin))
	fputs(buf, fout);
    
    fclose(fin);
    fclose(fout);
    
    strncpy(fhdr.title, title, sizeof(fhdr.title) - 1);
    fhdr.title[sizeof(fhdr.title) - 1] = '\0';
    
    strcpy(fhdr.owner, owner);
    sprintf(genbuf, BBSHOME "/boards/%c/%s/.DIR", board[0], board);
    append_record(genbuf, &fhdr, sizeof(fhdr));
    /* XXX: bid of cache.c's getbnum starts from 1 */
    if((bid = getbnum(board)) > 0)
	touchbtotal(bid);

}
Ejemplo n.º 3
0
int bbsfadd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	const char *id = getparm("id");
	const char *desc = getparm("desc");
	if (*id != '\0') {
		override_t ov;
		memset(&ov, 0, sizeof(ov));
		strlcpy(ov.id, id, sizeof(ov.id));
		if (!searchuser(ov.id))
			return BBS_ENOUSR;
		strlcpy(ov.exp, desc, sizeof(ov.exp));
		char file[HOMELEN];
		sethomefile(file, currentuser.userid, "friends");
		if (get_num_records(file, sizeof(ov)) == MAXFRIENDS)
			return BBS_EFRNDQE;
		// TODO: be atomic
		if (!search_record(file, NULL, sizeof(ov), cmpname, ov.id))
			append_record(file, &ov, sizeof(ov));
		printf("Location: fall\n\n");
		return 0;
	}
	xml_header("bbs");
	printf("<bbsfadd ");
	print_session();
	printf(">%s</bbsfadd>", id);
	return 0;
}
Ejemplo n.º 4
0
void mailUser(char *userid)
{
    int count;
    FILE *fp, *fp2;
    time4_t t;
    fileheader_t header;
    struct stat st;
    char filename[512];

    fp2 = fopen(mailfile, "r");
    if (fp2 == NULL) {
	fprintf(stderr, "Cannot open file %s\n", mailfile);
	return;
    }

    sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid);
    if (stat(filename, &st) == -1) {
	if (Mkdir(filename) == -1) {
	    fprintf(stderr, "mail box create error %s \n", filename);
	    fclose(fp2);
	    return;
	}
    }
    else if (!(st.st_mode & S_IFDIR)) {
	fprintf(stderr, "mail box error\n");
	fclose(fp2);
	return;
    }

    stampfile(filename, &header);
    fp = fopen(filename, "w");
    if (fp == NULL) {
	fprintf(stderr, "Cannot open file %s\n", filename);
	fclose(fp2);
	return;
    }

    t = time(NULL);
    fprintf(fp, "作者: 小天使系統\n"
	    "標題: 給小天使的一封信\n"
	    "時間: %s\n",
	    ctime4(&t));

    while ((count = fread(filename, 1, sizeof(filename), fp2))) {
	fwrite(filename, 1, count, fp);
    }
    fclose(fp);
    fclose(fp2);

    strcpy(header.title, "給小天使的一封信");
    strcpy(header.owner, "小天使系統");
    sprintf(filename, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
    append_record(filename, &header, sizeof(header));
    mailalertuser(userid);
    printf("%s\n", userid);
}
Ejemplo n.º 5
0
void del_file(char *userid)
{
    char buf[200], buf1[200];
    struct dirent *de;
    DIR *dirp;
    char *ptr;

    sprintf(buf, BBSHOME "/home/%c/%s", userid[0], userid);

    if (chdir(buf) == -1)
	return;

    if (!(dirp = opendir(buf)))
	return;

    while ((de = readdir(dirp)))
    {
	ptr = de->d_name;
	if (ptr[0] > ' ' && ptr[0] != '.')
	{
	    if (strstr(ptr, "writelog"))
#ifdef HOLDWRITELOG
	    {
		fileheader_t mymail;

		stampfile(buf, &mymail);
		mymail.filemode = FILE_READ;
		strcpy(mymail.owner, "[備.忘.錄]");
		strcpy(mymail.title, "熱線記錄");
		sprintf(buf1, BBSHOME "/home/%c/%s/writelog",
			userid[0], userid);
		rename(buf1, buf);
		sprintf(buf1, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
		append_record(buf1, &mymail, sizeof(mymail));
	    }
#else
	    unlink(ptr);
#endif
	    else if (strstr(ptr, "chat_"))
		unlink(ptr);
	    else if (strstr(ptr, "ve_"))
		unlink(ptr);
	    else if (strstr(ptr, "SR."))
		unlink(ptr);
	    else if (strstr(ptr, ".old"))
		unlink(ptr);
	    else if (strstr(ptr, "talk_"))
		unlink(ptr);
	}
    }
Ejemplo n.º 6
0
int mail_file(char *tmpfile,char * userid,char * title)
{
	struct fileheader newmessage;
	struct stat st;
	char    fname[STRLEN], filepath[STRLEN], *ip;
	char genbuf[STRLEN],save_title[STRLEN],save_filename[STRLEN];
	int     fp, count;
	memset(&newmessage, 0, sizeof(newmessage));
	sprintf(genbuf, "%s (%s)",BBSID,BBSNAME);
	strncpy(newmessage.owner, genbuf, STRLEN);
	strncpy(newmessage.title, title, STRLEN);
	strncpy(save_title, newmessage.title, STRLEN);
	sprintf(filepath, "/home/bbs/mail/%c/%s", toupper(userid[0]), userid);
	if (stat(filepath, &st) == -1)
	{
		if (mkdir(filepath, 0755) == -1)
			return -1;
	}
	else
	{
		if (!(st.st_mode & S_IFDIR))
			return -1;
	}
	sprintf(fname, "M.%d.A", time(NULL));
	sprintf(filepath, "/home/bbs/mail/%c/%s/%s", toupper(userid[0]), userid, fname);
	ip = strrchr(fname, 'A');
	count = 0;
	while ((fp = open(filepath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1)
	{
		if (*ip == 'Z')
			ip++, *ip = 'A', *(ip + 1) = '\0';
		else
			(*ip)++;
		sprintf(filepath, "mail/%c/%s/%s", toupper(userid[0]), userid, fname);
		if (count++ > MAX_POSTRETRY)
		{
			return -1;
		}
	}
	close(fp);
	strcpy(newmessage.filename, fname);
	strncpy(save_filename, fname, STRLEN);
	sprintf(filepath, "/home/bbs/mail/%c/%s/%s", toupper(userid[0]), userid, fname);
	sprintf(genbuf,"/bin/cp %s %s",tmpfile,filepath);
	system(genbuf);
	sprintf(genbuf, "/home/bbs/mail/%c/%s/%s", toupper(userid[0]), userid, ".DIR");
	if (append_record(genbuf, &newmessage, sizeof(newmessage)) == -1)
		return -1;

}
Ejemplo n.º 7
0
void informBM(char *userid, boardheader_t *bptr, int nEXP)
{
    int     uid, i;
    char    filename[256], buf[64];
    fileheader_t mymail;
    FILE    *fp;
    if( !(uid = searchuser(userid, userid)) )
	return;
    sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid);
    stampfile(filename, &mymail);
    if( (fp = fopen(filename, "w")) == NULL )
	return;

    printf("brdname: %s, BM: %s\n", bptr->brdname, userid);
    fprintf(fp,
	    "作者: 系統通知.\n"
	    "標題: 警告: 貴板板友即將過期/已經過期\n"
	    "時間: %s\n"
	    " %s 的板主您好: \n"
	    "    下列貴板板友即將過期或已經過期:\n"
	    "------------------------------------------------------------\n",
	    CTIMEx(buf, now), bptr->brdname);
    for( i = 0 ; i < nEXP ; ++i )
	if( explist[i].expire == -1 )
	    fprintf(fp, "%-15s  已經過期\n", explist[i].userid);
	else
	    fprintf(fp, "%-15s  即將在 %s 過期\n",
		    explist[i].userid, CTIMEx(buf, explist[i].expire));
    fprintf(fp,
	    "------------------------------------------------------------\n"
	    "說明:\n"
	    "    為了節省系統資源, 系統將自動清除掉超過四個月未上站\n"
	    "的使用者. 此時若有某位您不認識的使用者恰好註冊了該帳號,\n"
	    "將會視為貴板板友而放行進入.\n"
	    "    建議您暫時將這些使用者自貴板的板友名單中移除.\n"
	    "\n"
	    "    這封信件是由程式自動發出, 請不要直接回覆這封信. 若\n"
	    "您有相關問題請麻煩至看板 SYSOP, 或是直接與看板總管聯繫. :)\n"
	    "\n"
	    BBSNAME "站長群敬上"
	    );
    fclose(fp);

    strcpy(mymail.title, "警告: 貴板板友即將過期/已經過期");
    strcpy(mymail.owner, "系統通知.");
    sprintf(filename, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
    mailalertuid(uid);
    append_record(filename, &mymail, sizeof(mymail));
}
Ejemplo n.º 8
0
void
csbbslog(const char *mode, const char *fmt, ...)
{
	va_list args;
	time_t now;
	char msgbuf[128], buf[128];
	char timestr[20];

	va_start(args, fmt);
	vsprintf(msgbuf, fmt, args);
	va_end(args);

	time(&now);
	strftime(timestr, sizeof(timestr), "%m/%d/%Y %X", localtime(&now));

	sprintf(buf, "%s %.8s: %s\n", timestr, mode, msgbuf);
	append_record("log/csbbs.log", buf, strlen(buf));
}
Ejemplo n.º 9
0
static int do_article(const char *fname, const char *path,
		      const char *owner, const char *title)
{
	char *p, mypath[PATHLEN];
	struct fileheader fh;

	if (mycp(fname, path))
		return -1;
	strcpy(mypath, path);
	p = strrchr(mypath, '/') + 1;
	bzero(&fh, sizeof(fh));
	strcpy(fh.filename, p);
	strcpy(fh.owner, owner);
	strcpy(fh.title, title);
	strcpy(p, DIR_REC);
	if (append_record(mypath, &fh, sizeof(fh)) == 0)
		return 0;
	return -1;
}
Ejemplo n.º 10
0
static void insert_row ()
{
  char tbl_name[30];
	
  fscanf (in_s, " into %s values (", tbl_name);
  put_msg(DEBUG, "table name: \"%s\".\n", tbl_name);
  schema_p sch = get_schema (tbl_name);
  if (!sch)
    {
      put_msg (ERROR, "Schema \"%s\" does not exist.\n", tbl_name);
      skip_line ();
      return;
    }
  /* put_schema_info (DEBUG, sch); */
  record rec = new_filled_record ( sch );

  append_record (rec, sch);
  release_record (rec, sch);
}
Ejemplo n.º 11
0
static void
a_additem(menu_t * pm, const fileheader_t * myheader)
{
    char            buf[PATHLEN];

    setadir(buf, pm->path);
    if (append_record(buf, myheader, FHSZ) == -1)
	return;
    pm->now = pm->num++;

    if (pm->now >= pm->page + p_lines) {
	pm->page = pm->now - ((pm->page == 10000 && pm->now > p_lines / 2) ?
			      (p_lines / 2) : (pm->now % p_lines));
    }
    /* Ptt */
    strlcpy(pm->header[pm->now - pm->page].filename,
	    myheader->filename,
	    sizeof(pm->header[pm->now - pm->page].filename));
}
Ejemplo n.º 12
0
int visit_all()
{
	struct titlenode *tmp;
	struct fileheader post;
	int     i = 0;
	tmp = toptitle.next;

	while (tmp)
	{
		struct postnode *tmppost;
		i++;
		tmppost = tmp->post;
		while (tmppost)
		{
			get_record(fname, &post, sizeof(post), tmppost->num);
			append_record(tname, &post, sizeof(post));
			tmppost = tmppost->next;
		}
		tmp = tmp->next;
	}

}
Ejemplo n.º 13
0
int transman(char *path)
{
  char name[128];
  char buf[512], filename[512], *direct="";
  int n=0;
  fileheader_t fh;
  FILE *fp;

  chdir(path);

  fp = fopen(".Names", "r");
  if(fp)
   for(n=0; fgets(buf,512,fp)>0; n++)
   {
     strtok(buf,"\r\n");
     if(buf[0]=='#') continue;
     if(buf[0]=='N') 
        strcpy(name, buf+5);
     else 
       if(buf[0]=='P') 
        { 
         direct = buf+7;
         strcpy(filename, ".");
         stampfile(filename, &fh);
         unlink(filename);
         if(dashd(direct))
                 {
                  sprintf(fh.title, "¡» %s", name);
                  transman(direct);     
                 }
         else
                  sprintf(fh.title, "¡º %s", name);
         rename(direct, filename);
         append_record(".DIR", &fh, sizeof(fh)); 
        }
   }
  chdir("..");
  return n;
}
Ejemplo n.º 14
0
tbl_p table_project ( tbl_p t, const char *dest_name,
		      int num_fields, char *fields[] )
{
  schema_p s = t->sch;
  schema_p dest = make_sub_schema ( s, dest_name, num_fields, fields );
  if ( dest == NULL ) return NULL;

  record rec = new_record ( s ), rec_dest = new_record ( dest );

  set_tbl_position ( t, TBL_BEG );
  while ( get_record ( rec, s ) ) 
    {
      fill_sub_record ( rec_dest, dest, rec, s );
      put_record_info (DEBUG, rec_dest, dest);
      append_record ( rec_dest, dest );
    }

  release_record (rec, s);
  release_record (rec_dest, dest);

  return dest->tbl;
}
Ejemplo n.º 15
0
static unsigned char* get_difference_fast(unsigned char *before, 
		int before_len,
		unsigned char *after,
		int after_len,
		int *result_len,
		int verbose)
{
	unsigned char *result = new unsigned char[4];
	*result_len = 4;

// Store size of new buffer
	*(int32_t*)result = after_len;



// Get last different bytes
	unsigned char *last_difference_after = after + after_len - 1;
	unsigned char *last_difference_before = before + before_len - 1;
	while(1)
	{
		if(last_difference_after < after || 
			last_difference_before < before) break;
		if(*last_difference_after != *last_difference_before)
		{
			break;
		}
		last_difference_after--;
		last_difference_before--;
	}
	last_difference_after++;
	last_difference_before++;






	int done = 0;
	unsigned char *before_ptr = before;
	unsigned char *after_ptr = after;
	unsigned char *before_end = before + before_len;
	unsigned char *after_end = after + after_len;

// Scan forward for first difference
	while(!done)
	{
		if(before_ptr < before_end && 
			after_ptr < after_end)
		{
// Both characters equal
			if(*before_ptr == *after_ptr &&
				before_ptr < last_difference_before &&
				after_ptr < last_difference_after)
			{
				before_ptr++;
				after_ptr++;			
			}
			else
// Characters differ
			{
// Get length of difference.
				unsigned char *before_difference_start = before_ptr;
				unsigned char *after_difference_start = after_ptr;


				while(*before_ptr != *after_ptr &&
					before_ptr < last_difference_before &&
					after_ptr < last_difference_after)
				{
					before_ptr++;
					after_ptr++;
				}

// Finished comparing if either pointer hits its last difference
				if(before_ptr >= last_difference_before ||
					after_ptr >= last_difference_after)
				{
					done = 1;
					before_ptr = last_difference_before;
					after_ptr = last_difference_after;
				}



				int after_start = after_difference_start - after;
				int before_start = before_difference_start - before;
				int after_len = after_ptr - after_difference_start;
				int before_len = before_ptr - before_difference_start;

				if(verbose)
				{
					char string[1024];
					memcpy(string, after_difference_start, MIN(after_len, 40));
					string[MIN(after_len, 40)] = 0;
					printf("after_offset=0x%x before_offset=0x%x after_size=%d before_size=%d \"%s\"\n", 
						after_start, 
						before_start,
						after_len,
						before_len,
						string);
				}


// Create difference record
				append_record(&result,
					result_len,
					after_difference_start,
					after_start,
					after_len,
					before_len);
			}
		}
		else
			done = 1;
	}
	return result;
}
Ejemplo n.º 16
0
int
m_sob(void)
{
    char genbuf[256], buf[256], userid[25], passbuf[24], msg[2048]="";
    int count=0, i, isimported=0, corrected;
    FILE *fp;
    sobuserec man;
    time4_t d;

    clear();
    move(1,0);

    outs(
 "   請注意 這是只給陽光沙灘使用者!\n"
 "      讓沙灘的使用者轉移個人資產以及重要信用資料, 享有平等安全的環境.\n"
 "      如果您不需要, 請直離開.\n"
 "    -----------------------------------------------------------------\n"
 "    特別叮嚀:\n"
 "      為了帳號安全,您只有連續十次密碼錯誤的機會,請小心輸入.\n"
 "      連續次錯誤您的變身功\能就會被開罰單並直接通知站長.\n"
 "      請不要在變身過程中不正常斷線, 刻意斷線變半獸人站長不救唷.\n"
	);

   if(getkey("是否要繼續?(y/N)")!='y') return 0;
   if(search_ulistn(usernum,2)) 
        {vmsg("請登出其他視窗, 以免變身失敗"); return 0;}
   do
   {
    if(!getdata(10,0, "      沙灘的ID [大小寫要完全正確]:", userid, 20,
	       DOECHO)) return 0;
    if(bad_user_id(userid)) continue;
    sprintf(genbuf, "sob/passwd/%c/%s.inf",userid[0], userid);
    if(!(fp=fopen(genbuf, "r"))) 
       {
        isimported = 1;
        strcat(genbuf, ".done");
        if(!(fp=fopen(genbuf, "r")))
         {
           vmsg("查無此人或已經匯入過..請注意大小寫 ");
           isimported = 0;
           continue;
         }
       }
    count = fread(&man, sizeof(man), 1, fp);
    fclose(fp);
   }while(!count);
   count = 0;
   do{
    if(!getdata(11,0, "      沙灘的密碼:", passbuf, sizeof(passbuf), 
		  NOECHO)) return 0;
    if(++count>=10)
    {
          cuser.userlevel |= PERM_VIOLATELAW;
          cuser.vl_count++;
	  passwd_update(usernum, &cuser);
          post_violatelaw(cuser.userid, "[PTT警察]", "測試帳號錯誤十次",
		          "違法觀察");
          mail_violatelaw(cuser.userid, "[PTT警察]", "測試帳號錯誤十次",
		          "違法觀察");

          return 0;
    }
    if(!(corrected = checkpasswd(man.passwd, passbuf)))
       vmsg("密碼錯誤"); 
   } while(!corrected);
   move(12,0);
   clrtobot();

   if(!isimported)
     {
       if(!dashf(genbuf))  // avoid multi-login
       {
         vmsg("請不要嘗試多重id踹匯入");
         return 0;
       }
       sprintf(buf,"%s.done",genbuf);
       rename(genbuf,buf);
#ifdef MERGEMONEY

   reload_money(); 

   sprintf(buf, 
           "您的沙灘鸚鵡螺 %10d 換算成 " MONEYNAME " 幣為 %9d (匯率 22:1), \n"
           "    沙灘貝殼有 %10d 換算為 " MONEYNAME " 幣為 %9d (匯率 222105:1), \n"
           "    原有 %10d 匯入後共有 %d\n",
	   (int)man.goldmoney, (int)man.goldmoney/22, 
	   (int)man.silvermoney, (int)man.silvermoney/222105,
	   cuser.money,
	   (int)(cuser.money + man.goldmoney/22 + man.silvermoney/222105));
   demoney(man.goldmoney/22 + man.silvermoney/222105 );
   strcat(msg, buf); 
#endif

     i =  cuser.exmailbox + man.exmailbox + man.exmailboxk/2000;
     if (i > MAX_EXKEEPMAIL) i = MAX_EXKEEPMAIL;
     sprintf(buf, "您的沙灘信箱有 %d (%dk), 原有 %d 匯入後共有 %d\n", 
	    man.exmailbox, man.exmailboxk, cuser.exmailbox, i);
     strcat(msg, buf);
     cuser.exmailbox = i;

     if(man.userlevel & PERM_MAILLIMIT)
      {
       sprintf(buf, "開啟信箱無上限\n");
       strcat(msg, buf);
       cuser.userlevel |= PERM_MAILLIMIT;
      }

     if (cuser.firstlogin > man.firstlogin)
	 d = man.firstlogin;
     else
	 d = cuser.firstlogin;
     cuser.firstlogin = d;

     if (cuser.numlogins < man.numlogins)
	 i = man.numlogins;
     else
	 i = cuser.numlogins;

     sprintf(buf, "沙灘進站次數 %d 此帳號 %d 將取 %d \n", man.numlogins,
	   cuser.numlogins, i);
     strcat(msg,buf);
     cuser.numlogins = i;

     if (cuser.numposts < man.numposts )
	 i = man.numposts;
     else
	 i = cuser.numposts;
     sprintf(buf, "沙灘文章次數 %d 此帳號 %d 將取 %d\n", 
                 man.numposts,cuser.numposts,i);
     strcat(msg,buf);
     cuser.numposts = i;
     outs(msg);
     while (search_ulistn(usernum,2)) 
        {vmsg("請將重覆上站其他線關閉! 再繼續");}
     passwd_update(usernum, &cuser);
   }
   sethomeman(genbuf, cuser.userid);
   mkdir(genbuf, 0755);
   sprintf(buf, "tar zxvf %c/%s.tar.gz>/dev/null",
	   userid[0], userid);
   chdir("sob/home");
   system(buf);
   chdir(BBSHOME);

   if (getans("是否匯入個人信箱? (Y/n)")!='n')
   {
	sethomedir(buf, cuser.userid);
	sprintf(genbuf, "sob/home/%c/%s/.DIR",
		userid[0], userid);
	merge_dir(buf, genbuf, 1);
        strcat(msg, "匯入個人信箱\n");
   }
   if(getans("是否匯入個人信箱精華區(個人作品集)? (會覆蓋\現有設定) (y/N)")=='y')
   {
        fileheader_t fh;
        sprintf(buf,
	 "rm -rd home/%c/%s/man>/dev/null ; "
         "mv sob/home/%c/%s/man home/%c/%s>/dev/null;"
         "mv sob/home/%c/%s/gem home/%c/%s/man>/dev/null", 
              cuser.userid[0], cuser.userid,
	      userid[0], userid,
	      cuser.userid[0], cuser.userid,
	      userid[0], userid,
	      cuser.userid[0], cuser.userid);
        system(buf);
        strcat(msg, "匯入個人信箱精華區(個人作品集)\n");
        sprintf(buf,"home/%c/%s/man/gem", cuser.userid[0], cuser.userid);
        if(dashd(buf))
         {
          strcat(fh.title, "◆ 個人作品集");
          strcat(fh.filename, "gem");
          sprintf(fh.owner, cuser.userid);
          sprintf(buf, "home/%c/%s/man/.DIR", cuser.userid[0], cuser.userid);
          append_record(buf, &fh, sizeof(fh));
         }
   }
Ejemplo n.º 17
0
Archivo: xyz.c Proyecto: dk00/old-stuff
int
Goodbye()
{
  extern void movie();
  char genbuf[200];

/*
woju
*/
  char ans[4];


  setuserfile(genbuf, fn_writelog);
  if (more(genbuf, NA) != -1) {
/* MH */
/* Àˬd¤ô²y°O¿ý®e¶q, ÁקK¦³¤H¡u¤Ù¿n¡v¤j¶q¤ô²y */
     struct stat st;
     int writelog_limit;
    
     if (HAS_PERM(PERM_BM))
        writelog_limit = MH_WRITELOGLIMIT_BM;
     else if (HAS_PERM(PERM_LOGINOK))
        writelog_limit = MH_WRITELOGLIMIT_LOGINOK;
     else
        writelog_limit = MH_WRITELOGLIMIT_BASIC;
     do
     {
       char buf[80];
       
       setuserfile(buf, fn_writelog);
       stat(buf, &st);
       if(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT) && st.st_size / 1024 > writelog_limit)
       {
         my_outmsg_row("±zªº¤ô²y°O¿ý¤w¶W¹L­­©w®e¶q¡AµLªk¿ï¾Ü¡u«O¯d¡v", b_lines - 2);
         getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) (C/M)?[M]",
            ans, 3, LCECHO, 0);
       }
       else
       {
         getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) «O¯d(R) (C/M/R)?[R]",
            ans, 3, LCECHO, 0);
       }
       if (*ans == 'm') {
          fileheader mymail;
          char title[128], buf[80];

          sethomepath(buf, cuser.userid);
          stampfile(buf, &mymail);

          mymail.savemode = 'H';        /* hold-mail flag */
          mymail.filemode = FILE_READ;
          strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]");
          strcpy(mymail.title, "¼ö½u°O¿ý");
          if(mh_memoforward(cuser.userid, genbuf, &mymail, sizeof(mymail)))
          {
            sethomedir(title, cuser.userid);
            append_record(title, &mymail, sizeof(mymail));
            /* MH: ³Æ§Ñ¿ý¥[¤W§@ªÌ¼ÐÃDµ¥¸ê°T...¤£µM¦b'x'Âà±H©Î¬Obuildirªº®É­Ô
                   ·|Äê±¼ */
#if 1
            {
              FILE *src, *dst;
              char buf2[200];
              time_t now;
              
              if((src = fopen(genbuf, "r")) == NULL)
              {
                sprintf(buf2, "errno: %d, genbuf:%s", errno, genbuf);
                log_usies("MH ", buf2);
              }
              if((dst = fopen(buf, "w")) == NULL)
              {
                sprintf(buf2, "errno: %d, buf:%s", errno, buf);
                log_usies("MH ", buf2);
                fclose(src);
              }
              now = time(NULL);
              sprintf(buf2, "§@ªÌ: %s\n¼ÐÃD: %s\n®É¶¡: %s\n", mymail.owner, mymail.title, ctime(&now));
              fputs(buf2, dst);
              while(fgets(buf2, 199, src) != NULL)
                fputs(buf2, dst);
              fclose(src);
              fclose(dst);
              unlink(genbuf);
            }
#else
            Rename(genbuf, buf);
#endif
          }
        }
       else if (*ans == 'c') {
          char buf[80];

          setuserfile(buf, fn_writelog);
          unlink(buf);
       }
     } while(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT) && st.st_size / 1024 > writelog_limit && *ans != 'm' && *ans != 'c');

      clear();
      move(0, 0);
      prints("                             °ª¶¯¤¤¾Ç-¬õ¼Ó¿v¹Ú                                ");
      movie(0);
  }
/*    */

  getdata(b_lines - 1, 0, "±z½T©w­nÂ÷¶}¡i " BOARDNAME " ¡j¶Ü(Y/N)¡H[N] ",
    genbuf, 3, LCECHO, 0);

  if (*genbuf != 'y')
    return 0;

  movie(999);
  if (cuser.userlevel)
  {
    getdata(b_lines - 1, 0, "(G)ÀH­·¦Ó³u (M)¦«¹Ú¯¸ªø (N)¦X§@ªÀªº¨¥½×¼s³õ¡H[G] ",
      genbuf, 3, LCECHO, 0);
    if (genbuf[0] == 'm')
      mail_sysop();
    else if (genbuf[0] == 'n')
      note();
  }

  save_userrc();
#if 0
  save_mailmsg();
#endif

  clear();
  prints("¿Ë·Rªº %s(%s)¡A§O§Ñ¤F¦A«×¥úÁ{"
    " %s ¡I\n¥H¤U¬O±z¦b¯¸¤ºªºµù¥U¸ê®Æ:\n",
    cuser.userid, cuser.username, BoardName);
  user_display(&cuser, 0);

  if (currmode)
    u_exit("EXIT ");

  pressanykey();
  sleep(1);
  reset_tty();
  exit(0);
}
Ejemplo n.º 18
0
int
append_record_forward(char *fpath, fileheader_t * record, int size, const char *origid)
{
    FILE *fp;
    char buf[PATHLEN];
    char address[64] = "";
    char fwd_title[STRLEN] = "";
    int r;

    // No matter what, append it, and return if that failed.
    r = append_record(fpath, record, size);
    if (r < 0)
        return r;

// #ifdef USE_MAIL_AUTO_FORWARD

    if (strlen(fpath) + strlen(FN_FORWARD) >= PATHLEN) {
        log_filef("log/invalid_append_record_forward", LOG_CREAT,
                  "%s %s %s\n", Cdatelite(&now), cuser.userid, fpath);
        return -1;
    }
    setdirpath(buf, fpath, FN_FORWARD);
    fp = fopen(buf, "r");
    if (!fp)
        return 0;

    // Load and setup address
    address[0] = 0;
    fscanf(fp, "%63s", address);
    fclose(fp);
    chomp(address);
    strip_blank(address, address);

#ifdef UNTRUSTED_FORWARD_TIMEBOMB
    if (dasht(buf) < UNTRUSTED_FORWARD_TIMEBOMB) {
        // We may unlink here, but for systems with timebomb,
        // just leave it alone and let user see it in login screen.
        // unlink(buf);
        return 0;
    }
#endif

    if (get_num_records(fpath, sizeof(fileheader_t)) > MAX_KEEPMAIL_HARDLIMIT) {
        unlink(buf);
        // TODO add a mail so that origid knows what happened.
        LOG_IF(LOG_CONF_INTERNETMAIL,
               log_filef("log/internet_mail.log", LOG_CREAT, 
                         "%s [%s] (%s -> %s) mailbox overflow (%d > %d)\n",
                         Cdatelite(&now), __FUNCTION__,
                         origid, address,
                         get_num_records(fpath, sizeof(fileheader_t)),
                         MAX_KEEPMAIL_HARDLIMIT));
        return 0;
    }


    if (!*address ||
        strchr(address, '@') == NULL ||
        strcasestr(address, str_mail_address)) {
#ifndef UNTRUSTED_FORWARD_TIMEBOMB
        // delete the setting if we don't have timebombs.
        unlink(buf);
        LOG_IF(LOG_CONF_INTERNETMAIL,
               log_filef("log/internet_mail.log", LOG_CREAT, 
                         "%s [%s] Removed bad address: %s (%s)\n",
                         Cdatelite(&now), __FUNCTION__,
                         address, origid));
#endif
        return 0;
    }

    setdirpath(buf, fpath, record->filename);
    // because too many user set wrong forward address,
    // let's put their own address instead. 
    // and again because some really stupid user
    // does not understand they've set auto-forward,
    // let's mark this in the title.
    snprintf(fwd_title, sizeof(fwd_title)-1,
             "[自動轉寄] %s", record->title);
    bsmtp(buf, fwd_title, address, origid);
    LOG_IF(LOG_CONF_INTERNETMAIL,
           log_filef("log/internet_mail.log", LOG_CREAT, 
                     "%s [%s] %s -> (%s) %s: %s\n",
                     Cdatelite(&now), __FUNCTION__,
                     cuser.userid, origid, address, fwd_title));
// #endif // USE_MAIL_AUTO_FORWARD
    return 0;
}
Ejemplo n.º 19
0
// Delete and archive the physical (except header) of file
//
// if backup_direct is provided, backup according to that directory.
// if backup_path points to buffer, return back the backuped file
// Return -1 if cannot delete file, 0 for success,
// 1 if delete success but backup failed.
int
delete_file_content2(const char *direct, const fileheader_t *fh,
                     const char *backup_direct,
                     char *backup_path, size_t sz_backup_path,
                     const char *reason) {
    char fpath[PATHLEN];
    fileheader_t backup = { {0} };
    int backup_failed = DELETE_FILE_CONTENT_SUCCESS;

    if(!fh->filename[0] || !direct)
        return DELETE_FILE_CONTENT_FAILED;

#ifdef FN_SAFEDEL
    if (
#ifdef FN_SAFEDEL_PREFIX_LEN
            strncmp(fh->filename, FN_SAFEDEL, FN_SAFEDEL_PREFIX_LEN) == 0 ||
#endif
            strcmp(fh->filename, FN_SAFEDEL) == 0 ||
#endif
        0)
        return DELETE_FILE_CONTENT_SUCCESS;

    if (backup_path) {
        assert(backup_direct);
        assert(sz_backup_path > 0);
        *backup_path = 0;
    }

    // solve source file name
    setdirpath(fpath, direct, fh->filename);
    if (!dashf(fpath))
        return DELETE_FILE_CONTENT_BACKUP_FAILED;

    // FIXME some announcements were made by sym-links, especial for those
    // in mail. we should ignore them.
    if (backup_direct &&
        !dashl(fpath) &&
        strncmp(fh->owner, RECYCLE_BIN_OWNER, strlen(RECYCLE_BIN_OWNER)) != 0) {

        // FIXME maybe for non-board files we should do this by simply touching
        // file instead of full log.
        if (reason && *reason)
            log_filef(fpath,  LOG_CREAT, "\n※ 刪除原因: %s", reason);
        log_filef(fpath,  LOG_CREAT, "\n※ Deleted by: %s (%s) %s\n",
                  cuser.userid, fromhost, Cdatelite(&now));

        // TODO or only memcpy(&backup, fh, sizeof(backup)); ?
        strlcpy(backup.owner, fh->owner, sizeof(backup.owner));
        strlcpy(backup.date, fh->date, sizeof(backup.date));
        strlcpy(backup.title, fh->title, sizeof(backup.title));
        strlcpy(backup.filename, fh->filename, sizeof(backup.filename));

        if (backup_direct != direct &&
            strcmp(backup_direct, direct) != 0) {
            // need to create a new file entry.
            char *slash = NULL;
            char bakpath[PATHLEN];

            strlcpy(bakpath, backup_direct, sizeof(bakpath));
            slash = strrchr(bakpath, '/');
            if (slash)
                *slash = 0;
            if (stampfile_u(bakpath, &backup) == 0 &&
                Rename(fpath, bakpath) == 0) {
                strlcpy(fpath, bakpath, sizeof(fpath));
            } else {
                backup_direct = NULL;
                backup_failed = 1;
            }
        }

        // now, always backup according to fpath
        if (backup_direct) {
#ifdef USE_TIME_CAPSULE
            if (!timecapsule_archive_new_revision(
                        fpath, &backup, sizeof(backup),
                        backup_path, sz_backup_path))
                backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
#else
            // we can't backup to same folder.
            if (strcmp(direct, backup_direct) == 0) {
                backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
            } else {
                if (append_record(backup_direct, &backup, sizeof(backup)) < 0)
                    backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED;
                if (backup_path)
                    strlcpy(backup_path, fpath, sz_backup_path);
            }
            // the fpath is used as-is.
            *fpath = 0;
#endif
        }
    }

    // the file should be already in time capsule
    if (*fpath && unlink(fpath) != 0)
        return DELETE_FILE_CONTENT_FAILED;
    return backup_failed;
}
Ejemplo n.º 20
0
/**************************************************************
 * 直接與 SMTP Port 連接
 **************************************************************/
static int DirectSMTPMail(int ms, const char *fname,
						const char *from, const char *to,
						const char *title, const char *forward)
{
	FILE *fp;
	char gbufTmp[512];

	if (fname == NULL || *fname == '\0')
		return -1;

	if ((fp = fopen(fname, "r")) == NULL)
		return -1;

	sleep(1);		/* lasehu: wait for mail server response */

	net_printf(ms, "MAIL FROM:<%s>\r\n", from);
	if (!net_gets(ms, gbufTmp, sizeof(gbufTmp)))
		return -1;
	if (strncmp(gbufTmp, "250 ", 4))
		return -1;

	net_printf(ms, "RCPT TO:<%s>\r\n", to);
	if (!net_gets(ms, gbufTmp, sizeof(gbufTmp)))
		return -1;
	if (strncmp(gbufTmp, "250 ", 4))
		return -1;

	net_printf(ms, "DATA\r\n");
	if (!net_gets(ms, gbufTmp, sizeof(gbufTmp)))
		return -1;
	if (strncmp(gbufTmp, "354 ", 4))
		return -1;

	net_printf(ms, "From: %s\r\n", from);
	net_printf(ms, "To: %s\r\n", to);

	output_rfc2047_qp(gbufTmp, title, "BIG5");
	net_printf(ms, "Subject: %s\r\n", gbufTmp);
	if (forward)	/* lthuang */
		net_printf(ms, "X-Forwarded-By: %s.bbs@%s", forward, myhostname);
	net_printf(ms, "Content-Type: text/plain; charset=BIG5\r\n");
	output_rfc2047_qp(gbufTmp, BBSTITLE, "BIG5");
	net_printf(ms, "X-Disclaimer: [%s]", gbufTmp);
	output_rfc2047_qp(gbufTmp, _msg_x_disclaimer, "BIG5");
	net_printf(ms, " %s\r\n\r\n", gbufTmp);

	while (fgets(gbufTmp, sizeof(gbufTmp), fp))
	{
		char *ptr;

		if ((ptr = strchr(gbufTmp, '\n')) != NULL)
			*ptr = '\0';
		net_printf(ms, "%s\r\n", gbufTmp);
	}
	fclose(fp);

	net_printf(ms, "\r\n.\r\n");
	if (!net_gets(ms, gbufTmp, sizeof(gbufTmp)))
		return -1;

	if (strncmp(gbufTmp, "250 ", 4))
		return -1;
	net_printf(ms, "RSET\r\n");
	if (!net_gets(ms, gbufTmp, sizeof(gbufTmp)))
		return -1;

#ifdef BBSLOG_MAIL
	{
		time_t now;
		char timestr[20];

		time(&now);
		strftime(timestr, sizeof(timestr), "%m/%d/%Y %X", localtime(&now));
		sprintf(gbufTmp, "%s %-12.12s %s\n", timestr, from, to);
		append_record(PATH_MAILLOG, gbufTmp, strlen(gbufTmp));
	}
#endif

	return 0;
}
Ejemplo n.º 21
0
int x_love() {
    char buf1[200], save_title[TTLEN + 1];
    char receiver[61], path[STRLEN] = "home/";
    int x, y = 0, tline = 0, poem = 0;
    FILE *fp, *fpo;
    time_t timenow;
    struct tm *gtime;
    fileheader_t mhdr;
    
    setutmpmode(LOVE);
    time(&timenow);
    gtime = localtime(&timenow);
    sprintf(buf1,"%c/%s/love%d%d",
	    cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min);
    strcat(path,buf1);
    move(1,0);
    clrtobot();
    
    outs("\n歡迎使用情書產生器 v0.00 版 \n");
    outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n");
    
    if(!getdata(7, 0, "收信人:", receiver, 60, DOECHO)) return 0;
    if(receiver[0] && !(searchuser(receiver) &&
			getdata(8, 0, "主  題:", save_title,
				TTLEN, DOECHO))) {
	move(10, 0);
	outs("收信人或主題不正確, 情書無法傳遞. ");
	pressanykey();
	return 0;
    }
    
    fpo = fopen(path, "w");
    fprintf(fpo, "\n");
    if((fp = fopen(DATA, "r"))) {
	while(fgets(buf1,100, fp)) {
	    switch(buf1[0]) {
	    case '#':
		break;
	    case '@':
		if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4))
		    tline=3;
		else if(!strncmp(buf1,"@poem",5)) {
		    poem = 1;
		    tline = 1;
		    fprintf(fpo, "\n\n");
		} else
		    tline=2;
		break;
	    case '1':
	    case '2':
	    case '3':
	    case '4':
	    case '5':
	    case '6':
	    case '7':
	    case '8':
	    case '9':
		sscanf(buf1,"%d",&x);
		y = (rand() % (x - 1)) * tline; 
		break;
	    default:
		if(!poem) {
		    if(y > 0)
			y = y - 1;
		    else {
			if(tline > 0) {
			    fprintf(fpo, "%s", buf1);
			    tline--;
			}
		    }
		} else {
		    if(buf1[0] == '$')
			y--;
		    else if(y == 0)
			fprintf(fpo,"%s",buf1);
		}
	    } 

	}
	
	fclose(fp);
	fclose(fpo);
	if(vedit(path, YEA, NULL) == -1) {
	    unlink(path);
	    clear();
	    outs("\n\n 放棄寄情書\n");
	    pressanykey();
	    return -2;
	}
	sethomepath(buf1, receiver);
	stampfile(buf1, &mhdr);
	Rename(path, buf1);
	strncpy(mhdr.title, save_title, TTLEN);
	strcpy(mhdr.owner, cuser.userid);
	mhdr.savemode = '\0';
	sethomedir(path, receiver );
	if(append_record(path, &mhdr, sizeof(mhdr)) == -1)
	    return -1;
	hold_mail(buf1, receiver);
	return 1;
    }
    return 0;
}
Ejemplo n.º 22
0
int showout()
{
	int     i, i2 = 0;
	char    foo[1024];
	char    tmpfile[STRLEN];
	char    buf[20];
	int     notreload = 0;
	GOPHER  newitem;
	while (1)
	{
		if (gopher_position < 0)
		{
			return;
		}
		print_gophertitle();
		printgopher_title();
		update_endline();
		if (!notreload)
		{
			i = 0;
			if (get_con(g_main[gopher_position]->server, g_main[gopher_position]->port) == -1)
			{
				show_message(NULL);
				free(g_main[gopher_position]);
				gopher_position--;
				notreload = 0;
				continue;
			}
			enterdir(g_main[gopher_position]->file);
			show_message("¶Áȡ׼±¸ÖÐ");
			for (i = 0; i < MAXGOPHERITEMS; i++)
			{
				if (readfield(a, foo, 1024) <= 0)
				{
					break;
				}
				if (foo[0] == '.' && foo[1] == '\r' && foo[2] == '\n')
				{
					break;
				}
				strncpy(newitem.title, foo, 70);
				if (readfield(a, foo, 1024) == 0)
				{
					break;
				}
				strncpy(newitem.file, foo, 80);
				if (readfield(a, foo, 1024) == 0)
				{
					break;
				}
				strncpy(newitem.server, foo, 40);
				if (readline(a, foo, 1024) == 0)
				{
					break;
				}
				newitem.port = atoi(foo);
				if (newitem.title[0] != newitem.file[0])
				{
					break;
				}
				if (newitem.title[0] != '0' && newitem.title[0] != '1')
				{
					i--;
					continue;
				}
				refresh();
				append_record(gophertmpfile, &newitem, sizeof(GOPHER));
				sprintf(buf, "[1;3%dmת[3%dm»»[3%dm×Ê[3%dmÁÏ[3%dmÖÐ", (i % 7) + 1
				        ,((i + 1) % 7) + 1, ((i + 2) % 7) + 1, ((i + 3) % 7) + 1, ((i + 4) % 7) + 1);
				show_message(buf);
			}
			show_message(NULL);
		}
		else
			notreload = 0;
		if (i <= 0)
		{
			move(3, 0);
			clrtobot();
			move(10, 0);
			clrtoeol();
			prints("                             ûÓÐÈκεÄ×ÊÁÏ...");
			pressanykey();
			free(g_main[gopher_position]);
			gopher_position--;
			continue;
		}
		close(a);
		move(0, 0);
		clrtobot();
		setlistrange(i);
		i2 = choose(NA, g_main[gopher_position]->position, print_gophertitle, deal_gopherkey, show_gopher, do_gopher);
		if (i2 == -1)
		{
			free(g_main[gopher_position]);
			clear_gophertmpfile();
			gopher_position--;
			continue;
		}
		g_main[gopher_position]->position = i2;
		get_record(gophertmpfile, &newitem, sizeof(GOPHER), i2 + 1);
		tmpitem = &newitem;
		if (newitem.title[0] == '0')
		{
			if (get_con(newitem.server, newitem.port) == -1)
				continue;
			enterdir(newitem.file);
			setuserfile(tmpfile, "gopher.tmp");
			savetmpfile(tmpfile);
			ansimore(tmpfile, YEA);
			notreload = 1;
			unlink(tmpfile);
			continue;
		}
		else
		{
			GOPHER *newgi;
			clear_gophertmpfile();
			gopher_position++;
			newgi = (GOPHER *) malloc(sizeof(GOPHER));
			strncpy(newgi->server, tmpitem->server, 40);
			strncpy(newgi->file, tmpitem->file, 80);
			strncpy(newgi->title, tmpitem->title, 70);
			newgi->port = tmpitem->port;
			newgi->position = 0;
			g_main[gopher_position] = newgi;
			continue;
		}
	}
}
Ejemplo n.º 23
0
Archivo: chat.c Proyecto: wyat/kbs
void call_alias(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1998.01.25 */
    char buf[128], buf2[200];
    FILE *fp;
    char path[40];
    char emoteid[40];
    int nIdx;

    nextword(&arg, emoteid, sizeof(emoteid));
    sethomefile(path, getCurrentUser()->userid, "/emotes");
    if (!emoteid[0]) {
        if ((fp = fopen(path, "r")) == NULL) {
            printchatline(pthis, "*** 还没有自定义的emote ***");
            return;
        }
        nIdx = 0;
        printchatline(pthis, "〖用户自定义emote列表〗");
        while (fread(buf, 128, 1, fp) > 0) {
            printchatline(pthis, buf);
        }
        fclose(fp);
    } else {
        nIdx = 0;
        if ((fp = fopen(path, "r")) != NULL) {
            while (1) {
                const char *tmpbuf;
                char tmpemote[40];

                if (fread(buf, 128, 1, fp) == 0) {
                    nIdx = 0;
                    break;
                }
                tmpbuf = buf;
                nextword(&tmpbuf, tmpemote, sizeof(tmpemote));
                nIdx++;
                if (strcasecmp(emoteid, tmpemote) == 0)
                    break;
            }
            fclose(fp);
        }
        if (nIdx > 0) {
            if (*arg) {
                printchatline(pthis, "*** 该emote已经被定义过了 ***");
                return;
            }
            if (delete_record(path, 128, nIdx, NULL, NULL) == 0) {
                printchatline(pthis, "*** 该自定义emote已经被删除了 ***");
                sprintf(buf, "/alias_del %s", emoteid);
                chat_send(pthis, buf);
            } else {
                bbslog("3error", "delete alias %s fail", emoteid);
                printchatline(pthis, "*** system error ***");
            }
        } else if (!*arg)
            printchatline(pthis, "*** 请指定emote对应的字串 ***");
        else {
            fp = fopen(path, "r");
            if (fp != NULL) {
                fseek(fp, 0, SEEK_END);
                if (ftell(fp) >= 128 * MAX_EMOTES) {
                    fclose(fp);
                    printchatline(pthis,
                                  "*** 用户自定义emote的列表已满 ***");
                    return;
                }
                fclose(fp);
            }
            sprintf(buf, "%s %s", emoteid, arg);
            if (append_record(path, buf, 128) == 0) {
                printchatline(pthis, "*** 自定义emote已经设定 ***");
                sprintf(buf2, "/alias_add %s", buf);
                chat_send(pthis, buf2);
            } else {
                bbslog("3error", "add alias %s fail", emoteid);
                printchatline(pthis, "*** 系统错误 ***");
            }
        }
    }
}
Ejemplo n.º 24
0
Archivo: chat.c Proyecto: wyat/kbs
void call_ignore(chatcontext * pthis, const char *arg)
{                               /* added by Luzi 1997.11.28 */
    char buf[STRLEN], buf2[76];
    FILE *fp;
    char uident[IDLEN + 1];
    char path[40];
    char ignoreuser[IDLEN + 1];
    int nIdx;

    sethomefile(path, getCurrentUser()->userid, "/ignores");
    if (!*arg) {
        nIdx = 0;
        if ((fp = fopen(path, "r")) != NULL) {
            strcpy(buf2, "【忽略其讯息的用户ID列表】");
            while (fread(buf, IDLEN + 1, 1, fp) > -0) {
                if (nIdx % 4 == 0) {
                    printchatline(pthis, buf2);
                    *buf2 = '\0';
                }
                nIdx++;
                sprintf(buf2 + strlen(buf2), "  %-13s", buf);
            }
            fclose(fp);
        }
        if (nIdx > 0)
            printchatline(pthis, buf2);
        else
            printchatline(pthis, "*** 尚未设定忽略用户的名单 ***");
    } else if (!strcasecmp(arg, getCurrentUser()->userid))
        printchatline(pthis, "*** 无法忽略自己的信息 ***");
    else {
        strncpy(uident, arg, IDLEN + 1);
        uident[IDLEN] = 0;
        if (!searchuser(uident))
            /* change getuser -> searchuser, by dong, 1999.10.26 */
            printchatline(pthis, "*** 没有这个 ID ***");
        else {
            nIdx =
                search_record(path, ignoreuser, IDLEN + 1,
                              (RECORD_FUNC_ARG) cmpinames, uident);
            if (nIdx > 0)
                printchatline(pthis, "*** 该ID已经被忽略了 ***");
            else {
                fp = fopen(path, "r");
                if (fp != NULL) {
                    fseek(fp, 0, SEEK_END);
                    if (ftell(fp) >= (IDLEN + 1) * MAX_IGNORE) {
                        fclose(fp);
                        printchatline(pthis, "*** 忽略用户名单已满 ***");
                        return;
                    }
                    fclose(fp);
                }
                if (append_record(path, uident, IDLEN + 1) == 0) {
                    printchatline(pthis, "*** 忽略已经设定 ***");
                    bbslog("user", "ignore %s", uident);
                    sprintf(buf, "/ignore %s", uident);
                    chat_send(pthis, buf);
                } else {
                    printchatline(pthis, "*** 系统错误 ***");
                    bbslog("3error", "ignore %s failed", uident);
                }
            }
        }
    }
}
Ejemplo n.º 25
0
static int summarize(struct stats_file *data_file,
			struct stats_file *history_file,
			struct stats_file *temp_file,
			int account_period_offset)
{
	struct stats_iter data_iter;
	struct stats_iter history_iter;
	struct stats_record *cur, *next;

	GDate today, date_change_step_size;

	/*
	 * First calculate the date when switch from monthly
	 * accounting period size to daily size
	 */
	g_date_set_time_t(&today, time(NULL));

	date_change_step_size = today;
	if (g_date_get_day(&today) - account_period_offset >= 0)
		g_date_subtract_months(&date_change_step_size, 2);
	else
		g_date_subtract_months(&date_change_step_size, 3);

	g_date_set_day(&date_change_step_size, account_period_offset);


	/* Now process history file */
	cur = NULL;

	if (history_file) {
		history_iter.file = history_file;
		history_iter.begin = get_iterator_begin(history_iter.file);
		history_iter.end = get_iterator_end(history_iter.file);
		history_iter.it = history_iter.begin;

		cur = process_file(&history_iter, temp_file, NULL,
					&date_change_step_size,
					account_period_offset);
	}

	data_iter.file = data_file;
	data_iter.begin = get_iterator_begin(data_iter.file);
	data_iter.end = get_iterator_end(data_iter.file);
	data_iter.it = data_iter.begin;

	/*
	 * Ensure date_file records are newer than the history_file
	 * record
	 */
	if (cur) {
		next = get_next_record(&data_iter);
		while (next && cur->ts > next->ts)
			next = get_next_record(&data_iter);
	}

	/* And finally process the new data records */
	cur = process_file(&data_iter, temp_file, cur,
				&date_change_step_size, account_period_offset);

	if (cur)
		append_record(temp_file, cur);

	return 0;
}
Ejemplo n.º 26
0
int append_article(char *fname, char *path, char *author, char *title,
				char ident, char *stamp, int artmode, int flag, char *fromhost)
#endif
{
	char dotdir[PATHLEN], fn_stamp[PATHLEN];
	char stampbuf[64];	/* M.0987654321.[A-Z]+ */
	FILEHEADER fhbuf, *fhr = &fhbuf;
	struct stat st;
	char buffer[256];

 	/* check if directory exists for 'path' */
	if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode))
		return -1;

 	/* create unique filename from time & store in stampbuf,'path' unmodified */
	get_only_name(path, stampbuf);
	sprintf(fn_stamp, "%s/%s", path, stampbuf);

 	/* actually copy the file into where the post finally resides */
	if (mycp(fname, fn_stamp) == -1)
	{
		unlink(fn_stamp);	/* debug */
		return -1;
	}
 	/* append 'Origin:' line at the end of post if 'fromhost' was specified */
	if (fromhost)
	{
#ifdef USE_IDENT
		sprintf(buffer, "--\n* Origin: %s * From: %s [%s通過認證]\n",
			BBSTITLE, fromhost, (ident == 7) ? "已" : "未");
#else
		sprintf(buffer, "--\n* Origin: %s * From: %s\n", BBSTITLE, fromhost);
#endif
		append_record(fn_stamp, buffer, strlen(buffer));
	}

	chmod(fn_stamp, 0600);	/* lthuang */

 	/* now adding index to .DIR file */
	memset(fhr, 0, FH_SIZE);
	xstrncpy(fhr->filename, stampbuf, sizeof(fhr->filename));
	xstrncpy(fhr->owner, author, sizeof(fhr->owner));
	xstrncpy(fhr->title, title, sizeof(fhr->title));
	fhr->ident = ident;

	/* add by asuka */
	fhr->accessed |= flag;

	sprintf(dotdir, "%s/%s", path, DIR_REC);

	/* get next valid postno from .DIR file if in the article mode */
	/* 精華區 / 信箱 不需要用到 postno */
	if (artmode && get_only_postno(dotdir, 0, fhr))
		return -1;
	if (stamp)
		strcpy(stamp, stampbuf);

#ifdef USE_THREADING 		/* syhu */
	update_threadinfo( fhr, path, thrheadpos, thrpostidx ); 	/* syhu */
#endif

 	/* do the acutal update in .DIR file by writing to it */
 	/* 'dotdir' is opened twice. First is in get_only_post() */
 	if (append_record(dotdir, fhr, FH_SIZE) == -1)
 	{
 		unlink(fn_stamp);	/* lthuang */
 		return -1;
 	}

	if (artmode) {
		return fhr->postno;
	}
	return 0;
}
Ejemplo n.º 27
0
tbl_p table_search (tbl_p t, char *attr, char *op, int val)
{
	schema_p 			s;
	field_desc_p 		f;
	int 				i;

	pager_profiler_reset();

	int (*pointer)(int, int);

	if (t == NULL) return NULL;

	s = t->sch;

	for ( f = s->first; f != NULL; f = f->next, i++)
		if ( strcmp (f->name, attr) == 0)
		{
			if ( f->type != INT_TYPE )
			{
				put_msg (ERROR, "\"%s\" is not an integer field.\n", attr);
				return NULL;
			}
			break;
		}

	if ( f == NULL ) return NULL;

	char tmp_name[30] = "tmp_tbl__";
	strcat (tmp_name, s->name);
	schema_p res_sch = copy_schema ( s, tmp_name );
	record rec = new_record ( s );

	if(strcmp(op, "<") == 0)
	{
		//printf("Less than search \n");
		pointer = &less_than;
	}
	else if(strcmp(op, "<=") == 0)
	{
		//printf("Less then or equal search \n");
		pointer = &less_than_equal;
	}
	else if(strcmp(op, ">") == 0)
	{
		//printf("Greater then search \n");
		pointer = &greater_then;
	}
	else if(strcmp(op, ">=") == 0)
	{
		//printf("Greater then or equal search \n");
		pointer = &greater_then_equal;
	}
	else if(strcmp(op, "!=") == 0)
	{
		//printf("Not equal search \n");
		pointer = &not_equal;
	}
	else
	{
		//printf("Equal search \n");
		pointer = &int_equal;
	}

	set_tbl_position ( t, TBL_BEG );
	while ( find_record_int_val(rec, s, f->offset, pointer, val) )
	{
		put_record_info (DEBUG, rec, s);
		append_record ( rec, res_sch );
	}

	release_record (rec, s);

	put_pager_profiler_info(INFO);

	return res_sch->tbl;
}
Ejemplo n.º 28
0
static void
a_delete(menu_t * pm, const char *backup_dir)
{
    char            fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN];
    char            ans[4];
    fileheader_t    backup, *fhdr = &(pm->header[pm->now - pm->page]);
    const char *msg_errsync = "刪除檔案失敗,請退回上層目錄後再重試一次",
               *msg_errsync2 = "檔案可能已被它人刪除,請退回上層目錄再重進確認",
               *msg_errbackup = "檔案已刪除但無法備份。請至 " BN_BUGREPORT
                                "報告您試圖刪除檔案的位置。";

    snprintf(fpath, sizeof(fpath),
	     "%s/%s", pm->path, fhdr->filename);
    setadir(buf, pm->path);

    if (fhdr->filename[0] == 'H' && fhdr->filename[1] == '.') {
	getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ",
		ans, sizeof(ans), LCECHO);
	if (ans[0] != 'y')
	    return;
	if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) {
            vmsg(msg_errsync);
	    return;
        }
    } else if (dashl(fpath)) {
	getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ",
		ans, sizeof(ans), LCECHO);
	if (ans[0] != 'y')
	    return;
	if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) {
            vmsg(msg_errsync);
	    return;
        }
	unlink(fpath);
    } else if (dashf(fpath)) {

	getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans,
		sizeof(ans), LCECHO);
	if (ans[0] != 'y')
	    return;

        if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) {
            vmsg(msg_errsync);
            return;
        }

        switch(delete_file_content(buf, fhdr, backup_dir, NULL, 0)) {
            case DELETE_FILE_CONTENT_BACKUP_FAILED:
                vmsg(msg_errbackup);
                break;
            case DELETE_FILE_CONTENT_FAILED:
                vmsg(msg_errsync2);
                break;
            default:
#ifndef USE_TIME_CAPSULE
                // When not using time capsule, .DIR content may be changed in
                // board (BN_DELETE/BN_JUNK) and need to be changed. However
                // since that's going to be deprecated in future, let's have a
                // simple workaround here.
                if (backup_dir) {
                    const char *bn = NULL;
                    if (strstr(backup_dir, "/" BN_JUNK "/"))
                        bn = BN_JUNK;
                    else if (strstr(backup_dir, "/" BN_DELETED "/"))
                        bn = BN_DELETED;
                    if (bn)
                        setbtotal(getbnum(bn));
                }
#endif
                break;
        }

    } else if (dashd(fpath)) {

        // TODO(hungte) We should create a top level folder and move everything
        // inside.

	// XXX we also check PERM_MAILLIMIT here because RMAIL
	// may be not trusted...
	const char *save_bn = ( HasUserPerm(PERM_MAILLIMIT) && (currstat & RMAIL) ) ?
		BN_JUNK : BN_DELETED;

	getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans,
		sizeof(ans), LCECHO);
	if (ans[0] != 'y')
	    return;
	if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) {
            vmsg(msg_errsync);
	    return;
        }

	setapath(buf, save_bn);
	// XXX because this directory will hold folders from entire site,
	// let's allow it to use a large set of file names.
	if (stampadir(buf, &backup, 1) != 0)
	{
	    vmsg("抱歉,系統目前無法刪除資料,請通知站務人員");
	    return;
	}

	snprintf(cmd, sizeof(cmd),
		"rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf);
	system(cmd);

	strlcpy(backup.owner, cuser.userid, sizeof(backup.owner));
	strcpy(backup.title, "◆");
	strlcpy(backup.title + 2, fhdr->title + 2, sizeof(backup.title) - 3);

        // restrict access if source is hidden
        if ((fhdr->filemode & FILE_BM) || (fhdr->filemode & FILE_HIDE))
            backup.filemode |= FILE_BM;

	/* merge setapath(buf, save_bn); setadir(buf, buf); */
	snprintf(buf, sizeof(buf), "man/boards/%c/%s/" FN_DIR,
		*save_bn, save_bn);
	append_record(buf, &backup, sizeof(backup));

    } else {			/* Ptt 損毀的項目 */
	getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ",
		ans, sizeof(ans), LCECHO);
	if (ans[0] != 'y')
	    return;
	if (delete_fileheader(buf, fhdr, pm->now + 1) == -1)
	    return;
    }
    pm->num--;
}
Ejemplo n.º 29
0
static struct stats_record *process_file(struct stats_iter *iter,
					struct stats_file *temp_file,
					struct stats_record *cur,
					GDate *date_change_step_size,
					int account_period_offset)
{
	struct stats_record *home, *roaming;
	struct stats_record *next;

	home = NULL;
	roaming = NULL;

	if (!cur)
		cur = get_next_record(iter);
	next = get_next_record(iter);

	while (next) {
		GDate date_cur;
		GDate date_next;
		int append;

		append = FALSE;

		if (cur->roaming)
			roaming = cur;
		else
			home = cur;

		g_date_set_time_t(&date_cur, cur->ts);
		g_date_set_time_t(&date_next, next->ts);

		if (g_date_compare(&date_cur, date_change_step_size) < 0) {
			/* month period size */
			GDateDay day_cur, day_next;
			GDateMonth month_cur, month_next;

			month_cur = g_date_get_month(&date_cur);
			month_next = g_date_get_month(&date_next);

			day_cur = g_date_get_day(&date_cur);
			day_next = g_date_get_day(&date_next);

			if (day_cur == day_next && month_cur != month_next)
				append = TRUE;
			else if (day_cur < account_period_offset
					&& day_next >= account_period_offset)
				append = TRUE;
		} else {
			/* day period size */
			if (g_date_days_between(&date_cur, &date_next) > 0)
				append = TRUE;
		}

		if (append) {
			if (home) {
				append_record(temp_file, home);
				home = NULL;
			}

			if (roaming) {
				append_record(temp_file, roaming);
				roaming = NULL;
			}
		}

		cur = next;
		next = get_next_record(iter);
	}

	return cur;
}
Ejemplo n.º 30
0
TTBIN_FILE *parse_ttbin_data(uint8_t *data, uint32_t size)
{
    const uint8_t *const end = data + size;
    TTBIN_FILE *file;
    unsigned length;

    FILE_HEADER               *file_header = 0;
    union
    {
        uint8_t *data;
        struct
        {
            uint8_t tag;
            union
            {
                FILE_SUMMARY_RECORD         summary;
                FILE_GPS_RECORD             gps;
                FILE_HEART_RATE_RECORD      heart_rate;
                FILE_STATUS_RECORD          status;
                FILE_TREADMILL_RECORD       treadmill;
                FILE_SWIM_RECORD            swim;
                FILE_LAP_RECORD             lap;
                FILE_RACE_SETUP_RECORD      race_setup;
                FILE_RACE_RESULT_RECORD     race_result;
                FILE_TRAINING_SETUP_RECORD  training_setup;
                FILE_GOAL_PROGRESS_RECORD   goal_progress;
                FILE_INTERVAL_SETUP_RECORD  interval_setup;
                FILE_INTERVAL_START_RECORD  interval_start;
                FILE_INTERVAL_FINISH_RECORD interval_finish;
            };
        } *record;
    } p;

    TTBIN_RECORD *record;

    /* check that the file is long enough */
    if (size < (sizeof(FILE_HEADER) - sizeof(RECORD_LENGTH)))
        return 0;

    if (*data++ != TAG_FILE_HEADER)
        return 0;

    file = malloc(sizeof(TTBIN_FILE));
    memset(file, 0, sizeof(TTBIN_FILE));

    file_header = (FILE_HEADER*)data;
    data += sizeof(FILE_HEADER) + (file_header->length_count - 1) * sizeof(RECORD_LENGTH);
    file->file_version    = file_header->file_version;
    memcpy(file->firmware_version, file_header->firmware_version, sizeof(file->firmware_version));
    file->product_id      = file_header->product_id;
    file->timestamp_local = file_header->timestamp;
    file->timestamp_utc   = file_header->timestamp - file_header->local_time_offset;
    file->utc_offset      = file_header->local_time_offset;

    for (p.data = data; p.data < end; p.data += length)
    {
        unsigned index = 0;

        /* find the length of this tag */
        while ((index < file_header->length_count) && (file_header->lengths[index].tag < p.record->tag))
            ++index;
        if ((index < file_header->length_count) && (file_header->lengths[index].tag == p.record->tag))
            length = file_header->lengths[index].length;
        else
        {
            free_ttbin(file);
            return 0;
        }

        switch (p.record->tag)
        {
        case TAG_SUMMARY:
            file->activity       = p.record->summary.activity;
            file->total_distance = p.record->summary.distance;
            file->duration       = p.record->summary.duration;
            file->total_calories = p.record->summary.calories;
            break;
        case TAG_STATUS:
            p.record->status.timestamp -= file->utc_offset;

            record = append_record(file, p.record->tag, length);
            record->status.status = p.record->status.status;
            record->status.activity = p.record->status.activity;
            record->status.timestamp = p.record->status.timestamp;
            append_array(&file->status_records, record);
            break;
        case TAG_GPS:
            /* if the GPS signal is lost, 0xffffffff is stored in the file */
            if (p.record->gps.timestamp == 0xffffffff)
                break;

            record = append_record(file, p.record->tag, length);
            record->gps.latitude     = p.record->gps.latitude / 1e7;
            record->gps.longitude    = p.record->gps.longitude / 1e7;
            record->gps.elevation    = 0.0f;
            record->gps.heading      = p.record->gps.heading / 100.0f;
            record->gps.speed        = p.record->gps.speed / 100.0f;
            record->gps.timestamp    = p.record->gps.timestamp;
            record->gps.calories     = p.record->gps.calories;
            record->gps.inc_distance = p.record->gps.inc_distance;
            record->gps.cum_distance = p.record->gps.cum_distance;
            record->gps.cycles       = p.record->gps.cycles;
            append_array(&file->gps_records, record);
            break;
        case TAG_HEART_RATE:
            p.record->heart_rate.timestamp -= file->utc_offset;

            record = append_record(file, p.record->tag, length);
            record->heart_rate.timestamp  = p.record->heart_rate.timestamp;
            record->heart_rate.heart_rate = p.record->heart_rate.heart_rate;
            append_array(&file->heart_rate_records, record);
            break;
        case TAG_LAP:
            record = append_record(file, p.record->tag, length);
            record->lap.total_time     = p.record->lap.total_time;
            record->lap.total_distance = p.record->lap.total_distance;
            record->lap.total_calories = p.record->lap.total_calories;
            append_array(&file->lap_records, record);
            break;
        case TAG_TREADMILL:
            p.record->treadmill.timestamp -= file->utc_offset;

            record = append_record(file, p.record->tag, length);
            record->treadmill.timestamp = p.record->treadmill.timestamp;
            record->treadmill.distance  = p.record->treadmill.distance;
            record->treadmill.calories  = p.record->treadmill.calories;
            record->treadmill.steps     = p.record->treadmill.steps;
            append_array(&file->treadmill_records, record);
            break;
        case TAG_SWIM:
            p.record->swim.timestamp -= file->utc_offset;

            record = append_record(file, p.record->tag, length);
            record->swim.timestamp      = p.record->swim.timestamp;
            record->swim.total_distance = p.record->swim.total_distance;
            record->swim.strokes        = p.record->swim.strokes;
            record->swim.completed_laps = p.record->swim.completed_laps;
            record->swim.total_calories = p.record->swim.total_calories;
            append_array(&file->swim_records, record);
            break;
        case TAG_RACE_SETUP:
            record = append_record(file, p.record->tag, length);
            record->race_setup.distance = p.record->race_setup.distance;
            record->race_setup.duration = p.record->race_setup.duration;
            memcpy(record->race_setup.name, p.record->race_setup.name, sizeof(p.record->race_setup.name));
            file->race_setup = record;
            break;
        case TAG_RACE_RESULT:
            if (!file->race_setup)
            {
                free_ttbin(file);
                return 0;
            }
            record = append_record(file, p.record->tag, length);
            record->race_result.distance = p.record->race_result.distance;
            record->race_result.duration = p.record->race_result.duration;
            record->race_result.calories = p.record->race_result.calories;
            file->race_result = record;
            break;
        case TAG_TRAINING_SETUP:
            record = append_record(file, p.record->tag, length);
            record->training_setup.type      = p.record->training_setup.type;
            record->training_setup.value_min = p.record->training_setup.min;
            record->training_setup.max       = p.record->training_setup.max;
            file->training_setup = record;
            break;
        case TAG_GOAL_PROGRESS:
            record = append_record(file, p.record->tag, length);
            record->goal_progress.percent = p.record->goal_progress.percent;
            record->goal_progress.value   = p.record->goal_progress.value;
            append_array(&file->goal_progress_records, record);
            break;
        case TAG_INTERVAL_SETUP:
            record = append_record(file, p.record->tag, length);
            record->interval_setup.warm_type = p.record->interval_setup.warm_type;
            record->interval_setup.warm      = p.record->interval_setup.warm;
            record->interval_setup.work_type = p.record->interval_setup.work_type;
            record->interval_setup.work      = p.record->interval_setup.work;
            record->interval_setup.rest_type = p.record->interval_setup.rest_type;
            record->interval_setup.rest      = p.record->interval_setup.rest;
            record->interval_setup.cool_type = p.record->interval_setup.cool_type;
            record->interval_setup.cool      = p.record->interval_setup.cool;
            record->interval_setup.sets      = p.record->interval_setup.sets;
            file->interval_setup = record;
            break;
        case TAG_INTERVAL_START:
            record = append_record(file, p.record->tag, length);
            record->interval_start.type = p.record->interval_start.type;
            append_array(&file->interval_start_records, record);
            break;
        case TAG_INTERVAL_FINISH:
            record = append_record(file, p.record->tag, length);
            record->interval_finish.type           = p.record->interval_finish.type;
            record->interval_finish.total_time     = p.record->interval_finish.total_time;
            record->interval_finish.total_distance = p.record->interval_finish.total_distance;
            record->interval_finish.total_calories = p.record->interval_finish.total_calories;
            append_array(&file->interval_finish_records, record);
            break;
        default:
            record = append_record(file, p.record->tag, length);
            memcpy(record->data, p.data + 1, length - 1);
            break;
        }
    }

    return file;
}