home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / oss / cvs-2004 / bahasa / utilities / config_app.pl,v < prev    next >
Text File  |  2003-12-07  |  32KB  |  1,476 lines

  1. head    1.11;
  2. access;
  3. symbols
  4.     Initial:1.1.1.1 bule:1.1.1;
  5. locks; strict;
  6. comment    @# @;
  7.  
  8.  
  9. 1.11
  10. date    2003.12.07.07.43.54;    author bule;    state Exp;
  11. branches;
  12. next    1.10;
  13.  
  14. 1.10
  15. date    2003.10.26.01.53.09;    author bule;    state Exp;
  16. branches;
  17. next    1.9;
  18.  
  19. 1.9
  20. date    2003.10.17.00.39.35;    author bule;    state Exp;
  21. branches;
  22. next    1.8;
  23.  
  24. 1.8
  25. date    2003.10.04.18.22.57;    author bule;    state Exp;
  26. branches;
  27. next    1.7;
  28.  
  29. 1.7
  30. date    2003.09.05.06.42.30;    author bule;    state Exp;
  31. branches;
  32. next    1.6;
  33.  
  34. 1.6
  35. date    2003.08.31.18.48.47;    author bule;    state Exp;
  36. branches;
  37. next    1.5;
  38.  
  39. 1.5
  40. date    2003.08.22.00.46.20;    author bule;    state Exp;
  41. branches;
  42. next    1.4;
  43.  
  44. 1.4
  45. date    2003.08.21.20.20.57;    author bule;    state Exp;
  46. branches;
  47. next    1.3;
  48.  
  49. 1.3
  50. date    2003.08.21.06.18.06;    author bule;    state Exp;
  51. branches;
  52. next    1.2;
  53.  
  54. 1.2
  55. date    2003.08.19.06.20.01;    author bule;    state Exp;
  56. branches;
  57. next    1.1;
  58.  
  59. 1.1
  60. date    2003.08.12.19.18.23;    author bule;    state Exp;
  61. branches
  62.     1.1.1.1;
  63. next    ;
  64.  
  65. 1.1.1.1
  66. date    2003.08.12.19.18.23;    author bule;    state Exp;
  67. branches;
  68. next    ;
  69.  
  70.  
  71. desc
  72. @@
  73.  
  74.  
  75. 1.11
  76. log
  77. @*** empty log message ***
  78. @
  79. text
  80. @#!/usr/bin/perl -w
  81. #/////////////////////////////////////////////////////////////////////////////
  82. #/////////////////////////////////////////////////////////////////////////////
  83. #/ Project Name: Bahasa Indonesia Dictionary
  84. #/ Directory:    bahasa/utilities
  85. #/ File Name:    config_app.pl 
  86. #/ Author(s):    John L. Whiteman
  87. #/ Created:      June 23, 2003  
  88. #/ Modified:     November 08, 2003
  89. #/ Description:  The purpose of this PERL script is to assist you 
  90. #/               with installing the Bahasa Indonesia Dictionary 
  91. #/               application.  It doesn't create the database.  Use 
  92. #/               the config_db.pl script to help you with configuring 
  93. #/               the database required for this project.  
  94. #/ 
  95. #/ Copyright (c) 2003 John L. Whiteman
  96. #/
  97. #/ Permission is herby granted, free of charge, to any person obtaining a 
  98. #/ copy of this software, data, and associated documentation files 
  99. #/ (the "Software"), to deal in the Software without restriction, 
  100. #/ including without limitation the rights to use, copy, modify, merge, 
  101. #/ publish, distribute, sublicense, and/or sell copies of Software, and to
  102. #/ permit persons to whom the Software is furnished to do so, subject to 
  103. #/ the following conditions:
  104. #/
  105. #/ The above copyright notice and this permission notice shall be 
  106. #/ included in all copies or substantial portions of the Software.
  107. #/
  108. #/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  109. #/ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  110. #/ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  111. #/ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
  112. #/ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
  113. #/ TORT OR OTHERWISE, ARISING IN THE SOFTWARE.  
  114. #/////////////////////////////////////////////////////////////////////////////
  115. #/////////////////////////////////////////////////////////////////////////////
  116. use strict;
  117. use Cwd;
  118. use File::Copy;
  119.  
  120. show_introduction();
  121.  
  122. while(1) {
  123.  
  124.     my ($response) = 
  125.     promptyn("Would you like to continue?");
  126.  
  127.     if (!$response) {
  128.  
  129.         print "\nInstallation script terminated!\n\n";
  130.  
  131.         exit(0);
  132.     }
  133.  
  134.     last;
  135. }
  136.  
  137. my (%DICTIONARY_CFG) = ();
  138.  
  139. $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} = 
  140. prompt_installation_directory();
  141.  
  142. my ($SLASH) = "/";
  143.  
  144. $SLASH = "\\"
  145. if ($DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} =~ /\\/);
  146.  
  147. #These are all the required directories and 
  148. #files associated with this project.
  149. #They are followed by default permissions.
  150. #Change these permissions to best suite your needs 
  151. #Add your own files and directories if applicable
  152. #Changing the paths to these files is likely cause
  153. #the project to fail
  154. my (%manifest) = (
  155. "backups" => 0703,
  156. "docs" => 0700,
  157. "mysql" => 0703,
  158. "php" => 0701,
  159. "utilities" => 0700,
  160. "web" => 0700,
  161. "backups${SLASH}empty.sql" => 0600,
  162. "docs${SLASH}installation.txt" => 0600,
  163. "docs${SLASH}readme.txt" => 0600,
  164. "mysql${SLASH}administration.sql" => 0606,
  165. "mysql${SLASH}administrators.sql" => 0606,
  166. "mysql${SLASH}alphabet.sql" => 0606,
  167. "mysql${SLASH}create.sql" => 0604,
  168. "mysql${SLASH}destroy.sql" => 0604,
  169. "mysql${SLASH}dictionary.sql" => 0606,
  170. "mysql${SLASH}hits.sql" => 0606,
  171. "mysql${SLASH}misses.sql" => 0606,
  172. "mysql${SLASH}parts_of_speech.sql" => 0606,
  173. "mysql${SLASH}pronunciations.sql" => 0606,
  174. "mysql${SLASH}requests.sql" => 0606,
  175. "mysql${SLASH}searches.sql" => 0606,
  176. "mysql${SLASH}tasks.sql" => 0606,
  177. "php${SLASH}Dictionary.php" => 0604,
  178. "php${SLASH}Indonesia.php" => 0604,
  179. "php${SLASH}Statistics.php" => 0604,
  180. "php${SLASH}Web.php" => 0604,
  181. "utilities${SLASH}config_app.pl" => 0700,
  182. "utilities${SLASH}config_db.pl" => 0700,
  183. "utilities${SLASH}make_release_ready.pl" => 0700,
  184. "web${SLASH}admin.php" => 0604, 
  185. "web${SLASH}admins.php" => 0604, 
  186. "web${SLASH}backup.php" => 0604, 
  187. "web${SLASH}bahasa.css" => 0604, 
  188. "web${SLASH}bahasa.js" => 0604, 
  189. "web${SLASH}cpwd.php" => 0604, 
  190. "web${SLASH}delete.php" => 0604, 
  191. "web${SLASH}dictionary.php" => 0604, 
  192. "web${SLASH}download.php" => 0604, 
  193. "web${SLASH}editor.php" => 0604, 
  194. "web${SLASH}email.php" => 0604, 
  195. "web${SLASH}help.php" => 0604, 
  196. "web${SLASH}insert.php" => 0604, 
  197. "web${SLASH}ipa.php" => 0604, 
  198. "web${SLASH}login.php" => 0604, 
  199. "web${SLASH}logout.php" => 0604, 
  200. "web${SLASH}misses.php" => 0604, 
  201. "web${SLASH}offline.php" => 0604, 
  202. "web${SLASH}online.php" => 0604, 
  203. "web${SLASH}pos.php" => 0604, 
  204. "web${SLASH}pronunciations.php" => 0604, 
  205. "web${SLASH}reference.php" => 0604, 
  206. "web${SLASH}request.php" => 0604, 
  207. "web${SLASH}requests.php" => 0604, 
  208. "web${SLASH}search.php" => 0604, 
  209. "web${SLASH}sql.php" => 0604, 
  210. "web${SLASH}statistics.php" => 0604,
  211. "web${SLASH}update.php" => 0604,
  212. "web${SLASH}upload.php" => 0604
  213. );
  214.  
  215. my (%class_files) = (
  216.  
  217. "php${SLASH}Indonesia.php" =>
  218. "php${SLASH}Dictionary.php",
  219.  
  220. "php${SLASH}Statistics.php" =>
  221. "php${SLASH}Dictionary.php");
  222.  
  223. my (%web_files) = (
  224.  
  225. "web${SLASH}admin.php" => 
  226. "php${SLASH}Indonesia.php",
  227.  
  228. "web${SLASH}admins.php" => 
  229. "php${SLASH}Indonesia.php",
  230.  
  231. "web${SLASH}backup.php" => 
  232. "php${SLASH}Indonesia.php",
  233.  
  234. "web${SLASH}bahasa.css" => 
  235. "php${SLASH}Indonesia.php",
  236.  
  237. "web${SLASH}bahasa.js" => 
  238. "php${SLASH}Indonesia.php",
  239.  
  240. "web${SLASH}cpwd.php" =>
  241. "php${SLASH}Indonesia.php",
  242.  
  243. "web${SLASH}delete.php" =>
  244. "php${SLASH}Indonesia.php",
  245.  
  246. "web${SLASH}download.php" =>
  247. "php${SLASH}Indonesia.php",
  248.  
  249. "web${SLASH}dictionary.php" =>
  250. "php${SLASH}Indonesia.php",
  251.  
  252. "web${SLASH}editor.php" =>
  253. "php${SLASH}Indonesia.php",
  254.  
  255. "web${SLASH}email.php" =>
  256. "php${SLASH}Indonesia.php",
  257.  
  258. "web${SLASH}help.php" =>
  259. "php${SLASH}Indonesia.php",
  260.  
  261. "web${SLASH}insert.php" =>
  262. "php${SLASH}Indonesia.php",
  263.  
  264. "web${SLASH}ipa.php" =>
  265. "php${SLASH}Indonesia.php",
  266.  
  267. "web${SLASH}login.php" =>
  268. "php${SLASH}Indonesia.php",
  269.  
  270. "web${SLASH}logout.php" =>
  271. "php${SLASH}Indonesia.php",
  272.  
  273. "web${SLASH}misses.php" =>
  274. "php${SLASH}Indonesia.php",
  275.  
  276. "web${SLASH}offline.php" =>
  277. "php${SLASH}Indonesia.php",
  278.  
  279. "web${SLASH}online.php" =>
  280. "php${SLASH}Indonesia.php",
  281.  
  282. "web${SLASH}pos.php" =>
  283. "php${SLASH}Indonesia.php",
  284.  
  285. "web${SLASH}pronunciations.php" =>
  286. "php${SLASH}Indonesia.php",
  287.  
  288. "web${SLASH}reference.php" =>
  289. "php${SLASH}Indonesia.php",
  290.  
  291. "web${SLASH}request.php" =>  
  292. "php${SLASH}Indonesia.php",
  293.  
  294. "web${SLASH}requests.php" =>  
  295. "php${SLASH}Indonesia.php",
  296.  
  297. "web${SLASH}search.php" =>
  298. "php${SLASH}Indonesia.php",
  299.  
  300. "web${SLASH}sql.php" =>
  301. "php${SLASH}Indonesia.php",
  302.  
  303. "web${SLASH}statistics.php" =>  
  304. "php${SLASH}Statistics.php",
  305.  
  306. "web${SLASH}tasks.php" =>  
  307. "php${SLASH}Indonesia.php",
  308.  
  309. "web${SLASH}update.php" =>  
  310. "php${SLASH}Indonesia.php",
  311.  
  312. "web${SLASH}upload.php" =>  
  313. "php${SLASH}Indonesia.php");
  314.  
  315. my ($dictionary_class) = "php${SLASH}Dictionary.php";
  316.  
  317. my ($web_class) = "php${SLASH}Web.php";
  318.  
  319. my (%modified_manifest) = ();
  320.  
  321. print "Verifying setup directories and files...\n\n";
  322.  
  323. #Now verify that all directories and files exist
  324. #We will change the permissions only after the 
  325. #configuration is finished.
  326. foreach(sort(keys(%manifest))) {
  327.  
  328.     my ($path) = $_;
  329.  
  330.     my ($permissions) = $manifest{$path};
  331.  
  332.     $path = 
  333.     $DICTIONARY_CFG{INSTALLATION_DIRECTORY} . $SLASH . $path; 
  334.  
  335.     $modified_manifest{$path} = $permissions;
  336.  
  337.     print "${path} ";
  338.  
  339.     show_error("\nCan't find ${path}", -1) if (!-e "$path");
  340.  
  341.     print "[OK]\n";
  342. }
  343.  
  344. $DICTIONARY_CFG{"DB_HOST"} = 
  345. prompt("What is or will be the name or IP address of the database server?", 1);
  346.  
  347. $DICTIONARY_CFG{"DB_NAME"} = 
  348. prompt("What is or will be the database name for the dictionary database?", 1);
  349.  
  350. $DICTIONARY_CFG{"DB_USER"} = 
  351. prompt("What is or will be the database user's name?", 1);
  352.  
  353. $DICTIONARY_CFG{"DB_PASSWORD"} = 
  354. prompt("What is or will be $DICTIONARY_CFG{DB_USER}'s password?", 1);
  355.  
  356. while(1) {
  357.  
  358.     $DICTIONARY_CFG{"EMAIL"} = 
  359.     prompt("What is or will be the website's primary e-mail address?", 1);
  360.  
  361.     last if (is_email($DICTIONARY_CFG{"EMAIL"}));
  362.  
  363.     show_error(
  364.     "This doesn't appear to be a valid e-mail address.  Try again.", 0);
  365. }
  366.  
  367. my (%modified_web_files) = ();
  368.  
  369. #Qualify the default directories by prepending the installation 
  370. #directories then check to ensure the files exist then assign 
  371. #then to hash that indicates which class file to use.  These files
  372. #pertain to the PHP web code.
  373. foreach(sort(keys(%web_files))) {
  374.  
  375.     my ($web_file) = 
  376.     $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  377.     $SLASH . ${_};
  378.  
  379.     my ($class_file) = 
  380.     $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  381.     $SLASH . $web_files{$_};
  382.  
  383.     #Check here if exists...abort if doesn't
  384.     show_error(
  385.     "Can't find PHP web file ${web_file}\n" .
  386.     "Please make sure you installation path is correct.", -1)
  387.         if (!-f "$web_file");
  388.  
  389.     #Check here if exists...abort if doesn't
  390.     show_error(
  391.     "Can't find PHP class file ${class_file}\n" .
  392.     "Please make sure you installation path is correct.", -1)
  393.         if (!-f "$class_file");
  394.  
  395.     $modified_web_files{"$web_file"} = "$class_file";
  396. }
  397.  
  398. my (%modified_class_files) = ();
  399.  
  400. #Do the same for child class files 
  401. foreach(sort(keys(%class_files))) {
  402.  
  403.     my ($child_class) = 
  404.     $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  405.     $SLASH . ${_};
  406.  
  407.     my ($parent_class) = 
  408.     $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  409.     $SLASH . $class_files{$_};
  410.  
  411.     #Check here if exists...abort if doesn't
  412.     show_error(
  413.     "Can't find PHP class file ${child_class}\n" .
  414.     "Please make sure you installation path is correct.", -1)
  415.         if (!-f "$child_class");
  416.  
  417.     #Check here if exists...abort if doesn't
  418.     show_error(
  419.     "Can't find PHP parent class file ${parent_class}\n" .
  420.     "Please make sure you installation path is correct.", -1)
  421.         if (!-f "$parent_class");
  422.  
  423.     $modified_class_files{"$child_class"} = "$parent_class";
  424. }
  425.  
  426. #Dictionary class is the parent class of everything 
  427. $dictionary_class = $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  428. $SLASH . $dictionary_class;
  429.  
  430. #Check here if exists...abort if doesn't
  431. show_error(
  432. "Can't find PHP parent dictionary class file ${dictionary_class}\n" .
  433. "Please make sure you installation path is correct.", -1)
  434.     if (!-f "$dictionary_class");
  435.  
  436. #Web class to be inserted into web PHP files
  437. $web_class = $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"} . 
  438. $SLASH . $web_class;
  439.  
  440. #Check here if exists...abort if doesn't
  441. show_error(
  442. "Can't find PHP web class file ${web_class}\n" .
  443. "Please make sure you installation path is correct.", -1)
  444.     if (!-f "$web_class");
  445.  
  446. #Verify that configuration values given are correct before 
  447. #proceeding 
  448. while(1) {
  449.  
  450.     print "\n[VERIFY THESE VALUES]\n\n";
  451.  
  452.     foreach(sort(keys(%DICTIONARY_CFG))) {
  453.  
  454.         my ($name) = $_;
  455.  
  456.         my ($value) = $DICTIONARY_CFG{$name};
  457.  
  458.         print "${name} = ${value}\n";
  459.     }
  460.  
  461.     my ($response) = 
  462.     promptyn("Are these values correct?");
  463.  
  464.     if (!$response) {
  465.  
  466.         print "\nInstallation script terminated!\n\n";
  467.  
  468.         exit(0);
  469.     }
  470.  
  471.     last;
  472. }
  473.  
  474. print "Configuring Dictionary.pm class file...\n";
  475.  
  476. #Configure the Dictionary.php class with given values
  477. configure_dictionary_class("$dictionary_class", \%DICTIONARY_CFG, $SLASH);
  478.  
  479. print "Configuring other class files...\n";
  480.  
  481. #Modify the web files' require_once() statements to include full path
  482. #to source class files
  483. foreach(sort(keys(%modified_class_files))) {
  484.  
  485.     my ($child_class) = $_;
  486.  
  487.     my ($parent_class) = $modified_class_files{$child_class};
  488.  
  489.     configure_php_file($child_class, $parent_class, $SLASH, "");
  490. }
  491.  
  492. print "Configuring PHP web files...\n";
  493.  
  494. #Modify the web files' require_once() statements to include full path
  495. #to source class files
  496. foreach(sort(keys(%modified_web_files))) {
  497.  
  498.     my ($web_file) = $_;
  499.  
  500.     my ($class_file) = $modified_web_files{$web_file};
  501.  
  502.     configure_php_file($web_file, $class_file, $SLASH, $web_class);
  503. }
  504.  
  505. print "Setting default permissions to directories and files...\n";
  506.  
  507. change_permissions(\%modified_manifest);
  508.  
  509. #Prompt if user wants to install web files to web server
  510. while(1) {
  511.  
  512.     my ($response) = 
  513.     promptyn(
  514.     "Would you like to install the PHP web files to your web server?");
  515.      
  516.     if (!$response) {
  517.  
  518.         print 
  519.         "\nInstallation script done!\n" .
  520.         "Once again double check permissions " .
  521.         "for directories and files.\n\n"; 
  522.  
  523.         exit(0);
  524.     }
  525.  
  526.     last;
  527. }
  528.  
  529. #Change permissions to installation directory
  530. chmod(0701, $DICTIONARY_CFG{"INSTALLATION_DIRECTORY"});
  531.  
  532. my ($web_directory) = "";
  533.  
  534. #Prompt for web server installation directory
  535. while(1) {
  536.  
  537. TRY_AGAIN:
  538.  
  539.     $web_directory = 
  540.     prompt(
  541.     "What is the name of the web directory to copy the " .
  542.     "PHP web files?", 1); 
  543.  
  544.     #Remove trailing slash for UNIX systems if exists
  545.     $web_directory =~ s/\/$//;
  546.  
  547.     #Remove trailing slash for Windows systems if exists
  548.     $web_directory =~ s/\\$//;
  549.  
  550.     if (!-d "$web_directory") {
  551.  
  552.         show_error(    
  553.         "Web directory ${web_directory} does not exist.\n"  .
  554.         "Manually create this directory or use an existing one\n" .
  555.         "before continuing.  I'll wait.", 0);
  556.  
  557.         my ($response) =
  558.         promptyn("Try again?", 1);  
  559.  
  560.         if (!$response) {
  561.  
  562.             print 
  563.             "\nInstallation script done.\n" .
  564.             "Manually copy web PHP files and sub-directories " .
  565.             "when you are ready.\n\n"; 
  566.  
  567.             exit(0);
  568.         } 
  569.  
  570.     } else {
  571.  
  572.         my ($response) = 
  573.         promptyn("Is web directory ${web_directory} correct?");
  574.  
  575.         if (!$response) {
  576.  
  577.             $response = 
  578.             promptyn(
  579.             "Would you like to try another web directory?"); 
  580.  
  581.             goto TRY_AGAIN if ($response);
  582.  
  583.             print 
  584.             "\nInstallation script done.\n" .
  585.             "Manually copy web PHP files and sub-directories " .
  586.             "when you are ready.\n\n"; 
  587.  
  588.             exit(0);
  589.         }
  590.  
  591.         last;
  592.     }
  593. }
  594.  
  595. print "Copying PHP web files...\n";
  596.  
  597. foreach(sort(keys(%modified_web_files))) {
  598.  
  599.     my ($src) = $_;
  600.     my ($tgt) = $web_directory . $SLASH . get_basename($src); 
  601.  
  602.     copy("$src", "$tgt");
  603.  
  604.     chmod(0604, "$tgt");
  605.  
  606.     show_error(
  607.     "Can't copy\n${src} to\n${tgt}\n" .
  608.     "Read documentation about manual web installation.", -1) 
  609.         if (!-f "$tgt");
  610. }
  611.  
  612. print 
  613. "Installation script done!\n" .
  614. "Once again double check permissions for directories and files.\n\n"; 
  615.  
  616. #----------------------------------------------------------------------------
  617. #Changes installation directories and files to default permissions 
  618. #----------------------------------------------------------------------------
  619. sub change_permissions {
  620.  
  621.     my ($modified_manifest) = shift;
  622.  
  623.     foreach(sort(keys(%$modified_manifest))) {
  624.  
  625.         my ($path) = $_;
  626.  
  627.         my ($permissions) = $$modified_manifest{$path};
  628.  
  629.         chmod($permissions, $path);
  630.     }
  631.  
  632.     return;
  633. }
  634. #----------------------------------------------------------------------------
  635. #Configures the Dictionary.pm class files to run under this environment.
  636. #----------------------------------------------------------------------------
  637. sub configure_dictionary_class {
  638.  
  639.     my ($file) = shift;
  640.     my ($cfg) = shift;
  641.     my ($slash) = shift;
  642.     my ($file_backup) = $file . "." . $$ . ".bak"; 
  643.     my ($cfg_entry) = "";
  644.  
  645.     #Compose the dictionary configuration PHP entries
  646.     #Also change permissions to directories if applicable
  647.     foreach(sort(keys(%$cfg))) {
  648.  
  649.         my ($name) = $_;
  650.         my ($value) = $$cfg{$_};
  651.  
  652.         $value =~ s/\\/\\\\/g
  653.         if (($name eq "INSTALLATION_DIRECTORY") && ($slash eq "\\"));
  654.  
  655.         $cfg_entry .= 
  656.         "\$this->configuration[\"${name}\"] = \"${value}\";\n\n"; 
  657.     }
  658.  
  659.     #Clean it up
  660.     chomp($cfg_entry);
  661.  
  662.     #Remove existing backup file if exists
  663.     unlink("$file_backup") if (-f "$file_backup");
  664.  
  665.     #Make a backup copy just to be safe
  666.     copy("$file", "$file_backup") || goto RECOVER_AND_ABORT_A;
  667.  
  668.     #Remove the original file
  669.     unlink("$file");
  670.  
  671.     #Create a new PHP file 
  672.     open(NEW_FILE, ">${file}") || goto RECOVER_AND_ABORT_B;
  673.  
  674.     #Open the original file (backup)
  675.     open(OLD_FILE, "${file_backup}") || goto RECOVERY_AND_ABORT_C;
  676.  
  677.     my ($ignore_flag) = 0;
  678.  
  679.     while(<OLD_FILE>) {
  680.  
  681.         my ($tmp) = $_;
  682.  
  683.         if ($tmp =~ /\/\/\<CONFIGURATION\>/) {
  684.  
  685.             print NEW_FILE $tmp;
  686.  
  687.             print NEW_FILE $cfg_entry; 
  688.  
  689.             $ignore_flag = 1;
  690.  
  691.             next;
  692.  
  693.         } elsif (($tmp =~ /\/\/\<\/CONFIGURATION\>/) &&
  694.                  ($ignore_flag)) { 
  695.  
  696.             print NEW_FILE $tmp;
  697.  
  698.             $ignore_flag = 0;
  699.  
  700.         } elsif (!$ignore_flag) {
  701.  
  702.             print NEW_FILE $tmp;
  703.         }
  704.     }
  705.  
  706.     close(NEW_FILE);
  707.  
  708.     close(OLD_FILE);
  709.  
  710.     #Double check to ensure new file exists
  711.     goto  RECOVERY_AND_ABORT_D if (!-f "$file");
  712.  
  713.     #Remove the backup file
  714.     unlink("$file_backup") if (-f "$file_backup");
  715.  
  716.     #Give proper permissions
  717.     chmod(0604, "$file");
  718.  
  719.     return;
  720.  
  721. RECOVER_AND_ABORT_A:
  722.  
  723.     #Remove backup if exists
  724.     unlink("$file_backup") if (-f "$file_backup");
  725.  
  726.     show_error(
  727.     "Can't copy ${file} to ${file_backup}\n" .
  728.     "Make sure you have proper permissions or enough space.",
  729.     -1);
  730.  
  731. RECOVER_AND_ABORT_B:
  732.  
  733.     close(NEW_FILE);
  734.  
  735.     #Remove the new file if it was partially created
  736.     unlink("$file");
  737.  
  738.     #Move backup file back to its original spot
  739.     move("$file_backup", "$file"); 
  740.  
  741.     if (!-f "$file") {
  742.  
  743.         show_error(
  744.         "Could not configure and restore PHP file ${file}\n" .
  745.         "Correct the error and reinstall before running " .
  746.         "this script again.", -1); 
  747.     }
  748.  
  749.     show_error(
  750.     "Could not configure PHP file ${file}\n" .
  751.     "Correct the error and try again.", -1); 
  752.  
  753. RECOVER_AND_ABORT_C:
  754.  
  755.     close(NEW_FILE);
  756.  
  757.     close(OLD_FILE);
  758.  
  759.     #Remove the new file if it was partially created
  760.     unlink("$file");
  761.  
  762.     #Move backup file back to its original spot
  763.     move("$file_backup", "$file");
  764.  
  765.     if (!-f "$file") {
  766.  
  767.         show_error(
  768.         "Could not configure and restore PHP file ${file}\n" .
  769.         "Correct the error and reinstall before running " .
  770.         "this script again.", -1); 
  771.     }
  772.  
  773.     show_error(
  774.     "Could not configure PHP file ${file}\n" .
  775.     "Correct the error and try again.", -1); 
  776.  
  777. RECOVER_AND_ABORT_D:
  778.  
  779.     #Remove the new file if it was partially created
  780.     unlink("$file");
  781.  
  782.     #Move backup file back to its original spot
  783.     move("$file_backup", "$file");
  784.  
  785.     if (!-f "$file") {
  786.  
  787.         show_error(
  788.         "Could not configure and restore PHP file ${file}\n" .
  789.         "Correct the error and reinstall before running " .
  790.         "this script again.", -1); 
  791.     }
  792.  
  793.     show_error(
  794.     "Could not configure PHP file ${file}\n" .
  795.     "Correct the error and try again.", -1); 
  796. }
  797. #----------------------------------------------------------------------------
  798. #Configures PHP files to include required absolute class file paths
  799. #----------------------------------------------------------------------------
  800. sub configure_php_file {
  801.  
  802.     my ($file) = shift; 
  803.     my ($class_file) = shift;
  804.     my ($slash) = shift;
  805.     my ($web_class) = shift || "";
  806.     my ($file_backup) = $file . "." . $$ . ".bak"; 
  807.  
  808.     #Remove existing backup file if exists
  809.     unlink("$file_backup") if (-f "$file_backup");
  810.  
  811.     #Make a backup copy just to be safe
  812.     copy("$file", "$file_backup") || goto RECOVER_AND_ABORT_A;
  813.  
  814.     #Remove the original file
  815.     unlink("$file");
  816.  
  817.     #Create a new PHP file 
  818.     open(NEW_FILE, ">${file}") || goto RECOVER_AND_ABORT_B;
  819.  
  820.     #Open the original file (backup)
  821.     open(OLD_FILE, "${file_backup}") || goto RECOVERY_AND_ABORT_C;
  822.  
  823.     $class_file =~ s/\\/\\\\/g if ($slash eq "\\");
  824.  
  825.     #New require_once() string
  826.     my ($new_require) = 
  827.     "require_once(\"${class_file}\");\n";
  828.  
  829.     #Also add web class if applicable
  830.     if ($web_class ne "") {
  831.  
  832.         $web_class =~ s/\\/\\\\/g if ($slash eq "\\");
  833.  
  834.         $new_require .= 
  835.         "require_once(\"${web_class}\");\n";
  836.     }
  837.  
  838.     my ($ignore_old_require_flag) = 0;
  839.  
  840.     while(<OLD_FILE>) {
  841.  
  842.         my ($tmp) = $_;
  843.  
  844.         #Insert the new one
  845.         if (
  846.         ($tmp =~ /require_once\(/) && 
  847.         ($tmp =~ /\)\;/) && 
  848.         (!$ignore_old_require_flag)) {
  849.  
  850.             print NEW_FILE $new_require; 
  851.  
  852.             $ignore_old_require_flag = 1;
  853.  
  854.         #Ignore the old requires
  855.         } elsif (
  856.           ($tmp =~ /require_once\(/) && 
  857.           ($tmp =~ /\)\;/))  {
  858.  
  859.             next;
  860.  
  861.         }  else {
  862.  
  863.             print NEW_FILE $tmp; 
  864.         }
  865.     }
  866.  
  867.     close(NEW_FILE);
  868.  
  869.     close(OLD_FILE);
  870.  
  871.     #Double check to ensure new file exists
  872.     goto  RECOVERY_AND_ABORT_D if (!-f "$file");
  873.  
  874.     #Remove the backup file
  875.     unlink("$file_backup") if (-f "$file_backup");
  876.  
  877.     chmod(0604, "$file");
  878.  
  879.     return;
  880.  
  881. RECOVER_AND_ABORT_A:
  882.  
  883.     #Remove backup if exists
  884.     unlink("$file_backup") if (-f "$file_backup");
  885.  
  886.     show_error(
  887.     "Can't copy ${file} to ${file_backup}\n" .
  888.     "Make sure you have propery permissions or enough space.",
  889.     -1);
  890.  
  891. RECOVER_AND_ABORT_B:
  892.  
  893.     close(NEW_FILE);
  894.  
  895.     #Remove the new file if it was partially created
  896.     unlink("$file");
  897.  
  898.     #Move backup file back to its original spot
  899.     move("$file_backup", "$file"); 
  900.  
  901.     if (!-f "$file") {
  902.  
  903.         show_error(
  904.         "Could not configure and restore PHP file ${file}\n" .
  905.         "Correct the error and reinstall before running " .
  906.         "this script again.", -1); 
  907.     }
  908.  
  909.     show_error(
  910.     "Could not configure PHP file ${file}\n" .
  911.     "Correct the error and try again.", -1); 
  912.  
  913. RECOVER_AND_ABORT_C:
  914.  
  915.     close(NEW_FILE);
  916.  
  917.     close(OLD_FILE);
  918.  
  919.     #Remove the new file if it was partially created
  920.     unlink("$file");
  921.  
  922.     #Move backup file back to its original spot
  923.     move("$file_backup", "$file");
  924.  
  925.     if (!-f "$file") {
  926.  
  927.         show_error(
  928.         "Could not configure and restore PHP file ${file}\n" .
  929.         "Correct the error and reinstall before running " .
  930.         "this script again.", -1); 
  931.     }
  932.  
  933.     show_error(
  934.     "Could not configure PHP file ${file}\n" .
  935.     "Correct the error and try again.", -1); 
  936.  
  937. RECOVER_AND_ABORT_D:
  938.  
  939.     #Remove the new file if it was partially created
  940.     unlink("$file");
  941.  
  942.     #Move backup file back to its original spot
  943.     move("$file_backup", "$file");
  944.  
  945.     if (!-f "$file") {
  946.  
  947.         show_error(
  948.         "Could not configure and restore PHP file ${file}\n" .
  949.         "Correct the error and reinstall before running " .
  950.         "this script again.", -1); 
  951.     }
  952.  
  953.     show_error(
  954.     "Could not configure PHP file ${file}\n" .
  955.     "Correct the error and try again.", -1); 
  956. }
  957. #----------------------------------------------------------------------------
  958. #Returns the basename of a path
  959. #----------------------------------------------------------------------------
  960. sub get_basename {
  961.  
  962.     my ($path) = shift;
  963.     my (@@path_tree) = shift;
  964.  
  965.     if ($path =~ /\\/) {
  966.  
  967.         @@path_tree = split(/\\/, $path);
  968.  
  969.         return($path_tree[$#path_tree]);
  970.  
  971.     } elsif ($path =~ /\//) {
  972.  
  973.         @@path_tree = split(/\//, $path);
  974.  
  975.         return($path_tree[$#path_tree]);
  976.     }
  977.  
  978.     return($path);
  979. }
  980. #----------------------------------------------------------------------------
  981. #Verifies given token is an e-mail address.  This can be greatly enhanced.
  982. #It just looks for @@ and . with spacing before, in between, and after for 
  983. #the time being.  Should be good enough though.
  984. #----------------------------------------------------------------------------
  985. sub is_email {
  986.  
  987.     my ($token) = shift;
  988.  
  989.     return(1) if ($token =~ /\w+\@@\w+\.\w+/);
  990. }
  991. #----------------------------------------------------------------------------
  992. #Generic prompt 
  993. #----------------------------------------------------------------------------
  994. sub prompt {
  995.  
  996.     my ($prompt) = shift;
  997.     my ($required_flag) = shift;
  998.     my ($response) = "";
  999.  
  1000.     #Iterate until correct response is found
  1001.     while(1) {
  1002.  
  1003.         #Show prompt message
  1004.         print "\n${prompt}\n\n";
  1005.  
  1006.         #Grab response
  1007.         $response = <STDIN>;
  1008.  
  1009.         #Remove leading and trailing white-spaces
  1010.         trim(\$response);
  1011.         
  1012.         if (($response) eq "" && ($required_flag)) {
  1013.  
  1014.             show_error("This parameter requires a value!", 0);
  1015.     
  1016.             next;
  1017.         } 
  1018.  
  1019.         last;
  1020.     }
  1021.  
  1022.     return($response);
  1023. }
  1024. #----------------------------------------------------------------------------
  1025. #Generic yes or no prompt.  Returns 1 for yes and 0 for no. 
  1026. #----------------------------------------------------------------------------
  1027. sub promptyn {
  1028.  
  1029.     my ($prompt) = shift;
  1030.     my ($response);
  1031.     my ($ucresponse);
  1032.     my (%responses) = (YES => 1, NO => 1, Y => 1, N => 1);
  1033.  
  1034.     #Iterate until correct response is found
  1035.     while(1) {
  1036.  
  1037.         #Show prompt message
  1038.         print "\n${prompt} [y|n]\n\n";
  1039.  
  1040.         #Grab response
  1041.         $response = <STDIN>;
  1042.         
  1043.         #Clean leading and trailing white spaces
  1044.         trim(\$response);
  1045.  
  1046.         if ($response eq "") {
  1047.  
  1048.             show_error(
  1049.             "Please respond with a 'y' or 'n' answer!", 0);
  1050.  
  1051.             next;
  1052.  
  1053.         }  else {
  1054.  
  1055.             $ucresponse = uc($response);
  1056.  
  1057.             if (exists($responses{$ucresponse})) {
  1058.  
  1059.                 last;
  1060.  
  1061.             } else {
  1062.  
  1063.                 show_error(
  1064.                 "Please respond with a 'y' or 'n' answer!", 0);
  1065.             }
  1066.         }
  1067.     }
  1068.  
  1069.     return(1) if ($ucresponse =~ /^Y/);
  1070.  
  1071.     return(0);
  1072. }
  1073. #----------------------------------------------------------------------------
  1074. #Generic prompt with default
  1075. #----------------------------------------------------------------------------
  1076. sub promptx {
  1077.  
  1078.     my ($prompt) = shift;
  1079.     my ($default) = shift;
  1080.     my ($required_flag) = shift;
  1081.     my ($response) = "";
  1082.  
  1083.     #Iterate until correct response is found
  1084.     while(1) {
  1085.  
  1086.         print "\n${prompt} [${default}]\n\n";
  1087.  
  1088.         $response = <STDIN>;
  1089.  
  1090.         chomp($response);
  1091.  
  1092.         if ($response eq "") {
  1093.  
  1094.             $response = $default;
  1095.  
  1096.             last;
  1097.  
  1098.         } else {
  1099.  
  1100.             trim(\$response);
  1101.  
  1102.             if (($response) eq "" && ($required_flag)) {
  1103.  
  1104.                 show_error(
  1105.                 "This parameter requires a value!", 0);
  1106.  
  1107.                 next;
  1108.  
  1109.             } else {
  1110.  
  1111.  
  1112.                 last;
  1113.             }
  1114.         }
  1115.     }
  1116.  
  1117.     return("$response");
  1118. }
  1119. #----------------------------------------------------------------------------
  1120. #Prompt for installation directory
  1121. #----------------------------------------------------------------------------
  1122. sub prompt_installation_directory {
  1123.  
  1124.     my ($pwd) = cwd();
  1125.     my ($default_dir) = "";
  1126.     my ($installation_directory) = "";
  1127.  
  1128.     if ($pwd) {
  1129.  
  1130.         if (-d "$pwd") {
  1131.  
  1132.             show_error(
  1133.             "You must run this installation script " .
  1134.             "under the same directory that it resides.", -1)
  1135.                 if ($pwd !~ /utilities$/);
  1136.  
  1137.             $default_dir = $pwd;
  1138.  
  1139.             $default_dir =~ s/\/utilities$//;
  1140.         } 
  1141.     }
  1142.  
  1143.     if (-d "$default_dir") {
  1144.  
  1145.         while(1) {
  1146.  
  1147.             $installation_directory =
  1148.             promptx(
  1149.             "Enter the installation directory:\n", 
  1150.             "$default_dir", 1);
  1151.     
  1152.             if (!-d "$installation_directory") {
  1153.  
  1154.                 show_error(
  1155.                 "'${installation_directory}'" .
  1156.                 " does not exists.  Please try again.", 0);
  1157.  
  1158.                 next;
  1159.             }
  1160.  
  1161.             last;
  1162.         }
  1163.  
  1164.     } else {
  1165.  
  1166.  
  1167.         while(1) {
  1168.     
  1169.             $installation_directory =
  1170.             prompt("Enter the installation directory: ", 1);
  1171.  
  1172.             if (!-d "$installation_directory") {
  1173.  
  1174.                 show_error(
  1175.                 "'${installation_directory}'" .
  1176.                 " does not exists.  Please try again.", 0);
  1177.  
  1178.                 next;
  1179.             }
  1180.  
  1181.             last;
  1182.         }
  1183.     }
  1184.  
  1185.     #Remove trailing slash for UNIX systems if exists
  1186.     $installation_directory =~ s/\/$//;
  1187.  
  1188.     #Remove trailing slash for Windows systems if exists
  1189.     $installation_directory =~ s/\\$//;
  1190.  
  1191.     return("$installation_directory");
  1192. }
  1193. #----------------------------------------------------------------------------
  1194. #Display error message then terminate script
  1195. #----------------------------------------------------------------------------
  1196. sub show_error {
  1197.  
  1198.     my ($msg) = shift;
  1199.     my ($exit_flag) = shift || 0;
  1200.  
  1201.     print "\nInstallation Error:\n${msg}\n\n";
  1202.  
  1203.     exit(-1) if ($exit_flag);
  1204.  
  1205.     return;
  1206. }
  1207. #----------------------------------------------------------------------------
  1208. #Introduction message
  1209. #----------------------------------------------------------------------------
  1210. sub show_introduction {
  1211.  
  1212.     print <<EOF;
  1213.  
  1214. /////////////////////////////////////////////////////////////////////////////
  1215.          BAHASA INDONESIA DICTIONARY APPLICATION CONFIGURATION SCRIPT
  1216. /////////////////////////////////////////////////////////////////////////////
  1217.  
  1218. Copyright (c) 2003 John L. Whiteman
  1219.  
  1220. Permission is herby granted, free of charge, to any person obtaining a 
  1221. copy of this software, data, and associated documentation files 
  1222. (the "Software"), to deal in the Software without restriction, 
  1223. including without limitation the rights to use, copy, modify, merge, 
  1224. publish, distribute, sublicense, and/or sell copies of Software, and to
  1225. permit persons to whom the Software is furnished to do so, subject to 
  1226. the following conditions:
  1227.  
  1228. The above copyright notice and this permission notice shall be 
  1229. included in all copies or substantial portions of the Software.
  1230.  
  1231. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  1232. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  1233. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  1234. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
  1235. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
  1236. TORT OR OTHERWISE, ARISING IN THE SOFTWARE.  
  1237.  
  1238. /////////////////////////////////////////////////////////////////////////////
  1239.  
  1240. The purpose of this script is to configure 
  1241. the Bahasa Indonesia Dictionary PHP files to
  1242. run on this host.  It doesn't do any 
  1243. mySQL database configuration, but it will 
  1244. prompt you for database questions.  
  1245.  
  1246. This script assumes that your web server is
  1247. running on this host.  You are responsible 
  1248. for setting the correct permissions for 
  1249. these files after configuration.
  1250.  
  1251. I've tried to make this script as portable 
  1252. as possible.  If for some reason this script 
  1253. fails then you will have to configure the files
  1254. manually.  See documentation for more details. 
  1255.  
  1256. Please feel free to modify this script to what
  1257. best fits your needs.
  1258.  
  1259. You can abort at any time by pressing CTRL C.
  1260.  
  1261. /////////////////////////////////////////////////////////////////////////////
  1262.  
  1263. EOF
  1264.  
  1265.     return;
  1266. }
  1267. #----------------------------------------------------------------------------
  1268. #Trim leading and trailing white-spaces from string token.  Pass token by
  1269. #reference only.
  1270. #----------------------------------------------------------------------------
  1271. sub trim {
  1272.  
  1273.     my ($token) = shift;
  1274.  
  1275.     return if (!$token);
  1276.  
  1277.     $$token =~ s/^\s+//;
  1278.     $$token =~ s/\s+$//;
  1279.  
  1280.     return;
  1281. }
  1282. #----------------------------------------------------------------------------
  1283. #----------------------------------------------------------------------------
  1284. @
  1285.  
  1286.  
  1287. 1.10
  1288. log
  1289. @*** empty log message ***
  1290. @
  1291. text
  1292. @d9 1
  1293. a9 1
  1294. #/ Modified:     October 21, 2003
  1295. d153 6
  1296. @
  1297.  
  1298.  
  1299. 1.9
  1300. log
  1301. @*** empty log message ***
  1302. @
  1303. text
  1304. @d9 1
  1305. a9 1
  1306. #/ Modified:     October 16, 2003
  1307. d116 1
  1308. d118 1
  1309. d173 3
  1310. d177 3
  1311. @
  1312.  
  1313.  
  1314. 1.8
  1315. log
  1316. @*** empty log message ***
  1317. @
  1318. text
  1319. @d9 1
  1320. a9 1
  1321. #/ Modified:     October 01, 2003
  1322. d108 2
  1323. @
  1324.  
  1325.  
  1326. 1.7
  1327. log
  1328. @*** empty log message ***
  1329. @
  1330. text
  1331. @d9 1
  1332. a9 1
  1333. #/ Modified:     September 04, 2003
  1334. d433 3
  1335. @
  1336.  
  1337.  
  1338. 1.6
  1339. log
  1340. @*** empty log message ***
  1341. @
  1342. text
  1343. @d9 1
  1344. a9 1
  1345. #/ Modified:     August 31, 2003
  1346. d94 1
  1347. a94 1
  1348. "mysql${SLASH}pronunciation.sql" => 0606,
  1349. d121 1
  1350. d188 3
  1351. @
  1352.  
  1353.  
  1354. 1.5
  1355. log
  1356. @*** empty log message ***
  1357. @
  1358. text
  1359. @d9 1
  1360. a9 1
  1361. #/ Modified:     August 21, 2003
  1362. d112 1
  1363. d160 3
  1364. @
  1365.  
  1366.  
  1367. 1.4
  1368. log
  1369. @*** empty log message ***
  1370. @
  1371. text
  1372. @d416 1
  1373. a416 1
  1374.         "\nInstallation script completed!\n" .
  1375. d507 1
  1376. a507 1
  1377. "\nInstallation script completed!\n" .
  1378. @
  1379.  
  1380.  
  1381. 1.3
  1382. log
  1383. @*** empty log message ***
  1384. @
  1385. text
  1386. @d9 1
  1387. a9 1
  1388. #/ Modified:     August 20, 2003
  1389. d82 3
  1390. d876 1
  1391. a876 1
  1392. #It just lloks for @@ and . with spacing before, in between, and after for 
  1393. d1106 1
  1394. a1106 3
  1395.     print "\n\n";
  1396.  
  1397.     print "-" x 77;
  1398. d1108 23
  1399. a1130 1
  1400.     print "\n";
  1401. d1132 1
  1402. a1132 2
  1403.     print <<EOF;
  1404. [BAHASA INDONESIA DICTIONARY CONFIGURATION]
  1405. d1150 2
  1406. a1151 2
  1407. Please feel free to modify this script to best 
  1408. fit your needs.
  1409. d1155 2
  1410. a1157 4
  1411.  
  1412.     print "-" x 77;
  1413.  
  1414.     print "\n";
  1415. @
  1416.  
  1417.  
  1418. 1.2
  1419. log
  1420. @*** empty log message ***
  1421. @
  1422. text
  1423. @d9 1
  1424. a9 1
  1425. #/ Modified:     August 18, 2003
  1426. d52 1
  1427. a52 1
  1428.         exit;
  1429. d101 1
  1430. d362 1
  1431. a362 1
  1432.         exit;
  1433. d373 1
  1434. a373 1
  1435. print "Configuring other class file...\n";
  1436. d412 4
  1437. a415 1
  1438.         print "\nInstallation script completed!\n\n";
  1439. d417 1
  1440. a417 1
  1441.         exit;
  1442. d428 2
  1443. d444 1
  1444. a444 1
  1445.         "Directory ${web_directory} does not exist.\n"  .
  1446. d458 1
  1447. a458 1
  1448.             exit;
  1449. d463 19
  1450. d916 1
  1451. a916 1
  1452. #Generic yes or no prompt 
  1453. d1026 1
  1454. a1026 1
  1455.                 if ($pwd !~ /bahasa\/utilities$/);
  1456. @
  1457.  
  1458.  
  1459. 1.1
  1460. log
  1461. @Initial revision
  1462. @
  1463. text
  1464. @d2 35
  1465. a1132 1
  1466.  
  1467. @
  1468.  
  1469.  
  1470. 1.1.1.1
  1471. log
  1472. @Bahasa Indonesia Dictionary
  1473. @
  1474. text
  1475. @@
  1476.