//------------------------------------------------------------------------------
// home web server
// copyright (c) 2004-2008 ari pikivirta [ari.pikivirta@kolumbus.fi]
//------------------------------------------------------------------------------
// send email about bugs, features needed and features you would like;
// if you like this very much, feel free to donate and support supporting
// and developing these at www.paypal.com - (ari pikivirta@kolumbus.fi).
//------------------------------------------------------------------------------
//
// r1.3.9.104, 26062008, ari pikivirta
// * added online percentage statistics calculation
// * added 100% server replace tag
//
// r1.3.8.103, 22062008, ari pikivirta
// * | |MONITORAVGSINCE( server replace tag added
// * all mime table related variables removed
//
// r1.3.8.100, 18062008, ari pikivirta
// * readded some procedures to show more of the possible exceptions that might happen
// * added try..except around the timer function
// * fixed bug on session list selection on update
// * removed communication log
// * fixed memory leaks caused by the idlogintercept ? (anyway fixed)
//
// r1.3.7.99, 16062008, ari pikivirta
// * updated internet updater
//
// r1.3.7.98, 08062008, ari pikivirta
// * all lists trough begin and end update functions to fasten drawing
// * readded freeing windows cached memory on entering no clients state
//
// r1.3.6.97, ari pikivirta
// * removed unnecessary procedures from source code (cleaning only(
// * changed statistics to use high(integer) to define maximum size for statistics
// (might still be 2g as it was before, but maby someday..)
//
// 31032008, r1.3.6.96, ari pikivirta
// * fixed bug on going up directories on directory browsing
// * tried to make setting window easier to use by just changing look
// * added button to clear statistics (was previously only available via right click)
//
// r1.3.6.95, ari pikivirta (special build)
// * load content server-replace-tag moved before other tags to allow
// replacing tags inside the loaded contents also
// * added ismember server-replace-tag to limit access to something, results TRUE or FALSE
// * removed exception events for test purposes (ja37)
//
// 05012008, r1.3.5.94, ari pikivirta
// * terminal wait timeout changed from 5s to 10s
// * removed unnecessary "Anonymous" assigning on failed login
// * showing when isapi dll is loaded to memory and freed
// * removed forcing of send/receive buffer sizes
// * added address to the transfers monitoring list
//
// 04032008, r1.3.4.93, ari pikivirta
// * added unknwon file extension into the browser view
// * removed dot from file extension icon cache name for easier editing
// * open ssl libraries updated (still might be needed to replace on different platforms,
// but now worked on 32 and 64bit vista)
// * added new tag || LOADCONTENT(fname) to load part of content form another file
//
// 03012008, r1.3.4.92, ari pikivirta
// * updater have now progressbar as it had some long time ago (update to id10)
// * removed server address setting, because is really not needed
//
// 29122007, r1.3.4.91, ari pikviirta
// * indy 10.2.3 snapshot 28122007
// * added file count and total size under the browse list
// * added replace tag for password
// * added extension to dirlist replace tag for having icons for files
// * changed browse folders view to look much better
// * added icon cache folder and alias to the settings
//
// 06122007, r1.3.3, b90, ari pikivirta
// * updated home page to go to /products.html
// * added communication logging window to see the communication details
// * fixed compatibility issue with the openssl libraries
//
// 04122007, r1.3.2, b89, ari pikivirta
// * updated to indy 10.2.3
//
// 20082007, r1.3.2, b88, ari pikivirta
// * added all time statistics with possibility to reset
// * limited statistics to 2G (maximum integer) to avoid overflow
// * minor changes to reduce fails on writing setting files
//
// 25072007, r1.3.2, b87, ari pikivirta
// * added new server-replace-tag as FILEREV(filename)
// * directories for default extensions doesn't need to have "\" ending anymore
// * most critical sections changed to mrews to achieve even faster responses
// * selected list positions remain even on list updates
//
// 25032007, r1.3.2, b86, ari pikivirta
// * improved the dirlist replace tag functionality, it's sorted now
// * added possibility to enable folder browsing under the web root
//
// 19032007, r1.3.2, b85, ari pikivirta
// * added autoban for clients trying to get unexisting file several times
// * improved start on windows startup to check the check value from registry
// instead of internal settings
//
// 19032007, r1.3.2, b84, ari pikivirta
// * fixed low speed transfer to ignore zero setting (no limit)
//
// 18032007, r1.3.2, b83, ari pikivirta
// * added possibility to create new log file / day
// * added possibility to not to log date to the log file (will shorten log lines)
// * added confirmation before applying very low transfer speed limitation
// * added password generator button to the client edit window
//
// 07032007, r1.3.1, b82, ari pikivirta
// * fixed bug caused by isapi/cgi file exist checking - actions were not able to perform
// * fixed wrong status information text on trayicon hint when server was stopped
//
// 06032007, r1.3.1, b81, ari pikivirta
// * changed download statistics internal to transfer stream
//
// 28022007, r1.3.0, b80, ari pikivirta
// (beta)
// * ported all communicaiton code from indy 9.0.50 to indy 10.1.6
// * open ssl web page can be used to download latest ssl libraries
// * removed security page's different verify modes, removed
// also http checkbox (these were no use)
// * rewrote logging background buffer, temporary holds now up to 32 messages
// * added possibility to hide tray icon when minimized
// * monitored files will not increase if same ip downloads same file within one hour
// * added some options for the logging (dontlog servefails, unexistingfiles, bannedips)
// * added checking of file existence on special extension cases too
// * added "|| DOCUMENT" and "|| RESPHEAD" server-replace-tags
//
// 22022007, r1.2.12, b79, ari pikivirta
// (beta)
// * fileage replaced by the api_files new filedtm function
// * filesize(s) replaced by api_files getfilesize function (not platform specific)
// all file size(s) are now shown more common formatting
// * server-replace-tag code improved to be more efficient
// * hourly statistics code improved to make serving of files even faster
// * removed client port's from the logging (not needed)
// * fixed logging of normal file serving (showed the whole file path)
// * main created on startup, other windowses created on access to save memory
// * client sessions show up as active for defined time
// * logo picture loaded on demand only, freed when main window is minimized
// * uncommented the cgi and isapi extension edit possibility
// * cgi process execution path now defined into the CreateProcess()
// * free cached memory when idle or stopped
// * added new view to monitor file transfers
// * added possibility to limit transfer speeds (common to all clients)
// * PathExt Environment variable for this process is possible to set on setting window
// * changed using own buffering on file streams
//
// r1.2.12, b78, ari pikivirta
// * changed all document logging relative path to shorten the log lines
//
// 02022007, r1.2.12, b77, ari pikivirta
// * some minor changes into the source (just making it even more efficient)
// * reduced internal statisticslist to 7 days (connections, useragents, etc..)
// * re-checked php (cgi) and isapi functionality
//
// r1.2.12, b76, ari pikivirta
// * added possibility to add comment for each ban list item
// * fixed logging to file (was forgot to add on changes to logging on b72!)
// * setting view now remembers it's size, position and internal stuff
// * added button to set default mimetypes in case corrupt
//
// 25012007, r1.2.11, b75, ari pikivirta
// * added possibility to ban ip range(s) also
//
// 25012007, r1.2.11, b74, ari pikivirta
// * document directories were still wrong for the cgi and isapi dll
//
// 23012007, r1.2.11, b73, ari pikivirta
// * fixed both cgi and isapi dll directories on execute (was root instead of
// the document's folder)
// * fixed bug in updating the progress wasn't shown in bytes until finished
//
// 28122006, r1.2.11, b72, ari pikivirta
// * changed the way how visible log lines are being inserted onto the api_richedit
// * added possibility to limit logfile lines also
//
// 26122006, r1.2.11, b71, ari pikivirta
// * added support for statistics of above 2G download(s), giga(s) showing
// as separate item after the Mb value
// * changed the structure of serving files (should be much faster than before)
// * server-replace-tags will work on html and text files even the mimelist is cleared
// * active users list updated only if it's changed to make normal operation even faster
//
// 30112006, r1.2.10, b70, ari pikivirta
// * internet update part updated to be possible to receive messages from file server
// * tray icon hint info modified to have also web server current status
//
// 29112006, r1.1.9, b69, ari pikivirta
// * fixed bug with monitoring list items, it was increased even serving
// file failed
//
// 27112006, r1.1.9, b68, ari pikivirta
// * removed "-" marks from the log message after ">"
// * fixed button colors on the http settings php tab
// * fixed php help text anchors to always fit onto the php tab screen even if resized
//
// 25112006, r1.1.9, b67, ari pikivirta
// * fixed some visible component positions on the http server settings view
// * added hint of last log message onto the trayicon
//
// 21112006, r1.1.9, b66, ari pikivirta
// * added custom configuration possibility using configurator (registered
// users only)
//
// 20102006, r1.0.9, b65, ari pikivirta
// * added termination of all client threads at application close (destroy)
// * changed buildinfo data to integer to get rid of warning message at compile
//
// 17092006, r1.0.9, b64, ari pikivirta
// * removed isapi and cgi custom extensions (there seems to be no need for
// such items), now using defaults only (.exe and .dll)
// * added possibility to export/inport all the setting files. this is for the
// situation that you need to reinstall windows for example - after inporting
// all settings are as they used to be (drives in the paths however must be
// rechecked)
// * fixed wrong hint on the clear log button
// * removed word wrapping from the log view (was annoying)
//
// 11.8.2006, r1.0.8, b63, ari pikivirta
// * finally found the bug in start on windows startup removing (found in
// api_registry component)
// * fixed bug on web server exit, it failed to purge all sessions sometimes
//
// 31.7.2006, r1.0.8, b62, ari pikivirta
// * fixed date in html header
// * added internal redirect document setting possibility to for example
// redirect "/ftpinstall.zip" to "/files/ftpserverinstall.exe"
// * added || REQUESTHEAD replace tag
//
// 31.7.2006, r1.0.8, b61, ari pikivirta
// * added date to html response header for htp time protocol
//
// 28.7.2006, r1.0.8, b60, ari pikivirta
// * removed unnecessary statistics that consume memory
// * fixed problem of domain and root alias files to be stored into
// wrong folder on create and exit
// * fixed registry issue with removing running on windows startup
// * fixed bug that prevented php compiler to run even it was regognized
// * changed behaviour of trayicon (not showing while window is showing)
//
// 15.10.2005, r1.0.8, b59, ari pikivirta
// * fixed problem with clients logging in personal pages if using domain or
// directory aliases.
// * some fixes with item positioning when windows are resized
//
// 17.9.2005, r1.0.8, b58, ari pikivirta
// * found out problem that arised from testing with other indy versions and
// fixed those (probably perious version had cgi, isapi, https not working)
//
// 3.9.2005, r1.0.8, b57, ari pikivirta
// * added possibility disable close confirmation (default)
// * separated php from cgi and isapi tab
// * added file extension specific lists to run both cgi or isapi
// * changed background color of history diagram
//
// 7.6.2005, r1.0.8, b56, ari pikivirta
// * added multiple default file possibility
// * http settings window now remembers it's position and size
// * main window headers remember their widths
// * updated internet update
//
// 16042005, r1.0.7, b55, ari pikivirta
// * removed user agent statistics because not needed
// * fixed saving of root and domain aliases lists on settings window
// * application restores on exit if minimized
//
// 31012005, r1.0.7, b54, ari pikivirta
// * fixed log file select (changed web directory instead in b52)
//
// 31012005, r1.0.7, b53, ari pikivirta
// * fixed default page checking from folders - reported bug (Alex)
// * added some more tray icon popup items - requested feature
// * confirmation needed to close the application - applied request
//
// 13012005, r1.0.7, b52, ari pikivirta
// * rebuild all synchronizations from the client threads
// * added user agent statistics
// * added downloaded bytes diagram into about window
// * changed log book settings into setting window as a new tab
// * added free selectable extensions of served files not put in log book
// * fixed problem with the member folders
// * added server-replace-tags for avg bytes per day and user agent
//
// 27122004, r1.0.6, b51, ari pikivirta
// * some ftp server updates applied to web server also (only small changes
// in internal work order)
// * added saving of special file list in every update
//
// 09112004, r1.0.6, b50, ari pikivirta
// * added possibility to alter ports for http and https
// * fixed first view to "about" which it should have been
//
// 26092004, r1.0.6, b49, ari pikivirta
// * added php ini path into php settings
// * fixed cgi and isapi admin email informations
//
// 25092004, r1.0.6, b48, ari pikivirta
// * fixed php files handling (messed up with cgi and isapi detection)
// * root aliases now serve all files from defined root alias (until session time out)
//
// 25092004, r1.0.6, b47, ari pikivirta
// * fixed modifying of the root aliases (didn't appear when item clicked at list)
// * fixed removing root alias name from document being served from root alias root
// * added tip for the first startup to easy the first steps
//
// 15092004, r1.0.6, b46, ari pikivirta
// * fixed root aliases
// * added domain aliases to have multiple roots via different domain names (requested feature)
// * fixed bugs with system log (sometimes changed font)
// * added missing sort methods for member last time and last document
//
// 28082004, r1.0.5, b45, ari pikivirta
// * added average per day into file monitoring and also made as server-replace-tag
// * added count per day into file monitoring and also made as server-replace-tag
// * fixed restoring of tab index (when installed first time)
//
// 26082004, r1.0.5, b44, ari pikivirta
// * fixed buttons to ho scrambled
// * added saving of window position and size, also tab index
//
// 24082004, b43, ari pikivirta
// * fixed clearing of monitored file counter
// * added server-replace-tag for showing monitored file counts
// * removed registry queries that are only available in Windows NT or above
// to make these compatible also for 98SE and ME.
//
// 19082004, b42, ari pikivirta
// * fixed memory leak in logging messages (they were not decreased at any point!)
// * fixed loading/saving of enable fading information
//
// 18082004, b41, ari pikivirta
// * fixed log file from emptying log after program restart
//
// 16082004, b40, ari pikivirta
// * fixed last client connect time in active clients monitoring
// * fixed deleting all same session ids on session end
// * separated dont log texts (and html pages) and dont log pictures
// in log settings
// * changed exception chandling on get head request (if file is in use)
// * added possibility to enable/disable window fading effect
//
// 15082004, b39, ari pikivirta
// * rechecked all unit through
// * fixed one possible unthreadsafe situation when serving templates
//
// 14082004, b38, ari pikivirta
// * changed user and monitored file save file format
// * added members last time and last document
// * also added session monitoring view (fixed 20:19 - second today)
// * fixed if savetolog wasn't checked it didn't log anything (21:28)
// * fixed monitored file delete (22:02)
// * fixed monitored file compare to be not casesensitive (22:02)
//
// 13082004, r1.04, b38, ari pikivirta
// * fixed edit box font when editing
// * fixed listbox fonts change on mouse over (looked weird)
//
// 10082004, b37, ari pikivirta
// * compiled with latest libraries
// * moved to using 096m openssl libraries
// * separated using same monitored file module with ftp server
//
// 04082004, b36, ari pikivirta
// * updated some of components
//
// 03082004, b35, ari pikivirta
// * fixed the bug in removing monitored file from list
// * added lists sorting function after list changes
//
// 31072004, b34, ari pikivirta
// * changed monitored file check to not be casesensitive
// * when not logging html and pictures - this will also happen to visible log
//
// 28072004, b33, ari pikivirta
// * added support for root aliases (user web pages for example)
// * added banned ip list to disallow unwanted connections
// * fixed some possible not thread safe function calls
//
// 27072004, r1.03, b32, ari pikivirta
// * added cgi and isapi aliases (must exist in alias folder to run)
//
// 26072004, b31, ari pikivirta
// * added green icon into the taskbar to show client present
// * fixed bytes downloaded counter again (it was counting uploads)
// * fixed internal getfilelist server data implementation
// * added new internal server data implementation of to get file size
//
// 24072004, b30, ari pikivirta
// * added reset monitored file counter button
// * changed monitored file last time to show up "-" if last time does not exist
// * added port as visible when logging data
// * added couple of new "internal server tags" to replace
//
// 22072004, b29, ari pikivirta
// * changed the way to synchronize threads
// * changed https possible without http
// * fixed server software name
//
// 21072004, b28, ari pikivirta
// * fixed not logging of *image* and *text* files
// * fixed files monitoring
// * fixed member addresses checking
//
// 20072004, r1.02, b27, ari pikivirta
// * open ssl support is finally working
// * added log messages etc. showing also in statusbar
// * fixed the downloaded bytes calculation (overrun when >2G - the legendary)
// * reversed this history read order
// * included some demos into the pub package with source of course
//
// 19072004, b26, ari pikivirta
// * added possibility to change port number (http and https cannot exist in same)
// * changed mimelist to exist in http settings window
// * added ssl password string (didn't work without :))
// * fixed http client count when server is stopped
//
// 18072004, r1.01, b25, ari pikivirta
// * started implementing SSL possibility
//
// 17072004, r1.01, b24, ari pikivirta
// * fixed php support if set as default file (buglist / christoffer)
//
// 17072004, b23, ari pikivirta
// * changed back using indy http server component
// * added last address and date of member users into the list
// * added support for php processing
// * added support for cgi applications
// * fixed mimetype search from mimelist editor
// * fixed isapi dll action mistake
//
// 16072004, b22, ari pikivirta
// * took mimelist into usage (was missing before 'cause of my nice memory)
//
// 14072004, b21, ari pikivirta
// * fixed the internet updating..
//
// 12072004, b20, ari pikivirta
// * added rezisable header for special files and "member" users
// * fized special file listing to contain also the last ip
// * changed the get file creation time to get through fileage function
// * file monitor separated as it's own window
//
// 10072004, b19, ari pikivirta
// * added possibility monitor selected files
//
// 09072004, b18, ari pikivirta
// * went back to using ics
// * fixed downloaded bytes calculation
// * modified answer pages (changed hgwillsendmyself place)
// * added http lock as a separate than uilock (it really is)
//
// 07072004, b17, ari pikivirta
// * changed to using idhttpserver
// * added home logo
// * added some statistics
//
// 06072004, b16, ari pikivirta
// * home server was split into four different server applications