if (isset($isMd5) && $isMd5) { echo HTML::insertScript('md5.js'); echo HTML::insertScript('password.php'); } if (isset($focusFormField) && !empty($focusFormField)) { echo HTML::start('script', array('src' => '../js/focus.php?field=' . $focusFormField, 'type' => 'text/javascript')); echo HTML::end('script'); } echo HTML::end('head'); echo HTML::start('body'); require_once "../layout/component.php"; echo HTML::start('div', array('id' => 'wrap')); echo HTML::start('div', array('id' => 'header')); echo appLogo(); echo HTML::para(HTML::link(_("Skip over navigation"), '#main', null, array('accesskey' => 2)), array('id' => 'skip_navigation')); echo shortcuts(isset($tab) ? $tab : null, isset($nav) ? $nav : null); if (isset($tab)) { echo menuBar($tab); } echo HTML::end('div'); // #header echo HTML::rule(); echo HTML::start('div', array('id' => 'main')); echo HTML::start('div', array('id' => 'content')); if (defined("OPEN_DEMO") && OPEN_DEMO) { echo Msg::info(_("This is a demo version")); } /** * Display "public" message(s) from controller if available */ echo FlashMsg::get();
function cpPhpcron ($phpcron_command="default") { global $PHP_SELF; global $phpcron_file; global $phpcron_off; global $phpcron_psinfo_file; global $assignment_info,$user_config_file, $left_mlc_ch, $right_mlc_ch, $sc_ch, $uc_contents_length; global $uc_contents, $uc_contents_length; global $cp_left_col; global $cp_right_col; global $cp_row_title; global $cp_title; global $status_on; global $status_off; global $status_venabled; global $phpcrontab_filename; global $log_result_file; global $admin_email_address; global $system_name; global $daemon_mode; global $phpcron_venabled_file; global $enable_virtual_daemon; global $phpcron_output_file; global $admin_email_address; global $error_messages; global $php_path; echo pageTitle("PHPCRON Admin - Control Panel"); switch ($phpcron_command) { case "VStop": /* Disable Virtual Daemon */ if (file_exists($phpcron_venabled_file)) { deleteFile($phpcron_venabled_file); appendToFile(" **************************************************************** PHPCRON Virtual Daemon Stopped ".date("m/d/Y").":".date("h:i:s:A")." **************************************************************** ", $log_result_file); } break; case "DStop": /* Turn off Daemon */ if(!stopOtherPhpcron()) { $error_messages.=" Error: Cannot Stop Phpcron. Make sure the server process can write to ".dirname($phpron_off)."<BR>"; } break; case "Start": $os_formatted_path=formatPath($phpcron_file); if ($enable_virtual_daemon) { /*Enable Virtual Daemon */ /* If no perpetual loop just write "VIRTUAL DAEMON ENABLED" to phpcron_venabled_file. This will allow phpcron to be run from the unix crontab with the phpcron_virtuald script. */ $save_results=saveFile("VIRTUAL DAEMON ENABLED", $phpcron_venabled_file); appendToFile(" **************************************************************** PHPCRON Virtual Daemon Started ".date("m/d/Y").":".date("h:i:s:A")." **************************************************************** ", $log_result_file); if(!$save_results[0]) { //if not a successful save get error messages $index=1; $output=""; while($save_results[$index]) { $output.=$save_results[$index]; $index++; } $error_messages.=implode("\r\n",$save_results). "Cannot Enable Virtual Daemon- Must be able to write to ".formatPath($phpcron_venabled_file)." in order for PHPCRON Admin to control PHPCRON's execution. You will need to fix, and try again for PHPCRON Admin to work properly.<br>\r\n"; } else { $error_messages.="The Virtual Daemon has been enabled. Make sure you place phpcron_virtuald on your unix crontab file using crontab -e.\n"; } break; } /* Otherwise Start Up PHPCRON.PHP in either daemon(perpetual) or non-daemon mode) */ if(isOtherPhpcrond() and $daemon_mode) { $error_messages.="PHPCRON is already running in daemon mode - Cannot start more than one instance<br>"; } else { /*Start phpcron in background. NoHup allows it to continue after logout */ if ($daemon_mode) { $exec_string="nohup $php_path $os_formatted_path -r $phpcron_output_file > /dev/null &"; } else { $exec_string="$php_path $os_formatted_path -r $phpcron_output_file"; } //$error_messages.=$exec_string; exec($exec_string); sleep(1); if (!$daemon_mode) { $error_messages.="Ran PHPCRON only once. This is usually only done for testing purposes.<br>\n"; } } /* Know there's an error somewhere if the output file can't be made */ if (!file_exists("$phpcron_output_file")) { $error_messages.= " Error: Failed to execute $phpcron_file. Check path and permissions. Can't read $phpcron_output_file. <br> "; } break; case "Email_Log": $attachment=$log_result_file; $mimetype="text/english"; $subject="$system_name PHPCRON Log File Attached"; $body="PHPCRON Log file is attached for $system_name"; if($mailserver_error=mailAttachment($log_email_address, $subject, $body, $attachment, $mimetype)) { $error_messages.="Error: Unable to Email Log File:<br>\r\n".$mailserver_error; } else { $error_messages.="Emailed Log File to $admin_email_address"; } break; case "Delete_Log": $error_messages.=clearLogFile($log_result_file); break; case "Save_UC": list($uc_contents, $uc_contents_array)=parseUserConfig($user_config_file, $left_mlc_ch, $right_mlc_ch, $sc_ch); /* For Debugging (echo to screen instead of save): echo "File Rebuilt is: ".nl2br(htmlentities(rebuildUserCfg($assignment_info, $uc_contents_array)))."<br>"; */ /* Rebuild User Configuration File, then Save it */ $save_results=saveFile(rebuildUserCfg($assignment_info, $uc_contents_array), $user_config_file); if($save_results[0]) { //this would be successful save $settings_state=" <em> Options saved with the following settings: </em> <br> "; } else { $index=1; while($save_results[$index]) { $error_messages.=$save_results[$index]; $index++; } $element=0; $tab_save_error=true; $error_messages.="Please fix and try again.<br>"; } //Load Newly Saved File $uc_contents = addslashes(implode ("", file ($user_config_file))); $uc_contents_length=strlen($uc_contents); /* Include new values to override old values included at top of file */ include($user_config_file); //no break - just let it flow into default default: break; } /* Build Main Control Panel Box */ $output.= " <!--**********Begin JavaScript*******************--> <SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\"> <!-- function isNumber(theField) { string=theField.value; for (i = 0; i < string.length; i++) { // Check that each character is number. var c = string.charAt(i); if (!((c >= \"0\") && (c <= \"9\"))) { alert(\"This field requires a number.\"); theField.focus(); return false; } } return true; } --> </SCRIPT> <!--**********End JavaScript*******************--> <!--**********Begin Control Panel Table**************--> <table align=\"center\" border=\"0\" class=\"control_panel\" cellpadding=\"2\" cellspacing=\"0\" width=\"600px\" summary=\"Control Panel\"> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_title> <strong>PHPCRON CONTROL PANEL</strong> </td> </tr> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <strong>Status</strong> </td> </tr> <tr> <td style=$cp_left_col> Server OS: </td> <td style=$cp_right_col> ".PHP_OS." </td> </tr> "; if (isOtherPhpcrond()) { $daemon_running=true; } $output.=" <tr> <td style=$cp_left_col> Mode: </td> "; if ($daemon_mode) { $output.=" <td style=$cp_right_col> Daemon </td> </tr> "; } else { $output.="<td style=$cp_right_col> Non-Daemon </td> </tr> "; } $output.=" <tr> <td style=$cp_left_col> Daemon Running ? </td> "; if($daemon_running) { $output.=" <td style=$status_on> Yes </td> </tr>"; } else { $output.=" <td style=$status_off> No </td> </tr>"; } //Echo Process Info if in Unix if(!MS_WINDOWS and file_exists($phpcron_psinfo_file)) { $file_contents=file($phpcron_psinfo_file); $output.= " <tr> <td style=$cp_left_col> Owner: </td> <td style=$cp_right_col> $file_contents[1]<br> </td> </tr> <tr> <td style=$cp_left_col> Process Id: </td> <td style=$cp_right_col> $file_contents[2] <br> <br> </td> </tr> "; } $output.=" <tr> <td valign=\"baseline\" style=$cp_left_col> Start/Stop Controls: </td> "; if (MS_WINDOWS){ if (!$daemon_running) { $output.=" <td style=$cp_right_col> Start Control Not Available in Windows </td> </tr> <tr>"; } $end_output .= "Please note that PHPCRON Admin does not allow starting PHPCRON under any Microsoft operating system (this may be fixed in a future version). If using PHPCRON on a remote server, you will need to start PHPCRON through a telnet session. A start control will only appear and work under Unix. You can however, enable the Virtual Daemon <br> "; } if (!MS_WINDOWS and $daemon_mode and !$daemon_running) { $output.=" <td style=$cp_right_col> <form action=$PHP_SELF method=\"post\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Start\"> <input type=\"submit\" value=\"Start Daemon\"> </form> </td> "; } elseif (!MS_WINDOWS and !$daemon_mode and !$daemon_running) { $output.=" <td style=$cp_right_col> <form action=$PHP_SELF method=\"post\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Start\"> <input type=\"submit\" value=\"Run PHPCRON Once\"> </form> </td> "; } if ($daemon_running) { $output.=" <td style=$cp_right_col> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"DStop\"> <input type=\"submit\" value=\"Stop Daemon\"> </form> </td> "; } $output.=" </tr> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <strong>Virtual Daemon</strong> </td> </tr> <tr> <td style=$cp_left_col> Virtual Daemon: </td> "; if (file_exists($phpcron_venabled_file)) { $output.=" <td style=$status_on > Enabled </td> </tr> "; } else { $output.=" <td style=$status_off > Disabled </td> </tr> "; } if (file_exists($phpcron_venabled_file)) { $output.=" <tr> <td style=$cp_left_col> </td> <td style=$cp_right_col> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"VStop\"> <input type=\"submit\" value=\"Disable\"> </form> </td> "; } else { $output.=" <tr> <td style=$cp_left_col> </td> <td style=$cp_right_col> <form action=$PHP_SELF method=\"post\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Start\"> <input type=\"hidden\" name=\"enable_virtual_daemon\" value=\"true\"> <input type=\"submit\" value=\"Enable\"> </form> </td> "; } /* Save and Reset of Options */ //allow to revert to original file $output.=" </tr> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <strong>Update Status</strong> </td> </tr> <tr> <td style=$cp_left_col> </td> <td style=$cp_right_col> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Update\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> </form> <!--************Begin Options Form************ --> </td> </tr> "; //Save Options /* Build Options Box */ if($phpcron_command != "Save_UC") { $settings_state=" <em> Current Settings: </em> <br>"; } /*Separate out Multi-Line Comments, Single Line Comments, and Executable Portions of file into identifiable arrays stored in $uc_contents_array */ list($uc_contents, $uc_contents_array)=parseUserConfig($user_config_file, $left_mlc_ch, $right_mlc_ch, $sc_ch); //Split up executable string into ordered arrays containing variable, value, and type of variable if($assignment_info=getAssignmentInfo($uc_contents_array)){ $options_output.=" <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <form action=\"$PHP_SELF\" method=\"post\"> <strong>Options</strong> <br> (Set in ".formatPath($user_config_file). ")<br> $settings_state </td> "; $horiz_pos=0; while($horiz_pos<$uc_contents_length) { $i=0; while($assignment_info[$horiz_pos][$i]["variable"]) { $cell_width="400px"; $options_output.=" </tr> <tr> <td style=$cp_left_col width=\"$cell_width\">". $assignment_info[$horiz_pos][$i]["variable"]. " (".$assignment_info[$horiz_pos][$i]["type"]. "):". "</td> <td style=$cp_right_col width=\"$cell_width\" valign=\"middle\">". getFormElement($assignment_info[$horiz_pos][$i]["variable"], $assignment_info[$horiz_pos][$i]["value"], $assignment_info[$horiz_pos][$i]["type"], $horiz_pos, $i)." <input type=\"hidden\" name=\"assignment_info[$horiz_pos][$i][variable]\" value=\"".$assignment_info[$horiz_pos][$i][variable]."\"> <input type=\"hidden\" name=\"assignment_info[$horiz_pos][$i][type]\" value=\"".$assignment_info[$horiz_pos][$i]["type"]."\"> </td> "; $i++; } $horiz_pos++; } $options_output.= " <!--*****************Begin Submit Buttons *********************--> <tr> <td style=$cp_left_col> <HR> </td> <td style=$cp_right_col> <HR> </td> </tr> <tr> <td style=$cp_left_col> Save Changes To Options: </td> <td style=$cp_right_col> <input type=\"submit\" value=\"Save\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Save_UC\"> </form> </td> </tr> <tr> <td style=$cp_left_col > Reset Options to Values in File: </td> <td style=$cp_right_col> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Reset\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> </form> </td> </tr> <!--*****************End Submit Buttons *********************--> <!--*************************BEGIN PHPCRONTAB DISPLAY IN TEXT AREA*********************--> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <strong>PHPCRONTAB SCHEDULE </strong> </td> </tr> <tr> <td style=$cp_right_col colspan=\"2\" > <form name=\"po_form\"> <input type=\"hidden\" name=\"focushere\"> <textarea readonly onFocus=\"this.blur();\" wrap=\"off\" cols=\"80\" rows=\"20\" name=\"command_output_textarea\">"; //Read from phpcrontab file $path_errors=isPathBad($phpcrontab_filename,true,true); if ($path_errors) { // $error_messages.="Error: Unable to read file ".formatPath($phpcrontab_filename)."<br>"; while ( list($file_or_dir, $error_string) = each($path_errors)) { while (list($each_error) = each($error_string)) { $error_messages.=$path_errors[$file_or_dir][$each_message]; } } } $tab_output=explode("<br>","ERROR: CANNOT DISPLAY PHPCRONTAB\n "); if (is_readable($phpcrontab_filename)) { $tab_output=file($phpcrontab_filename); } $options_output.=implode("",$tab_output)." </textarea> </form> </td> </tr> <!--*************************END PHPCRONTAB DISPLAY IN TEXT AREA*********************--> <!--*****************Begin Submit Buttons *********************--> <tr> <td style=$cp_right_col colspan=\"2\"> <HR> </td> </tr> <tr> <!-- <td style=$cp_left_col > Edit Schedule (Basic): </td> --> <td style=$cp_right_col colspan=\"2\"> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Edit Schedule (Basic)\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Edit_Tab_By_Form\"> </form> </td> </tr> <tr> <td style=$cp_right_col colspan=\"2\"> <HR> </td> </tr> <!--*****************End Submit Buttons *********************--> <!--*************************BEGIN PHPCRON OUTPUT DISPLAY IN TEXT AREA*********************--> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <a name=\"Output_Display\"> <strong>PHPCRON OUTPUT </strong> </a> </td> </tr> <tr> <td style=$cp_right_col colspan=\"2\" > <form name=\"po_form\"> <input type=\"hidden\" name=\"focushere\"> <textarea readonly onFocus=\"this.blur();\" wrap=\"off\" cols=\"80\" rows=\"20\" name=\"command_output_textarea\">"; //Read from phpcron_output file if ($path_errors=isPathBad("$phpcron_output_file",true,true)) { $error_messages.="Error: Unable to read output file ".formatPath("$phpcron_output_file")."<br>"; while ( list($file_or_dir, $error_string) = each($path_errors)) { while (list($each_error) = each($error_string)) { $error_messages.=$path_errors[$file_or_dir][$each_error]; } } $command_output=explode("<br>","ERROR: CANNOT DISPLAY PHPCRON OUTPUT\r\nCannot Read Output File $phpcron_output_file\n "); } else { $command_output=file("$phpcron_output_file"); } $options_output.=implode("",$command_output)." </textarea> </form> </td> </tr> <!--*************************END PHPCRON OUTPUT DISPLAY IN TEXT AREA*********************--> <!--*************************BEGIN SUBMIT BUTTONS ****************************--> <tr> <td style=$cp_right_col colspan=\"2\"> <form action=\"$PHP_SELF#Output_Display\" method=\"post\"> <input type=\"submit\" value=\"Update Display\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> </form> </td> </tr> <!--*************************END SUBMIT BUTTONS ****************************--> <!--*************************BEGIN PHPCRON LOG DISPLAY IN TEXT AREA*********************--> <tr> <td align=\"center\" valign=\"middle\" colspan=\"2\" style=$cp_row_title> <a name=\"log_display\"> <strong>PHPCRON COMMAND LOG </strong> </a> </td> </tr> <tr> <td style=$cp_right_col colspan=\"2\"> <form name=\"log_form\" > <input type=\"hidden\" name=\"focuslog\"> <textarea readonly onFocus=\"this.blur();\" wrap=\"off\" cols=\"80\" rows=\"20\" name=\"command_output_textarea\">"; //Read from phpcron_output file if ($path_errors=isPathBad($log_result_file,true,true)) { while ( list($file_or_dir, $error_string) = each($path_errors)) { while (list($each_error) = each($error_string)) { $error_messages.=$path_errors[$file_or_dir][$each_error]; } } $error_messages.="Error: Unable to read log file ".formatPath($log_result_file)."<br> This will occur if Phpcron has not been run as a Daemon or Virtual Daemon yet, since the log is only created at that point.<br>"; $log_output=explode("<br>","ERROR: CANNOT DISPLAY LOG FILE\r\nTo create, run Phpcron in Daemon mode or as a Virtual Daemon.\r\n "); } else { $log_output=file($log_result_file); } $options_output.=implode("",$log_output)." </textarea> </form> </td> </tr> <!--*************************END PHPCRON LOG DISPLAY IN TEXT AREA*********************--> <!--*************************BEGIN SUBMIT BUTTONS ****************************--> <tr> <td style=$cp_right_col colspan=\"2\"> <form action=\"$PHP_SELF#log_display\" method=\"post\" onSubmit=\"document.log_form.scrollIntoView(false);\"> <input type=\"submit\" value=\"Update Display\"> </form> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Download Log File\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"download_log\" value=\"true\"> </form> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Email Log File To:\"> <input type=\"text\" name=\"log_email_address\" value=\"$admin_email_address\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Email_Log\"> </form> <form action=\"$PHP_SELF\" method=\"post\"> <input type=\"submit\" value=\"Permanently Clear Log File\"> <input type=\"hidden\" name=\"admin_subpage\" value=\"Control_Panel\"> <input type=\"hidden\" name=\"phpcron_command\" value=\"Delete_Log\"> </form> </td> </tr> <!--*************************END SUBMIT BUTTONS ****************************--> <tr> <td align=\"center\" colspan=\"2\" style=$cp_row_title> </td> </tr> </table> <!--**********End Control Panel Table**************--> "; } else { /* Syntax for user config file allows comments but is somewhat strict -stick to assignments only! and no sinqle quoted strings */ $output.=" </table> <!--**********End Control Panel Table**************--> "; $error_messages.= " <br>Error: Syntax error in user configuration file ".formatPath($user_config_file).". User configuration file should only contain variable assignments and comments in proper php syntax - and must include php ending script characters (only <?php and ?> are supported). No other statements or html should be included. Please edit manually and try again. "; } /* Echo to Page */ echo menuBar()."<br>"; if ($error_messages) { echoErrorMessages($error_messages); } echo $output. $options_output; if($end_output){ echo " <span class=\"notes\"> <hr> $end_output <hr> </span> "; } echo " <br> ".menuBar(); }