/* * Function name: valid_read_all_sanction * Description : This function can be used to query whether there is a * 'read all' sanction set that allows 'reader' to read in * 'euid'. Note that there is no check on the arguments, * which means the first argument _must_ be in lower case. * Arguments : string reader - the euid that wants to read. * string euid - the euid that 'reader' wants to read. * Returns : int 1/0 - allowed/disallowed. */ static int valid_read_all_sanction(string reader, string euid) { return (file_time(SANCTION_DIR + euid + "/" + reader + SANCTION_READ_ALL) || file_time(SANCTION_DIR + euid + "/" + query_wiz_dom(reader) + SANCTION_READ_ALL) || file_time(SANCTION_DIR + euid + "/all" + SANCTION_READ_ALL)); }
/* * Function name: valid_write_all_sanction * Description : This function can be used to query whether there is a * 'write all' sanction set that allows 'writer' to write in * 'euid'. Note that there is no check on the arguments, * which means the first argument _must_ be in lower case. * Arguments : string writer - the euid that wants to write. * string euid - the euid that 'writer' wants to write. * Returns : int 1/0 - allowed/disallowed. */ static int valid_write_all_sanction(string writer, string euid) { return (file_time(SANCTION_DIR + euid + "/" + writer + SANCTION_WRITE_ALL) || file_time(SANCTION_DIR + euid + "/" + query_wiz_dom(writer) + SANCTION_WRITE_ALL) || file_time(SANCTION_DIR + euid + "/all" + SANCTION_WRITE_ALL)); }
/* * Function name: valid_read_path_sanction * Description : This function can be used to query whether there is a * read sanction set that allows 'reader' to read the * directory 'path' in 'euid'. Note that there is no check * on the arguments, which means the first argument _must_ * be in lower case. * Arguments : string reader - the euid that wants to read. * string euid - the euid that 'reader' wants to read. * string path - the path that 'reader' wants to read within * the directory of 'euid' starting with "/". * Returns : int 1/0 - allowed/disallowed. */ static int valid_read_path_sanction(string reader, string euid, string path) { return (file_time(SANCTION_DIR + euid + "/all" + path + SANCTION_READ) || file_time(SANCTION_DIR + euid + "/" + reader + path + SANCTION_READ) || file_time(SANCTION_DIR + euid + "/" + query_wiz_dom(reader) + path + SANCTION_READ)); }
void load_limit_table(void) { static time_t update_time = 0; time_t t; int i = 0; FILE *fp; char buf[256], *ptr; t = file_time(SPEC_SITE_FILE); if (update_time > t) return; fp = fopen(SPEC_SITE_FILE, "r"); if (NULL == fp) return; while (fgets(buf, sizeof (buf), fp) && i < MAX_SPEC_SITE) { if ('#' == buf[0]) continue; ptr = strtok(buf, " "); if (!ptr) continue; *ptr = 0; inet_aton(buf, &(limit[i].from)); limit[i].limit = atoi(ptr + 1); if (limit[i].limit <= 0) limit[i].limit = DEFAULT_LIMIT; i++; } fclose(fp); qsort(limit, i, sizeof (struct sitelimit), (void *) m_cmp); sitelimit_cnt = i; update_time = time(0); }
int filecache_retrieve(TARGET *t, MD5SUM buildmd5sum) { MD5SUM blobmd5sum; MD5SUM copymd5sum; time_t time; /* if the target is available in the cache */ const char *cachedname = filecache_getfilename(t, buildmd5sum, 0); if (!cachedname) return 0; if (!filecache_findlink(cachedname, blobmd5sum)) { if( DEBUG_MD5HASH) { printf("Cannot find %s in cache as %s\n", t->name, cachedname); filecache_disable(t); } return 0; } getcachedmd5sum( t, 1 ); if ( file_time( t->boundname, &time ) == 0 ) { if (memcmp(blobmd5sum, t->contentmd5sum, sizeof(MD5SUM)) == 0) { if (!(t->flags & T_FLAG_NOCARE)) #ifdef _MSC_VER _utime(t->boundname, NULL); #else utime(t->boundname, NULL); #endif printf("%s is already the proper cached target.\n", t->name); return 1; } } cachedname = filecache_getfilename(t, blobmd5sum, ".blob"); /* try to get it from the cache */ if (copyfile(t->boundname, cachedname, ©md5sum) && memcmp(copymd5sum, blobmd5sum, sizeof(MD5SUM)) == 0) { printf( "Using cached %s\n", t->name ); return 1; } else if (!(t->flags & T_FLAG_OPTIONALFILECACHE)) { printf( "Cannot retrieve %s from cache (will build normally)\n", t->name ); return 0; } if( DEBUG_MD5HASH) { printf( "Cannot find %s in cache as %s\n", t->name, cachedname ); } return 0; }
int bbsnewmail_main() { FILE *fp; struct fileheader x; int total = 0, total2 = 0; char dir[80]; if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); sprintf(dir, "mail/%c/%s/.DIR", mytoupper(currentuser->userid[0]), currentuser->userid); if (cache_header(file_time(dir), 1)) return 0; html_header(1); //check_msg(); changemode(RMAIL); //去掉了框架 printf("<body topmargin=0 leftMargin=1 MARGINWIDTH=1 MARGINHEIGHT=0>" WWWLEFT_DIV); printf("<center>\n"); printf ("%s -- 未读邮件列表 [使用者: %s] [信箱容量: %dk, 已用空间: %dk]<hr>\n", BBSNAME, currentuser->userid, max_mailsize(currentuser), get_mailsize(currentuser)); fp = fopen(dir, "r"); if (fp == 0) http_fatal("目前您的信箱没有任何信件"); printf("<table border=1>\n"); printf ("<tr><td>序号</td><td>状态</td><td>发信人</td><td>日期</td><td>信件标题</td></tr>\n"); while (1) { if (fread(&x, sizeof (x), 1, fp) <= 0) break; total++; if (x.accessed & FH_READ) continue; printf("<tr><td>%d</td><td>N</td>", total); printf("<td>%s</td>", userid_str(fh2owner(&x))); printf("<td>%6.6s</td>", Ctime(x.filetime) + 4); printf("<td><a href=bbsmailcon?file=%s&num=%d>", fh2fname(&x), total - 1); if (strncmp("Re: ", x.title, 4)) printf("★ "); hprintf("%42.42s", void1(x.title)); printf(" </a></td></tr>\n"); total2++; } fclose(fp); printf("</table><hr>\n"); printf("您的信箱共有%d封信件, 其中新信%d封.", total, total2); printf("</center>"); showfile(MY_BBS_HOME "/wwwtmp/googleanalytics"); // printf("</body>"); //修改框架,页面底部 printf(WWWFOOT_DIV "</body></html>\n"); http_quit(); return 0; }
int mails_time(char *id) { char path[80]; if (!loginok || isguest) return 0; sprintf(path, "mail/%c/%s/.DIR", mytoupper(id[0]), id); return file_time(path); }
string sponsoring(string name) { int i,w; string *s,s2,s3,s4; // Daten einlesen, wenn die daten aelter als 1 Tag sind oder sich // /log/SPONSORS geaendert hat. if ((time() > filetime+86400) || filetime!=file_time("/log/SPONSOR")) { relatives=m_allocate(0,2); filetime=file_time("/log/SPONSOR"); s=explode(read_file("/log/SPONSOR"),"\n"); foreach(string str: s) { sscanf(str,"%s: %s macht %s zum Learner.",s2,s3,s4); if (IS_LEARNER(lower_case(s3)) && IS_LEARNER(lower_case(s4))) { relatives[lower_case(s4),0]=s3; s3=lower_case(s3); s4+=" ("+query_wiz_level(lower_case(s4))+")"; if (!relatives[s3,1]) relatives[s3,1]=({s4}); else relatives[s3,1]+=({s4});
int bbsnewmail_main() { //modify by mintbaggio 20040829 for new www FILE *fp; struct fileheader x; int total = 0, total2 = 0; char dir[80]; if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); sprintf(dir, "mail/%c/%s/.DIR", mytoupper(currentuser.userid[0]), currentuser.userid); if(cache_header(file_time(dir),1)) return 0; html_header(1); check_msg(); changemode(RMAIL); printf("<body><center>\n"); printf ("<div class=rhead>%s -- 新邮件列表 [使用者: <span class=h11>%s</span>]<br>[信箱容量: <span class=h11>%d</span>k, 已用空间: <span class=h11>%dk</span>]</div><hr>\n", BBSNAME, currentuser.userid, max_mail_size(), get_mail_size()); fp = fopen(dir, "r"); if (fp == 0) http_fatal("目前您的信箱没有任何信件"); printf("<table border=1>\n"); printf ("<tr><td>序号</td><td>状态</td><td>发信人</td><td>日期</td><td>信件标题</td></tr>\n"); while (1) { if (fread(&x, sizeof (x), 1, fp) <= 0) break; total++; if (x.accessed & FH_READ) continue; printf("<tr><td>%d</td><td>N</td>", total); printf("<td>%s</td>", userid_str(fh2owner(&x))); printf("<td>%6.6s</td>", Ctime(x.filetime) + 4); printf("<td><a href=bbsmailcon?file=%s&num=%d>", fh2fname(&x), total - 1); if (strncmp("Re: ", x.title, 4)) printf("★ "); hprintf("%42.42s", void1(x.title)); printf(" </a></td></tr>\n"); total2++; } fclose(fp); printf("</table><hr>\n"); printf("您的信箱共有%d封信件, 其中新信%d封.", total, total2); printf("</center></body>"); http_quit(); return 0; }
static int get_user_mail_size(char * userid) { int currsize = 0; char currmaildir[STRLEN], tmpmail[STRLEN]; struct fileheader tmpfh; FILE *fp; time_t t; sethomefile(tmpmail, userid, "msgindex"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sethomefile(tmpmail, userid, "msgindex2"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sethomefile(tmpmail, userid, "msgcontent"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sprintf(currmaildir, "mail/%c/%s/%s", mytoupper(userid[0]), userid, DOT_DIR); t = file_time(currmaildir); if(!t) return (currsize/1024); fp = fopen(currmaildir, "r"); if(!fp) return (currsize/1024); while(fread(&tmpfh, 1, sizeof(tmpfh), fp) == sizeof(tmpfh)) { setmailfile(tmpmail, userid, fh2fname(&tmpfh)); currsize += file_size_s(tmpmail); } fclose(fp); return (currsize/1024); }
void timestamp_from_path( timestamp * const time, OBJECT * const path ) { PROFILE_ENTER( timestamp ); PATHNAME f1; PATHNAME f2; int found; BINDING * b; string buf[ 1 ]; if ( file_time( path, time ) < 0 ) timestamp_clear( time ); PROFILE_EXIT( timestamp ); }
int testPOWERJUNK(char *path, char *fn) { char buf[1024]; int s; sprintf(buf, "%s/%s", path, fn); if (strncmp(fn, ".POWER", 6) && strncmp(buf, ".SOMEONE", 8) && strncmp(buf, ".UNREAD", 7)) return 0; if (nowtime - file_time(buf) < 3600 * 5) return 0; s = file_size(buf); unlink(buf); printf("%s %d\n", buf, s); totalsize += s; return 0; }
ULONG TS_file_time(TS_class *TS, BYTE *filename) { DICT_entry *cur; ULONG *tstamp; if (!strcasecmp(filename, "$obsolete")) return (0L); cur = DICT_lookup(TS->cache, filename); if (cur == NULL) { cur = DICT_enter(TS->cache, filename, D_DEFHEAP); tstamp = (ULONG*) mem_alloc(sizeof(ULONG)); *tstamp = file_time(filename); cur->def = tstamp; } return (*(ULONG *) cur->def); }
int main() { int i, no=0; char brd[100], buf[256]; init_all(); printf("<body background=/bg_1.gif bgproperties=fixed>"); printf("<nobr><center>%s -- 精华区下载服务<hr color=green>\n", BBSNAME); printf("【注】各板面精华区以压缩格式存储,请下载后用winzip等工具解压到某一目录后阅读。压缩包每周更新一次。<br>"); printf("<table border=1>\n"); printf("<tr><td>序号<td>名称<td>大小(字节)<td>更新时间\n"); for(i=0; i<MAXBOARD; i++) { strsncpy(brd, shm_bcache->bcache[i].filename, 60); sprintf(buf, "%s%s.html.tar.gz", DIGESTPATH, brd); if(!file_exist(buf)) continue; no++; getdatestring(file_time(buf), NA); printf("<tr><td>%d<td><a href=/digest/%s.html.tar.gz>%s</a><td align=right>%d<td>%s\n", no, brd, brd, file_size(buf), datestring); } printf("</table>"); }
int bbsboardlistscript_main() { int total; struct boardmem *(data[MAXBOARD]); char *secstr; changemode(READING); if (cache_header (max(thisversion, file_time(MY_BBS_HOME "/wwwtmp")), 500)) return 0; secstr = getparm("secstr"); if (secstr[0]== '*') total = listmybrd(data); else total = makeboardlist(getsectree(secstr), data); printf("Content-type: application/x-javascript; charset=%s\r\n\r\n", CHARSET); printf("var boardlistscript="); boardlistscript(data, total); return 0; }
int main(int n, char *arg[]) { char buf[256], dir[256], tmp[256],tmp1[256]; if (n < 2) exit(0); strcpy(board, arg[1]); sprintf(buf, dl_path "/%s.tgz", board); if (do_testtime(file_time(buf), ".", 0, 2*3600) == 0) { printf("#no need to update %s\n", buf); return 0; } printf("process %s\n",board); sprintf(dir, dl_path "/tmp/an.tmp/%s", board); sprintf(buf, "mkdir -p %s", dir); system(buf); system("pwd"); sprintf(tmp, "一塌糊涂BBS %s版精华区(%s)", board, c_time(time(0))); do_index(".", dir, tmp, 1, 0); sprintf(tmp1, "%s/tmp/an.tmp/%s", dl_path, board); chdir(tmp1); sprintf(tmp1, "%s/bin/makechm -b %s", MY_BBS_HOME, board); system(tmp1); chdir(dl_path "/tmp/an.tmp"); printf("board: %s\n", board); sprintf(buf, "tar -zcf %s.tgz %s", board, board); system(buf); sprintf(buf, "rm -rf %s", board); printf("%s\n", buf); system(buf); snprintf(buf,sizeof(buf),"%s/%s.tgz",dl_path,board); if(file_size(buf)>100*1024*1024) truncate(buf,0); sprintf(buf, "mv -f %s.tgz %s", board, dl_path); printf("%s\n", buf); system(buf); sync(); return 0; }
static int load_server() { FILE *fp; char line[256], *start, *end; int ft; ft = file_time("AI_SERVER"); if(ft <= server_last_update) { if(random() % (num_server+1)) return 0; } else server_last_update = ft; num_server = 0; fp = fopen("AI_SERVER", "r"); // 包含删除文件就禁用server的意思 if(fp == NULL) return -1; while((num_server<MAX_SERVER_NUM) && fgets(line, sizeof(line), fp)) { if(*line == '#') continue; start = line; end = strpbrk(start, "\r\n"); if(end) *end = 0; end = strchr(start, ':'); if(!end) { server[num_server].port = 9999; } else { *end = 0; server[num_server].port = atoi(end+1); } strsncpy(server[num_server].ip, start, sizeof(server[num_server].ip)); server[num_server].count = 0; //printf("%s %d\n", server[num_server].ip, server[num_server].port); num_server++; } fclose(fp); return 1; }
int checksum_retrieve(TARGET *t, MD5SUM buildmd5sum) { CHECKSUMDATA cachedata, *c = &cachedata; char buildmd5sumstring[33]; checksums_readfile(); strcpy(buildmd5sumstring, md5tostring(buildmd5sum)); c->boundname = buildmd5sumstring; if (!hashcheck(checksumhash, (HASHDATA **)&c)) { return 0; } getcachedmd5sum(t, 0); if (t->contentchecksum && t->contentchecksum->mtime != 0 && memcmp( c->contentmd5sum, t->contentchecksum->contentmd5sum, MD5_SUMSIZE ) == 0 ) { time_t time; #ifdef _MSC_VER _utime(t->boundname, NULL); #else utime(t->boundname, NULL); #endif file_time(t->boundname, &time); t->contentchecksum->mtime = time; t->contentchecksum->age = 0; checksumsdirty = 1; //printf("JAMDEBUG: %s is already the proper cached target.\n", t->name); return 1; } else { memset(&c->contentmd5sum, 0, MD5_SUMSIZE); } return 0; }
int index2009_main() { //struct boardmem *x; //int i, total = 0; char *secstr; //char ydq[3]; const struct sectree *sec; struct brcinfo *brcinfo; brcinfo = brc_readinfo(currentuser->userid); secstr = getparm("secstr"); sec = getsectree(secstr); if (secstr[0] != '*' && !strcmp(sec->basestr, brcinfo->lastsec)) { if (cache_header (max(thisversion, file_time(MY_BBS_HOME "/wwwtmp")), 120)) return 0; } if (secstr[0] != '*' && strcmp(sec->basestr, brcinfo->lastsec)) { strsncpy(brcinfo->lastsec, sec->basestr, sizeof (brcinfo->lastsec)); brc_saveinfo(currentuser->userid, brcinfo); } html_header(1); printf("<title>一路BBS 凝聚华人力量,加强中外交流</title>"); //check_msg(); printf("<style type=text/css>A {color: #0000f0}</style>"); printf("<script src=" BBSJS "></script>\n"); printf("<script src=" BBSBOAJS "></script>\n"); printf("</head><body topmargin=0 leftMargin=1 MARGINWIDTH=1 MARGINHEIGHT=0>" WWWLEFT_DIV); showsecpage2009(sec); printf(WWWFOOT_DIV "</body></html>"); return 0; }
/* Zonesize >= blocksize */ void eat_file(ino_t inode, int f) { int ct = 0, i, j; zone_t z = 0; char *buf; time_t timeval; buf = alloc_block(); do { for (i = 0, j = 0; i < zone_per_block; i++, j += ct) { memset(buf, 0, block_size); if ((ct = read(f, buf, block_size)) > 0) { if (i == 0) z = alloc_zone(); put_block((z << zone_shift) + i, buf); } } timeval = (dflag ? current_time : file_time(f)); if (ct) add_zone(inode, z, (size_t) j, timeval); } while (ct == block_size); close(f); free(buf); }
void timestamp( char *target, time_t *time ) { PATHNAME f1, f2; BINDING binding, *b = &binding; string buf[1]; # ifdef DOWNSHIFT_PATHS string path; char *p; string_copy( &path, target ); p = path.value; do *p = tolower( *p ); while( *p++ ); target = path.value; # endif string_new( buf ); if( !bindhash ) bindhash = hashinit( sizeof( BINDING ), "bindings" ); /* Quick path - is it there? */ b->name = target; b->time = b->flags = 0; b->progress = BIND_INIT; if( hashenter( bindhash, (HASHDATA **)&b ) ) b->name = newstr( target ); /* never freed */ if( b->progress != BIND_INIT ) goto afterscanning; b->progress = BIND_NOENTRY; /* Not found - have to scan for it */ path_parse( target, &f1 ); /* Scan directory if not already done so */ { BINDING binding, *b = &binding; f2 = f1; f2.f_grist.len = 0; path_parent( &f2 ); path_build( &f2, buf, 0 ); b->name = buf->value; b->time = b->flags = 0; b->progress = BIND_INIT; if( hashenter( bindhash, (HASHDATA **)&b ) ) b->name = newstr( buf->value ); /* never freed */ if( !( b->flags & BIND_SCANNED ) ) { file_dirscan( buf->value, time_enter, bindhash ); b->flags |= BIND_SCANNED; } } /* Scan archive if not already done so */ if( f1.f_member.len ) { BINDING binding, *b = &binding; f2 = f1; f2.f_grist.len = 0; f2.f_member.len = 0; string_truncate( buf, 0 ); path_build( &f2, buf, 0 ); b->name = buf->value; b->time = b->flags = 0; b->progress = BIND_INIT; if( hashenter( bindhash, (HASHDATA **)&b ) ) b->name = newstr( buf->value ); /* never freed */ if( !( b->flags & BIND_SCANNED ) ) { file_archscan( buf->value, time_enter, bindhash ); b->flags |= BIND_SCANNED; } } afterscanning: if( b->progress == BIND_SPOTTED ) { if( file_time( b->name, &b->time ) < 0 ) b->progress = BIND_MISSING; else b->progress = BIND_FOUND; } *time = b->progress == BIND_FOUND ? b->time : 0; string_free( buf ); # ifdef DOWNSHIFT_PATHS string_free( &path ); #endif }
void dlcount(void) { char *temp, *p, *q = NULL, *date, *file, *base, month[20]; FILE *fp; int i, date_ok, file_ok, result, filesize; time_t filedate = (time_t)0, lastcheck; struct tm tm; temp = calloc(PATH_MAX, sizeof(char)); /* * Check if we have a mark when we did this the last time. * If not, create one and don't do anything. Run the next time. */ snprintf(temp, PATH_MAX, "%s/var/dlcount.stat", getenv("MBSE_ROOT")); if ((lastcheck = file_time(temp)) == -1) { Syslog('+', "Checking WWW downloads never done before, creating timestamp"); if ((fp = fopen(temp, "a"))) { fclose(fp); } free(temp); return; } /* * Refresh timestamp */ unlink(temp); if ((fp = fopen(temp, "a"))) { fclose(fp); } date = calloc(81, sizeof(char)); file = calloc(PATH_MAX, sizeof(char)); base = calloc(PATH_MAX, sizeof(char)); if (strlen(CFG.www_logfile) && (fp = fopen(CFG.www_logfile, "r"))) { /* * Check apache logfile */ if (!do_quiet) printf("Checking WWW downloads\n"); Syslog('+', "Checking WWW downloads"); while (fgets(temp, PATH_MAX-1, fp)) { date_ok = file_ok = FALSE; memset(date, 0, 80); memset(file, 0, PATH_MAX); memset(base, 0, PATH_MAX); Striplf(temp); /* * Parse logline, be aware for lots of garbage created by systems * that try to compromise the webserver. */ // Syslog('f', "%s", printable(temp, 100)); p = strchr(temp, '['); if (p) { q = strchr(p, ']'); if (q && ((q-p) < 40)) { strncpy(date, p+1, q - p - 1); tm.tm_mday = atoi(strtok(date, "/\0")); snprintf(month, 20, "%s", strtok(NULL, "/\0")); for (i = 0; i < 12; i++) if (strncasecmp(months[i], month, 3) == 0) break; tm.tm_mon = i; tm.tm_year = atoi(strtok(NULL, ":\0")) - 1900; tm.tm_hour = atoi(strtok(NULL, ":\0")); tm.tm_min = atoi(strtok(NULL, ":\0")); tm.tm_sec = atoi(strtok(NULL, ":\0")); filedate = mktime(&tm); if (filedate > lastcheck) date_ok = TRUE; } } if (date_ok && (p = strchr(temp, '"'))) { q = strchr(p+1, '"'); if (q && ((q-p) < 128)) { strncpy(file, p+1, q - p - 1); if (strncmp(file, "GET ", 4) == 0) { if ((p = strstr(file, CFG.www_link2ftp))) { snprintf(base, PATH_MAX, "%s%s", CFG.ftp_base, p + strlen(CFG.www_link2ftp)); for (i = strlen(base); i; i--) { if (base[i] == ' ') { base[i] = '\0'; break; } } file_ok = TRUE; } } } } if (file_ok) { p = strtok(q, (char *)" \0"); result = atoi(strtok(NULL, (char *)" \0")); filesize = atoi(strtok(NULL, (char *)" \0")); if (result == 200) { /* * So far it seems that the file is possible downloaded from the bbs. * Now search the download area and filerecord. */ Syslog('f', "%s %s %d", rfcdate(filedate), base, filesize); count_download(base, filedate, filesize, (char *)"WWW"); } } } fclose(fp); } if (strlen(CFG.ftp_logfile) && (fp = fopen(CFG.ftp_logfile, "r"))) { /* * Check ftp logfile */ if (!do_quiet) printf("Checking FTP downloads\n"); Syslog('+', "Checking FTP downloads"); while (fgets(temp, PATH_MAX-1, fp)) { date_ok = file_ok = FALSE; memset(date, 0, 80); memset(file, 0, PATH_MAX); memset(base, 0, PATH_MAX); Striplf(temp); /* * Parse logline. */ // Syslog('f', "%s", printable(temp, 100)); p = strtok(temp, " \0"); /* Day of week */ p = strtok(NULL, " \0"); /* Month */ for (i = 0; i < 12; i++) if (strncasecmp(months[i], p, 3) == 0) break; tm.tm_mon = i; tm.tm_mday = atoi(strtok(NULL, " \0")); /* Day in month */ tm.tm_hour = atoi(strtok(NULL, ":\0")); /* Hour */ tm.tm_min = atoi(strtok(NULL, ":\0")); /* Minute */ tm.tm_sec = atoi(strtok(NULL, " \0")); /* Seconds */ tm.tm_year = atoi(strtok(NULL, " \0")) - 1900; /* Year */ filedate = mktime(&tm); if (filedate > lastcheck) date_ok = TRUE; p = strtok(NULL, " \0"); /* 0 */ p = strtok(NULL, " \0"); /* Remote host */ filesize = atoi(strtok(NULL, " \0")); /* Filesize */ p = strtok(NULL, " \0"); /* Filename */ if (p == NULL) break; snprintf(base, PATH_MAX, "%s", p); if (date_ok) { /* * So far it seems that the file is possible downloaded from the bbs. * Now search the download area and filerecord. */ Syslog('f', "%s %s %d", rfcdate(filedate), base, filesize); count_download(base, filedate, filesize, (char *)"FTP"); } } } free(base); free(file); free(date); free(temp); }
int main(int argc, char *argv[]) { struct cgi_applet *a = NULL; struct rlimit rl; int i; seteuid(BBSUID); setuid(BBSUID); setgid(BBSGID); cgi_time(NULL); rl.rlim_cur = 20 * 1024 * 1024; rl.rlim_max = 40 * 1024 * 1024; setrlimit(RLIMIT_CORE, &rl); thispid = getpid(); now_t = time(NULL); srand(now_t * 2 + thispid); wwwcache = get_shm(WWWCACHE_SHMKEY, sizeof (struct WWWCACHE)); if (NULL == wwwcache) exit(0); thisversion = file_time(argv[0]); if (thisversion > wwwcache->www_version) wwwcache->www_version = thisversion; html_header(0); if (geteuid() != BBSUID) http_fatal("uid error."); chdir(BBSHOME); shm_init(); if (ummap()) http_fatal("mmap error."); signal(SIGTERM, wantquit); if (access("NOLOGIN", F_OK)) nologin = 0; get_att_server(); while (FCGI_Accept() >= 0) { // start_outcache(); cginame = NULL; incgiloop = 1; if (setjmp(cgi_start)) { // end_outcache(); cgi_time(a); if (!incgiloop || wwwcache->www_version > thisversion || rt++ > 40000) { logtimeused(); exit(2); } incgiloop = 0; continue; } html_header(0); now_t = time(NULL); via_proxy = 0; strsncpy(fromhost, getsenv("REMOTE_ADDR"), 46); //ipv6 by leoncom inet_pton(PF_INET6,fromhost,&from_addr); //inet_aton(fromhost, &from_addr); /* ipv6 by leoncom 无视validproxy for (i = 0; wwwcache->validproxy[i] && i < MAX_PROXY_NUM; i++) { if (from_addr.s_addr == wwwcache->validproxy[i]) { via_proxy = 1; break; } } if (via_proxy) { char *ptr, *p; int IPLEN = 255; ptr = getenv("HTTP_X_FORWARDED_FOR"); if (!ptr) ptr = getsenv("REMOTE_ADDR"); p = strrchr(ptr, ','); if (p != NULL) { while (!isdigit(*p) && *p) p++; if (*p) strncpy(fromhost, p, IPLEN); else strncpy(fromhost, ptr, IPLEN); } else strncpy(fromhost, ptr, IPLEN); fromhost[IPLEN] = 0; inet_aton(fromhost, &from_addr); } */ if (url_parse()) http_fatal("%s 没有实现的功能!", getsenv("SCRIPT_URL")); http_parm_init(); a = get_cgi_applet(needcgi); if (a != NULL) { cginame = a->name[0]; //access(getsenv("QUERY_STRING"), F_OK); wwwcache->www_visit++; (*(a->main)) (); // end_outcache(); cgi_time(a); if (!incgiloop || wwwcache->www_version > thisversion) { logtimeused(); exit(4); } incgiloop = 0; continue; } http_fatal("%s 没有实现的功能!", getsenv("SCRIPT_URL")); // end_outcache(); incgiloop = 0; } munmap(ummap_ptr, ummap_size); exit(5); }
time_t file_time (const std::string& name) { return file_time (name.c_str ()); }
/* * Get cached md5sum of a file. If none found, or not up to date, if the file is source * try to recalculate the sum. If not, then return empty sum (all zeroes). */ int getcachedmd5sum( TARGET *t, int source ) { HCACHEDATA cachedata, *c = &cachedata; int use_cache = 1; HCACHEFILE *file; const char *target = t->boundname; # ifdef DOWNSHIFT_PATHS char path[ MAXJPATH ]; char *p; #endif if ( t->contentmd5sum_calculated ) return t->contentmd5sum_changed; if (!source) { memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum)); memset(&t->contentmd5sum, 0, sizeof(t->contentmd5sum)); t->contentmd5sum_calculated = 1; t->contentmd5sum_changed = 0; return t->contentmd5sum_changed; } file = hcachefile_get( t ); ++queries; # ifdef DOWNSHIFT_PATHS p = path; do *p++ = (char)tolower( *target ); while( *target++ ); target = path; # endif c->boundname = target; if( hashcheck( file->hcachehash, (HASHDATA **) &c ) ) { if ( t->time == 0 ) { /* This file was generated. Grab its timestamp. */ file_time( c->boundname, &c->mtime ); } else if( c->mtime != t->time ) use_cache = 0; if ( use_cache ) { use_cache = memcmp(md5sumempty, &c->contentmd5sum, sizeof(c->contentmd5sum)) != 0; } if( use_cache ) { if( DEBUG_MD5HASH ) printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum)); c->age = 0; /* The entry has been used, its young again */ ++hits; t->contentmd5sum_changed = 0; memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum)); t->contentmd5sum_calculated = 1; return t->contentmd5sum_changed; } else { if( DEBUG_MD5HASH ) printf( "md5 cache out of date for %s (time %d, md5time %d)\n", t->boundname , (int)t->time, (int)c->mtime ); } } else { if( hashenter( file->hcachehash, (HASHDATA **)&c ) ) { c->boundname = newstr( c->boundname ); c->next = file->hcachelist; file->hcachelist = c; c->time = 0; c->includes = NULL; c->hdrscan = NULL; } } file->dirty = 1; /* 'c' points at the cache entry. Its out of date. */ { MD5SUM origmd5sum; #ifdef OPT_BUILTIN_LUA_SUPPORT_EXT LIST *md5callback; #endif memcpy( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) ); #ifdef OPT_BUILTIN_LUA_SUPPORT_EXT pushsettings( t->settings ); md5callback = var_get( "MD5CALLBACK" ); popsettings( t->settings ); if ( md5callback ) { luahelper_md5callback(t->boundname, c->contentmd5sum, md5callback->string); } else { #endif md5file( t->boundname, c->contentmd5sum ); #ifdef OPT_BUILTIN_LUA_SUPPORT_EXT } #endif t->contentmd5sum_changed = memcmp( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) ) != 0; } if( DEBUG_MD5HASH ) printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum)); c->mtime = t->time; if ( c->mtime == 0 ) { /* This file was generated. Grab its timestamp. */ file_time( c->boundname, &c->mtime ); } c->age = 0; memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum)); t->contentmd5sum_calculated = (char)(memcmp(md5sumempty, &t->contentmd5sum, sizeof(t->contentmd5sum)) != 0); memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum)); return t->contentmd5sum_changed; }
void filecache_update(TARGET *t) { MD5SUM blobmd5sum; int haveblobmd5sum = 0; const char *cachedname; const char *blobname; int cacheerror; if (!t->filecache_generate) return; /* If the buildmd5sum is empty, then the file doesn't exist. */ cacheerror = ismd5empty(t->buildmd5sum); if (cacheerror) return; haveblobmd5sum = 0; cachedname = filecache_getfilename(t, t->buildmd5sum, NULL); if (!cachedname) return; /* Search for the appropriate .link file that matches the target. */ haveblobmd5sum = filecache_findlink(cachedname, blobmd5sum); /* If we weren't able to determine the target md5sum, do it now. */ if (!haveblobmd5sum) { #ifdef OPT_BUILTIN_LUA_SUPPORT_EXT LIST *md5callback; pushsettings( t->settings ); md5callback = var_get( "MD5CALLBACK" ); popsettings( t->settings ); if ( md5callback ) { luahelper_md5callback(t->boundname, blobmd5sum, md5callback->string); } else { #endif md5file(t->boundname, blobmd5sum); #ifdef OPT_BUILTIN_LUA_SUPPORT_EXT } #endif memcpy(t->contentmd5sum, blobmd5sum, sizeof(MD5SUM)); if (ismd5empty(t->contentmd5sum)) return; } { /* Is the blob already there? */ time_t blobtime; blobname = filecache_getfilename(t, blobmd5sum, ".blob"); if (file_time(blobname, &blobtime) == -1) { time_t blobpartialtime; const char *blobpartialname; if(DEBUG_MD5HASH) printf("Caching %s as %s\n", t->name, cachedname); else printf("Caching %s\n", t->name); /* Write the new .blob to the cache. */ blobpartialname = filecache_getfilename(t, blobmd5sum, ".blob.partial"); if (file_time(blobpartialname, &blobpartialtime) == -1) { if (copyfile(blobpartialname, t->boundname, &blobmd5sum) == 0 || rename(blobpartialname, blobname) != 0) { printf("** Unable to write %s to cache.\n", t->name, cachedname); filecache_disable(t); return; } } } } /* Write the new .link file to the cache. */ { FILE *file; BUFFER linknamebuff; buffer_init(&linknamebuff); buffer_addstring(&linknamebuff, cachedname, strlen(cachedname)); buffer_addchar(&linknamebuff, '-'); buffer_addstring(&linknamebuff, md5tostring(blobmd5sum), 32); buffer_addstring(&linknamebuff, ".link", 5); buffer_addchar(&linknamebuff, 0); file_mkdir(buffer_ptr(&linknamebuff)); file = fopen(buffer_ptr(&linknamebuff), "wb"); if (file) { write_md5sum(file, blobmd5sum); write_string(file, t->name); fclose(file); } buffer_free(&linknamebuff); } }
int main(int, char **) { clock_t chronometer=clock(); //Chronometre std::ofstream file_time("time.csv"); std::ofstream file_makespan("makspan.csv"); std::ofstream file_popgen("popgen.csv"); int taille_pop = 100; if (!file_time || !file_makespan || !file_popgen) { std::cout << "fichiers non initialises" << std::endl; } std::vector<Data> data_tab; data_tab.push_back(Data("INSTANCES/la01.dat")); data_tab.push_back(Data("INSTANCES/la02.dat")); data_tab.push_back(Data("INSTANCES/la03.dat")); data_tab.push_back(Data("INSTANCES/la04.dat")); data_tab.push_back(Data("INSTANCES/la05.dat")); data_tab.push_back(Data("INSTANCES/la06.dat")); data_tab.push_back(Data("INSTANCES/la07.dat")); data_tab.push_back(Data("INSTANCES/la08.dat")); data_tab.push_back(Data("INSTANCES/la09.dat")); data_tab.push_back(Data("INSTANCES/la10.dat")); data_tab.push_back(Data("INSTANCES/la11.dat")); data_tab.push_back(Data("INSTANCES/la12.dat")); data_tab.push_back(Data("INSTANCES/la13.dat")); data_tab.push_back(Data("INSTANCES/la14.dat")); data_tab.push_back(Data("INSTANCES/la15.dat")); data_tab.push_back(Data("INSTANCES/la16.dat")); data_tab.push_back(Data("INSTANCES/la17.dat")); data_tab.push_back(Data("INSTANCES/la18.dat")); data_tab.push_back(Data("INSTANCES/la19.dat")); data_tab.push_back(Data("INSTANCES/la20.dat")); // Calcul des RL et des 5eme generation de chaque donnee int cpt = 0; for (std::vector<Data>::iterator it = data_tab.begin(); it != data_tab.end();it++) { file_time << "Data " << cpt << ";"; file_makespan << "Data " << cpt << std::endl; std::cout << "Data " << cpt << std::endl; Bierwirth b(*it); b.evaluer(); b.recherche_locale(file_makespan); Population P(taille_pop, (*it)); file_makespan << "Premiere iteration de l'algo genetique : " << std::endl; P.algo_genetique(file_makespan);std::cout << "."; P.algo_genetique();std::cout << "."; P.algo_genetique();std::cout << "."; P.algo_genetique();std::cout << "."; file_makespan << "Cinquieme iteration de l'algo genetique : " << std::endl; P.algo_genetique(file_makespan);std::cout << "."; file_time << (float)(clock() - chronometer) / CLOCKS_PER_SEC << std::endl; file_makespan << std::endl; std::cout << std::endl; cpt++; } //Calcul d'une 100eme generation de la premiere donnee Population P(taille_pop, (data_tab[0])); for (int i = 0;i < 100;i++) { std::cout << i << "%" << std::endl; file_popgen << i << ";" << P.get_makespan() << std::endl; P.algo_genetique(); } std::cout << "Temps de l'execution : " << (float)(clock() - chronometer) / CLOCKS_PER_SEC << std::endl; file_makespan.close(); file_time.close(); file_popgen.close(); return 0; }
static const char * search_helper( const char *target, time_t *time, LIST *(*varget)( const char*, void* ), void *userData, int uncached ) { PATHNAME f[1]; LIST *varlist; char buf[ MAXJPATH ]; #ifdef OPT_PATH_BINDING_EXT PATHNAME bf[1]; #endif /* Parse the filename */ path_parse( target, f ); f->f_grist.ptr = 0; f->f_grist.len = 0; #ifdef OPT_PATH_BINDING_EXT if ( list_first(varlist = varget( "BINDING", userData )) ) { path_parse( list_value(list_first(varlist)), bf ); f->f_dir = bf->f_dir; f->f_base = bf->f_base; f->f_suffix = bf->f_suffix; } #endif if( list_first(varlist = varget( "LOCATE", userData )) ) { f->f_root.ptr = list_value(list_first(varlist)); f->f_root.len = (int)(strlen( list_value(list_first(varlist)) )); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( f, buf, 1, 1 ); #else path_build( f, buf, 1 ); #endif if( DEBUG_SEARCH ) printf( "locate %s: %s\n", target, buf ); if ( uncached ) { file_time( buf, time ); } else { timestamp( buf, time, 0 ); } return newstr( buf ); } else if( list_first(varlist = varget( "SEARCH", userData )) ) { LIST *searchextensionslist; LISTITEM* var = list_first(varlist); while( var ) { f->f_root.ptr = list_value(var); f->f_root.len = (int)(strlen( list_value(var) )); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( f, buf, 1, 1 ); #else path_build( f, buf, 1 ); #endif if( DEBUG_SEARCH ) printf( "search %s: %s\n", target, buf ); if ( uncached ) { file_time( buf, time ); } else { timestamp( buf, time, 0 ); } if( *time ) return newstr( buf ); var = list_next( var ); } searchextensionslist = varget( "SEARCH_EXTENSIONS", userData ); if ( list_first(searchextensionslist) ) { LISTITEM* ext = list_first(searchextensionslist); for ( ; ext; ext = list_next(ext) ) { LISTITEM* var = list_first(varlist); while( var ) { f->f_root.ptr = list_value(var); f->f_root.len = (int)(strlen( list_value(var) )); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT strcpy( path_build( f, buf, 1, 1 ), list_value(ext) ); #else strcpy( path_build( f, buf, 1 ), list_value(ext) ); #endif if( DEBUG_SEARCH ) printf( "search %s: %s\n", target, buf ); if ( uncached ) { file_time( buf, time ); } else { timestamp( buf, time, 0 ); } if( *time ) return newstr( buf ); var = list_next( var ); } } } } /* Look for the obvious */ /* This is a questionable move. Should we look in the */ /* obvious place if SEARCH is set? */ f->f_root.ptr = 0; f->f_root.len = 0; #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( f, buf, 1, 1 ); #else path_build( f, buf, 1 ); #endif if( DEBUG_SEARCH ) printf( "search %s: %s\n", target, buf ); if ( uncached ) { file_time( buf, time ); } else { timestamp( buf, time, 0 ); } return newstr( buf ); }
/* * Return values: * 0 - Success * 1 - Some error * 2 - Orphaned tic */ int ProcessTic(fa_list **sbl, orphans **opl) { int First, Listed = FALSE, DownLinks = 0, MustRearc = FALSE; int UnPacked = FALSE, IsArchive = FALSE, rc, i, j, k; char *Temp, *unarc = NULL, *cmd = NULL; char temp1[PATH_MAX], temp2[PATH_MAX], sbe[24], TDesc[1024]; unsigned int crc, crc2, Kb; sysconnect Link; FILE *fp; struct utimbuf ut; int BBS_Imp = FALSE, DidBanner = FALSE; faddr *p_from; qualify *qal = NULL, *tmpq; orphans *topl; if (TIC.TicIn.PathError) { WriteError("Our Aka is in the path"); tic_bad++; return 1; } Temp = calloc(PATH_MAX, sizeof(char)); if (!do_quiet) { mbse_colour(LIGHTGREEN, BLACK); printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (TIC.Orphaned) { fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, TRUE, FALSE); Syslog('+', "File not in inbound: %s", TIC.TicIn.File); free(Temp); return 2; } snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); crc = file_crc(Temp, CFG.slow_util && do_quiet); TIC.FileSize = file_size(Temp); TIC.FileDate = file_time(Temp); if (TIC.TicIn.Size) { if (TIC.TicIn.Size != TIC.FileSize) WriteError("Size is %ld, expected %ld", TIC.FileSize, TIC.TicIn.Size); } else { /* * No filesize in TIC file, add filesize. */ TIC.TicIn.Size = TIC.FileSize; } if (TIC.Crc_Int) { if (crc != TIC.Crc_Int) { Syslog('!', "CRC: expected %08lX, the file is %08lX", TIC.Crc_Int, crc); fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, FALSE, TRUE); if (check_crc) { Syslog('+', "Bad CRC, will check this ticfile later"); free(Temp); return 1; } else { Syslog('!', "CRC: error, recalculating crc"); ReCalcCrc(Temp); } } } else { Syslog('+', "CRC: missing, calculating CRC"); ReCalcCrc(Temp); } /* * Load and check the .TIC area. */ if (!SearchTic(TIC.TicIn.Area)) { UpdateNode(); Syslog('f', "Unknown file area %s", TIC.TicIn.Area); p_from = fido2faddr(TIC.Aka); if (!create_ticarea(TIC.TicIn.Area, p_from)) { Bad((char *)"Unknown file area %s", TIC.TicIn.Area); free(Temp); tidy_faddr(p_from); return 1; } tidy_faddr(p_from); /* * Try to load the .TIC area again. */ if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Reload of new created file area %s failed", TIC.TicIn.Area); free(Temp); return 1; } } if ((tic.Secure) && (!TIC.TicIn.Hatch)) { First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if (Link.aka.zone) { if ((Link.aka.zone == TIC.Aka.zone) && (Link.aka.net == TIC.Aka.net) && (Link.aka.node == TIC.Aka.node) && (Link.aka.point== TIC.Aka.point) && (Link.receivefrom)) Listed = TRUE; } } if (!Listed) { Bad((char *)"%s NOT connected to %s", aka2str(TIC.Aka), TIC.TicIn.Area); free(Temp); return 1; } } if ((!SearchNode(TIC.Aka)) && (!TIC.TicIn.Hatch)) { Bad((char *)"%s NOT known", aka2str(TIC.Aka)); free(Temp); return 1; } if (!TIC.TicIn.Hatch) { if (strcasecmp(TIC.TicIn.Pw, nodes.Fpasswd)) { Bad((char *)"Pwd error, got %s, expected %s", TIC.TicIn.Pw, nodes.Fpasswd); free(Temp); return 1; } } else { if (strcasecmp(TIC.TicIn.Pw, CFG.hatchpasswd)) { Bad((char *)"Password error in local Hatch"); WriteError("WARNING: it might be a Trojan in your inbound"); free(Temp); return 1; } } if (Magic_DeleteFile()) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); file_rm(temp1); Syslog('+', "Deleted file %s", temp1); file_rm(Temp); free(Temp); return 0; } if (Magic_MoveFile()) { if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Unknown Area: %s", TIC.TicIn.Area); free(Temp); return 1; } } strncpy(T_File.Echo, tic.Name, 20); strncpy(T_File.Group, tic.Group, 12); TIC.KeepNum = tic.KeepLatest; Magic_Keepnum(); if (!tic.FileArea) { Syslog('+', "Passthru TIC area!"); strcpy(TIC.BBSpath, CFG.ticout); strcpy(TIC.BBSdesc, tic.Comment); } else { snprintf(Temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((fp = fopen(Temp, "r")) == NULL) { WriteError("Can't access fareas.data area: %ld", tic.FileArea); free(Temp); return 1; } fread(&areahdr, sizeof(areahdr), 1, fp); if (fseek(fp, ((tic.FileArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) { fclose(fp); WriteError("Can't seek area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } if (fread(&area, areahdr.recsize, 1, fp) != 1) { fclose(fp); WriteError("Can't read area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } fclose(fp); strcpy(TIC.BBSpath, area.Path); strcpy(TIC.BBSdesc, area.Name); /* * If the File area has a special announce group, change * the group to that name. */ if (strlen(area.NewGroup)) strncpy(T_File.Group, area.NewGroup, 12); } strncpy(T_File.Comment, tic.Comment, 55); /* * Check if the destination area really exists, it may be that * the area is not linked to an existing BBS area. */ if (tic.FileArea && access(TIC.BBSpath, W_OK)) { WriteError("No write access to \"%s\"", TIC.BBSpath); Bad((char *)"Dest directory not available"); free(Temp); return 1; } if ((tic.DupCheck) && (check_dupe)) { snprintf(Temp, PATH_MAX, "%s%s", TIC.TicIn.Area, TIC.TicIn.Crc); crc2 = 0xffffffff; crc2 = upd_crc32(Temp, crc2, strlen(Temp)); if (CheckDupe(crc2, D_FILEECHO, CFG.tic_dupes)) { Bad((char *)"Duplicate file"); tic_dup++; free(Temp); return 1; } } /* * Count the actual downlinks for this area and build the list of * systems qualified to receive this file. */ First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) { DownLinks++; p_from = fido2faddr(Link.aka); if (TIC.TicIn.Hatch) { fill_qualify(&qal, Link.aka, FALSE, in_list(p_from, sbl, TRUE)); } else { fill_qualify(&qal, Link.aka, ((TIC.Aka.zone == Link.aka.zone) && (TIC.Aka.net == Link.aka.net) && (TIC.Aka.node == Link.aka.node) && (TIC.Aka.point == Link.aka.point)), in_list(p_from, sbl, TRUE)); } tidy_faddr(p_from); } } T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Update the uplink's counters. */ Kb = TIC.FileSize / 1024; if (SearchNode(TIC.Aka)) { StatAdd(&nodes.FilesRcvd, 1L); StatAdd(&nodes.F_KbRcvd, Kb); UpdateNode(); SearchNode(TIC.Aka); } /* * Update the fileecho and group counters. */ StatAdd(&fgroup.Files, 1L); StatAdd(&fgroup.KBytes, Kb); fgroup.LastDate = time(NULL); StatAdd(&tic.Files, 1L); StatAdd(&tic.KBytes, Kb); tic.LastAction = time(NULL); UpdateTic(); if (!do_quiet) { printf("Unpacking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } /* * Check if this is an archive, and if so, which compression method * is used for this file. */ if (strlen(tic.Convert) || tic.FileId || tic.ConvertAll || strlen(tic.Banner)) { /* * Create tmp workdir */ if (create_tmpwork()) { free(Temp); tidy_qualify(&qal); return 1; } if ((unarc = unpacker(TIC.TicIn.File)) == NULL) Syslog('+', "Unknown archive format %s", TIC.TicIn.File); else { IsArchive = TRUE; if ((strlen(tic.Convert) && (strcmp(unarc, tic.Convert) == 0)) || (tic.ConvertAll)) MustRearc = TRUE; } } /* * Copy the file if there are downlinks and we send the * original file, but want to rearc it for ourself, or if * it's a passthru area. */ if (((tic.SendOrg) && (MustRearc || strlen(tic.Banner))) || (!tic.FileArea)) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); snprintf(temp2, PATH_MAX, "%s/%s", CFG.ticout, TIC.TicIn.File); if ((rc = file_cp(temp1, temp2) == 0)) { TIC.SendOrg = TRUE; } else { WriteError("Copy %s to %s failed: %s", temp1, temp2, strerror(rc)); } } if (MustRearc && IsArchive) { snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); if (!checkspace(temp2, TIC.TicIn.File, UNPACK_FACTOR)) { Bad((char *)"Not enough free diskspace left"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (chdir(temp2) != 0) { WriteError("$Can't change to %s", temp2); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!getarchiver(unarc)) { WriteError("Can't get archiver for %s", unarc); chdir(TIC.Inbound); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (strlen(archiver.funarc) == 0) { Syslog('!', "No unarc command available"); } else { cmd = xstrcpy(archiver.funarc); snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { UnPacked = TRUE; } else { chdir(TIC.Inbound); Bad((char *)"Archive maybe corrupt"); free(Temp); clean_tmpwork(); return 1; } free(cmd); } } /* * Scan file for viri. */ if (tic.VirScan) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (!do_quiet) { printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (VirScanFile(temp1)) { chdir(TIC.Inbound); Bad((char *)"Possible virus found!"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!do_quiet) { printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } } if (tic.FileId && tic.FileArea && IsArchive) { if (UnPacked) { snprintf(temp1, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); snprintf(Temp, PATH_MAX, "FILE_ID.DIZ"); if (getfilecase(temp1, Temp)) { Syslog('f', "Found %s", Temp); snprintf(temp1, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), Temp); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); } else { Syslog('f', "Didn't find a FILE_ID.DIZ"); } } else { if (!getarchiver(unarc)) { chdir(TIC.Inbound); } else { cmd = xstrcpy(archiver.iunarc); if (cmd == NULL) { WriteError("No unarc command available"); } else { snprintf(temp1, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT")); chdir(temp1); snprintf(temp1, PATH_MAX, "%s/%s FILE_ID.DIZ", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) { snprintf(temp1, PATH_MAX, "%s/%s file_id.diz", TIC.Inbound, TIC.TicIn.File); execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); } free(cmd); } } /* if getarchiver */ } /* if not unpacked */ } /* if need FILE_ID.DIZ and not passthru */ /* * Create internal file description, priority is FILE_ID.DIZ, * 2nd LDesc, and finally the standard description. */ if (!Get_File_Id()) { if (TIC.TicIn.TotLDesc > 2) { for (i = 0; i < TIC.TicIn.TotLDesc; i++) { strncpy(TIC.File_Id[i], TIC.TicIn.LDesc[i], 48); } TIC.File_Id_Ct = TIC.TicIn.TotLDesc; } else { /* * Format the description line (max 255 chars) in parts of 48 characters. */ if (strlen(TIC.TicIn.Desc) <= 48) { strcpy(TIC.File_Id[0], TIC.TicIn.Desc); TIC.File_Id_Ct++; } else { memset(&TDesc, 0, sizeof(TDesc)); strcpy(TDesc, TIC.TicIn.Desc); while (strlen(TDesc) > 48) { j = 48; while ((TDesc[j] != ' ') && (j > 0)) j--; if (j == 0) { Syslog('f', "Panic, no spaces"); j = 47; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, j); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; k = strlen(TDesc); j++; /* Correct space */ for (i = 0; i <= k; i++, j++) TDesc[i] = TDesc[j]; if (TIC.File_Id_Ct == 23) break; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, 48); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, strlen(TIC.File_Id[TIC.File_Id_Ct]), TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; } } } /* not get FILE_ID.DIZ */ /* * Now check if other (older) ticfiles point to this file, * if found mark it to purge later. */ for (topl = *opl; topl; topl = topl->next) { if ((strcmp(topl->Area, TIC.TicIn.Area) == 0) && (strcmp(topl->FileName, TIC.TicIn.File) == 0)) { topl->Purged = TRUE; } } /* * Rearc file if it is an unpacked archive. */ if ((MustRearc) && (UnPacked) && (tic.FileArea)) { if (Rearc(tic.Convert)) { /* * Get new filesize for import and announce */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Calculate the CRC if we must send the new archived file. */ if (!TIC.SendOrg) { ReCalcCrc(temp1); } } else { WriteError("Rearc failed"); } /* if Rearc() */ } /* * Change banner if needed. */ if ((strlen(tic.Banner)) && IsArchive) { cmd = xstrcpy(archiver.barc); if ((cmd == NULL) || (!strlen(cmd))) { Syslog('+', "No banner command for %s", archiver.name); } else { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); snprintf(Temp, PATH_MAX, "%s/etc/%s", getenv("MBSE_ROOT"), tic.Banner); if (execute_str(cmd, temp1, (char *)NULL, Temp, (char *)"/dev/null", (char *)"/dev/null")) { WriteError("Changing the banner failed"); } else { Syslog('+', "New banner %s", tic.Banner); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; ReCalcCrc(temp1); DidBanner = TRUE; } } } clean_tmpwork(); chdir(TIC.Inbound); /* * If the file is converted, we set the date of the original * received file as the file creation date. */ snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); if ((MustRearc || DidBanner) && CFG.ct_KeepDate) { if ((tic.Touch) && (tic.FileArea)) { ut.actime = mktime(localtime(&TIC.FileDate)); ut.modtime = mktime(localtime(&TIC.FileDate)); utime(Temp, &ut); Syslog('-', "Restamp filedate %s to %s", Temp, rfcdate(ut.modtime)); } } /* * Now make sure the file timestamp is updated. The file may be restamped, * altered by banners etc. */ TIC.FileDate = file_time(Temp); /* * If not passthru, import in the BBS. */ if (tic.FileArea) { Syslog('+', "Import: %s (%s) Area: %s", TIC.NewFile, TIC.NewFullName, TIC.TicIn.Area); BBS_Imp = Add_BBS(&qal); if (!BBS_Imp) { Bad((char *)"File Import Error"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } } chdir(TIC.Inbound); /* * Create file announce record */ if (tic.FileArea) { if (strlen(TIC.TicIn.Magic)) magic_update(TIC.TicIn.Magic, TIC.NewFile); else Magic_UpDateAlias(); for (i = 0; i < TIC.File_Id_Ct; i++) strncpy(T_File.LDesc[i], TIC.File_Id[i], 48); T_File.TotLdesc = TIC.File_Id_Ct; T_File.Announce = tic.Announce; strncpy(T_File.Name, TIC.NewFile, 12); strncpy(T_File.LName, TIC.NewFullName, 80); T_File.Fdate = TIC.FileDate; Add_ToBeRep(T_File); } if (TIC.SendOrg && !tic.FileArea) { /* * If it's a passthru area we don't need the * file in the inbound anymore so it can be * deleted. */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (file_rm(temp1) == 0) Syslog('f', "Deleted %s", temp1); } if (DownLinks) { First = TRUE; /* * Add all our system aka's to the seenby lines in the same zone, * omit aka's already in the seenby list. */ for (i = 0; i < 39; i++) { if (CFG.akavalid[i] && (tic.Aka.zone == CFG.aka[i].zone)) { p_from = fido2faddr(CFG.aka[i]); if (! in_list(p_from, sbl, TRUE)) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node, CFG.aka[i].point); else snprintf(sbe, 24, "%u:%u/%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node); fill_list(sbl, sbe, NULL); } tidy_faddr(p_from); } } /* * Add seen-by lines for all systems that will receive this file. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node, tmpq->aka.point); else snprintf(sbe, 24, "%u:%u/%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node); fill_list(sbl, sbe, NULL); } } uniq_list(sbl); sort_list(sbl); /* * Now forward this file to the qualified downlinks. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { ForwardFile(tmpq->aka, *sbl); tic_out++; } } } Magic_ExecCommand(); Magic_CopyFile(); Magic_UnpackFile(); Magic_AdoptFile(); snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); if (unlink(Temp)) { WriteError("$Can't delete %s", Temp); } free(Temp); tidy_qualify(&qal); return 0; }
/* ******************************************************************** */ int build_rac_index(void) { FILE *fdb; FILE *fndx; unsigned long call_offset = 0; unsigned long x = 0; char racdata[RAC_DATA_LEN+8]; char amacall_path[MAX_VALUE]; get_user_base_dir("data/AMACALL.ndx", amacall_path, sizeof(amacall_path)); /* ==================================================================== */ /* If the index file is there, exit */ /* */ if (filethere(amacall_path)) { /* if file is there make sure the index date is newer */ if(file_time(amacall_path)<=file_time(amacall_path)) { return(1); } else { // RAC index old, rebuilding statusline(langcode("STIFCC0103"), 1); fprintf(stderr,"RAC index is old. Rebuilding index.\n"); // XmTextFieldSetString(text,"RAC Index old rebuilding"); // XtManageChild(text); // XmUpdateDisplay(XtParent(text)); } } /* ==================================================================== */ /* Open the database and index file */ /* */ fdb=fopen(get_data_base_dir("fcc/AMACALL.LST"),"rb"); if (fdb==NULL) { fprintf(stderr,"Build:Could not open RAC data base: %s\n", get_data_base_dir("fcc/AMACALL.LST") ); return(0); } fndx=fopen(amacall_path,"w"); if (fndx==NULL) { fprintf(stderr,"Build:Could not open/create RAC data base index: %s\n", amacall_path ); (void)fclose(fdb); return(0); } /* ==================================================================== */ /* Skip past the header to the first callsign (VA2AA) */ /* */ memset(racdata, 0, sizeof(racdata)); while (!feof(fdb) && strncmp(racdata,"VA",2)) { call_offset = (unsigned long)ftell(fdb); if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL) { fprintf(stderr,"Build:header:Unable to read data base\n"); (void)fclose(fdb); (void)fclose(fndx); fprintf(stderr,"rc=0\n"); return (0); } } /* ==================================================================== */ /* write out the current callsign and RBA of the db file */ /* skip 100 records and do it again until no more */ /* */ while (!feof(fdb)) { fprintf(fndx,"%6.6s%li\n",racdata,(long)call_offset); call_offset = (unsigned long)ftell(fdb); for (x=0;x<=100 && !feof(fdb);x++) if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL) break; } (void)fclose(fdb); (void)fclose(fndx); // XmTextFieldSetString(text,""); // XtManageChild(text); return(1); }