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;
223 background-color: #408080;
225 border-color: #102020;
235 background-color: #408080;
237 border-color: #102020;
249 background-color: #204040;
255 background-color: #204040;
259 background-color: #204040;
264 background-color: #357070;
269 background-color: #306060;
276 #################################################################################
277 # Begin list of subroutines. #
278 #################################################################################
280 sub kiriwrite_variablecheck{
281 #################################################################################
282 # kiriwrite_variablecheck: Check to see if the data passed is valid. #
286 # kiriwrite_variablecheck(variablename, type, option, noerror); #
288 # variablename Specifies the variable to be checked. #
289 # type Specifies what type the variable is. #
290 # option Specifies the maximum/minimum length of the variable #
291 # (if minlength/maxlength is used) or if the filename should be #
292 # checked to see if it is blank. #
293 # noerror Specifies if Kiriwrite should return an error or not on #
295 #################################################################################
297 # Get the values that were passed to the subroutine.
299 my ($variable_data, $variable_type, $variable_option, $variable_noerror) = @_;
301 if ($variable_type eq "numbers"){
303 # Check for numbers and return an error if there is anything else than numebrs.
305 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated.
306 $variable_data_validated =~ tr/0-9//d; # Take away all of the numbers and from the variable.
307 # If it only contains numbers then it should be blank.
309 if ($variable_data_validated eq ""){
310 # The validated variable is blank. So continue to the end of this section where the return function should be.
312 # The variable is not blank, so check if the no error value is set
315 if ($variable_noerror eq 1){
317 # The validated variable is not blank and the noerror
318 # value is set to 1. So return an value of 1.
319 # (meaning that the data is invalid).
323 } elsif ($variable_noerror eq 0) {
325 # The validated variable is not blank and the noerror
328 kiriwrite_error("invalidvariable");
332 # The variable noerror value is something else
333 # pther than 1 or 0. So return an error.
335 kiriwrite_error("invalidvariable");
343 } elsif ($variable_type eq "lettersnumbers"){
345 # Check for letters and numbers and return an error if there is anything else other
346 # than letters and numbers.
348 my $variable_data_validated = $variable_data; # Copy the variable_data to variable_data_validated
349 $variable_data_validated =~ tr/a-zA-Z0-9.//d;
350 $variable_data_validated =~ s/\s//g;
352 if ($variable_data_validated eq ""){
353 # The validated variable is blank. So continue to the end of this section where the return function should be.
355 # The variable is not blank, so check if the no error value is set
358 if ($variable_noerror eq 1){
360 # The validated variable is not blank and the noerror
361 # value is set to 1. So return an value of 1.
362 # (meaning that the data is invalid).
366 } elsif ($variable_noerror eq 0) {
368 # The validated variable is not blank and the noerror
371 kiriwrite_error("invalidvariable");
375 # The variable noerror value is something else
376 # pther than 1 or 0. So return an error.
378 kiriwrite_error("invalidvariable");
386 } elsif ($variable_type eq "maxlength"){
387 # Check for the length of the variable, return an error if it is longer than the length specified.
389 # Check if the variable_data string is blank, if it is then set the variable_data_length
392 my $variable_data_length = 0;
394 if (!$variable_data){
396 # Set variable_data_length to '0'.
397 $variable_data_length = 0;
401 # Get the length of the variable recieved.
402 $variable_data_length = length($variable_data);
408 if ($variable_data_length > $variable_option){
410 # The variable length is longer than it should be so check if
411 # the no error value is set 1.
413 if ($variable_noerror eq 1){
415 # The no error value is set to 1, so return an
416 # value of 1 (meaning tha the variable is
417 # too long to be used).
421 } elsif ($variable_noerror eq 0){
423 # The no error value is set to 0, so return
426 kiriwrite_error("variabletoolong");
430 # The no error value is something else other
431 # than 0 or 1, so return an error.
433 kiriwrite_error("variabletoolong");
439 # The variable length is exactly or shorter than specified, so continue to end of this section where
440 # the return function should be.
446 } elsif ($variable_type eq "datetime"){
447 # Check if the date and time setting format is valid.
449 if ($variable_data eq ""){
451 if ($variable_noerror eq 1){
453 # The no error value is set to 1 so return
454 # a value of 1 (meaning that the date and
455 # time format was blank).
459 } elsif ($variable_noerror eq 0){
461 # The no error value is set to 1 so return
464 kiriwrite_error("dateformatblank");
468 # The no error value is something else other
469 # than 0 or 1, so return an error.
471 kiriwrite_error("invalidvariable");
477 my $variable_data_validated = $variable_data;
478 $variable_data_validated =~ tr|dDmMyYhms/():[ ]||d;
480 if ($variable_data_validated eq ""){
482 # The date and time format is valid. So
487 # The validated data variable is not blank, meaning
488 # that it contains something else, so return an error
491 if ($variable_noerror eq 1){
493 # The no error value is set to 1 so return
494 # an value of 2. (meaning that the date and
495 # time format was invalid).
499 } elsif ($variable_noerror eq 0){
501 # The no error value is set to 0 so return
504 kiriwrite_error("dateformatinvalid");
508 # The no error value is something else other
509 # than 0 or 1 so return an error.
511 kiriwrite_error("invalidvariable");
519 } elsif ($variable_type eq "directory"){
520 # Check if the directory only contains letters and numbers and
521 # return an error if anything else appears.
523 my $variable_data_validated = $variable_data;
524 $variable_data_validated =~ tr/a-zA-Z0-9//d;
526 if ($variable_data eq ""){
528 if ($variable_noerror eq 1){
530 # The no error value is set to 1 so return
531 # a value of 1 (meaning that the directory
536 } elsif ($variable_noerror eq 0){
538 # The no error value is set to 1 so return
541 kiriwrite_error("blankdirectory");
545 # The no error value is something else other
546 # than 0 or 1, so return an error.
548 kiriwrite_error("invalidvariable");
554 if ($variable_data_validated eq ""){
556 # The validated data variable is blank, meaning that
557 # it only contains letters and numbers.
561 # The validated data variable is not blank, meaning
562 # that it contains something else, so return an error
565 if ($variable_noerror eq 1){
567 # The no error value is set to 1 so return
568 # an value of 2. (meaning that the directory
573 } elsif ($variable_noerror eq 0){
575 # The no error value is set to 0 so return
578 kiriwrite_error("invaliddirectory");
582 # The no error value is something else other
583 # than 0 or 1 so return an error.
585 kiriwrite_error("invalidvariable");
593 } elsif ($variable_type eq "language_filename"){
595 # The variable type is a language filename type.
596 # Check if the language file name is blank and
597 # if it is then return an error (or value).
599 if ($variable_data eq ""){
601 # The language filename is blank so check the
602 # no error value and return an error (or value).
604 if ($variable_noerror eq 1){
606 # Language filename is blank and the no error value
607 # is set as 1, so return a value of 1 (saying that
608 # the language filename is blank).
612 } elsif ($variable_noerror eq 0) {
614 # Language filename is blank and the no error value
615 # is not set as 1, so return an error.
617 kiriwrite_error("languagefilenameblank");
621 # The noerror value is something else other
622 # than 0 or 1 so return an error.
624 kiriwrite_error("invalidvariable");
630 # Set the following variables for later on.
632 my $variable_data_length = 0;
633 my $variable_data_char = "";
634 my $variable_data_seek = 0;
636 # Get the length of the language file name.
638 $variable_data_length = length($variable_data);
642 # Get a character from the language filename passed to this
643 # subroutine and the character the seek counter value is set
646 $variable_data_char = substr($variable_data, $variable_data_seek, 1);
648 # Check if the language filename contains a forward slash or a dot,
649 # if the selected character is a forward slash then return an error
652 if ($variable_data_char eq "/" || $variable_data_char eq "."){
654 # The language filename contains a forward slash or
655 # a dot so depending on the no error value, return
656 # an error or a value.
658 if ($variable_noerror eq 1){
660 # Language filename contains a forward slash or a dot
661 # and the no error value has been set to 1, so return
662 # an value of 2 (saying that the language file name is
667 } elsif ($variable_noerror eq 0) {
669 # Language filename contains a forward slash and the no
670 # error value has not been set to 1, so return an error.
672 kiriwrite_error("languagefilenameinvalid");
676 # The noerror value is something else other than
677 # 1 or 0 so return an error.
679 kiriwrite_error("invalidvariable");
685 # Increment the seek counter.
687 $variable_data_seek++;
689 } until ($variable_data_seek eq $variable_data_length);
693 } elsif ($variable_type eq "module"){
695 # The variable type is a presentation module filename.
697 # Check if the variable_data is blank and if it is
700 if ($variable_data eq ""){
702 # The presentation module is blank so check if an error
703 # value should be returned or a number should be
706 if ($variable_noerror eq 1){
708 # Module name is blank and the no error value
709 # is set to 1 so return a value of 2 (meaning
710 # that the page filename is blank).
714 } elsif ($variable_noerror eq 0) {
716 # Module name contains is blank and the no error
717 # value is set to 0 so return an error.
719 kiriwrite_critical("moduleblank");
723 # The no error value is something else other
724 # than 0 or 1 so return an error.
726 kiriwrite_critical("invalidvalue");
734 my $variable_data_validated = $variable_data;
735 $variable_data_validated =~ tr/a-zA-Z0-9//d;
737 if ($variable_data_validated eq ""){
741 if ($variable_noerror eq 1){
743 # Module name contains invalid characters and
744 # the no error value is set to 1 so return a
745 # value of 2 (meaning that the page filename
750 } elsif ($variable_noerror eq 0) {
752 # Module name contains invalid characters and
753 # the no error value is set to 0 so return an
756 kiriwrite_critical("moduleinvalid");
760 # The no error value is something else other
761 # than 0 or 1 so return an error.
763 kiriwrite_error("invalidvalue");
771 } elsif ($variable_type eq "serverprotocol"){
773 # Check if the server protocol is TCP or UDP and return
774 # an error if it isn't.
776 if ($variable_data ne "tcp" && $variable_data ne "udp"){
778 # The protocol given is not valid, check if the no
779 # error value is set to 1 and return an error if it isn't.
781 if ($variable_noerror eq 1){
783 # The no error value has been set to 1, so return a
784 # value of 1 (meaning that the server protocol is
789 } elsif ($variable_noerror eq 0){
791 # The no error value has been set to 0, so return
794 kiriwrite_error("serverprotocolinvalid");
798 # The no error value is something else other than 0
799 # or 1, so return an error.
801 kiriwrite_error("invalidoption");
809 } elsif ($variable_type eq "port"){
811 # Check if the port number given is less than 0 or more than 65535
812 # and return an error if it is.
814 if ($variable_data < 0 || $variable_data > 65535){
816 # The port number is less than 0 and more than 65535 so
817 # check if the no error value is set to 1 and return an
820 if ($variable_noerror eq 1){
822 # The no error value has been set to 1, so return a
823 # value of 1 (meaning that the port number is invalid).
827 } elsif ($variable_noerror eq 0){
829 # The no error value has been set to 0, so return
832 kiriwrite_error("serverportnumberinvalid");
836 # The no error value is something else other than 0
837 # or 1, so return an error.
839 kiriwrite_error("invalidoption");
849 # Another type than the valid ones above has been specified so return an error specifying an invalid option.
850 kiriwrite_error("invalidoption");
855 #################################################################################
856 # kiriwrite_error: Subroutine for processing error messages. #
860 # kiriwrite_error(errortype); #
862 # errortype Specifies the error type to use. #
863 #################################################################################
865 my $error_type = shift;
867 # Load the list of error messages.
869 my (%kiriwrite_error, $kiriwrite_error);
873 # Generic Error Messages
875 "generic" => $kiriwrite_lang{$language_selected}{generic},
877 "invalidvariable" => $kiriwrite_lang{$language_selected}{invalidvariable},
878 "invalidvalue" => $kiriwrite_lang{$language_selected}{invalidvalue},
879 "invalidoption" => $kiriwrite_lang{$language_selected}{invalidoption},
880 "variabletoolong" => $kiriwrite_lang{$language_selected}{variabletoolong},
881 "blankdirectory" => $kiriwrite_lang{$language_selected}{blankdirectory},
882 "invaliddirectory" => $kiriwrite_lang{$language_selected}{invaliddirectory},
883 "moduleblank" => $kiriwrite_lang{$language_selected}{moduleblank},
884 "moduleinvalid" => $kiriwrite_lang{$language_selected}{moduleinvalid},
886 # Specific Error Messages
888 "dbdirectorytoolong" => $kiriwrite_lang{$language_selected}{dbdirectorytoolong},
889 "outputdirectorytoolong" => $kiriwrite_lang{$language_selected}{outputdirectorytoolong},
890 "imagesuripathtoolong" => $kiriwrite_lang{$language_selected}{imagesuripathtoolong},
891 "dateformattoolong" => $kiriwrite_lang{$language_selected}{dateformattoolong},
892 "customdateformattoolong" => $kiriwrite_lang{$language_selected}{customdateformattoolong},
893 "languagefilenametoolong" => $kiriwrite_lang{$language_selected}{languagefilenametoolong},
895 "dateformatblank" => $kiriwrite_lang{$language_selected}{dateformatblank},
896 "dateformatinvalid" => $kiriwrite_lang{$language_selected}{dateformatinvalid},
897 "languagefilenameinvalid" => $kiriwrite_lang{$language_selected}{languagefilenameinvalid},
899 "dbdirectoryblank" => $kiriwrite_lang{$language_selected}{dbdirectoryblank},
900 "dbdirectoryinvalid" => $kiriwrite_lang{$language_selected}{dbdirectoryinvalid},
902 "outputdirectoryblank" => $kiriwrite_lang{$language_selected}{outputdirectoryblank},
903 "outputdirectoryinvalid" => $kiriwrite_lang{$language_selected}{outputdirectoryinvalid},
905 "presmoduleblank" => $kiriwrite_lang{$language_selected}{presmoduleblank},
906 "presmoduleinvalid" => $kiriwrite_lang{$language_selected}{presmoduleinvalid},
908 "dbmoduleblank" => $kiriwrite_lang{$language_selected}{dbmoduleblank},
909 "dbmoduleinvalid" => $kiriwrite_lang{$language_selected}{dbmoduleinvalid},
911 "presmodulemissing" => $kiriwrite_lang{$language_selected}{presmodulemissing},
912 "dbmodulemissing" => $kiriwrite_lang{$language_selected}{dbmodulemissing},
913 "languagefilemissing" => $kiriwrite_lang{$language_selected}{languagefilemissing},
915 "servernametoolong" => $kiriwrite_lang{$language_selected}{servernametoolong},
916 "servernameinvalid" => $kiriwrite_lang{$language_selected}{servernameinvalid},
917 "serverportnumbertoolong" => $kiriwrite_lang{$language_selected}{serverportnumbertoolong},
918 "serverportnumberinvalidcharacters" => $kiriwrite_lang{$language_selected}{serverportnumberinvalidcharacters},
919 "serverportnumberinvalid" => $kiriwrite_lang{$language_selected}{serverportnumberinvalid},
920 "serverprotocolnametoolong" => $kiriwrite_lang{$language_selected}{serverprotocolnametoolong},
921 "serverprotocolinvalid" => $kiriwrite_lang{$language_selected}{serverprotocolinvalid},
922 "serverdatabasenametoolong" => $kiriwrite_lang{$language_selected}{serverdatabasenametoolong},
923 "serverdatabasenameinvalid" => $kiriwrite_lang{$language_selected}{serverdatabasenameinvalid},
924 "serverdatabaseusernametoolong" => $kiriwrite_lang{$language_selected}{serverdatabaseusernametoolong},
925 "serverdatabaseusernameinvalid" => $kiriwrite_lang{$language_selected}{serverdatabaseusernameinvalid},
926 "serverdatabasepasswordtoolong" => $kiriwrite_lang{$language_selected}{serverdatabasepasswordtoolong},
927 "serverdatabasetableprefixtoolong" => $kiriwrite_lang{$language_selected}{serverdatabasetableprefixtoolong},
928 "serverdatabasetableprefixinvalid" => $kiriwrite_lang{$language_selected}{serverdatabasetableprefixinvalid},
930 "removeinstallscripttoolong" => $kiriwrite_lang{$language_selected}{removeinstallscripttoolong},
931 "cannotwriteconfigurationindirectory" => $kiriwrite_lang{$language_selected}{cannotwriteconfigurationindirectory},
932 "configurationfilereadpermissionsinvalid" => $kiriwrite_lang{$language_selected}{configurationfilereadpermissionsinvalid},
933 "configurationfilewritepermissionsinvalid" => $kiriwrite_lang{$language_selected}{configurationfilewritepermissionsinvalid},
937 # Check if the specified error is blank and if it is
938 # use the generic error messsage.
940 if (!$kiriwrite_error{$error_type}){
941 $error_type = "generic";
946 print start_html({ -title => $kiriwrite_lang{$language_selected}{error}, -style => { -code => $cssstyle }});
948 print h2($kiriwrite_lang{$language_selected}{error});
950 print $kiriwrite_error{$error_type};
952 print $kiriwrite_lang{$language_selected}{errormessagetext};
960 sub kiriwrite_writeconfig{
961 #################################################################################
962 # kiriwrite_writeconfig: Writes a configuration file. #
966 # kiriwrite_writeconfig(); #
967 #################################################################################
969 my ($passedsettings) = @_;
971 # Open the configuration file for writing.
973 open (my $configfile, "> " . "kiriwrite.xml");
975 print $configfile "<?xml version=\"1.0\"?>
978 <!-- This file was automatically generated by Kiriwrite, please feel free to edit to your own needs. -->
981 <database>" . $passedsettings->{DatabaseDirectory} . "</database>
982 <output>" . $passedsettings->{OutputDirectory} . "</output>
983 <images>" . $passedsettings->{ImagesURIPath} . "</images>
986 <lang>" . $passedsettings->{Language} . "</lang>
989 <presentation>" . $passedsettings->{PresentationModule} . "</presentation>
990 <database>" . $passedsettings->{DatabaseModule} . "</database>
991 <datetime>" . $passedsettings->{DateFormat} . "</datetime>
994 <server>" . $passedsettings->{DatabaseServer} . "</server>
995 <port>" . $passedsettings->{DatabasePort} . "</port>
996 <protocol>" . $passedsettings->{DatabaseProtocol} . "</protocol>
997 <database>" . $passedsettings->{DatabaseName} . "</database>
998 <username>" . $passedsettings->{DatabaseUsername} . "</username>
999 <password>" . $passedsettings->{DatabasePassword} . "</password>
1000 <prefix>" . $passedsettings->{DatabaseTablePrefix} . "</prefix>
1006 close ($configfile);
1010 #################################################################################
1011 # End list of subroutines. #
1012 #################################################################################
1014 if (!$http_query_confirm){
1016 $http_query_confirm = 0;
1020 if ($http_query_confirm eq 1){
1022 # The confirm value has been given so get the data from the query.
1024 my $http_query_dbdirectory = $query->param('dbdirectory');
1025 my $http_query_outputdirectory = $query->param('outputdirectory');
1026 my $http_query_imagesuripath = $query->param('imagesuripath');
1028 my $http_query_dateformat = $query->param('dateformat');
1029 my $http_query_customdateformat = $query->param('customdateformat');
1031 my $http_query_language = $query->param('language');
1033 my $http_query_presmodule = $query->param('presmodule');
1034 my $http_query_dbmodule = $query->param('dbmodule');
1036 my $http_query_databaseserver = $query->param('databaseserver');
1037 my $http_query_databaseport = $query->param('databaseport');
1038 my $http_query_databaseprotocol = $query->param('databaseprotocol');
1039 my $http_query_databasename = $query->param('databasename');
1040 my $http_query_databaseusername = $query->param('databaseusername');
1041 my $http_query_databasepassword = $query->param('databasepassword');
1042 my $http_query_databasetableprefix = $query->param('databasetableprefix');
1043 my $http_query_removeinstallscript = $query->param('removeinstallscript');
1045 # Check the length of the variables.
1047 my $kiriwrite_dbdirectory_length_check = kiriwrite_variablecheck($http_query_dbdirectory, "maxlength", 64, 1);
1048 my $kiriwrite_outputdirectory_length_check = kiriwrite_variablecheck($http_query_outputdirectory, "maxlength", 64, 1);
1049 my $kiriwrite_imagesuripath_length_check = kiriwrite_variablecheck($http_query_imagesuripath, "maxlength", 512, 1);
1050 my $kiriwrite_dateformat_length_check = kiriwrite_variablecheck($http_query_dateformat, "maxlength", 32, 1);
1051 my $kiriwrite_customdateformat_length_check = kiriwrite_variablecheck($http_query_customdateformat, "maxlength", 32, 1);
1052 my $kiriwrite_language_length_check = kiriwrite_variablecheck($http_query_language, "maxlength", 16, 1);
1054 # Check if any errors occured while checking the
1055 # length of the variables.
1057 if ($kiriwrite_dbdirectory_length_check eq 1){
1059 # The database directory given is too long
1060 # so return an error.
1062 kiriwrite_error("dbdirectorytoolong");
1066 if ($kiriwrite_outputdirectory_length_check eq 1){
1068 # The output directory given is too long
1069 # so return an error.
1071 kiriwrite_error("outputdirectorytoolong");
1075 if ($kiriwrite_imagesuripath_length_check eq 1){
1077 # The images URI path given is too long
1078 # so return an error.
1080 kiriwrite_error("imagesuripathtoolong");
1084 if ($kiriwrite_dateformat_length_check eq 1){
1086 # The date format given is too long
1087 # so return an error.
1089 kiriwrite_error("dateformattoolong");
1093 if ($kiriwrite_customdateformat_length_check eq 1){
1095 # The date format given is too long
1096 # so return an error.
1098 kiriwrite_error("customdateformattoolong");
1102 if ($kiriwrite_language_length_check eq 1){
1104 # The language filename given is too long
1105 # so return an error.
1107 kiriwrite_error("languagefilenametoolong");
1111 # Check if the custom date and time setting has anything
1112 # set and if it doesn't then use the predefined one set.
1114 my $finaldateformat = "";
1116 if ($http_query_customdateformat ne ""){
1118 $finaldateformat = $http_query_customdateformat;
1122 $finaldateformat = $http_query_dateformat;
1126 my $kiriwrite_datetime_check = kiriwrite_variablecheck($finaldateformat, "datetime", 0, 1);
1128 if ($kiriwrite_datetime_check eq 1){
1130 # The date and time format is blank so return
1133 kiriwrite_error("dateformatblank");
1135 } elsif ($kiriwrite_datetime_check eq 2){
1137 # The date and time format is invalid so
1140 kiriwrite_error("dateformatinvalid");
1144 # Check if the language filename given is valid.
1146 my $kiriwrite_language_languagefilename_check = kiriwrite_variablecheck($http_query_language, "language_filename", "", 1);
1148 if ($kiriwrite_language_languagefilename_check eq 1) {
1150 # The language filename given is blank so
1153 kiriwrite_error("languagefilenameblank");
1155 } elsif ($kiriwrite_language_languagefilename_check eq 2){
1157 # The language filename given is invalid so
1160 kiriwrite_error("languagefilenameinvalid");
1164 # Check if the directory names only contain letters and numbers and
1165 # return a specific error if they don't.
1167 my $kiriwrite_dbdirectory_check = kiriwrite_variablecheck($http_query_dbdirectory, "directory", 0, 1);
1168 my $kiriwrite_outputdirectory_check = kiriwrite_variablecheck($http_query_outputdirectory, "directory", 0, 1);
1170 if ($kiriwrite_dbdirectory_check eq 1){
1172 # The database directory name is blank, so return
1175 kiriwrite_error("dbdirectoryblank");
1177 } elsif ($kiriwrite_dbdirectory_check eq 2){
1179 # The database directory name is invalid, so return
1182 kiriwrite_error("dbdirectoryinvalid");
1186 if ($kiriwrite_outputdirectory_check eq 1){
1188 # The output directory name is blank, so return
1191 kiriwrite_error("outputdirectoryblank");
1193 } elsif ($kiriwrite_outputdirectory_check eq 2){
1195 # The output directory name is invalid, so return
1198 kiriwrite_error("outputdirectoryinvalid");
1202 if ($kiriwrite_dbdirectory_check eq 1){
1204 # The database directory name is blank, so return
1207 kiriwrite_error("dbdirectoryblank");
1209 } elsif ($kiriwrite_dbdirectory_check eq 2){
1211 # The database directory name is invalid, so return
1214 kiriwrite_error("dbdirectoryinvalid");
1218 if ($kiriwrite_outputdirectory_check eq 1){
1220 # The output directory name is blank, so return
1223 kiriwrite_error("outputdirectoryblank");
1225 } elsif ($kiriwrite_outputdirectory_check eq 2){
1227 # The output directory name is invalid, so return
1230 kiriwrite_error("outputdirectoryinvalid");
1234 # Check the module names to see if they're valid.
1236 my $kiriwrite_presmodule_modulename_check = kiriwrite_variablecheck($http_query_presmodule, "module", 0, 1);
1237 my $kiriwrite_dbmodule_modulename_check = kiriwrite_variablecheck($http_query_dbmodule, "module", 0, 1);
1239 if ($kiriwrite_presmodule_modulename_check eq 1){
1241 # The presentation module name is blank, so return
1244 kiriwrite_error("presmoduleblank");
1248 if ($kiriwrite_presmodule_modulename_check eq 2){
1250 # The presentation module name is invalid, so return
1253 kiriwrite_error("presmoduleinvalid");
1257 if ($kiriwrite_dbmodule_modulename_check eq 1){
1259 # The database module name is blank, so return
1262 kiriwrite_error("dbmoduleblank");
1266 if ($kiriwrite_dbmodule_modulename_check eq 2){
1268 # The database module name is invalid, so return
1271 kiriwrite_error("dbmoduleinvalid");
1275 # Check if the database module, presentation module and
1276 # language file exists.
1278 if (!-e "Modules/Presentation/" . $http_query_presmodule . ".pm"){
1280 # The presentation module is missing so return an
1283 kiriwrite_error("presmodulemissing");
1287 if (!-e "Modules/Database/" . $http_query_dbmodule . ".pm"){
1289 # The database module is missing so return an
1292 kiriwrite_error("dbmodulemissing");
1296 if (!-e "lang/" . $http_query_language . ".xml"){
1298 # The language file is missing so return an
1301 kiriwrite_error("languagefilenamemissing");
1305 # Check the database server settings.
1307 my $kiriwrite_databaseserver_length_check = kiriwrite_variablecheck($http_query_databaseserver, "maxlength", 128, 1);
1308 my $kiriwrite_databaseserver_lettersnumbers_check = kiriwrite_variablecheck($http_query_databaseserver, "lettersnumbers", 0, 1);
1309 my $kiriwrite_databaseport_length_check = kiriwrite_variablecheck($http_query_databaseport, "maxlength", 5, 1);
1310 my $kiriwrite_databaseport_numbers_check = kiriwrite_variablecheck($http_query_databaseport, "numbers", 0, 1);
1311 my $kiriwrite_databaseport_port_check = kiriwrite_variablecheck($http_query_databaseport, "port", 0, 1);
1312 my $kiriwrite_databaseprotocol_length_check = kiriwrite_variablecheck($http_query_databaseprotocol, "maxlength", 5, 1);
1313 my $kiriwrite_databaseprotocol_protocol_check = kiriwrite_variablecheck($http_query_databaseprotocol, "serverprotocol", 0, 1);
1314 my $kiriwrite_databasename_length_check = kiriwrite_variablecheck($http_query_databasename, "maxlength", 32, 1);
1315 my $kiriwrite_databasename_lettersnumbers_check = kiriwrite_variablecheck($http_query_databasename, "lettersnumbers", 0, 1);
1316 my $kiriwrite_databaseusername_length_check = kiriwrite_variablecheck($http_query_databaseusername, "maxlength", 16, 1);
1317 my $kiriwrite_databaseusername_lettersnumbers_check = kiriwrite_variablecheck($http_query_databaseusername, "lettersnumbers", 0, 1);
1318 my $kiriwrite_databasepassword_length_check = kiriwrite_variablecheck($http_query_databasepassword, "maxlength", 64, 1);
1319 my $kiriwrite_databasetableprefix_length_check = kiriwrite_variablecheck($http_query_databasetableprefix, "maxlength", 16, 1);
1320 my $kiriwrite_databasetableprefix_lettersnumbers_check = kiriwrite_variablecheck($http_query_databasetableprefix, "lettersnumbers", 0, 1);
1322 if ($kiriwrite_databaseserver_length_check eq 1){
1324 # The length of the database server name is too long so
1327 kiriwrite_error("servernametoolong");
1331 if ($kiriwrite_databaseserver_lettersnumbers_check eq 1){
1333 # The database server name contains characters other
1334 # than letters and numbers, so return an error.
1336 kiriwrite_error("servernameinvalid");
1340 if ($kiriwrite_databaseport_length_check eq 1){
1342 # The database port number length is too long so return
1345 kiriwrite_error("serverportnumbertoolong");
1349 if ($kiriwrite_databaseport_numbers_check eq 1){
1351 # The database port number contains characters other
1352 # than numbers so return an error.
1354 kiriwrite_error("serverportnumberinvalidcharacters");
1358 if ($kiriwrite_databaseport_port_check eq 1){
1360 # The database port number given is invalid so return
1363 kiriwrite_error("serverportnumberinvalid");
1367 if ($kiriwrite_databaseprotocol_length_check eq 1){
1369 # The database protocol name given is too long so
1372 kiriwrite_error("serverprotocolnametoolong");
1376 if ($kiriwrite_databaseprotocol_protocol_check eq 1){
1378 # The server protcol given is invalid so return
1381 kiriwrite_error("serverprotocolinvalid");
1385 if ($kiriwrite_databasename_length_check eq 1){
1387 # The SQL database name is too long so return
1390 kiriwrite_error("serverdatabasenametoolong");
1394 if ($kiriwrite_databasename_lettersnumbers_check eq 1){
1396 # The database name contains invalid characters
1397 # so return an error.
1399 kiriwrite_error("serverdatabasenameinvalid");
1403 if ($kiriwrite_databaseusername_length_check eq 1){
1405 # The database username given is too long so
1408 kiriwrite_error("serverdatabaseusernametoolong");
1412 if ($kiriwrite_databaseusername_lettersnumbers_check eq 1){
1414 # The database username contains invalid characters
1415 # so return an error.
1417 kiriwrite_error("serverdatabaseusernameinvalid");
1421 if ($kiriwrite_databasepassword_length_check eq 1){
1423 # The database password given is too long so return
1426 kiriwrite_error("serverdatabasepasswordtoolong");
1430 if ($kiriwrite_databasetableprefix_length_check eq 1){
1432 # The database table prefix given is too long so
1435 kiriwrite_error("serverdatabasetableprefixtoolong");
1439 if ($kiriwrite_databasetableprefix_lettersnumbers_check eq 1){
1441 # The database table prefix given contains invalid
1442 # characters so return an error.
1444 kiriwrite_error("serverdatabasetableprefixinvalid");
1448 # Check the length of value of the checkboxes.
1450 my $kiriwrite_removeinstallscript_length_check = kiriwrite_variablecheck($http_query_removeinstallscript, "maxlength", 2, 1);
1452 if ($kiriwrite_removeinstallscript_length_check eq 1){
1454 # The remove install script value is too long
1455 # so return an error.
1457 kiriwrite_error("removeinstallscripttoolong");
1461 # Check if there is write permissions for the directory.
1465 # No write permissions for the directory the
1466 # script is running from so return an error.
1468 kiriwrite_error("cannotwriteconfigurationindirectory");
1472 # Check if the configuration file already exists.
1474 if (-e 'kiriwrite.xml'){
1476 # Check if the configuration file has read permissions.
1478 if (!-r 'kiriwrite.xml'){
1480 # The configuration file has invalid read permissions
1481 # set so return an error.
1483 kiriwrite("configurationfilereadpermissionsinvalid");
1487 # Check if the configuration file has write permissions.
1489 if (!-w 'kiriwrite.xml'){
1491 # The configuration file has invalid write permissions
1492 # set so return an error.
1494 kiriwrite("configurationfilewritepermissionsinvalid");
1500 # Write the new configuration file.
1502 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 });
1504 my $installscriptmessage = "";
1506 # Check if the installation script should be deleted.
1508 if (!$http_query_removeinstallscript){
1510 $http_query_removeinstallscript = "off";
1514 if ($http_query_removeinstallscript eq "on"){
1516 if (unlink("install.cgi")){
1518 $installscriptmessage = $kiriwrite_lang{$language_selected}{installscriptremoved};
1522 $installscriptmessage = $kiriwrite_lang{$language_selected}{cannotremovescript};
1523 $installscriptmessage =~ s/%s/$!/g;
1527 #"Unable to remove the installer script: " . $! . " The installer script will have to be deleted manually.";
1535 print start_html({ -title => $kiriwrite_lang{$language_selected}{installertitle}, -style => { -code => $cssstyle }});
1536 print h2($kiriwrite_lang{$language_selected}{installertitle});
1537 print $kiriwrite_lang{$language_selected}{installedmessage};
1539 if ($installscriptmessage){
1543 print $installscriptmessage;
1549 print $kiriwrite_lang{$language_selected}{usekiriwritetext};
1552 print a({-href=>'kiriwrite.cgi'}, $kiriwrite_lang{$language_selected}{usekiriwritelink});
1558 # Create a list of common date and time formats.
1560 my @datetime_formats = [
1561 'DD/MM/YY (hh:mm:ss)', 'DD/MM/YY hh:mm:ss', 'D/M/Y (hh:mm:ss)',
1562 'D/M/Y hh:mm:ss', 'D/M/YY (hh:mm:ss)', 'D/M/YY hh:mm:ss',
1563 'DD/MM (hh:mm:ss)', 'D/M (hh:mm:ss)', 'DD/MM hh:mm:ss',
1564 'D/M hh:mm:ss', 'DD/MM hh:mm', 'D/M hh:mm',
1565 'DD/MM/YY', 'D/M/Y', 'DD/MM',
1567 'YY-MM-DD (hh:mm:ss)', 'YY-MM-DD hh:mm:ss', 'Y-M-D (hh:mm:ss)',
1568 'Y-M-D hh:mm:ss', 'M-D (hh:mm:ss)', 'M-D hh:mm:ss',
1572 # Create the list of tests to do.
1574 my ($test_list, %test_list);
1575 my %dependency_results;
1576 my %database_results;
1581 my $dependency_error = 0;
1582 my $database_onemodule = 0;
1583 my $database_error = 0;
1587 my $language_xml_data;
1588 my $language_file_friendly;
1590 my $presentation_file_friendly;
1592 # Check to see if the needed Perl modules are installed.
1594 $test_list{CheckDBI}{Name} = "DBI";
1595 $test_list{CheckDBI}{Type} = "dependency";
1596 $test_list{CheckDBI}{Code} = "DBI";
1598 $test_list{CheckXMLSimple}{Name} = "XML::Simple";
1599 $test_list{CheckXMLSimple}{Type} = "dependency";
1600 $test_list{CheckXMLSimple}{Code} = "XML::Simple";
1602 $test_list{CheckXMLParser}{Name} = "XML::Parser";
1603 $test_list{CheckXMLParser}{Type} = "dependency";
1604 $test_list{CheckXMLParser}{Code} = "XML::Parser";
1606 $test_list{CheckTieHash}{Name} = "Tie::IxHash";
1607 $test_list{CheckTieHash}{Type} = "dependency";
1608 $test_list{CheckTieHash}{Code} = "Tie::IxHash";
1610 $test_list{Encode}{Name} = "Encode";
1611 $test_list{Encode}{Type} = "dependency";
1612 $test_list{Encode}{Code} = "Encode";
1614 $test_list{DBDmysql}{Name} = "DBD::mysql";
1615 $test_list{DBDmysql}{Type} = "database";
1616 $test_list{DBDmysql}{Code} = "DBD::mysql";
1618 $test_list{DBDSQLite}{Name} = "DBD::SQLite";
1619 $test_list{DBDSQLite}{Type} = "database";
1620 $test_list{DBDSQLite}{Code} = "DBD::SQLite";
1622 # Check the file and directory permissions to see if they are correct.
1624 $test_list{MainDirectory}{Name} = "Kiriwrite Directory (.)";
1625 $test_list{MainDirectory}{Type} = "file";
1626 $test_list{MainDirectory}{Code} = ".";
1627 $test_list{MainDirectory}{Writeable} = "1";
1629 $test_list{LanguageDirectory}{Name} = "Language Directory (lang)";
1630 $test_list{LanguageDirectory}{Type} = "file";
1631 $test_list{LanguageDirectory}{Code} = "lang";
1632 $test_list{LanguageDirectory}{Writeable} = "0";
1634 $test_list{ModulesDirectory}{Name} = "Modules Directory (Modules)";
1635 $test_list{ModulesDirectory}{Type} = "file";
1636 $test_list{ModulesDirectory}{Code} = "Modules";
1637 $test_list{ModulesDirectory}{Writeable} = "0";
1639 $test_list{DBModulesDirectory}{Name} = "Database Modules Directory (Modules/Database)";
1640 $test_list{DBModulesDirectory}{Type} = "file";
1641 $test_list{DBModulesDirectory}{Code} = "Modules/Database";
1642 $test_list{DBModulesDirectory}{Writeable} = "0";
1644 $test_list{PresModulesDirectory}{Name} = "Presentation Modules Directory (Modules/Presentation)";
1645 $test_list{PresModulesDirectory}{Type} = "file";
1646 $test_list{PresModulesDirectory}{Code} = "Modules/Presentation";
1647 $test_list{PresModulesDirectory}{Writeable} = "0";
1649 # Preform those tests.
1651 foreach $test (keys %test_list){
1653 # Check the type of test.
1655 if ($test_list{$test}{Type} eq "dependency"){
1657 if (eval "require " . $test_list{$test}{Code}){
1659 # The module exists and is working correctly.
1661 $dependency_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1665 # The module does not exist or has an error.
1667 $dependency_error = 1;
1668 $dependency_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testfail};
1672 } elsif ($test_list{$test}{Type} eq "database"){
1674 if (eval "require " . $test_list{$test}{Code}){
1676 # The module exists and it is working correctly.
1678 $database_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1679 $database_onemodule = 1;
1683 # The module does not exist or has an error.
1685 $database_error = 1;
1686 $database_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testfail};
1690 } elsif ($test_list{$test}{Type} eq "file"){
1692 if (-e $test_list{$test}{Code}){
1694 # The filename given does exist.
1698 # the filename given does not exist.
1701 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{doesnotexist};
1705 # Test to see if the filename given has read
1708 if (-r $test_list{$test}{Code}){
1710 # The filename given has valid permissions set.
1712 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1716 # The filename given has invalid permissions set.
1719 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{invalidpermissionsset};
1723 if ($test_list{$test}{Writeable} eq 1){
1725 # Test to see if the filename given has write
1728 if (-w $test_list{$test}{Code}){
1730 # The filename given has valid permissions set.
1732 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{testpass};
1736 # The filename given has invalid permissions set.
1739 $file_results{$test_list{$test}{Name}}{result} = $kiriwrite_lang{$language_selected}{errormessage} . $kiriwrite_lang{$language_selected}{invalidpermissionsset};
1753 # Print the page for installing Kiriwrite.
1755 print start_html( -title=> $kiriwrite_lang{$language_selected}{installertitle}, -style => { -code => $cssstyle });
1757 print start_table( { -width=> "100%" } );
1759 print start_td({ -class => "languagebar" });
1760 print $kiriwrite_lang{$language_selected}{installertitle};
1762 print start_td({ -class => "languagebarselect" });
1763 print start_form("POST", "install.cgi");
1765 # This is a bodge for the language list.
1767 my $language_name_short;
1768 my $language_list_seek = 0;
1770 print "<select name=\"installlanguage\">";
1772 foreach $language_name_short (@language_list_short){
1774 print "<option value=\"" . $language_name_short . "\">" . $language_list_long[$language_list_seek] . "</option>";
1775 $language_list_seek++;
1780 print submit($kiriwrite_lang{$language_selected}{switch});
1787 print h2($kiriwrite_lang{$language_selected}{installertitle});
1789 print $kiriwrite_lang{$language_selected}{installertext};
1791 print h3($kiriwrite_lang{$language_selected}{dependencytitle});
1792 print h4($kiriwrite_lang{$language_selected}{requiredmodules});
1793 print $kiriwrite_lang{$language_selected}{perlmodules};
1797 if ($dependency_error eq 1){
1799 print $kiriwrite_lang{$language_selected}{errormessage};
1800 print $kiriwrite_lang{$language_selected}{dependencyperlmodulesmissing};
1806 print start_table();
1808 print start_td({ -class => "tablecellheader" });
1809 print $kiriwrite_lang{$language_selected}{module};
1811 print start_td({ -class => "tablecellheader" });
1812 print $kiriwrite_lang{$language_selected}{result};
1816 foreach $test (keys %dependency_results) {
1819 print start_td({ -class => "tablename" });
1822 print start_td({ -class => "tabledata" });
1823 print $dependency_results{$test}{result};
1831 print h4($kiriwrite_lang{$language_selected}{databasemodules});
1832 print $kiriwrite_lang{$language_selected}{databasemodulestext};
1836 if ($database_error eq 1){
1838 print $kiriwrite_lang{$language_selected}{warningmessage};
1839 print $kiriwrite_lang{$language_selected}{databaseperlmodulesmissing};
1845 print start_table();
1847 print start_td({ -class => "tablecellheader" });
1848 print $kiriwrite_lang{$language_selected}{module};
1850 print start_td({ -class => "tablecellheader" });
1851 print $kiriwrite_lang{$language_selected}{result};
1855 foreach $test (keys %database_results) {
1858 print start_td({ -class => "tablename" });
1861 print start_td({ -class => "tabledata" });
1862 print $database_results{$test}{result};
1870 print h4($kiriwrite_lang{$language_selected}{filepermissions});
1872 print $kiriwrite_lang{$language_selected}{filepermissionstext};
1876 if ($file_error eq 1){
1878 print $kiriwrite_lang{$language_selected}{errormessage};
1879 print $kiriwrite_lang{$language_selected}{filepermissionsinvalid};
1885 print start_table();
1887 print start_td({ -class => "tablecellheader" });
1890 print start_td({ -class => "tablecellheader" });
1895 foreach $test (keys %file_results) {
1898 print start_td({ -class => "tablename" });
1901 print start_td({ -class => "tabledata" });
1902 print $file_results{$test}{result};
1910 if ($dependency_error eq 1){
1913 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1914 print $kiriwrite_lang{$language_selected}{dependencymodulesnotinstalled};
1920 if ($database_onemodule eq 0){
1923 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1924 print $kiriwrite_lang{$language_selected}{databasemodulesnotinstalled};
1930 if ($file_error eq 1){
1933 print h4($kiriwrite_lang{$language_selected}{criticalerror});
1934 print $kiriwrite_lang{$language_selected}{filepermissionerrors};
1941 my (%available_languages, $available_languages);
1942 my @presentation_modules;
1943 my @database_modules;
1945 my $presentation_modules_ref = \@presentation_modules;
1946 my $database_modules_ref = \@database_modules;
1948 # Get the list of available languages.
1950 tie(%available_languages, 'Tie::IxHash');
1952 opendir(LANGUAGEDIR, "lang");
1953 my @language_directory = grep /m*\.xml$/, readdir(LANGUAGEDIR);
1954 closedir(LANGUAGEDIR);
1956 my $xsl = XML::Simple->new();
1958 foreach my $language_file (@language_directory){
1960 # Load the XML data.
1962 $language_xml_data = $xsl->XMLin("lang/" . $language_file);
1964 # Get the friendly name for the language file.
1966 $language_file_friendly = $language_file;
1967 $language_file_friendly =~ s/.xml$//g;
1969 $language_name = $language_xml_data->{about}->{name};
1971 $available_languages{$language_file_friendly} = $language_name . " (" . $language_file_friendly . ")";
1975 # Get the list of presentation modules.
1977 opendir(OUTPUTSYSTEMDIR, "Modules/Presentation");
1978 my @presmodule_directory = grep /m*\.pm$/, readdir(OUTPUTSYSTEMDIR);
1979 closedir(OUTPUTSYSTEMDIR);
1981 foreach my $presmodule_file (@presmodule_directory){
1983 # Get the friendly name for the database module.
1985 $presmodule_file =~ s/.pm$//g;
1987 push(@presentation_modules, $presmodule_file);
1991 # Get the list of database modules.
1993 opendir(DATABASEDIR, "Modules/Database");
1994 my @dbmodule_directory = grep /m*\.pm$/, readdir(DATABASEDIR);
1995 closedir(DATABASEDIR);
1997 foreach my $dbmodule_file (@dbmodule_directory){
1999 # Get the friendly name for the database module.
2001 $dbmodule_file =~ s/.pm$//g;
2003 push(@database_modules, $dbmodule_file);
2007 print h3($kiriwrite_lang{$language_selected}{settingstitle});
2009 print $kiriwrite_lang{$language_selected}{settingstext};
2013 print start_form("POST", "install.cgi");
2014 print hidden( -name => 'confirm', -default => '1');
2015 print hidden( -name => 'installlanguage', -default => $language_selected);
2017 print start_table({ -width => "100%" });
2020 print start_td({ -class => "tablecellheader" });
2021 print $kiriwrite_lang{$language_selected}{setting};
2023 print start_td({ -class => "tablecellheader" });
2024 print $kiriwrite_lang{$language_selected}{value};
2029 print start_td({ -class => "tablecellheader" });
2030 print $kiriwrite_lang{$language_selected}{directories};
2032 print start_td({ -class => "tablecellheader" });
2037 print start_td({ -class => "tablename" });
2038 print $kiriwrite_lang{$language_selected}{databasedirectory};
2040 print start_td({ -class => "tabledata" });
2041 print textfield({ -name => "dbdirectory", -size => 32, -maxlength => 64, -value => $default_dbdirectory });
2046 print start_td({ -class => "tablename" });
2047 print $kiriwrite_lang{$language_selected}{outputdirectory};
2049 print start_td({ -class => "tabledata" });
2050 print textfield({ -name => "outputdirectory", -size => 32, -maxlength => 64, -value => $default_outputdirectory });
2055 print start_td({ -class => "tablename" });
2056 print $kiriwrite_lang{$language_selected}{imagesuripath};
2058 print start_td({ -class => "tabledata" });
2059 print textfield({ -name => "imagesuripath", -size => 32, -maxlength => 64, -value => $default_imagesuri });
2064 print start_td({ -class => "tablecellheader" });
2065 print $kiriwrite_lang{$language_selected}{date};
2067 print start_td({ -class => "tablecellheader" });
2073 print start_td({ -class => "tablename" });
2074 print $kiriwrite_lang{$language_selected}{dateformat};
2076 print start_td({ -class => "tabledata" });
2078 print popup_menu( -name => "dateformat", -values => @datetime_formats );
2079 print textfield({ -name => "customdateformat", -size => 32, -maxlength => 64, });
2085 print start_td({ -class => "tablecellheader" });
2086 print $kiriwrite_lang{$language_selected}{language};
2088 print start_td({ -class => "tablecellheader" });
2093 print start_td({ -class => "tablename" });
2094 print $kiriwrite_lang{$language_selected}{systemlanguage};
2096 print start_td({ -class => "tabledata" });
2098 # Note: This the following code is bodge. If anyone can fix it so that it all works
2099 # with popup_menu properly it will be appriciated.
2101 print "<select name=\"language\">";
2103 foreach my $language (keys %available_languages){
2105 if ($language eq $language_selected){
2107 print "<option value=\"" . $language . "\" selected=selected>" . $available_languages{$language} . "</option>";
2111 print "<option value=\"" . $language . "\">" . $available_languages{$language} . "</option>";
2123 print start_td({ -class => "tablecellheader" });
2124 print $kiriwrite_lang{$language_selected}{modules};
2126 print start_td({ -class => "tablecellheader" });
2132 print start_td({ -class => "tablename" });
2133 print $kiriwrite_lang{$language_selected}{presentationmodule};
2135 print start_td({ -class => "tabledata" });
2136 print popup_menu({ -name => 'presmodule', -values => $presentation_modules_ref, -default => "HTML4S" });
2141 print start_td({ -class => "tablename" });
2142 print $kiriwrite_lang{$language_selected}{databasemodule};
2144 print start_td({ -class => "tabledata" });
2145 print popup_menu({ -name => 'dbmodule', -values => $database_modules_ref, -default => "SQLite" });
2150 print start_td({ -class => "tablename" });
2151 print $kiriwrite_lang{$language_selected}{databaseserver};
2153 print start_td({ -class => "tabledata" });
2154 print textfield({ -name => "databaseserver", -size => 32, -maxlength => 128, -value => $default_server });
2159 print start_td({ -class => "tablename" });
2160 print $kiriwrite_lang{$language_selected}{databaseport};
2162 print start_td({ -class => "tabledata" });
2163 print textfield({ -name => "databaseport", -maxlength => 5, -size => 5, -value => $default_port });
2168 print start_td({ -class => "tablename" });
2169 print $kiriwrite_lang{$language_selected}{databaseprotocol};
2171 print start_td({ -class => "tabledata" });
2172 print popup_menu( -name => "databaseprotocol", -values => [ 'tcp', 'udp' ], -default => $default_protocol);
2177 print start_td({ -class => "tablename" });
2178 print $kiriwrite_lang{$language_selected}{databasename};
2180 print start_td({ -class => "tabledata" });
2181 print textfield({ -name => "databasename", -size => 32, -maxlength => 32, -default => $default_name });
2186 print start_td({ -class => "tablename" });
2187 print $kiriwrite_lang{$language_selected}{databaseusername};
2189 print start_td({ -class => "tabledata" });
2190 print textfield({ -name => "databaseusername", -size => 16, -maxlength => 16, -default => $default_username });
2195 print start_td({ -class => "tablename" });
2196 print $kiriwrite_lang{$language_selected}{databasepassword};
2198 print start_td({ -class => "tabledata" });
2199 print password_field({ -name => "databasepassword", -size => 32, -maxlength => 64 });
2204 print start_td({ -class => "tablename" });
2205 print $kiriwrite_lang{$language_selected}{databasetableprefix};
2207 print start_td({ -class => "tabledata" });
2208 print textfield({ -name => "databasetableprefix", -size => 32, -maxlength => 32, -default => $default_prefix });
2213 print start_td({ -class => "tablecellheader" });
2214 print $kiriwrite_lang{$language_selected}{installationoptions};
2216 print start_td({ -class => "tablecellheader" });
2222 print start_td({ -class => "tablename" });
2223 print $kiriwrite_lang{$language_selected}{installoptions};
2225 print start_td({ -class => "tabledata" });
2226 print checkbox( -name => 'removeinstallscript', -checked => 1, -label => " " . $kiriwrite_lang{$language_selected}{removeinstallscript});
2233 print submit($kiriwrite_lang{$language_selected}{savesettingsbutton});
2235 print reset($kiriwrite_lang{$language_selected}{resetsettingsbutton});