Exemplo n.º 1
0
/* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */
int
force_open(const char *fname)
{
    int             fd;
    time4_t          expire;

    expire = now - 3600;	/* lock 存在超過一個小時就是有問題! */

    if (dasht(fname) > expire)
	return -1;
    unlink(fname);
    fd = OpenCreate(fname, O_WRONLY | O_TRUNC);

    return fd;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
static int
a_showmenu(menu_t * pm)
{
    char           *title, *editor;
    int             n;
    fileheader_t   *item;
    time4_t         dtime;

    showtitle("精華文章", pm->mtitle);
    prints("   " ANSI_COLOR(1;36) "編號    標      題%56s" ANSI_RESET,
	   "編    選      日    期");

    if (!pm->num)
    {
	outs("\n  《精華區》尚在吸取天地間的日月精華中... :)");
    }
    else
    {
	char buf[PATHLEN];

	// determine if path is valid.
	if (!a_loadname(pm))
	    return 0;

	for (n = 0; n < p_lines && pm->page + n < pm->num; n++) {
	    int flTagged = 0;
	    item = &pm->header[n];
	    title = item->title;
	    editor = item->owner;
	    /*
	     * Ptt 把時間改為取檔案時間 dtime = atoi(&item->filename[2]);
	     */
	    snprintf(buf, sizeof(buf), "%s/%s", pm->path, item->filename);
	    if(copyqueue_querysize() > 0 && copyqueue_fileinqueue(buf))
	    {
		flTagged = 1;
	    }
	    dtime = dasht(buf);
	    a_timestamp(buf, &dtime);
	    prints("\n%6d%c%c%-47.46s%-13s[%s]", pm->page + n + 1,
		   (item->filemode & FILE_BM) ? 'X' :
		   (item->filemode & FILE_HIDE) ? ')' : '.',
		   flTagged ? 'c' : ' ',
		   title, editor,
		   buf);
	}
    }

    move(b_lines, 0);
    if(copyqueue_querysize() > 0)
    {		// something in queue
	char buf[STRLEN];
	snprintf(buf, sizeof(buf),  "【已標記(複製) %d 項】", copyqueue_querysize());
	vs_footer(buf, pm->level == 0 ?
		" (c)標記/複製 - 無管理權限,無法貼上 " :
		" (c)標記/複製 (p)貼上/取消/重設標記 (a)附加至文章後\t(q/←)離開 (h)說明");
    }
    else if(pm->level)
    {		// BM
	vs_footer(" 【板  主】 ",
		" (n)新增文章 (g)新增目錄 (e)編輯檔案\t(q/←)離開 (h)說明");
    }
    else
    {		// normal user
	vs_footer(" 【功\能鍵】 ",
		" (k↑j↓)移動游標 (enter/→)讀取資料\t(q/←)離開 (h)說明");
    }
    return 1;
}