#include #include #include "wuftpd.h" #include "wuftpd.m" #include #include #include static HELP_FILE help_logs ("wuftpd","logs"); static HELP_FILE help_banner ("wuftpd","banner"); struct ftpstats{ long download; long upload; int nbdownload; int nbupload; int anonymous; }; /* Count the number of file transfer in the log file. */ static int logs_count ( const char *file, ftpstats &st) { ftpstats st; glocal.st.download = 0; glocal.st.upload = 0; glocal.st.nbdownload = 0; glocal.st.nbupload = 0; glocal.st.anonymous = 0; (file,false); char username[100]; int size; char direction,access_mode; sscanf (line ,"%*s %*s %*s %*s %*s" // Skip the date " %*s %*s" // Transfert time, remote host " %d %*s %*s %*s %c %c %s" ,&size,&direction,&access_mode,username); if (access_mode == 'a') glocal.st.anonymous++; if (direction == 'o'){ glocal.st.download += size; glocal.st.nbdownload++; }else{ glocal.st.upload += size; glocal.st.nbupload++; } return 0; st = glocal.st; return glocal.st.nbdownload + glocal.st.nbupload; } static void logs_viewstats (const char *file, const char *host) { DIALOG_TEXTBOX dia; glocal.dia.setcontext (""); SSTRING cmd; cmd.setfromf ("-r -g -a -f%s",file); { SSTRING tmp; tmp.setfromf (MSG_U(I_OUTPUTCMD,"Output of command xferstats %s") ,cmd.get()); glocal.dia.newf_text ("",tmp.get()); glocal.dia.newf_text ("",""); } ("xferstats",cmd.get(),40); glocal.dia.newf_text ("",line); return 0; glocal.dia.newf_text ("",line); return 0; SSTRING title; title.setfromf (MSG_U(T_HOSTFTPLOGS,"FTP stats for %s"),host); int nof = 0; glocal.dia.edit (title.get(),"",help_logs,nof,MENUBUT_QUIT); } static void logs_view (const char *file, const char *host) { const char *file; const char *host; PRIVATE_MESSAGE timer; bool first; glocal.first = true; glocal.host = host; glocal.file = file; dialog_settimer (glocal.timer,5 ,true); (MSG_U(T_LOGDETAILS,"Log details"),"",help_logs); newf_head (MSG_U(H_LOGDETAILS ,"File name\tSize\tDirection\tAccess mode\tUser\tDate")); setbutinfo (MENU_USR1,MSG_U(B_VIEWSTATS,"View stats") ,MSG_R(B_VIEWSTATS)); sethdispo ("lrllll"); sortable(); sortpolicy ("anaaaa"); waitfor (glocal.timer); int nbline = (glocal.file,false); char fname[PATH_MAX],username[100]; char month[4],day[3],hour[9],year[5]; int size; char direction,access_mode; sscanf (line ,"%*s %3s %2s %8s %4s" // date " %*s %*s" // Transfert time, remote host " %d %s %*s %*s %c %c %s" ,month,day,hour,year ,&size,fname,&direction,&access_mode,username); static const char *tbmonth[]={ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", "Sep","Oct","Nov","Dec" }; int nomonth = 0; for (int i=0; i<12; i++){ if (strcasecmp(tbmonth[i],month)==0){ nomonth = i; break; } } char date[10+1+8+1]; sprintf (date,"%04d/%02d/%02d %8.8s" ,atoi(year),nomonth+1,atoi(day),hour); glocal.editrecords.new_menuitemf (fname,"%d\t%s\t%s\t%s\t%s" ,size ,direction=='o' ? MSG_U(I_DOWNLOAD,"Download") : MSG_U(I_UPLOAD,"Upload") ,access_mode=='a' ? MSG_U(I_ANONYMOUS,"Anonymous") : access_mode == 'g' ? MSG_U(I_GUEST,"Guest") : MSG_U(I_USER,"User") ,username ,date); return 0; if (glocal.first && nbline > 0){ setcursor (nbline-1); glocal.first = false; } logs_viewstats (glocal.file,glocal.host); dialog_deltimer (glocal.timer); } PUBLIC void WUFTPD::viewlogs() { VIRTUAL_FTPS sorted; PRIVATE_MESSAGE timer; glocal.sorted.neverdelete(); for (int i=0; i(glocal.sorted); VIRTUAL_FTP *f1 = (VIRTUAL_FTP*)o1; VIRTUAL_FTP *f2 = (VIRTUAL_FTP*)o2; return f1->addr.cmp(f2->addr); dialog_settimer (glocal.timer,3,true); (MSG_U(T_FTPLOGS,"FTP transfer logs") ,MSG_U(I_FTPLOGS,"Select one line to get a complete report") ,help_logs); newf_head (MSG_U(H_FTPLOGS,"Host\tTransfers\tDownloads\tSize\tUploads\tSize\tAnonymous")); waitfor (glocal.timer); // Just to wake up and refresh the list sethdispo ("lrrrrrr"); sortable(); sortpolicy ("annnnnn"); ftpstats st; int nb = logs_count (configf_lookuppath("/var/log/xferlog"),st); new_menuitemf (MSG_U(I_MAINSERVER,"Main server"),"%d\t%d\t%ld\t%d\t%ld\t%d" ,nb,st.nbdownload,st.download,st.nbupload,st.upload ,st.anonymous); for (int i=0; ilogfile.is_empty()){ new_menuitemf (ftp->addr.get(),"-\t-\t-\t-\t-\t-"); }else{ nb = logs_count (ftp->logfile.get(),st); new_menuitemf (ftp->addr.get(),"%d\t%d\t%ld\t%d\t%ld\t%d" ,nb,st.nbdownload,st.download,st.nbupload,st.upload ,st.anonymous); } } if (no == 0){ logs_view (configf_lookuppath("/var/log/xferlog"),MSG_R(I_MAINSERVER)); }else{ VIRTUAL_FTP *ftp = glocal.sorted.getitem(no-1); if (ftp->logfile.is_empty()){ xconf_notice (MSG_U(N_NOLOGFORHOST ,"There is no log file for this virtual host.\n" "Consult the main server log")); }else{ logs_view (ftp->logfile.get(),ftp->addr.get()); } } dialog_deltimer (glocal.timer); } void wuftpd_editbanner (const char *fname) { SSTRING text; DIALOG dia; (fname,false); glocal.text.append (line); return 0; dia.newf_textarea ("",glocal.text,70,15); int nof = 0; SSTRING title; title.setfromf (MSG_U(T_BANNERFILE,"Banner file %s"),fname); while (1){ MENU_STATUS code = dia.edit (title.get(),"",help_banner,nof); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else{ int ok = (fname,false); fputs (glocal.text.get(),fout); return 0; if (ok != -1) break; } } }