3 #################################################################################
4 # Kiriwrite (kiriwrite.cgi) #
5 # Main program script #
9 # Copyright (C) 2005-2007 Steve Brokenshire <sbrokenshire@xestia.co.uk> #
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. #
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.#
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.
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 = (
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
61 my $env_script_name_length = length($env_script_name);
62 my $filename_seek = 0;
63 my $filename_char = "";
64 my $filename_last = 0;
67 $filename_char = substr($env_script_name, $filename_seek, 1);
68 if ($filename_char eq "/"){
69 $filename_last = $filename_seek + 1;
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.
80 "script_filename" => $script_filename,
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. #
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.
108 # Define some values for later.
120 # Get the list of filenames.
124 # Get the values from id[]
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.
139 # Get the values from name[]
143 $selected = $form_data->{'name[' . $seek . ']'};
151 $selected_list[$seek] = $selected;
153 } until ($seek eq $count || $count eq 0);
155 # Create a final list of filenames to be used for
162 # Check if the selected value is on and include
163 # the filename in the final list.
167 $selected = $selected_list[$seek];
169 if ($selected eq "on"){
171 $filename = $filename_list[$seek];
172 $final_list[$final_count] = $filename;
177 } until ($seek eq $count || $count eq 0);
183 sub kiriwrite_settings_load{
184 #################################################################################
185 # kiriwrite_settings_load: Load the configuration settings into the global #
190 # kiriwrite_settings_load(); #
191 #################################################################################
193 # Load the required Perl modules.
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");
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");
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}
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
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");
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
306 kiriwrite_critical("presmoduleblank");
310 if ($kiriwrite_config_presmodule_filename eq 2){
312 # The presentation module filename is invalid so return an
315 kiriwrite_critical("presmoduleinvalid");
319 if ($kiriwrite_config_dbmodule_filename eq 1){
321 # The database module filename given is blank so return an
324 kiriwrite_critical("dbmoduleblank");
328 if ($kiriwrite_config_dbmodule_filename eq 2){
330 # The database module filename given is invalid so return
333 kiriwrite_critical("dbmoduleinvalid");
337 # Check if the text area column and row values are blank and return a critical
340 if (!$kiriwrite_config{"display_textarearows"}){
342 # The text area row value is blank so return
345 kiriwrite_critical("textarearowblank");
349 if (!$kiriwrite_config{"display_textareacols"}){
351 # The text area column value is blank so return
354 kiriwrite_critical("textareacolblank");
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
366 kiriwrite_critical("textarearowtoolong");
370 if ($kiriwrite_config_textarearows_number eq 1){
372 # The text area row value is invalid so return an
375 kiriwrite_critical("textarearowinvalid");
379 if ($kiriwrite_config_textareacols_maxlength eq 1){
381 # The text area column value is too long so return
384 kiriwrite_critical("textareacoltoolong");
388 if ($kiriwrite_config_textareacols_number eq 1){
390 # The text area column value is invalid so return
393 kiriwrite_critical("textareacolinvalid");
397 # Check if the amount of items per view settings are blank and return a critical
400 if (!$kiriwrite_config{"display_pagecount"}){
402 # The display page count is blank so return a
405 kiriwrite_critical("pagecountblank");
409 if (!$kiriwrite_config{"display_templatecount"}){
411 # The display template count is blank so return
414 kiriwrite_critical("templatecountblank");
418 if (!$kiriwrite_config{"display_filtercount"}){
420 # The display filter count is blank so return a
423 kiriwrite_critical("filtercountblank");
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");
439 if ($kiriwrite_config_pagecount_number eq 1){
441 # The page count value is invalid so return
444 kiriwrite_critical("pagecountinvalid");
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");
457 if ($kiriwrite_config_templatecount_number eq 1){
459 # The template count value is invalid so return
462 kiriwrite_critical("filtercountinvalid");
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");
475 if ($kiriwrite_config_filtercount_number eq 1){
477 # The filter count value is invalid so return
480 kiriwrite_critical("templatecountinvalid");
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");
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");
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");
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");
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");
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");
566 # Include the Modules directory.
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"} });
594 sub kiriwrite_variablecheck{
595 #################################################################################
596 # kiriwrite_variablecheck: Checks the variables for any invalid characters. #
600 # kiriwrite_variablecheck(variable, type, length, noerror); #
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 #
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.
626 # The variable is not blank, so check if the no error value is set
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).
637 } elsif ($variable_noerror eq 0) {
639 # The validated variable is not blank and the noerror
642 kiriwrite_error("invalidvariable");
646 # The variable noerror value is something else
647 # pther than 1 or 0. So return an error.
649 kiriwrite_error("invalidvariable");
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.
669 # The variable is not blank, so check if the no error value is set
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).
680 } elsif ($variable_noerror eq 0) {
682 # The validated variable is not blank and the noerror
685 kiriwrite_error("invalidvariable");
689 # The variable noerror value is something else
690 # pther than 1 or 0. So return an error.
692 kiriwrite_error("invalidvariable");
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
706 my $variable_data_length = 0;
708 if (!$variable_data){
710 # Set variable_data_length to '0'.
711 $variable_data_length = 0;
715 # Get the length of the variable recieved.
716 $variable_data_length = length($variable_data);
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).
735 } elsif ($variable_noerror eq 0){
737 # The no error value is set to 0, so return
740 kiriwrite_error("variabletoolong");
744 # The no error value is something else other
745 # than 0 or 1, so return an error.
747 kiriwrite_error("variabletoolong");
753 # The variable length is exactly or shorter than specified, so continue to end of this section where
754 # the return function should be.
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
776 } elsif ($variable_noerror eq 0){
778 # The no error value is set to 0, so return
781 kiriwrite_error("blankvariable");
785 # The no error value is something else other
786 # than 0 or 1, so return an error.
788 kiriwrite_error("invalidvariable");
796 } elsif ($variable_type eq "filename"){
797 # Check for letters and numbers, if anything else than letters and numbers is there (including spaces) return
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
815 } elsif ($variable_noerror eq 0){
817 # The no error value is set to 1 so return
820 kiriwrite_error("blankfilename");
824 # The no error value is something else other
825 # than 0 or 1, so return an error.
827 kiriwrite_error("invalidvariable");
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.
850 # The validated data variable is not blank, meaning
851 # that it contains something else, so return an error
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
863 } elsif ($variable_noerror eq 0){
865 # The no error value is set to 0 so return
868 kiriwrite_error("invalidfilename");
872 # The no error value is something else other
873 # than 0 or 1 so return an error.
875 kiriwrite_error("invalidvariable");
883 } elsif ($variable_type eq "filenameindir"){
884 # Check if the filename is in the directory and return an
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
900 } elsif ($variable_noerror eq 0){
902 # The no error value is set to 1 so return
905 kiriwrite_error("blankfilename");
909 # The no error value is something else other
910 # than 0 or 1, so return an error.
912 kiriwrite_error("invalidvariable");
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.
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
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
972 kiriwrite_error("invalidfilename");
976 # The no error value is something else other
977 # than 0 or 1 so return an error.
979 kiriwrite_error("invalidvariable");
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;
994 # Append the current character to the directory name and to the current
997 $variable_database_list = $variable_database_list . $variable_data_char;
998 $variable_database_listcurrent = $variable_database_listcurrent . $variable_data_char;
1002 # Increment the seek counter.
1004 $variable_data_seek++;
1006 } until ($variable_data_seek eq $variable_data_length);
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).
1023 } elsif ($variable_noerror eq 0){
1025 # The no error value is set to 1 so return
1028 kiriwrite_error("blankdatetimeformat");
1032 # The no error value is something else other
1033 # than 0 or 1, so return an error.
1035 kiriwrite_error("invalidvariable");
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
1051 # The validated data variable is not blank, meaning
1052 # that it contains something else, so return an error
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).
1063 } elsif ($variable_noerror eq 0){
1065 # The no error value is set to 0 so return
1068 kiriwrite_error("invaliddatetimeformat");
1072 # The no error value is something else other
1073 # than 0 or 1 so return an error.
1075 kiriwrite_error("invalidvariable");
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
1100 } elsif ($variable_noerror eq 0){
1102 # The no error value is set to 1 so return
1105 kiriwrite_error("blankdirectory");
1109 # The no error value is something else other
1110 # than 0 or 1, so return an error.
1112 kiriwrite_error("invalidvariable");
1118 if ($variable_data_validated eq ""){
1120 # The validated data variable is blank, meaning that
1121 # it only contains letters and numbers.
1125 # The validated data variable is not blank, meaning
1126 # that it contains something else, so return an error
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
1137 } elsif ($variable_noerror eq 0){
1139 # The no error value is set to 0 so return
1142 kiriwrite_error("invaliddirectory");
1146 # The no error value is something else other
1147 # than 0 or 1 so return an error.
1149 kiriwrite_error("invalidvariable");
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).
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");
1185 # The noerror value is something else other
1186 # than 0 or 1 so return an error.
1188 kiriwrite_error("invalidvariable");
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);
1206 # Get a character from the language filename passed to this
1207 # subroutine and the character the seek counter value is set
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
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
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");
1240 # The noerror value is something else other than
1241 # 1 or 0 so return an error.
1243 kiriwrite_error("invalidvariable");
1249 # Increment the seek counter.
1251 $variable_data_seek++;
1253 } until ($variable_data_seek eq $variable_data_length);
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.
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
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");
1290 # The no error value is something else other
1291 # than 0 or 1 so return an error.
1293 kiriwrite_error("invalidvariable");
1301 } elsif ($variable_type eq "page_filename"){
1303 # The variable type is a page filename type. Check
1304 # if the data is empty and if it is then return an
1307 if ($variable_data eq ""){
1309 # The filename is blank so check the no error
1310 # value and depending on it return an value
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).
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");
1330 # The no error value is something else other
1331 # than 0 or 1 so return an error.
1333 kiriwrite_error("invalidvariable");
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
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
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
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
1381 kiriwrite_error("invalidfilename");
1385 # The no error value is something else other
1386 # than 0 or 1 so return an error.
1388 kiriwrite_error("invalidvariable");
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.
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
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
1433 kiriwrite_error("invalidfilename");
1437 # The no error value is something else other
1438 # than 0 or 1 so return an error.
1440 kiriwrite_error("invalidvariable");
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;
1455 # Append the current character to the directory name and to the current
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;
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
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).
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");
1494 # The no error value is something else other
1495 # than 0 or 1 so return an error.
1497 kiriwrite_error("invalidvariable");
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
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
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).
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");
1535 # The no error value is something else other
1536 # than 0 or 1 so return an error.
1538 kiriwrite_critical("invalidvalue");
1546 my $variable_data_validated = $variable_data;
1547 $variable_data_validated =~ tr/a-zA-Z0-9//d;
1549 if ($variable_data_validated eq ""){
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
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
1568 kiriwrite_critical("moduleinvalid");
1572 # The no error value is something else other
1573 # than 0 or 1 so return an error.
1575 kiriwrite_error("invalidvalue");
1583 } elsif ($variable_type eq "utf8"){
1585 # The variable type is a UTF8 string.
1587 if (!$variable_data){
1589 $variable_data = "";
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
1613 # The UTF-8 string is valid.
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.
1620 if ($variable_noerror eq 1){
1622 # The no error value has been set to 1, so return
1623 # a value of 1 (meaning that the UTF-8 string is
1628 } elsif ($variable_noerror eq 0) {
1630 # The no error value has been set to 0, so return
1633 kiriwrite_error("invalidutf8");
1637 # The no error value is something else other than 0
1638 # or 1, so return an error.
1640 kiriwrite_error("invalidoption");
1647 $chunk = $chunk + $process;
1651 # # Check if the string is a valid UTF8 string.
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
1664 # # The UTF-8 string is valid.
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.
1671 # if ($variable_noerror eq 1){
1673 # # The no error value has been set to 1, so return
1674 # # a value of 1 (meaning that the UTF-8 string is
1679 # } elsif ($variable_noerror eq 0) {
1681 # # The no error value has been set to 0, so return
1684 # kiriwrite_error("invalidutf8");
1688 # # The no error value is something else other than 0
1689 # # or 1, so return an error.
1691 # kiriwrite_error("invalidoption");
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
1717 } elsif ($variable_noerror eq 0){
1719 # The no error value has been set to 0, so return
1722 kiriwrite_error("serverprotocolinvalid");
1726 # The no error value is something else other than 0
1727 # or 1, so return an error.
1729 kiriwrite_error("invalidoption");
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).
1755 } elsif ($variable_noerror eq 0){
1757 # The no error value has been set to 0, so return
1760 kiriwrite_error("serverportnumberinvalid");
1764 # The no error value is something else other than 0
1765 # or 1, so return an error.
1767 kiriwrite_error("invalidoption");
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. #
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";
1799 sub kiriwrite_processfilename{
1800 #################################################################################
1801 # kiriwrite_processfilename: Processes a name and turns it into a filename that #
1802 # can be used by Kiriwrite. #
1806 # kiriwrite_processfilename(text); #
1808 # text Specifies the text to be used in the process for creating a new #
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.
1847 # Get the character that is the seek counter
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.
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.#
1872 # kiriwrite_language(string, [text, text, ...]); #
1874 # string Specifies the string to process. #
1875 # text Specifies the text to pass to the string (can be repeated many #
1877 #################################################################################
1884 $string =~ s/%s/$item/;
1892 sub kiriwrite_error{
1893 #################################################################################
1894 # kiriwrite_error: Prints out an error message. #
1898 # kiriwrite_error(errortype, errorext); #
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();
1914 # Load the list of error messages.
1916 my @kiriwrite_error = (
1918 # Catch all error message.
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"
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};
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};
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();
1974 $kiriwrite_presmodule->endbox();
1976 kiriwrite_output_header;
1977 kiriwrite_output_page($kiriwrite_lang->{error}->{error}, $kiriwrite_presmodule->grab(), "none");
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. #
1990 # kiriwrite_fileexists(filename); #
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.
2004 # Specified file does exist so return a value of 0.
2010 # Specified file does not exist so return a value of 1.
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. #
2026 # kiriwrite_filepermissions(filename, [read], [write], [filemissingskip]); #
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
2055 # The file exists so the checks are to be done.
2057 $ignorechecks_result = 0;
2061 # The file does not exist so the checks don't need to
2062 # be done to prevent false positives.
2064 $ignorechecks_result = 1;
2070 $ignorechecks_result = 0;
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.
2083 # The file is readable, so do nothing.
2087 # The file is not readable, so return 1.
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.
2104 # The file is writeable, so do nothing.
2108 # The file is not writeable, so return 1.
2116 # No problems have occured, so return 0.
2122 sub kiriwrite_utf8convert{
2123 #################################################################################
2124 # kiriwrite_utf8convert: Properly converts values into UTF-8 values. #
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 );
2148 sub kiriwrite_critical{
2149 #################################################################################
2150 # kiriwrite_critical: Displays an critical error message that cannot be #
2151 # normally by the kiriwrite_error subroutine. #
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) = @_;
2164 # Get the error type from the errortype string.
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."
2205 if (!$error_list{$error_type}){
2207 $error_type = "generic";
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};
2218 sub kiriwrite_output_page{
2219 #################################################################################
2220 # kiriwrite_output_page: Outputs the page to the browser/stdout/console. #
2224 # kiriwrite_output_page(pagetitle, pagedata, menutype); #
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.
2285 # As the database filename is blank, don't add an option to add a page.
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} });
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} });
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
2345 if ($pagetitle eq ""){
2346 $scriptpageline =~ s/<kiriwrite:title>//g;
2348 $scriptpageline =~ s/<kiriwrite:title>/ ($pagetitle)/g;
2353 # Append processed line to the pageoutput variable.
2355 $pageoutput = $pageoutput . $scriptpageline;
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";
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");
2434 # No mode has been specified, so print the default "first-run" view of the
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.
2455 Web-based webpage compiler.
2459 Steve Brokenshire <sbrokenshire@xestia.co.uk>
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).