"Fossies" - the Fresh Open Source Software Archive

Member "node-runner-0.6.0/installer.php" (29 Dec 2004, 39885 Bytes) of package /linux/www/old/node-runner-0.6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "installer.php" see the Fossies "Dox" file reference documentation.

    1 <?
    2 ## This script serves as an installer for Node Runner 0.6.0.
    3 ## To run this script, use it as a parameter to your PHP interpreter
    4 ## from the command line. (e.g. /usr/bin/php -q installer).
    5 
    6 // Turn off PHP's Safe Mode and adjust max_execution_time (Windows Hack)
    7 $safe_mode_off = ini_set("safe_mode", "0");
    8 $max_time = ini_set("max_execution_time", "9999");
    9 
   10 // Turn off error reporting (it's built-in to this script).
   11 error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
   12 
   13 
   14 // COMMON FUNCTIONS
   15 
   16 function dir_contents($dir) {
   17   // Returns array of file names from $dir
   18   $i=0;
   19   if ($use_dir = @opendir($dir)) {
   20     while (($file = readdir($use_dir)) != false) {
   21       if (($file != ".") && ($file != "..")) {
   22         $files_array[$i] = "$file";
   23         $i++;
   24       }
   25     }
   26     closedir($use_dir);
   27   }
   28   return $files_array;
   29 }
   30 
   31 function copyr($source, $dest) {
   32   // Copies contents of directory recursively
   33   // Simple copy for a file
   34   if (is_file($source)) {      
   35       return copy($source, $dest);      
   36   }
   37 
   38   // Make destination directory  
   39   if (!is_dir($dest)) {
   40       $success = mkdir($dest, 0755);      
   41       if (!$success) { return false; }
   42   }
   43  
   44   // Loop through the folder
   45   $use_dir = @opendir($source);
   46   while (($entry = readdir($use_dir)) != false) {
   47       // Skip pointers
   48       if ($entry == '.' || $entry == '..') {
   49           continue;
   50       }
   51 
   52       if ((ereg("/", $dest)) &&  (substr($dest, -1) != '/')) {
   53         $dest .= '/';
   54     $source .= '/';
   55       } else if ((ereg("\\\\", $dest)) &&  (substr($dest, -1) != "\\")) {
   56         $dest .= "\\";
   57     $source .= "\\";
   58       }
   59 
   60       // Deep copy directories
   61       if ($dest !== $source.$entry) {
   62           copyr($source.$entry, $dest.$entry);
   63       }
   64   }
   65  
   66   // Clean up
   67   closedir($use_dir);
   68   return true;
   69 }
   70 
   71 // End COMMON FUNCTIONS
   72 
   73 
   74 // Set $glbl_hash
   75 $glbl_hash = md5(mktime());
   76 
   77 
   78 
   79 echo "\n\n\n#################################################\n";
   80 echo " Welcome to the Node Runner installation script.\n";
   81 echo "#################################################\n\n";
   82 
   83 
   84 // STEP 1: Determine NEW INSTALL or UPGRADE.
   85 
   86 do {
   87 
   88   $stdin = fopen('php://stdin', 'r');
   89   echo "Is this a NEW INSTALL or an UPGRADE (N/U)? ";
   90   $install_type = fgets($stdin,4);
   91   $install_type = ltrim(rtrim(strtoupper($install_type)));
   92   fclose($stdin);
   93 
   94   if ($install_type == 'N') {
   95     $install_type = 'NEW INSTALL';
   96   } else if ($install_type == 'U') {
   97     $install_type = 'UPGRADE';
   98   } else {
   99     unset($install_type);
  100   }
  101 
  102 } while (!$install_type);
  103 
  104 // End STEP 1
  105 
  106 
  107 
  108 
  109 
  110 
  111 
  112 
  113 
  114 
  115 // STEP 2: Prompt for location of HTML
  116 echo "\n\nWhere would you like to store your HTML files for Node Runner?\n";
  117 echo "(ex. /var/www/node-runner/)  Enter location or type NONE to skip.\n\n";
  118 
  119 do {
  120   unset($perm_errors);
  121 
  122   do {
  123     $stdin = fopen('php://stdin', 'r');
  124     echo "Location: ";
  125     $dest_loc_html = fgets($stdin,250);
  126     $dest_loc_html = ltrim(rtrim($dest_loc_html));
  127     if ((ereg("/", $dest_loc_html)) && (substr($dest_loc_html, -1) != '/')) {
  128       $dest_loc_html .= '/';
  129     } else if ((ereg("\\\\", $dest_loc_html)) &&  (substr($dest_loc_html, -1) != "\\")) {
  130       $dest_loc_html .= "\\";
  131     }
  132     fclose($stdin);
  133     
  134     if (($dest_loc_html == ".") || ($dest_loc_html == "..") || (ereg("\./", $dest_loc_html)) || (ereg("\.\\\\", $dest_loc_html))) {
  135       echo "\nERROR: Please use absolute path for location, not relative.\n\n";
  136       unset($dest_loc_html);      
  137     }
  138 
  139     if (strtoupper($dest_loc_html) == 'NONE') {
  140       $dest_loc_html = 'NONE';
  141     }
  142 
  143   } while (!$dest_loc_html);
  144 
  145   
  146   echo "\n\n";
  147 
  148   if ($dest_loc_html != 'NONE') {
  149     // Check to see if destination exists.
  150     if (is_dir($dest_loc_html)) {
  151       // Destination directory exists, so check it for files.
  152       $existing_files = dir_contents($dest_loc_html);
  153       if (!empty($existing_files)) {
  154         // Destination directory already contains files, so prompt for permission to remove them.
  155 
  156         do {
  157           $stdin = fopen('php://stdin', 'r');
  158           echo "This directory already exists, overwrite it? [Y/N] ";
  159           $remove_them = fgets($stdin,4);
  160           $remove_them = ltrim(rtrim(strtoupper($remove_them)));
  161           fclose($stdin);
  162           if ($remove_them == 'Y') {
  163             // Attempt to remove all files from this directory.
  164             echo "Destination files will be overwritten.\n\n";
  165             $failure = 0;
  166             foreach($existing_files as $file) {
  167               $success = unlink($dest_loc_html.$file);
  168               if (!$success) { $failure++; }
  169             }
  170             if ($failure) {
  171               echo "ERROR: Could not remove old files.  Check permissions.\n";
  172               echo "This may cause problems copying the new HTML files over.\n\n";
  173             }
  174           } else if ($remove_them == 'N') {
  175             // Do NOT attempt to remove files from this directory.
  176             echo "Destination files will not be overwritten.\n\n";
  177           } else {
  178             unset($remove_them);
  179           }
  180         } while (!$remove_them);
  181     
  182       } else {
  183         // Destination directory exists, but contains no files.
  184         // We shouldn't need to do anything here - this is just a placeholder.
  185       }
  186     
  187 
  188     } else {
  189       // Destination directory does not exist, so attempt to create it.
  190       $create_dir = mkdir($dest_loc_html, 0755);
  191       if (!$create_dir) {
  192         echo "ERROR: Unable to create destination directory.  Make sure you have permission\nto create the $dest_loc_html directory.  Please try again.\n\n";
  193         $perm_errors = 1;
  194     continue;
  195       }
  196 
  197     }
  198   }
  199 
  200   unset($existing_files);
  201 
  202 } while ($perm_errors);
  203 // End STEP 2
  204 
  205 
  206 
  207 
  208 
  209 
  210 
  211 // STEP 3: Copy HTML files from tarball source locations to destination directory chosen above.
  212 
  213 if ($dest_loc_html != 'NONE') {
  214 
  215   $html_dir = chdir('html');
  216   if (!$html_dir) {
  217     echo "Cannot change to 'html' directory.  Where did it go?\n\n";
  218     echo "Setup cannot continue.  Exiting.\n\n";
  219     exit();
  220   }
  221 
  222   $cwd = getcwd();
  223   if (ereg("/", $cwd)) {
  224     $cwd .= '/';  
  225   } else if (ereg("\\\\", $cwd)) {
  226     $cwd .= "\\";
  227   }
  228   $html_files = dir_contents($cwd);
  229   $failure = 0;
  230   foreach ($html_files as $file) {
  231     $html_filecopy = copyr($cwd.$file, $dest_loc_html.$file);
  232     if (!$html_filecopy) { $failure++; }
  233   }
  234 
  235   if ($failure) {
  236     echo "One or more files were not copied correctly.  You may need to\nmanually re-copy the contents of the 'html' directory\nto the $dest_loc_html directory.\n\n";
  237   }
  238 
  239 }
  240 
  241 // End STEP 3
  242 
  243 
  244 
  245 
  246 
  247 
  248 
  249 
  250 
  251 
  252 
  253 // STEP 4: Prompt for destination location for rest of tarball source files
  254 
  255 echo "\nWhere would you like to store the rest of the files (non-HTML) for Node Runner?\n";
  256 echo "(Default: /usr/local/node-runner/)  Enter location or leave blank for default.\n\n";
  257 
  258 do {
  259   unset($perm_errors);
  260 
  261   do {
  262     $stdin = fopen('php://stdin', 'r');
  263     echo "Location [/usr/local/node-runner/]: ";
  264     $dest_loc_rest = fgets($stdin,250);
  265     $dest_loc_rest = ltrim(rtrim($dest_loc_rest));
  266 
  267     if (!$dest_loc_rest) {
  268       $dest_loc_rest = '/usr/local/node-runner/';
  269     }
  270 
  271     if (ereg("/", $dest_loc_rest)) {
  272       if  (substr($dest_loc_rest, -1) != '/') {
  273         $dest_loc_rest .= '/';
  274       }
  275       $path_to_include = $dest_loc_rest.'include/';
  276       $nr_inc_file = $dest_loc_rest.'etc/nr.inc';
  277       $etc_directory = $dest_loc_rest.'etc/';
  278       $sql_directory = $dest_loc_rest.'sql/';
  279       $node_start_file = $dest_loc_rest.'node.start';
  280       if ($dest_loc_html) { $connect_php_file = $dest_loc_html.'connect.php'; }
  281     } else if (ereg("\\\\", $dest_loc_rest)) {
  282       if  (substr($dest_loc_rest, -1) != "\\") {
  283         $dest_loc_rest .= "\\";
  284       }
  285       $path_to_include = $dest_loc_rest."include\\";
  286       $path_to_include = str_replace("\\", "\\\\", $path_to_include);
  287       $nr_inc_file = $dest_loc_rest."etc\\nr.inc";
  288       $etc_directory = $dest_loc_rest.'etc\\';
  289       $etc_directory = str_replace("\\", "\\\\", $etc_directory);
  290       $sql_directory = $dest_loc_rest.'sql\\';
  291       $node_start_file = $dest_loc_rest.'node.start';
  292       if ($dest_loc_html) { $connect_php_file = $dest_loc_html.'connect.php'; }
  293     }
  294     fclose($stdin);
  295   
  296     if (($dest_loc_rest == ".") || ($dest_loc_rest == "..") || (ereg("\./", $dest_loc_rest)) || (ereg("\.\\\\", $dest_loc_rest))) {
  297       echo "\nERROR: Please use absolute path for location, not relative.\n\n";
  298       unset($dest_loc_rest);
  299     }
  300   } while (!$dest_loc_rest);
  301 
  302   echo "\n\n";
  303 
  304   // Check to see if destination exists.
  305   if (is_dir($dest_loc_rest)) {
  306       // Destination directory exists, so check it for files.
  307       $existing_files = dir_contents($dest_loc_rest);
  308       if (!empty($existing_files)) {
  309         // Destination directory already contains files, so prompt for permission to remove them.
  310 
  311         do {
  312           $stdin = fopen('php://stdin', 'r');
  313           echo "This directory already exists, overwrite it? [Y/N] ";
  314           $remove_them = fgets($stdin,4);
  315           $remove_them = ltrim(rtrim(strtoupper($remove_them)));
  316           fclose($stdin);
  317           if ($remove_them == 'Y') {
  318             // Attempt to remove all files from this directory.
  319             echo "Destination files will be overwritten.\n\n";
  320             $failure = 0;
  321             foreach($existing_files as $file) {
  322               $success = unlink($dest_loc_rest.$file);
  323               if (!$success) { $failure++; }
  324             }
  325             if ($failure) {
  326               echo "ERROR: Could not remove old files.  Check permissions.\n";
  327               echo "This may cause problems copying the new HTML files over.\n\n";
  328             }
  329           } else if ($remove_them == 'N') {
  330             // Do NOT attempt to remove files from this directory.
  331             echo "Destination files will not be overwritten.\n\n";
  332           } else {
  333             unset($remove_them);
  334           }
  335         } while (!$remove_them);
  336     
  337       } else {
  338         // Destination directory exists, but contains no files.
  339         // We shouldn't need to do anything here - this is just a placeholder.
  340       }
  341     
  342 
  343   } else {
  344      // Destination directory does not exist, so attempt to create it.
  345      $create_dir = mkdir($dest_loc_rest, 0755);
  346      if (!$create_dir) {
  347        echo "Unable to create destination directory.  Make sure you have permission\nto create the $dest_loc_rest directory.  Please try again.\n\n";
  348        $perm_errors = 1;     
  349      }
  350 
  351   }
  352 
  353 } while ($perm_errors);
  354 
  355 // End STEP 4
  356 
  357 
  358 
  359 
  360 
  361 
  362 
  363 
  364 
  365 
  366 
  367 
  368 
  369 // STEP 5: Copy all other files from tarball source locations to destination directory chosen above.
  370 
  371 if ($dest_loc_html != 'NONE') {
  372   $back_one_dir = chdir('..');
  373   if (!$back_one_dir) {
  374     echo "Cannot find the rest of the source files.  Where did they go?\n\n";
  375     echo "Setup cannot continue.  Exiting.\n\n";
  376     exit();
  377   }
  378 }
  379 
  380 $cwd = getcwd();
  381   if (ereg("/", $cwd)) {
  382     $cwd .= '/';  
  383   } else if (ereg("\\\\", $cwd)) {
  384     $cwd .= "\\";
  385   }
  386 $rest_of_files = dir_contents($cwd);
  387 $failure = 0;
  388 foreach ($rest_of_files as $file) {
  389   if ($file == 'html') { continue; }
  390   $rest_of_filecopy = copyr($cwd.$file, $dest_loc_rest.$file);
  391   if (!$rest_of_filecopy) { $failure++; }
  392 }
  393 
  394 // Remove the installer.php file from $dest_loc_rest
  395 $rm_installer = unlink($dest_loc_rest."installer.php");
  396 
  397 if ($failure) {
  398   echo "One or more files were not copied correctly.  You may need to\nmanually re-copy the contents of the $cwd directory\nto the $dest_loc_rest directory.\n\n";
  399 }
  400 
  401 // End STEP 5
  402 
  403 
  404 
  405 
  406 
  407 
  408 
  409 
  410 
  411 
  412 // STEP 6: Prompt for all variables in nr.inc file.
  413 
  414 $stdin = fopen('php://stdin', 'r');
  415 echo "\n\nIt is now time to define the general settings for Node Runner.\nAnswer the following questions or leave blank for default settings.\nFor Yes/No questions, the default value will be presented in uppercase.\n\nPress Enter to continue...";
  416 $anykey = fgets($stdin,4);
  417 
  418 do {
  419   unset($perm_errors);
  420   if (!is_writable($nr_inc_file)) {
  421     echo "ERROR: Could not open nr.inc for writing.\n\n";
  422     $stdin = fopen('php://stdin', 'r');
  423     echo "Do you wish to skip this part? [y/N] ";
  424     $skip_config = fgets($stdin,4);
  425     $skip_config = ltrim(rtrim(strtolower($skip_config)));
  426     fclose($stdin);
  427   
  428     if (strtoupper($skip_config) == 'Y') {
  429       echo "\n\nYou have opted to skip configuration of general settings.  Before using\n";
  430       echo "Node Runner, you must now manually configure the options in the nr.inc file.\n\n";
  431     } else {
  432       $stdin = fopen('php://stdin', 'r');
  433       echo "\n\nPlease correct the permissions on the nr.inc file and press Enter to continue...";    
  434       $anykey = fgets($stdin,4);
  435       $perm_errors = 1;    
  436     }
  437   }
  438 } while ($perm_errors);
  439 
  440 if (strtoupper($skip_config) != 'Y') {
  441 
  442 echo "\n\n";
  443 
  444 
  445 
  446 echo "Since you are running Node Runner on this machine, it will serve as\n";
  447 echo "the highest level node in your network monitoring heirarchy.  For example,\n";
  448 echo "if Node Runner could not contact the machine on which it is running, it\n";
  449 echo "wouldn't try to contact other machines, because it would assume that it\n";
  450 echo "lost it's network connection or the NIC was bad.  That said, you need to\n";
  451 echo "pick a TCP port which is open on this machine (localhost) that will be\n";
  452 echo "available to query at any time.  The default is 80, assuming that you will\n";
  453 echo "be serving the Node Runner web interface from this machine as well.\n\n";
  454 do {
  455 
  456   unset($connection_valid);
  457   $stdin = fopen('php://stdin', 'r');
  458   echo "TCP Port: [80] ";
  459   $test_port = fgets($stdin,4);
  460   $test_port = intval(ltrim(rtrim(strtolower($test_port))));
  461   fclose($stdin);
  462   
  463   if (!$test_port) {
  464     $test_port = 80;
  465   }
  466   
  467   $socket = fsockopen("127.0.0.1", $test_port, $errno, $errstr, 5);
  468   if (!$socket) {
  469     echo "\n\nERROR: TCP port $test_port did not respond.  Please choose another port.\n\n";
  470   } else {
  471     $connection_valid = 1;
  472     fclose($socket);
  473   }
  474   
  475 } while (!$connection_valid);
  476 
  477 
  478 echo "\n\n\n";
  479 
  480 
  481 $stdin = fopen('php://stdin', 'r');
  482 echo "Database Host [localhost]: ";
  483 $dbhost = fgets($stdin,250);
  484 $dbhost = ltrim(rtrim(strtolower($dbhost)));
  485 fclose($stdin);
  486 
  487 if (!$dbhost) {
  488   $dbhost = 'localhost';
  489 }
  490 
  491 echo "\n";
  492 
  493 
  494 $stdin = fopen('php://stdin', 'r');
  495 echo "Database Name [node_runner]: ";
  496 $db = fgets($stdin,250);
  497 $db = ltrim(rtrim(strtolower($db)));
  498 fclose($stdin);
  499 
  500 if (!$db) {
  501   $db = 'node_runner';
  502 }
  503 
  504 echo "\n";
  505 
  506 
  507 $stdin = fopen('php://stdin', 'r');
  508 echo "Database Username [nruser]: ";
  509 $dbuser = fgets($stdin,250);
  510 $dbuser = ltrim(rtrim(strtolower($dbuser)));
  511 fclose($stdin);
  512 
  513 if (!$dbuser) {
  514   $dbuser = 'nruser';
  515 }
  516 
  517 echo "\n";
  518 
  519 
  520 $stdin = fopen('php://stdin', 'r');
  521 echo "Database Password [changeme]: ";
  522 $dbpass = fgets($stdin,250);
  523 $dbpass = ltrim(rtrim(strtolower($dbpass)));
  524 fclose($stdin);
  525 
  526 if (!$dbpass) {
  527   $dbpass = 'changeme';
  528 }
  529 
  530 echo "\n";
  531 
  532 
  533 $stdin = fopen('php://stdin', 'r');
  534 echo "Sender address for email alerts [nr@$dbhost]: ";
  535 $sender = fgets($stdin,250);
  536 $sender = ltrim(rtrim(strtolower($sender)));
  537 fclose($stdin);
  538 
  539 if (!$sender) {
  540   $sender = "nr@$dbhost";
  541 }
  542 
  543 $sender = '"Node Runner" <'.$sender.'>';
  544 
  545 echo "\n";
  546 
  547 
  548 $stdin = fopen('php://stdin', 'r');
  549 echo "Send detailed status info with alerts? (y/N) ";
  550 $detailed_email = fgets($stdin,4);
  551 $detailed_email = ltrim(rtrim(strtolower($detailed_email)));
  552 fclose($stdin);
  553 
  554 if (strtoupper($detailed_email) == 'Y') {
  555   $detailed_email = "1";
  556 } else {
  557   $detailed_email = "0";
  558 }
  559   
  560 echo "\n";
  561 
  562 
  563 $stdin = fopen('php://stdin', 'r');
  564 echo "Minutes to wait between each \"DOWN\" alert: [15] ";
  565 $delay = fgets($stdin,6);
  566 $delay = intval(ltrim(rtrim(strtolower($delay))));
  567 fclose($stdin);
  568 
  569 if (!$delay) {
  570   $delay = "15";
  571 }
  572 
  573 echo "\n";
  574 
  575 
  576 $stdin = fopen('php://stdin', 'r');
  577 echo "Max number of \"DOWN\" alerts to send: [0 = unlimited] ";
  578 $max_alerts = fgets($stdin,6);
  579 $max_alerts = intval(ltrim(rtrim(strtolower($max_alerts))));
  580 fclose($stdin);
  581 
  582 if (!$max_alerts) {
  583   $max_alerts = "0";
  584 }
  585 
  586 echo "\n";
  587 
  588 
  589 $stdin = fopen('php://stdin', 'r');
  590 echo "Max query attempts before a node is declared as \"DOWN\": [2] ";
  591 $max_attempts = fgets($stdin,4);
  592 $max_attempts = intval(ltrim(rtrim(strtolower($max_attempts))));
  593 fclose($stdin);
  594 
  595 if (!$max_attempts) {
  596   $max_attempts = "2";
  597 }
  598 
  599 echo "\n\n";
  600 
  601 do {
  602   unset($whoops);
  603   $stdin = fopen('php://stdin', 'r');
  604   echo "\nNode Runner's polling script (node.start) is intended to run as a\n";
  605   echo "cron job (scheduled task).  The script will run every few minutes, polling\n";
  606   echo "your network nodes with each iteration.  Please specify how many minutes\n";
  607   echo "apart this script should be scheduled.\n\n";
  608   echo "NOTE: Be sure to allow enough time between iterations.  For small networks,\n";
  609   echo "2 minutes is probably sufficient, where larger networks might require 3.\n\n";
  610   echo "Minutes between iterations: [2] ";
  611   $qtime = fgets($stdin,4);
  612   $qtime = intval(ltrim(rtrim(strtolower($qtime))));
  613   fclose($stdin);
  614 
  615   if (!$qtime) {
  616     $qtime = "2";
  617   }
  618 
  619   if (($qtime != 1) && ($qtime != 2) && ($qtime != 3) && ($qtime != 4) && ($qtime != 5)&& ($qtime != 6)
  620    && ($qtime != 10) && ($qtime != 12) && ($qtime != 15) && ($qtime != 20) && ($qtime != 30)) {
  621     echo "\n\nERROR: You have chosen to run the node.start script at an interval\n";
  622     echo "of $qtime minutes, which is not evenly divisible by 60 (minutes).  That\n";
  623     echo "means when you run your cron job, at some point during each hour, you\n";
  624     echo "will have a gap in polling which is greater than $qtime minutes.  If this\n";
  625     echo "doesn't make any sense to you, do some research on cron jobs and try to\n";
  626     echo "figure out how you would run a script every $qtime minutes.\n\n";
  627     $stdin = fopen('php://stdin', 'r');
  628     echo "Press Enter and try again...";
  629     $anykey = fgets($stdin,4);
  630     fclose($stdin);
  631     $whoops = 1;
  632     echo "\n\n";
  633   }
  634 } while ($whoops);
  635 
  636 
  637 
  638 echo "\n\n\n";
  639 
  640 
  641 $stdin = fopen('php://stdin', 'r');
  642 echo "You may encounter 'Connection Refused' errors when polling certain types\n";
  643 echo "of devices.  This is especially true when polling the telnet service on\n";
  644 echo "certain routers, or the HTTP service on web servers that have crashed\n";
  645 echo "(e.g. IIS 4+).  In the first case, the service should be regarded as\n";
  646 echo "\"UP\", but in the second case, it would be \"DOWN\".  With these\n";
  647 echo "considerations in mind, you may choose to ignore 'Connection Refused'\n";
  648 echo "errors, in which case Node Runner will regard the node as \"UP\".\n";
  649 echo "You can always change this setting at a later time.\n\n";
  650 echo "Ignore 'Connection Refused' errors: [y/N] ";
  651 $allow_refused = fgets($stdin,4);
  652 $allow_refused = ltrim(rtrim(strtolower($allow_refused)));
  653 fclose($stdin);
  654 
  655 if (strtoupper($allow_refused) == 'Y') {
  656   $allow_refused = "1";
  657 } else {
  658   $allow_refused = "0";
  659 }
  660   
  661 echo "\n\n\n";
  662 
  663 
  664 $stdin = fopen('php://stdin', 'r');
  665 echo "Enable debugging? [y/N] ";
  666 $debug = fgets($stdin,4);
  667 $debug = ltrim(rtrim(strtolower($debug)));
  668 fclose($stdin);
  669 
  670 if (strtoupper($debug) == 'Y') {
  671   $debug = "1";
  672 } else {
  673   $debug = "0";
  674 }
  675   
  676 echo "\n\n";
  677 
  678 
  679 $stdin = fopen('php://stdin', 'r');
  680 echo "Node Runner can be configured to wait a specified amount of time\n";
  681 echo "before it sends its initial \"DOWN\" email notification.  You might\n";
  682 echo "choose this option if you have slow or high-latency network lines\n";
  683 echo "which can generate intermittent \"DOWN\" reports.\n\n";
  684 echo "Minutes to wait before sending first notification: [0] ";
  685 $firstmail = fgets($stdin,4);
  686 $firstmail = intval(ltrim(rtrim(strtolower($firstmail))));
  687 fclose($stdin);
  688 
  689 if (!$firstmail) {
  690   $firstmail = "0";
  691 }
  692 
  693 echo "\n\n\n";
  694 
  695 
  696 $stdin = fopen('php://stdin', 'r');
  697 echo "Only allow admins to start the Network Dashboard marquee? [y/N] ";
  698 $secure_monitor = fgets($stdin,4);
  699 $secure_monitor = ltrim(rtrim(strtolower($secure_monitor)));
  700 fclose($stdin);
  701 
  702 if (strtoupper($secure_monitor) == 'Y') {
  703   $secure_monitor = "1";
  704 } else {
  705   $secure_monitor = "0";
  706 }
  707   
  708 echo "\n";
  709 
  710 
  711 $stdin = fopen('php://stdin', 'r');
  712 echo "Display list of recent network failures on Network Dashboard? [Y/n] ";
  713 $show_recent = fgets($stdin,4);
  714 $show_recent = ltrim(rtrim(strtolower($show_recent)));
  715 fclose($stdin);
  716 
  717 if (strtoupper($show_recent) == 'N') {
  718   $show_recent = "0";
  719 } else {
  720   $show_recent = "1";
  721 }
  722   
  723 echo "\n";
  724 
  725 
  726 $stdin = fopen('php://stdin', 'r');
  727 echo "Display 'Node Statistics Snapshot' on Network Dashboard? [Y/n] ";
  728 $status_stats = fgets($stdin,4);
  729 $status_stats = ltrim(rtrim(strtolower($status_stats)));
  730 fclose($stdin);
  731 
  732 if (strtoupper($status_stats) == 'N') {
  733   $status_stats = "0";
  734 } else {
  735   $status_stats = "1";
  736 }
  737   
  738 echo "\n\n";
  739 
  740 
  741 $stdin = fopen('php://stdin', 'r');
  742 echo "The Network Dashboard displays a list of any nodes that are currently\n";
  743 echo "down.  Below each node is a link to manually poll the node in cases\n";
  744 echo "where you don't wish to wait for the next iteration of the polling\n";
  745 echo "script.  If you are worried about click-happy users abusing the option\n";
  746 echo "you may wish to disable the functionality.  (Default = disabled)\n\n";
  747 echo "Allow 'Click to Poll Manually' option on Network Dashboard? [y/N] ";
  748 $monitor_polling = fgets($stdin,4);
  749 $monitor_polling = ltrim(rtrim(strtolower($monitor_polling)));
  750 fclose($stdin);
  751 
  752 if (strtoupper($monitor_polling) == 'Y') {
  753   $monitor_polling = "1";
  754 } else {
  755   $monitor_polling = "0";
  756 }
  757   
  758 echo "\n\n\n";
  759 
  760 
  761 $stdin = fopen('php://stdin', 'r');
  762 echo "Really long node names can be truncated on the Network Dashboard to\n";
  763 echo "prevent line wrapping and other unattractive side effects.  This\n";
  764 echo "setting only affects the Network Dashboard display, names will not\n";
  765 echo "be truncated in the database itself.\n\n";
  766 echo "Maximum length of node names (in chars): [22] ";
  767 $truncate_at = fgets($stdin,6);
  768 $truncate_at = intval(ltrim(rtrim(strtolower($truncate_at))));
  769 fclose($stdin);
  770 
  771 if (!$truncate_at) {
  772   $truncate_at = "22";
  773 }
  774   
  775 echo "\n\n\n";
  776 
  777 
  778 $stdin = fopen('php://stdin', 'r');
  779 echo "Refresh rate (in seconds) for Network Dashboard: [30] ";
  780 $dash_refrate = fgets($stdin,4);
  781 $dash_refrate = intval(ltrim(rtrim(strtolower($dash_refrate))));
  782 fclose($stdin);
  783 
  784 if (!$dash_refrate) {
  785   $dash_refrate = "30";
  786 }
  787   
  788 echo "\n";
  789 
  790 
  791 $stdin = fopen('php://stdin', 'r');
  792 echo "Allow RSS feed for NR project news on main page of web interface? [Y/n] ";
  793 $allow_rss = fgets($stdin,4);
  794 $allow_rss = ltrim(rtrim(strtolower($allow_rss)));
  795 fclose($stdin);
  796 
  797 if (strtoupper($allow_rss) == 'N') {
  798   $allow_rss = "0";
  799 } else {
  800   $allow_rss = "1";
  801 }
  802   
  803 echo "\n";
  804 
  805 
  806 $stdin = fopen('php://stdin', 'r');
  807 echo "Web Interface URL: [http://localhost/node-runner/] ";
  808 $nr_url = fgets($stdin,250);
  809 $nr_url = ltrim(rtrim(strtolower($nr_url)));
  810 fclose($stdin);
  811 
  812 if (($nr_url) && (substr($nr_url, -1) != '/')) {
  813   $nr_url .= '/';
  814 } else if (!$nr_url) {
  815   $nr_url = 'http://localhost/node-runner/';
  816 }
  817 
  818 echo "\n";
  819 
  820 } // end if (strtoupper($skip_config) != 'Y')
  821 
  822 // End STEP 6
  823 
  824 
  825 
  826 
  827 
  828 
  829 
  830 
  831 // STEP 7: Write collected setup info to nr.inc file.
  832 
  833 if (strtoupper($skip_config) != 'Y') {
  834 
  835   $handle = fopen($nr_inc_file, "r");
  836   $contents = fread($handle, filesize($nr_inc_file));  
  837   fclose($handle);    
  838 
  839   $contents = str_replace("dbhost = \"localhost\"","dbhost = \"$dbhost\"",$contents);  
  840   $contents = str_replace("db = \"\"","db = \"$db\"",$contents);
  841   $contents = str_replace("dbuser = \"\"","dbuser = \"$dbuser\"",$contents);
  842   $contents = str_replace("dbpass = \"\"","dbpass = \"$dbpass\"",$contents);
  843   $contents = str_replace("sender = \"\"","sender = \"".addslashes($sender)."\"",$contents);
  844   $contents = str_replace("detailed_email = 0","detailed_email = $detailed_email",$contents);
  845   $contents = str_replace("delay = 15","delay = $delay",$contents);
  846   $contents = str_replace("max_alerts = 0","max_alerts = $max_alerts",$contents);
  847   $contents = str_replace("max_attempts = 2","max_attempts = $max_attempts",$contents);
  848   $contents = str_replace("qtime = 2","qtime = $qtime",$contents);
  849   $contents = str_replace("allow_refused = 0","allow_refused = $allow_refused",$contents);
  850   $contents = str_replace("debug = 0","debug = $debug",$contents);
  851   $contents = str_replace("firstmail = 0","firstmail = $firstmail",$contents);
  852   $contents = str_replace("secure_monitor = 0","secure_monitor = $secure_monitor",$contents);
  853   $contents = str_replace("show_recent = 1","show_recent = $show_recent",$contents);
  854   $contents = str_replace("monitor_polling = 0","monitor_polling = $monitor_polling",$contents);
  855   $contents = str_replace("truncate_at = 22","truncate_at = $truncate_at",$contents);
  856   $contents = str_replace("status_stats = 1","status_stats = $status_stats",$contents);
  857   $contents = str_replace("dash_refrate = 30","dash_refrate = $dash_refrate",$contents);
  858   $contents = str_replace("allow_rss = 1","allow_rss = $allow_rss",$contents);
  859   $contents = str_replace("glbl_hash = \"Rx1Uo12n6N\"","glbl_hash = \"$glbl_hash\"",$contents);
  860   $contents = str_replace("path_to_include = \"/path/to/include/\"","path_to_include = \"$path_to_include\"",$contents);
  861   $contents = str_replace("nr_url = \"http://localhost/node-runner/\"","nr_url = \"$nr_url\"",$contents);  
  862   
  863   $handle = fopen($nr_inc_file, "w");
  864   $output = fwrite($handle, $contents);
  865   fclose($handle); 
  866 
  867 } // end if (strtoupper($skip_config) != 'Y')
  868 
  869 // End STEP 7
  870 
  871 
  872 
  873 
  874 
  875 
  876 
  877 
  878 // STEP 8: Verify existence of 'etc' directory and modify 'node.start' and 'connect.php' accordingly.
  879 
  880 unset($skip_config);
  881 
  882 $stdin = fopen('php://stdin', 'r');
  883 echo "\n\nSetup will now attempt to set the location of the 'etc' directory\n";
  884 echo "in your 'node.start' and 'connect.php' files.\n\nPress Enter to continue...";
  885 $anykey = fgets($stdin,4);
  886 
  887 if (!is_dir($etc_directory)) {
  888   // Note that the $etc_directory variable must be set at this point, or it would not have written the nr.inc file.
  889   echo "ERROR: For some reason, your 'etc' directory is missing.\n\n";
  890   echo "You will need to set a variable manually in your 'node.start'\n";
  891   echo "and the 'connect.php' files to make them work.  You might also\n";
  892   echo "make sure the general variables you defined were successfully\n";
  893   echo "written to the 'nr.inc' file.\n\n";
  894 } else {
  895     
  896   do { // make sure the 'node.start' file exists and is writable
  897     unset($perm_errors);
  898     if (!is_writable($node_start_file)) {
  899       echo "ERROR: Could not open node.start for writing.\n\n";
  900       $stdin = fopen('php://stdin', 'r');
  901       echo "Do you wish to skip this part? [y/N] ";
  902       $skip_config = fgets($stdin,4);
  903       $skip_config = ltrim(rtrim(strtolower($skip_config)));
  904       fclose($stdin);
  905   
  906       if (strtoupper($skip_config) == 'Y') {
  907         echo "\n\nYou have opted to skip this step.  Before you attempt to execute the\n";
  908         echo "node.start script, you must now manually configure the '\$path_to_etc'\n";
  909     echo "variable within the file.\n\n";
  910       } else {
  911         $stdin = fopen('php://stdin', 'r');
  912         echo "\n\nPlease correct the permissions on the node.start file and press Enter to continue...";    
  913         $anykey = fgets($stdin,4);
  914         $perm_errors = 1;    
  915       }
  916     }
  917   } while ($perm_errors);
  918   
  919   do { // make sure the 'connect.php' file exists and is writable
  920     unset($perm_errors);
  921     if (!is_writable($connect_php_file)) {
  922       echo "ERROR: Could not open connect.php for writing.\n\n";
  923       $stdin = fopen('php://stdin', 'r');
  924       echo "Do you wish to skip this part? [y/N] ";
  925       $skip_config = fgets($stdin,4);
  926       $skip_config = ltrim(rtrim(strtolower($skip_config)));
  927       fclose($stdin);
  928   
  929       if (strtoupper($skip_config) == 'Y') {
  930         echo "\n\nYou have opted to skip this step.  Before you attempt to use the\n";
  931         echo "Node Runner web interface, you must now manually configure the\n";
  932         echo "'\$etcdir' variable within the 'connect.php' file.\n\n";
  933       } else {
  934         $stdin = fopen('php://stdin', 'r');
  935         echo "\n\nPlease correct the permissions on the node.start file and press Enter to continue...";    
  936         $anykey = fgets($stdin,4);
  937         $perm_errors = 1;    
  938       }
  939     }
  940   } while ($perm_errors);
  941   
  942   // At this point, we have verified that the node.start and connect.php files exist and are writable,
  943   // so we can now modify them.
  944   
  945   // First the node.start file
  946   unset($contents);
  947   $handle = fopen($node_start_file, "r");
  948   $contents = fread($handle, filesize($node_start_file));  
  949   fclose($handle);    
  950 
  951   $contents = str_replace("path_to_etc = \"etc/\"","path_to_etc = \"$etc_directory\"",$contents);  
  952   
  953   $handle = fopen($node_start_file, "w");
  954   $output = fwrite($handle, $contents);
  955   fclose($handle); 
  956   
  957   // Then the connect.php file
  958   unset($contents);
  959   $handle = fopen($connect_php_file, "r");
  960   $contents = fread($handle, filesize($connect_php_file));  
  961   fclose($handle);    
  962 
  963   $contents = str_replace("etcdir = \"../etc\"","etcdir = \"$etc_directory\"",$contents);  
  964   
  965   $handle = fopen($connect_php_file, "w");
  966   $output = fwrite($handle, $contents);
  967   fclose($handle); 
  968   
  969 }
  970 
  971 // End STEP 8
  972 
  973 
  974 
  975 
  976 
  977 
  978 
  979 
  980 
  981 
  982 
  983 // STEP 9: Set up database tables
  984 
  985 echo "\n\nTime to install or upgrade your database...";
  986 do {
  987   $connect = mysql_connect($dbhost,$dbuser,$dbpass);
  988   if (!$connect) {
  989     $stdin = fopen('php://stdin', 'r');
  990     echo "\n\nERROR: Could not connect: ".mysql_error()."\n";
  991     echo "Please grant the user \"$dbuser\" access to the database and\n";
  992     echo "press Enter to continue...";
  993     $anykey = fgets($stdin,4);
  994     fclose($stdin);
  995   }
  996 } while (!$connect);
  997 
  998 // Make sure all sql files are available
  999 $sql_file_array = array($sql_directory.'nr-mysql-setup.php',
 1000                         $sql_directory.'update-nr-to-v0.2.php',
 1001                         $sql_directory.'update-nr-to-v0.3.php',
 1002                         $sql_directory.'update-nr-to-v0.4.php',
 1003                         $sql_directory.'update-nr-to-v0.4.2.php',
 1004                         $sql_directory.'update-nr-to-v0.5.0.php',
 1005                         $sql_directory.'update-nr-to-v0.5.1.php',
 1006                         $sql_directory.'update-nr-to-v0.6.0.php');
 1007 
 1008 for ($x=0; $x<sizeof($sql_file_array); $x++) {
 1009   do {
 1010     unset($file_missing);
 1011     if (!is_file($sql_file_array[$x])) {
 1012       $stdin = fopen('php://stdin', 'r');
 1013       echo "\n\nERROR: Cannot find $sql_file_array[$x] file.\n";
 1014       echo "This file is required by the Node Runner setup process.\n";
 1015       echo "Please make sure the file exists in $sql_directory\n";
 1016       echo "and press Enter to continue...";
 1017       $anykey = fgets($stdin,4);
 1018       fclose($stdin);
 1019       $file_missing = 1;
 1020     }
 1021   } while ($file_missing) ;
 1022 }
 1023 
 1024 
 1025 if ($install_type == 'NEW INSTALL') {
 1026   // install_type (from above) is NEW INSTALL
 1027   
 1028   $stdin = fopen('php://stdin', 'r');
 1029   echo "\n\nHave you already created the database for Node Runner (per step 2 of\n";
 1030   echo "the INSTALL file)? [y/N] ";
 1031   $createit = fgets($stdin,4);
 1032   $createit = ltrim(rtrim(strtoupper($createit)));
 1033   fclose($stdin);
 1034   if (!$createit) {
 1035     $createit = 'N';
 1036   }
 1037 
 1038   if ($createit == 'N') {
 1039     echo "\n\nChecking database permissions...\n\n";
 1040     $createdb = mysql_query("CREATE DATABASE $db;");
 1041     if (!$createdb) {
 1042       $stdin = fopen('php://stdin', 'r');
 1043       echo "ERROR: Database could not be created.  You probably do not have permission\n";
 1044       echo "to create databases with the user account specified.  You will need\n";
 1045       echo "to manually create the \"$db\" database before setup can\n";
 1046       echo "continue.  Do that now, and press Enter when you're finished...";
 1047       $anykey = fgets($stdin,4);
 1048       fclose($stdin);
 1049     }
 1050   }
 1051     
 1052   do {
 1053     unset($err_msg);
 1054     echo "\n\nSetup will now attempt to populate the Node Runner database.\n";
 1055     require_once($sql_directory.'nr-mysql-setup.php');
 1056     if ($err_msg) {
 1057       echo "\n\nERROR: Database could not be populated.  MySQL said:\n\n".$err_msg."\n\n";
 1058       $stdin = fopen('php://stdin', 'r');
 1059       echo "Do you want to correct this error and try again? [Y/n] ";
 1060       $tryagain = fgets($stdin,4);
 1061       $tryagain = ltrim(rtrim(strtoupper($tryagain)));
 1062       fclose($stdin);
 1063 
 1064       if (strtoupper($tryagain) == 'N') {
 1065         unset($err_msg);
 1066       } else {
 1067         $err_msg = 1;
 1068       }
 1069           
 1070     } else {
 1071       // database population worked, so move on.
 1072       unset($err_msg);
 1073       echo "\n\nDatabase populated successfully.\n\n";
 1074     }
 1075   } while ($err_msg);
 1076      
 1077 
 1078   
 1079 
 1080 
 1081   
 1082 } else {
 1083   // install_type (from above) is UPGRADE
 1084 
 1085   echo "\n\nFrom which version will you be upgrading?\n\n";
 1086   echo "A) 0.1\n";
 1087   echo "B) 0.2\n";
 1088   echo "C) 0.3\n";
 1089   echo "D) 0.4.0 - 0.4.1\n";
 1090   echo "E) 0.4.2 - 0.4.9\n";
 1091   echo "F) 0.5.0\n";
 1092   echo "G) 0.5.1 - 0.5.2\n";
 1093   
 1094   do {
 1095     $stdin = fopen('php://stdin', 'r');
 1096     echo "\nSelect a letter: ";
 1097     $updateit = fgets($stdin,4);
 1098     $updateit = ltrim(rtrim(strtoupper($updateit)));
 1099     fclose($stdin);
 1100     if (($updateit != 'A') &&
 1101         ($updateit != 'B') &&
 1102         ($updateit != 'C') &&
 1103         ($updateit != 'D') &&
 1104         ($updateit != 'E') &&
 1105         ($updateit != 'F') &&
 1106         ($updateit != 'G')) {
 1107         unset($updateit);
 1108     }
 1109   } while (!$updateit);
 1110 
 1111   echo "\n\nSetup will now attempt to upgrade the Node Runner database.\n";
 1112   unset($err_msg);
 1113 
 1114   // Begin really long switch statement for specific versions.
 1115   switch($updateit) {
 1116     case ($updateit == 'A'):
 1117     require_once($sql_directory.'update-nr-to-v0.2.php');
 1118     require_once($sql_directory.'update-nr-to-v0.3.php');
 1119     require_once($sql_directory.'update-nr-to-v0.4.php');
 1120     require_once($sql_directory.'update-nr-to-v0.4.2.php');
 1121     require_once($sql_directory.'update-nr-to-v0.5.0.php');
 1122     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1123     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1124     if ($err_msg) {
 1125       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1126     } else {
 1127       echo "\n\nDatabase upgraded successfully.\n\n";
 1128     }
 1129     break;
 1130     case ($updateit == 'B'):
 1131     require_once($sql_directory.'update-nr-to-v0.3.php');
 1132     require_once($sql_directory.'update-nr-to-v0.4.php');
 1133     require_once($sql_directory.'update-nr-to-v0.4.2.php');
 1134     require_once($sql_directory.'update-nr-to-v0.5.0.php');
 1135     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1136     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1137     if ($err_msg) {
 1138       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1139     } else {
 1140       echo "\n\nDatabase upgraded successfully.\n\n";
 1141     }
 1142     break;
 1143     case ($updateit == 'C'):
 1144     require_once($sql_directory.'update-nr-to-v0.4.php');
 1145     require_once($sql_directory.'update-nr-to-v0.4.2.php');
 1146     require_once($sql_directory.'update-nr-to-v0.5.0.php');
 1147     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1148     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1149     if ($err_msg) {
 1150       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1151     } else {
 1152       echo "\n\nDatabase upgraded successfully.\n\n";
 1153     }
 1154     break;
 1155     case ($updateit == 'D'):
 1156     require_once($sql_directory.'update-nr-to-v0.4.2.php');
 1157     require_once($sql_directory.'update-nr-to-v0.5.0.php');
 1158     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1159     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1160     if ($err_msg) {
 1161       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1162     } else {
 1163       echo "\n\nDatabase upgraded successfully.\n\n";
 1164     }
 1165     break;
 1166     case ($updateit == 'E'):
 1167     require_once($sql_directory.'update-nr-to-v0.5.0.php');
 1168     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1169     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1170     if ($err_msg) {
 1171       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1172     } else {
 1173       echo "\n\nDatabase upgraded successfully.\n\n";
 1174     }
 1175     break;
 1176     case ($updateit == 'F'):
 1177     require_once($sql_directory.'update-nr-to-v0.5.1.php');
 1178     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1179     if ($err_msg) {
 1180       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1181     } else {
 1182       echo "\n\nDatabase upgraded successfully.\n\n";
 1183     }
 1184     break;
 1185     case ($updateit == 'G'):
 1186     require_once($sql_directory.'update-nr-to-v0.6.0.php');
 1187     if ($err_msg) {
 1188       echo "\n\nERROR: Database could not be upgraded.  MySQL said:\n\n".$err_msg."\n\n";
 1189     } else {
 1190       echo "\n\nDatabase upgraded successfully.\n\n";
 1191     }
 1192     break;
 1193   } // End really long switch statement for specific versions.
 1194   
 1195 }
 1196 
 1197 $stdin = fopen('php://stdin', 'r');
 1198 echo "Press Enter to continue...";
 1199 $anykey = fgets($stdin,4);
 1200 fclose($stdin);
 1201   
 1202 // End STEP 9
 1203 
 1204 
 1205 
 1206 
 1207 
 1208 
 1209 
 1210 
 1211 
 1212 
 1213 // STEP 10: Create line for user to copy to cron for node.start script.
 1214 
 1215 echo "\n\nLastly, you need to schedule the node.start script to run at regular\n";
 1216 echo "intervals throughout the hour.  This setup script will NOT do that for\n";
 1217 echo "you, because it probably requires admin/root access.  However, to\n";
 1218 echo "schedule the script on your own, follow these instructions.\n\n";
 1219 echo "View instructions for:\n\n";
 1220 echo "1) Unix\n";
 1221 echo "2) Windows\n";
 1222 $stdin = fopen('php://stdin', 'r');
 1223 echo "\nWhich OS? [1] ";
 1224 $os_instructs = fgets($stdin,4);
 1225 $os_instructs = intval(ltrim(rtrim(strtoupper($os_instructs))));
 1226 fclose($stdin);
 1227 
 1228 if (!$os_instructs) {
 1229   $os_instructs = 1;
 1230 }
 1231 
 1232 echo "\n\n";
 1233 
 1234 
 1235 if ($os_instructs == 1) {
 1236 
 1237   echo "For UNIX users, you need to add a cron job, using the 'crontab'\n";
 1238   echo "application.  Just type 'crontab -e', and add the following line,\n";
 1239   echo "which is being generated based on the answers you provided above:\n\n";
 1240 
 1241   // Another switch statement for pre-defined $qtime
 1242   switch($qtime) {
 1243     case ($qtime == '1'):
 1244     $cron_string = "*";
 1245     break;
 1246     case ($qtime == '2'):
 1247     $cron_string = "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58";
 1248     break;
 1249     case ($qtime == '3'):
 1250     $cron_string = "0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57";
 1251     break;
 1252     case ($qtime == '4'):
 1253     $cron_string = "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56";
 1254     break;
 1255     case ($qtime == '5'):
 1256     $cron_string = "0,5,10,15,20,25,30,35,40,45,50,55";
 1257     break;
 1258     case ($qtime == '6'):
 1259     $cron_string = "0,6,12,18,24,30,36,42,48,54";
 1260     break;
 1261     case ($qtime == '10'):
 1262     $cron_string = "0,10,20,30,40,50";
 1263     break;
 1264     case ($qtime == '12'):
 1265     $cron_string = "0,12,24,36,48";
 1266     break;
 1267     case ($qtime == '15'):
 1268     $cron_string = "0,15,30,45";
 1269     break;
 1270   }
 1271   
 1272   echo "$cron_string * * * * /usr/bin/php -q $node_start_file >> /tmp/nr-debug.txt\n\n";
 1273   
 1274   echo "NOTE: Line may wrap on screen, but it should only be a single line.\n\n";
 1275 
 1276 } else if ($os_instructs == 2) {
 1277 
 1278   echo "For Windows users, it is recommended that you create a batch script\n";
 1279   echo "to call the PHP interpreter and the node.start script every $qtime\n";
 1280   echo "minutes, similar to the following (lines should not wrap):\n\n\n";
 1281 
 1282   echo "@echo off\n\n";
 1283   echo ":: Script to run Node Runner polling script every $qtime minutes.\n";
 1284   echo ":: NOTE: This script requires sleep.exe (Batch File Wait) utility.\n\n";
 1285   echo "cd \php\n";
 1286   echo ":loop\n";
 1287   echo "php -q $node_start_file >> %TEMP%\\nr-debug.txt\n";
 1288   echo "sleep ".($qtime * 60)."\n";
 1289   echo "goto loop\n\n";
 1290 
 1291   echo "\nNOTE: The sleep.exe utility is freely available in most versions of Windows\n";
 1292   echo "Resource Kits.  Search on the microsoft.com website to download it.\n\n";
 1293 
 1294 }
 1295 
 1296 echo "NOTE FOR ANY OS: You may need to adjust the location of the PHP CLI\n";
 1297 echo "interpreter and the nr-debug.txt file.\n";
 1298 
 1299 // End STEP 10
 1300 
 1301 
 1302 echo "\n\n\nThat's it!  Node Runner installation is complete.  It is recommended\n";
 1303 echo "that you remove this installer script (installer.php) now to prevent anyone\n";
 1304 echo "from tampering with your installation.\n\n";
 1305 echo "You can now login to the web interface with a default username of 'admin' and\n";
 1306 echo "default password of 'node-runner'.  Please change this password asap.\n\n";
 1307 echo "Please report any bugs using the SourceForge.net tracker, which is available\n";
 1308 echo "on the Node Runner website.  Thank you for using Open Source software.\n\n";
 1309 
 1310 
 1311 
 1312 ?>