1 #################################################################################
2 # Xestia Scanner Server - Common System Module #
5 # Copyright (C) 2010-2011 Steve Brokenshire <sbrokenshire@xestia.co.uk> #
7 # This module is licensed under the same license as Xestia Scanner Server which #
8 # is licensed under the GPL version 3. #
10 # This program is free software: you can redistribute it and/or modify #
11 # it under the terms of the GNU General Public License as published by #
12 # the Free Software Foundation, version 3 of the License. #
14 # This program is distributed in the hope that it will be useful, #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17 # GNU General Public License for more details. #
19 # You should have received a copy of the GNU General Public License #
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
21 #################################################################################
23 package Modules::System::Common;
29 use MIME::Base64 qw(encode_base64url);
31 our @ISA = qw(Exporter);
32 our @EXPORT = qw(xestiascan_initialise xestiascan_settings_load xestiascan_fileexists xestiascan_filepermissions xestiascan_output_header xestiascan_output_page xestiascan_variablecheck xestiascan_processconfig xestiascan_processfilename xestiascan_utf8convert xestiascan_language xestiascan_error);
34 sub xestiascan_initialise{
35 #################################################################################
36 # xestiascan_initialise: Get the enviroment stuff. #
37 #################################################################################
39 # Get the script filename.
41 my $env_script_name = $ENV{'SCRIPT_NAME'};
43 # Process the script filename until there is only the
46 my $env_script_name_length = length($env_script_name);
47 my $filename_seek = 0;
48 my $filename_char = "";
49 my $filename_last = 0;
52 $filename_char = substr($env_script_name, $filename_seek, 1);
53 if ($filename_char eq "/"){
54 $filename_last = $filename_seek + 1;
57 } until ($filename_seek eq $env_script_name_length || $env_script_name_length eq 0);
59 my $env_script_name_finallength = $env_script_name_length - $filename_last;
60 my $script_filename = substr($env_script_name, $filename_last, $env_script_name_finallength);
62 # Setup the needed enviroment variables for Xestia Scanner Server.
64 %main::xestiascan_env = (
65 "script_filename" => $script_filename,
70 sub xestiascan_settings_load{
71 #################################################################################
72 # xestiascan_settings_load: Load the configuration settings into the global #
77 # xestiascan_settings_load(); #
78 #################################################################################
80 # Check if the Xestia Scanner Server configuration file exists before
81 # using it and return an critical error if it doesn't exist.
83 my ($xestiascan_settingsfilehandle, @config_data, %config, $config);
84 my $xestiascan_conf_exist = xestiascan_fileexists("xsdss.cfg");
86 if ($xestiascan_conf_exist eq 1){
88 # The configuration really does not exist so return an critical error.
90 xestiascan_critical("configfilemissing");
94 # Check if the Xestia Scanner Server configuration file has valid permission
95 # settings before using it and return an critical error if it doesn't have the
96 # valid permission settings.
98 my $xestiascan_conf_permissions = xestiascan_filepermissions("xsdss.cfg", 1, 0);
100 if ($xestiascan_conf_permissions eq 1){
102 # The permission settings for the Xestia Scanner Server configuration
103 # file are invalid, so return an critical error.
105 xestiascan_critical("configfileinvalidpermissions");
109 # Converts the file into meaningful data for later on in this subroutine.
111 my $xestiascan_conf_file = 'xsdss.cfg';
113 open($xestiascan_settingsfilehandle, $xestiascan_conf_file);
114 binmode $xestiascan_settingsfilehandle, ':utf8';
115 @config_data = <$xestiascan_settingsfilehandle>;
116 %config = xestiascan_processconfig(@config_data);
117 close($xestiascan_settingsfilehandle);
119 # Go and fetch the settings and place them into a hash (that is global).
121 %main::xestiascan_config = (
123 "directory_noncgi_images" => $config{config}{directory_noncgi_images},
124 "directory_noncgi_scans" => $config{config}{directory_noncgi_scans},
125 "directory_fs_scans" => $config{config}{directory_fs_scans},
127 "system_language" => $config{config}{system_language},
128 "system_presmodule" => $config{config}{system_presmodule},
129 "system_authmodule" => $config{config}{system_authmodule},
130 "system_outputmodule" => $config{config}{system_outputmodule},
131 "system_datetime" => $config{config}{system_datetime},
133 "database_server" => $config{config}{database_server},
134 "database_port" => $config{config}{database_port},
135 "database_protocol" => $config{config}{database_protocol},
136 "database_sqldatabase" => $config{config}{database_sqldatabase},
137 "database_username" => $config{config}{database_username},
138 "database_password" => $config{config}{database_password},
139 "database_tableprefix" => $config{config}{database_tableprefix}
143 # Do a validation check on all of the variables that were loaded into the global configuration hash.
145 xestiascan_variablecheck($main::xestiascan_config{"directory_noncgi_images"}, "maxlength", 512, 0);
146 xestiascan_variablecheck($main::xestiascan_config{"directory_noncgi_scans"}, "maxlength", 512, 0);
148 xestiascan_variablecheck($main::xestiascan_config{"directory_fs_scans"}, "maxlength", 4096, 0);
150 my $xestiascan_config_language_filename = xestiascan_variablecheck($main::xestiascan_config{"system_language"}, "language_filename", "", 1);
151 my $xestiascan_config_presmodule_filename = xestiascan_variablecheck($main::xestiascan_config{"system_presmodule"}, "module", 0, 1);
152 my $xestiascan_config_authmodule_filename = xestiascan_variablecheck($main::xestiascan_config{"system_authmodule"}, "module", 0, 1);
153 # Check if the language filename is valid and return an critical error if
156 if ($xestiascan_config_language_filename eq 1){
158 # The language filename is blank so return an critical error.
160 xestiascan_critical("languagefilenameblank");
162 } elsif ($xestiascan_config_language_filename eq 2){
164 # The language filename is invalid so return an critical error.
166 xestiascan_critical("languagefilenameinvalid");
170 # Check if the presentation and database module names are valid and return a critical
171 # error if they aren't.
173 if ($xestiascan_config_presmodule_filename eq 1){
175 # The presentation module filename given is blank so return an
178 xestiascan_critical("presmoduleblank");
182 if ($xestiascan_config_presmodule_filename eq 2){
184 # The presentation module filename is invalid so return an
187 xestiascan_critical("presmoduleinvalid");
191 if ($xestiascan_config_authmodule_filename eq 1){
193 # The database module filename given is blank so return an
196 xestiascan_critical("authmoduleblank");
200 if ($xestiascan_config_authmodule_filename eq 2){
202 # The database module filename given is invalid so return
205 xestiascan_critical("authmoduleinvalid");
209 # Check if the language file does exist before loading it and return an critical error
210 # if it does not exist.
212 my $xestiascan_config_language_fileexists = xestiascan_fileexists("lang/" . $main::xestiascan_config{"system_language"} . ".lang");
214 if ($xestiascan_config_language_fileexists eq 1){
216 # Language file does not exist so return an critical error.
218 xestiascan_critical("languagefilemissing");
222 # Check if the language file has valid permission settings and return an critical error if
223 # the language file has invalid permissions settings.
225 my $xestiascan_config_language_filepermissions = xestiascan_filepermissions("lang/" . $main::xestiascan_config{"system_language"} . ".lang", 1, 0);
227 if ($xestiascan_config_language_filepermissions eq 1){
229 # Language file contains invalid permissions so return an critical error.
231 xestiascan_critical("languagefilenameinvalidpermissions");
235 # Load the language file.
237 my ($xestiascan_languagefilehandle, @lang_data);
239 open($xestiascan_languagefilehandle, "lang/" . $main::xestiascan_config{"system_language"} . ".lang");
240 @lang_data = <$xestiascan_languagefilehandle>;
241 %main::xestiascan_lang = xestiascan_processconfig(@lang_data);
242 close($xestiascan_languagefilehandle);
244 # Check if the presentation module does exist before loading it and return an critical error
245 # if the presentation module does not exist.
247 my $xestiascan_config_presmodule_fileexists = xestiascan_fileexists("Modules/Presentation/" . $main::xestiascan_config{"system_presmodule"} . ".pm");
249 if ($xestiascan_config_presmodule_fileexists eq 1){
251 # Presentation module does not exist so return an critical error.
253 xestiascan_critical("presmodulemissing");
257 # Check if the presentation module does have the valid permission settings and return a
258 # critical error if the presentation module contains invalid permission settings.
260 my $xestiascan_config_presmodule_permissions = xestiascan_filepermissions("Modules/Presentation/" . $main::xestiascan_config{"system_presmodule"} . ".pm", 1, 0);
262 if ($xestiascan_config_presmodule_permissions eq 1){
264 # Presentation module contains invalid permissions so return an critical error.
266 xestiascan_critical("presmoduleinvalidpermissions");
270 # Check if the database module does exist before loading it and return an critical error
271 # if the database module does not exist.
273 my $xestiascan_config_authmodule_fileexists = xestiascan_fileexists("Modules/Auth/" . $main::xestiascan_config{"system_authmodule"} . ".pm");
275 if ($xestiascan_config_authmodule_fileexists eq 1){
277 # Database module does not exist so return an critical error.
279 xestiascan_critical("authmodulemissing");
283 # Check if the database module does have the valid permission settings and return an
284 # critical error if the database module contains invalid permission settings.
286 my $xestiascan_config_authmodule_permissions = xestiascan_filepermissions("Modules/Auth/" . $main::xestiascan_config{"system_authmodule"} . ".pm", 1, 0);
288 if ($xestiascan_config_authmodule_permissions eq 1){
290 # Presentation module contains invalid permissions so return an critical error.
292 xestiascan_critical("authmoduleinvalidpermissions");
296 # Include the Modules directory.
300 # Load the presentation module.
302 my $presmodulename = "Presentation::" . $main::xestiascan_config{"system_presmodule"};
303 ($presmodulename) = $presmodulename =~ m/^(.*)$/g; # CHECK THIS!!
304 eval "use " . $presmodulename;
305 $presmodulename = "Modules::Presentation::" . $main::xestiascan_config{"system_presmodule"};
306 $main::xestiascan_presmodule = $presmodulename->new();
307 $main::xestiascan_presmodule->clear();
309 # Load the database module.
311 my $dbmodulename = "Auth::" . $main::xestiascan_config{"system_authmodule"};
312 ($dbmodulename) = $dbmodulename =~ m/^(.*)$/g; # CHECK THIS!!
313 eval "use " . $dbmodulename;
314 $dbmodulename = "Modules::Auth::" . $main::xestiascan_config{"system_authmodule"};
315 $main::xestiascan_authmodule = $dbmodulename->new();
317 # Load the following settings to the database module.
319 $main::xestiascan_authmodule->loadsettings({ DateTime => $main::xestiascan_config{"system_datetime"}, Server => $main::xestiascan_config{"database_server"}, Port => $main::xestiascan_config{"database_port"}, Protocol => $main::xestiascan_config{"database_protocol"}, Database => $main::xestiascan_config{"database_sqldatabase"}, Username => $main::xestiascan_config{"database_username"}, Password => $main::xestiascan_config{"database_password"}, TablePrefix => $main::xestiascan_config{"database_tableprefix"} });
325 sub xestiascan_language{
326 #################################################################################
327 # xestiascan_language: Process language strings that needs certain text #
332 # xestiascan_language(string, [text, text, ...]); #
334 # string Specifies the string to process. #
335 # text Specifies the text to pass to the string (can be repeated many #
337 #################################################################################
344 $string =~ s/%s/$item/;
352 sub xestiascan_error{
353 #################################################################################
354 # xestiascan_error: Prints out an error message. #
358 # xestiascan_error(errortype, errorext); #
360 # errortype Specifies the type of error that occured. #
361 # errorext Specifies the extended error information. #
362 #################################################################################
364 # Get the error type from the subroutine.
366 my ($error_type, $error_extended) = @_;
368 # Disconnect from the database server.
370 if ($main::xestiascan_authmodule){
371 $main::xestiascan_authmodule->disconnect();
374 # Load the list of error messages.
376 my @xestiascan_error = (
378 # Catch all error message.
381 # Standard error messages.
382 "blankfilename", "blankvariable", "fileexists", "internalerror", "invalidoption", "invalidaction", "invalidfilename", "invalidmode", "invalidutf8", "invalidvariable", "variabletoolong",
384 # Specific error messages.
385 "authconnectionerror", "autherror", "authmoduleblank", "authmoduleinvalid", "authmodulemissing",
386 "blankdatetimeformat", "blankdirectory", "blankpictureid", "bottomrightx",
387 "bottomrightxinvalidnumber", "bottomrighty", "bottomrightyinvalidnumber", "brightnessblank",
388 "brightnessinvalidnumber", "colourblank", "colourinvalidoption", "invaliddatetimeformat",
389 "invaliddirectory", "invalidpictureid", "languagefilenamemissing", "moduleinvalid",
390 "nametoolong", "notpermitted", "outputmoduleblank", "outputmoduleinvalid",
391 "passwordblank", "passwordsdonotmatch", "passwordtoolong", "permissiontypeblank", "presmoduleblank",
392 "presmoduleinvalid", "presmodulemissing", "resolutionblank", "resolutioninvalidnumber",
393 "rotateblank", "rotateinvalidoption", "scannererror", "serverdatabasenameinvalid",
394 "serverdatabasenametoolong", "serverdatabasepasswordtoolong", "serverdatabasetableprefixinvalid", "serverdatabasetableprefixtoolong",
395 "serverdatabaseusernameinvalid", "serverdatabaseusernametoolong", "servernameinvalid", "servernametoolong",
396 "serverportnumberinvalid", "serverportnumberinvalidcharacters", "serverportnumbertoolong", "serverprotocolinvalid",
397 "serverprotocolnametoolong", "topleftxblank", "topleftxinvalidnumber", "topleftyblank", "topleftyinvalidnumber",
398 "userexists", "usernameblank", "usernametoolong", "variabletoolong"
402 # Check if the error message name is a valid error message name
403 # and return the generic error message if it isn't.
405 my $error_string = "";
407 if (grep /^$error_type$/, @xestiascan_error){
409 # The error type is valid so get the error language string
410 # associated with this error messsage name.
412 $error_string = $main::xestiascan_lang{error}{$error_type};
416 # The error type is invalid so set the error language
417 # string using the generic error message name.
419 $error_string = $main::xestiascan_lang{error}{generic};
423 $main::xestiascan_presmodule->clear();
425 $main::xestiascan_presmodule->startbox("errorbox");
426 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{error}, { Style => "errorheader" });
427 $main::xestiascan_presmodule->addlinebreak();
428 $main::xestiascan_presmodule->addtext($error_string, { Style => "errortext" });
430 # Check to see if extended error information was passed.
432 if ($error_extended){
434 # Write the extended error information.
436 $main::xestiascan_presmodule->addlinebreak();
437 $main::xestiascan_presmodule->addlinebreak();
438 $main::xestiascan_presmodule->addtext($main::xestiascan_lang{error}{extendederror});
439 $main::xestiascan_presmodule->addlinebreak();
440 $main::xestiascan_presmodule->addlinebreak();
441 $main::xestiascan_presmodule->startbox("datalist");
442 $main::xestiascan_presmodule->addtext($error_extended);
443 $main::xestiascan_presmodule->endbox();
447 $main::xestiascan_presmodule->endbox();
451 if ($main::successful_auth eq 1){
453 $menulist = "standard";
461 &xestiascan_output_header;
462 xestiascan_output_page($main::xestiascan_lang{error}{error}, $main::xestiascan_presmodule->grab(), $menulist);
468 sub xestiascan_fileexists{
469 #################################################################################
470 # xestiascan_fileexists: Check if a file exists and returns a value depending on #
471 # if the file exists or not. #
475 # xestiascan_fileexists(filename); #
477 # filename Specifies the file name to check if it exists or not. #
478 #################################################################################
480 # Get the value that was passed to the subroutine.
484 # Check if the filename exists, if it does, return a value of 0, else
485 # return a value of 1, meaning that the file was not found.
489 # Specified file does exist so return a value of 0.
495 # Specified file does not exist so return a value of 1.
503 sub xestiascan_filepermissions{
504 #################################################################################
505 # xestiascan_filepermissions: Check if the file permissions of a file and return #
506 # either a 1 saying that the permissions are valid or return a 0 saying that #
507 # the permissions are invalid. #
511 # xestiascan_filepermissions(filename, [read], [write], [filemissingskip]); #
513 # filename Specifies the filename to check for permissions. #
514 # read Preform check that the file is readable. #
515 # write Preform check that the file is writeable. #
516 # filemissingskip Skip the check of seeing if it can read or write if the #
518 #################################################################################
520 # Get the values that was passed to the subroutine.
522 my ($filename, $readpermission, $writepermission, $ignorechecks) = @_;
524 # Check to make sure that the read permission and write permission values
525 # are only 1 character long.
527 xestiascan_variablecheck($readpermission, "maxlength", 1, 0);
528 xestiascan_variablecheck($writepermission, "maxlength", 1, 0);
529 xestiascan_variablecheck($ignorechecks, "maxlength", 1, 0);
531 my $ignorechecks_result = 0;
533 # Check if the file should be ignored for read and write checking if
540 # The file exists so the checks are to be done.
542 $ignorechecks_result = 0;
546 # The file does not exist so the checks don't need to
547 # be done to prevent false positives.
549 $ignorechecks_result = 1;
555 $ignorechecks_result = 0;
559 # Check if the file should be checked to see if it can be read.
561 if ($readpermission && $ignorechecks_result eq 0){
563 # The file should be checked to see if it does contain read permissions
564 # and return a 0 if it is invalid.
568 # The file is readable, so do nothing.
572 # The file is not readable, so return 1.
580 # Check if the file should be checked to see if it can be written.
582 if ($writepermission && $ignorechecks_result eq 0){
584 # The file should be checked to see if it does contain write permissions
585 # and return a 0 if it is invalid.
589 # The file is writeable, so do nothing.
593 # The file is not writeable, so return 1.
601 # No problems have occured, so return 0.
607 sub xestiascan_utf8convert{
608 #################################################################################
609 # xestiascan_utf8convert: Properly converts values into UTF-8 values. #
613 # utfstring # The UTF-8 string to convert. #
614 #################################################################################
616 # Get the values passed to the subroutine.
618 my ($utfstring) = @_;
620 # Load the Encode perl module.
622 use Encode qw(decode_utf8 encode_utf8);
624 # Convert the string.
626 my $finalutf8 = Encode::decode_utf8( $utfstring );
633 sub xestiascan_critical{
634 #################################################################################
635 # xestiascan_critical: Displays an critical error message that cannot be #
636 # normally by the xestiascan_error subroutine. #
640 # errortype Specifies the type of critical error that has occured. #
641 #################################################################################
643 # Get the value that was passed to the subroutine.
645 my ($error_type) = @_;
649 # Get the error type from the errortype string.
653 # Generic critical error message.
655 "generic" => "A critical error has occured but the error is not known to Xestia Scanner Server.",
657 # Specific critical error messages.
659 "configfilemissing" => "The Xestia Scanner Server configuration file is missing! Running the installer script for Xestia Scanner Server is recommended.",
660 "configfileinvalidpermissions" => "The Xestia Scanner Server configuration file has invalid permission settings set! Please set the valid permission settings for the configuration file.",
661 "authmoduleblank" => "The authentication module name is blank! Running the installer script for Xestia Scanner Server is recommended.",
662 "authmodulemissing" => "The authentication module is missing! Running the installer script for Xestia Scanner Server is recommended.",
663 "authmoduleinvalidpermissions" => "The authentication module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the configuration file.",
664 "authmoduleinvalid" => "The authentication module name given is invalid. Running the installer script for Xestia Scanner Server is recommended.",
665 "invalidvalue" => "An invalid value was passed.",
666 "languagefilenameblank" => "The language filename given is blank! Running the installer script for Xestia Scanner Server is recommended.",
667 "languagefilenameinvalid" => "The language filename given is invalid! Running the installer script for Xestia Scanner Server is recommended.",
668 "languagefilemissing" => "The language filename given does not exist. Running the installer script for Xestia Scanner Server is recommended.",
669 "languagefilenameinvalidpermissions" => "The language file with the filename given has invalid permissions set. Please set the valid permission settings for the language file.",
670 "presmodulemissing" => "The presentation module is missing! Running the installer script for Xestia Scanner Server is recommended.",
671 "presmoduleinvalidpermissions" => "The presentation module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the presentation module.",
672 "presmoduleinvalid" => "The presentation module name given is invalid. Running the installer script for Xestia Scanner Server is recommended.",
673 "textarearowblank" => "The text area row value given is blank. Running the installer script for Xestia Scanner Server is recommended.",
674 "textarearowtoolong" => "The text area row value is too long. Running the installer script for Xestia Scanner Server is recommended.",
675 "textarearowinvalid" => "The text area row value is invalid. Running the installer script for Xestia Scanner Server is recommended.",
676 "textareacolblank" => "The text area row value given is blank. Running the installer script for Xestia Scanner Server is recommended.",
677 "textareacoltoolong" => "The text area column value is too long. Running the installer script for Xestia Scanner Server is recommended.",
678 "textareacolinvalid" => "The text area column value is invalid. Running the installer script for Xestia Scanner Server is recommended.",
679 "pagecountblank" => "The page count value is blank. Running the installer script for Xestia Scanner Server is recommended.",
680 "templatecountblank" => "The template count value is blank. Running the installer script for Xestia Scanner Server is recommended.",
681 "filtercountblank" => "The filter count value is blank. Running the installer script for Xestia Scanner Server is recommended.",
682 "pagecounttoolong" => "The page count value is too long. Running the installer script for Xestia Scanner Server is recommended.",
683 "templatecounttoolong" => "The template count value is too long. Running the installer script for Xestia Scanner Server is recommended.",
684 "filtercounttoolong" => "The filter count value is too long. Running the installer script for Xestia Scanner Server is recommended.",
685 "pagecountinvalid" => "The page count value is invalid. Running the installer script for Xestia Scanner Server is recommended.",
686 "templatecountinvalid" => "The template count value is invalid. Running the installer script for Xestia Scanner Server is recommended.",
687 "filtercountinvalid" => "The filter count is invalid. Running the installer script for Xestia Scanner Server is recommended."
691 if (!$error_list{$error_type}){
693 $error_type = "generic";
697 print "Content-Type: text/html; charset=utf-8;\r\n";
698 print "Expires: Sun, 01 Jan 2008 00:00:00 GMT\r\n\r\n";
699 print "Critical Error: " . $error_list{$error_type};
704 sub xestiascan_variablecheck{
705 #################################################################################
706 # xestiascan_variablecheck: Checks the variables for any invalid characters. #
710 # xestiascan_variablecheck(variable, type, length, noerror); #
712 # variable Specifies the variable to be checked. #
713 # type Specifies what type the variable is. #
714 # option Specifies the maximum/minimum length of the variable #
715 # (if minlength/maxlength is used) or if the filename should be #
716 # checked to see if it is blank. #
717 # noerror Specifies if Xestia Scanner Server should return an error #
718 # or not on certain values. #
719 #################################################################################
721 # Get the values that were passed to the subroutine.
723 my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
725 if (!$variable_data){
729 if (!$variable_type){
733 if ($variable_type eq "numbers"){
735 # Check for numbers and return an error if there is anything else than numebrs.
737 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated.
738 $variable_data_validated =~ tr/0-9//d; # Take away all of the numbers and from the variable.
739 # If it only contains numbers then it should be blank.
741 if ($variable_data_validated eq ""){
742 # The validated variable is blank. So continue to the end of this section where the return function should be.
744 # The variable is not blank, so check if the no error value is set
747 if ($variable_noerror eq 1){
749 # The validated variable is not blank and the noerror
750 # value is set to 1. So return an value of 1.
751 # (meaning that the data is invalid).
755 } elsif ($variable_noerror eq 0) {
757 # The validated variable is not blank and the noerror
760 xestiascan_error("invalidvariable");
764 # The variable noerror value is something else
765 # pther than 1 or 0. So return an error.
767 xestiascan_error("invalidvariable");
775 } elsif ($variable_type eq "decimal"){
777 # Check for numbers and decimal and return an error if there is anything else than numebrs.
779 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated.
780 $variable_data_validated =~ tr/0-9.//d; # Take away all of the numbers and from the variable.
781 # If it only contains numbers then it should be blank.
783 if ($variable_data_validated eq ""){
784 # The validated variable is blank. So continue to the end of this section where the return function should be.
786 # The variable is not blank, so check if the no error value is set
789 if ($variable_noerror eq 1){
791 # The validated variable is not blank and the noerror
792 # value is set to 1. So return an value of 1.
793 # (meaning that the data is invalid).
797 } elsif ($variable_noerror eq 0) {
799 # The validated variable is not blank and the noerror
802 xestiascan_error("invalidvariable");
806 # The variable noerror value is something else
807 # pther than 1 or 0. So return an error.
809 xestiascan_error("invalidvariable");
817 } elsif ($variable_type eq "lettersnumbers"){
819 # Check for letters and numbers and return an error if there is anything else other
820 # than letters and numbers.
822 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated
823 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
824 $variable_data_validated =~ s/\s//g;
826 if ($variable_data_validated eq ""){
827 # The validated variable is blank. So continue to the end of this section where the return function should be.
829 # The variable is not blank, so check if the no error value is set
832 if ($variable_noerror eq 1){
834 # The validated variable is not blank and the noerror
835 # value is set to 1. So return an value of 1.
836 # (meaning that the data is invalid).
840 } elsif ($variable_noerror eq 0) {
842 # The validated variable is not blank and the noerror
845 xestiascan_error("invalidvariable");
849 # The variable noerror value is something else
850 # pther than 1 or 0. So return an error.
852 xestiascan_error("invalidvariable");
860 } elsif ($variable_type eq "maxlength"){
861 # Check for the length of the variable, return an error if it is longer than the length specified.
863 # Check if the variable_data string is blank, if it is then set the variable_data_length
866 my $variable_data_length = 0;
868 if (!$variable_data){
870 # Set variable_data_length to '0'.
871 $variable_data_length = 0;
875 # Get the length of the variable recieved.
876 $variable_data_length = length($variable_data);
882 if ($variable_data_length > $variable_option){
884 # The variable length is longer than it should be so check if
885 # the no error value is set 1.
887 if ($variable_noerror eq 1){
889 # The no error value is set to 1, so return an
890 # value of 1 (meaning tha the variable is
891 # too long to be used).
895 } elsif ($variable_noerror eq 0){
897 # The no error value is set to 0, so return
900 xestiascan_error("variabletoolong");
904 # The no error value is something else other
905 # than 0 or 1, so return an error.
907 xestiascan_error("variabletoolong");
913 # The variable length is exactly or shorter than specified, so continue to end of this section where
914 # the return function should be.
920 } elsif ($variable_type eq "blank"){
921 # Check if the variable is blank and if it is blank, then return an error.
923 if (!$variable_data){
925 # The variable data really is blank, so check what
926 # the no error value is set.
928 if ($variable_noerror eq 1){
930 # The no error value is set to 1, so return
931 # a value of 1 (saying that the variable was
936 } elsif ($variable_noerror eq 0){
938 # The no error value is set to 0, so return
941 xestiascan_error("blankvariable");
945 # The no error value is something else other
946 # than 0 or 1, so return an error.
948 xestiascan_error("invalidvariable");
956 } elsif ($variable_type eq "filename"){
957 # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return
960 # Check if the filename passed is blank, if it is then return with an error.
962 if ($variable_data eq ""){
964 # The filename specified is blank, so check what the
965 # noerror value is set.
967 if ($variable_noerror eq 1){
969 # The no error value is set to 1 so return
970 # a value of 1 (meaning that the filename
975 } elsif ($variable_noerror eq 0){
977 # The no error value is set to 1 so return
980 xestiascan_error("blankfilename");
984 # The no error value is something else other
985 # than 0 or 1, so return an error.
987 xestiascan_error("invalidvariable");
996 my $variable_data_validated = $variable_data;
997 $variable_data_validated =~ tr/a-zA-Z0-9\.//d;
999 # Check if the validated data variable is blank, if it is
1000 # then continue to the end of this section where the return
1001 # function should be, otherwise return an error.
1003 if ($variable_data_validated eq ""){
1005 # The validated data variable is blank, meaning that
1006 # it only contained letters and numbers.
1010 # The validated data variable is not blank, meaning
1011 # that it contains something else, so return an error
1014 if ($variable_noerror eq 1){
1016 # The no error value is set to 1 so return
1017 # an value of 2. (meaning that the filename
1023 } elsif ($variable_noerror eq 0){
1025 # The no error value is set to 0 so return
1028 xestiascan_error("invalidfilename");
1032 # The no error value is something else other
1033 # than 0 or 1 so return an error.
1035 xestiascan_error("invalidvariable");
1043 } elsif ($variable_type eq "filenameindir"){
1044 # Check if the filename is in the directory and return an
1045 # error if it isn't.
1047 if ($variable_data eq ""){
1049 # The filename specified is blank, so check what the
1050 # noerror value is set.
1052 if ($variable_noerror eq 1){
1054 # The no error value is set to 1 so return
1055 # a value of 1 (meaning that the filename
1060 } elsif ($variable_noerror eq 0){
1062 # The no error value is set to 1 so return
1065 xestiascan_error("blankfilename");
1069 # The no error value is something else other
1070 # than 0 or 1, so return an error.
1072 xestiascan_error("invalidvariable");
1081 # Set the following variables for later on.
1083 my $variable_data_length = 0;
1084 my $variable_data_char = "";
1085 my $variable_data_validated = "";
1086 my $variable_data_seek = 0;
1087 my $variable_database_list = "";
1088 my $variable_database_listcurrent = "";
1089 my $variable_data_firstlevel = 1;
1091 # Get the length of the variable recieved.
1093 $variable_data_length = length($variable_data);
1095 # Check if the database filename contains the directory command
1096 # for up a directory level and if it is, return an error
1097 # or return with a number.
1101 # Get a character from the filename passed to this subroutine.
1103 $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1105 # Check if the current character is the forward slash character.
1107 if ($variable_data_char eq "/"){
1109 # Check if the current directory is blank (and on the first level), or if the
1110 # current directory contains two dots or one dot, if it does return an error.
1112 if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent eq "."){
1114 # Check if the noerror value is set to 1, if it is return an
1115 # number, else return an proper error.
1117 if ($variable_noerror eq 1){
1119 # Page filename contains invalid characters and
1120 # the no error value is set to 1 so return a
1121 # value of 2 (meaning that the page filename
1126 } elsif ($variable_noerror eq 0) {
1128 # Page filename contains invalid characters and
1129 # the no error value is set to 0 so return an
1132 xestiascan_error("invalidfilename");
1136 # The no error value is something else other
1137 # than 0 or 1 so return an error.
1139 xestiascan_error("invalidvariable");
1145 # Append the forward slash, clear the current directory name and set
1146 # the first directory level value to 0.
1148 $variable_database_list = $variable_database_list . $variable_data_char;
1149 $variable_database_listcurrent = "";
1150 $variable_data_firstlevel = 0;
1154 # Append the current character to the directory name and to the current
1157 $variable_database_list = $variable_database_list . $variable_data_char;
1158 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1162 # Increment the seek counter.
1164 $variable_data_seek++;
1166 } until ($variable_data_seek eq $variable_data_length);
1170 } elsif ($variable_type eq "datetime"){
1171 # Check if the date and time setting format is valid.
1173 if ($variable_data eq ""){
1175 if ($variable_noerror eq 1){
1177 # The no error value is set to 1 so return
1178 # a value of 1 (meaning that the date and
1179 # time format was blank).
1183 } elsif ($variable_noerror eq 0){
1185 # The no error value is set to 1 so return
1188 xestiascan_error("blankdatetimeformat");
1192 # The no error value is something else other
1193 # than 0 or 1, so return an error.
1195 xestiascan_error("invalidvariable");
1201 my $variable_data_validated = $variable_data;
1202 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
1204 if ($variable_data_validated eq ""){
1206 # The date and time format is valid. So
1211 # The validated data variable is not blank, meaning
1212 # that it contains something else, so return an error
1215 if ($variable_noerror eq 1){
1217 # The no error value is set to 1 so return
1218 # an value of 2. (meaning that the date and
1219 # time format was invalid).
1223 } elsif ($variable_noerror eq 0){
1225 # The no error value is set to 0 so return
1228 xestiascan_error("invaliddatetimeformat");
1232 # The no error value is something else other
1233 # than 0 or 1 so return an error.
1235 xestiascan_error("invalidvariable");
1243 } elsif ($variable_type eq "directory"){
1244 # Check if the directory only contains letters and numbers and
1245 # return an error if anything else appears.
1247 my $variable_data_validated = $variable_data;
1248 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1250 if ($variable_data eq ""){
1252 if ($variable_noerror eq 1){
1254 # The no error value is set to 1 so return
1255 # a value of 1 (meaning that the directory
1260 } elsif ($variable_noerror eq 0){
1262 # The no error value is set to 1 so return
1265 xestiascan_error("blankdirectory");
1269 # The no error value is something else other
1270 # than 0 or 1, so return an error.
1272 xestiascan_error("invalidvariable");
1278 if ($variable_data_validated eq ""){
1280 # The validated data variable is blank, meaning that
1281 # it only contains letters and numbers.
1285 # The validated data variable is not blank, meaning
1286 # that it contains something else, so return an error
1289 if ($variable_noerror eq 1){
1291 # The no error value is set to 1 so return
1292 # an value of 2. (meaning that the directory
1297 } elsif ($variable_noerror eq 0){
1299 # The no error value is set to 0 so return
1302 xestiascan_error("invaliddirectory");
1306 # The no error value is something else other
1307 # than 0 or 1 so return an error.
1309 xestiascan_error("invalidvariable");
1317 } elsif ($variable_type eq "language_filename"){
1319 # The variable type is a language filename type.
1320 # Check if the language file name is blank and
1321 # if it is then return an error (or value).
1323 if ($variable_data eq ""){
1325 # The language filename is blank so check the
1326 # no error value and return an error (or value).
1328 if ($variable_noerror eq 1){
1330 # Language filename is blank and the no error value
1331 # is set as 1, so return a value of 1 (saying that
1332 # the language filename is blank).
1336 } elsif ($variable_noerror eq 0) {
1338 # Language filename is blank and the no error value
1339 # is not set as 1, so return an error.
1341 xestiascan_critical("languagefilenameblank");
1345 # The noerror value is something else other
1346 # than 0 or 1 so return an error.
1348 xestiascan_error("invalidvariable");
1354 # Set the following variables for later on.
1356 my $variable_data_length = 0;
1357 my $variable_data_char = "";
1358 my $variable_data_seek = 0;
1360 # Get the length of the language file name.
1362 $variable_data_length = length($variable_data);
1366 # Get a character from the language filename passed to this
1367 # subroutine and the character the seek counter value is set
1370 $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1372 # Check if the language filename contains a forward slash or a dot,
1373 # if the selected character is a forward slash then return an error
1376 if ($variable_data_char eq "/" || $variable_data_char eq "."){
1378 # The language filename contains a forward slash or
1379 # a dot so depending on the no error value, return
1380 # an error or a value.
1382 if ($variable_noerror eq 1){
1384 # Language filename contains a forward slash or a dot
1385 # and the no error value has been set to 1, so return
1386 # an value of 2 (saying that the language file name is
1391 } elsif ($variable_noerror eq 0) {
1393 # Language filename contains a forward slash and the no
1394 # error value has not been set to 1, so return an error.
1396 xestiascan_critical("languagefilenameinvalid");
1400 # The noerror value is something else other than
1401 # 1 or 0 so return an error.
1403 xestiascan_error("invalidvariable");
1409 # Increment the seek counter.
1411 $variable_data_seek++;
1413 } until ($variable_data_seek eq $variable_data_length);
1417 } elsif ($variable_type eq "module"){
1419 # The variable type is a presentation module filename.
1421 # Check if the variable_data is blank and if it is
1424 if ($variable_data eq ""){
1426 # The presentation module is blank so check if an error
1427 # value should be returned or a number should be
1430 if ($variable_noerror eq 1){
1432 # Module name is blank and the no error value
1433 # is set to 1 so return a value of 2 (meaning
1434 # that the page filename is blank).
1438 } elsif ($variable_noerror eq 0) {
1440 # Module name contains is blank and the no error
1441 # value is set to 0 so return an error.
1443 xestiascan_critical("moduleblank");
1447 # The no error value is something else other
1448 # than 0 or 1 so return an error.
1450 xestiascan_critical("invalidvalue");
1458 my $variable_data_validated = $variable_data;
1459 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1461 if ($variable_data_validated eq ""){
1465 if ($variable_noerror eq 1){
1467 # Module name contains invalid characters and
1468 # the no error value is set to 1 so return a
1469 # value of 2 (meaning that the page filename
1474 } elsif ($variable_noerror eq 0) {
1476 # Module name contains invalid characters and
1477 # the no error value is set to 0 so return an
1480 xestiascan_critical("moduleinvalid");
1484 # The no error value is something else other
1485 # than 0 or 1 so return an error.
1487 xestiascan_error("invalidvalue");
1495 } elsif ($variable_type eq "utf8"){
1497 # The variable type is a UTF8 string.
1499 if (!$variable_data){
1501 $variable_data = "";
1510 while ($chunk < $length){
1512 $chunkdata = substr($variable_data, $chunk, $process);
1514 if ($chunkdata =~ m/\A(
1515 [\x09\x0A\x0D\x20-\x7E] # ASCII
1516 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
1517 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
1518 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
1519 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
1520 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
1521 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
1522 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
1525 # The UTF-8 string is valid.
1529 # The UTF-8 string is not valid, check if the no error
1530 # value is set to 1 and return an error if it isn't.
1532 if ($variable_noerror eq 1){
1534 # The no error value has been set to 1, so return
1535 # a value of 1 (meaning that the UTF-8 string is
1540 } elsif ($variable_noerror eq 0) {
1542 # The no error value has been set to 0, so return
1545 xestiascan_error("invalidutf8");
1549 # The no error value is something else other than 0
1550 # or 1, so return an error.
1552 xestiascan_error("invalidoption");
1559 $chunk = $chunk + $process;
1563 # # Check if the string is a valid UTF8 string.
1565 # if ($variable_data =~ m/^(
1566 # [\x09\x0A\x0D\x20-\x7E] # ASCII
1567 # | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
1568 # | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
1569 # | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
1570 # | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
1571 # | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
1572 # | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
1573 # | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
1576 # # The UTF-8 string is valid.
1580 # # The UTF-8 string is not valid, check if the no error
1581 # # value is set to 1 and return an error if it isn't.
1583 # if ($variable_noerror eq 1){
1585 # # The no error value has been set to 1, so return
1586 # # a value of 1 (meaning that the UTF-8 string is
1591 # } elsif ($variable_noerror eq 0) {
1593 # # The no error value has been set to 0, so return
1596 # xestiascan_error("invalidutf8");
1600 # # The no error value is something else other than 0
1601 # # or 1, so return an error.
1603 # xestiascan_error("invalidoption");
1611 } elsif ($variable_type eq "serverprotocol"){
1613 # Check if the server protocol is TCP or UDP and return
1614 # an error if it isn't.
1616 if ($variable_data ne "tcp" && $variable_data ne "udp"){
1618 # The protocol given is not valid, check if the no
1619 # error value is set to 1 and return an error if it isn't.
1621 if ($variable_noerror eq 1){
1623 # The no error value has been set to 1, so return a
1624 # value of 1 (meaning that the server protocol is
1629 } elsif ($variable_noerror eq 0){
1631 # The no error value has been set to 0, so return
1634 xestiascan_error("serverprotocolinvalid");
1638 # The no error value is something else other than 0
1639 # or 1, so return an error.
1641 xestiascan_error("invalidoption");
1649 } elsif ($variable_type eq "port"){
1651 # Check if the port number given is less than 0 or more than 65535
1652 # and return an error if it is.
1654 if ($variable_data < 0 || $variable_data > 65535){
1656 # The port number is less than 0 and more than 65535 so
1657 # check if the no error value is set to 1 and return an
1658 # error if it isn't.
1660 if ($variable_noerror eq 1){
1662 # The no error value has been set to 1, so return a
1663 # value of 1 (meaning that the port number is invalid).
1667 } elsif ($variable_noerror eq 0){
1669 # The no error value has been set to 0, so return
1672 xestiascan_error("serverportnumberinvalid");
1676 # The no error value is something else other than 0
1677 # or 1, so return an error.
1679 xestiascan_error("invalidoption");
1689 # Another type than the valid ones above has been specified so return an error specifying an invalid option.
1690 xestiascan_error("invalidoption");
1694 sub xestiascan_output_header{
1695 #################################################################################
1696 # xestiascan_output_header: Outputs the header to the browser/stdout/console. #
1700 # xestiascan_output_header(username, seed, expires); #
1701 #################################################################################
1703 my $headertype = shift;
1705 # Print a header saying that the page expires immediately since the
1706 # date is set in the past.
1708 $headertype = "none" if !$headertype;
1710 if ($headertype eq "cookie"){
1712 my $username = shift;
1714 my $expires = shift;
1722 # Get the date and time information.
1724 my ($exp_sec, $exp_min, $exp_hour, $exp_mday, $exp_mon, $exp_year, $exp_wday, $exp_yday, $exp_isdst) = localtime(time + $expires);
1726 my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
1727 my @weekday = qw(Sun Mon Tue Wed Thu Fri Sat);
1729 $exp_sec = "0" . $exp_sec if $exp_sec < 10;
1730 $exp_min = "0" . $exp_min if $exp_min < 10;
1731 $exp_hour = "0" . $exp_hour if $exp_hour < 10;
1732 $exp_mday = "0" . $exp_mday if $exp_mday < 10;
1733 $exp_mon = "0" . $exp_mon if $exp_mon < 10;
1735 my $expires_time = $weekday[$exp_wday] . ", " . $exp_mday . "-" . $month[$exp_mon] . "-" . ($exp_year + 1900) . " " . $exp_hour . ":" . $exp_min . ":" . $exp_sec . " GMT";
1737 # Print out the cookies.
1739 print "Set-Cookie: " . $main::xestiascan_config{'database_tableprefix'} . "_auth_seed=" . $seed . "; expires=" . $expires_time ."\r\n";
1740 print "Set-Cookie: " . $main::xestiascan_config{'database_tableprefix'} . "_auth_username=" . encode_base64url($username) . "; expires=" . $expires_time ."\r\n";
1742 } elsif ($headertype eq "cookie_logout") {
1744 # Get the date and time information.
1746 my ($exp_sec, $exp_min, $exp_hour, $exp_mday, $exp_mon, $exp_year, $exp_wday, $exp_yday, $exp_isdst) = localtime(time - 100);
1748 my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
1749 my @weekday = qw(Sun Mon Tue Wed Thu Fri Sat);
1751 $exp_sec = "0" . $exp_sec if $exp_sec < 10;
1752 $exp_min = "0" . $exp_min if $exp_min < 10;
1753 $exp_hour = "0" . $exp_hour if $exp_hour < 10;
1754 $exp_mday = "0" . $exp_mday if $exp_mday < 10;
1755 $exp_mon = "0" . $exp_mon if $exp_mon < 10;
1757 my $expires_time = $weekday[$exp_wday] . ", " . $exp_mday . "-" . $month[$exp_mon] . "-" . ($exp_year + 1900) . " " . $exp_hour . ":" . $exp_min . ":" . $exp_sec . " GMT";
1759 print "Set-Cookie: " . $main::xestiascan_config{'database_tableprefix'} . "_auth_seed=; expires=" . $expires_time ."\r\n";
1760 print "Set-Cookie: " . $main::xestiascan_config{'database_tableprefix'} . "_auth_username=; expires=" . $expires_time ."\r\n";
1764 #print "Set-Cookie: seed=$seed:username=" . $username . "; expires=" . $weekday[$exp_wday] . " " . $exp_mday . "-" . $month[$exp_mon] . "-" . ($exp_year + 1900) . " " . $exp_hour . ":" . $exp_min . ":" . $exp_sec . " GMT\r\n";
1766 print "Content-Type: text/html; charset=utf-8\r\n";
1767 print "Expires: Sun, 01 Jan 2007 00:00:00 GMT\r\n\r\n";
1773 sub xestiascan_processfilename{
1774 #################################################################################
1775 # xestiascan_processfilename: Processes a name and turns it into a filename that#
1776 # can be used by Xestia Scanner Server. #
1780 # xestiascan_processfilename(text); #
1782 # text Specifies the text to be used in the process for creating a new #
1784 #################################################################################
1786 # Get the values that have been passed to the subroutine.
1788 my ($process_text) = @_;
1790 # Define some variables that will be used later on.
1792 my $processed_stageone = "";
1793 my $processed_stagetwo = "";
1794 my $processed_length = "";
1795 my $processed_char = "";
1796 my $processed_seek = 0;
1797 my $processed_filename = "";
1799 # Set the first stage value of the processed filename to the
1800 # process filename and then filter it out to only contain
1801 # numbers and letters (no spaces) and then convert the
1802 # capitals to small letters.
1804 $processed_stageone = $process_text;
1805 $processed_stageone =~ tr#a-zA-Z0-9##cd;
1806 $processed_stageone =~ tr/A-Z/a-z/;
1808 # Now set the second stage value of the processed filename
1809 # to the first stage value of the processed filename and
1810 # then limit the filename down to 32 characters.
1812 $processed_stagetwo = $processed_stageone;
1813 $processed_length = length($processed_stagetwo);
1815 # Process the second stage filename into the final
1816 # filename and do so until the seek counter is 32
1817 # or reaches the length of the second stage filename.
1821 # Get the character that is the seek counter
1824 $processed_char = substr($processed_stagetwo, $processed_seek, 1);
1826 # Append to the final processed filename.
1828 $processed_filename = $processed_filename . $processed_char;
1830 # Increment the seek counter.
1834 } until ($processed_seek eq 32 || $processed_seek eq $processed_length);
1836 return $processed_filename;
1841 sub xestiascan_processconfig{
1842 #################################################################################
1843 # xestiascan_processconfig: Processes an INI style configuration file. #
1847 # xestiascan_processconfig(data); #
1849 # data Specifies the data to process. #
1850 #################################################################################
1852 my (@settings) = @_;
1854 my ($settings_line, %settings, $settings, $sectionname, $setting_name, $setting_value);
1856 foreach $settings_line (@settings){
1858 next if !$settings_line;
1860 # Check if the first character is a bracket.
1862 if (substr($settings_line, 0, 1) eq "["){
1863 $settings_line =~ s/\[//;
1864 $settings_line =~ s/\](.*)//;
1865 $settings_line =~ s/\n//;
1866 $sectionname = $settings_line;
1870 $setting_name = $settings_line;
1871 $setting_value = $settings_line;
1872 $setting_name =~ s/\=(.*)//;
1873 $setting_name =~ s/\n//;
1874 $setting_value =~ s/(.*)\=//;
1875 $setting_value =~ s/\n//;
1877 # Remove the spacing before and after the '=' sign.
1879 $setting_name =~ s/\s+$//;
1880 $setting_value =~ s/^\s+//;
1881 $setting_value =~ s/\r//;
1883 $settings{$sectionname}{$setting_name} = $setting_value;
1891 sub xestiascan_output_page{
1892 #################################################################################
1893 # xestiascan_output_page: Outputs the page to the browser/stdout/console. #
1897 # xestiascan_output_page(pagetitle, pagedata, menutype); #
1899 # pagetitle Specifies the page title. #
1900 # pagedata Specifies the page data. #
1901 # menutype Prints out which menu to use. #
1902 #################################################################################
1904 my ($pagetitle, $pagedata, $menutype) = @_;
1906 # Open the script page template and load it into the scriptpage variable,
1907 # while declaring the variable.
1909 open (my $filehandle_scriptpage, "<:utf8", 'page.html');
1910 my @scriptpage = <$filehandle_scriptpage>;
1911 binmode $filehandle_scriptpage, ':utf8';
1912 close ($filehandle_scriptpage);
1914 my $query_lite = new CGI::Lite;
1915 my $form_data = $query_lite->parse_form_data;
1917 # Define the variables required.
1919 my $scriptpageline = "";
1920 my $pageoutput = "";
1922 $main::xestiascan_presmodule->clear();
1924 # Print out the main menu for Xestia Scanner Server.
1926 if ($menutype ne "none"){
1928 $main::xestiascan_presmodule->addlink($main::xestiascan_env{'script_filename'} . "?mode=scan", { Text => $main::xestiascan_lang{menu}{scanconfig} });
1929 $main::xestiascan_presmodule->addtext(" | ");
1930 $main::xestiascan_presmodule->addlink($main::xestiascan_env{'script_filename'} . "?mode=users", { Text => $main::xestiascan_lang{menu}{userconfig} });
1931 $main::xestiascan_presmodule->addtext(" | ");
1932 $main::xestiascan_presmodule->addlink($main::xestiascan_env{'script_filename'} . "?mode=settings", { Text => $main::xestiascan_lang{menu}{settingsconfig} });
1933 $main::xestiascan_presmodule->addtext(" | ");
1934 $main::xestiascan_presmodule->addlink($main::xestiascan_env{'script_filename'} . "?mode=logout", { Text => $main::xestiascan_lang{menu}{logout} });
1936 $main::xestiascan_presmodule->addlinebreak();
1940 my $menuoutput = $main::xestiascan_presmodule->grab();
1942 # Find <xestiascan> tages and replace with the apporiate variables.
1944 foreach $scriptpageline (@scriptpage){
1946 $scriptpageline =~ s/<xestiascan:menu>/$menuoutput/g;
1947 $scriptpageline =~ s/<xestiascan:imagespath>/$main::xestiascan_config{"directory_noncgi_images"}/g;
1948 $scriptpageline =~ s/<xestiascan:pagedata>/$pagedata/g;
1950 # Check if page title specified is blank, otherwise add a page title
1953 if (!$pagetitle || $pagetitle eq ""){
1954 $scriptpageline =~ s/<xestiascan:title>//g;
1956 $scriptpageline =~ s/<xestiascan:title>/ ($pagetitle)/g;
1961 # Append processed line to the pageoutput variable.
1963 $pageoutput = $pageoutput . $scriptpageline;