Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.3.0
[kiriwrite/.git] / cgi-files / kiriwrite.cgi
1 #!/usr/bin/perl -Tw
3 #################################################################################
4 # Kiriwrite (kiriwrite.cgi)                                                     #
5 # Main program script                                                           #
6 #                                                                               #
7 # Version: 0.1.0                                                                #
8 #                                                                               #
9 # Copyright (C) 2005-2007 Steve Brokenshire <sbrokenshire@xestia.co.uk>         #
10 #                                                                               #
11 # This program is free software; you can redistribute it and/or modify it under #
12 # the terms of the GNU General Public License as published by the Free          #
13 # Software Foundation; as version 2 of the License.                             #
14 #                                                                               #
15 # This program is distributed in the hope that it will be useful, but WITHOUT   #
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
17 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.#
18 #                                                                               #
19 # You should have received a copy of the GNU General Public License along with  #
20 # this program; if not, write to the Free Software Foundation, Inc., 51         #
21 # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                           #
22 #################################################################################
24 use strict;                             # Throw errors if there's something wrong.
25 use warnings;                           # Write warnings to the HTTP Server Log file.
27 use utf8;
28 use CGI::Lite;
29 use Tie::IxHash;
31 binmode STDOUT, ':utf8';
33 # This is commented out because it uses a fair bit of CPU usage.
35 #use CGI::Carp('fatalsToBrowser');      # Output errors to the browser.
37 # Declare global variables for Kiriwrite settings and languages.
39 our ($kiriwrite_config, %kiriwrite_config, %kiriwrite_lang, $kiriwrite_lang, $kiriwrite_version, %kiriwrite_version, $kiriwrite_env, %kiriwrite_env, $kiriwrite_presmodule, $kiriwrite_dbmodule, $form_data);
41 # Setup the version information for Kiriwrite.
43 %kiriwrite_version = (
44         "major"         => 0,
45         "minor"         => 2,
46         "revision"      => 0
47 );
49 sub BEGIN{
50 #################################################################################
51 # BEGIN: Get the enviroment stuff                                               #
52 #################################################################################
54         # Get the script filename.
56         my $env_script_name = $ENV{'SCRIPT_NAME'};
58         # Process the script filename until there is only the
59         # filename itself.
61         my $env_script_name_length = length($env_script_name);
62         my $filename_seek = 0;
63         my $filename_char = "";
64         my $filename_last = 0;
66         do {
67                 $filename_char = substr($env_script_name, $filename_seek, 1);
68                 if ($filename_char eq "/"){
69                         $filename_last = $filename_seek + 1;
70                 }
71                 $filename_seek++;
72         } until ($filename_seek eq $env_script_name_length || $env_script_name_length eq 0);
74         my $env_script_name_finallength = $env_script_name_length - $filename_last;
75         my $script_filename = substr($env_script_name, $filename_last, $env_script_name_finallength);
77         # Setup the needed enviroment variables for Kiriwrite.
79         %kiriwrite_env = (
80                 "script_filename" => $script_filename,
81         );
83 }
85 #################################################################################
86 # Begin listing the functions needed.                                           #
87 #################################################################################
89 sub kiriwrite_selectedlist{
90 #################################################################################
91 # kiriwrite_page_selectedlist: Get the list of selected pages to use.           #
92 #                                                                               #
93 # Usage:                                                                        #
94 #                                                                               #
95 # kiriwrite_page_selectedlist();                                                #
96 #################################################################################
98         my $count       = $form_data->{'count'};
100         # Check if the list of files has a value and if not set it 0.
102         if (!$count){
104                 $count = 0;
106         }
108         # Define some values for later.
110         my @filename_list; 
111         my @selected_list;
112         my @final_list;
114         my $filename;
115         my $selected;
117         my $final_count = 0;
118         my $seek = 0;
120         # Get the list of filenames.
122         do {
124                 # Get the values from id[]
126                 $seek++;
128                 $filename               = $form_data->{'id[' . $seek . ']'};
129                 $filename_list[$seek]   = $filename;
131         } until ($seek eq $count || $count eq 0);
133         # Get the list of selected filenames.
135         $seek = 0;
137         do {
139                 # Get the values from name[]
141                 $seek++;
143                 $selected       = $form_data->{'name[' . $seek . ']'};
145                 if (!$selected){
147                         $selected = 'off';
149                 }
151                 $selected_list[$seek]   = $selected;
153         } until ($seek eq $count || $count eq 0);
155         # Create a final list of filenames to be used for
156         # processing.
158         $seek = 0;
160         do {
162                 # Check if the selected value is on and include
163                 # the filename in the final list.
165                 $seek++;
167                 $selected       = $selected_list[$seek];
169                 if ($selected eq "on"){
171                         $filename       = $filename_list[$seek];
172                         $final_list[$final_count] = $filename;
173                         $final_count++;
175                 }
177         } until ($seek eq $count || $count eq 0);
179         return @final_list;
183 sub kiriwrite_settings_load{
184 #################################################################################
185 # kiriwrite_settings_load: Load the configuration settings into the global      #
186 # variables.                                                                    #
187 #                                                                               #
188 # Usage:                                                                        #
189 #                                                                               #
190 # kiriwrite_settings_load();                                                    #
191 #################################################################################
193         # Load the required Perl modules.
195         use Config::Auto;
197         # Check if the Kiriwrite configuration file exists before using it and
198         # return an critical error if it doesn't exist.
200         my $kiriwrite_conf_exist = kiriwrite_fileexists("kiriwrite.cfg");
202         if ($kiriwrite_conf_exist eq 1){
204                 # The configuration really does not exist so return an critical error.
206                 kiriwrite_critical("configfilemissing");
208         }
210         # Check if the Kiriwrite configuration file has valid permission settings
211         # before using it and return an critical error if it doesn't have the
212         # valid permission settings.
214         my $kiriwrite_conf_permissions = kiriwrite_filepermissions("kiriwrite.cfg", 1, 0);
216         if ($kiriwrite_conf_permissions eq 1){
218                 # The permission settings for the Kiriwrite configuration file are
219                 # invalid, so return an critical error.
221                 kiriwrite_critical("configfileinvalidpermissions");
223         }
225         # Converts the XML file into meaningful data for later on in this subroutine.
227         my $kiriwrite_conf_file = 'kiriwrite.cfg';
228         my $config = Config::Auto::parse($kiriwrite_conf_file, format => "ini");
230         # Go and fetch the settings and place them into a hash (that is global).
232         %kiriwrite_config = (
234                 "directory_data_db"             => $config->{config}{directory_data_db},
235                 "directory_data_output"         => $config->{config}{directory_data_output},
236                 "directory_noncgi_images"       => $config->{config}{directory_noncgi_images},
238                 "system_language"               => $config->{config}{system_language},
239                 "system_presmodule"             => $config->{config}{system_presmodule},
240                 "system_dbmodule"               => $config->{config}{system_dbmodule},
241                 "system_datetime"               => $config->{config}{system_datetime},
243                 "display_textarearows"          => $config->{config}{display_textarearows},
244                 "display_textareacols"          => $config->{config}{display_textareacols},
245                 "display_pagecount"             => $config->{config}{display_pagecount},
246                 "display_templatecount"         => $config->{config}{display_templatecount},
247                 "display_filtercount"           => $config->{config}{display_filtercount},
249                 "database_server"               => $config->{config}{database_server},
250                 "database_port"                 => $config->{config}{database_port},
251                 "database_protocol"             => $config->{config}{database_protocol},
252                 "database_sqldatabase"          => $config->{config}{database_sqldatabase},
253                 "database_username"             => $config->{config}{database_username},
254                 "database_password"             => $config->{config}{database_password},
255                 "database_tableprefix"          => $config->{config}{database_tableprefix}
257         );
259         # Do a validation check on all of the variables that were loaded into the global configuration hash.
261         kiriwrite_variablecheck($kiriwrite_config{"directory_data_db"}, "maxlength", 64, 0);
262         kiriwrite_variablecheck($kiriwrite_config{"directory_data_output"}, "maxlength", 64, 0);
263         kiriwrite_variablecheck($kiriwrite_config{"directory_noncgi_images"}, "maxlength", 512, 0);
264         kiriwrite_variablecheck($kiriwrite_config{"directory_data_template"}, "maxlength", 64, 0);
266         my $kiriwrite_config_language_filename = kiriwrite_variablecheck($kiriwrite_config{"system_language"}, "language_filename", "", 1);
267         my $kiriwrite_config_presmodule_filename = kiriwrite_variablecheck($kiriwrite_config{"system_presmodule"}, "module", 0, 1);
268         my $kiriwrite_config_dbmodule_filename = kiriwrite_variablecheck($kiriwrite_config{"system_dbmodule"}, "module", 0, 1);
270         my $kiriwrite_config_textarearows_maxlength = kiriwrite_variablecheck($kiriwrite_config{"display_textarearows"}, "maxlength", 3, 1);
271         my $kiriwrite_config_textarearows_number = kiriwrite_variablecheck($kiriwrite_config{"display_textareacols"}, "numbers", 0, 1);
272         my $kiriwrite_config_textareacols_maxlength = kiriwrite_variablecheck($kiriwrite_config{"display_textareacols"}, "maxlength", 3, 1);
273         my $kiriwrite_config_textareacols_number = kiriwrite_variablecheck($kiriwrite_config{"display_textareacols"}, "numbers", 0, 1);
274         my $kiriwrite_config_pagecount_maxlength = kiriwrite_variablecheck($kiriwrite_config{"display_pagecount"}, "maxlength", 4, 1);
275         my $kiriwrite_config_pagecount_number = kiriwrite_variablecheck($kiriwrite_config{"display_pagecount"}, "numbers", 0, 1);
276         my $kiriwrite_config_templatecount_maxlength = kiriwrite_variablecheck($kiriwrite_config{"display_templatecount"}, "maxlength", 4, 1);
277         my $kiriwrite_config_templatecount_number = kiriwrite_variablecheck($kiriwrite_config{"display_templatecount"}, "numbers", 0, 1);
278         my $kiriwrite_config_filtercount_maxlength = kiriwrite_variablecheck($kiriwrite_config{"display_filtercount"}, "maxlength", 4, 1);
279         my $kiriwrite_config_filtercount_number = kiriwrite_variablecheck($kiriwrite_config{"display_filtercount"}, "numbers", 0, 1);
281         # Check if the language filename is valid and return an critical error if
282         # they aren't.
284         if ($kiriwrite_config_language_filename eq 1){
286                 # The language filename is blank so return an critical error.
288                 kiriwrite_critical("languagefilenameblank");
290         } elsif ($kiriwrite_config_language_filename eq 2){
292                 # The language filename is invalid so return an critical error.
294                 kiriwrite_critical("languagefilenameinvalid");
296         }
298         # Check if the presentation and database module names are valid and return a critical
299         # error if they aren't.
301         if ($kiriwrite_config_presmodule_filename eq 1){
303                 # The presentation module filename given is blank so return an 
304                 # critical error.
306                 kiriwrite_critical("presmoduleblank");
308         }
310         if ($kiriwrite_config_presmodule_filename eq 2){
312                 # The presentation module filename is invalid so return an
313                 # critical error.
315                 kiriwrite_critical("presmoduleinvalid");
317         }
319         if ($kiriwrite_config_dbmodule_filename eq 1){
321                 # The database module filename given is blank so return an
322                 # critical error.
324                 kiriwrite_critical("dbmoduleblank");
326         }
328         if ($kiriwrite_config_dbmodule_filename eq 2){
330                 # The database module filename given is invalid so return
331                 # an critical error.
333                 kiriwrite_critical("dbmoduleinvalid");
335         }
337         # Check if the text area column and row values are blank and return a critical
338         # error if they are.
340         if (!$kiriwrite_config{"display_textarearows"}){
342                 # The text area row value is blank so return
343                 # a critical error.
345                 kiriwrite_critical("textarearowblank");
347         }
349         if (!$kiriwrite_config{"display_textareacols"}){
351                 # The text area column value is blank so return
352                 # a critical error.
354                 kiriwrite_critical("textareacolblank");
356         }
358         # Check if the text area column and row values to see if they are valid and return
359         # a critical error if they aren't.
361         if ($kiriwrite_config_textarearows_maxlength eq 1){
363                 # The text area row value is too long so return an
364                 # critical error.
366                 kiriwrite_critical("textarearowtoolong");
368         }
370         if ($kiriwrite_config_textarearows_number eq 1){
372                 # The text area row value is invalid so return an
373                 # critical error.
375                 kiriwrite_critical("textarearowinvalid");
377         }
379         if ($kiriwrite_config_textareacols_maxlength eq 1){
381                 # The text area column value is too long so return
382                 # an critical error.
384                 kiriwrite_critical("textareacoltoolong");
386         }
388         if ($kiriwrite_config_textareacols_number eq 1){
390                 # The text area column value is invalid so return
391                 # an critical error.
393                 kiriwrite_critical("textareacolinvalid");
395         }
397         # Check if the amount of items per view settings are blank and return a critical
398         # error if they are.
400         if (!$kiriwrite_config{"display_pagecount"}){
402                 # The display page count is blank so return a
403                 # critical error.
405                 kiriwrite_critical("pagecountblank");
407         }
409         if (!$kiriwrite_config{"display_templatecount"}){
411                 # The display template count is blank so return
412                 # a critical error.
414                 kiriwrite_critical("templatecountblank");
416         }
418         if (!$kiriwrite_config{"display_filtercount"}){
420                 # The display filter count is blank so return a
421                 # critical error.
423                 kiriwrite_critical("filtercountblank");
425         }
427         # Check if the amount of items per view settings are valid and return a critical
428         # error message if they aren't.
430         if ($kiriwrite_config_pagecount_maxlength eq 1){
432                 # The length of the page count value is too long
433                 # so return a critical error.
435                 kiriwrite_critical("pagecounttoolong");
437         }
439         if ($kiriwrite_config_pagecount_number eq 1){
441                 # The page count value is invalid so return
442                 # a critical error.
444                 kiriwrite_critical("pagecountinvalid");
446         }
448         if ($kiriwrite_config_templatecount_maxlength eq 1){
450                 # The length of the template count value is too
451                 # long so return a critical error.
453                 kiriwrite_critical("filtercounttoolong");
455         }
457         if ($kiriwrite_config_templatecount_number eq 1){
459                 # The template count value is invalid so return
460                 # a critical error.
462                 kiriwrite_critical("filtercountinvalid");
464         }
466         if ($kiriwrite_config_filtercount_maxlength eq 1){
468                 # The length of the filter count value is too
469                 # long so return a critical error.
471                 kiriwrite_critical("templatecounttoolong");
473         }
475         if ($kiriwrite_config_filtercount_number eq 1){
477                 # The filter count value is invalid so return
478                 # a critical error.
480                 kiriwrite_critical("templatecountinvalid");
482         }
484         # Check if the language file does exist before loading it and return an critical error
485         # if it does not exist.
487         my $kiriwrite_config_language_fileexists = kiriwrite_fileexists("lang/" . $kiriwrite_config{"system_language"} . ".lang");
489         if ($kiriwrite_config_language_fileexists eq 1){
491                 # Language file does not exist so return an critical error.
493                 kiriwrite_critical("languagefilemissing");
495         }
497         # Check if the language file has valid permission settings and return an critical error if
498         # the language file has invalid permissions settings.
500         my $kiriwrite_config_language_filepermissions = kiriwrite_filepermissions("lang/" . $kiriwrite_config{"system_language"} . ".lang", 1, 0);
502         if ($kiriwrite_config_language_filepermissions eq 1){
504                 # Language file contains invalid permissions so return an critical error.
506                 kiriwrite_critical("languagefilenameinvalidpermissions");
508         }
510         # Load the language file.
512         $kiriwrite_lang = Config::Auto::parse("lang/" . $kiriwrite_config{"system_language"} . ".lang", format => "ini");
514         # Check if the presentation module does exist before loading it and return an critical error
515         # if the presentation module does not exist.
517         my $kiriwrite_config_presmodule_fileexists = kiriwrite_fileexists("Modules/Presentation/" . $kiriwrite_config{"system_presmodule"} . ".pm");
519         if ($kiriwrite_config_presmodule_fileexists eq 1){
521                 # Presentation module does not exist so return an critical error.
523                 kiriwrite_critical("presmodulemissing");
525         }
527         # Check if the presentation module does have the valid permission settings and return a
528         # critical error if the presentation module contains invalid permission settings.
530         my $kiriwrite_config_presmodule_permissions = kiriwrite_filepermissions("Modules/Presentation/" . $kiriwrite_config{"system_presmodule"} . ".pm", 1, 0);
532         if ($kiriwrite_config_presmodule_permissions eq 1){
534                 # Presentation module contains invalid permissions so return an critical error.
536                 kiriwrite_critical("presmoduleinvalidpermissions");
538         }
540         # Check if the database module does exist before loading it and return an critical error
541         # if the database module does not exist.
543         my $kiriwrite_config_dbmodule_fileexists = kiriwrite_fileexists("Modules/Database/" . $kiriwrite_config{"system_dbmodule"} . ".pm");
545         if ($kiriwrite_config_dbmodule_fileexists eq 1){
547                 # Database module does not exist so return an critical error.
549                 kiriwrite_critical("dbmodulemissing");
551         }
553         # Check if the database module does have the valid permission settings and return an
554         # critical error if the database module contains invalid permission settings.
556         my $kiriwrite_config_dbmodule_permissions = kiriwrite_filepermissions("Modules/Database/" . $kiriwrite_config{"system_dbmodule"} . ".pm", 1, 0);
558         if ($kiriwrite_config_dbmodule_permissions eq 1){
560                 # Presentation module contains invalid permissions so return an critical error.
562                 kiriwrite_critical("dbmoduleinvalidpermissions");
564         }
566         # Include the Modules directory.
568         use lib "Modules/";
570         # Load the presentation module.
572         my $presmodulename = "Presentation::" . $kiriwrite_config{"system_presmodule"};
573         ($presmodulename) = $presmodulename =~ m/^(.*)$/g;
574         eval "use " . $presmodulename;
575         $presmodulename = "Kiriwrite::Presentation::" . $kiriwrite_config{"system_presmodule"};
576         $kiriwrite_presmodule = $presmodulename->new();
578         # Load the database module.
580         my $dbmodulename = "Database::" . $kiriwrite_config{"system_dbmodule"};
581         ($dbmodulename) = $dbmodulename =~ m/^(.*)$/g;
582         eval "use " . $dbmodulename;
583         $dbmodulename = "Kiriwrite::Database::" . $kiriwrite_config{"system_dbmodule"};
584         $kiriwrite_dbmodule = $dbmodulename->new();
586         # Load the following settings to the database module.
588         $kiriwrite_dbmodule->loadsettings({ Directory => $kiriwrite_config{"directory_data_db"}, DateTime => $kiriwrite_config{"system_datetime"}, Server => $kiriwrite_config{"database_server"}, Port => $kiriwrite_config{"database_port"}, Protocol => $kiriwrite_config{"database_protocol"}, Database => $kiriwrite_config{"database_sqldatabase"}, Username => $kiriwrite_config{"database_username"}, Password => $kiriwrite_config{"database_password"}, TablePrefix => $kiriwrite_config{"database_tableprefix"} });
590         return;
594 sub kiriwrite_variablecheck{
595 #################################################################################
596 # kiriwrite_variablecheck: Checks the variables for any invalid characters.     #
597 #                                                                               #
598 # Usage:                                                                        #
599 #                                                                               #
600 # kiriwrite_variablecheck(variable, type, length, noerror);                     #
601 #                                                                               #
602 # variable      Specifies the variable to be checked.                           #
603 # type          Specifies what type the variable is.                            #
604 # option        Specifies the maximum/minimum length of the variable            #
605 #               (if minlength/maxlength is used) or if the filename should be   #
606 #               checked to see if it is blank.                                  #
607 # noerror       Specifies if Kiriwrite should return an error or not on         #
608 #               certain values.                                                 #
609 #################################################################################
611         # Get the values that were passed to the subroutine.
613         my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
615         if ($variable_type eq "numbers"){
617                 # Check for numbers and return an error if there is anything else than numebrs.
619                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated.
620                 $variable_data_validated =~ tr/0-9//d;          # Take away all of the numbers and from the variable. 
621                                                                 # If it only contains numbers then it should be blank.
623                 if ($variable_data_validated eq ""){
624                         # The validated variable is blank. So continue to the end of this section where the return function should be.
625                 } else {
626                         # The variable is not blank, so check if the no error value is set
627                         # to 1 or not.
629                         if ($variable_noerror eq 1){
631                                 # The validated variable is not blank and the noerror
632                                 # value is set to 1. So return an value of 1.
633                                 # (meaning that the data is invalid).
635                                 return 1;
637                         } elsif ($variable_noerror eq 0) {
639                                 # The validated variable is not blank and the noerror
640                                 # value is set to 0.
642                                 kiriwrite_error("invalidvariable");
644                         } else {
646                                 # The variable noerror value is something else
647                                 # pther than 1 or 0. So return an error.
649                                 kiriwrite_error("invalidvariable");
651                         }
653                 }
655                 return 0;
657         } elsif ($variable_type eq "lettersnumbers"){
659                 # Check for letters and numbers and return an error if there is anything else other
660                 # than letters and numbers.
662                 my $variable_data_validated = $variable_data;   # Copy the variable_data to variable_data_validated
663                 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
664                 $variable_data_validated =~ s/\s//g;
666                 if ($variable_data_validated eq ""){
667                         # The validated variable is blank. So continue to the end of this section where the return function should be.
668                 } else {
669                         # The variable is not blank, so check if the no error value is set
670                         # to 1 or not.
672                         if ($variable_noerror eq 1){
674                                 # The validated variable is not blank and the noerror
675                                 # value is set to 1. So return an value of 1.
676                                 # (meaning that the data is invalid).
678                                 return 1;
680                         } elsif ($variable_noerror eq 0) {
682                                 # The validated variable is not blank and the noerror
683                                 # value is set to 0.
685                                 kiriwrite_error("invalidvariable");
687                         } else {
689                                 # The variable noerror value is something else
690                                 # pther than 1 or 0. So return an error.
692                                 kiriwrite_error("invalidvariable");
694                         }
696                 }
698                 return 0;
700         } elsif ($variable_type eq "maxlength"){
701                 # Check for the length of the variable, return an error if it is longer than the length specified.
703                 # Check if the variable_data string is blank, if it is then set the variable_data_length
704                 # to '0'.
706                 my $variable_data_length = 0;
708                 if (!$variable_data){
710                         # Set variable_data_length to '0'.
711                         $variable_data_length = 0;
713                 } else {
715                         # Get the length of the variable recieved.
716                         $variable_data_length = length($variable_data);
718                 }
722                 if ($variable_data_length > $variable_option){
724                         # The variable length is longer than it should be so check if
725                         # the no error value is set 1.
727                         if ($variable_noerror eq 1){
729                                 # The no error value is set to 1, so return an
730                                 # value of 1 (meaning tha the variable is
731                                 # too long to be used).
733                                 return 1;
735                         } elsif ($variable_noerror eq 0){
737                                 # The no error value is set to 0, so return
738                                 # an error.
740                                 kiriwrite_error("variabletoolong");
742                         } else {
744                                 # The no error value is something else other
745                                 # than 0 or 1, so return an error.
747                                 kiriwrite_error("variabletoolong");
749                         }
751                 } else {
753                         # The variable length is exactly or shorter than specified, so continue to end of this section where
754                         # the return function should be.
756                 }
758                 return 0;
760         } elsif ($variable_type eq "blank"){
761                 # Check if the variable is blank and if it is blank, then return an error.
763                 if (!$variable_data){
765                         # The variable data really is blank, so check what
766                         # the no error value is set.
768                         if ($variable_noerror eq 1){
770                                 # The no error value is set to 1, so return
771                                 # a value of 1 (saying that the variable was
772                                 # blank).
774                                 return 1;
776                         } elsif ($variable_noerror eq 0){
778                                 # The no error value is set to 0, so return
779                                 # an error.
781                                 kiriwrite_error("blankvariable");
783                         } else {
785                                 # The no error value is something else other
786                                 # than 0 or 1, so return an error.
788                                 kiriwrite_error("invalidvariable");
790                         }
792                 }
794                 return 0;
796         } elsif ($variable_type eq "filename"){
797                 # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return
798                 # an error.
800                 # Check if the filename passed is blank, if it is then return with an error.
802                 if ($variable_data eq ""){
804                         # The filename specified is blank, so check what the
805                         # noerror value is set.
807                         if ($variable_noerror eq 1){
809                                 # The no error value is set to 1 so return
810                                 # a value of 1 (meaning that the filename
811                                 # was blank).
813                                 return 1;
815                         } elsif ($variable_noerror eq 0){
817                                 # The no error value is set to 1 so return
818                                 # an error.
820                                 kiriwrite_error("blankfilename");
822                         } else {
824                                 # The no error value is something else other
825                                 # than 0 or 1, so return an error.
827                                 kiriwrite_error("invalidvariable");
829                         }
831                 } else {
834                 }
836                 my $variable_data_validated = $variable_data;
837                 $variable_data_validated =~ tr/a-zA-Z0-9\.//d;
839                 # Check if the validated data variable is blank, if it is 
840                 # then continue to the end of this section where the return 
841                 # function should be, otherwise return an error.
843                 if ($variable_data_validated eq ""){
845                         # The validated data variable is blank, meaning that 
846                         # it only contained letters and numbers.
848                 } else {
850                         # The validated data variable is not blank, meaning 
851                         # that it contains something else, so return an error
852                         # (or a value).
854                         if ($variable_noerror eq 1){
856                                 # The no error value is set to 1 so return
857                                 # an value of 2. (meaning that the filename
858                                 # is invalid).
861                                 return 2;
863                         } elsif ($variable_noerror eq 0){
865                                 # The no error value is set to 0 so return
866                                 # an error.
868                                 kiriwrite_error("invalidfilename");
870                         } else {
872                                 # The no error value is something else other
873                                 # than 0 or 1 so return an error.
875                                 kiriwrite_error("invalidvariable");
877                         }
879                 }
881                 return 0;
883         } elsif ($variable_type eq "filenameindir"){
884                 # Check if the filename is in the directory and return an
885                 # error if it isn't.
887                 if ($variable_data eq ""){
889                         # The filename specified is blank, so check what the
890                         # noerror value is set.
892                         if ($variable_noerror eq 1){
894                                 # The no error value is set to 1 so return
895                                 # a value of 1 (meaning that the filename
896                                 # was blank).
898                                 return 1;
900                         } elsif ($variable_noerror eq 0){
902                                 # The no error value is set to 1 so return
903                                 # an error.
905                                 kiriwrite_error("blankfilename");
907                         } else {
909                                 # The no error value is something else other
910                                 # than 0 or 1, so return an error.
912                                 kiriwrite_error("invalidvariable");
914                         }
916                 } else {
919                 }
921                 # Set the following variables for later on.
923                 my $variable_data_length = 0;
924                 my $variable_data_char = "";
925                 my $variable_data_validated = "";
926                 my $variable_data_seek = 0;
927                 my $variable_database_list = "";
928                 my $variable_database_listcurrent = "";
929                 my $variable_data_firstlevel = 1;
931                 # Get the length of the variable recieved.
933                 $variable_data_length = length($variable_data);
935                 # Check if the database filename contains the directory command
936                 # for up a directory level and if it is, return an error
937                 # or return with a number.
939                 do {
941                         # Get a character from the filename passed to this subroutine.
943                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
945                         # Check if the current character is the forward slash character.
947                         if ($variable_data_char eq "/"){
949                                 # Check if the current directory is blank (and on the first level), or if the
950                                 # current directory contains two dots or one dot, if it does return an error.
952                                 if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent eq "."){
954                                         # Check if the noerror value is set to 1, if it is return an
955                                         # number, else return an proper error.
957                                         if ($variable_noerror eq 1){
959                                                 # Page filename contains invalid characters and
960                                                 # the no error value is set to 1 so return a 
961                                                 # value of 2 (meaning that the page filename
962                                                 # is invalid).
964                                                 return 2;
966                                         } elsif ($variable_noerror eq 0) {
968                                                 # Page filename contains invalid characters and
969                                                 # the no error value is set to 0 so return an
970                                                 # error.
972                                                 kiriwrite_error("invalidfilename");
974                                         } else {
976                                                 # The no error value is something else other
977                                                 # than 0 or 1 so return an error.
979                                                 kiriwrite_error("invalidvariable");
981                                         }
983                                 }
985                                 # Append the forward slash, clear the current directory name and set
986                                 # the first directory level value to 0.
988                                 $variable_database_list = $variable_database_list . $variable_data_char;
989                                 $variable_database_listcurrent = "";
990                                 $variable_data_firstlevel = 0;
992                         } else {
994                                 # Append the current character to the directory name and to the current
995                                 # directory name.
997                                 $variable_database_list = $variable_database_list . $variable_data_char;
998                                 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1000                         }
1002                         # Increment the seek counter.
1004                         $variable_data_seek++;
1006                 } until ($variable_data_seek eq $variable_data_length);
1008                 return 0;
1010         } elsif ($variable_type eq "datetime"){
1011                 # Check if the date and time setting format is valid.
1013                 if ($variable_data eq ""){
1015                         if ($variable_noerror eq 1){
1017                                 # The no error value is set to 1 so return
1018                                 # a value of 1 (meaning that the date and
1019                                 # time format was blank).
1021                                 return 1;
1023                         } elsif ($variable_noerror eq 0){
1025                                 # The no error value is set to 1 so return
1026                                 # an error.
1028                                 kiriwrite_error("blankdatetimeformat");
1030                         } else {
1032                                 # The no error value is something else other
1033                                 # than 0 or 1, so return an error.
1035                                 kiriwrite_error("invalidvariable");
1037                         }
1039                 }
1041                 my $variable_data_validated = $variable_data;
1042                 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
1044                 if ($variable_data_validated eq ""){
1046                         # The date and time format is valid. So
1047                         # skip this bit.
1049                 } else {
1051                         # The validated data variable is not blank, meaning 
1052                         # that it contains something else, so return an error
1053                         # (or a value).
1055                         if ($variable_noerror eq 1){
1057                                 # The no error value is set to 1 so return
1058                                 # an value of 2. (meaning that the date and
1059                                 # time format was invalid).
1061                                 return 2;
1063                         } elsif ($variable_noerror eq 0){
1065                                 # The no error value is set to 0 so return
1066                                 # an error.
1068                                 kiriwrite_error("invaliddatetimeformat");
1070                         } else {
1072                                 # The no error value is something else other
1073                                 # than 0 or 1 so return an error.
1075                                 kiriwrite_error("invalidvariable");
1077                         }
1079                 }
1081                 return 0;
1083         } elsif ($variable_type eq "directory"){
1084                 # Check if the directory only contains letters and numbers and
1085                 # return an error if anything else appears.
1087                 my $variable_data_validated = $variable_data;
1088                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1090                 if ($variable_data eq ""){
1092                         if ($variable_noerror eq 1){
1094                                 # The no error value is set to 1 so return
1095                                 # a value of 1 (meaning that the directory
1096                                 # name was blank).
1098                                 return 1;
1100                         } elsif ($variable_noerror eq 0){
1102                                 # The no error value is set to 1 so return
1103                                 # an error.
1105                                 kiriwrite_error("blankdirectory");
1107                         } else {
1109                                 # The no error value is something else other
1110                                 # than 0 or 1, so return an error.
1112                                 kiriwrite_error("invalidvariable");
1114                         }
1116                 }
1118                 if ($variable_data_validated eq ""){
1120                         # The validated data variable is blank, meaning that
1121                         # it only contains letters and numbers.
1123                 } else {
1125                         # The validated data variable is not blank, meaning 
1126                         # that it contains something else, so return an error
1127                         # (or a value).
1129                         if ($variable_noerror eq 1){
1131                                 # The no error value is set to 1 so return
1132                                 # an value of 2. (meaning that the directory
1133                                 # name is invalid).
1135                                 return 2;
1137                         } elsif ($variable_noerror eq 0){
1139                                 # The no error value is set to 0 so return
1140                                 # an error.
1142                                 kiriwrite_error("invaliddirectory");
1144                         } else {
1146                                 # The no error value is something else other
1147                                 # than 0 or 1 so return an error.
1149                                 kiriwrite_error("invalidvariable");
1151                         }
1153                 }
1155                 return 0;
1157         } elsif ($variable_type eq "language_filename"){
1159                 # The variable type is a language filename type.
1160                 # Check if the language file name is blank and 
1161                 # if it is then return an error (or value).
1163                 if ($variable_data eq ""){
1165                         # The language filename is blank so check the
1166                         # no error value and return an error (or value).
1168                         if ($variable_noerror eq 1){
1170                                 # Language filename is blank and the no error value
1171                                 # is set as 1, so return a value of 1 (saying that
1172                                 # the language filename is blank).
1174                                 return 1;
1176                         } elsif ($variable_noerror eq 0) {
1178                                 # Language filename is blank and the no error value
1179                                 # is not set as 1, so return an error.
1181                                 kiriwrite_critical("languagefilenameblank");
1183                         } else {
1185                                 # The noerror value is something else other
1186                                 # than 0 or 1 so return an error.
1188                                 kiriwrite_error("invalidvariable");
1190                         }
1192                 }
1194                 # Set the following variables for later on.
1196                 my $variable_data_length = 0;
1197                 my $variable_data_char = "";
1198                 my $variable_data_seek = 0;
1200                 # Get the length of the language file name.
1202                 $variable_data_length = length($variable_data);
1204                 do {
1206                         # Get a character from the language filename passed to this 
1207                         # subroutine and the character the seek counter value is set
1208                         # to.
1210                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1212                         # Check if the language filename contains a forward slash or a dot, 
1213                         # if the selected character is a forward slash then return an error
1214                         # (or value).
1216                         if ($variable_data_char eq "/" || $variable_data_char eq "."){
1218                                 # The language filename contains a forward slash or
1219                                 # a dot so depending on the no error value, return
1220                                 # an error or a value.
1222                                 if ($variable_noerror eq 1){
1224                                         # Language filename contains a forward slash or a dot
1225                                         # and the no error value has been set to 1, so return 
1226                                         # an value of 2 (saying that the language file name is 
1227                                         # invalid).
1229                                         return 2;
1231                                 } elsif ($variable_noerror eq 0) {
1233                                         # Language filename contains a forward slash and the no
1234                                         # error value has not been set to 1, so return an error.
1236                                         kiriwrite_critical("languagefilenameinvalid");
1238                                 } else {
1240                                         # The noerror value is something else other than
1241                                         # 1 or 0 so return an error.
1243                                         kiriwrite_error("invalidvariable");
1245                                 }
1247                         }
1249                         # Increment the seek counter.
1251                         $variable_data_seek++;
1253                 } until ($variable_data_seek eq $variable_data_length);
1255                 return 0;
1257         } elsif ($variable_type eq "pagesetting"){
1259                 # The variable type is a page setting, so check if the page
1260                 # setting has one of the valid options.
1262                 if ($variable_data eq 0 || $variable_data eq 1 || $variable_data eq 2 || $variable_data eq 3){
1264                         # The variable is one of the options above, so continue
1265                         # to the end of this section.
1267                 } else {
1269                         # The variable is not one of the options above, so check
1270                         # and see if a error or a value should be returned.
1272                         if ($variable_noerror eq 1){
1274                                 # The page setting is invalid and the no error
1275                                 # value is set 1, so return a value of 1
1276                                 # (saying that the page setting value is
1277                                 # invalid).
1279                                 return 1;
1281                         } elsif ($variable_noerror eq 0) {
1283                                 # Page setting is invalid and the no error value
1284                                 # is not 1, so return an error.
1286                                 kiriwrite_error("invalidvariable");
1288                         } else {
1290                                 # The no error value is something else other
1291                                 # than 0 or 1 so return an error.
1293                                 kiriwrite_error("invalidvariable");
1295                         }
1297                 }
1299                 return 0;
1301         } elsif ($variable_type eq "page_filename"){
1302          
1303                 # The variable type is a page filename type. Check
1304                 # if the data is empty and if it is then return an
1305                 # error (or value).
1307                 if ($variable_data eq ""){
1309                         # The filename is blank so check the no error
1310                         # value and depending on it return an value
1311                         # or an error.
1313                         if ($variable_noerror eq 1){
1315                                 # Page filename is blank and the no error value
1316                                 # is set as 1, so return a value of 1 (saying
1317                                 # the filename is blank).
1319                                 return 1;
1321                         } elsif ($variable_noerror eq 0) {
1323                                 # Page filename is blank and the no error value
1324                                 # is not 1, so return an error.
1326                                 kiriwrite_error("emptypagefilename");
1328                         } else {
1330                                 # The no error value is something else other
1331                                 # than 0 or 1 so return an error.
1333                                 kiriwrite_error("invalidvariable");
1335                         }
1336                 }
1338                 # Set the following variables for later on.
1341                 my $variable_data_length = 0;
1342                 my $variable_data_slash = 0;
1343                 my $variable_data_char = "";
1344                 my $variable_data_validated = "";
1345                 my $variable_data_seek = 0;
1346                 my $variable_database_list = "";
1347                 my $variable_database_listcurrent = "";
1348                 my $variable_data_firstlevel = 1;
1350                 # Get the length of the filename.
1352                 $variable_data_length = length($variable_data);
1354                 # Check that only valid characters should be appearing in
1355                 # the filename.
1357                 $variable_data_validated = $variable_data;
1358                 $variable_data_validated =~ tr|a-zA-Z0-9\.\/\-_||d;
1360                 if ($variable_data_validated ne ""){
1362                         # The validated variable is not blank, meaning the
1363                         # variable contains invalid characters, so return
1364                         # an error.
1366                         if ($variable_noerror eq 1){
1368                                 # Page filename contains invalid characters and
1369                                 # the no error value is set to 1 so return a 
1370                                 # value of 2 (meaning that the page filename
1371                                 # is invalid).
1373                                 return 2;
1375                         } elsif ($variable_noerror eq 0) {
1377                                 # Page filename contains invalid characters and
1378                                 # the no error value is set to 0 so return an
1379                                 # error.
1381                                 kiriwrite_error("invalidfilename");
1383                         } else {
1385                                 # The no error value is something else other
1386                                 # than 0 or 1 so return an error.
1388                                 kiriwrite_error("invalidvariable");
1390                         }
1392                 }
1394                 # Check if the page filename contains the directory command
1395                 # for up a directory level and if it is, return an error
1396                 # or return with a number.
1398                 do {
1400                         # Get a character from the filename passed to this subroutine.
1402                         $variable_data_char = substr($variable_data, $variable_data_seek, 1);
1404                         # Check if the current character is the forward slash character.
1406                         if ($variable_data_char eq "/"){
1408                                 # Check if the current directory is blank (and on the first level), or if the
1409                                 # current directory contains two dots or one dot, if it does return an error.
1411                                 $variable_data_slash = 1;
1413                                 if ($variable_database_listcurrent eq "" && $variable_data_firstlevel eq 1 || $variable_database_listcurrent eq ".." || $variable_database_listcurrent eq "."){
1415                                         # Check if the noerror value is set to 1, if it is return an
1416                                         # number, else return an proper error.
1418                                         if ($variable_noerror eq 1){
1420                                                 # Page filename contains invalid characters and
1421                                                 # the no error value is set to 1 so return a 
1422                                                 # value of 2 (meaning that the page filename
1423                                                 # is invalid).
1425                                                 return 2;
1427                                         } elsif ($variable_noerror eq 0) {
1429                                                 # Page filename contains invalid characters and
1430                                                 # the no error value is set to 0 so return an
1431                                                 # error.
1433                                                 kiriwrite_error("invalidfilename");
1435                                         } else {
1437                                                 # The no error value is something else other
1438                                                 # than 0 or 1 so return an error.
1440                                                 kiriwrite_error("invalidvariable");
1442                                         }
1444                                 }
1446                                 # Append the forward slash, clear the current directory name and set
1447                                 # the first directory level value to 0.
1449                                 $variable_database_list = $variable_database_list . $variable_data_char;
1450                                 $variable_database_listcurrent = "";
1451                                 $variable_data_firstlevel = 0;
1453                         } else {
1455                                 # Append the current character to the directory name and to the current
1456                                 # directory name.
1458                                 $variable_data_slash = 0;
1460                                 $variable_database_list = $variable_database_list . $variable_data_char;
1461                                 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1463                         }
1465                         # Increment the seek counter.
1467                         $variable_data_seek++;
1469                 } until ($variable_data_seek eq $variable_data_length);
1471                 # Check if the last character is a slash and return an
1472                 # error if it is.
1474                 if ($variable_data_slash eq 1){
1476                         if ($variable_noerror eq 1){
1478                                 # Last character is a slash and the no error 
1479                                 # value is set to 1 so return a value of 2 
1480                                 # (meaning that the page filename is invalid).
1482                                 return 2;
1484                         } elsif ($variable_noerror eq 0) {
1486                                 # Page filename contains a slash for the last
1487                                 # character and the no error value is set to 0 
1488                                 # so return an error.
1490                                 kiriwrite_error("invalidfilename");
1492                         } else {
1494                                 # The no error value is something else other
1495                                 # than 0 or 1 so return an error.
1497                                 kiriwrite_error("invalidvariable");
1499                         }
1501                 }
1503                 return 0;
1505         } elsif ($variable_type eq "module"){
1507                 # The variable type is a presentation module filename.
1509                 # Check if the variable_data is blank and if it is
1510                 # return an error.
1512                 if ($variable_data eq ""){
1514                         # The presentation module is blank so check if an error
1515                         # value should be returned or a number should be
1516                         # returned.
1518                         if ($variable_noerror eq 1){
1520                                 # Module name is blank and the no error value 
1521                                 # is set to 1 so return a value of 2 (meaning 
1522                                 # that the page filename is blank).
1524                                 return 1;
1526                         } elsif ($variable_noerror eq 0) {
1528                                 # Module name contains is blank and the no error 
1529                                 # value is set to 0 so return an error.
1531                                 kiriwrite_critical("moduleblank");
1533                         } else {
1535                                 # The no error value is something else other
1536                                 # than 0 or 1 so return an error.
1538                                 kiriwrite_critical("invalidvalue");
1540                         }
1542                 } else {
1544                 }
1546                 my $variable_data_validated = $variable_data;
1547                 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1549                 if ($variable_data_validated eq ""){
1551                 } else {
1553                         if ($variable_noerror eq 1){
1555                                 # Module name contains invalid characters and
1556                                 # the no error value is set to 1 so return a 
1557                                 # value of 2 (meaning that the page filename
1558                                 # is invalid).
1560                                 return 2;
1562                         } elsif ($variable_noerror eq 0) {
1564                                 # Module name contains invalid characters and
1565                                 # the no error value is set to 0 so return an
1566                                 # error.
1568                                 kiriwrite_critical("moduleinvalid");
1570                         } else {
1572                                 # The no error value is something else other
1573                                 # than 0 or 1 so return an error.
1575                                 kiriwrite_error("invalidvalue");
1577                         }
1579                 }
1581                 return 0;
1583         } elsif ($variable_type eq "utf8"){
1585                 # The variable type is a UTF8 string.
1587                 if (!$variable_data){
1589                         $variable_data = "";
1591                 }
1593                 my $chunk = 0;
1594                 my $process = 8192;
1595                 my $length = 0;
1596                 my $chunkdata = "";
1598                 while ($chunk < $length){
1600                         $chunkdata = substr($variable_data, $chunk, $process);
1602                         if ($chunkdata =~ m/\A(
1603                                 [\x09\x0A\x0D\x20-\x7E]            # ASCII
1604                                 | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
1605                                 |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
1606                                 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
1607                                 |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
1608                                 |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1609                                 | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1610                                 |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1611                         )*\z/x){
1613                                 # The UTF-8 string is valid.
1614         
1615                         } else {
1616         
1617                                 # The UTF-8 string is not valid, check if the no error
1618                                 # value is set to 1 and return an error if it isn't.
1619         
1620                                 if ($variable_noerror eq 1){
1621         
1622                                         # The no error value has been set to 1, so return
1623                                         # a value of 1 (meaning that the UTF-8 string is
1624                                         # invalid).
1625         
1626                                         return 1; 
1627         
1628                                 } elsif ($variable_noerror eq 0) {
1629         
1630                                         # The no error value has been set to 0, so return
1631                                         # an error.
1632         
1633                                         kiriwrite_error("invalidutf8");
1634         
1635                                 } else {
1636         
1637                                         # The no error value is something else other than 0
1638                                         # or 1, so return an error.
1639         
1640                                         kiriwrite_error("invalidoption");
1641         
1642                                 }
1643         
1644                         }
1647                         $chunk = $chunk + $process;
1649                 }
1651 #               # Check if the string is a valid UTF8 string.
1652
1653 #               if ($variable_data =~ m/^(
1654 #                       [\x09\x0A\x0D\x20-\x7E]              # ASCII
1655 #                       | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
1656 #                       |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
1657 #                       | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
1658 #                       |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
1659 #                       |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1660 #                       | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1661 #                       |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1662 #               )*$/x){
1663
1664 #                       # The UTF-8 string is valid.
1665
1666 #               } else {
1667
1668 #                       # The UTF-8 string is not valid, check if the no error
1669 #                       # value is set to 1 and return an error if it isn't.
1670
1671 #                       if ($variable_noerror eq 1){
1672
1673 #                               # The no error value has been set to 1, so return
1674 #                               # a value of 1 (meaning that the UTF-8 string is
1675 #                               # invalid).
1676
1677 #                               return 1; 
1678
1679 #                       } elsif ($variable_noerror eq 0) {
1680
1681 #                               # The no error value has been set to 0, so return
1682 #                               # an error.
1683
1684 #                               kiriwrite_error("invalidutf8");
1685
1686 #                       } else {
1687
1688 #                               # The no error value is something else other than 0
1689 #                               # or 1, so return an error.
1690
1691 #                               kiriwrite_error("invalidoption");
1692
1693 #                       }
1694
1695 #               }
1697                 return 0;
1699         } elsif ($variable_type eq "serverprotocol"){
1701                 # Check if the server protocol is TCP or UDP and return
1702                 # an error if it isn't.
1704                 if ($variable_data ne "tcp" && $variable_data ne "udp"){
1706                         # The protocol given is not valid, check if the no
1707                         # error value is set to 1 and return an error if it isn't.
1709                         if ($variable_noerror eq 1){
1711                                 # The no error value has been set to 1, so return a
1712                                 # value of 1 (meaning that the server protocol is
1713                                 # invalid).
1715                                 return 1;
1717                         } elsif ($variable_noerror eq 0){
1719                                 # The no error value has been set to 0, so return
1720                                 # an error.
1722                                 kiriwrite_error("serverprotocolinvalid");
1724                         } else {
1726                                 # The no error value is something else other than 0
1727                                 # or 1, so return an error.
1729                                 kiriwrite_error("invalidoption");
1731                         }
1733                 }
1735                 return 0;
1737         } elsif ($variable_type eq "port"){
1739                 # Check if the port number given is less than 0 or more than 65535
1740                 # and return an error if it is.
1742                 if ($variable_data < 0 || $variable_data > 65535){
1744                         # The port number is less than 0 and more than 65535 so
1745                         # check if the no error value is set to 1 and return an
1746                         # error if it isn't.
1748                         if ($variable_noerror eq 1){
1750                                 # The no error value has been set to 1, so return a
1751                                 # value of 1 (meaning that the port number is invalid).
1753                                 return 1;
1755                         } elsif ($variable_noerror eq 0){
1757                                 # The no error value has been set to 0, so return
1758                                 # an error.
1760                                 kiriwrite_error("serverportnumberinvalid");
1762                         } else {
1764                                 # The no error value is something else other than 0
1765                                 # or 1, so return an error.
1767                                 kiriwrite_error("invalidoption");
1769                         }
1771                 }
1773                 return 0;
1775         }
1777         # Another type than the valid ones above has been specified so return an error specifying an invalid option.
1778         kiriwrite_error("invalidoption");
1782 sub kiriwrite_output_header{
1783 #################################################################################
1784 # kiriwrite_output_header: Outputs the header to the browser/stdout/console.    #
1785 #                                                                               #
1786 # Usage:                                                                        #
1787 #                                                                               #
1788 # kiriwrite_output_header();                                                    #
1789 #################################################################################
1791         # Print a header saying that the page expires immediately since the
1792         # date is set in the past.
1794         print "Expires: Sun, 01 Jan 2006 00:00:00 GMT\r\n";
1795         print "Content-Type: text/html; charset=utf-8;\r\n\r\n";
1796         return;
1799 sub kiriwrite_processfilename{
1800 #################################################################################
1801 # kiriwrite_processfilename: Processes a name and turns it into a filename that #
1802 # can be used by Kiriwrite.                                                     #
1803 #                                                                               #
1804 # Usage:                                                                        #
1805 #                                                                               #
1806 # kiriwrite_processfilename(text);                                              #
1807 #                                                                               #
1808 # text          Specifies the text to be used in the process for creating a new #
1809 #               filename.                                                       #
1810 #################################################################################
1812         # Get the values that have been passed to the subroutine.
1814         my ($process_text) = @_;
1816         # Define some variables that will be used later on.
1818         my $processed_stageone  = "";
1819         my $processed_stagetwo  = "";
1820         my $processed_length    = "";
1821         my $processed_char      = "";
1822         my $processed_seek      = 0;
1823         my $processed_filename  = "";
1825         # Set the first stage value of the processed filename to the
1826         # process filename and then filter it out to only contain
1827         # numbers and letters (no spaces) and then convert the
1828         # capitals to small letters.
1830         $processed_stageone = $process_text;
1831         $processed_stageone =~ tr#a-zA-Z0-9##cd;
1832         $processed_stageone =~ tr/A-Z/a-z/;
1834         # Now set the second stage value of the processed filename
1835         # to the first stage value of the processed filename and
1836         # then limit the filename down to 32 characters.
1838         $processed_stagetwo = $processed_stageone;
1839         $processed_length = length($processed_stagetwo);
1841         # Process the second stage filename into the final 
1842         # filename and do so until the seek counter is 32
1843         # or reaches the length of the second stage filename.
1845         do {
1847                 # Get the character that is the seek counter
1848                 # is set at.
1850                 $processed_char = substr($processed_stagetwo, $processed_seek, 1);
1852                 # Append to the final processed filename.
1854                 $processed_filename = $processed_filename . $processed_char;
1856                 # Increment the seek counter.
1858                 $processed_seek++;
1860         } until ($processed_seek eq 32 || $processed_seek eq $processed_length);
1862         return $processed_filename;
1866 sub kiriwrite_language{
1867 #################################################################################
1868 # kiriwrite_language: Process language strings that needs certain text inserted.#
1869 #                                                                               #
1870 # Usage:                                                                        #
1871 #                                                                               #
1872 # kiriwrite_language(string, [text, text, ...]);                                #
1873 #                                                                               #
1874 # string        Specifies the string to process.                                #
1875 # text          Specifies the text to pass to the string (can be repeated many  #
1876 #               times).                                                         #
1877 #################################################################################
1879         my $string = shift;
1880         my $item;
1882         foreach $item (@_){
1884                 $string =~ s/%s/$item/;
1886         }
1888         return $string;
1892 sub kiriwrite_error{
1893 #################################################################################
1894 # kiriwrite_error: Prints out an error message.                                 #
1895 #                                                                               #
1896 # Usage:                                                                        #
1897 #                                                                               #
1898 # kiriwrite_error(errortype, errorext);                                         #
1899 #                                                                               #
1900 # errortype     Specifies the type of error that occured.                       #
1901 # errorext      Specifies the extended error information.                       #
1902 #################################################################################
1904         # Get the error type from the subroutine.
1906         my ($error_type, $error_extended) = @_;
1908         # Disconnect from the database server.
1910         if ($kiriwrite_dbmodule){
1911                 $kiriwrite_dbmodule->disconnect();
1912         }
1914         # Load the list of error messages.
1916         my @kiriwrite_error = (
1918                 # Catch all error message.
1919                 "generic", 
1921                 # Standard error messages.
1922                 "blankfilename", "blankvariable", "fileexists", "internalerror", "invalidoption", "invalidaction", "invalidfilename", "invalidmode", "invalidutf8", "invalidvariable", "variabletoolong",
1924                 # Specific error messages.
1925                 "blankcompiletype", "blankdatabasepageadd", "blankdirectory", "blankfindfilter", "blankdatetimeformat", "browsenumbertoolong", "browsenumberinvalid",  "databaseconnectionerror", "databasecategoriestoolong", "databasecopysame", "databasealreadyexists", "datadirectorymissing", "datadirectoryinvalidpermissions", "databasedescriptiontoolong", "databasefilenameinvalid", "databasefilenametoolong", "databaseerror", "databaseinvalidpermissions", "databasenameinvalid", "databasenametoolong", "databasenameblank", "databasemissingfile", "databasemovemissingfile", "databasenorename", "databasemovesame", "dbmoduleblank", "dbmoduleinvalid", "dbdirectoryblank", "dbdirectoryinvalid", "dbmodulemissing", "filtercountinvalid", "filtercounttoolong", "filtersdatabasenotcreated", "filtersdbdatabaseerror", "filtersdbpermissions", "filtersdbmissing", "filteridblank", "filterdoesnotexist", "filteridinvalid", "filteridtoolong", "findfiltertoolong", "filterpriorityinvalid", "filterpriorityinvalidchars", "filterprioritytoolong", "invalidcompiletype", "invalidpagenumber", "nopagesselected",  "invaliddirectory", "invaliddatetimeformat", "invalidlanguagefilename", "languagefilenamemissing", "moduleblank", "moduleinvalid",      "newcopydatabasedatabaseerror", "newcopydatabasedoesnotexist", "newcopydatabasefileinvalidpermissions", "newmovedatabasedatabaseerror", "newmovedatabasedoesnotexist", "newmovedatabasefileinvalidpermissions", "nodatabasesavailable", "nodatabaseselected", "noeditvaluesselected", "oldcopydatabasedatabaseerror", "oldcopydatabasedoesnotexist", "oldcopydatabasefileinvalidpermissions", "oldmovedatabasedatabaseerror",   "oldmovedatabasedoesnotexist", "oldmovedatabasefileinvalidpermissions", "outputdirectoryblank", "outputdirectoryinvalid", "outputdirectorymissing", "outputdirectoryinvalidpermissions", "overridetemplatevalueinvalid", "overridetemplatetoolong", "overridetemplateinvalid",  "presmoduleblank", "presmoduleinvalid", "presmodulemissing", "pagecountinvalid", "pagecounttoolong",  "pagefilenamedoesnotexist", "pagefilenameexists", "pagefilenameinvalid", "pagefilenametoolong", "pagefilenameblank", "pagetitletoolong", "pagedescriptiontoolong", "pagesectiontoolong", "pagedatabasefilenametoolong", "pagesettingstoolong", "pagesettingsinvalid", "pagetemplatefilenametoolong", "replacefiltertoolong", "servernameinvalid", "servernametoolong", "serverdatabasenameinvalid", "serverdatabasenametoolong", "serverdatabaseusernameinvalid", "serverdatabaseusernametoolong", "serverdatabasepasswordtoolong", "serverdatabasetableprefixinvalid", "serverdatabasetableprefixtoolong", "serverportnumberinvalid", "serverportnumberinvalidcharacters", "serverportnumbertoolong", "serverprotocolnametoolong", "serverprotocolinvalid", "templatecountinvalid", "templatecounttoolong", "templatenameblank", "templatefilenameexists", "templatefilenameinvalid", "templatedatabaseerror", "templatedatabaseinvalidpermissions", "templatedatabaseinvalidformat", "templatedirectoryblank", "templatedirectoryinvalid", "templatedatabasenotcreated", "templatefilenametoolong", "templatenametoolong", "templatedescriptiontoolong", "templatedatabasemissing", "templatedoesnotexist", "templatefilenameblank", "textarearowblank", "textarearowtoolong", "textarearowinvalid", "textareacolblank", "textareacoltoolong", "textareacolinvalid"
1927         );
1929         # Check if the error message name is a valid error message name
1930         # and return the generic error message if it isn't.
1932         my $error_string = "";
1934         if (grep /^$error_type$/, @kiriwrite_error){
1936                 # The error type is valid so get the error language string
1937                 # associated with this error messsage name.
1939                 $error_string = $kiriwrite_lang->{error}->{$error_type};
1941         } else {
1943                 # The error type is invalid so set the error language
1944                 # string using the generic error message name.
1946                 $error_string = $kiriwrite_lang->{error}->{generic};
1948         }
1950         $kiriwrite_presmodule->clear();
1952         $kiriwrite_presmodule->startbox("errorbox");
1953         $kiriwrite_presmodule->addtext($kiriwrite_lang->{error}->{error}, { Style => "errorheader" });
1954         $kiriwrite_presmodule->addlinebreak();
1955         $kiriwrite_presmodule->addtext($error_string, { Style => "errortext" });
1957         # Check to see if extended error information was passed.
1959         if ($error_extended){
1961                 # Write the extended error information.
1963                 $kiriwrite_presmodule->addlinebreak();
1964                 $kiriwrite_presmodule->addlinebreak();
1965                 $kiriwrite_presmodule->addtext($kiriwrite_lang->{error}->{extendederror});
1966                 $kiriwrite_presmodule->addlinebreak();
1967                 $kiriwrite_presmodule->addlinebreak();
1968                 $kiriwrite_presmodule->startbox("datalist");
1969                 $kiriwrite_presmodule->addtext($error_extended);
1970                 $kiriwrite_presmodule->endbox();
1972         }
1974         $kiriwrite_presmodule->endbox();
1976         kiriwrite_output_header;
1977         kiriwrite_output_page($kiriwrite_lang->{error}->{error}, $kiriwrite_presmodule->grab(), "none");
1979         exit;
1983 sub kiriwrite_fileexists{
1984 #################################################################################
1985 # kiriwrite_fileexists: Check if a file exists and returns a value depending on #
1986 # if the file exists or not.                                                    #
1987 #                                                                               # 
1988 # Usage:                                                                        #
1989 #                                                                               #
1990 # kiriwrite_fileexists(filename);                                               #
1991 #                                                                               #
1992 # filename      Specifies the file name to check if it exists or not.           #
1993 #################################################################################
1995         # Get the value that was passed to the subroutine.
1997         my ($filename) = @_;
1999         # Check if the filename exists, if it does, return a value of 0, else
2000         # return a value of 1, meaning that the file was not found.
2002         if (-e $filename){
2004                 # Specified file does exist so return a value of 0.
2006                 return 0;
2008         } else {
2010                 # Specified file does not exist so return a value of 1.
2012                 return 1;
2014         }
2018 sub kiriwrite_filepermissions{
2019 #################################################################################
2020 # kiriwrite_filepermissions: Check if the file permissions of a file and return #
2021 # either a 1 saying that the permissions are valid or return a 0 saying that    #
2022 # the permissions are invalid.                                                  #
2023 #                                                                               #
2024 # Usage:                                                                        #
2025 #                                                                               #
2026 # kiriwrite_filepermissions(filename, [read], [write], [filemissingskip]);      #
2027 #                                                                               #
2028 # filename              Specifies the filename to check for permissions.        #
2029 # read                  Preform check that the file is readable.                #
2030 # write                 Preform check that the file is writeable.               #
2031 # filemissingskip       Skip the check of seeing if it can read or write if the #
2032 #                       file is missing.                                        #
2033 #################################################################################
2035         # Get the values that was passed to the subroutine.
2037         my ($filename, $readpermission, $writepermission, $ignorechecks) = @_;
2039         # Check to make sure that the read permission and write permission values
2040         # are only 1 character long.
2042         kiriwrite_variablecheck($readpermission, "maxlength", 1, 0);
2043         kiriwrite_variablecheck($writepermission, "maxlength", 1, 0);
2044         kiriwrite_variablecheck($ignorechecks, "maxlength", 1, 0);
2046         my $ignorechecks_result = 0;
2048         # Check if the file should be ignored for read and write checking if 
2049         # it doesn't exist.
2051         if ($ignorechecks){
2053                 if (-e $filename){
2055                         # The file exists so the checks are to be done.
2057                         $ignorechecks_result = 0;
2059                 } else {
2061                         # The file does not exist so the checks don't need to
2062                         # be done to prevent false positives.
2064                         $ignorechecks_result = 1;
2066                 }
2068         } else {
2070                 $ignorechecks_result = 0;
2072         }
2074         # Check if the file should be checked to see if it can be read.
2076         if ($readpermission && $ignorechecks_result eq 0){
2078                 # The file should be checked to see if it does contain read permissions
2079                 # and return a 0 if it is invalid.
2081                 if (-r $filename){
2083                         # The file is readable, so do nothing.
2085                 } else {
2087                         # The file is not readable, so return 1.
2089                         return 1;
2091                 }
2093         }
2095         # Check if the file should be checked to see if it can be written.
2097         if ($writepermission && $ignorechecks_result eq 0){
2099                 # The file should be checked to see if it does contain write permissions
2100                 # and return a 0 if it is invalid.
2102                 if (-w $filename){
2104                         # The file is writeable, so do nothing.
2106                 } else {
2108                         # The file is not writeable, so return 1.
2110                         return 1;
2112                 }
2114         }
2116         # No problems have occured, so return 0.
2118         return 0;
2122 sub kiriwrite_utf8convert{
2123 #################################################################################
2124 # kiriwrite_utf8convert: Properly converts values into UTF-8 values.            #
2125 #                                                                               #
2126 # Usage:                                                                        #
2127 #                                                                               #
2128 # utfstring     # The UTF-8 string to convert.                                  #
2129 #################################################################################
2131         # Get the values passed to the subroutine.
2133         my ($utfstring) = @_;
2135         # Load the Encode perl module.
2137         use Encode qw(decode_utf8);
2139         # Convert the string.
2141         my $finalutf8 = Encode::decode_utf8( $utfstring );
2143         return $finalutf8;
2144         #return $utfstring;
2148 sub kiriwrite_critical{
2149 #################################################################################
2150 # kiriwrite_critical: Displays an critical error message that cannot be         #
2151 # normally by the kiriwrite_error subroutine.                                   #
2152 #                                                                               #
2153 # Usage:                                                                        #
2154 #                                                                               #
2155 # errortype     Specifies the type of critical error that has occured.          #
2156 #################################################################################
2158         # Get the value that was passed to the subroutine.
2160         my ($error_type) = @_;
2162         my %error_list;
2164         # Get the error type from the errortype string.
2166         %error_list = (
2168                 # Generic critical error message.
2170                 "generic"                       => "A critical error has occured but the error is not known to Kiriwrite.",
2172                 # Specific critical error messages.
2174                 "configfilemissing"             => "The Kiriwrite configuration file is missing! Running the installer script for Kiriwrite is recommended.",
2175                 "configfileinvalidpermissions"  => "The Kiriwrite configuration file has invalid permission settings set! Please set the valid permission settings for the configuration file.",
2176                 "dbmodulemissing"               => "The database module is missing! Running the installer script for Kiriwrite is recommended.",
2177                 "dbmoduleinvalidpermissions"    => "The database module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the configuration file.",
2178                 "dbmoduleinvalid"               => "The database module name given is invalid. Running the installer script for Kiriwrite is recommended.",
2179                 "invalidvalue"                  => "An invalid value was passed.",
2180                 "languagefilenameblank"         => "The language filename given is blank! Running the installer script for Kiriwrite is recommended.",
2181                 "languagefilenameinvalid"       => "The language filename given is invalid! Running the installer script for Kiriwrite is recommended.",
2182                 "languagefilemissing"   => "The language filename given does not exist. Running the installer script for Kiriwrite is recommended.",
2183                 "languagefilenameinvalidpermissions"    => "The language file with the filename given has invalid permissions set. Please set the valid permission settings for the language file.",
2184                 "presmodulemissing"             => "The presentation module is missing! Running the installer script for Kiriwrite is recommended.",
2185                 "presmoduleinvalidpermissions"  => "The presentation module cannot be used as it has invalid permission settings set! Please set the valid permission settings for the presentation module.",
2186                 "presmoduleinvalid"             => "The presentation module name given is invalid. Running the installer script for Kiriwrite is recommended.",
2187                 "textarearowblank"              => "The text area row value given is blank. Running the installer script for Kiriwrite is recommended.",
2188                 "textarearowtoolong"            => "The text area row value is too long. Running the installer script for Kiriwrite is recommended.",
2189                 "textarearowinvalid"            => "The text area row value is invalid. Running the installer script for Kiriwrite is recommended.",
2190                 "textareacolblank"              => "The text area row value given is blank. Running the installer script for Kiriwrite is recommended.",
2191                 "textareacoltoolong"            => "The text area column value is too long. Running the installer script for Kiriwrite is recommended.",
2192                 "textareacolinvalid"            => "The text area column value is invalid. Running the installer script for Kiriwrite is recommended.",
2193                 "pagecountblank"                => "The page count value is blank. Running the installer script for Kiriwrite is recommended.",
2194                 "templatecountblank"            => "The template count value is blank. Running the installer script for Kiriwrite is recommended.",
2195                 "filtercountblank"              => "The filter count value is blank. Running the installer script for Kiriwrite is recommended.",
2196                 "pagecounttoolong"              => "The page count value is too long. Running the installer script for Kiriwrite is recommended.",
2197                 "templatecounttoolong"          => "The template count value is too long. Running the installer script for Kiriwrite is recommended.",
2198                 "filtercounttoolong"            => "The filter count value is too long. Running the installer script for Kiriwrite is recommended.",
2199                 "pagecountinvalid"              => "The page count value is invalid. Running the installer script for Kiriwrite is recommended.",
2200                 "templatecountinvalid"          => "The template count value is invalid. Running the installer script for Kiriwrite is recommended.",
2201                 "filtercountinvalid"            => "The filter count is invalid. Running the installer script for Kiriwrite is recommended."
2203         );
2205         if (!$error_list{$error_type}){
2207                 $error_type = "generic";
2209         }
2211         print "Expires: Sun, 01 Jan 2006 00:00:00 GMT\r\n";
2212         print "Content-Type: text/html; charset=utf-8;\r\n\r\n";
2213         print "Critical Error: " . $error_list{$error_type};
2214         exit;
2218 sub kiriwrite_output_page{
2219 #################################################################################
2220 # kiriwrite_output_page: Outputs the page to the browser/stdout/console.        #
2221 #                                                                               #
2222 # Usage:                                                                        #
2223 #                                                                               #
2224 # kiriwrite_output_page(pagetitle, pagedata, menutype);                         #
2225 #                                                                               #
2226 # pagetitle     Specifies the page title.                                       #
2227 # pagedata      Specifies the page data.                                        #
2228 # menutype      Prints out which menu to use.                                   #
2229 #################################################################################
2231         my ($pagetitle, $pagedata, $menutype) = @_;
2233         # Open the script page template and load it into the scriptpage variable,
2234         # while declaring the variable.
2236         open (my $filehandle_scriptpage, "<:utf8", 'page.html');
2237         my @scriptpage = <$filehandle_scriptpage>;
2238         binmode $filehandle_scriptpage, ':utf8';
2239         close ($filehandle_scriptpage);
2241         # Define the variables required.
2243         my $scriptpageline = "";
2244         my $pageoutput = "";
2245         my $menuoutput = "";
2247         $kiriwrite_presmodule->clear();
2249         # Print out the main menu for Kiriwrite.
2251         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db", { Text => $kiriwrite_lang->{menu}->{viewdatabases} });
2252         $kiriwrite_presmodule->addtext(" | ");
2253         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=page", { Text => $kiriwrite_lang->{menu}->{viewpages} });
2254         $kiriwrite_presmodule->addtext(" | ");
2255         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $kiriwrite_lang->{menu}->{viewfilters} });
2256         $kiriwrite_presmodule->addtext(" | ");
2257         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template", { Text => $kiriwrite_lang->{menu}->{viewtemplates} });
2258         $kiriwrite_presmodule->addtext(" | ");
2259         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $kiriwrite_lang->{menu}->{compilepages} });
2260         $kiriwrite_presmodule->addtext(" | ");
2261         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $kiriwrite_lang->{menu}->{viewsettings} });
2262         $kiriwrite_presmodule->addlinebreak();
2264         # Check what menu is going to be printed along with the default 'top' menu.
2266         if ($menutype eq "database"){
2268                 # If the menu type is database then print out the database sub-menu.
2270                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db", { Text => $kiriwrite_lang->{database}->{submenu_viewdatabases} });
2271                 $kiriwrite_presmodule->addtext(" | ");
2272                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=db&action=new", { Text => $kiriwrite_lang->{database}->{submenu_adddatabase} });
2274         } elsif ($menutype eq "pages"){
2275                 # If the menu type is pages then print out the pages sub-menu.
2277                 # First, fetch the database name from the HTTP query string.
2279                 my $db_filename = $form_data->{'database'};
2281                 # Check if a value has been placed in the db_filename string.
2283                 if (!$db_filename){
2285                         # As the database filename is blank, don't add an option to add a page.
2287                 } else {
2289                         # A database file has been specified so add an option to add a page to
2290                         # the selected database.
2292                         $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=page&action=add&database="  . $db_filename, { Text => $kiriwrite_lang->{pages}->{submenu_addpage} });
2294                 }
2296         } elsif ($menutype eq "filter"){
2298                 # If the menu type is filters then print out the filter sub-menu.
2300                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter", { Text => $kiriwrite_lang->{filter}->{submenu_showfilters} });
2301                 $kiriwrite_presmodule->addtext(" | ");
2302                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=filter&action=add", { Text => $kiriwrite_lang->{filter}->{submenu_addfilter} });
2304         } elsif ($menutype eq "settings"){
2306                 # If the menu type is options then print out the options sub-menu.
2308                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings", { Text => $kiriwrite_lang->{setting}->{submenu_viewsettings} });
2309                 $kiriwrite_presmodule->addtext(" | ");
2310                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=settings&action=edit", { Text => $kiriwrite_lang->{setting}->{submenu_editsettings} });
2312         } elsif ($menutype eq "template"){
2314                 # If the menu type is template then print out the template sub-menu.
2316                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template", { Text => $kiriwrite_lang->{template}->{submenu_showtemplates} });
2317                 $kiriwrite_presmodule->addtext(" | ");
2318                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=template&action=add", { Text => $kiriwrite_lang->{template}->{submenu_addtemplate} });
2320         } elsif ($menutype eq "compile"){
2322                 # If the menu type is compile then print out the compile sub-menu.
2324                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile", { Text => $kiriwrite_lang->{compile}->{submenu_listdatabases} });
2325                 $kiriwrite_presmodule->addtext(" | ");
2326                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile&action=all", { Text => $kiriwrite_lang->{compile}->{submenu_compileall} });
2327                 $kiriwrite_presmodule->addtext(" | ");
2328                 $kiriwrite_presmodule->addlink($kiriwrite_env{'script_filename'} . "?mode=compile&action=clean", { Text => $kiriwrite_lang->{compile}->{submenu_cleanoutputdirectory} });
2330         }
2332         $menuoutput = $kiriwrite_presmodule->grab();
2334         # Find <kiriwrite> tages and replace with the apporiate variables.
2336         foreach $scriptpageline (@scriptpage){
2338                 $scriptpageline =~ s/<kiriwrite:menu>/$menuoutput/g;
2339                 $scriptpageline =~ s/<kiriwrite:imagespath>/$kiriwrite_config{"directory_noncgi_images"}/g;
2340                 $scriptpageline =~ s/<kiriwrite:pagedata>/$pagedata/g;
2342                 # Check if page title specified is blank, otherwise add a page title
2343                 # to the title.
2345                 if ($pagetitle eq ""){
2346                         $scriptpageline =~ s/<kiriwrite:title>//g;
2347                 } else {
2348                         $scriptpageline =~ s/<kiriwrite:title>/ ($pagetitle)/g;
2349                 }
2351                 
2353                 # Append processed line to the pageoutput variable.
2355                 $pageoutput = $pageoutput . $scriptpageline;
2357         }
2359         print $pageoutput;
2361         return;
2365 #################################################################################
2366 # End listing the functions needed.                                             #
2367 #################################################################################
2369 #################################################################################
2370 # Begin proper script execution.                                                #
2371 #################################################################################
2373 kiriwrite_settings_load;        # Load the configuration options.
2375 my $query_lite = new CGI::Lite;
2377 # Check if a mode has been specified and if a mode has been specified, continue
2378 # and work out what mode has been specified.
2380 $form_data = $query_lite->parse_form_data;
2382 if ($form_data->{'mode'}){
2383         my $http_query_mode = $form_data->{'mode'};
2385         if ($http_query_mode eq "db"){
2387                 # If mode is 'db' (database), then load the database perl library and
2388                 # check what action is required.
2390                 require "./lib/database.lib";
2392         } elsif ($http_query_mode eq "page"){
2394                 # If mode is 'page', load the page library and then check what 
2395                 # action is required.
2397                 require "./lib/page.lib";
2399         } elsif ($http_query_mode eq "filter"){
2401                 # Load the filter perl library and then check the
2402                 # value of the action HTTP query.
2404                 require "./lib/filter.lib";
2406         } elsif ($http_query_mode eq "template"){
2408                 # Load the template perl library and check if an action has
2409                 # been specified in the HTTP query.
2411                 require "./lib/template.lib";
2413         } elsif ($http_query_mode eq "compile"){
2415                 # Load the compile perl library.
2417                 require "./lib/compile.lib";
2419         } elsif ($http_query_mode eq "settings"){
2421                 # Load the settings perl library.
2423                 require "./lib/settings.lib";
2425         } else {
2426                 # Another mode has been specified than the ones above, so return an error saying that
2427                 # an invalid option was specified.
2429                 kiriwrite_error("invalidmode");
2430         }
2432 } else {
2434         # No mode has been specified, so print the default "first-run" view of the
2435         # database list.
2437         require "./lib/database.lib";
2439         my $pagedata = kiriwrite_database_list();
2441         kiriwrite_output_header;                # Output the header to browser/console/stdout.
2442         kiriwrite_output_page("", $pagedata, "database");       # Output the page to browser/console/stdout.
2443         exit;                                   # End the script.
2447 __END__
2449 =head1 NAME
2451 Kiriwrite
2453 =head1 DESCRIPTION
2455 Web-based webpage compiler.
2457 =head1 AUTHOR
2459 Steve Brokenshire <sbrokenshire@xestia.co.uk>
2461 =head1 USAGE
2463 This perl script is intended to be used on a web server which has CGI with Perl support or with mod_perl support.
2465 =head1 DOCUMENTATION
2467 For more information on how to use Kiriwrite, please see the documentation that was included with Kiriwrite.
2469 - From the Xestia Documentation website: http://documentation.xestia.co.uk and click on the Kiriwrite link on the page.
2471 - From the Documentation directory from the Kiriwrite source packages (.tar/.tar.gz/.tar.bz2).
2473 - In the /usr/share/doc/kiriwrite directory if you installed the distribution-specific packages (and also have access to the server itself).
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