Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Forked Xestia Scanner Server!
[xestiascansrv/.git] / cgi-files / install-multiuser.cgi
1 #!/usr/bin/perl -Tw
3 #################################################################################
4 # Xestia Scanner Server Installer Script (install-multiuser.cgi)                #
5 # Multiuser installation script for Xestia Scanner Server                       #
6 #                                                                               #
7 # Version: 0.1.0                                                                #
8 #                                                                               #
9 # Copyright (C) 2005-2011 Steve Brokenshire <sbrokenshire@xestia.co.uk>         #
10 #                                                                               #
11 # This module is licensed under the same license as Xestia Scanner Server which #
12 # is licensed under the GPL version 3.                                          #
13 #                                                                               #
14 # This program is free software: you can redistribute it and/or modify          #
15 # it under the terms of the GNU General Public License as published by          #
16 # the Free Software Foundation, version 3 of the License.                       #
17 #                                                                               #
18 # This program is distributed in the hope that it will be useful,               #
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of                #
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 #
21 # GNU General Public License for more details.                                  #
22 #                                                                               #
23 # You should have received a copy of the GNU General Public License             #
24 # along with this program.  If not, see <http://www.gnu.org/licenses/>.         #
25 ################################################################################# 
27 use strict;                             # Throw errors if there's something wrong.
28 use warnings;                           # Write warnings to the HTTP Server Log file.
30 use utf8;
32 eval "use CGI::Lite";
34 if ($@){
35         print "Content-type: text/html;\r\n\r\n";
36         print "The CGI::Lite Perl Module is not installed. Please install CGI::Lite and then run this installation script again. CGI::Lite can be installed through CPAN.";
37         exit;
38 }
40 my $modperlenabled = 0;
41 my $installscriptname = "install-multiuser.cgi";
42 my $originstallscriptname = "install.cgi";
43 my $xestiascanscriptname = "xsdss.cgi";
44 my $language_selected = "en-GB";
46 my %xestiascan_config;
48 my $cssstyle = "
50 a {
51         color: #FFFFFF;
52 }
54 body {
55         margin: 0px; 
56         font-family: sans-serif; 
57         padding: 0px; 
58         font-size: 13px;
59         background-color: #402040;
60         color: #ffffff;
61         background-image: url('/images/xestiascan/pagebackground.png');
62         background-repeat: repeat-x;
63 }
65 select {
66         #font-size: 12px;
67         #padding: 3px;
68         #background-color: #408080;
69         #color: #FFFFFF;
70         #border-color: #102020;
71         #border-style: solid;
72         #border-width: 1px;
73         #padding: 3px;
74 }
76 td,table {
77         padding: 5px;
78         border-spacing: 0px;
79 }
81 .languagebar {
82         background-color: #204040;
83         vertical-align: top;
84 }
86 .languagebarselect {
87         text-align: right;
88         background-color: #204040;
89 }
91 .tablecellheader {
92         font-size: 12px;
93         background-color: #703570;      
94         font-weight: bold;
95         text-align: left;
96         background-image: url('/images/xestiascan/tabletop.png');
97         background-repeat: repeat-x;
98 }
100 .tabledata {
101         background-color: #603060;
104 .topbar {
105         padding: 3px;
106         background-color: #753575;
107         border-bottom-style: solid;
108         border-bottom-width: 1px;
109         border-bottom-color: #EE70EE;
110         text-align: right;
111         min-height: 17px;
112         background-image: url('/images/xestiascan/menutop.png');
113         background-repeat: repeat-x;
116 .title {
117         font-size: 16px;
118         font-weight: bold;
119         position: absolute;
120         text-align: left;
121         z-index: 0;
122         left: 0;
123         padding-left: 3px;
126 .pageheader {
127         font-size: 18px;
128         font-weight: bold;
131 .subheader {
132         font-size: 14px;
133         font-weight: bold;
136 .tablename {
138         background-color: #301530;
142 .pagespacing {
144         padding: 3px;
149 ";
151 # Default settings.
153 my $default_dbmodule            = "PostgreSQL";
154 my $default_server              = "localhost";
155 my $default_port                = "5432";
156 my $default_protocol            = "tcp";
157 my $default_name                = "database";
158 my $default_username            = "username";
159 my $default_prefix              = "xestiascan";
161 my $default_adminusername       = "Administrator";
162 my $default_adminpassword       = "Password";
164 my $query_lite = new CGI::Lite;
165 my $form_data = $query_lite->parse_form_data;
167 my ($xestiascan_lang, %xestiascan_lang);
169 $xestiascan_lang{"en-GB"}{"languagename"}       = "English (British)";
170         $xestiascan_lang{"en-GB"}{"testpass"}           = "OK";
171         $xestiascan_lang{"en-GB"}{"testfail"}           = "Error";
173         $xestiascan_lang{"en-GB"}{"invalidconfigfile"}          = "An error occured whilst reading the configuration file. It may be in an invalid format, missings or that no permissions are set! You will need to enter these details manually below.";
175         $xestiascan_lang{"en-GB"}{"generic"}                    = "An error occured which is not known to the Xestia Scanner Server multiuser installer.";
176         $xestiascan_lang{"en-GB"}{"invalidvariable"}            = "The variable given was invalid.";
177         $xestiascan_lang{"en-GB"}{"invalidvalue"}               = "The value given was invalid.";
178         $xestiascan_lang{"en-GB"}{"invalidutf8"}                = "The value given has does not contain valid UTF8.";
179         $xestiascan_lang{"en-GB"}{"invalidoption"}              = "The option given was invalid.";
180         $xestiascan_lang{"en-GB"}{"variabletoolong"}            = "The variable given is too long.";
181         $xestiascan_lang{"en-GB"}{"blankdirectory"}             = "The directory name given is blank.";
182         $xestiascan_lang{"en-GB"}{"invaliddirectory"}           = "The directory name given is invalid.";
183         $xestiascan_lang{"en-GB"}{"moduleblank"}                        = "The module filename given is blank.";
184         $xestiascan_lang{"en-GB"}{"moduleinvalid"}              = "The module filename given is invalid.";
186         $xestiascan_lang{"en-GB"}{"dbdirectorytoolong"}         = "The database directory name given is too long.";
187         $xestiascan_lang{"en-GB"}{"outputdirectorytoolong"}     = "The output directory name given is too long.";
188         $xestiascan_lang{"en-GB"}{"imagesuripathtoolong"}       = "The images URI path name given is too long.";
189         $xestiascan_lang{"en-GB"}{"dateformattoolong"}          = "The date format given is too long.";
190         $xestiascan_lang{"en-GB"}{"customdateformattoolong"}    = "The custom date format given is too long.";
191         $xestiascan_lang{"en-GB"}{"languagefilenametoolong"}    = "The language filename given is too long.";
193         $xestiascan_lang{"en-GB"}{"authmoduleinvalidpermissions"}       = "The authentication moudle has invalid file permissions set.";
195         $xestiascan_lang{"en-GB"}{"dateformatblank"}            = "The date format given was blank.";
196         $xestiascan_lang{"en-GB"}{"dateformatinvalid"}          = "The date format given is invalid.";
197         $xestiascan_lang{"en-GB"}{"languagefilenameinvalid"}    = "The language filename given is invalid.";
199         $xestiascan_lang{"en-GB"}{"dbdirectoryblank"}           = "The database directory name given is blank.";
200         $xestiascan_lang{"en-GB"}{"dbdirectoryinvalid"}         = "The database directory name given is invalid.";
202         $xestiascan_lang{"en-GB"}{"outputdirectoryblank"}       = "The output directory name given is blank.";
203         $xestiascan_lang{"en-GB"}{"outputdirectoryinvalid"}     = "The output directory name given is invalid.";
205         $xestiascan_lang{"en-GB"}{"textarearowblank"}           = "The text area row value given is blank.";
206         $xestiascan_lang{"en-GB"}{"textarearowtoolong"}         = "The text area row value given is too long.";
207         $xestiascan_lang{"en-GB"}{"textarearowinvalid"}         = "The text area row value given is invalid.";
209         $xestiascan_lang{"en-GB"}{"textareacolsblank"}          = "The text area columns value given is blank.";
210         $xestiascan_lang{"en-GB"}{"textareacolstoolong"}                = "The text area columns value given is too long.";
211         $xestiascan_lang{"en-GB"}{"textareacolsinvalid"}                = "The text area columns value given is invalid.";
213         $xestiascan_lang{"en-GB"}{"presmoduleblank"}            = "The presentation module name given is blank.";
214         $xestiascan_lang{"en-GB"}{"presmoduleinvalid"}          = "The presentation module name given is invalid.";
216         $xestiascan_lang{"en-GB"}{"authmoduleblank"}            = "The database module name given is blank.";
217         $xestiascan_lang{"en-GB"}{"dbmoduleinvalid"}            = "The database module name given is invalid.";
218  
219         $xestiascan_lang{"en-GB"}{"outputmoduleblank"}          = "The output module name given is blank.";
220         $xestiascan_lang{"en-GB"}{"outputmoduleinvalid"}                = "The output module name given is invalid.";
221  
222         $xestiascan_lang{"en-GB"}{"presmodulemissing"}          = "The presentation module with the filename given is missing.";
223         $xestiascan_lang{"en-GB"}{"outputmodulemissing"}                = "The output module with the filename given is missing.";
224         $xestiascan_lang{"en-GB"}{"authmodulemissing"}          = "The authentication module with the filename given is missing.";
225         $xestiascan_lang{"en-GB"}{"languagefilenamemissing"}    = "The language file with the filename given is missing.";
226  
227         $xestiascan_lang{"en-GB"}{"servernametoolong"}          = "The database server name given is too long.";
228         $xestiascan_lang{"en-GB"}{"servernameinvalid"}          = "The database server name given is invalid.";
229         $xestiascan_lang{"en-GB"}{"serverportnumbertoolong"}    = "The database server port number given is too long.";
230         $xestiascan_lang{"en-GB"}{"serverportnumberinvalidcharacters"}  = "The database server port number given contains invalid characters.";
231         $xestiascan_lang{"en-GB"}{"serverportnumberinvalid"}    = "The database server port number given is invalid.";
232         $xestiascan_lang{"en-GB"}{"serverprotocolnametoolong"}  = "The database server protocol name given is too long.";
233         $xestiascan_lang{"en-GB"}{"serverprotocolinvalid"}              = "The database server protocol name is invalid.";
234         $xestiascan_lang{"en-GB"}{"serverdatabasenametoolong"}  = "The database name given is too long.";
235         $xestiascan_lang{"en-GB"}{"serverdatabasenameinvalid"}  = "The database name given is invalid.";
236         $xestiascan_lang{"en-GB"}{"serverdatabaseusernametoolong"}      = "The database server username given is too long.";
237         $xestiascan_lang{"en-GB"}{"serverdatabaseusernameinvalid"}      = "The database server username given is invalid.";
238         $xestiascan_lang{"en-GB"}{"serverdatabasepasswordtoolong"}      = "The database server password is too long.";
239         $xestiascan_lang{"en-GB"}{"serverdatabasetableprefixtoolong"}   = "The database server table prefix given is too long.";
240         $xestiascan_lang{"en-GB"}{"serverdatabasetableprefixinvalid"}   = "The database server table prefix given is invalid.";
241         $xestiascan_lang{"en-GB"}{"createmodulestoolong"}       = "The create modules value given is too long.";
242         $xestiascan_lang{"en-GB"}{"createscannerstoolong"}      = "The create scanners value given is too long.";
243         $xestiascan_lang{"en-GB"}{"createsessionstoolong"}      = "The create sessions value given is too long.";
244         $xestiascan_lang{"en-GB"}{"createuserstoolong"}         = "The create users value given is too long.";
245         $xestiascan_lang{"en-GB"}{"forcerecreatetoolong"}       = "The force recreate value given is too long.";
246         $xestiascan_lang{"en-GB"}{"deleteinstalltoolong"}       = "The delete installer value given is too long.";
247         $xestiascan_lang{"en-GB"}{"deletemultiusertoolong"}     = "The delete multiuser installer value given is too long.";
249         $xestiascan_lang{"en-GB"}{"notmultiuser"}               = "The module given is not a multiuser module.";
251         $xestiascan_lang{"en-GB"}{"removeinstallscripttoolong"} = "The remove install script value given is too long.";
252         $xestiascan_lang{"en-GB"}{"cannotwriteconfigurationindirectory"}        = "The configuration file cannot be written because the directory the install script is running from has invalid permissions.";
253         $xestiascan_lang{"en-GB"}{"configurationfilereadpermissionsinvalid"}    = "The configuration that currently exists has invalid read permissions set.";
254         $xestiascan_lang{"en-GB"}{"configurationfilewritepermissionsinvalid"}   = "The configuration that currently exists has invalid write permissions set.";
256         $xestiascan_lang{"en-GB"}{"errormessagetext"}   = "Please press the back button on your browser or preform the command needed to return to the previous page.";
258         $xestiascan_lang{"en-GB"}{"switch"}             = "Switch";
259         $xestiascan_lang{"en-GB"}{"setting"}            = "Setting";
260         $xestiascan_lang{"en-GB"}{"value"}              = "Value";
261         $xestiascan_lang{"en-GB"}{"filename"}           = "Filename";
262         $xestiascan_lang{"en-GB"}{"module"}             = "Module";
263         $xestiascan_lang{"en-GB"}{"result"}             = "Result";
264         $xestiascan_lang{"en-GB"}{"error"}              = "Error!";
265         $xestiascan_lang{"en-GB"}{"criticalerror"}      = "Critical Error!";
266         $xestiascan_lang{"en-GB"}{"errormessage"}       = "Error: ";
267         $xestiascan_lang{"en-GB"}{"warningmessage"}     = "Warning: ";
269         $xestiascan_lang{"en-GB"}{"doesnotexist"}       = "Does not exist.";
270         $xestiascan_lang{"en-GB"}{"invalidpermissionsset"}      = "Invalid permissions set.";
272         $xestiascan_lang{"en-GB"}{"dependencyperlmodulesmissing"}       = "One or more Perl modules that are needed by Xestia Scanner Server are not installed or has problems. See the Xestia Scanner Server documentation for more information on this.";
273         $xestiascan_lang{"en-GB"}{"databaseperlmodulesmissing"} = "One or more Perl modules that are needed by the Xestia Scanner Server database modules are not installed or has problems. See the Xestia Scanner Server documentation for more information on this. There should however, be no problems with the database modules which use the Perl modules that have been found.";
274         $xestiascan_lang{"en-GB"}{"filepermissionsinvalid"}     = "One or more of the filenames checked does not exist or has invalid permissions set. See the Xestia Scanner Server documentation for more information on this.";
275         $xestiascan_lang{"en-GB"}{"dependencymodulesnotinstalled"}      = "One of the required Perl modules is not installed or has errors. See the Xestia Scanner Server documentation for more information on this.";
276         $xestiascan_lang{"en-GB"}{"databasemodulesnotinstalled"}        = "None of Perl modules that are used by the database modules are not installed. See the Xestia Scanner Server documentation for more information on this.";
277         $xestiascan_lang{"en-GB"}{"filepermissionerrors"}       = "One or more filenames checked has errors. See the Xestia Scanner Server documentation for more information on this.",
279         $xestiascan_lang{"en-GB"}{"installertitle"}     = "Xestia Scanner Server Multiuser Installer";
280         $xestiascan_lang{"en-GB"}{"installertext"}      = "This installer script will setup the user and session tables needed for your multiuser installation of Xestia Scanner Server. If you already have user or session tables then they will be skipped unless you have selected the recreate table checkbox.";
281         $xestiascan_lang{"en-GB"}{"modperlnotice"}      = "mod_perl has been detected. Please ensure that you have setup this script and the main Xestia Scanner Server script so that mod_perl can use Xestia Scanner Server properly. Please read the mod_perl specific part of Chapter 1: Installation in the Xestia Scanner Server documentation.";
282         $xestiascan_lang{"en-GB"}{"dependencytitle"}    = "Dependency and file testing results";
283         $xestiascan_lang{"en-GB"}{"requiredmodules"}    = "Required Modules";
284         $xestiascan_lang{"en-GB"}{"perlmodules"}                = "These Perl modules are used internally by Xestia Scanner Server.";
285         $xestiascan_lang{"en-GB"}{"databasemodules"}    = "Perl Database Modules";
286         $xestiascan_lang{"en-GB"}{"databasemodulestext"}        = "These Perl modules are used by the database modules.";
287         $xestiascan_lang{"en-GB"}{"filepermissions"}    = "File permissions";
288         $xestiascan_lang{"en-GB"}{"filepermissionstext"}        = "The file permissions are for file and directories that are critical to Xestia Scanner Server such as module and language directories.";
289         
290         $xestiascan_lang{"en-GB"}{"settingstitle"}      = "Xestia Scanner Server Settings";
291         $xestiascan_lang{"en-GB"}{"settingstext"}       = "The settings given here will be used by Xestia Scanner Server. Some default settings are given here. Certain database modules (like SQLite) do not need the database server settings and can be left alone.";
292         $xestiascan_lang{"en-GB"}{"directories"}                = "Directories";
293         $xestiascan_lang{"en-GB"}{"databasedirectory"}  = "Database Directory";
294         $xestiascan_lang{"en-GB"}{"outputdirectory"}    = "Output Directory";
295         $xestiascan_lang{"en-GB"}{"imagesuripath"}      = "Images (URI path)";
296         $xestiascan_lang{"en-GB"}{"display"}            = "Display";
297         $xestiascan_lang{"en-GB"}{"textareacols"}       = "Text Area Columns";
298         $xestiascan_lang{"en-GB"}{"textarearows"}       = "Text Area Rows";
299         $xestiascan_lang{"en-GB"}{"date"}               = "Date";
300         $xestiascan_lang{"en-GB"}{"dateformat"}         = "Date Format";
301         $xestiascan_lang{"en-GB"}{"language"}           = "Language";
302         $xestiascan_lang{"en-GB"}{"systemlanguage"}     = "System Language";
303         $xestiascan_lang{"en-GB"}{"modules"}            = "Modules";
304         $xestiascan_lang{"en-GB"}{"presentationmodule"} = "Presentation Module";
305         $xestiascan_lang{"en-GB"}{"outputmodule"}       = "Output Module";
306         $xestiascan_lang{"en-GB"}{"authsettings"}       = "Authentication Settings";
307         $xestiascan_lang{"en-GB"}{"authenticationmodule"}       = "Authentication Module";
308         $xestiascan_lang{"en-GB"}{"multiuseronly"}      = "Only multiuser-supported authentication modules are listed.";
309         $xestiascan_lang{"en-GB"}{"databaseserver"}     = "Database Server";
310         $xestiascan_lang{"en-GB"}{"databaseport"}       = "Database Port";
311         $xestiascan_lang{"en-GB"}{"databaseprotocol"}   = "Database Protocol";
312         $xestiascan_lang{"en-GB"}{"databasename"}       = "Database Name";
313         $xestiascan_lang{"en-GB"}{"databaseusername"}   = "Database Username";
314         $xestiascan_lang{"en-GB"}{"databasepassword"}   = "Database Password";
315         $xestiascan_lang{"en-GB"}{"databasetableprefix"}        = "Database Table Prefix";
316         $xestiascan_lang{"en-GB"}{"adminuseraccountsettings"}   = "Administrative User Account Settings";
317         $xestiascan_lang{"en-GB"}{"adminusername"}      = "Username:";
318         $xestiascan_lang{"en-GB"}{"adminpassword"}      = "Password:";
319         $xestiascan_lang{"en-GB"}{"installationoptions"}        = "Installation Options";
320         $xestiascan_lang{"en-GB"}{"installoptions"}     = "Install Options";
321         $xestiascan_lang{"en-GB"}{"installationoptions"}        = "Installation Options";
322         $xestiascan_lang{"en-GB"}{"createtables"} = "Create tables";
323         $xestiascan_lang{"en-GB"}{"createtablemodulepermissions"} = "Create the modules permissions table.";
324         $xestiascan_lang{"en-GB"}{"createtablescannerspermissions"} = "Create the scanners permissions table.";
325         $xestiascan_lang{"en-GB"}{"createtablesessions"} = "Create the sessions table.";
326         $xestiascan_lang{"en-GB"}{"createtableusers"} = "Create the users table.";
327         $xestiascan_lang{"en-GB"}{"forcerecreate"}      = "Force recreate";
328         $xestiascan_lang{"en-GB"}{"forcerecreatetables"}        = "Force recreation of the selected tables.";
329         $xestiascan_lang{"en-GB"}{"deleteinstallscripts"}       = "Delete install scripts";
330         $xestiascan_lang{"en-GB"}{"removeinstallscript"}        = "Delete the Xestia Scanner Server Installer script.";
331         $xestiascan_lang{"en-GB"}{"removemultiuserinstallscript"}       = "Delete the Xestia Scanner Server Multiuser Installer script.";
332         $xestiascan_lang{"en-GB"}{"recommendremoving"}  = "Deleting the installer scripts after you have finished using them is strongly recommended to secure your Xestia Scanner Server multiuser installation!";
333         $xestiascan_lang{"en-GB"}{"savesettingsbutton"} = "Save Settings";
334         $xestiascan_lang{"en-GB"}{"resetsettingsbutton"}        = "Reset Settings";
336         $xestiascan_lang{"en-GB"}{"adminaccountname"} = "Administrator";
337         $xestiascan_lang{"en-GB"}{"adminaccountpassword"} = "Password";
339         $xestiascan_lang{"en-GB"}{"installscriptkept"} = "Warning: The installer script has not been removed.";
340         $xestiascan_lang{"en-GB"}{"multiuserinstallscriptkept"} = "Warning: The multiuser installer script has not been removed.";
341         $xestiascan_lang{"en-GB"}{"multiuserscriptremoved"}     = "The multiuser installer script was removed.";
342         $xestiascan_lang{"en-GB"}{"installscriptremoved"}       = "The installer script was removed.";
343         $xestiascan_lang{"en-GB"}{"installedmessage"}   = "The configuration file for Xestia Scanner Server has been written. To change the settings in the configuration file at a later date use the Edit Settings link in the View Settings sub-menu at the top of the page when using Xestia Scanner Server.";
344         $xestiascan_lang{"en-GB"}{"cannotremovemultiuserinstallerscript"}       = "Unable to remove the multiuser installer script: %s. The multiuser installer script will have to be deleted manually.";
345         $xestiascan_lang{"en-GB"}{"cannotremoveinstallerscript"}        = "Unable to remove the installer script: %s. The installer script will have to be deleted manually.";
346         $xestiascan_lang{"en-GB"}{"usexestiascannerservertext"} = "To use Xestia Scanner Server click or select the link below (will not work if the Xestia Scanner Server script is not called xsdss.cgi):";
347         $xestiascan_lang{"en-GB"}{"usexestiascannerserverlink"} = "Start using Xestia Scanner Server";
349         $xestiascan_lang{"en-GB"}{"multiuserresults"} = "The multiuser installer has preformed the following actions:";
350         $xestiascan_lang{"en-GB"}{"forciblyrecreated"} = "The tables will be forcibly recreated.";
351         $xestiascan_lang{"en-GB"}{"notforciblyrecreated"} = "The tables will not be forcibly recreated.";
352         $xestiascan_lang{"en-GB"}{"modulestableerror"} = "An error occured while creating the permissions table for modules: ";
353         $xestiascan_lang{"en-GB"}{"modulestablesuccess"} = "The permissions table for modules was created successfully.";
354         $xestiascan_lang{"en-GB"}{"scannerstableerror"} = "An error occured while creating the permissions table for scanners: ";
355         $xestiascan_lang{"en-GB"}{"scannerstablesuccess"} = "The permissions table for scanners was created successfully.";
356         $xestiascan_lang{"en-GB"}{"sessionstableerror"} = "An error occured while creating the permissions table for scanners: ";
357         $xestiascan_lang{"en-GB"}{"sessionstablesuccess"} = "The sessions table was created successfully.";
358         $xestiascan_lang{"en-GB"}{"userstableerror"} = "An error occured while creating the permissions table for users: ";
359         $xestiascan_lang{"en-GB"}{"userstablesuccess"} = "The users table was created successfully.";
360         $xestiascan_lang{"en-GB"}{"adminaccounterror"} = "An error occured whilst trying to create the administrative account: ";
361         $xestiascan_lang{"en-GB"}{"adminaccountsuccess"} = "The administrative account was created successfully.";
363         $xestiascan_lang{"en-GB"}{"autherroroccured"} = "An error occured whilst using the authentication module: ";
366 #################################################################################
367 # Begin list of subroutines.                                                    #
368 #################################################################################
370 sub xestiascan_variablecheck{
371 #################################################################################
372 # xestiascan_variablecheck: Check to see if the data passed is valid.           #
373 #                                                                               #
374 # Usage:                                                                        #
375 #                                                                               #
376 # xestiascan_variablecheck(variablename, type, option, noerror);                #
377 #                                                                               #
378 # variablename  Specifies the variable to be checked.                           #
379 # type          Specifies what type the variable is.                            #
380 # option        Specifies the maximum/minimum length of the variable            #
381 #               (if minlength/maxlength is used) or if the filename should be   #
382 #               checked to see if it is blank.                                  #
383 # noerror       Specifies if Xestia Scanner Server should return an error or not#
384 #               on certain values.                                              #
385 #################################################################################
387         # Get the values that were passed to the subroutine.
389         my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
391         if ($variable_type eq "numbers"){
393                 # Check for numbers and return an error if there is anything else than numebrs.
395                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated.
396                 $variable_data_validated =~ tr/0-9//d;          # Take away all of the numbers and from the variable. 
397                                                                 # If it only contains numbers then it should be blank.
399                 if ($variable_data_validated eq ""){
400                         # The validated variable is blank. So continue to the end of this section where the return function should be.
401                 } else {
402                         # The variable is not blank, so check if the no error value is set
403                         # to 1 or not.
405                         if ($variable_noerror eq 1){
407                                 # The validated variable is not blank and the noerror
408                                 # value is set to 1. So return an value of 1.
409                                 # (meaning that the data is invalid).
411                                 return 1;
413                         } elsif ($variable_noerror eq 0) {
415                                 # The validated variable is not blank and the noerror
416                                 # value is set to 0.
418                                 xestiascan_error("invalidvariable");
420                         } else {
422                                 # The variable noerror value is something else
423                                 # pther than 1 or 0. So return an error.
425                                 xestiascan_error("invalidvariable");
427                         }
429                 }
431                 return 0;
433         } elsif ($variable_type eq "lettersnumbers"){
435                 # Check for letters and numbers and return an error if there is anything else other
436                 # than letters and numbers.
438                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated
439                 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
440                 $variable_data_validated =~ s/\s//g;
442                 if ($variable_data_validated eq ""){
443                         # The validated variable is blank. So continue to the end of this section where the return function should be.
444                 } else {
445                         # The variable is not blank, so check if the no error value is set
446                         # to 1 or not.
448                         if ($variable_noerror eq 1){
450                                 # The validated variable is not blank and the noerror
451                                 # value is set to 1. So return an value of 1.
452                                 # (meaning that the data is invalid).
454                                 return 1;
456                         } elsif ($variable_noerror eq 0) {
458                                 # The validated variable is not blank and the noerror
459                                 # value is set to 0.
461                                 xestiascan_error("invalidvariable");
463                         } else {
465                                 # The variable noerror value is something else
466                                 # pther than 1 or 0. So return an error.
468                                 xestiascan_error("invalidvariable");
470                         }
472                 }
474                 return 0;
476         } elsif ($variable_type eq "maxlength"){
477                 # Check for the length of the variable, return an error if it is longer than the length specified.
479                 # Check if the variable_data string is blank, if it is then set the variable_data_length
480                 # to '0'.
482                 my $variable_data_length = 0;
484                 if (!$variable_data){
486                         # Set variable_data_length to '0'.
487                         $variable_data_length = 0;
489                 } else {
491                         # Get the length of the variable recieved.
492                         $variable_data_length = length($variable_data);
494                 }
498                 if ($variable_data_length > $variable_option){
500                         # The variable length is longer than it should be so check if
501                         # the no error value is set 1.
503                         if ($variable_noerror eq 1){
505                                 # The no error value is set to 1, so return an
506                                 # value of 1 (meaning tha the variable is
507                                 # too long to be used).
509                                 return 1;
511                         } elsif ($variable_noerror eq 0){
513                                 # The no error value is set to 0, so return
514                                 # an error.
516                                 xestiascan_error("variabletoolong");
518                         } else {
520                                 # The no error value is something else other
521                                 # than 0 or 1, so return an error.
523                                 xestiascan_error("variabletoolong");
525                         }
527                 } else {
529                         # The variable length is exactly or shorter than specified, so continue to end of this section where
530                         # the return function should be.
532                 }
534                 return 0;
536         } elsif ($variable_type eq "datetime"){
537                 # Check if the date and time setting format is valid.
539                 if ($variable_data eq ""){
541                         if ($variable_noerror eq 1){
543                                 # The no error value is set to 1 so return
544                                 # a value of 1 (meaning that the date and
545                                 # time format was blank).
547                                 return 1;
549                         } elsif ($variable_noerror eq 0){
551                                 # The no error value is set to 1 so return
552                                 # an error.
554                                 xestiascan_error("dateformatblank");
556                         } else {
558                                 # The no error value is something else other
559                                 # than 0 or 1, so return an error.
561                                 xestiascan_error("invalidvariable");
563                         }
565                 }
567                 my $variable_data_validated = $variable_data;
568                 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
570                 if ($variable_data_validated eq ""){
572                         # The date and time format is valid. So
573                         # skip this bit.
575                 } else {
577                         # The validated data variable is not blank, meaning 
578                         # that it contains something else, so return an error
579                         # (or a value).
581                         if ($variable_noerror eq 1){
583                                 # The no error value is set to 1 so return
584                                 # an value of 2. (meaning that the date and
585                                 # time format was invalid).
587                                 return 2;
589                         } elsif ($variable_noerror eq 0){
591                                 # The no error value is set to 0 so return
592                                 # an error.
594                                 xestiascan_error("dateformatinvalid");
596                         } else {
598                                 # The no error value is something else other
599                                 # than 0 or 1 so return an error.
601                                 xestiascan_error("invalidvariable");
603                         }
605                 }
607                 return 0;
609         } elsif ($variable_type eq "directory"){
610                 # Check if the directory only contains letters and numbers and
611                 # return an error if anything else appears.
613                 my $variable_data_validated = $variable_data;
614                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
616                 if ($variable_data eq ""){
618                         if ($variable_noerror eq 1){
620                                 # The no error value is set to 1 so return
621                                 # a value of 1 (meaning that the directory
622                                 # name was blank).
624                                 return 1;
626                         } elsif ($variable_noerror eq 0){
628                                 # The no error value is set to 1 so return
629                                 # an error.
631                                 xestiascan_error("blankdirectory");
633                         } else {
635                                 # The no error value is something else other
636                                 # than 0 or 1, so return an error.
638                                 xestiascan_error("invalidvariable");
640                         }
642                 }
644                 if ($variable_data_validated eq ""){
646                         # The validated data variable is blank, meaning that
647                         # it only contains letters and numbers.
649                 } else {
651                         # The validated data variable is not blank, meaning 
652                         # that it contains something else, so return an error
653                         # (or a value).
655                         if ($variable_noerror eq 1){
657                                 # The no error value is set to 1 so return
658                                 # an value of 2. (meaning that the directory
659                                 # name is invalid).
661                                 return 2;
663                         } elsif ($variable_noerror eq 0){
665                                 # The no error value is set to 0 so return
666                                 # an error.
668                                 xestiascan_error("invaliddirectory");
670                         } else {
672                                 # The no error value is something else other
673                                 # than 0 or 1 so return an error.
675                                 xestiascan_error("invalidvariable");
677                         }
679                 }
681                 return 0;
683         } elsif ($variable_type eq "language_filename"){
685                 # The variable type is a language filename type.
686                 # Check if the language file name is blank and 
687                 # if it is then return an error (or value).
689                 if ($variable_data eq ""){
691                         # The language filename is blank so check the
692                         # no error value and return an error (or value).
694                         if ($variable_noerror eq 1){
696                                 # Language filename is blank and the no error value
697                                 # is set as 1, so return a value of 1 (saying that
698                                 # the language filename is blank).
700                                 return 1;
702                         } elsif ($variable_noerror eq 0) {
704                                 # Language filename is blank and the no error value
705                                 # is not set as 1, so return an error.
707                                 xestiascan_error("languagefilenameblank");
709                         } else {
711                                 # The noerror value is something else other
712                                 # than 0 or 1 so return an error.
714                                 xestiascan_error("invalidvariable");
716                         }
718                 }
720                 # Set the following variables for later on.
722                 my $variable_data_length = 0;
723                 my $variable_data_char = "";
724                 my $variable_data_seek = 0;
726                 # Get the length of the language file name.
728                 $variable_data_length = length($variable_data);
730                 do {
732                         # Get a character from the language filename passed to this 
733                         # subroutine and the character the seek counter value is set
734                         # to.
736                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
738                         # Check if the language filename contains a forward slash or a dot, 
739                         # if the selected character is a forward slash then return an error
740                         # (or value).
742                         if ($variable_data_char eq "/" || $variable_data_char eq "."){
744                                 # The language filename contains a forward slash or
745                                 # a dot so depending on the no error value, return
746                                 # an error or a value.
748                                 if ($variable_noerror eq 1){
750                                         # Language filename contains a forward slash or a dot
751                                         # and the no error value has been set to 1, so return 
752                                         # an value of 2 (saying that the language file name is 
753                                         # invalid).
755                                         return 2;
757                                 } elsif ($variable_noerror eq 0) {
759                                         # Language filename contains a forward slash and the no
760                                         # error value has not been set to 1, so return an error.
762                                         xestiascan_error("languagefilenameinvalid");
764                                 } else {
766                                         # The noerror value is something else other than
767                                         # 1 or 0 so return an error.
769                                         xestiascan_error("invalidvariable");
771                                 }
773                         }
775                         # Increment the seek counter.
777                         $variable_data_seek++;
779                 } until ($variable_data_seek eq $variable_data_length);
781                 return 0;
783         } elsif ($variable_type eq "module"){
785                 # The variable type is a presentation module filename.
787                 # Check if the variable_data is blank and if it is
788                 # return an error.
790                 if ($variable_data eq ""){
792                         # The presentation module is blank so check if an error
793                         # value should be returned or a number should be
794                         # returned.
796                         if ($variable_noerror eq 1){
798                                 # Module name is blank and the no error value 
799                                 # is set to 1 so return a value of 2 (meaning 
800                                 # that the page filename is blank).
802                                 return 1;
804                         } elsif ($variable_noerror eq 0) {
806                                 # Module name contains is blank and the no error 
807                                 # value is set to 0 so return an error.
809                                 xestiascan_critical("moduleblank");
811                         } else {
813                                 # The no error value is something else other
814                                 # than 0 or 1 so return an error.
816                                 xestiascan_critical("invalidvalue");
818                         }
820                 } else {
822                 }
824                 my $variable_data_validated = $variable_data;
825                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
827                 if ($variable_data_validated eq ""){
829                 } else {
831                         if ($variable_noerror eq 1){
833                                 # Module name contains invalid characters and
834                                 # the no error value is set to 1 so return a 
835                                 # value of 2 (meaning that the page filename
836                                 # is invalid).
838                                 return 2;
840                         } elsif ($variable_noerror eq 0) {
842                                 # Module name contains invalid characters and
843                                 # the no error value is set to 0 so return an
844                                 # error.
846                                 xestiascan_critical("moduleinvalid");
848                         } else {
850                                 # The no error value is something else other
851                                 # than 0 or 1 so return an error.
853                                 xestiascan_error("invalidvalue");
855                         }
857                 }
859                 return 0;
861         } elsif ($variable_type eq "serverprotocol"){
863                 # Check if the server protocol is TCP or UDP and return
864                 # an error if it isn't.
866                 if ($variable_data ne "tcp" && $variable_data ne "udp"){
868                         # The protocol given is not valid, check if the no
869                         # error value is set to 1 and return an error if it isn't.
871                         if ($variable_noerror eq 1){
873                                 # The no error value has been set to 1, so return a
874                                 # value of 1 (meaning that the server protocol is
875                                 # invalid).
877                                 return 1;
879                         } elsif ($variable_noerror eq 0){
881                                 # The no error value has been set to 0, so return
882                                 # an error.
884                                 xestiascan_error("serverprotocolinvalid");
886                         } else {
888                                 # The no error value is something else other than 0
889                                 # or 1, so return an error.
891                                 xestiascan_error("invalidoption");
893                         }
895                 }
897                 return 0;
899         } elsif ($variable_type eq "port"){
901                 # Check if the port number given is less than 0 or more than 65535
902                 # and return an error if it is.
904                 if ($variable_data < 0 || $variable_data > 65535){
906                         # The port number is less than 0 and more than 65535 so
907                         # check if the no error value is set to 1 and return an
908                         # error if it isn't.
910                         if ($variable_noerror eq 1){
912                                 # The no error value has been set to 1, so return a
913                                 # value of 1 (meaning that the port number is invalid).
915                                 return 1;
917                         } elsif ($variable_noerror eq 0){
919                                 # The no error value has been set to 0, so return
920                                 # an error.
922                                 xestiascan_error("serverportnumberinvalid");
924                         } else {
926                                 # The no error value is something else other than 0
927                                 # or 1, so return an error.
929                                 xestiascan_error("invalidoption");
931                         }
933                 }
935                 return 0;
937         } elsif ($variable_type eq "utf8"){
938                 
939                 # The variable type is a UTF8 string.
940                 
941                 if (!$variable_data){
942                         
943                         $variable_data = "";
944                         
945                 }
946                 
947                 my $chunk = 0;
948                 my $process = 8192;
949                 my $length = 0;
950                 my $chunkdata = "";
951                 
952                 while ($chunk < $length){
953                         
954                         $chunkdata = substr($variable_data, $chunk, $process);
955                         
956                         if ($chunkdata =~ m/\A(
957                                 [\x09\x0A\x0D\x20-\x7E]            # ASCII
958                                 | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
959                                 |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
960                                 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
961                         |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
962                         |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
963                         | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
964                         |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
965                         )*\z/x){
966                                 
967                                 # The UTF-8 string is valid.
968                                 
969                         } else {
970                                 
971                                 # The UTF-8 string is not valid, check if the no error
972                                 # value is set to 1 and return an error if it isn't.
973                                 
974                                 if ($variable_noerror eq 1){
975                                         
976                                         # The no error value has been set to 1, so return
977                                         # a value of 1 (meaning that the UTF-8 string is
978                                         # invalid).
979                                         
980                                         return 1; 
981                                         
982                                 } elsif ($variable_noerror eq 0) {
983                                         
984                                         # The no error value has been set to 0, so return
985                                         # an error.
986                                         
987                                         xestiascan_error("invalidutf8");
988                                         
989                                 } else {
990                                         
991                                         # The no error value is something else other than 0
992                                         # or 1, so return an error.
993                                         
994                                         xestiascan_error("invalidoption");
995                                         
996                                 }
997                                 
998                         }
999                         
1000                         
1001                         $chunk = $chunk + $process;
1002                         
1003                 }
1004                 
1005                 return 0;
1006                 
1007         }
1009         # Another type than the valid ones above has been specified so return an error specifying an invalid option.
1010         xestiascan_error("invalidoption");
1014 sub xestiascan_error{
1015 #################################################################################
1016 # xestiascan_error: Subroutine for processing error messages.                   #
1017 #                                                                               #
1018 # Usage:                                                                        #
1019 #                                                                               #
1020 # xestiascan_error(errortype);                                                  #
1021 #                                                                               #
1022 # errortype     Specifies the error type to use.                                #
1023 #################################################################################
1025         my $error_type = shift;
1027         # Load the list of error messages.
1029         my (%xestiascan_error, $xestiascan_error);
1031         %xestiascan_error = (
1033                 # Generic Error Messages
1035                 "generic"                       => $xestiascan_lang{$language_selected}{generic},
1037                 "invalidvariable"               => $xestiascan_lang{$language_selected}{invalidvariable},
1038                 "invalidvalue"                  => $xestiascan_lang{$language_selected}{invalidvalue},
1039                 "invalidoption"                 => $xestiascan_lang{$language_selected}{invalidoption},
1040                 "variabletoolong"               => $xestiascan_lang{$language_selected}{variabletoolong},
1041                 "blankdirectory"                => $xestiascan_lang{$language_selected}{blankdirectory},
1042                 "invaliddirectory"              => $xestiascan_lang{$language_selected}{invaliddirectory},
1043                 "moduleblank"                   => $xestiascan_lang{$language_selected}{moduleblank},
1044                 "moduleinvalid"                 => $xestiascan_lang{$language_selected}{moduleinvalid},
1046                 # Specific Error Messages
1048                 "dbdirectorytoolong"            => $xestiascan_lang{$language_selected}{dbdirectorytoolong},
1049                 "outputdirectorytoolong"        => $xestiascan_lang{$language_selected}{outputdirectorytoolong},
1050                 "imagesuripathtoolong"          => $xestiascan_lang{$language_selected}{imagesuripathtoolong},
1051                 "dateformattoolong"             => $xestiascan_lang{$language_selected}{dateformattoolong},
1052                 "customdateformattoolong"       => $xestiascan_lang{$language_selected}{customdateformattoolong},
1053                 "languagefilenametoolong"       => $xestiascan_lang{$language_selected}{languagefilenametoolong},
1054                 
1055                 "dateformatblank"               => $xestiascan_lang{$language_selected}{dateformatblank},
1056                 "dateformatinvalid"             => $xestiascan_lang{$language_selected}{dateformatinvalid},
1057                 "languagefilenameinvalid"       => $xestiascan_lang{$language_selected}{languagefilenameinvalid},
1058                 
1059                 "dbdirectoryblank"              => $xestiascan_lang{$language_selected}{dbdirectoryblank},
1060                 "dbdirectoryinvalid"            => $xestiascan_lang{$language_selected}{dbdirectoryinvalid},
1062                 "textarearowblank"              => $xestiascan_lang{$language_selected}{textarearowblank},
1063                 "textarearowtoolong"            => $xestiascan_lang{$language_selected}{textarearowtoolong},
1064                 "textarearowinvalid"            => $xestiascan_lang{$language_selected}{textarearowinvalid},
1066                 "textareacolsblank"             => $xestiascan_lang{$language_selected}{textareacolsblank},
1067                 "textareacolstoolong"           => $xestiascan_lang{$language_selected}{textareacolstoolong},
1068                 "textareacolsinvalid"           => $xestiascan_lang{$language_selected}{textareacolsinvalid},
1070                 "outputdirectoryblank"          => $xestiascan_lang{$language_selected}{outputdirectoryblank},
1071                 "outputdirectoryinvalid"        => $xestiascan_lang{$language_selected}{outputdirectoryinvalid},
1073                 "presmoduleblank"               => $xestiascan_lang{$language_selected}{presmoduleblank},
1074                 "presmoduleinvalid"             => $xestiascan_lang{$language_selected}{presmoduleinvalid},
1076                 "authmoduleblank"               => $xestiascan_lang{$language_selected}{authmoduleblank},
1077                 "authmoduleinvalid"             => $xestiascan_lang{$language_selected}{authmoduleinvalid},
1078                 "authmoduleinvalidpermissions"  => $xestiascan_lang{$language_selected}{authmoduleinvalidpermissions},
1080                 "presmodulemissing"             => $xestiascan_lang{$language_selected}{presmodulemissing},
1081                 "authmodulemissing"             => $xestiascan_lang{$language_selected}{authmodulemissing},
1082                 "languagefilenamemissing"       => $xestiascan_lang{$language_selected}{languagefilenamemissing},
1084                 "servernametoolong"             => $xestiascan_lang{$language_selected}{servernametoolong},
1085                 "servernameinvalid"             => $xestiascan_lang{$language_selected}{servernameinvalid},
1086                 "serverportnumbertoolong"       => $xestiascan_lang{$language_selected}{serverportnumbertoolong},
1087                 "serverportnumberinvalidcharacters"     => $xestiascan_lang{$language_selected}{serverportnumberinvalidcharacters},
1088                 "serverportnumberinvalid"       => $xestiascan_lang{$language_selected}{serverportnumberinvalid},
1089                 "serverprotocolnametoolong"     => $xestiascan_lang{$language_selected}{serverprotocolnametoolong},
1090                 "serverprotocolinvalid"         => $xestiascan_lang{$language_selected}{serverprotocolinvalid},
1091                 "serverdatabasenametoolong"     => $xestiascan_lang{$language_selected}{serverdatabasenametoolong},
1092                 "serverdatabasenameinvalid"     => $xestiascan_lang{$language_selected}{serverdatabasenameinvalid},
1093                 "serverdatabaseusernametoolong" => $xestiascan_lang{$language_selected}{serverdatabaseusernametoolong},
1094                 "serverdatabaseusernameinvalid" => $xestiascan_lang{$language_selected}{serverdatabaseusernameinvalid},
1095                 "serverdatabasepasswordtoolong" => $xestiascan_lang{$language_selected}{serverdatabasepasswordtoolong},
1096                 "serverdatabasetableprefixtoolong"      => $xestiascan_lang{$language_selected}{serverdatabasetableprefixtoolong},
1097                 "serverdatabasetableprefixinvalid"      => $xestiascan_lang{$language_selected}{serverdatabasetableprefixinvalid},
1098                 "createmodulestoolong"                  => $xestiascan_lang{$language_selected}{createmodulestoolong},
1099                 "createscannerstoolong"                 => $xestiascan_lang{$language_selected}{createscannerstoolong},
1100                 "createsessionstoolong"                 => $xestiascan_lang{$language_selected}{createsessionstoolong},
1101                 "createuserstoolong"                    => $xestiascan_lang{$language_selected}{createuserstoolong},
1102                 "forcerecreatetoolong"                  => $xestiascan_lang{$language_selected}{forcerecreatetoolong},
1103                 "deleteinstalltoolong"                  => $xestiascan_lang{$language_selected}{deleteinstalltoolong},
1104                 "deletemultiusertoolong"                => $xestiascan_lang{$language_selected}{deletemultiusertoolong},
1105         
1106                 "removeinstallscripttoolong"    => $xestiascan_lang{$language_selected}{removeinstallscripttoolong},
1107                 "cannotwriteconfigurationindirectory"   => $xestiascan_lang{$language_selected}{cannotwriteconfigurationindirectory},
1108                 "configurationfilereadpermissionsinvalid"       => $xestiascan_lang{$language_selected}{configurationfilereadpermissionsinvalid},
1109                 "configurationfilewritepermissionsinvalid"      => $xestiascan_lang{$language_selected}{configurationfilewritepermissionsinvalid},
1111         );
1113         # Check if the specified error is blank and if it is
1114         # use the generic error messsage.
1116         if (!$xestiascan_error{$error_type}){
1117                 $error_type = "generic";
1118         }
1120         print "Content-type: text/html; charset=utf-8;\r\n\r\n";
1122         print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
1123         print "<head>\n<title>$xestiascan_lang{$language_selected}{installertitle}</title>\n<style type=\"text/css\" media=\"screen\">$cssstyle</style>\n</head>\n<body>\n";
1125         print "<h2>$xestiascan_lang{$language_selected}{error}</h2>";
1127         print $xestiascan_error{$error_type};
1128         print "<br />\n";
1129         print $xestiascan_lang{$language_selected}{errormessagetext};
1131         print "</body>\n</html>";
1133         exit;
1137 sub xestiascan_processconfig{
1138 #################################################################################
1139 # xestiascan_processconfig: Processes an INI style configuration file.          #
1140 #                                                                               #
1141 # Usage:                                                                        #
1142 #                                                                               #
1143 # xestiascan_processconfig(data);                                               #
1144 #                                                                               #
1145 # data  Specifies the data to process.                                          #
1146 #################################################################################
1148         my (@settings) = @_;
1150         my ($settings_line, %settings, $settings, $sectionname, $setting_name, $setting_value);
1152         foreach $settings_line (@settings){
1154                 next if !$settings_line;
1156                 # Check if the first character is a bracket.
1158                 if (substr($settings_line, 0, 1) eq "["){
1159                         $settings_line =~ s/\[//;
1160                         $settings_line =~ s/\](.*)//;
1161                         $settings_line =~ s/\n//;
1162                         $sectionname = $settings_line;
1163                         next;
1164                 }
1166                 $setting_name  = $settings_line;
1167                 $setting_value = $settings_line;
1168                 $setting_name  =~ s/\=(.*)//;
1169                 $setting_name  =~ s/\n//;
1170                 $setting_value =~ s/(.*)\=//;
1171                 $setting_value =~ s/\n//;
1173                 # Remove the spacing before and after the '=' sign.
1175                 $setting_name =~ s/\s+$//;
1176                 $setting_value =~ s/^\s+//;
1177                 $setting_value =~ s/\r//;
1179                 $settings{$sectionname}{$setting_name} = $setting_value;
1181         }
1183         return %settings;
1187 sub xestiascan_fileexists{
1188         #################################################################################
1189         # xestiascan_fileexists: Check if a file exists and returns a value depending on #
1190         # if the file exists or not.                                                    #
1191         #                                                                               # 
1192         # Usage:                                                                        #
1193         #                                                                               #
1194         # xestiascan_fileexists(filename);                                              #
1195         #                                                                               #
1196         # filename      Specifies the file name to check if it exists or not.           #
1197         #################################################################################
1198         
1199         # Get the value that was passed to the subroutine.
1200         
1201         my ($filename) = @_;
1202         
1203         # Check if the filename exists, if it does, return a value of 0, else
1204         # return a value of 1, meaning that the file was not found.
1205         
1206         if (-e $filename){
1207                 
1208                 # Specified file does exist so return a value of 0.
1209                 
1210                 return 0;
1211                 
1212         } else {
1213                 
1214                 # Specified file does not exist so return a value of 1.
1215                 
1216                 return 1;
1217                 
1218         }
1219         
1222 sub xestiascan_filepermissions{
1223         #################################################################################
1224         # xestiascan_filepermissions: Check if the file permissions of a file and return #
1225         # either a 1 saying that the permissions are valid or return a 0 saying that    #
1226         # the permissions are invalid.                                                  #
1227         #                                                                               #
1228         # Usage:                                                                        #
1229         #                                                                               #
1230         # xestiascan_filepermissions(filename, [read], [write], [filemissingskip]);     #
1231         #                                                                               #
1232         # filename              Specifies the filename to check for permissions.        #
1233         # read                  Preform check that the file is readable.                #
1234         # write                 Preform check that the file is writeable.               #
1235         # filemissingskip       Skip the check of seeing if it can read or write if the #
1236         #                       file is missing.                                        #
1237         #################################################################################
1238         
1239         # Get the values that was passed to the subroutine.
1240         
1241         my ($filename, $readpermission, $writepermission, $ignorechecks) = @_;
1242         
1243         # Check to make sure that the read permission and write permission values
1244         # are only 1 character long.
1245         
1246         xestiascan_variablecheck($readpermission, "maxlength", 1, 0);
1247         xestiascan_variablecheck($writepermission, "maxlength", 1, 0);
1248         xestiascan_variablecheck($ignorechecks, "maxlength", 1, 0);
1249         
1250         my $ignorechecks_result = 0;
1251         
1252         # Check if the file should be ignored for read and write checking if 
1253         # it doesn't exist.
1254         
1255         if ($ignorechecks){
1256                 
1257                 if (-e $filename){
1258                         
1259                         # The file exists so the checks are to be done.
1260                         
1261                         $ignorechecks_result = 0;
1262                         
1263                 } else {
1264                         
1265                         # The file does not exist so the checks don't need to
1266                         # be done to prevent false positives.
1267                         
1268                         $ignorechecks_result = 1;
1269                         
1270                 }
1271                 
1272         } else {
1273                 
1274                 $ignorechecks_result = 0;
1275                 
1276         }
1277         
1278         # Check if the file should be checked to see if it can be read.
1279         
1280         if ($readpermission && $ignorechecks_result eq 0){
1281                 
1282                 # The file should be checked to see if it does contain read permissions
1283                 # and return a 0 if it is invalid.
1284                 
1285                 if (-r $filename){
1286                         
1287                         # The file is readable, so do nothing.
1288                         
1289                 } else {
1290                         
1291                         # The file is not readable, so return 1.
1292                         
1293                         return 1;
1294                         
1295                 }
1296                 
1297         }
1298         
1299         # Check if the file should be checked to see if it can be written.
1300         
1301         if ($writepermission && $ignorechecks_result eq 0){
1302                 
1303                 # The file should be checked to see if it does contain write permissions
1304                 # and return a 0 if it is invalid.
1305                 
1306                 if (-w $filename){
1307                         
1308                         # The file is writeable, so do nothing.
1309                         
1310                 } else {
1311                         
1312                         # The file is not writeable, so return 1.
1313                         
1314                         return 1;
1315                         
1316                 }
1317                 
1318         }
1319         
1320         # No problems have occured, so return 0.
1321         
1322         return 0;
1323         
1326 sub xestiascan_settings_load{
1327 #################################################################################
1328 # xestiascan_settings_load: Load the configuration settings into the global     #
1329 # variables.                                                                    #
1330 #                                                                               #
1331 # Usage:                                                                        #
1332 #                                                                               #
1333 # xestiascan_settings_load();                                                   #
1334 #################################################################################
1336         # Check if the Xestia Scanner Server configuration file exists before using it and
1337         # return an critical error if it doesn't exist.
1339         my ($xestiascan_settingsfilehandle, @config_data, %config, $config);
1340         my $xestiascan_conf_exist = xestiascan_fileexists("xsdss.cfg");
1342         if ($xestiascan_conf_exist eq 1){
1344                 # The configuration really does not exist so return an critical error.
1345                 
1346                 return 1;
1348         }
1349         
1350         # Check if the Xestia Scanner Server configuration file has valid permission settings
1351         # before using it and return an critical error if it doesn't have the
1352         # valid permission settings.
1354         my $xestiascan_conf_permissions = xestiascan_filepermissions("xsdss.cfg", 1, 0);
1356         if ($xestiascan_conf_permissions eq 1){
1358                 # The permission settings for the Xestia Scanner Server configuration file are
1359                 # invalid, so return an critical error.
1360                 
1361                 return 1;
1363         }
1365         # Converts the file into meaningful data for later on in this subroutine.
1367         my $xestiascan_conf_file = 'xsdss.cfg';
1369         open($xestiascan_settingsfilehandle, $xestiascan_conf_file);
1370         binmode $xestiascan_settingsfilehandle, ':utf8';
1371         @config_data = <$xestiascan_settingsfilehandle>;
1372         %config = xestiascan_processconfig(@config_data);
1373         close($xestiascan_settingsfilehandle);
1375         # Go and fetch the settings and place them into a hash.
1376         
1377         %xestiascan_config = (
1379                 "system_language"               => $config{config}{system_language},
1380                 "system_presmodule"             => $config{config}{system_presmodule},
1381                 "system_authmodule"             => $config{config}{system_authmodule},
1382                 "system_outputmodule"           => $config{config}{system_outputmodule},
1383                 "system_datetime"               => $config{config}{system_datetime},
1384                 
1385                 "database_server"               => $config{config}{database_server},
1386                 "database_port"                 => $config{config}{database_port},
1387                 "database_protocol"             => $config{config}{database_protocol},
1388                 "database_sqldatabase"          => $config{config}{database_sqldatabase},
1389                 "database_username"             => $config{config}{database_username},
1390                 "database_password"             => $config{config}{database_password},
1391                 "database_tableprefix"          => $config{config}{database_tableprefix}
1393         );
1395         # Do a validation check on all of the variables that were loaded into the global configuration hash.
1397         my $xestiascan_config_dbmodule_filename = xestiascan_variablecheck($xestiascan_config{"system_authmodule"}, "module", 0, 1);
1399         # Check if the database module name is valid.
1401         if ($xestiascan_config_dbmodule_filename eq 1){
1403                 # The database module filename given is blank so return.
1404                 
1405                 return 1;
1407         }
1409         if ($xestiascan_config_dbmodule_filename eq 2){
1411                 # The database module filename given is invalid so return
1412                 # an critical error.
1414                 return 1;
1416         }
1418         # Check if the database module does exist before loading it and return an critical error
1419         # if the database module does not exist.
1421         my $xestiascan_config_dbmodule_fileexists = xestiascan_fileexists("Modules/Auth/" . $xestiascan_config{"system_authmodule"} . ".pm");
1423         if ($xestiascan_config_dbmodule_fileexists eq 1){
1425                 # Database module does not exist so return an critical error.
1426                 
1427                 return 1;
1429         }
1431         # Check if the database module does have the valid permission settings and return an
1432         # critical error if the database module contains invalid permission settings.
1434         my $xestiascan_config_dbmodule_permissions = xestiascan_filepermissions("Modules/Auth/" . $xestiascan_config{"system_authmodule"} . ".pm", 1, 0);
1436         if ($xestiascan_config_dbmodule_permissions eq 1){
1438                 # Presentation module contains invalid permissions so return an critical error.
1439                 
1440                 return 1;
1442         }
1443         
1444         return 0;
1448 sub xestiascan_addtablerow{
1449 #################################################################################
1450 # xestiascan_addtablerow: Adds a table row.                                     #
1451 #                                                                               #
1452 # Usage:                                                                        #
1453 #                                                                               #
1454 # xestiascan_addtablerow(name, data);                                           #
1455 #                                                                               #
1456 # name          Specifies the name of the table row.                            #
1457 # namestyle     Specifies the style for the name of the table row.              #
1458 # data          Specifies the data to be used in the table row.                 #
1459 # datastyle     Specifies the style for the data of the table row.              #
1460 #################################################################################
1462         my ($name, $namestyle, $data, $datastyle) = @_;
1464         if (!$data){
1466                 $data = "";
1468         }
1470         print "<tr>\n";
1471         print "<td class=\"$namestyle\">$name</td>\n";
1472         print "<td class=\"$datastyle\">$data</td>\n";
1473         print "</tr>\n";
1477 #################################################################################
1478 # End list of subroutines.                                                      #
1479 #################################################################################
1481 # Process the list of available languages.
1483 my $language_list_name;
1484 my @language_list_short;
1485 my @language_list_long;
1487 foreach my $language (keys %xestiascan_lang){
1489         $language_list_name = $xestiascan_lang{$language}{"languagename"} . " (" . $language .  ")";
1490         push(@language_list_short, $language);
1491         push(@language_list_long, $language_list_name);
1495 my $http_query_confirm = $form_data->{'confirm'};
1497 $http_query_confirm = 0 if !$http_query_confirm;
1499 if ($http_query_confirm eq 1){
1501         # The action to create the tables has been confirmed. Get
1502         # the required values.
1503         
1504         my $http_query_authmodule       = $form_data->{'authmodule'};
1505         
1506         my $http_query_databaseserver   = $form_data->{'databaseserver'};
1507         my $http_query_databaseport     = $form_data->{'databaseport'};
1508         my $http_query_databaseprotocol = $form_data->{'databaseprotocol'};
1509         my $http_query_databasename     = $form_data->{'databasename'};
1510         my $http_query_databaseusername = $form_data->{'databaseusername'};
1511         my $http_query_databasepassword = $form_data->{'databasepassword'};
1512         my $http_query_databasetableprefix      = $form_data->{'databasetableprefix'};
1513         
1514         my $http_query_adminusername    = $form_data->{'multiuseradminusername'};
1515         my $http_query_adminpassword    = $form_data->{'multiuseradminpassword'};
1516         
1517         my $http_query_createmodules    = $form_data->{'createmodules'};
1518         my $http_query_createscanners   = $form_data->{'createscanners'};
1519         my $http_query_createsessions   = $form_data->{'createsessions'};
1520         my $http_query_createusers      = $form_data->{'createusers'};
1521         
1522         my $http_query_forcerecreate    = $form_data->{'forcerecreate'};
1523         
1524         my $http_query_deleteinstall    = $form_data->{'deleteinstall'};
1525         my $http_query_deletemultiuser  = $form_data->{'deleteinstallmultiuser'};
1526         
1527         # Check the data that has been passed to the multiuser installer.
1528         
1529         if (!$http_query_createmodules){
1530                 
1531                 $http_query_createmodules = "off";
1532                 
1533         }
1535         if (!$http_query_createscanners){
1536                 
1537                 $http_query_createscanners = "off";
1538                 
1539         }
1541         if (!$http_query_createsessions){
1542                 
1543                 $http_query_createsessions = "off";
1544                 
1545         }
1546         
1547         if (!$http_query_createusers){
1548                 
1549                 $http_query_createusers = "off";
1550                 
1551         }
1552         
1553         if (!$http_query_forcerecreate){
1554                 
1555                 $http_query_forcerecreate = "off";
1556                 
1557         }
1558         
1559         if (!$http_query_deleteinstall){
1560         
1561                 $http_query_deleteinstall = "off";
1562                 
1563         }
1564         
1565         if (!$http_query_deletemultiuser){
1566                 
1567                 $http_query_deletemultiuser = "off";
1568                 
1569         }
1570         
1571         my $xestiascan_authmodule_modulename_check              = xestiascan_variablecheck($http_query_authmodule, "module", 0, 1);
1572         my $xestiascan_databaseserver_length_check              = xestiascan_variablecheck($http_query_databaseserver, "maxlength", 128, 1);
1573         my $xestiascan_databaseserver_lettersnumbers_check      = xestiascan_variablecheck($http_query_databaseserver, "lettersnumbers", 0, 1);
1574         my $xestiascan_databaseport_length_check                = xestiascan_variablecheck($http_query_databaseport, "maxlength", 5, 1);
1575         my $xestiascan_databaseport_numbers_check               = xestiascan_variablecheck($http_query_databaseport, "numbers", 0, 1);
1576         my $xestiascan_databaseport_port_check                  = xestiascan_variablecheck($http_query_databaseport, "port", 0, 1);
1577         my $xestiascan_databaseprotocol_length_check            = xestiascan_variablecheck($http_query_databaseprotocol, "maxlength", 5, 1);
1578         my $xestiascan_databaseprotocol_protocol_check          = xestiascan_variablecheck($http_query_databaseprotocol, "serverprotocol", 0, 1);
1579         my $xestiascan_databasename_length_check                = xestiascan_variablecheck($http_query_databasename, "maxlength", 32, 1);
1580         my $xestiascan_databasename_lettersnumbers_check        = xestiascan_variablecheck($http_query_databasename, "lettersnumbers", 0, 1);
1581         my $xestiascan_databaseusername_length_check            = xestiascan_variablecheck($http_query_databaseusername, "maxlength", 16, 1);
1582         my $xestiascan_databaseusername_lettersnumbers_check    = xestiascan_variablecheck($http_query_databaseusername, "lettersnumbers", 0, 1);
1583         my $xestiascan_databasepassword_length_check            = xestiascan_variablecheck($http_query_databasepassword, "maxlength", 64, 1);
1584         my $xestiascan_databasetableprefix_length_check         = xestiascan_variablecheck($http_query_databasetableprefix, "maxlength", 16, 1);
1585         my $xestiascan_databasetableprefix_lettersnumbers_check = xestiascan_variablecheck($http_query_databasetableprefix, "lettersnumbers", 0, 1);
1586         
1587         if ($xestiascan_authmodule_modulename_check eq 1){
1588                 
1589                 # The database module name is blank, so return
1590                 # an error.
1591                 
1592                 xestiascan_error("authmoduleblank");
1593                 
1594         }
1595         
1596         if ($xestiascan_authmodule_modulename_check eq 2){
1597                 
1598                 # The database module name is invalid, so return
1599                 # an error.
1600                 
1601                 xestiascan_error("authmoduleinvalid");
1602                 
1603         }
1604         
1605         if (!-e "Modules/Auth/" . $http_query_authmodule . ".pm"){
1606                 
1607                 # The database module is missing so return an
1608                 # error.
1609                 
1610                 xestiascan_error("authmodulemissing");
1611                 
1612         }
1613         
1614         if ($xestiascan_databaseserver_length_check eq 1){
1615                 
1616                 # The length of the database server name is too long so
1617                 # return an error.
1618                 
1619                 xestiascan_error("servernametoolong");
1620                 
1621         }
1622         
1623         if ($xestiascan_databaseserver_lettersnumbers_check eq 1){
1624                 
1625                 # The database server name contains characters other
1626                 # than letters and numbers, so return an error.
1627                 
1628                 xestiascan_error("servernameinvalid");
1629                 
1630         }
1631         
1632         if ($xestiascan_databaseport_length_check eq 1){
1633                 
1634                 # The database port number length is too long so return
1635                 # an error.
1636                 
1637                 xestiascan_error("serverportnumbertoolong");
1638                 
1639         }
1640         
1641         if ($xestiascan_databaseport_numbers_check eq 1){
1642                 
1643                 # The database port number contains characters other
1644                 # than numbers so return an error.
1645                 
1646                 xestiascan_error("serverportnumberinvalidcharacters");
1647                 
1648         }
1649         
1650         if ($xestiascan_databaseport_port_check eq 1){
1651                 
1652                 # The database port number given is invalid so return
1653                 # an error.
1654                 
1655                 xestiascan_error("serverportnumberinvalid");
1656                 
1657         }
1658         
1659         if ($xestiascan_databaseprotocol_length_check eq 1){
1660                 
1661                 # The database protocol name given is too long so
1662                 # return an error.
1663                 
1664                 xestiascan_error("serverprotocolnametoolong");
1665                 
1666         }
1667         
1668         if ($xestiascan_databaseprotocol_protocol_check eq 1){
1669                 
1670                 # The server protcol given is invalid so return
1671                 # an error.
1672                 
1673                 xestiascan_error("serverprotocolinvalid");
1674                 
1675         }
1676         
1677         if ($xestiascan_databasename_length_check eq 1){
1678                 
1679                 # The SQL database name is too long so return
1680                 # an error.
1681                 
1682                 xestiascan_error("serverdatabasenametoolong");
1683                 
1684         }
1685         
1686         if ($xestiascan_databasename_lettersnumbers_check eq 1){
1687                 
1688                 # The database name contains invalid characters
1689                 # so return an error.
1690                 
1691                 xestiascan_error("serverdatabasenameinvalid");
1692                 
1693         }
1694         
1695         if ($xestiascan_databaseusername_length_check eq 1){
1696                 
1697                 # The database username given is too long so
1698                 # return an error.
1699                 
1700                 xestiascan_error("serverdatabaseusernametoolong");
1701                 
1702         }
1703         
1704         if ($xestiascan_databaseusername_lettersnumbers_check eq 1){
1705                 
1706                 # The database username contains invalid characters
1707                 # so return an error.
1708                 
1709                 xestiascan_error("serverdatabaseusernameinvalid");
1710                 
1711         }
1712         
1713         if ($xestiascan_databasepassword_length_check eq 1){
1714                 
1715                 # The database password given is too long so return
1716                 # an error.
1717                 
1718                 xestiascan_error("serverdatabasepasswordtoolong");
1719                 
1720         }
1721         
1722         if ($xestiascan_databasetableprefix_length_check eq 1){
1723                 
1724                 # The database table prefix given is too long so
1725                 # return an error.
1726                 
1727                 xestiascan_error("serverdatabasetableprefixtoolong");
1728                 
1729         }
1730         
1731         if ($xestiascan_databasetableprefix_lettersnumbers_check eq 1){
1732                 
1733                 # The database table prefix given contains invalid
1734                 # characters so return an error.
1735                 
1736                 xestiascan_error("serverdatabasetableprefixinvalid");
1737                 
1738         }
1739         
1740         # Check the admin username and password to make sure they have valid UTF-8.
1742         xestiascan_variablecheck($http_query_adminusername, "utf8", 0, 0);
1743         xestiascan_variablecheck($http_query_adminpassword, "utf8", 0, 0);
1744         
1745         # Check the checkable values.
1746         
1747         my $xestiascan_createmodules_length_check               = xestiascan_variablecheck($http_query_createmodules, "maxlength", 3, 1);
1748         my $xestiascan_createscanners_length_check              = xestiascan_variablecheck($http_query_createscanners, "maxlength", 3, 1);
1749         my $xestiascan_createsessions_length_check              = xestiascan_variablecheck($http_query_createsessions, "maxlength", 3, 1);
1750         my $xestiascan_createusers_length_check                 = xestiascan_variablecheck($http_query_createusers, "maxlength", 3, 1);
1751         my $xestiascan_forcerecreate_length_check               = xestiascan_variablecheck($http_query_forcerecreate, "maxlength", 3, 1);
1752         my $xestiascan_deleteinstall_length_check               = xestiascan_variablecheck($http_query_deleteinstall, "maxlength", 3, 1);
1753         my $xestiascan_deletemultiuser_length_check             = xestiascan_variablecheck($http_query_deletemultiuser, "maxlength", 3, 1);
1754         
1755         if ($xestiascan_createmodules_length_check eq 1){
1756                 
1757                 xestiascan_error("createmodulestoolong");
1758                 
1759         }
1760         
1761         if ($xestiascan_createscanners_length_check eq 1){
1762         
1763                 xestiascan_error("createscannerstoolong");
1764                 
1765         }
1766         
1767         if ($xestiascan_createsessions_length_check eq 1){
1769                 xestiascan_error("createsessionstoolong");
1770                 
1771         }
1772         
1773         if ($xestiascan_createusers_length_check eq 1){
1774         
1775                 xestiascan_error("createuserstoolong");
1776                 
1777         }
1778         
1779         if ($xestiascan_forcerecreate_length_check eq 1){
1781                 xestiascan_error("forcerecreatetoolong");
1782                 
1783         }
1784         
1785         if ($xestiascan_deleteinstall_length_check eq 1){
1786                 
1787                 xestiascan_error("deleteinstalltoolong");
1788                 
1789         }
1790         
1791         if ($xestiascan_deletemultiuser_length_check eq 1){
1792                 
1793                 xestiascan_error("deletemultiusertoolong");
1794                 
1795         }
1796         
1797         # Check to see if the tables need to be recreated forcibly.
1798         
1799         my $forcerecreate = 0;
1800         
1801         if ($http_query_forcerecreate eq "on"){
1802                 
1803                 $forcerecreate = 1;
1804                 
1805         }
1806         
1807         # Load the authentication module. Double check to make sure
1808         # it really is a multiuser module and throw an error if not.
1809         
1810         my $authmodule_fullname = "Auth::" . $http_query_authmodule;
1811         ($authmodule_fullname) = $authmodule_fullname =~ m/^(.*)$/g; # CHECK THIS!!
1812         eval "use " . $authmodule_fullname;
1813         $authmodule_fullname = "Modules::Auth::" . $http_query_authmodule;
1814         my $authmodule = $authmodule_fullname->new();
1815         
1816         my %authmodule_capabilities = $authmodule->capabilities();
1817         
1818         if ($authmodule_capabilities{'multiuser'} ne 1){
1819         
1820                 # Return an error, this module is not a multiuser module.
1821                 
1822                 xestiascan_error("notmultiuser");
1823                 
1824         }
1825         
1826         # Check if password value is blank and load settings files
1827         # if this is the case.
1828         
1829         if (!$http_query_databasepassword){
1830                 
1831                 if (xestiascan_settings_load eq 0){
1832                         
1833                         $http_query_databasepassword = $xestiascan_config{"database_password"};
1834                         
1835                 }
1836                 
1837         }
1838         
1839         # Load the settings for the database server.
1840         
1841         $authmodule->loadsettings({ DateTime => "DD/MM/YY hh:mm:ss", Server => $http_query_databaseserver, Port => $http_query_databaseport, Protocol => $http_query_databaseprotocol, Database => $http_query_databasename, Username => $http_query_databaseusername, Password => $http_query_databasepassword, TablePrefix => $http_query_databasetableprefix });
1842         
1843         # Connect to the database server.
1844         
1845         $authmodule->connect();
1847         if ($authmodule->geterror eq "AuthConnectionError"){
1848                 
1849                 # A database connection error has occured so return
1850                 # an error.
1851                 
1852                 print "Content-Type: text/html; charset=utf-8;\r\n\r\n";
1853                 print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
1854                 print "<head>\n<title>$xestiascan_lang{$language_selected}{installertitle}</title>\n";
1855                 print "<style type=\"text/css\" media=\"screen\">$cssstyle</style>\n</head>\n<body>";
1856                 
1857                 print "<div class=\"topbar\">
1858                 <span class=\"title\">" . $xestiascan_lang{$language_selected}{installertitle} .  "</span>";
1859                 print "</div>"; 
1860                 
1861                 print "<div class=\"pagespacing\">";
1862                 print $xestiascan_lang{$language_selected}{autherroroccured} . $authmodule->geterror(1);
1863                 print "</div>";
1864                 
1865                 exit;
1866                 
1867         }
1869         # Print the header part.
1870         
1871         print "Content-type: text/html; charset=utf-8;\r\n\r\n";
1872         
1873         print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
1874         print "<head>\n<title>$xestiascan_lang{$language_selected}{installertitle}</title>\n";
1875         print "<style type=\"text/css\" media=\"screen\">$cssstyle</style>\n</head>\n<body>";
1877         print "<div class=\"topbar\">
1878         <span class=\"title\">" . $xestiascan_lang{$language_selected}{installertitle} .  "</span>";
1879         print "</div>"; 
1880         
1881         print "<div class=\"pagespacing\">\n";
1882         print "<span class=\"pageheader\">$xestiascan_lang{$language_selected}{installertitle}</span><br /><br />\n";
1883         
1884         print $xestiascan_lang{$language_selected}{multiuserresults} . "<br /><br />";
1885         
1886         # Create/Recreate the tables as needed.
1887         
1888         if ($forcerecreate eq 1){
1889         
1890                 print $xestiascan_lang{$language_selected}{forciblyrecreated};
1891                 
1892         } else {
1893         
1894                 print $xestiascan_lang{$language_selected}{notforciblyrecreated};
1895                 
1896         }
1897         
1898         print "<br /><br />";
1899         
1900         # Create/Recreate the modules permissions table.
1901         
1902         if ($http_query_createmodules eq "on"){
1903         
1904                 $authmodule->populatetables("modules", $forcerecreate);
1905         
1906                 if ($authmodule->geterror eq "DatabaseError"){
1907                 
1908                         print $xestiascan_lang{$language_selected}{modulestableerror} . $authmodule->geterror(1) . "<br />";    
1909         
1910                 } else {
1911                         
1912                         print $xestiascan_lang{$language_selected}{modulestablesuccess} . "<br />";
1913                         
1914                 }
1915                         
1916         }
1917                 
1918         # Create/Recreate the scanners permissions table.
1920         if ($http_query_createscanners eq "on"){
1921         
1922                 $authmodule->populatetables("scanners", $forcerecreate);
1924                 if ($authmodule->geterror eq "DatabaseError"){
1925                 
1926                         print $xestiascan_lang{$language_selected}{scannerstableerror} . $authmodule->geterror(1) . "<br />";   
1927         
1928                 } else {
1929                 
1930                         print $xestiascan_lang{$language_selected}{scannerstablesuccess} . "<br />";
1931                         
1932                 }
1933                         
1934         }
1935                 
1936         # Create/Recreate the sessions permissions table.
1938         if ($http_query_createsessions eq "on"){
1939         
1940                 $authmodule->populatetables("sessions", $forcerecreate);
1941                 
1942                 if ($authmodule->geterror eq "DatabaseError"){
1943                 
1944                         print $xestiascan_lang{$language_selected}{sessionstableerror} . $authmodule->geterror(1) . "<br />";
1945                         
1946                 } else {
1947                         
1948                         print $xestiascan_lang{$language_selected}{sessionstablesuccess} . "<br />";
1949                         
1950                 }
1951                 
1952         }
1953         
1954         # Create/Recreate the users table.
1955         
1956         if ($http_query_createusers eq "on"){
1957         
1958                 $authmodule->populatetables("users", $forcerecreate);
1959                 
1960                 if ($authmodule->geterror eq "DatabaseError"){
1961                         
1962                         print $xestiascan_lang{$language_selected}{userstableerror} . $authmodule->geterror(1) . "<br />";
1963                         
1964                 } else {
1965                         
1966                         print $xestiascan_lang{$language_selected}{userstablesuccess} . "<br />";
1967                 
1968                         # Since the users table was created, add the Administrative account.
1969                         
1970                         my (%userinfo, $userinfo);
1971                         
1972                         $userinfo{Username} = $http_query_adminusername;
1973                         $userinfo{Name} = "Administrator";
1974                         $userinfo{Password} = $http_query_adminpassword; 
1975                         $userinfo{Enabled} = "on";
1976                         $userinfo{Admin} = "on";
1977                         
1978                         $authmodule->adduser($http_query_adminusername, %userinfo);
1979                         
1980                         if ($authmodule->geterror eq "DatabaseError"){
1981                         
1982                                 print $xestiascan_lang{$language_selected}{adminaccounterror} . $authmodule->geterror(1) . "<br />";
1983                                 
1984                         } else {
1985                                 
1986                                 print $xestiascan_lang{$language_selected}{adminaccountsuccess} . "<br />";
1987                                 
1988                         }
1989                         
1990                 }
1991                 
1992         }
1993         
1994         print "<br />";
1996         # Check if the scripts need deleting.
1997         
1998         my $installscriptmessage;
1999         
2000         if ($http_query_deleteinstall eq "on"){
2001                 
2002                 if (unlink($originstallscriptname)){
2003                         
2004                         print $xestiascan_lang{$language_selected}{installscriptremoved} . "<br />";
2005                         
2006                 } else {
2008                         $installscriptmessage = $xestiascan_lang{$language_selected}{cannotremoveinstallerscript};
2009                         $installscriptmessage =~ s/%s/$!/g;
2010                         
2011                         print $installscriptmessage . "<br />";
2012                         
2013                 }
2014                 
2015         } else {
2016         
2017                 print $xestiascan_lang{$language_selected}{installscriptkept} . "<br />";
2018                 
2019         }
2020         
2021         if ($http_query_deletemultiuser eq "on"){
2022                 
2023                 if (unlink($installscriptname)){
2024                 
2025                         print $xestiascan_lang{$language_selected}{multiuserscriptremoved} . "<br />";  
2026                         
2027                 } else {
2028                         
2029                         $installscriptmessage = $xestiascan_lang{$language_selected}{cannotremovemultiuserinstallerscript};
2030                         $installscriptmessage =~ s/%s/$!/g;
2031                         
2032                         print $installscriptmessage . "<br />";         
2033                         
2034                 }
2035                 
2036         } else {
2037                 
2038                 print $xestiascan_lang{$language_selected}{multiuserinstallscriptkept} . "<br />";
2039                 
2040         }
2041         
2042         print "<br />";
2043         
2044         print $xestiascan_lang{$language_selected}{usexestiascannerservertext} . "<br /><br />";
2045         
2046         print "<a href=\"" . $xestiascanscriptname . "\">$xestiascan_lang{$language_selected}{usexestiascannerserverlink}</a>";
2047         
2048         print "</div>";
2049         
2050         exit;
2051         
2054 # Load the configuration file and get the required settings.
2056 # Check to see if the settings file is valid.
2058 # Get the list of database modules.
2060 opendir(DATABASEDIR, "Modules/Auth");
2061 my @dbmodule_directory = grep /m*\.pm$/, readdir(DATABASEDIR);
2062 closedir(DATABASEDIR);
2064 my @database_modules;
2066 foreach my $dbmodule_file (@dbmodule_directory){
2068         # Get the friendly name for the database module.
2070         next if $dbmodule_file =~ m/^\./;
2071         next if $dbmodule_file !~ m/.pm$/;
2072         $dbmodule_file =~ s/.pm$//g;
2073         push(@database_modules, $dbmodule_file);
2078 # Check to see if the database module does support a multiuser configuration.
2080 my $dbmodule;
2081 my $dbmodule_out = "";
2082 my @dbmodule_multiuser;
2083 my $dbmodule_fullname;
2084 my %dbmodule_capabilities;
2085 use lib "Modules/";
2087 foreach my $dbmodule_file (@database_modules){
2089         # Load the module and see if has multiuser support and
2090         # if it has then add it to the list of multiuser supported
2091         # database modules and then unload it.
2093         my $dbmodule_fullname = "Auth::" . $dbmodule_file;
2094         ($dbmodule_fullname) = $dbmodule_fullname =~ m/^(.*)$/g; # CHECK THIS!!
2095         eval "use " . $dbmodule_fullname;
2096         $dbmodule_fullname = "Modules::Auth::" . $dbmodule_file;
2097         $dbmodule = $dbmodule_fullname->new();
2099         %dbmodule_capabilities = $dbmodule->capabilities();
2101         undef($dbmodule);
2102         
2103         push(@dbmodule_multiuser, $dbmodule_file) if $dbmodule_capabilities{'multiuser'} eq 1;
2107 # Print out a form specifying if the users and/or sessions table should be created.
2109 my $config_fail = 0;
2111 if (xestiascan_settings_load ne 0){
2113         $config_fail = 1;
2114         
2115 } else {
2116         
2117         $default_dbmodule       = $xestiascan_config{system_authmodule};
2118         $default_server         = $xestiascan_config{database_server};
2119         $default_port           = $xestiascan_config{database_port};
2120         $default_protocol       = $xestiascan_config{database_protocol};
2121         $default_name           = $xestiascan_config{database_sqldatabase};
2122         $default_username       = $xestiascan_config{database_username};
2123         $default_prefix         = $xestiascan_config{database_tableprefix};
2124         
2127 print "Content-type: text/html; charset=utf-8;\r\n\r\n";
2129 print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
2130 print "<head>\n<title>$xestiascan_lang{$language_selected}{installertitle}</title>\n";
2131 print "<style type=\"text/css\" media=\"screen\">$cssstyle</style>\n</head>\n<body>";
2133 # Start language bar.
2135 print "<div class=\"topbar\">
2136 <span class=\"title\">" . $xestiascan_lang{$language_selected}{installertitle} .  "</span>";
2138 my $language_name_short;
2139 my $language_list_seek = 0;
2140 my $installlanguage_out = "";
2142 $installlanguage_out = "<select name=\"installlanguage\">\n";
2144 foreach $language_name_short (@language_list_short){
2146         $installlanguage_out = $installlanguage_out . "<option value=\"" . $language_name_short . "\">" . $language_list_long[$language_list_seek] . "</option>\n";
2147         $language_list_seek++;
2151 $installlanguage_out = $installlanguage_out . "</select>\n";
2153 print "<form action=\"" . $installscriptname . "\" method=\"POST\">\n$installlanguage_out\n<input type=\"submit\" value=\"$xestiascan_lang{$language_selected}{switch}\">\n</form>\n";
2154 print "</div>";
2156 print "<div class=\"pagespacing\">";
2158 print "<span class=\"pageheader\">$xestiascan_lang{$language_selected}{installertitle}</span><br /><br />\n";
2159 print $xestiascan_lang{$language_selected}{installertext};
2161 print "<br /><br />";
2163 if ($config_fail eq 1){
2165         print $xestiascan_lang{$language_selected}{invalidconfigfile};
2166         print "<br /><br />";
2167         
2170 print "<form action=\"" . $installscriptname . "\" method=\"POST\">";
2171 print "<input type=\"hidden\" name=\"confirm\" value=\"1\">\n<input type=\"hidden\" name=\"installlanguage\" value=\"$language_selected\">\n";
2173 # End of language bar, begin main installer part.
2175 print "<table width=\"100%\">";
2176 xestiascan_addtablerow($xestiascan_lang{$language_selected}{authsettings}, "tablecellheader", "", "tablecellheader");
2178 $dbmodule_out = "<select name=\"authmodule\">";
2180 foreach my $dbmodule_file (@dbmodule_multiuser){
2181         if ($default_dbmodule eq $dbmodule_file){
2182                 $dbmodule_out = $dbmodule_out . "<option value=\"$dbmodule_file\" selected>$dbmodule_file</option>";            
2183         } else {
2184                 $dbmodule_out = $dbmodule_out . "<option value=\"$dbmodule_file\">$dbmodule_file</option>";
2185         }
2188 $dbmodule_out = $dbmodule_out . "</select><br />" . $xestiascan_lang{$language_selected}{multiuseronly};
2190 xestiascan_addtablerow($xestiascan_lang{$language_selected}{authenticationmodule}, "tablename", $dbmodule_out, "tabledata");
2191 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databaseserver}, "tablename", "<input type=\"text\" name=\"databaseserver\" size=\"32\" maxlength=\"128\" value=\"$default_server\">\n", "tabledata");
2192 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databaseport}, "tablename", "<input type=\"text\" name=\"databaseport\" maxlength=\"5\" size=\"5\" value=\"$default_port\">\n", "tabledata");
2193 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databaseprotocol}, "tablename", "<select name=\"databaseprotocol\">\n<option value=\"tcp\">tcp</option>\n<option value=\"udp\">udp</option>\n</select>\n", "tabledata");
2194 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databasename}, "tablename", "<input type=\"text\" name=\"databasename\" size=\"32\" maxlength=\"32\" value=\"$default_name\">\n", "tabledata");
2195 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databaseusername}, "tablename", "<input type=\"text\" name=\"databaseusername\" size=\"16\" maxlength=\"16\" value=\"$default_username\">\n", "tabledata");
2196 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databasepassword}, "tablename", "<input type=\"password\" name=\"databasepassword\" size=\"32\" maxlength=\"64\"><br />Leave password blank to use password in configuration file.\n", "tabledata");
2197 xestiascan_addtablerow($xestiascan_lang{$language_selected}{databasetableprefix}, "tablename", "<input type=\"text\" name=\"databasetableprefix\" size=\"32\" maxlength=\"32\" value=\"$default_prefix\">\n", "tabledata");
2199 xestiascan_addtablerow($xestiascan_lang{$language_selected}{adminuseraccountsettings}, "tablecellheader", "", "tablecellheader");
2200 xestiascan_addtablerow($xestiascan_lang{$language_selected}{adminusername}, "tablename", "<input type=\"text\" name=\"multiuseradminusername\" size=\"32\" maxlength=\"32\" value=\"$xestiascan_lang{$language_selected}{adminaccountname}\">", "tabledata");
2201 xestiascan_addtablerow($xestiascan_lang{$language_selected}{adminpassword}, "tablename", "<input type=\"password\" name=\"multiuseradminpassword\" size=\"32\" maxlength=\"128\" value=\"$xestiascan_lang{$language_selected}{adminaccountpassword}\">", "tabledata");
2203 xestiascan_addtablerow($xestiascan_lang{$language_selected}{installationoptions}, "tablecellheader", "", "tablecellheader");
2204 xestiascan_addtablerow($xestiascan_lang{$language_selected}{createtables}, "tablename", "<input type=\"checkbox\" name=\"createmodules\" checked>" . $xestiascan_lang{$language_selected}{createtablemodulepermissions} . "<br /><input type=\"checkbox\" name=\"createscanners\" checked>" . $xestiascan_lang{$language_selected}{createtablescannerspermissions} . "<br /><input type=\"checkbox\" name=\"createsessions\" checked>" . $xestiascan_lang{$language_selected}{createtablesessions} . "<br /><input type=\"checkbox\" name=\"createusers\" checked>" . $xestiascan_lang{$language_selected}{createtableusers} . "<br />", "tabledata");
2205 xestiascan_addtablerow($xestiascan_lang{$language_selected}{forcerecreate}, "tablename", "<input type=\"checkbox\" name=\"forcerecreate\">" . $xestiascan_lang{$language_selected}{forcerecreatetables}, "tabledata");
2206 xestiascan_addtablerow($xestiascan_lang{$language_selected}{deleteinstallscripts}, "tablename", "<input type=\"checkbox\" name=\"deleteinstall\" checked>" . $xestiascan_lang{$language_selected}{removeinstallscript} . "<br /><input type=\"checkbox\" name=\"deleteinstallmultiuser\" checked>" . $xestiascan_lang{$language_selected}{removemultiuserinstallscript} . "<br /><br /><b>" . $xestiascan_lang{$language_selected}{warningmessage} . $xestiascan_lang{$language_selected}{recommendremoving} . "</b>", "tabledata");
2208 print "</table>\n";
2210 print "<input type=\"submit\" value=\"Create tables\"> | <input type=\"reset\" value=\"Reset settings\">";
2212 print "</form></div>";
2214 print "</body></html>";
2216 __END__
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy