3 #################################################################################
4 # Kiriwrite Installer Script (install.cgi) #
5 # Installation script for Kiriwrite #
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.
28 use CGI qw(:standard *table *Tr *td);
29 #use CGI::Carp('fatalsToBrowser'); # Output errors to the browser.
31 # Setup strings in specific languages. Style should be no spacing for
32 # language title and one tabbed spacing for each string.
34 # Define some default settings.
36 my $default_language = "en-GB";
37 my $default_dbdirectory = "db";
38 my $default_outputdirectory = "output";
39 my $default_imagesuri = "/images/kiriwrite";
41 my $default_server = "localhost";
42 my $default_port = "3306";
43 my $default_protocol = "tcp";
44 my $default_name = "database";
45 my $default_username = "username";
46 my $default_prefix = "kiriwrite";
48 my ($kiriwrite_lang, %kiriwrite_lang);
50 $kiriwrite_lang{"en-GB"}{"languagename"} = "English (British)";
51 $kiriwrite_lang{"en-GB"}{"testpass"} = "OK";
52 $kiriwrite_lang{"en-GB"}{"testfail"} = "Error";
54 $kiriwrite_lang{"en-GB"}{"generic"} = "An error occured which is not known to the Kiriwrite installer.";
55 $kiriwrite_lang{"en-GB"}{"invalidvariable"} = "The variable given was invalid.";
56 $kiriwrite_lang{"en-GB"}{"invalidvalue"} = "The value given was invalid.";
57 $kiriwrite_lang{"en-GB"}{"invalidoption"} = "The option given was invalid.";
58 $kiriwrite_lang{"en-GB"}{"variabletoolong"} = "The variable given is too long.";
59 $kiriwrite_lang{"en-GB"}{"blankdirectory"} = "The directory name given is blank.";
60 $kiriwrite_lang{"en-GB"}{"invaliddirectory"} = "The directory name given is invalid.";
61 $kiriwrite_lang{"en-GB"}{"moduleblank"} = "The module filename given is blank.";
62 $kiriwrite_lang{"en-GB"}{"moduleinvalid"} = "The module filename given is invalid.";
64 $kiriwrite_lang{"en-GB"}{"dbdirectorytoolong"} = "The database directory name given is too long.";
65 $kiriwrite_lang{"en-GB"}{"outputdirectorytoolong"} = "The output directory name given is too long.";
66 $kiriwrite_lang{"en-GB"}{"imagesuripathtoolong"} = "The images URI path name given is too long.";
67 $kiriwrite_lang{"en-GB"}{"dateformattoolong"} = "The date format given is too long.";
68 $kiriwrite_lang{"en-GB"}{"customdateformattoolong"} = "The custom date format given is too long.";
69 $kiriwrite_lang{"en-GB"}{"languagefilenametoolong"} = "The language filename given is too long.";
71 $kiriwrite_lang{"en-GB"}{"dateformatblank"} = "The date format given was blank.";
72 $kiriwrite_lang{"en-GB"}{"dateformatinvalid"} = "The date format given is invalid.";
73 $kiriwrite_lang{"en-GB"}{"languagefilenameinvalid"} = "The language filename given is invalid.";
75 $kiriwrite_lang{"en-GB"}{"dbdirectoryblank"} = "The database directory name given is blank.";
76 $kiriwrite_lang{"en-GB"}{"dbdirectoryinvalid"} = "The database directory name given is invalid.";
78 $kiriwrite_lang{"en-GB"}{"outputdirectoryblank"} = "The output directory name given is blank.";
79 $kiriwrite_lang{"en-GB"}{"outputdirectoryinvalid"} = "The output directory name given is invalid.";
81 $kiriwrite_lang{"en-GB"}{"presmoduleblank"} = "The presentation module name given is blank.";
82 $kiriwrite_lang{"en-GB"}{"presmoduleinvalid"} = "The presentation module name given is invalid.";
84 $kiriwrite_lang{"en-GB"}{"dbmoduleblank"} = "The database module name given is blank.";
85 $kiriwrite_lang{"en-GB"}{"dbmoduleinvalid"} = "The database module name given is invalid.";
87 $kiriwrite_lang{"en-GB"}{"presmodulemissing"} = "The presentation module with the filename given is missing.";
88 $kiriwrite_lang{"en-GB"}{"dbmodulemissing"} = "The database module with the filename given is missing.";
89 $kiriwrite_lang{"en-GB"}{"languagefilemissing"} = "The language file with the filename given is missing.";
91 $kiriwrite_lang{"en-GB"}{"servernametoolong"} = "The database server name given is too long.";
92 $kiriwrite_lang{"en-GB"}{"servernameinvalid"} = "The database server name given is invalid.";
93 $kiriwrite_lang{"en-GB"}{"serverportnumbertoolong"} = "The database server port number given is too long.";
94 $kiriwrite_lang{"en-GB"}{"serverportnumberinvalidcharacters"} = "The database server port number given contains invalid characters.";
95 $kiriwrite_lang{"en-GB"}{"serverportnumberinvalid"} = "The database server port number given is invalid.";
96 $kiriwrite_lang{"en-GB"}{"serverprotocolnametoolong"} = "The database server protocol name given is too long.";
97 $kiriwrite_lang{"en-GB"}{"serverprotocolinvalid"} = "The database server protocol name is invalid.";
98 $kiriwrite_lang{"en-GB"}{"serverdatabasenametoolong"} = "The database name given is too long.";
99 $kiriwrite_lang{"en-GB"}{"serverdatabasenameinvalid"} = "The database name given is invalid.";
100 $kiriwrite_lang{"en-GB"}{"serverdatabaseusernametoolong"} = "The database server username given is too long.";
101 $kiriwrite_lang{"en-GB"}{"serverdatabaseusernameinvalid"} = "The database server username given is invalid.";
102 $kiriwrite_lang{"en-GB"}{"serverdatabasepasswordtoolong"} = "The database server password is too long.";
103 $kiriwrite_lang{"en-GB"}{"serverdatabasetableprefixtoolong"} = "The database server table prefix given is too long.";
104 $kiriwrite_lang{"en-GB"}{"serverdatabasetableprefixinvalid"} = "The database server table prefix given is invalid.";
106 $kiriwrite_lang{"en-GB"}{"removeinstallscripttoolong"} = "The remove install script value given is too long.";
107 $kiriwrite_lang{"en-GB"}{"cannotwriteconfigurationindirectory"} = "The configuration file cannot be written because the directory the install script is running from has invalid permissions.";
108 $kiriwrite_lang{"en-GB"}{"configurationfilereadpermissionsinvalid"} = "The configuration that currently exists has invalid read permissions set.";
109 $kiriwrite_lang{"en-GB"}{"configurationfilewritepermissionsinvalid"} = "The configuration that currently exists has invalid write permissions set.";
111 $kiriwrite_lang{"en-GB"}{"errormessagetext"} = "Please press the back button on your browser or preform the command needed to return to the previous page.";
113 $kiriwrite_lang{"en-GB"}{"switch"} = "Switch";
114 $kiriwrite_lang{"en-GB"}{"setting"} = "Setting";
115 $kiriwrite_lang{"en-GB"}{"value"} = "Value";
116 $kiriwrite_lang{"en-GB"}{"filename"} = "Filename";
117 $kiriwrite_lang{"en-GB"}{"module"} = "Module";
118 $kiriwrite_lang{"en-GB"}{"result"} = "Result";
119 $kiriwrite_lang{"en-GB"}{"error"} = "Error!";
120 $kiriwrite_lang{"en-GB"}{"criticalerror"} = "Critical Error!";
121 $kiriwrite_lang{"en-GB"}{"errormessage"} = "Error: ";
122 $kiriwrite_lang{"en-GB"}{"warningmessage"} = "Warning: ";
124 $kiriwrite_lang{"en-GB"}{"doesnotexist"} = "Does not exist.";
125 $kiriwrite_lang{"en-GB"}{"invalidpermissionsset"} = "Invalid permissions set.";
127 $kiriwrite_lang{"en-GB"}{"dependencyperlmodulesmissing"} = "One or more Perl modules that are needed by Kiriwrite are not installed or has problems. See the Kiriwrite documentation for more information on this.";
128 $kiriwrite_lang{"en-GB"}{"databaseperlmodulesmissing"} = "One or more Perl modules that are needed by the Kiriwrite database modules are not installed or has problems. See the Kiriwrite documentation for more information on this. There should however, be no problems with the database modules which use the Perl modules that have been found.";
129 $kiriwrite_lang{"en-GB"}{"filepermissionsinvalid"} = "One or more of the filenames checked does not exist or has invalid permissions set. See the Kiriwrite documentation for more information on this.";
130 $kiriwrite_lang{"en-GB"}{"dependencymodulesnotinstalled"} = "One of the required Perl modules is not installed or has errors. See the Kiriwrite documentation for more information on this.";
131 $kiriwrite_lang{"en-GB"}{"databasemodulesnotinstalled"} = "None of Perl modules that are used by the database modules are not installed. See the Kiriwrite documentation for more information on this.";
132 $kiriwrite_lang{"en-GB"}{"filepermissionerrors"} = "One or more filenames checked has errors. See the Kiriwrite documentation for more information on this.",
134 $kiriwrite_lang{"en-GB"}{"installertitle"} = "Kiriwrite Installer";
135 $kiriwrite_lang{"en-GB"}{"installertext"} = "This installer script will setup the configuration file used for Kiriwrite. The settings displayed here can be changed at a later date by selecting the Edit Settings link in the View Settings sub-menu.";
136 $kiriwrite_lang{"en-GB"}{"dependencytitle"} = "Dependency and file testing results";
137 $kiriwrite_lang{"en-GB"}{"requiredmodules"} = "Required Modules";
138 $kiriwrite_lang{"en-GB"}{"perlmodules"} = "These Perl modules are used internally by Kiriwrite.";
139 $kiriwrite_lang{"en-GB"}{"databasemodules"} = "Database Modules";
140 $kiriwrite_lang{"en-GB"}{"databasemodulestext"} = "These Perl modules are used by the database modules.";
141 $kiriwrite_lang{"en-GB"}{"filepermissions"} = "File permissions";
142 $kiriwrite_lang{"en-GB"}{"filepermissionstext"} = "The file permissions are for file and directories that are critical to Kiriwrite such as module and language directories.";
144 $kiriwrite_lang{"en-GB"}{"settingstitle"} = "Kiriwrite Settings";
145 $kiriwrite_lang{"en-GB"}{"settingstext"} = "The settings given here will be used by Kiriwrite. Some default settings are given here. Certain database modules (like SQLite) do not need the database server settings and can be left alone.";
146 $kiriwrite_lang{"en-GB"}{"directories"} = "Directories";
147 $kiriwrite_lang{"en-GB"}{"databasedirectory"} = "Database Directory";
148 $kiriwrite_lang{"en-GB"}{"outputdirectory"} = "Output Directory";
149 $kiriwrite_lang{"en-GB"}{"imagesuripath"} = "Images (URI path)";
150 $kiriwrite_lang{"en-GB"}{"date"} = "Date";
151 $kiriwrite_lang{"en-GB"}{"dateformat"} = "Date Format";
152 $kiriwrite_lang{"en-GB"}{"language"} = "Language";
153 $kiriwrite_lang{"en-GB"}{"systemlanguage"} = "System Language";
154 $kiriwrite_lang{"en-GB"}{"modules"} = "Modules";
155 $kiriwrite_lang{"en-GB"}{"presentationmodule"} = "Presentation Module";
156 $kiriwrite_lang{"en-GB"}{"databasemodule"} = "Database Module";
157 $kiriwrite_lang{"en-GB"}{"databaseserver"} = "Database Server";
158 $kiriwrite_lang{"en-GB"}{"databaseport"} = "Database Port";
159 $kiriwrite_lang{"en-GB"}{"databaseprotocol"} = "Database Protocol";
160 $kiriwrite_lang{"en-GB"}{"databasename"} = "Database Name";
161 $kiriwrite_lang{"en-GB"}{"databaseusername"} = "Database Username";
162 $kiriwrite_lang{"en-GB"}{"databasepassword"} = "Database Password";
163 $kiriwrite_lang{"en-GB"}{"databasetableprefix"} = "Database Table Prefix";
164 $kiriwrite_lang{"en-GB"}{"installationoptions"} = "Installation Options";
165 $kiriwrite_lang{"en-GB"}{"installoptions"} = "Install Options";
166 $kiriwrite_lang{"en-GB"}{"removeinstallscript"} = "Delete this installer script after configuration file has been written.";
167 $kiriwrite_lang{"en-GB"}{"savesettingsbutton"} = "Save Settings";
168 $kiriwrite_lang{"en-GB"}{"resetsettingsbutton"} = "Reset Settings";
170 $kiriwrite_lang{"en-GB"}{"installscriptremoved"} = "The installer script was removed.";
171 $kiriwrite_lang{"en-GB"}{"installedmessage"} = "The configuration file for Kiriwrite has been written. To change the settings in the configuration file at a later date use the Edit Settings link in the View Settings sub-menu at the top of the page when using Kiriwrite.";
172 $kiriwrite_lang{"en-GB"}{"cannotremovescript"} = "Unable to remove the installer script: %s. The installer script will have to be deleted manually.";
173 $kiriwrite_lang{"en-GB"}{"usekiriwritetext"} = "To use Kiriwrite click or select the link below (will not work if the Kiriwrite script is not called kiriwrite.cgi):";
174 $kiriwrite_lang{"en-GB"}{"usekiriwritelink"} = "Start using Kiriwrite.";
178 my $language_selected = "";
179 my $http_query_confirm = $query->param('confirm');
180 my $http_query_installlanguage = $query->param('installlanguage');
182 if (!$http_query_installlanguage){
184 $language_selected = $default_language;
188 $language_selected = $http_query_installlanguage;
192 # Process the list of available languages.
194 my $language_list_name;
195 my @language_list_short;
196 my @language_list_long;
198 foreach my $language (keys %kiriwrite_lang){
200 $language_list_name = $kiriwrite_lang{$language}{"languagename"} . " (" . $language . ")";
201 push(@language_list_short, $language);
202 push(@language_list_long, $language_list_name);
206 # The CSS Stylesheet to use.
215 background-color: #408080;
217 font-family: sans-serif;
222 background-color: #408080;
224 border-color: #102020;
233 background-color: #408080;
235 border-color: #102020;
247 background-color: #204040;
253 background-color: #204040;
257 background-color: #204040;
262 background-color: #357070;
267 background-color: #306060;
274 #################################################################################
275 # Begin list of subroutines. #
276 #################################################################################
278 sub kiriwrite_variablecheck{
279 #################################################################################
280 # kiriwrite_variablecheck: Check to see if the data passed is valid. #
284 # kiriwrite_variablecheck(variablename, type, option, noerror); #
286 # variablename Specifies the variable to be checked. #
287 # type Specifies what type the variable is. #
288 # option Specifies the maximum/minimum length of the variable #
289 # (if minlength/maxlength is used) or if the filename should be #
290 # checked to see if it is blank. #
291 # noerror Specifies if Kiriwrite should return an error or not on #
293 #################################################################################
295 # Get the values that were passed to the subroutine.
297 my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
299 if ($variable_type eq "numbers"){
301 # Check for numbers and return an error if there is anything else than numebrs.
303 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated.
304 $variable_data_validated =~ tr/0-9//d; # Take away all of the numbers and from the variable.
305 # If it only contains numbers then it should be blank.
307 if ($variable_data_validated eq ""){
308 # The validated variable is blank. So continue to the end of this section where the return function should be.
310 # The variable is not blank, so check if the no error value is set
313 if ($variable_noerror eq 1){
315 # The validated variable is not blank and the noerror
316 # value is set to 1. So return an value of 1.
317 # (meaning that the data is invalid).
321 } elsif ($variable_noerror eq 0) {
323 # The validated variable is not blank and the noerror
326 kiriwrite_error("invalidvariable");
330 # The variable noerror value is something else
331 # pther than 1 or 0. So return an error.
333 kiriwrite_error("invalidvariable");
341 } elsif ($variable_type eq "lettersnumbers"){
343 # Check for letters and numbers and return an error if there is anything else other
344 # than letters and numbers.
346 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated
347 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
348 $variable_data_validated =~ s/\s//g;
350 if ($variable_data_validated eq ""){
351 # The validated variable is blank. So continue to the end of this section where the return function should be.
353 # The variable is not blank, so check if the no error value is set
356 if ($variable_noerror eq 1){
358 # The validated variable is not blank and the noerror
359 # value is set to 1. So return an value of 1.
360 # (meaning that the data is invalid).
364 } elsif ($variable_noerror eq 0) {
366 # The validated variable is not blank and the noerror
369 kiriwrite_error("invalidvariable");
373 # The variable noerror value is something else
374 # pther than 1 or 0. So return an error.
376 kiriwrite_error("invalidvariable");
384 } elsif ($variable_type eq "maxlength"){
385 # Check for the length of the variable, return an error if it is longer than the length specified.
387 # Check if the variable_data string is blank, if it is then set the variable_data_length
390 my $variable_data_length = 0;
392 if (!$variable_data){
394 # Set variable_data_length to '0'.
395 $variable_data_length = 0;
399 # Get the length of the variable recieved.
400 $variable_data_length = length($variable_data);
406 if ($variable_data_length > $variable_option){
408 # The variable length is longer than it should be so check if
409 # the no error value is set 1.
411 if ($variable_noerror eq 1){
413 # The no error value is set to 1, so return an
414 # value of 1 (meaning tha the variable is
415 # too long to be used).
419 } elsif ($variable_noerror eq 0){
421 # The no error value is set to 0, so return
424 kiriwrite_error("variabletoolong");
428 # The no error value is something else other
429 # than 0 or 1, so return an error.
431 kiriwrite_error("variabletoolong");
437 # The variable length is exactly or shorter than specified, so continue to end of this section where
438 # the return function should be.
444 } elsif ($variable_type eq "datetime"){
445 # Check if the date and time setting format is valid.
447 if ($variable_data eq ""){
449 if ($variable_noerror eq 1){
451 # The no error value is set to 1 so return
452 # a value of 1 (meaning that the date and
453 # time format was blank).
457 } elsif ($variable_noerror eq 0){
459 # The no error value is set to 1 so return
462 kiriwrite_error("dateformatblank");
466 # The no error value is something else other
467 # than 0 or 1, so return an error.
469 kiriwrite_error("invalidvariable");
475 my $variable_data_validated = $variable_data;
476 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
478 if ($variable_data_validated eq ""){
480 # The date and time format is valid. So
485 # The validated data variable is not blank, meaning
486 # that it contains something else, so return an error
489 if ($variable_noerror eq 1){
491 # The no error value is set to 1 so return
492 # an value of 2. (meaning that the date and
493 # time format was invalid).
497 } elsif ($variable_noerror eq 0){
499 # The no error value is set to 0 so return
502 kiriwrite_error("dateformatinvalid");
506 # The no error value is something else other
507 # than 0 or 1 so return an error.
509 kiriwrite_error("invalidvariable");
517 } elsif ($variable_type eq "directory"){
518 # Check if the directory only contains letters and numbers and
519 # return an error if anything else appears.
521 my $variable_data_validated = $variable_data;
522 $variable_data_validated =~ tr/a-zA-Z0-9//d;
524 if ($variable_data eq ""){
526 if ($variable_noerror eq 1){
528 # The no error value is set to 1 so return
529 # a value of 1 (meaning that the directory
534 } elsif ($variable_noerror eq 0){
536 # The no error value is set to 1 so return
539 kiriwrite_error("blankdirectory");
543 # The no error value is something else other
544 # than 0 or 1, so return an error.
546 kiriwrite_error("invalidvariable");
552 if ($variable_data_validated eq ""){
554 # The validated data variable is blank, meaning that
555 # it only contains letters and numbers.
559 # The validated data variable is not blank, meaning
560 # that it contains something else, so return an error
563 if ($variable_noerror eq 1){
565 # The no error value is set to 1 so return
566 # an value of 2. (meaning that the directory
571 } elsif ($variable_noerror eq 0){
573 # The no error value is set to 0 so return
576 kiriwrite_error("invaliddirectory");
580 # The no error value is something else other
581 # than 0 or 1 so return an error.
583 kiriwrite_error("invalidvariable");
591 } elsif ($variable_type eq "language_filename"){
593 # The variable type is a language filename type.
594 # Check if the language file name is blank and
595 # if it is then return an error (or value).
597 if ($variable_data eq ""){
599 # The language filename is blank so check the
600 # no error value and return an error (or value).
602 if ($variable_noerror eq 1){
604 # Language filename is blank and the no error value
605 # is set as 1, so return a value of 1 (saying that
606 # the language filename is blank).
610 } elsif ($variable_noerror eq 0) {
612 # Language filename is blank and the no error value
613 # is not set as 1, so return an error.
615 kiriwrite_error("languagefilenameblank");
619 # The noerror value is something else other
620 # than 0 or 1 so return an error.
622 kiriwrite_error("invalidvariable");
628 # Set the following variables for later on.
630 my $variable_data_length = 0;
631 my $variable_data_char = "";
632 my $variable_data_seek = 0;
634 # Get the length of the language file name.
636 $variable_data_length = length($variable_data);
640 # Get a character from the language filename passed to this
641 # subroutine and the character the seek counter value is set
644 $variable_data_char = substr($variable_data, $variable_data_seek, 1);
646 # Check if the language filename contains a forward slash or a dot,
647 # if the selected character is a forward slash then return an error
650 if ($variable_data_char eq "/" || $variable_data_char eq "."){
652 # The language filename contains a forward slash or
653 # a dot so depending on the no error value, return
654 # an error or a value.
656 if ($variable_noerror eq 1){
658 # Language filename contains a forward slash or a dot
659 # and the no error value has been set to 1, so return
660 # an value of 2 (saying that the language file name is
665 } elsif ($variable_noerror eq 0) {
667 # Language filename contains a forward slash and the no
668 # error value has not been set to 1, so return an error.
670 kiriwrite_error("languagefilenameinvalid");
674 # The noerror value is something else other than
675 # 1 or 0 so return an error.
677 kiriwrite_error("invalidvariable");
683 # Increment the seek counter.
685 $variable_data_seek++;
687 } until ($variable_data_seek eq $variable_data_length);
691 } elsif ($variable_type eq "module"){
693 # The variable type is a presentation module filename.
695 # Check if the variable_data is blank and if it is
698 if ($variable_data eq ""){
700 # The presentation module is blank so check if an error
701 # value should be returned or a number should be
704 if ($variable_noerror eq 1){
706 # Module name is blank and the no error value
707 # is set to 1 so return a value of 2 (meaning
708 # that the page filename is blank).
712 } elsif ($variable_noerror eq 0) {
714 # Module name contains is blank and the no error
715 # value is set to 0 so return an error.
717 kiriwrite_critical("moduleblank");
721 # The no error value is something else other
722 # than 0 or 1 so return an error.
724 kiriwrite_critical("invalidvalue");
732 my $variable_data_validated = $variable_data;
733 $variable_data_validated =~ tr/a-zA-Z0-9//d;
735 if ($variable_data_validated eq ""){
739 if ($variable_noerror eq 1){
741 # Module name contains invalid characters and
742 # the no error value is set to 1 so return a
743 # value of 2 (meaning that the page filename
748 } elsif ($variable_noerror eq 0) {
750 # Module name contains invalid characters and
751 # the no error value is set to 0 so return an
754 kiriwrite_critical("moduleinvalid");
758 # The no error value is something else other
759 # than 0 or 1 so return an error.
761 kiriwrite_error("invalidvalue");
769 } elsif ($variable_type eq "serverprotocol"){
771 # Check if the server protocol is TCP or UDP and return
772 # an error if it isn't.
774 if ($variable_data ne "tcp" && $variable_data ne "udp"){
776 # The protocol given is not valid, check if the no
777 # error value is set to 1 and return an error if it isn't.
779 if ($variable_noerror eq 1){
781 # The no error value has been set to 1, so return a
782 # value of 1 (meaning that the server protocol is
787 } elsif ($variable_noerror eq 0){
789 # The no error value has been set to 0, so return
792 kiriwrite_error("serverprotocolinvalid");
796 # The no error value is something else other than 0
797 # or 1, so return an error.
799 kiriwrite_error("invalidoption");
807 } elsif ($variable_type eq "port"){
809 # Check if the port number given is less than 0 or more than 65535
810 # and return an error if it is.
812 if ($variable_data < 0 || $variable_data > 65535){
814 # The port number is less than 0 and more than 65535 so
815 # check if the no error value is set to 1 and return an
818 if ($variable_noerror eq 1){
820 # The no error value has been set to 1, so return a
821 # value of 1 (meaning that the port number is invalid).
825 } elsif ($variable_noerror eq 0){
827 # The no error value has been set to 0, so return
830 kiriwrite_error("serverportnumberinvalid");
834 # The no error value is something else other than 0
835 # or 1, so return an error.
837 kiriwrite_error("invalidoption");
847 # Another type than the valid ones above has been specified so return an error specifying an invalid option.
848 kiriwrite_error("invalidoption");
853 #################################################################################
854 # kiriwrite_error: Subroutine for processing error messages. #
858 # kiriwrite_error(errortype); #
860 # errortype Specifies the error type to use. #
861 #################################################################################
863 my $error_type = shift;
865 # Load the list of error messages.
867 my (%kiriwrite_error, $kiriwrite_error);
871 # Generic Error Messages
873 "generic" => $kiriwrite_lang{$language_selected}{generic},
875 "invalidvariable" => $kiriwrite_lang{$language_selected}{invalidvariable},
876 "invalidvalue" => $kiriwrite_lang{$language_selected}{invalidvalue},
877 "invalidoption" => $kiriwrite_lang{$language_selected}{invalidoption},
878 "variabletoolong" => $kiriwrite_lang{$language_selected}{variabletoolong},
879 "blankdirectory" => $kiriwrite_lang{$language_selected}{blankdirectory},
880 "invaliddirectory" => $kiriwrite_lang{$language_selected}{invaliddirectory},
881 "moduleblank" => $kiriwrite_lang{$language_selected}{moduleblank},
882 "moduleinvalid" => $kiriwrite_lang{$language_selected}{moduleinvalid},
884 # Specific Error Messages
886 "dbdirectorytoolong" => $kiriwrite_lang{$language_selected}{dbdirectorytoolong},
887 "outputdirectorytoolong" => $kiriwrite_lang{$language_selected}{outputdirectorytoolong},
888 "imagesuripathtoolong" => $kiriwrite_lang{$language_selected}{imagesuripathtoolong},
889 "dateformattoolong" => $kiriwrite_lang{$language_selected}{dateformattoolong},
890 "customdateformattoolong" => $kiriwrite_lang{$language_selected}{customdateformattoolong},
891 "languagefilenametoolong" => $kiriwrite_lang{$language_selected}{languagefilenametoolong},
893 "dateformatblank" => $kiriwrite_lang{$language_selected}{dateformatblank},
894 "dateformatinvalid" => $kiriwrite_lang{$language_selected}{dateformatinvalid},
895 "languagefilenameinvalid" => $kiriwrite_lang{$language_selected}{languagefilenameinvalid},
897 "dbdirectoryblank" => $kiriwrite_lang{$language_selected}{dbdirectoryblank},
898 "dbdirectoryinvalid" => $kiriwrite_lang{$language_selected}{dbdirectoryinvalid},
900 "outputdirectoryblank" => $kiriwrite_lang{$language_selected}{outputdirectoryblank},
901 "outputdirectoryinvalid" => $kiriwrite_lang{$language_selected}{outputdirectoryinvalid},
903 "presmoduleblank" => $kiriwrite_lang{$language_selected}{presmoduleblank},
904 "presmoduleinvalid" => $kiriwrite_lang{$language_selected}{presmoduleinvalid},
906 "dbmoduleblank" => $kiriwrite_lang{$language_selected}{dbmoduleblank},
907 "dbmoduleinvalid" => $kiriwrite_lang{$language_selected}{dbmoduleinvalid},
909 "presmodulemissing" => $kiriwrite_lang{$language_selected}{presmodulemissing},
910 "dbmodulemissing" => $kiriwrite_lang{$language_selected}{dbmodulemissing},
911 "languagefilemissing" => $kiriwrite_lang{$language_selected}{languagefilemissing},
913 "servernametoolong" => $kiriwrite_lang{$language_selected}{servernametoolong},
914 "servernameinvalid" => $kiriwrite_lang{$language_selected}{servernameinvalid},
915 "serverportnumbertoolong" => $kiriwrite_lang{$language_selected}{serverportnumbertoolong},
916 "serverportnumberinvalidcharacters" => $kiriwrite_lang{$language_selected}{serverportnumberinvalidcharacters},
917 "serverportnumberinvalid" => $kiriwrite_lang{$language_selected}{serverportnumberinvalid},
918 "serverprotocolnametoolong" => $kiriwrite_lang{$language_selected}{serverprotocolnametoolong},
919 "serverprotocolinvalid" => $kiriwrite_lang{$language_selected}{serverprotocolinvalid},
920 "serverdatabasenametoolong" => $kiriwrite_lang{$language_selected}{serverdatabasenametoolong},
921 "serverdatabasenameinvalid" => $kiriwrite_lang{$language_selected}{serverdatabasenameinvalid},
922 "serverdatabaseusernametoolong" => $kiriwrite_lang{$language_selected}{serverdatabaseusernametoolong},
923 "serverdatabaseusernameinvalid" => $kiriwrite_lang{$language_selected}{serverdatabaseusernameinvalid},
924 "serverdatabasepasswordtoolong" => $kiriwrite_lang{$language_selected}{serverdatabasepasswordtoolong},
925 "serverdatabasetableprefixtoolong" => $kiriwrite_lang{$language_selected}{serverdatabasetableprefixtoolong},
926 "serverdatabasetableprefixinvalid" => $kiriwrite_lang{$language_selected}{serverdatabasetableprefixinvalid},
928 "removeinstallscripttoolong" => $kiriwrite_lang{$language_selected}{removeinstallscripttoolong},
929 "cannotwriteconfigurationindirectory" => $kiriwrite_lang{$language_selected}{cannotwriteconfigurationindirectory},
930 "configurationfilereadpermissionsinvalid" => $kiriwrite_lang{$language_selected}{configurationfilereadpermissionsinvalid},
931 "configurationfilewritepermissionsinvalid" => $kiriwrite_lang{$language_selected}{configurationfilewritepermissionsinvalid},
935 # Check if the specified error is blank and if it is
936 # use the generic error messsage.
938 if (!$kiriwrite_error{$error_type}){
939 $error_type = "generic";
944 print start_html({ -title => $kiriwrite_lang{$language_selected}{error}, -style => { -code => $cssstyle }});
946 print h2($kiriwrite_lang{$language_selected}{error});
948 print $kiriwrite_error{$error_type};
950 print $kiriwrite_lang{$language_selected}{errormessagetext};
958 sub kiriwrite_writeconfig{
959 #################################################################################
960 # kiriwrite_writeconfig: Writes a configuration file. #
964 # kiriwrite_writeconfig(); #
965 #################################################################################
967 my ($passedsettings) = @_;
969 # Open the configuration file for writing.
971 open (my $configfile, "> " . "kiriwrite.xml");
973 print $configfile "<?xml version=\"1.0\"?>
976 <!-- This file was automatically generated by Kiriwrite, please feel free to edit to your own needs. -->
979 <database>" . $passedsettings->{DatabaseDirectory} . "</database>
980 <output>" . $passedsettings->{OutputDirectory} . "</output>
981 <images>" . $passedsettings->{ImagesURIPath} . "</images>
984 <lang>" . $passedsettings->{Language} . "</lang>
987 <presentation>" . $passedsettings->{PresentationModule} . "</presentation>
988 <database>" . $passedsettings->{DatabaseModule} . "</database>
989 <datetime>" . $passedsettings->{DateFormat} . "</datetime>
992 <server>" . $passedsettings->{DatabaseServer} . "</server>
993 <port>" . $passedsettings->{DatabasePort} . "</port>
994 <protocol>" . $passedsettings->{DatabaseProtocol} . "</protocol>
995 <database>" . $passedsettings->{DatabaseName} . "</database>
996 <username>" . $passedsettings->{DatabaseUsername} . "</username>
997 <password>" . $passedsettings->{DatabasePassword} . "</password>
998 <prefix>" . $passedsettings->{DatabaseTablePrefix} . "</prefix>
1004 close ($configfile);
1008 #################################################################################
1009 # End list of subroutines. #
1010 #################################################################################
1012 if (!$http_query_confirm){
1014 $http_query_confirm = 0;
1018 if ($http_query_confirm eq 1){
1020 # The confirm value has been given so get the data from the query.
1022 my $http_query_dbdirectory = $query->param('dbdirectory');
1023 my $http_query_outputdirectory = $query->param('outputdirectory');
1024 my $http_query_imagesuripath = $query->param('imagesuripath');
1026 my $http_query_dateformat = $query->param('dateformat');
1027 my $http_query_customdateformat = $query->param('customdateformat');
1029 my $http_query_language = $query->param('language');
1031 my $http_query_presmodule = $query->param('presmodule');
1032 my $http_query_dbmodule = $query->param('dbmodule');
1034 my $http_query_databaseserver = $query->param('databaseserver');
1035 my $http_query_databaseport = $query->param('databaseport');
1036 my $http_query_databaseprotocol = $query->param('databaseprotocol');
1037 my $http_query_databasename = $query->param('databasename');
1038 my $http_query_databaseusername = $query->param('databaseusername');
1039 my $http_query_databasepassword = $query->param('databasepassword');
1040 my $http_query_databasetableprefix = $query->param('databasetableprefix');
1041 my $http_query_removeinstallscript = $query->param('removeinstallscript');
1043 # Check the length of the variables.
1045 my $kiriwrite_dbdirectory_length_check = kiriwrite_variablecheck($http_query_dbdirectory, "maxlength", 64, 1);
1046 my $kiriwrite_outputdirectory_length_check = kiriwrite_variablecheck($http_query_outputdirectory, "maxlength", 64, 1);
1047 my $kiriwrite_imagesuripath_length_check = kiriwrite_variablecheck($http_query_imagesuripath, "maxlength", 512, 1);
1048 my $kiriwrite_dateformat_length_check = kiriwrite_variablecheck($http_query_dateformat, "maxlength", 32, 1);
1049 my $kiriwrite_customdateformat_length_check = kiriwrite_variablecheck($http_query_customdateformat, "maxlength", 32, 1);
1050 my $kiriwrite_language_length_check = kiriwrite_variablecheck($http_query_language, "maxlength", 16, 1);
1052 # Check if any errors occured while checking the
1053 # length of the variables.
1055 if ($kiriwrite_dbdirectory_length_check eq 1){
1057 # The database directory given is too long
1058 # so return an error.
1060 kiriwrite_error("dbdirectorytoolong");
1064 if ($kiriwrite_outputdirectory_length_check eq 1){
1066 # The output directory given is too long
1067 # so return an error.
1069 kiriwrite_error("outputdirectorytoolong");
1073 if ($kiriwrite_imagesuripath_length_check eq 1){
1075 # The images URI path given is too long
1076 # so return an error.
1078 kiriwrite_error("imagesuripathtoolong");
1082 if ($kiriwrite_dateformat_length_check eq 1){
1084 # The date format given is too long
1085 # so return an error.
1087 kiriwrite_error("dateformattoolong");
1091 if ($kiriwrite_customdateformat_length_check eq 1){
1093 # The date format given is too long
1094 # so return an error.
1096 kiriwrite_error("customdateformattoolong");
1100 if ($kiriwrite_language_length_check eq 1){
1102 # The language filename given is too long
1103 # so return an error.
1105 kiriwrite_error("languagefilenametoolong");
1109 # Check if the custom date and time setting has anything
1110 # set and if it doesn't then use the predefined one set.
1112 my $finaldateformat = "";
1114 if ($http_query_customdateformat ne ""){
1116 $finaldateformat = $http_query_customdateformat;
1120 $finaldateformat = $http_query_dateformat;
1124 my $kiriwrite_datetime_check = kiriwrite_variablecheck($finaldateformat, "datetime", 0, 1);
1126 if ($kiriwrite_datetime_check eq 1){
1128 # The date and time format is blank so return
1131 kiriwrite_error("dateformatblank");
1133 } elsif ($kiriwrite_datetime_check eq 2){
1135 # The date and time format is invalid so
1138 kiriwrite_error("dateformatinvalid");
1142 # Check if the language filename given is valid.
1144 my $kiriwrite_language_languagefilename_check = kiriwrite_variablecheck($http_query_language, "language_filename", "", 1);
1146 if ($kiriwrite_language_languagefilename_check eq 1) {
1148 # The language filename given is blank so
1151 kiriwrite_error("languagefilenameblank");
1153 } elsif ($kiriwrite_language_languagefilename_check eq 2){
1155 # The language filename given is invalid so
1158 kiriwrite_error("languagefilenameinvalid");
1162 # Check if the directory names only contain letters and numbers and
1163 # return a specific error if they don't.
1165 my $kiriwrite_dbdirectory_check = kiriwrite_variablecheck($http_query_dbdirectory, "directory", 0, 1);
1166 my $kiriwrite_outputdirectory_check = kiriwrite_variablecheck($http_query_outputdirectory, "directory", 0, 1);
1168 if ($kiriwrite_dbdirectory_check eq 1){
1170 # The database directory name is blank, so return
1173 kiriwrite_error("dbdirectoryblank");
1175 } elsif ($kiriwrite_dbdirectory_check eq 2){
1177 # The database directory name is invalid, so return
1180 kiriwrite_error("dbdirectoryinvalid");
1184 if ($kiriwrite_outputdirectory_check eq 1){
1186 # The output directory name is blank, so return
1189 kiriwrite_error("outputdirectoryblank");
1191 } elsif ($kiriwrite_outputdirectory_check eq 2){
1193 # The output directory name is invalid, so return
1196 kiriwrite_error("outputdirectoryinvalid");
1200 if ($kiriwrite_dbdirectory_check eq 1){
1202 # The database directory name is blank, so return
1205 kiriwrite_error("dbdirectoryblank");
1207 } elsif ($kiriwrite_dbdirectory_check eq 2){
1209 # The database directory name is invalid, so return
1212 kiriwrite_error("dbdirectoryinvalid");
1216 if ($kiriwrite_outputdirectory_check eq 1){
1218 # The output directory name is blank, so return
1221 kiriwrite_error("outputdirectoryblank");
1223 } elsif ($kiriwrite_outputdirectory_check eq 2){
1225 # The output directory name is invalid, so return
1228 kiriwrite_error("outputdirectoryinvalid");
1232 # Check the module names to see if they're valid.
1234 my $kiriwrite_presmodule_modulename_check = kiriwrite_variablecheck($http_query_presmodule, "module", 0, 1);
1235 my $kiriwrite_dbmodule_modulename_check = kiriwrite_variablecheck($http_query_dbmodule, "module", 0, 1);
1237 if ($kiriwrite_presmodule_modulename_check eq 1){
1239 # The presentation module name is blank, so return
1242 kiriwrite_error("presmoduleblank");
1246 if ($kiriwrite_presmodule_modulename_check eq 2){
1248 # The presentation module name is invalid, so return
1251 kiriwrite_error("presmoduleinvalid");
1255 if ($kiriwrite_dbmodule_modulename_check eq 1){
1257 # The database module name is blank, so return
1260 kiriwrite_error("dbmoduleblank");
1264 if ($kiriwrite_dbmodule_modulename_check eq 2){
1266 # The database module name is invalid, so return
1269 kiriwrite_error("dbmoduleinvalid");
1273 # Check if the database module, presentation module and
1274 # language file exists.
1276 if (!-e "Modules/Presentation/" . $http_query_presmodule . ".pm"){
1278 # The presentation module is missing so return an
1281 kiriwrite_error("presmodulemissing");
1285 if (!-e "Modules/Database/" . $http_query_dbmodule . ".pm"){
1287 # The database module is missing so return an
1290 kiriwrite_error("dbmodulemissing");
1294 if (!-e "lang/" . $http_query_language . ".xml"){
1296 # The language file is missing so return an
1299 kiriwrite_error("languagefilenamemissing");
1303 # Check the database server settings.
1305 my $kiriwrite_databaseserver_length_check = kiriwrite_variablecheck($http_query_databaseserver, "maxlength", 128, 1);
1306 my $kiriwrite_databaseserver_lettersnumbers_check = kiriwrite_variablecheck($http_query_databaseserver, "lettersnumbers", 0, 1);
1307 my $kiriwrite_databaseport_length_check = kiriwrite_variablecheck($http_query_databaseport, "maxlength", 5, 1);
1308 my $kiriwrite_databaseport_numbers_check = kiriwrite_variablecheck($http_query_databaseport, "numbers", 0, 1);
1309 my $kiriwrite_databaseport_port_check = kiriwrite_variablecheck($http_query_databaseport, "port", 0, 1);
1310 my $kiriwrite_databaseprotocol_length_check = kiriwrite_variablecheck($http_query_databaseprotocol, "maxlength", 5, 1);
1311 my $kiriwrite_databaseprotocol_protocol_check = kiriwrite_variablecheck($http_query_databaseprotocol, "serverprotocol", 0, 1);
1312 my $kiriwrite_databasename_length_check = kiriwrite_variablecheck($http_query_databasename, "maxlength", 32, 1);
1313 my $kiriwrite_databasename_lettersnumbers_check = kiriwrite_variablecheck($http_query_databasename, "lettersnumbers", 0, 1);
1314 my $kiriwrite_databaseusername_length_check = kiriwrite_variablecheck($http_query_databaseusername, "maxlength", 16, 1);
1315 my $kiriwrite_databaseusername_lettersnumbers_check = kiriwrite_variablecheck($http_query_databaseusername, "lettersnumbers", 0, 1);
1316 my $kiriwrite_databasepassword_length_check = kiriwrite_variablecheck($http_query_databasepassword, "maxlength", 64, 1);
1317 my $kiriwrite_databasetableprefix_length_check = kiriwrite_variablecheck($http_query_databasetableprefix, "maxlength", 16, 1);
1318 my $kiriwrite_databasetableprefix_lettersnumbers_check = kiriwrite_variablecheck($http_query_databasetableprefix, "lettersnumbers", 0, 1);
1320 if ($kiriwrite_databaseserver_length_check eq 1){
1322 # The length of the database server name is too long so
1325 kiriwrite_error("servernametoolong");
1329 if ($kiriwrite_databaseserver_lettersnumbers_check eq 1){
1331 # The database server name contains characters other
1332 # than letters and numbers, so return an error.
1334 kiriwrite_error("servernameinvalid");
1338 if ($kiriwrite_databaseport_length_check eq 1){
1340 # The database port number length is too long so return
1343 kiriwrite_error("serverportnumbertoolong");
1347 if ($kiriwrite_databaseport_numbers_check eq 1){
1349 # The database port number contains characters other
1350 # than numbers so return an error.
1352 kiriwrite_error("serverportnumberinvalidcharacters");
1356 if ($kiriwrite_databaseport_port_check eq 1){
1358 # The database port number given is invalid so return
1361 kiriwrite_error("serverportnumberinvalid");
1365 if ($kiriwrite_databaseprotocol_length_check eq 1){
1367 # The database protocol name given is too long so
1370 kiriwrite_error("serverprotocolnametoolong");
1374 if ($kiriwrite_databaseprotocol_protocol_check eq 1){
1376 # The server protcol given is invalid so return
1379 kiriwrite_error("serverprotocolinvalid");
1383 if ($kiriwrite_databasename_length_check eq 1){
1385 # The SQL database name is too long so return
1388 kiriwrite_error("serverdatabasenametoolong");
1392 if ($kiriwrite_databasename_lettersnumbers_check eq 1){
1394 # The database name contains invalid characters
1395 # so return an error.
1397 kiriwrite_error("serverdatabasenameinvalid");
1401 if ($kiriwrite_databaseusername_length_check eq 1){
1403 # The database username given is too long so
1406 kiriwrite_error("serverdatabaseusernametoolong");
1410 if ($kiriwrite_databaseusername_lettersnumbers_check eq 1){
1412 # The database username contains invalid characters
1413 # so return an error.
1415 kiriwrite_error("serverdatabaseusernameinvalid");
1419 if ($kiriwrite_databasepassword_length_check eq 1){
1421 # The database password given is too long so return
1424 kiriwrite_error("serverdatabasepasswordtoolong");
1428 if ($kiriwrite_databasetableprefix_length_check eq 1){
1430 # The database table prefix given is too long so
1433 kiriwrite_error("serverdatabasetableprefixtoolong");
1437 if ($kiriwrite_databasetableprefix_lettersnumbers_check eq 1){
1439 # The database table prefix given contains invalid
1440 # characters so return an error.
1442 kiriwrite_error("serverdatabasetableprefixinvalid");
1446 # Check the length of value of the checkboxes.
1448 my $kiriwrite_removeinstallscript_length_check = kiriwrite_variablecheck($http_query_removeinstallscript, "maxlength", 2, 1);
1450 if ($kiriwrite_removeinstallscript_length_check eq 1){
1452 # The remove install script value is too long
1453 # so return an error.
1455 kiriwrite_error("removeinstallscripttoolong");
1459 # Check if there is write permissions for the directory.
1463 # No write permissions for the directory the
1464 # script is running from so return an error.
1466 kiriwrite_error("cannotwriteconfigurationindirectory");
1470 # Check if the configuration file already exists.
1472 if (-e 'kiriwrite.xml'){
1474 # Check if the configuration file has read permissions.
1476 if (!-r 'kiriwrite.xml'){
1478 # The configuration file has invalid read permissions
1479 # set so return an error.
1481 kiriwrite("configurationfilereadpermissionsinvalid");
1485 # Check if the configuration file has write permissions.
1487 if (!-w 'kiriwrite.xml'){
1489 # The configuration file has invalid write permissions
1490 # set so return an error.
1492 kiriwrite("configurationfilewritepermissionsinvalid");
1498 # Write the new configuration file.
1500 kiriwrite_writeconfig({ DatabaseDirectory => $http_query_dbdirectory, OutputDirectory => $http_query_outputdirectory, ImagesURIPath => $http_query_imagesuripath, DateFormat => $finaldateformat, Language => $http_query_language, PresentationModule => $http_query_presmodule, DatabaseModule => $http_query_dbmodule, DatabaseServer => $http_query_databaseserver, DatabasePort => $http_query_databaseport, DatabaseProtocol => $http_query_databaseprotocol, DatabaseName => $http_query_databasename, DatabaseUsername => $http_query_databaseusername, DatabasePassword => $http_query_databasepassword, DatabaseTablePrefix => $http_query_databasetableprefix });
1502 my $installscriptmessage = "";
1504 # Check if the installation script should be deleted.
1506 if (!$http_query_removeinstallscript){
1508 $http_query_removeinstallscript = "off";
1512 if ($http_query_removeinstallscript eq "on"){
1514 if (unlink("install.cgi")){
1516 $installscriptmessage = $kiriwrite_lang{$language_selected}{installscriptremoved};
1520 $installscriptmessage = $kiriwrite_lang{$language_selected}{cannotremovescript};
1521 $installscriptmessage =~ s/%s/$!/g;
1525 #"Unable to remove the installer script: " . $! . " The installer script will have to be deleted manually.";
1533 print start_html({ -title => $kiriwrite_lang{$language_selected}{installertitle}, -style => { -code => $cssstyle }});
1534 print h2($kiriwrite_lang{$language_selected}{installertitle});
1535 print $kiriwrite_lang{$language_selected}{installedmessage};
1537 if ($installscriptmessage){
1541 print $installscriptmessage;
1547 print $kiriwrite_lang{$language_selected}{usekiriwritetext};
1550 print a({-href=>'kiriwrite.cgi'}, $kiriwrite_lang{$language_selected}{usekiriwritelink});
1556 # Create a list of common date and time formats.
1558 my @datetime_formats = [
1559 'DD/MM/YY (hh:mm:ss)', 'DD/MM/YY hh:mm:ss', 'D/M/Y (hh:mm:ss)',
1560 'D/M/Y hh:mm:ss', 'D/M/YY (hh:mm:ss)', 'D/M/YY hh:mm:ss',
1561 'DD/MM (hh:mm:ss)', 'D/M (hh:mm:ss)', 'DD/MM hh:mm:ss',
1562 'D/M hh:mm:ss', 'DD/MM hh:mm', 'D/M hh:mm',
1563 'DD/MM/YY', 'D/M/Y', 'DD/MM',
1565 'YY-MM-DD (hh:mm:ss)', 'YY-MM-DD hh:mm:ss', 'Y-M-D (hh:mm:ss)',
1566 'Y-M-D hh:mm:ss', 'M-D (hh:mm:ss)', 'M-D hh:mm:ss',
1570 # Create the list of tests to do.
1572 my ($test_list, %test_list);
1573 my %dependency_results;
1574 my %database_results;
1579 my $dependency_error = 0;
1580 my $database_onemodule = 0;
1581 my $database_error = 0;
1585 my $language_xml_data;
1586 my $language_file_friendly;
1588 my $presentation_file_friendly;
1590 # Check to see if the needed Perl modules are installed.
1592 $test_list{CheckDBI}{Name} = "DBI";
1593 $test_list{CheckDBI}{Type} = "dependency";
1594 $test_list{CheckDBI}{Code} = "DBI";
1596 $test_list{CheckXMLSimple}{Name} = "XML::Simple";
1597 $test_list{CheckXMLSimple}{Type} = "dependency";
1598 $test_list{CheckXMLSimple}{Code} = "XML::Simple";
1600 $test_list{CheckXMLParser}{Name} = "XML::Parser";
1601 $test_list{CheckXMLParser}{Type} = "dependency";
1602 $test_list{CheckXMLParser}{Code} = "XML::Parser";
1604 $test_list{CheckTieHash}{Name} = "Tie::IxHash";
1605 $test_list{CheckTieHash}{Type} = "dependency";
1606 $test_list{CheckTieHash}{Code} = "Tie::IxHash";
1608 $test_list{Encode}{Name} = "Encode";
1609 $test_list{Encode}{Type} = "dependency";
1610 $test_list{Encode}{Code} = "Encode";
1612 $test_list{DBDmysql}{Name} = "DBD::mysql";
1613 $test_list{DBDmysql}{Type} = "database";
1614 $test_list{DBDmysql}{Code} = "DBD::mysql";
1616 $test_list{DBDSQLite}{Name} = "DBD::SQLite";
1617 $test_list{DBDSQLite}{Type} = "database";
1618 $test_list{DBDSQLite}{Code} = "DBD::SQLite";
1620 # Check the file and directory permissions to see if they are correct.
1622 $test_list{MainDirectory}{Name} = "Kiriwrite Directory (.)";
1623 $test_list{MainDirectory}{Type} = "file";
1624 $test_list{MainDirectory}{Code} = ".";
1625 $test_list{MainDirectory}{Writeable} = "1";
1627 $test_list{LanguageDirectory}{Name} = "Language Directory (lang)";
1628 $test_list{LanguageDirectory}{Type} = "file";
1629 $test_list{LanguageDirectory}{Code} = "lang";
1630 $test_list{LanguageDirectory}{Writeable} = "0";
1632 $test_list{ModulesDirectory}{Name} = "Modules Directory (Modules)";
1633 $test_list{ModulesDirectory}{Type} = "file";
1634 $test_list{ModulesDirectory}{Code} = "Modules";
1635 $test_list{ModulesDirectory}{Writeable} = "0";
1637 $test_list{DBModulesDirectory}{Name} = "Database Modules Directory (Modules/Database)";
1638 $test_list{DBModulesDirectory}{Type} = "file";
1639 $test_list{DBModulesDirectory}{Code} = "Modules/Database";
1640 $test_list{DBModulesDirectory}{Writeable} = "0";
1642 $test_list{PresModulesDirectory}{Name} = "Presentation Modules Directory (Modules/Presentation)";
1643 $test_list{PresModulesDirectory}{Type} = "file";
1644 $test_list{PresModulesDirectory}{Code} = "Modules/Presentation";
1645 $test_list{PresModulesDirectory}{Writeable} = "0";
1647 # Preform those tests.
1649 foreach $test (keys %test_list){
1651 # Check the type of test.
1653 if ($test_list{$test}{Type} eq "dependency"){
1655 if (eval "require " . $test_list{$test}{Code}){
1657 # The module exists and is working correctly.
1659 $dependency_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1663 # The module does not exist or has an error.
1665 $dependency_error = 1;
1666 $dependency_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testfail};
1670 } elsif ($test_list{$test}{Type} eq "database"){
1672 if (eval "require " . $test_list{$test}{Code}){
1674 # The module exists and it is working correctly.
1676 $database_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1677 $database_onemodule = 1;
1681 # The module does not exist or has an error.
1683 $database_error = 1;
1684 $database_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testfail};
1688 } elsif ($test_list{$test}{Type} eq "file"){
1690 if (-e $test_list{$test}{Code}){
1692 # The filename given does exist.
1696 # the filename given does not exist.
1699 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{doesnotexist};
1703 # Test to see if the filename given has read
1706 if (-r $test_list{$test}{Code}){
1708 # The filename given has valid permissions set.
1710 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1714 # The filename given has invalid permissions set.
1717 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{invalidpermissionsset};
1721 if ($test_list{$test}{Writeable} eq 1){
1723 # Test to see if the filename given has write
1726 if (-w $test_list{$test}{Code}){
1728 # The filename given has valid permissions set.
1730 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1734 # The filename given has invalid permissions set.
1737 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{invalidpermissionsset};
1751 # Print the page for installing Kiriwrite.
1753 print start_html( -title=> $kiriwrite_lang{$language_selected}{installertitle}, -style => { -code => $cssstyle });
1755 print start_table( { -width=> "100%" } );
1757 print start_td({ -class => "languagebar" });
1758 print $kiriwrite_lang{$language_selected}{installertitle};
1760 print start_td({ -class => "languagebarselect" });
1761 print start_form("POST", "install.cgi");
1763 # This is a bodge for the language list.
1765 my $language_name_short;
1766 my $language_list_seek = 0;
1768 print "<select name=\"installlanguage\">";
1770 foreach $language_name_short (@language_list_short){
1772 print "<option value=\"" . $language_name_short . "\">" . $language_list_long[$language_list_seek] . "</option>";
1773 $language_list_seek++;
1778 print submit($kiriwrite_lang{$language_selected}{switch});
1785 print h2($kiriwrite_lang{$language_selected}{installertitle});
1787 print $kiriwrite_lang{$language_selected}{installertext};
1789 print h3($kiriwrite_lang{$language_selected}{dependencytitle});
1790 print h4($kiriwrite_lang{$language_selected}{requiredmodules});
1791 print $kiriwrite_lang{$language_selected}{perlmodules};
1795 if ($dependency_error eq 1){
1797 print $kiriwrite_lang{$language_selected}{errormessage};
1798 print $kiriwrite_lang{$language_selected}{dependencyperlmodulesmissing};
1804 print start_table();
1806 print start_td({ -class => "tablecellheader" });
1807 print $kiriwrite_lang{$language_selected}{module};
1809 print start_td({ -class => "tablecellheader" });
1810 print $kiriwrite_lang{$language_selected}{result};
1814 foreach $test (keys %dependency_results) {
1817 print start_td({ -class => "tablename" });
1820 print start_td({ -class => "tabledata" });
1821 print $dependency_results{$test}{result};
1829 print h4($kiriwrite_lang{$language_selected}{databasemodules});
1830 print $kiriwrite_lang{$language_selected}{databasemodulestext};
1834 if ($database_error eq 1){
1836 print $kiriwrite_lang{$language_selected}{warningmessage};
1837 print $kiriwrite_lang{$language_selected}{databaseperlmodulesmissing};
1843 print start_table();
1845 print start_td({ -class => "tablecellheader" });
1846 print $kiriwrite_lang{$language_selected}{module};
1848 print start_td({ -class => "tablecellheader" });
1849 print $kiriwrite_lang{$language_selected}{result};
1853 foreach $test (keys %database_results) {
1856 print start_td({ -class => "tablename" });
1859 print start_td({ -class => "tabledata" });
1860 print $database_results{$test}{result};
1868 print h4($kiriwrite_lang{$language_selected}{filepermissions});
1870 print $kiriwrite_lang{$language_selected}{filepermissionstext};
1874 if ($file_error eq 1){
1876 print $kiriwrite_lang{$language_selected}{errormessage};
1877 print $kiriwrite_lang{$language_selected}{filepermissionsinvalid};
1883 print start_table();
1885 print start_td({ -class => "tablecellheader" });
1888 print start_td({ -class => "tablecellheader" });
1893 foreach $test (keys %file_results) {
1896 print start_td({ -class => "tablename" });
1899 print start_td({ -class => "tabledata" });
1900 print $file_results{$test}{result};
1908 if ($dependency_error eq 1){
1911 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1912 print $kiriwrite_lang{$language_selected}{dependencymodulesnotinstalled};
1918 if ($database_onemodule eq 0){
1921 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1922 print $kiriwrite_lang{$language_selected}{databasemodulesnotinstalled};
1928 if ($file_error eq 1){
1931 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1932 print $kiriwrite_lang{$language_selected}{filepermissionerrors};
1939 my (%available_languages, $available_languages);
1940 my @presentation_modules;
1941 my @database_modules;
1943 my $presentation_modules_ref = \@presentation_modules;
1944 my $database_modules_ref = \@database_modules;
1946 # Get the list of available languages.
1948 tie(%available_languages, 'Tie::IxHash');
1950 opendir(LANGUAGEDIR, "lang");
1951 my @language_directory = grep /m*\.xml$/, readdir(LANGUAGEDIR);
1952 closedir(LANGUAGEDIR);
1954 my $xsl = XML::Simple->new();
1956 foreach my $language_file (@language_directory){
1958 # Load the XML data.
1960 $language_xml_data = $xsl->XMLin("lang/" . $language_file);
1962 # Get the friendly name for the language file.
1964 $language_file_friendly = $language_file;
1965 $language_file_friendly =~ s/.xml$//g;
1967 $language_name = $language_xml_data->{about}->{name};
1969 $available_languages{$language_file_friendly} = $language_name . " (" . $language_file_friendly . ")";
1973 # Get the list of presentation modules.
1975 opendir(OUTPUTSYSTEMDIR, "Modules/Presentation");
1976 my @presmodule_directory = grep /m*\.pm$/, readdir(OUTPUTSYSTEMDIR);
1977 closedir(OUTPUTSYSTEMDIR);
1979 foreach my $presmodule_file (@presmodule_directory){
1981 # Get the friendly name for the database module.
1983 $presmodule_file =~ s/.pm$//g;
1985 push(@presentation_modules, $presmodule_file);
1989 # Get the list of database modules.
1991 opendir(DATABASEDIR, "Modules/Database");
1992 my @dbmodule_directory = grep /m*\.pm$/, readdir(DATABASEDIR);
1993 closedir(DATABASEDIR);
1995 foreach my $dbmodule_file (@dbmodule_directory){
1997 # Get the friendly name for the database module.
1999 $dbmodule_file =~ s/.pm$//g;
2001 push(@database_modules, $dbmodule_file);
2005 print h3($kiriwrite_lang{$language_selected}{settingstitle});
2007 print $kiriwrite_lang{$language_selected}{settingstext};
2011 print start_form("POST", "install.cgi");
2012 print hidden( -name => 'confirm', -default => '1');
2013 print hidden( -name => 'installlanguage', -default => $language_selected);
2015 print start_table({ -width => "100%" });
2018 print start_td({ -class => "tablecellheader" });
2019 print $kiriwrite_lang{$language_selected}{setting};
2021 print start_td({ -class => "tablecellheader" });
2022 print $kiriwrite_lang{$language_selected}{value};
2027 print start_td({ -class => "tablecellheader" });
2028 print $kiriwrite_lang{$language_selected}{directories};
2030 print start_td({ -class => "tablecellheader" });
2035 print start_td({ -class => "tablename" });
2036 print $kiriwrite_lang{$language_selected}{databasedirectory};
2038 print start_td({ -class => "tabledata" });
2039 print textfield({ -name => "dbdirectory", -size => 32, -maxlength => 64, -value => $default_dbdirectory });
2044 print start_td({ -class => "tablename" });
2045 print $kiriwrite_lang{$language_selected}{outputdirectory};
2047 print start_td({ -class => "tabledata" });
2048 print textfield({ -name => "outputdirectory", -size => 32, -maxlength => 64, -value => $default_outputdirectory });
2053 print start_td({ -class => "tablename" });
2054 print $kiriwrite_lang{$language_selected}{imagesuripath};
2056 print start_td({ -class => "tabledata" });
2057 print textfield({ -name => "imagesuripath", -size => 32, -maxlength => 64, -value => $default_imagesuri });
2062 print start_td({ -class => "tablecellheader" });
2063 print $kiriwrite_lang{$language_selected}{date};
2065 print start_td({ -class => "tablecellheader" });
2071 print start_td({ -class => "tablename" });
2072 print $kiriwrite_lang{$language_selected}{dateformat};
2074 print start_td({ -class => "tabledata" });
2076 print popup_menu( -name => "dateformat", -values => @datetime_formats );
2077 print textfield({ -name => "customdateformat", -size => 32, -maxlength => 64, });
2083 print start_td({ -class => "tablecellheader" });
2084 print $kiriwrite_lang{$language_selected}{language};
2086 print start_td({ -class => "tablecellheader" });
2091 print start_td({ -class => "tablename" });
2092 print $kiriwrite_lang{$language_selected}{systemlanguage};
2094 print start_td({ -class => "tabledata" });
2096 # Note: This the following code is bodge. If anyone can fix it so that it all works
2097 # with popup_menu properly it will be appriciated.
2099 print "<select name=\"language\">";
2101 foreach my $language (keys %available_languages){
2103 if ($language eq $language_selected){
2105 print "<option value=\"" . $language . "\" selected=selected>" . $available_languages{$language} . "</option>";
2109 print "<option value=\"" . $language . "\">" . $available_languages{$language} . "</option>";
2121 print start_td({ -class => "tablecellheader" });
2122 print $kiriwrite_lang{$language_selected}{modules};
2124 print start_td({ -class => "tablecellheader" });
2130 print start_td({ -class => "tablename" });
2131 print $kiriwrite_lang{$language_selected}{presentationmodule};
2133 print start_td({ -class => "tabledata" });
2134 print popup_menu({ -name => 'presmodule', -values => $presentation_modules_ref });
2139 print start_td({ -class => "tablename" });
2140 print $kiriwrite_lang{$language_selected}{databasemodule};
2142 print start_td({ -class => "tabledata" });
2143 print popup_menu({ -name => 'dbmodule', -values => $database_modules_ref });
2148 print start_td({ -class => "tablename" });
2149 print $kiriwrite_lang{$language_selected}{databaseserver};
2151 print start_td({ -class => "tabledata" });
2152 print textfield({ -name => "databaseserver", -size => 32, -maxlength => 128, -value => $default_server });
2157 print start_td({ -class => "tablename" });
2158 print $kiriwrite_lang{$language_selected}{databaseport};
2160 print start_td({ -class => "tabledata" });
2161 print textfield({ -name => "databaseport", -maxlength => 5, -size => 5, -value => $default_port });
2166 print start_td({ -class => "tablename" });
2167 print $kiriwrite_lang{$language_selected}{databaseprotocol};
2169 print start_td({ -class => "tabledata" });
2170 print popup_menu( -name => "databaseprotocol", -values => [ 'tcp', 'udp' ], -default => $default_protocol);
2175 print start_td({ -class => "tablename" });
2176 print $kiriwrite_lang{$language_selected}{databasename};
2178 print start_td({ -class => "tabledata" });
2179 print textfield({ -name => "databasename", -size => 32, -maxlength => 32, -default => $default_name });
2184 print start_td({ -class => "tablename" });
2185 print $kiriwrite_lang{$language_selected}{databaseusername};
2187 print start_td({ -class => "tabledata" });
2188 print textfield({ -name => "databaseusername", -size => 16, -maxlength => 16, -default => $default_username });
2193 print start_td({ -class => "tablename" });
2194 print $kiriwrite_lang{$language_selected}{databasepassword};
2196 print start_td({ -class => "tabledata" });
2197 print password_field({ -name => "databasepassword", -size => 32, -maxlength => 64 });
2202 print start_td({ -class => "tablename" });
2203 print $kiriwrite_lang{$language_selected}{databasetableprefix};
2205 print start_td({ -class => "tabledata" });
2206 print textfield({ -name => "databasetableprefix", -size => 32, -maxlength => 32, -default => $default_prefix });
2211 print start_td({ -class => "tablecellheader" });
2212 print $kiriwrite_lang{$language_selected}{installationoptions};
2214 print start_td({ -class => "tablecellheader" });
2220 print start_td({ -class => "tablename" });
2221 print $kiriwrite_lang{$language_selected}{installoptions};
2223 print start_td({ -class => "tabledata" });
2224 print checkbox( -name => 'removeinstallscript', -checked => 1, -label => " " . $kiriwrite_lang{$language_selected}{removeinstallscript});
2231 print submit($kiriwrite_lang{$language_selected}{savesettingsbutton});
2233 print reset($kiriwrite_lang{$language_selected}{resetsettingsbutton});