ServuEvent.dll is a simple dll that allows servu to run just about any exe, cmd or bat after a serv-u event has arrived. Every event has can be used with parameters and is given in ServuEven.ini: Before you use this some thing to be aware of: This dll only works for Serv-U 2.x!!!! ServuEvent.ini settings - check in your helpfile under "Extending Serv-U" how it works. ServuEvent.ini needs to be where you placed ServuEvent.dll. If you havent placed it there then it will try to find this file in the dir where Serv-U32.exe for version 2.x is. You can cut and paste the piece below to make your own ServuEvent.ini , then fill in the events as you use them. Uncomment a line by removing the ; in front of it. Servuevent.ini should be a part of this distribution. To execute a .bat or a .cmd file (yes there is a difference!) use: c:\windows\system32\cmd.exe /c blahblah.cmd or c:\windows\system32\cmd.exe /c blahblah.bat Examples of a console program with console piping: DownloadAllowedCheck.c could be: #include #include #include int main(int argc,char *argv[]) { time_t t; struct tm *tm; if (argc==1) return -1; printf("The server has been running for %ServerDays\n"); if (!stricmp(argv[2],"Administrator")){ printf("Only the Administrator is allowed to download anything\n"); return -1; //<0 command fails } time(&t); tm=localtime(&t); if (tm.wday==0 || tm_wday==6){ printf("Download on Sundat and Saturday is not allowed\n"); return -1; } return 0; //return 0 because we want servu to handle this further on } ---------------------------------------------------------------------- To make life easier ServuEvent supports a big bundle of cookies. Do not mistake these cookies with the Serv-u variables itself. These servuevent cookies can be used when calling external programs or cheking permissions using ServuEvent.dll. They are valid in the [Events] the [Pre] and the [Permissions] section The user cookies are, above the cookies are mentioned that you can at least use. But there are more cookies that you can also use. The User cookies are: %[DNS] = the dns name of the user, or the ip address %[PASSWORD] = the userpassword, only available when the user is anonymous %[COMMAND] = a string describing what the user is doing (last command) %[CWD] = the current working directory the user is in %[DIR] = the complete path of the dir being created/deleted %[DIRNAME] = the name of the dir being created/deleted %[FILE] = the complete filepath being uploaded/deleted/renamed %[FILENAME] = the name of the file being uploaded/deleted/renamed %[RENAMEFILE] = the complete filepath being uploaded/deleted/renamed %[RENAMEFILENAME] = the name of the file being uploaded/deleted/renamed %[LOGINTIME] = the adte/time when the user was logged in in mm-dd-yyyy hh:mm:ss %[USERCOUNT] = the count of all the logged in users %[EVENT] = the event number, see the servu help file for its reference %[SUBEVENT] = the sub event number, see the servu help file for its reference %[ID] = the unique connection id for the user %[NAME] = the name of the user that is logged in %[USER] = the name of the user that is logged in %[USERNAME] = the name of the user that is logged in %[IP] = the ip number of the user that is logged in %[LOCALIP] = the ip number of the server %[DURATION] = the duration of the up/download in msec %[SIZE] = the size of the up/download file %[AUX1] = this can differ, see the table below, see also the servu help file %[AUX2] = this can differ, see the table below, see also the servu help file %[SPEED] = the speed in bytes/milliseconds (which is almost KBytes/s) %[DOMAINPORT] = the port of the domain that the user is connected to (Only for Serv-u 4.1.0.3 and up) %[DOMAINID] = the ID of the domain the user is connected to (see in the ServuDaemon.ini) (Only for Serv-u 4.1.0.3 and up) %[BDAYUP] = amount of bytes upped during this day %[BDAYDN] = amount of bytes downed during this day %[BMNUP] = amount of bytes upped during this month %[BMNDN] = amount of bytes downed during this month %[BWKUP] = amount of bytes upped during this week %[BWKDN] = amount of bytes downed during this week %[BALUP] = amount of bytes upped totally %[BALDN] = amount of bytes downed totally %[KBDAYUP] = amount of Kbytes upped during this day %[KBDAYDN] = amount of Kbytes downed during this day %[KBMNUP] = amount of Kbytes upped during this month %[KBMNDN] = amount of Kbytes downed during this month %[KBWKUP] = amount of Kbytes upped during this week %[KBWKDN] = amount of Kbytes downed during this week %[KBALUP] = amount of Kbytes upped totally %[KBALDN] = amount of Kbytes downed totally %[MBDAYUP] = amount of Mbytes upped during this day %[MBDAYDN] = amount of Mbytes downed during this day %[MBMNUP] = amount of Mbytes upped during this month %[MBMNDN] = amount of Mbytes downed during this month %[MBWKUP] = amount of Mbytes upped during this week %[MBWKDN] = amount of Mbytes downed during this week %[MBALUP] = amount of Mbytes upped totally %[MBALDN] = amount of Mbytes downed totally %[GBDAYUP] = amount of Gbytes upped during this day %[GBDAYDN] = amount of Gbytes downed during this day %[GBMNUP] = amount of Gbytes upped during this month %[GBMNDN] = amount of Gbytes downed during this month %[GBWKUP] = amount of Gbytes upped during this week %[GBWKDN] = amount of Gbytes downed during this week %[GBALUP] = amount of Gbytes upped totally %[GBALDN] = amount of Gbytes downed totally %[DAYUP] = amount of bytes/Kbytes/MBytes/GBytes upped during this day %[DAYDN] = amount of bytes/Kbytes/MBytes/GBytes downed during this day %[MNUP] = amount of bytes/Kbytes/MBytes/GBytes upped during this month %[MNDN] = amount of bytes/Kbytes/MBytes/GBytes downed during this month %[WKUP] = amount of bytes/Kbytes/MBytes/GBytes upped during this week %[WKDN] = amount of bytes/Kbytes/MBytes/GBytes downed during this week %[ALUP] = amount of bytes/Kbytes/MBytes/GBytes upped totally %[ALDN] = amount of bytes/Kbytes/MBytes/GBytes downed totally %[FilesDAYUP] = amount of files upped during this day %[FilesDAYDN] = amount of files downed during this day %[FilesMNUP] = amount of files upped during this month %[FilesMNDN] = amount of files downed during this month %[FilesWKUP] = amount of files upped during this week %[FilesWKDN] = amount of files downed during this week %[FilesALUP] = amount of files upped totally %[FilesALDN] = amount of files downed totally %[ARGSALL] = the changed command line with some space adjustments, this is the complete commandline when the command is NOT recognised as a Pre command, otherwise it is the arguments after the Pre command. %[ARG0] .. %[ARGx] = with x any number, the arguments for the command. These are the arguments derived from the above cookie. So in case of the pre command not being recognized these are coming from the raw commandline. The System cookies are: %[DATE] = the current date on the server in with format YYYY-MM-DD %[TIME] = the current time on the server in with format HH:MM:SS %[TOTALSPEED] = the total speed of the server (up+down) %[TOTALSPEEDDOWN] = the sum of all the download speeds together %[TOTALSPEEDUP] = the sum of all the upload speeds together %[TOTALUSERSIDLE] = the number of users being idle %[TOTALUSERSDOWN] = the number of users downloading %[TOTALUSERSUP] = the number of users uploading %[TOTALUSERS] = The number of users connected %[RAW] = the raw command performed last, e.g. STOR blah.txt %[SERVUDIR] = the directory where Serv-U is located Apart from this all the settings for a user are stored in the ServuDaemon.ini or Serv-u.ini (version 2.x only). Settings such as: Note1=blah@blah.com HomeDir=.... etc... Will be available as cookies as well. So the examples of above are: %[Note1] %[HomeDir] ... These are user cookies. Please check the appropriate ini file for which ones you can use. Some usefull ones are: %[Group] %[HomeDir] %[Maintenance] %[Note1] %[Access1] A special word of warning for %[Group] usage. If you use it with multiple groups it will be taken from the ini file like (example): Group=TestGroup|AdminGroup . Now if you use it in a dos command then you MUST realize that the | character has a special meaning (it is the pipe character). Thus do place double quotes around it. So: ChgDir=c:\windows\system32\cmd.exe /c echo "%[GROUP]" >>c:\servu.log is correct where ChgDir=c:\windows\system32\cmd.exe /c echo %[GROUP] >>c:\servu.log is not correct. All cookies can be used with length options. That goes as follows: %minwidth.maxwidth[cookie] minwidth is the minimal number of character to be shown, this number can be <0 or >0 or even absent. if it is <0 then it will be right aligned, otherwise leftaligned this may or may not be followed by a period maxwidth is the maximal number of characters to be shown. Examples: Suppose the %[FILE] cookie has value C:\FTP\DIR\FILE.TXT %[FILE] gives "C:\FTP\DIR\FILE.TXT" %10[FILE] gives "C:\FTP\DIR\FILE.TXT" %-10[FILE] gives "C:\FTP\DIR\FILE.TXT" %25[FILE] gives "C:\FTP\DIR\FILE.TXT " %-25[FILE] gives " C:\FTP\DIR\FILE.TXT" %25.5[FILE] gives "C:\FT " %-25.5[FILE] gives " C:\FT" %.5[FILE] gives "C:\FT" %-.5[FILE] gives "%-.5[FILE]" this is an incorrect cookie %XY[FILE] gives "%XY[FILE]" this is not recognized as correct Any unrecognized cookie gets directly printed as shown in the abovev example. Now you can also use userdependant events, yet you MUST be aware which servu version you run for this. For that you have to place the events in the Users.ini file. The syntax is exactly as you would find in the Serv-u.ini file (Serv-u version 2.x) or ServuDaemon.ini file (Serv-u version 3.x) For version 2.x user Serv-U.ini Say we have user JOHN [USER=JOHN] Password=JOHNSPASS HomeDir=c:\ftp TimeOut=45 Access1=c:\ftp,RWAMCDLEP So now in Users.ini we make: [USER=JOHN] EndUp=HIDE|2|c:\windows\system32\cmd.exe /c echo %[USER] uploaded %[FILE] >>c:\serv-u\logs\%[USER].log ...etc... The events that you can use for a single user are: Login= Close= BouncedIP= TooMany= ;I discovered that Serv-U 6 never triggers this event, so you can not use it. WrongPass= ;I discovered that Serv-U 6 never triggers this event, so you can not use it. TimeOut= Login= StartUp= EndUp= StartDown= EndDown= AbortUp= AbortDown= Rename= DelFile= DelDir= ChgDir= MakeDir= BadPass= ;This event I had to create myself due to the point that not all Serv-U versions properly trigger WrongPass, it only works for Serv-u 3.x or up. ;It get triggered as soon as someone types a bad Password during login All these events work as documented in the ini file. So the arguments for example of IPName will not be triggered ever for a user since the username is normally not given yet at that moment. If a user has no event then the event in ServuEvent.ini will be executed. So the userevent overrules the global events from ServuEvent.ini Now how to use this DLL in servu? Simple grab your SevuDaemon.ini (servu 3.x and up) or Serv-U.ini (servu 2.5) and add the following. [EXTERNAL] EventHookDLL1=ServuEvent.dll Another small example of event use, log data of uploads to a file: EndUp=HIDE|2|c:\windows\system32\cmd.exe /c echo user %[NAME]/%[PASSWORD] from %[DNS] is on current directory %[CWD] uploaded "%[FILE]" >>c:\servu.log Or an event that logs everything on change of dir ChgDir=HIDE|2|c:\windows\system32\cmd.exe /c echo "USERCOUNT=%[USERCOUNT] GROUP="%[GROUP]" DNS=%[DNS] PASSWORD=%[PASSWORD] COMMAND=%[COMMAND] CWD=%[CWD] DIR=%[DIR] DIRNAME=%[DIRNAME] FILE=%[FILE] FILENAME=%[FILENAME] RENAMEFILE=%[RENAMEFILE] RENAMEFILENAME=%[RENAMEFILENAME] LOGINTIME=%[LOGINTIME] RAW=%[RAW] EVENT=%[EVENT] SUBEVENT=%[SUBEVENT] ID=%[ID] NAME=%[NAME] IP=%[IP] LOCALIP=%[LOCALIP] DURATION=%[DURATION] SIZE=%[SIZE] AUX1=%[AUX1] AUX2=%[AUX2] SPEED=%[SPEED] DOMAINPORT=%[DOMAINPORT] DOMAINID=%[DOMAINID] DATE=%[DATE] TIME=%[TIME]" >>c:\servu.log Implemented commands SITE WHO - show what users are doing The following commands ONLY work for the superuser/System administrator. They are experimental for now with it you can remotely add and remove users and change settings so be carefull what you do. This is not for beginners, you have to have a good understanding of the ini file. SITE READINI - show the whole ini file SITE READINI sectionname - show part of the ini file. e.g. SITE READINI Domain1 SITE READINI sectionname keyname - show part of the ini file specifically the blah=. e.g. SITE READINI USER=TestUser|1 Password SITE WRITEINI sectionname keyname=value - change part of the ini file. e.g. SITE WRITEINI USER=TestUser|1 Password NewPassword SITE DELINI sectionname - delete a whole part of the ini. E.g. SITE DELINI USER=testUser|1 SITE DELINI sectionname keyname - delete a part of the ini, specially the blah=. e.g. SITE DELINI Domain1 User1 SITE REHASH - reload the [Pre] and [Events] part of ServuEvent.ini SITE ADDUSER username password - add a user to the ini. Be aware you'll need to add more things via SITE WRITEINI check your ServuDaemon.ini or Serv-u.ini for that. SITE DELUSER username - delete the user. Only the system user is allowed to do that. Be aware it may take 15 seconds for servu to really delete the user. SITE CHPASS username password - change the password of the user SITE USERS - show a list of users SITE XWHO - get extended info about who is logged in SITE REBOOT - Shuts down the system and then restarts the system. SITE SHUTDOWN - Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. If the system supports the power-off feature, the power is also turned off. SITE POWEROFF - Shuts down the system and turns off the power. The system must support the power-off feature Notes of importance: In order to use this event you have to store the data in the ini and not in the registry. In order to use site chpass you cant use encrypted passwords. Be aware of redirecting a line like this: c:\windows\system32\cmd.exe /c test 2>>c:\test.log this will not redirect, use a space between the 2 and the >> Known sideeffects: If a user logs in and does not do change the current working dir then this %[CWD] will be empty. That means he is in the homedir. For your convenience I have repeated the internal Servu cookies, those can be used in the message files for servu. That means that they can also be used in the message files in Servu. You can also find this information in the servu help file. Time/date: %Time - displays the current time on your PC %Date - displays the current date on your PC Server statistics: %ServerDays - displays the number of days the server has been running %ServerHours - displays the number of hours the server has been running %ServerMins - displays the number of minutes the server has been up %ServerSecs - displays the number of seconds the server has been up %ServerKbUp - displays the no. Kbytes uploaded to the server since server start %ServerKbDown - displays the no. Kb downloaded from the server since server start %ServerFilesUp - displays the no. of files uploaded to the server since server start %ServerFilesDown - displays the no. of files downloaded from the server since server start %LoggedInAll - displays total no. of logged in users since server start %ServerAvg - displays the average server throughput since server start %ServerKBps - displays current server bandwidth use Server settings: %MaxUsers - displays the maximum no. of users, as set in 'Setup - Server' %MaxAnonymous - the maximum no. of anonymous users, as set in 'Setup - Server' User info: %Name - displays the user's login name %IP - displays the user's IP number or name if available %Dir - displays the user's current directory %Disk - displays the user's current disk drive %DFree - displays the amount of free space on the user's current disk in Kb %FUp - displays the number of files uploaded by the current user %FDown - displays the number of files downloaded %FTot - displays the total number of files transferred %BUp - displays the number of Kbytes uploaded by the user %BDown - displays the number of Kbytes downloaded by the user %BTot - displays the total number of Kbytes transferred %TConM - displays the total connect time in minutes %TConS - displays the connect time in seconds - to be used with '%tconm' %RatioUp - displays the 'upload' ratio part for UL/DL ratios %RatioDown - displays the 'download' ratio part for UL/DL ratios %RatioCredit - displays the current download credit for UL/DL ratios (Kb or 'files') %QuotaUsed - displays how much disk quota is used in Kb %QuotaLeft - displays how much disk quota is left in Kb %QuotaMax - displays the maximum amount of disk space that can be used in Kb Number of users: %UNow - displays the current number of Serv-U users connected %UAll - displays the number of users since the server was started %U24h - displays the number of users in the last 24 hours %UAnonAll - all currently logged in anonymous users %UAnonThisIP - all anonymous users logged into this IP home %UNonAnonAll - all non-anonymous users currently logged in %UNonAnonThisIP - all non-anonymous users logged into this IP home %UThisName - all current users with the current user name logged into this IP The file upload and download message directives are for the current session only (i.e. they do not show the aggregate over multiple sessions). The '%ServerDays', '%ServerHours', '%ServerMins', and '%ServerSecs' directives are meant for use together. The number of hours is what's left after the number of days is subtracted, and the same goes for the number of minutes and seconds. Thanks to and inspiration from: dshadow, various other unmentioned peole that had some nice addon ideas. Version: 1.0.0: Changed:Serv-U 2.x branch split off from 3.x and above branch