ddruff@gemini1consulting.com
Copyright © 2001 by David C. Druffner
| Revision History | ||
|---|---|---|
| Revision v. 0.5.1.0 | 10-09-2001 | Revised by: dcd |
| Initial Manual for v.0.5 of phpcron | ||
Manual for Phpcron,a PHP command line utility which allows you to schedule programs to run at certain specified times similar to the Unix standard Crond daemon (which it can be used in place of when started as a daemon or in conjunction with when Phpcron is being used as a "Virtual Daemon"). This manual also covers Phpcron Admin,an optional browser based interface to Phpcron, allowing a user to remotely schedule programs and change Phpcron options in a user friendly way without having to deal with console based sessions using ssh, telnet, or arcane text editors. Download updates to this manual and to Phpcron at Gemini 1 Consulting, LLC. Phpcron and Phpcron Admin provide an ideal solution for web hosts who wish to provide a graphical interface with the scheduling power of Crond.
An online manual is available which displays users comments, modifications, and tips, as well as any author comments since this manual was published.
The Phpcron scripts have been heavily commented with inline documentation using a version of Robodoc which this author revised to produce DocBook SGML. Attached as an Appendix is the generated source code documentation.
Phpcron is a PHP command line program which allows you to execute programs and system commands at certain scheduled times. Phpcron operates in a similar fashion to Unix's Crond daemon, parsing a configuration file called phpcrontab.conf every minute and determining whether any programs are schedule to run. If so, Phpcron executes the indicated programs. Phpcron allows a host of options, including logging and email features.
The Phpcron package also includes Phpcron Admin (phpcron_admin.php) which provides a browser based interface to Phpcron, allowing a user to remotely schedule programs and change Phpcron options in a user friendly way without having to deal with ssh, telnet, or arcane text editors.
The primary advantage of using Phpcron is the graphical interface provided by Phpcron Admin and the additional logging and email features provided by Phpcron. With Phpcron you can turn email notification of command execution on or off, logging on or off, and access all the configuration options under Phpcron Admin. In addition, Phpcron can be used both on Unix and MS Windows' systems. Phpcron and Phpcron Admin provide an ideal solution for web hosts who wish to provide a graphical interface with the scheduling power of Crond and the added feature enhancements provided by Phpcron.
This document is copyrighted © 2001 David C. Druffner and is distributed under the terms of the license, stated below.
This manual may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution is allowed and encouraged; however, this copyright notice must appear prominently in the work and this author would like to be notified at the following email address: <ddruff@gemini1consulting.com> prior to any such commercial distributions.
All translations, derivative works, or aggregate works incorporating this manual must be covered under this copyright notice. That is, you may not produce a derivative work from this manual and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the author.
Modifications: Any significant modifications (anything other than the correction of typos) to this document must be identified on the title page in the revision section of this document with the name and contact information of each author appearing next to each revision.
If you have any questions, please contact David Druffner
NO LIABILITY FOR THE CONTENTS OF THIS DOCUMENT CAN BE ACCEPTED. USE THE CONCEPTS, EXAMPLES AND OTHER CONTENT AT YOUR OWN RISK. THERE MAY BE ERRORS AND INACCURACIES, THAT MAY OF COURSE BE DAMAGING TO YOUR SYSTEM. PROCEED WITH CAUTION, AND ALTHOUGH THIS IS HIGHLY UNLIKELY, THE AUTHOR(S) DO NOT TAKE ANY RESPONSIBILITY FOR THAT.
All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as violating any trademark or service mark.
Naming of particular products or brands should not be seen as endorsements.
Phpcron, Phpcron Admin,and associated scripts, carry the following license which is GPL compatible and modeled on the modified BSD license (for GNU descriptions of various license types see the GNU License Page):
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1.Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3.The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, ANY DISTRIBUTOR, OR ANY DOWNLOAD HOSTING COMPANY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This document is version 0.5.1.0 The document version number is in S.S.M.M format. S.S. will always match the version of the software and M.M. will indicate the release of the manual relating to that version. The latest version of this document, which will be made available in a variety of formats, including plain text, HTML (tarred and zipped), Single Html,Adobe Acrobat PDF, and the SGML source, can be found at the Phpcron Document Page.
I have the pleasure of acknowledging:
Gemini 1 Consulting, LLC for support during the development of this progam and for providing the resources to host the Phpcron's documentation page.Gemini 1 Consulting, LLC is the developer of GemTrend™, a Windows based Building Controls Software application,and other innovative software products.
SourceForge, the host of Phpcron's download and development page.
Feedback is most certainly welcome for this document. Without your submissions and input, this document wouldn't exist. An online manual is available for you to submit comments for all to read and for consideration for incorporation into the next version of this manual.
At the minimum, please fill out the Feedback Form!Translations of this document are welcome. Please use the SGML Source, or failing that, the HTML or text version, all of which are found at the document page. Translations can be emailed to David Druffner.
The latest version of Phpcron can be found on the Sourceforge Phpcron Project Page and at Gemini 1 Consulting, LLC. When the package is uncompressed it should contain the following files:
phpcron.php (the primary Phpcron script)
phpcron_admin.php (the Phpcron Admin script
phpcron_commonlib.php (contains common library functions)
phpcron_userconfig.php (user configuration file, optional only if you don't use Phpcron Admin)
phpcrontab.conf (sample file which holds scheduling configuration, format is similar to Unix crontab)
phpcrond (Linux bash shell script for invoking Phpcron as a daemon)
phpcron (Linux bash shell script for invoking phpcron.php)
phpcron_virtuald (Linux bash shell script for invoking Phpcron as a Virtual Daemon - use this on the Unix crontab)
phpcron_test.sh (a test shell script to put on phpcrontab.conf to test execution of Phpcron)
phpcron_manual_big.html (this Phpcron manual in html)
phpcron_manual_big.txt (this Phpcron manual in text)
LICENSE.txt (license, info)
PHP 4 (at least version 4.0.1, it was tested on version 4.0.3pl1 ) installed as a CGI program which provides a command line interpreter. The main engine behind Phpcron and Phpcron Admin is phpcron.php, a script run at the command line.
Operating System. While the emphasis in development of Phpcron has been on Unix systems, it will run on Microsoft Windows platforms. However, Phpcron Admin will not be able to start the Phpcron Daemon,and the Virtual Daemon is designed to work with Unix's Crond.
The web server must allow system calls.If in safe mode, it won't allow this unless the safe mode directory option has been enabled, and then only for system calls to commands that are in the safe mode directory. See the safemode section of the PHP Manual for details.
Read/write/execute permissions for the user of the server process ( for Apache, usually "nobody", "www", "apache" or "httpd" - do a ps-ef | grep httpd to find out) to the directory containing Phpcron,read permissions to all files, write permissions to phpcrontab.conf. See Installation for details. If you are operating on a remote server you may need telnet access to do this, although some ftp clients allow you to set permissions.
Create a new subdirectory in your web server's document root (e.g., phpcron).
Copy the tar file to the new subdirectory and uncompress it.
You can optionally place phpcron.php and phpcron_commonlib.php in a different directory than phpcron_admin.php. For example, you may wish to place those files in your bin directory outside of the web root (so that it is within your path and you can execute easily from the command line). If you do, you must edit phpcron_admin.php, find the definition of the $phpcron_directory variable in the beginning of the script, and change it to equal a string which contains the path to the directory containing phpcron.php. The variable by default is set to the current directory.
Edit phpcron_commonlib.php, find the definition of the $php_path variable in the beginning of the script, and change it to equal a string which contains the path to the directory containing the "php" cgi executable. This will often be "/usr/local/bin" or "/usr/bin". Do an "ls /usr/local/bin/php" or "ls /usr/bin/php" to find out. If you still can't find it, check your $PATH environment variable: "echo $PATH" and look in all the directories in your path to locate the "php" executable.
Edit phpcron_virtuald, and change the definition of the PHPCRON_DIRECTORYto equal the path to the directory which holds phpcron.php. In addition, change the PHP_PATH variable to equal a string which contains the path to the directory containing the "php" cgi executable (see above).
![]() |
If you are in a Windows environment, path names should be written with a forward (/) slash (NOT a backslash or an escaped backslash (\\) ). |
Make sure the web server process has read/write/execute permissions to the installation directory, to the web server document root directory, phpcrontab.conf, and phpcron_userconfig.php. (Apache's process is usually owned by "www", "nobody", "apache" or "httpd").
Make the installation directory password protected, preferably with ssl login only and allow only web and/or system administrators to access (see web server documentation). This is crucial as Phpcron allows a user to execute system programs!
Point your browser to phpcron_admin.php. You probably will get some errors indicating that it cannot read your output file, log file and/or your phpcrontab.conf file. Scroll down until you see the options and edit the text boxes for $phpcrontab_filename and $log_result_file to point to your main installation directory. You will also want to change the email address, and any other appropriate options. Then click on the Save button. You may continue to get errors regarding not being able to read the output file until you start Phpcron since that file isn't created until Phpcron is run at least once.
![]() |
One option you may consider for security reasons is to place your phpcrontab.conf file outside of your web root. If you do so you will need to change the path of the phpcrontab.conf to point to that location. |
For reference, here is a screen shot showing the available options:
If you are on a Unix/Linux system, and want to utilize the Virtual Daemon you need to edit your Unix crontab file. Go to the command prompt (if you are installing on a remote system you will need to telnet or ssh to the server) and type crontab -e. If your server gives you access to crontab, that should put you into vi (or some other text editor) showing your Crontab file. Insert the following line (in Vi you insert by typing the escape key, then the letter "i", then the text to be inserted):
Notice the filename is preceeded by a dot and a space. The dot is the bash shell execute command. Many system admins (especially on virtual hosts) will require both the dot command, as well as the full path to the shell command (even if you would expect it already to be in your path). Now save and quit (in Vi this would be the escape key, then "ZZ"). This will cause Crond to execute phpcron_virtuald every minute in non-daemon mode, which simulates the effect of a Phpcron daemon but without its overhead.That's it. You can now view output, start and stop daemons (actual and virtual), view the log, and set options using the Control Panel. Set the schedule of programs using the Edit Schedule (Basic) and Edit Schedule (Advanced) menu selections. See the section on Phpcron Admin for screenshots and explanations of these options.
To test your installation, put the phpcron_test.sh script on your phpcrontab.conf file. Click on Edit Schedule (Basic) OR Edit Schedule (Advanced). For example, if it is Tuesday, enter something like this to execute the test script every minute (for more information on phpcrontab.conf see Phpcrontab):
Then press Save. This should execute the phpcron_test.sh file every minute. This little script creates an HTML file called phpcron_test.html and outputs to it the time of the script's execution. To verify that it has been executed, make sure that the Phpcron daemon (either actual or Virtual) is enabled, wait a minute, then point your browser to http://[yoursite]/[phpcron_installation_directory]/phpcron_test.html. You should see the HTML page updated every minute with the current time when you press reload on your browser.![]() |
A Note on privileges in Unix: Using chmod and chown, you should make the owner of the server process a member of a group (say phpcron_group) and grant that group the necessary privileges to read, write, and execute files in the phpcron installation directory . All other users should be denied even read access. These same restrictions should be implemented on a Windows system using the equivalent permission controls. |
![]() |
The above instructions assume you are going to use Phpcron Admin with Phpcron. If you only want to use Phpcron at the command line, just copy phpcron_commonlib.php, phpcron.php, phpcrontab.conf, and in a Unix environment, the shell scripts, phpcrond, and phpcron to a directory in your path, set the proper permissions, and execute with the proper options. |
I would really appreciate it if you could fill out this form and submit it. I was considering a scheme for a really annoying splash screen but decided that this form would be better. You will need to be connected to the internet when you do so. I have had hundreds of downloads of this script but have heard very little back. I need your comments to make the next version of Phpcron better.
Your email address won't be sold to or used by third parties, although, if you wish, we will place you on the developer's mailing list to announce updates. All information, including the email address is optional.
Phpcrontab.conf is the text file that holds the Phpcron scheduling directives. An example file is included in your download package. The format is the same as Crond's crontab. The format is:
Wild Cards and ranges are allowed. Each parameter is separated by one pace, except the command text which can be separated from the time parameters by more than one space. You can use leading zeros (e.g, 03) but it is not necessary. You can comment to the end of a line by beginning the comment with a pound sign (#) (shell style comments) but multiple C style (e.g., /*comment */) line comments are not allowed.
Example 1. Short Phpcrontab.conf Example
# Example phpcrontab.conf file with wildcard. # Executes command every Friday at 3:59 59 3 * * 5 sample_script.sh # executes on the 1st and 15th of the month 0 0 1,15 * * sample_script.sh #executes on the 1st-15th of the month #which are any weekday except Wednesday and Saturday 0 0 1-15 * 0-2,4,6 sample_script.sh |
You don't need Phpcron Admin to invoke Phpcron. Assuming that the Phpcron scripts are in your path, at your system prompt type
To invoke Phpcron as a daemon type the following:
On Linux systems, instead of the above, you can use the shell scripts which are simpler:
This executes the bash shell script phpcron which in turns executes phpcron.php.For daemon execution in Linux, type
![]() |
phpcron.php relies on the phpcron_commonlib.php file for certain critical functions. Thus, while phpcron.php can be executed at the command line without using Phpcron Admin and without relying on the phpcron_admin.php script, it must have access to phpcron_commonlib.php file. Make sure that phpcron_commonlib.php. is in the same directory as phpcron.php. |
There are a host of options to Phpcron - all of which can be set either on the command line or through Phpcron Admin. To see the entire set of switches type php phpcron.php -h (or in Linux phpcron -h at the system prompt). Most of the options have either a long format (using --) or a short format (-). Some of the more useful options are:
Common Phpcron Command Line Switches
Invokes phpcron as a daemon (runs continuously)
Invokes phpcron.php in non-daemon mode. In this mode, it runs once, then exits. Usually only used for debugging, also utilized by phpcron_virtuald to simulate a daemon.
Email Errors on - Email failure message if scheduled program fails to execute
Turn the mail notification feature on
Help - Gives Explanation of Options
Turn logging on and set the path to the log file
Stops all instances of the phpcron daemon
![]() |
All of the options in phpcron.php have what I call "original" defaults, the settings of which you can view with the -h switch. However, these are overridden by the settings in the optional phpcron_userconfig.php file if it exists in the Phpcron directory. Phpcron_userconfig.php file is also the one which Phpcron Admin parses, displays, and changes when it changes options. So if you use Phpcron Admin and change any Phpcron options, the original defaults will change at the command line. Finally,please note that the command line switches override both the original defaults and the settings in the phpcron_userconfig.php file. |
Phpcron Admin is a browser-based interface to Phpcron which allows you to configure Phpcron's options, stop and start Phpcron, and view the log file. It is an ideal utility for system administrators to use to allow their clients to schedule programs in a user friendly manner.
The Phpcron Admin Control Panel allows you to do the following:
view status of Phpcron (including PID of any currently running process)
set all configuration options for Phpcron
start and stop Phpcron (both in daemon and non-daemon modes)
enable and disable the Virtual Daemon,
view,download, and email the phpcron log file
schedule command execution (either through a direct edit of the phpcrontab.conf file or a user friendly form that checks entries for correct format)
Below is a screenshot, showing a section of the Control Panel. As you can see, the Virtual Daemon has been enabled.
The control panel also allows you to view and clear the log file, the Phpcron output, and the programs that are scheduled (the screen shots of these sections are not shown).
Below is the next section of the Control Panel showing the options that can be configured for Phpcron. These options mirror the options that can be set using the command line options.
![]() |
The options above are generated on the fly by parsing the phpcron_userconfig.php file. This file must exist to run Phpcron Admin (it is not needed to run the Phpcron on the command line). The options shown will also change depending on what variables are defined in the phpcron_userconfig.php file. |
Phpcron Admin also allows you to edit the phpcrontab.conf file and schedule your programs. This can be done with the "Edit Schedule (Advanced)" screen which allows you to directly edit the file (you can also edit the Options directly by selecting the Set Options (Advanced) menu choice).
However, a better (and safer) way to schedule programs is to use the "Edit Schedule (Basic)" option on the menu. This will present you with a form that allows you to edit the schedule parameters, and when saved, will validate the parameters to check that they are in the correct format (a Javascript validation is used also). Here is a screenshot of a portion of the Edit Schedule (Basic) screen:
As you can see, the top comments of the file are presented in a text box at the top. There is no need to add leading #, these are added automatically when the file is saved. The schedule parameters can be entered in time columns. When the file is saved (the save button is not shown in the screenshot) the form will be validated (the formats of the time parameters are checked to see if they are within the correct ranges, etc.)
Phpcron can be run in one of two "modes". The first is the "daemon mode" in which Phpcron runs continuously in the background. This mode is appropriate for systems in which only one user will be utilizing Phpcron. Unlike Unix's Crond daemon, a single Phpcron process parses only one configuration file (phpcrontab.conf) and cannot be configured to parse multiple users' crontabs. However, Phpcron can be run as a "Virtual Daemon" in conjunction with Unix's Crond, allowing multiple users on a single system to use Phpcron and Phpcron Admin.
The second mode that Phpcron can be run in is the "non-daemon mode". This simply runs the script once and quits. It parses the phpcrontab.conf file only once. It is not very useful except for testing purposes.
The real advantage that Phpcron has over Crond is the ability to use Phpcron Admin - a user friendly web based interface for the various scheduling and configuration options. However, in order to allow multiple users to use Phpcron on the same machine (e.g., in a virtual hosting environment) one would ordinarily need to invoke multiple instances of the Phpcron daemon - an unacceptable situation since this would overwhelm the server (in fact Phpcron is written to avoid this situation. It will automatically detect if another instance of Phpcron is running, and if so, refuse to run in daemon mode). However, one can allow multiple users utilize Phpcron by running it as a "Virtual Daemon". Instead of Phpcron running continuously, it is executed once every minute using Unix's Crond. This is done by putting editing your crontab file(using crontab -e, see Installation for details). This will cause Crond to run phpcron_virtuald every minute. phpcron_virtuald is a shell script wrapper which invokes phpcron.php in non-daemon mode only if the Virtual Daemon has been enabled by Phpcron Admin.
Phpcron Admin enables the Virtual Daemon by creating the file phpcron_venabled in the Phpcron directory. Before invoking phpcron.php, Phpcron_virtuald checks to see if the phpcron_venabled exists.If so, it executes phpcron.php in non-daemon mode. If the file does not exist, phpcron_virtuald does nothing. Thus the Virtual Daemon allows you to get the advantage of using Phpcron without the overhead of actual daemons running in the background, allowing multiple users on a system to use its features.
A Demonstration of Phpcron Admin and Phpcron is available here. Note that for security reasons, you won't be able to edit any configuration files and will get error messages saying that the configuration files can't be written to.
Code modifications and contributions are welcome. Suggestions include:
Further Testing and improvement on Windows 95/98/NT/2000 (the current version has been tested on Windows 95 and Linux only)
Please contribute at the Sourceforge Phpcron Project Page
The Phpcron scripts have been heavily commented with inline documentation using a version of Robodoc which this author revised to produce DocBook SGML. Attached as an Appendix is the documented code for your reference. Some versions of this document may not have the Appendix, in which case, you can obtain the full version of the manual with the attached Appendix at the Phpcron document page.
Generated from xref_file with ROBODoc v3.2.3 on Wed Oct 24 21:26:43 2001
This is the scheduling engine and command line utility. It can be controlled by phpcron_admin.php |
COPYRIGHT 2001 (C) David C. Druffner ddruff@gemini1consulting.com This script is released under a modified BSD License. See php phpcron.php -license and LICENSE.txt in download package for full license details |
Can't startup phpcron or execute most system calls in Windows, although stop and other functions work Other Bugs can be reported via the online manual: http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ |
This script can be controlled by Phpcron Admin (phpcron_admin.php), a based interface. The current manual for Phpcron and Phpcron Admin is located at http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ The Home Page is: http://phpcron.sourceforge.net/ Download from the Source Forge Project Page: http://www.sourceforge.net/projects/phpcron/ In-Line Documentation: A slightly modified version of ROBODOC is used to generate documentation for this code. I have modified the headers.c file in the Robodoc source code to et the variable header_markers to equal only /*ROBODOC* as the start of a header marker - this avoids confusion with other strings and comments in PHP code. Robodoc is available at http://www.xs4all.nl/~rfsber/Robo/robodoc.html |
This is the directory that holds the include files. Must be able to be written to by process running this script. By default this is null thus pointing to the same directory as this script . |
Boolean - set to true to mail user a notification that commands in phpcrontab.conf has been executed successfully |
Boolean - set to true to mail the user an error message regarding the failure of a scheduled phpcron command. |
String - address receiving mail sent if $mail_errors set to true to mail the user an error message |
String - Unique name of system on which the phpscript is used. You can name it whatever you want, but I suggest the host name - Used to identify system in email messages |
Boolean - Suppress all non-fatal error messages and other output (including debugging messages). This overides $debug |
Boolean - when this is set to true, phpcron.php runs in a continuously as a daemon. |
Gracefully stops this script. Time stamps the log file, deletes phpcron_psinfo file and exits. |
function stopThisProcess($stop_message) {
//Graceful Stop
global $log_result;
global $log_result_file;
global $pid;
global $phpcron_off;
global $phpcron_psinfo_file;
global $daemon_mode;
/* Only do this if this process is running as a daemon.
Don't want to log start/stops if only running once */
sendOutput($stop_message."\r\n", true);
if($daemon_mode) {
$stop_time= date("m/d/Y").":".date("h:i:s:A");
if ($log_result) {
$stop_message="
***********************************************************
PHPCRON (DAEMON) $pid Stopped $stop_time
Final Output Message:
".strip_tags($stop_message)."
***********************************************************
";
appendToFile("$stop_message", $log_result_file);
}
deleteFile($phpcron_off);
}
deleteFile($phpcron_psinfo_file);
deleteFile("$TEMP_DIR/".basename($phpcron_psinfo_file));
exit;
}
|
Kills any other phpcron daemons that may be running. This is a non-nice termination and is only used when stopOtherPhpcron doesn't work. It actually kills the process and does not properly timestamp logs, etc. |
Probably lots due to not testing on any other system. Ps command may be different for other systems. Kill process won't work on Windows systems. |
function killOtherPhpcron() {
/* Abort Phpcron daemons - not nice*/
//First try to stop nicely
if(stopOtherPhpcron()){
return true;
}
exec("ps -C php O p |grep 'phpcron.php.(*['--daemon'|'-D'].*'$|cut -d' ' -f1-4",$output,$result_code);
$i=0;
//loop through processes and kill them
while($i<=count($output[$i])-1) { //-1 is don't kill this process
//Get rid of any spaces and make sure only have one element
$output[$i]=trim($output[$i]);
$output_array=explode(" ", $output[$i]);
$output[$i]=$output_array[0];
//sendOutput("Output: Killing Phpcron daemon process $output[$i]\r\n");
exec("kill -9 $output[$i]",$killoutput, $result_code);
if ($result_code) {
//sendOutput("Error: Can't Kill process $output[$i]\r\n");
return false;
}
$i++;
}
return !isotherPhpcrond();
}
|
$cl_help="
--abort
-a
-Aborts a currently running phpcron daemon - Not Nice. Only use if
--quit fails
--phpcrontab PHPCRONTAB_CONF_FILE
-c PHPCRONTAB_CONF_FILE
-Sets the path for configuration file named as PHPCRONTAB_CONF_FILE
--daemon
-D
-Daemon Mode - Run until process is killed
--daemon-off
-d
-Daemon Off/Run Once - Parse the phpcrontab file once and stop
(original default)
--email-errors EMAIL_ADDRESS
-E EMAIL_ADDRESS
Email Errors on - Email failure message if scheduled program fails to
execute
--email-errors-off
-e
-Mail Errors Stop - Turn off email of errors (original default)
--help
-h
-?
-Prints this help
--logging LOGFILE
-L LOGFILE
-Turn logging on and set the path to the log file
--logging-off
-l
-Stops logging (original default)
--mail-notification EMAIL_ADDRESS
-M EMAIL_ADDRESS
-Turn the mail notification feature on
--mail-notification-off
-m
- Turn the mail notification feature off (original default)
--name SYSTEM_NAME
-n
-Set the system same used in mail messages
-r [DUMP_FILE]
- Redirect All Output to DUMP_FILE (default file: phpcron_output)
--suppress
-S
-Suppress all messages to screen except fatal errors
--suppress-off
-s
-Stop Suppression of output (original default, opposite of -S)
--slow-debug SECONDS
-sd SECONDS
-Slow Debug Scroll - SECONDS is integer by which debug messages are
slowed. Increase to slow debug messages when verbosity is turned on
--quit
-q
-Stops gracefully all currently running phpcron deamons
--verbose
-v
-Turn debugging messages on
--verbose-off
-Turn debugging messsages off (original default)
NOTE: The actual defaults may be different from the \"original default\" setting
if the user configuration options have been changed in the script or if a user
configuration file is being used.
For more information, see the manual that is packaged with the script.
";
|
Redirects all output to specified file |
Generated from phpcron_admin.php with ROBODoc v3.2.3 on Wed Oct 24 21:26:43 2001
COPYRIGHT 2001 (C) David C. Druffner ddruff@gemini1consulting.com This script is released under a modified BSD License. See php phpcron.php -license and LICENSE.txt in download package for full license details |
Can't startup phpcron or execute most system calls in Windows, although stop and other functions work Other Bugs can be reported via the online manual: http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ |
This is the browser based interface to phpcron.php. The current manual for Phpcron and Phpcron Admin is located at http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ The Home Page is: http://phpcron.sourceforge.net/ Download from the Source Forge Project Page: http://www.sourceforge.net/projects/phpcron/ In-Line Documentation: A slightly modified version of ROBODOC is used to generate documentation for this code. I have modified the headers.c file in the Robodoc source code to et the variable header_markers to equal only /*ROBODOC* as the start of a header marker - this avoids confusion with other strings and comments in PHP code. Robodoc is available at http://www.xs4all.nl/~rfsber/Robo/robodoc.html |
Constant containing path for directory of script being executed. This is mainly used to expand directories when paths are sent to the screen and the a path otherwise would have no directory name since it is in the current directory. See formatPath |
This is the only variable you need to set after installing. Its value is the directory in which you put phpcron.php and all supporting scripts (other than this script, phpcron_admin.php) in the installation package, including phpcron_commonlib.php,phpcron_userconfig.php, and phpcrontab.conf. |
This is the file which all output is redirected when the -r flag is used. See $cl_help |
Make this true to turn on some security features. The only thing this does now is turn off the "save as" text box on the edit screens |
function clearLogFile($log_result_file) {
/* Clears Log file, returns false on success, true and error messages on failure */
$clear_time= date("m/d/Y").":".date("h:i:s:A");
if(!deleteFile($log_result_file)) {
$error_messages="Cannot delete $log_result_file - Check path and permissions.<br>";
} else {
$clear_message="
***********************************************************
PHPCRON Log File Cleared on $clear_time
***********************************************************
";
//append to log file and get error messages, not success message
$append_results=appendToFile($clear_message,$log_result_file);
$append_results[0]="";
if(trim($append_results)) {
$error_messages.=implode(" ",$append_results);
}
}
return $error_messages; //if there are errors, this will return true, if not, false
}
|
This functions checks $file_contents to see if it has any PHP errors in it (syntax or otherwise) and returns those errors. It does so by saving a temporary file with file_contents to the web server document root directory and then opening a url to it. This should only be used on files that don't have any output - since it assumes that any output is an error (i.e., mainly intended to check if the syntax of the included user configuration file is ok.) |
$file_contents - contains contents of $file_name file to be checked for errors $file_name - contains full path of an existing file, the contents of which are $file_contents |
The primary purpose of this function is to make sure that the user configuration file does not have an error in it before it is saved if it is being edited through phpcron_admin. This could happen if the user mistakenly enters erroneous statements - especially in the free style edit mode. Since the userconfiguration file is included both in phpcron_admin.php and phpcron.php this could have disasterous results unless syntax errors, etc. are anticipated. |
This requires the web server to have read/write permissions to the web server's root document directory. |
function isBadPHP($file_contents, $file_name) {
global $DOCUMENT_ROOT;
global $SERVER_NAME;
global $phpcron_directory;
$file_name=$DOCUMENT_ROOT."/".basename($file_name).".tmp.php"; //add temporary extension
$save_results=saveFile(trim($file_contents), $file_name);
if(!$save_results[0]) { //if not a successful save
$save_results=implode("",$save_results);
$error_messages.="Save results: $save_results";
$index=2;
/* $error_messages.="
Error: Cannot save $file_name, verify permissions allow writing to file.<br>
Error: Cannot save temporary file - verify permissions allow writing to ".formatPath($phpcron_directory)."<br>";
*/
while(isset($save_results[$index])) {
$error_messages.=$save_results[$index];
$index++;
}
return $error_messages;
}
$handle = fopen ("http://$SERVER_NAME/".basename($file_name), "r");
while (!feof($handle)) {
$contents.=fread($handle,4096);
}
fclose($handle);
$contents=trim(strip_tags($contents));
//get rid of reference to temporary file name
$contents=str_replace ("in ".formatPath($file_name),"", $contents);
deleteFile($file_name);
/*If the output from the open has any characters in it at
all we are assuming there are errors*/
if ($contents) {
return "The following PHP errors are in your file<br>\r\n".$contents;
} else {
return false;
}
} //end of function
|
This functions checks $ct_param and $commands which are generated by editTabByForm they conform with proper crontab format. |
$ct_params - 2 dimensional array which contains scheduling parameters for
phpcrontab.conf.
$commands - array which contains scheduled phpcrontab commands.
|
It returns true if there is a validation error, false if the phpcrontab contents are valid. |
function isTabFormBad($ct_param, $commands) {
/* Validate parameters in Chron Tab Form Submitted from Structured Edit */
$command_number=0;
/* Cycle through each parameter */
while (list($first, $second) = each($ct_param)) {
$command_number++;
while (list($each_second) = each($second)) {
$test_value=trim($ct_param[$first][$each_second]);
$commands[$first]=trim($commands[$first]);
/* If it's an asterisk than it's ok - continue to next value */
if ($test_value =="*") {
continue;
}
}
/* If either there are any parameters for this line or
there are commands for this line than validate each parameter
for correct format */
//test if either a time parameter or commands are entered
$test_whole_string=trim(implode(" ",$ct_param[$first]));
if ($test_whole_string or $commands[$first]) {
$error_messages.=isCronTimeParamsBad($test_whole_string, $command_number);
}
}
/* If there are time parameters and no commands than give error */
if (trim(implode("",$ct_param[$first])) and !$commands[$first]) {
$error_messages.="Error in Command #$command_number: The commands field is empty<br>";
}
if ($error_messages) {
return "<h3>Cannot save because of validation errors - please fix and try again:</h3>
$error_messages";
} else {
return false;
}
}
|
function menuBar() {
global $PHP_SELF;
//Print Horizontal Menu Bar
$output="
<!--**********Begin Menu Bar**************-->
<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\" width=\"800px\" class=\"menuBar\" bgcolor=\"#9999CC\" summary=\"Menu Bar\">
<tr>
<td align=\"center\" width=\"25%\">
<a href=\"$PHP_SELF?admin_subpage=Control_Panel\" title=\"Turn ON/OFF, Set Options\">Control Panel</a>
</td>
<td>
|
</td>
<td align=\"center\" width=\"25%\">
<a href=\"$PHP_SELF?admin_subpage=Edit_UC_Full\" title=\"Directly Edit Options\">Set Options (Advanced)</a>
</td>
<td>
|
</td>
<td align=\"center\" width=\"25%\">
<a href=\"$PHP_SELF"."?admin_subpage=Edit_Tab_By_Form\" title=\"Form Edit of Phpcrontab\">Edit Schedule (Basic)</a>
</td>
<td>
|
</td>
<td align=\"center\" width=\"25%\">
<a href=\"$PHP_SELF?admin_subpage=Edit_Tab_Full\" title=\"Directly Edit Phpcrontab\">Edit Schedule (Advanced)<br></a>
</td>
</tr>
</table>
<!--**********End Menu Bar**************-->
";
return $output;
}
|
Completes the header for the HTML page inserting the page title, ending title and head ta and creating the opening body tag |
Returns a formatted string containing HTML for the end of the <head> and beginning of the body tag |
function pageTitle($title) {
return "
$title
</title>
</head>
<body>
<!--Begin Note for Non Compliant Browsers |*-->
<p class=\"ahem\" >
<font size=2px>
<strong>
<em>
For a better viewing experience, either turn your CSS stylesheets
on in your browser, or if your browser does not support stylesheets,
<a href=\"http://www.webstandards.org/upgrade/\"
title=\"Download a browser that complies with Web standards.\">download </a> a
browser that complies with web standards. Some browsers disable stylesheets when
JavaScript is disabled.
</em>
</strong>
</font>
</p>
<NOSCRIPT>
<p class=type1> <font size=2px> <strong> <em> Either you have JavaScript
turned off in your browser or your browser does not
support JavaScript. Although this site supports non-JavaScript browsers,
for better functionality you may want to <a href=\"http://www.webstandards.org/upgrade/\"
title=\"Download a browser that complies with Web standards.\">download </a>
a JavaScript enabled browser.
</em>
</strong>
</font>
</p><br/>
</NOSCRIPT>
<!--End Note for Non Compliant Browsers *|-->
";
}
|
string buildNewtab(int $max_line_number, string $phpcrontab_filename, array $ct_param, array $commands, array $side_line_comments); |
Takes information from editTabByForm and creates new file contents to be saved over phpcrontab.conf |
int $max_line_number - max number of lines in file string $phpcrontab_filename - filename of phpcrontab.conf array $ct_param - array containing scheduling parameters array $commands - array containing comments array $side_line_comments - array containing single line # comments |
function buildNewtab($max_line_number, $phpcrontab_filename, $ct_param, $commands, $side_line_comments, $top_line_comments, $bottom_line_comments) {
global $PHP_SELF;
$line_number=0;
/* Get rid of # as first character of each line (in case user inserted it) */
$top_line_comments=preg_replace("/^#/m", "", trim($top_line_comments));
/* Inserts # as first character of each line */
$top_line_comments=preg_replace("/^(.)/m", "#\\1", trim($top_line_comments));
$bottom_line_comments=preg_replace("/^#/m", "", trim($bottom_line_comments));
$bottom_line_comments=preg_replace("/^(.)/m", "#\\1", trim($bottom_line_comments));
$new_tab_contents.=$top_line_comments."\r\n\r\n";
while($line_number< $max_line_number) {
if($ct_param[$line_number]) {
$parameters=implode(" ", $ct_param[$line_number]);
$new_tab_contents.=$parameters." ".$commands[$line_number];
if($side_line_comments[$line_number]) {
$side_line_comments[$line_number]=preg_replace("/^#/m", "", trim($side_line_comments[$line_number]));
$side_line_comments[$line_number]=preg_replace("/^(.)/m", "#\\1", trim($side_line_comments[$line_number]));
$new_tab_contents.=" ".$side_line_comments[$line_number]."\r\n";
} else {
$new_tab_contents.="\r\n";
}
}
$line_number++;
}
$new_tab_contents.="\r\n\r\n".$bottom_line_comments;
return trim($new_tab_contents); //contents of file to be saved
}
|
string $phpcron_command - option argument which determines which command
to pass to phpcron (see switch statement)
|
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>
";
}
// } /* DCD Fix don't use this
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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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=\"get\">
<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();
}
|
function editTabByForm($phpcrontab_filename){
global $PHP_SELF;
global $new_tabfilename;
global $edit_table_title;
global $edit_table_title_no_border;
global $edit_tab_by_form;
global $tab_save_error;
global $new_tab_contents;
global $old_tabfilename;
global $create_tab;
global $secure;
/*NOTE: Allow create file: if there is no phpcrontab file or no parameters then
substitute another array for $line and save new file. */
if ($tab_save_error) {
$new_tabfilename=""; //initialize
$phpcrontab_filename=$old_tabfilename;
/* Don't read from file - just use attempted saved contents if save failure */
$phpcronconf_array=explode("\n",stripslashes($new_tab_contents));
} elseif(!$path_errors=isPathBad($phpcrontab_filename,true,true)) {
/* Read conf file into an array, with each line being an element in the array */
$phpcronconf_array=file($phpcrontab_filename);
} else {
if (is_readable($phpcrontab_filename)) {
$phpcronconf_array=file($phpcrontab_filename);
}
//If there are path errors, report them
while ( list($file_or_dir, $error_string) = each($path_errors)) {
while (list($each_message) = each($error_string)) {
$error_messages.=$path_errors[$file_or_dir][$each_message];
}
}
$error_messages="<h3>Cannot Edit $phpcrontab_filename because of file errors:</h3>".$error_messages;
}
//Tests for existence of phpcrontab file - if does not exist, creates one
if(!file_exists($phpcrontab_filename) or $create_tab) {
if (!$create_tab) {
$error_messages.="Creating new phpcrontab file - No existing file found for $phpcrontab_filename<br>";
} else {
$error_messages.="Creating new phpcrontab file<br>";
}
$create_tab=true;
$create_tab_contents=
"# comments: lines must begin with a #
# Phpcrontab.conf
#The phpcontab.conf file contains a schedule of scripts/programs to
# run in the traditional crontab format:
# minute (0-59) hour (0-23) day of month (1-31) month(1-12) day of week(0-6) command
# Wild Cards are allowed. Each parameter is separated by one space.
# Example:
#
# 59 3 * * 5 php sample_script.php # every Friday at 3:59 a.m.
#Ranges and multiple values will also work:
# 0 0 1-15 * * perl sample_script.pl #executes on 1st through 15th of month
# 0 0 1-3,15 * * perl sample_script.pl # executes on 1st-3rd and 15th of month
#
# MINUTES HOUR MONTHDAY MONTH WEEKDAYNUM
";
$phpcronconf_array=explode("\n",$create_tab_contents);
}
$crontab_stripped=formatPath($phpcrontab_filename);
$output.="
<!--**********Begin JavaScript*******************-->
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">
<!--
function isNumberBetween(string,low,high) {
for (i = 0; i < string.length; i++)
{
// Check that each character is number.
var c = string.charAt(i);
if (!((c >= \"0\") && (c <= \"9\"))) return false;
}
var number = parseInt (string); //converts string to integer
return ((number >= low) && (number <= high));
}
function trim(str)
{
var i = 0,j = str.length - 1;
while(str.charAt(i) == ' ') i++;
while(str.charAt(j) == ' ') j--;
j++;
return str.substring(i,j);
}
function validateField (field_string, textvalue, individual_parameter, theField, max_low, max_high) {
var warning_message=\"\";
if(!textvalue.match(/^(([0-9]{1,2}|[0-9]{1,2}-[0-9]{1,2}),?)+$/))
return warn(theField, textvalue + \" in the \" + field_string + \" field is in an incorrect format.\");
for (i_array in individual_parameter)
{
/*warning_message=warning_message+\"i_array: \" + i_array + \"Being Evaluated:\" + individual_parameter[i_array] + \"\\r\\n\";
*/
/* Check for Range */
if(individual_parameter[i_array].match(/^[0-9]*-[0-9]*,?$/)) {
var range=new Array();
range=individual_parameter[i_array].match(/[0-9]*-?/g) /* explode by hyphen*/
/*Just deletes , or - at end of string if it exists */
range[0]=range[0].replace(/[,-]/g,\"\");
range[1]=range[1].replace(/[,-]/g,\"\");
/*warning_message=warning_message+ \"Low Value: \" + range[0] + \" High Value is: \" + range[1] + \"\\r\\n \";;
*/
/*Make Sure High > Low */
if (parseInt(range[0])>=parseInt(range[1])) {
warning_message=warning_message + \"Low value of range \" + individual_parameter[i_array] + \" in \" + field_string + \" field is greater than or equal to high value.\\r\\n\";
}
for (i_range in range)
{
/*check each range to see if between correct values */
if (isNumberBetween(range[i_range],max_low,max_high)!=true)
{
if(range[i_range]==\"\") {
continue; //continue inner loop
}
warning_message=warning_message + range[i_range] + \" is in the \" + field_string + \" field which requires a number between \" + max_low + \" and \" + max_high +\".\\r\\n\";
}
}
continue; //continue outer loop
}
/*warning_message=warning_message+ \"Second Being Evaluated:\" + individual_parameter[i_array] + \"\\r\\n\";
*/
/*Just deletes , or - at end of string if it exists */
individual_parameter[i_array]=individual_parameter[i_array].replace(/[,-]/g,\"\");
if (isNumberBetween(individual_parameter[i_array],max_low,max_high)!=true)
{
if(individual_parameter[i_array]==\"\") return true;
warning_message=warning_message + individual_parameter[i_array] + \" is in the \" + field_string + \" field which requires a number between \" + max_low + \" and \" + max_high +\".\\r\\n\";
}
i_array++;
}
if(warning_message !=\"\") {
warning_message=\"Error(s):\\r\\n\" + warning_message;
return warn(theField,warning_message);
} else {
return true;
}
}
function checkParameter(theField, parameter_type) {
/*Textvalue is string hold all of values in field */
textvalue=trim(theField.value);
var i_array=0;
if (textvalue == \"*\") return true;
var individual_parameter=new Array();
/*Fill Array Individual Parameter with Values Separated by , or hyphens*/
individual_parameter=textvalue.match(/[0-9]+(-[0-9]+)?,?/g) /* took out hypen*/
switch (parameter_type) {
case 0:
return validateField (\"Minutes\", textvalue, individual_parameter, theField, 0, 59);
case 1:
return validateField (\"Hour\", textvalue, individual_parameter, theField, 0, 23);
case 2:
return validateField (\"Day of Month\", textvalue, individual_parameter, theField, 0, 31);
case 3:
return validateField (\"Month\", textvalue, individual_parameter, theField, 1, 12);
case 4:
return validateField (\"Week Day\", textvalue, individual_parameter, theField, 0, 6);
default:
return warn(theField, \"Error in Code: Parameter Type is Invalid - Can't validate entry\");
}
}
function warn (theField, s){
alert(s);
return false;
}
function NoEmpty(theField, s) {
if(theField.value==\"\")
alert(\"The \" + s + \" field requires an entry\");
}
-->
</SCRIPT>
<!--**********End *******************-->
<form action=\"$PHP_SELF?admin_subpage=Save_Edtab\" STYLE=\"margin-bottom: 0\" method=\"post\">
<!--*************** Begin Schedule Programs Table (edit phpcrontab info ) *********-->
<table align=\"center\" width=\"600px\" style=$edit_tab_by_form border=\"0\" cellspacing=\"0\" cellpadding=\"2\" summary=\"PHPCRONTAB Edit Form\">
<tr >
<td colspan=\"7\" align=\"center\" style=$edit_table_title>
<h2>Schedule Programs</h2>";
if ($create_tab) {
$output.= "
<h4>New PHPCRONTAB File</h4>";
} else {
$output.=
"<h4>(edit ".chunk_split($crontab_stripped, 20, " ").")</h4>";
}
$output.="
</td>
</tr>
";
$line_number=0;
/* Loop through the array containing the lines of the phpcrontab.conf file */
while ($line=$phpcronconf_array[$line_number]) {
$line=trim($line); //trim extra spaces
/* Get lines which contain mixed parameters and comments */
preg_match("/#.*$/",$line, $side_line_comments);
/* Gets rid of # as first character of each line -
add this back later when save file. User does not have to enter */
$side_line_comments[0]=preg_replace("/^#/m", "", trim($side_line_comments[0]));
preg_match("/^#.*$/",$line, $full_line_comments);
/* Get rid of # as first character of each line - add this back later when save file.
User does not have to enter. Also move lines over preserve vertical whitespace. */
$full_line_comments[0]=trim(preg_replace("/^#(.)/m", "\\1", trim($full_line_comments[0])));
// preserve vertial whitespace
$full_line_comments[0]=preg_replace("/^#/m", " ", $full_line_comments[0]);
if($full_line_comments[0]) {
$top_line_comments.=$full_line_comments[0]."\r\n";
$number_of_top_comments++;
}
if($param_headings_printed and $full_line_comments[0]) {
$bottom_line_comments.=$full_line_comments[0]."\r\n";
$number_of_bottom_comments++;
}
/* Delete commented out sections and lines */
$line=preg_replace("/#.*$/","",$line);
/* If line is a blank line then ignore line, otherwise
process commands */
if(!preg_match ("/^\s*$/", $line)) {
/*Print out Top Comments into a Text Area if haven't printed*/
if (!$param_headings_printed) {
$output.=tabTopComments($top_line_comments, $number_of_top_comments);
$param_headings_printed=true; //print headings only once
}
/* Parse line into a 6 element array (0-5),
5 time parameters (minute, hour, day of month, month, day of week)
+ command string */
$line = explode(" ", $line,6);
$command_text=array_pop($line); // pop off the command text
$command_text=trim ($command_text); //trim extra spaces
/* Cycle through first five parameters horizontally and put in
text boxes */
$parameter_no=0;
while ($parameter_no<5){
$box_size=4;
$output.= "
<td align=\"center\" >
<input class=\"color\" name=\"ct_param[$line_number][$parameter_no]\" type=\"text\" size=\"$box_size\" value=\"$line[$parameter_no]\" onChange=\"checkParameter(this, $parameter_no)\" >
</td>";
$parameter_no++;
}
/* Add Commands and Side Line Comment Boxes */
$output.="
<td align=\"center\">
<input class=\"color\" type=\"text\" name=\"commands[$line_number]\" value=\"$command_text\" onChange=\"NoEmpty(this, 'Commands')\">
</td>
<td align=\"center\">
<input class=\"color\" type=\"text\" name=\"side_line_comments[$line_number]\" value=\"$side_line_comments[0]\">
</td>
</tr>";
} // end of check for blank line
$line_number++;
} //end of parse loop
if (!$param_headings_printed) {
/* If no commands in file, print out Top Comments into a Text Area as would not have
previously printed */
$output.=tabTopComments($top_line_comments, $number_of_top_comments);
$param_headings_printed=true; //print headings only once
}
/* Add 5 additional lines for new commands. Can do 5 at a time. */
$max_lines=$line_number+5; //defines line number of last additional command input
$output.="
<tr>
<td align=\"center\" style=$edit_table_title colspan=\"7\">
Add Commands (up to 5 at a time):
</td>
</tr>
<tr>
";
while($line_number<$max_lines) {
$parameter_no=0;
while ($parameter_no<5){
$box_size=4;
$output.= "
<td align=\"center\" >
<input class=\"color\" name=\"ct_param[$line_number][$parameter_no]\" type=\"text\" size=\"$box_size\" value=\"$line[$parameter_no]\" onChange=\"checkParameter(this, $parameter_no)\" >
</td>
";
$parameter_no++;
}
$output.="
<td align=\"center\">
<input class=\"color\" type=\"text\" name=\"commands[$line_number]\" onChange=\"NoEmpty(this, 'Commands')\">
</td>
<td align=\"center\">
<input class=\"color\" type=\"text\" name=\"side_line_comments[$line_number]\">
</td>
</tr>
<tr>
";
$line_number++;
}
/* Bottom Comments */
$output.="
<td align=\"center\" colspan=\"7\" style=$edit_table_title>Bottom Comments:</td></tr>
<tr>
<td colspan=\"7\" align=\"center\">
<textarea name=\"bottom_line_comments\" cols=\"80\" rows=\"$number_of_bottom_comments\">$bottom_line_comments
</textarea>
</td>
</tr>
<!--*************** End Schedule Programs Section of Table (edit phpcrontab info ) *********-->
<tr>
<td style=$edit_table_title_no_border colspan=7>
<!--******* FORM SUBMITS*********-->
";
if ($create_tab) {
if (!$secure) {
$output.="
File: <em>New PHPCRONTAB File </em><br>
<input type=\"submit\" value=\"Save As:\">
<input class=\"color\" type=\"text\" name=\"new_tabfilename\">" ;
}
$output.="
<br>
Check to Save Over Existing File:
<input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\">
<input type=\"hidden\" name=\"max_line_number\" value=\"$line_number\">
<input type=\"hidden\" name=\"current_tabfilename\" value=\"$phpcrontab_filename\">
</form>
</td>
</tr>
<tr>
<td style=$edit_table_title_no_border colspan=7>
";
} else {
$output.="
<HR>
<input type=\"submit\" value=\"Save\">";
if (!$secure) {
$output.= "
<input type=\"submit\" value=\"Save As:\">
<input class=\"color\" type=\"text\" name=\"new_tabfilename\">";
}
$output.="
<br>
Check to Save Over Existing File:
<input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\">
<input type=\"hidden\" value=\"$line_number\" name=\"max_line_number\">
<input type=\"hidden\" name=\"current_tabfilename\" value=\"$phpcrontab_filename\">
</form>
</td>
</tr>
<tr>
<td border=0 style=$edit_table_title_no_border colspan=7>
";
/* This allows another file to be opened - commenting this out because I changed my mind.
Think its better for a crontab file to be opened by changing user configuration file.
But if you want to use this feature it is implemented, just uncomment.
<form action=\"$PHP_SELF\" method=\"get\">
<input type=\"submit\" value=\"Open:\">
<input class=\"color\" type=\"text\" name=\"new_tabfilename\">
<input type=\"hidden\" value=\"Edit_Tab_By_Form\" name=\"admin_subpage\">
</form>
*/
$output.="
<form action=\"$PHP_SELF\" method=\"get\">
<input type=\"submit\" value=\"Create New PHPCRONTAB File\">
<input type=\"hidden\" value=\"Edit_Tab_By_Form\" name=\"admin_subpage\">
<input type=\"hidden\" value=\"true\" name=\"create_tab\">
</form>
</td>
</tr>
<tr>
<td border=0 style=$edit_table_title_no_border colspan=7>
";
}
$output.="
<HR>
File: <em>$crontab_stripped</em>
</td>
</tr>
</table>
<br>
<!--*******END FORM SUBMITS *********-->";
if ($new_tabfilename) {
if($path_errors=isPathBad($new_tabfilename, true)) {
while ( list($file_or_dir, $error_messages) = each($path_errors)) {
while (list($each_message) = each($error_messages)) {
$error_messages.=$path_errors[$file_or_dir][$each_message];
}
}
}
else {
$phpcrontab_filename=$new_tabfilename;
}
}
if($error_messages) {echoErrorMessages($error_messages);};
echo $output;
} //end of function
|
string $filename - string containing filename of phpcrontab.conf string $box_title - string containing title of the edit box |
function fullEditBox($file_name, $box_title){
global $admin_subpage;
global $PHP_SELF;
global $modified_contents;
global $mc_rows;
global $fe_save_error;
global $full_edit_title;
global $secure;
if($path_errors=isPathbad($file_name, true, true)) {
while ( list($file_or_dir, $error_string) = each($path_errors)) {
while (list($each_message) = each($error_string)) {
$error_messages.=$path_errors[$file_or_dir][$each_message];
}
}
$error_messages="<h3>Cannot Edit $file_name because of file errors:<br></h3>".$error_messages;
//if path errors, echo message and retur
if (!is_readable($file_name)){
echoErrorMessages($error_messages);
echo $output;
return;
}
}
//Empty file into array
$file_array=file($file_name);
if ($fe_save_error) { //if previously bad save, display modified contents that weren't saved
$file_string=$modified_contents;
} else {
//Implode file_array to put string in text area element
$file_string=addslashes(trim(implode("",$file_array)));
//Set number of rows
if ($file_array) {
$total_lines=count($file_array);
}
$mc_rows=$total_lines+10;
}
//Build output
$output="
<!--*********** Begin Full Edit Box For $file_name************-->
<br>
<table border=\"1\" cellpadding=\"2\" width=\"600px\" cellspacing=\"0\" align=\"center\">
<tr>
<td align=center style=$full_edit_title colspan=7 >
<h3>
$box_title
<br><br>
(edit ".chunk_split(formatPath($file_name), 20, " ").")
<br>
</h3>
</td>
</tr>
<tr>
<td style=$full_edit_title>
<form action=\"$PHP_SELF\" method=\"post\">
<div align=\"center\">
<textarea name=\"modified_contents\" wrap=\"off\" cols=\"80\" rows=\"$mc_rows\"
class=\"fulledit\">".stripslashes($file_string)."
</textarea>
</div>
<HR>
<input type=\"submit\" value=\"Save\">";
if (!$secure) {
$output.= "<input type=\"submit\" value=\"Save As:\">
<input type=\"text\" class=\"color\" name=\"new_filename\">";
}
$output.=" <br>
Check to Save Over Existing File:
<input type=\"checkbox\" name=\"overwrite\" value=\"true\" class=\"title\">
<input type=\"hidden\" class=\"color\" name=\"current_filename\" value=\"$file_name\">
<input type=\"hidden\" name=\"admin_subpage\" value=\"$admin_subpage\">
<input type=\"hidden\" name=\"mc_rows\" value=\"$mc_rows\">
</form>
<form action=\"$PHP_SELF\" method=\"post\">
<input type=\"submit\" value=\"Reload Current File\">
<input type=\"hidden\" name=\"admin_subpage\" value=\"$admin_subpage\">
</form>
<HR>
Current File: ".formatPath($file_name)."
</td>
</tr>
</table>
<br>
<!--*********** End Full Edit Box For $file_name*************-->
";
if($error_messages) {
echoErrorMessages($error_messages);
}
echo $output;
}
|
Used in parsing phpcron_userconfig.php. Determines the variable, value and type of a quoted variable assignment, |
array $uc_contents_array[$horiz_pos]["executable"] A 2 dimensional array which contains the variable assignment strings derived from the phpcron_userconfig.php |
Returns false if a string in the array is not a variable assignment or, if successful, a three dimensional array containing variable name, value, and type for each assignment in the $uc_contents_array: $return_value[$horiz_pos][$i]["variable"], $return_value[$horiz_pos],[$i]["type"], $return_value[$horiz_pos],[$i]["type"] This information is assigned to $assignment_info in cpPhpcron. |
function getAssignmentInfo ($uc_contents_array){
/*Returns variable, value and type of quoted assignment (i.e., when $assignment is a
variable assignment like "a=3;" */
global $user_config_file;
global $uc_contents_length;
include("$user_config_file");
$horiz_pos=0;
while($horiz_pos<$uc_contents_length) {
if($uc_contents_array[$horiz_pos]["executable"]) {
$executable_string.= stripPhp($uc_contents_array[$horiz_pos]["executable"]);
}
$horiz_pos++;
}
/* Join Executable Strings and Test for syntax errors (if there are anything but
assignments, testedby comparing number of = with number of ; */
if(preg_match_all("/;/", $executable_string, $semi_matches) <> preg_match_all("/=/",$executable_string,$equal_matches)) {
return false; //syntax error in string - nunmber of assignments do not equal number of statements;
}
/* Cycle through array containing executable strings, explode and create 3 arrays containing
variable, value and type */
$horiz_pos=0;
while($horiz_pos<$uc_contents_length) {
//if this element is empty then skip the loop
if(!$uc_contents_array[$horiz_pos]["executable"]) {
$horiz_pos++;
continue;
} //end of if
//strip html tags
$uc_contents_array[$horiz_pos]["executable"]=trim(strip_tags($uc_contents_array[$horiz_pos]["executable"]));
/* Turn uc_contents_array element into separate assignment strings */
//break assignment_string into an array of separate assignments
if(!$assignment_array[$horiz_pos]=explode(";",$uc_contents_array[$horiz_pos]["executable"])) {
return false; // error if no semi-colon in string
}
/* Run through assignment array and break into variable, values, and type */
$i=0;
while($assignment_array[$horiz_pos][$i]) {
//assign variable to 0 and $value to 1; return if
if(!$temp=explode("=",$assignment_array[$horiz_pos][$i])) {
return false; //returns false if this string does not contain an assignment
}
$return_value[$horiz_pos][$i]["variable"]=$temp[0];
$return_value[$horiz_pos][$i]["value"]=$temp[1];
//maintain quotes for type testing
$test_string=trim(stripslashes($return_value[$horiz_pos][$i]["value"]));
//strip slashes, trim, and get rid of quotes
$value=trim(preg_replace("/\"/","",stripslashes($return_value[$horiz_pos][$i]["value"])));
/*Derive Types*/
if(preg_match("/^[0-9]*$/", $test_string)) {
$return_value[$horiz_pos][$i]["type"]="integer";
} elseif ($return_value[$horiz_pos][$i]["value"]=="true" or $value =="false") {
$return_value[$horiz_pos][$i]["type"]="boolean";
}elseif (preg_match("/^\".*\"$/", $test_string)){
$return_value[$horiz_pos][$i]["type"]="string";
} else {
echoErrorMessages("Error: A type could not be determined for variable
$return_value[$horiz_pos][$i][$variable] - Check Syntax in User Configuration File $user_config_file. Only variable
assignments of type String (surrounded by double quotes only), Integers, and Booleans are
supported in that file.");
return false;
}
$i++;
} //end of inside while
$horiz_pos++;
} //end of outside while
/*Returns 3 array string containing variable name, value,
and type for each assignment statement */
return $return_value;
}
|
array getComments (string $big_string, string $left_char,
string $right_char, string $current_pos)
|
Starting with the $current_pos position in $big_string, extracts from $big_string, a php comment that begins with $left_char and ends with $right_char or the beginning of a php block. Used when parsing the phpcron_userconfig.php |
$big_string - string containing contents of phpcron_userconfig.php
$left_char - the beginning character of the comment
$right_char - the ending character of the comment
$current_pos - the current position of the parser in $big_string, getComments
will search from this position forward
|
Returns an array containing as the first element, the comment string, and the second element the position after the comment in the $big_string. contents are valid. |
function getComments($bigstring, $left_char, $right_char, $current_pos) {
//gets substring which is delimited by left_char and right_char, starting from $current_pos
global $uc_contents_length;
$end_of_string= substr($bigstring, $current_pos); //get rest of string from current position to end
if(strstr($end_of_string, $right_char)) {
if ($right_char=="\n") { //if this is a single line comment
//position of ending comment not including ending character
$last_pos=strpos($bigstring, $right_char, $current_pos);
} else {
//position of ending comment including ending character
$last_pos=strpos($bigstring, $right_char, $current_pos)+strlen($right_char);
}
$substring= substr($bigstring, $current_pos, $last_pos-$current_pos); //get substring to end
} elseif (strstr($end_of_string, "?>")) {
// position of end of php block - but don't include end
$last_pos=strpos($bigstring, "?>", $current_pos)-1;
//get to end of php block
$substring= substr($bigstring, $current_pos, $last_pos-$current_pos);
} else { //otherwise, return end of string
$last_pos=$uc_contents_length;
$substring=$end_of_string;
}
$current_pos=$last_pos;
$current_pos=$last_pos; //update current position
$return_value = array ($substring, $current_pos);//return substring and current position
return $return_value;
}
|
string getFormElement (string $variable, string $value, string $type,
int horiz_pos, int $variable_index)
|
Constructs a string containing HTML comprising an appropriate form element to pass a value appropriate for $variable. For instance, if the variable is a boolean variable, a true/false radio button will be constructed, if a string, a text box. Used to construct the control panel. |
$variable - the string containing the name of the variable being analyzed
(extracted from the phpuserconfig.php)
$value - a string containing the name of the value
$type - a string conaining the name of the variable type (e.g., boolean,
string, etc)
$horiz_pos - the horizontal position where the parser is at in
parsing the contents of phpuserconfig.php
$variable_index - a number used as the second index of the three dimensional
array which holds the assignment info See cpPhpcron
|
Returns a string containing an appropriate HTML form element for the assignment type. For instance, if the variable is a boolean variable, a true/false radio button will be constructed, if a string, a text box. Used to construct the control panel. |
function getFormElement($variable, $value, $type, $horiz_pos, $variable_index) {
$value=trim(preg_replace("/\"/","",stripslashes($value))); //strip slashes, trim, and get rid of quotes
$box_size=strlen($value);
if($box_size > 40) {
$box_size=40; //size of text box
}
switch ($type) {
case "integer":
return "<input type=\"text\" class=\"color\" name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"$value\" size=\"$box_size\" onChange=\"isNumber(this)\">";
break;
case "boolean":
if($value=="true") {
return "
<input type=\"radio\" checked name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"true\">On
<input type=\"radio\" name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"false\">Off";
} else {
return "
<input type=\"radio\" name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"true\">On
<input type=\"radio\" checked name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"false\">Off";
}
break;
case "string":
return "
<input type=\"text\" class=\"color\" name=\"assignment_info[$horiz_pos][$variable_index][value]\" value=\"$value\" size=\"$box_size\">";
break;
default:
echoErrorMessages("Error: No Form Found for This Variable $variable- Check Syntax in User Configuration File. Only String, Integers, and
Booleans are supported.");
return false;
}
}
|
A 2 dimensional array constructed of the following:
$uc_contents_array[$horiz_pos]["executable"]
- the non-comment portions of phpcron_userconfig.php
$uc_contents_array[$horiz_pos]["ml_comments"]
- the multi-line comment portions of phpcron_userconfig.php
$uc_contents_array[$horiz_pos]["sl_comments"]
- the single line comment portions of phpcron_userconfig.php
|
A three dimensional array containing variable name, value, and type for each assignment in the $uc_contents_array: $assignment_info[$horiz_pos][$i]["variable"], $assignment_info[$horiz_pos],[$i]["type"], $assignment_info[$horiz_pos],[$i]["type"] cpPhpcron assigns gets this information from a call to getAssignmentInfo in cpPhpcron. |
array parseUserConfig(string $user_config_file, string $left_mlc_ch,
string $right_mlc_ch, string $sc_ch)
|
Parses the user configuration file $user_config_file, extracting single line comments,multi-line comments, and command portions of $user_config_file |
$user_config_file - the filename of the phpcron_userconfig.php
$left_mlc_ch - the characters which mark the beginning of a mult-line
comment
$right_mlc_ch - the characters which mark the end of a mult-line
comment
$sc_ch - the characters which mark the beginning of a single-line character
|
Returns an array containing as its first element $uc_contents, a string containing the contents of $user_config_file file and, as its second element, $uc_contents_array, a 2 dimensional array which contains the contents of the phpcron_userconfig.php |
function parseUserConfig($user_config_file, $left_mlc_ch, $right_mlc_ch, $sc_ch) {
/* parse the userconfig file named in $file to separate out mult-line comments surrounded
by $mlc_left_char and $mlc_right_char and single line comments begun with slc_ch */
global $uc_contents;
global $uc_contents_length;
$current_pos=0;
$horiz_pos=0;
while ($current_pos<$uc_contents_length){
$current_char=substr($uc_contents,$current_pos,strlen($left_mlc_ch));
//if character is a multi-line comment then find to end character of multi-line comment
if ($current_char==$left_mlc_ch) {
if($uc_contents_array[$horiz_pos]["executable"]) {$horiz_pos++;}
list($uc_contents_array[$horiz_pos]["ml_comments"], $current_pos)=getComments($uc_contents, $left_mlc_ch,$right_mlc_ch, $current_pos);
$horiz_pos++;
} elseif($current_char==$sc_ch){
//increment position for executable
if($uc_contents_array[$horiz_pos]["executable"]) {$horiz_pos++;}
list($uc_contents_array[$horiz_pos]["sl_comments"], $current_pos)=getComments($uc_contents, $sc_ch,"\n", $current_pos);
$horiz_pos++;
} else {
$uc_contents_array[$horiz_pos]["executable"]=stripPhp($uc_contents_array[$horiz_pos]["executable"].substr($current_char,0,1)); //after comments are stripped out, assign all else to this
}
$current_pos++;
}
$return_value=array ($uc_contents, $uc_contents_array);
return $return_value;
}
|
Rebuilds the new phpcron_userconfig.php to be saved given the information submitted by the control panel form. |
$assignment_info - a three dimensional array containing the data submitted
by the control panel form
$uc_contents_array - a 2 dimensional array containing the current contents of the
phpcron_userconfig.php such that:
$uc_contents_array
|
A string containing the new contents of the phpcron_userconfig.php after editing by the control panel form. This string is meant to be saved as the new phpcron_userconfig file. |
function rebuildUserCfg($assignment_info, $uc_contents_array) { //Print out Contents of File in Order
/* This function rebuilds the user_config_file using the new information from $assignment_info
submitted by the user. */
global $uc_contents_length;
$horiz_pos=0;
while($horiz_pos<$uc_contents_length) {
$i=0;
while($assignment_info[$horiz_pos][$i]["variable"] ) {
if ($assignment_info[$horiz_pos][$i]["type"]=="string") { //add quotes for a string
$assignment_info[$horiz_pos][$i]["value"]="\"".$assignment_info[$horiz_pos][$i]["value"]."\"";
}
if($i==0) {
/* After first time add additional elements (don't replace - otherwise won't get
additional assignments on same line) */
$uc_contents_array[$horiz_pos]["executable"]=$assignment_info[$horiz_pos][$i]["variable"].
"=".$assignment_info[$horiz_pos][$i]["value"].";";
}else {
$uc_contents_array[$horiz_pos]["executable"].=$assignment_info[$horiz_pos][$i]["variable"].
"=".$assignment_info[$horiz_pos][$i]["value"].";";
}
/* For Debugging:
echo "Horiz Pos: $horiz_pos Index: $i<br>";
echo "Assignment Info Variable:".$assignment_info[$horiz_pos][$i]["variable"]."<br>";
echo "Contents:".$uc_contents_array[$horiz_pos]["executable"]."<br>";
echo "SL Comments:".$uc_contents_array[$horiz_pos]["sl_comments"]."<br>";
echo "ML Comments:".$uc_contents_array[$horiz_pos]["ml_comments"]."<br>";
*/
$i++;
}
if($uc_contents_array[$horiz_pos+1]["sl_comments"]) {
$plus1=$horiz_pos+1;
/*For Debugging
echo "Exec Contents $horiz_pos:".$uc_contents_array[$horiz_pos]["executable"]."<br>";
echo "Exec Contents:".$plus1.$uc_contents_array[$horiz_pos+1]["executable"]."<br>";
echo "sl comments again:".$plus1.$uc_contents_array[$horiz_pos+1]["sl_comments"];
*/
/*only add tab if there are commands on same line (the executable element
holds a word character)*/
if (preg_match("/\w/",$uc_contents_array[$horiz_pos]["executable"])){
$uc_contents_array[$horiz_pos+1]["sl_comments"]="\t".$uc_contents_array[$horiz_pos+1]["sl_comments"]."\n";
} else {
$uc_contents_array[$horiz_pos+1]["sl_comments"]=$uc_contents_array[$horiz_pos+1]["sl_comments"]."\n";
}
}
if($uc_contents_array[$horiz_pos]["ml_comments"]) {
$uc_contents_array[$horiz_pos]["ml_comments"]=$uc_contents_array[$horiz_pos]["ml_comments"]."\n";
}
$new_file_contents.=$uc_contents_array[$horiz_pos]["sl_comments"].$uc_contents_array[$horiz_pos]["ml_comments"].$uc_contents_array[$horiz_pos]["executable"];
$horiz_pos++;
}
$new_file_contents="\r\n<?php\r\n\r\n".trim(stripslashes($new_file_contents))."\r\n\r\n?>"; //add php tags
return $new_file_contents;
}
|
function stripPhp($phpstring) {
$phpstring=preg_replace("/(<\?php)|(\?>)/","",$phpstring);
return $phpstring;
}
|
Creates a row of a table containing a textarea containing the top comments of the phpcrontab.conf. Comprises a part of the form which edits the phpcrontab.conf file. |
$top_line_comments - a string created in editTabByForm containing all of the comments at the top of the phpcrontab.conf file $number_of_top_comments - number of lines of top comments in phpcrontab.conf |
A string containing the HTML for producing the table row containing the textarea holding the top comments of phpcrontab.conf |
function tabTopComments($top_line_comments, $number_of_top_comments) {
global $edit_table_title;
return " <tr>
<td align=\"center\" colspan=\"7\">
<textarea name=\"top_line_comments\" cols=\"80\" wrap=\"off\" rows=\"$number_of_top_comments\">$top_line_comments
</textarea>
</td>
</tr>
<tr align=\"center\" style=$edit_table_title>
<td style=$edit_table_title>
Min<br>(0-59)
</td>
<td style=$edit_table_title>
Hour<br>(0-23)
</td>
<td style=$edit_table_title>
Month<br>Day<br>(1-31)
</td>
<td style=$edit_table_title>
Month<br>(1-12)
</td>
<td style=$edit_table_title>
Week<br>Day<br>(0-6)
</td>
<td style=$edit_table_title>
Commands
</td>
<td style=$edit_table_title>
Comments
</td>
</tr>
<tr>
";
}
|
Generated from phpcron_commonlib.php with ROBODoc v3.2.3 on Wed Oct 24 21:26:43 2001
This is a collection of functions used by both phpcron.php and phpcron_admin.php. |
COPYRIGHT 2001 (C) David C. Druffner ddruff@gemini1consulting.com This script is released under a modified BSD License. See php phpcron.php -license and LICENSE.txt in download package for full license details |
Bugs can be reported via the online manual: http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ |
This is a collection of functions used by both phpcron.php and phpcron_admin.php. The current manual for Phpcron and Phpcron Admin is located at http://www.gemini1consulting.com/tekhelp/online_manuals/phpcron/ The Home Page is: http://phpcron.sourceforge.net/ Download from the Source Forge Project Page: http://www.sourceforge.net/projects/phpcron/ In-Line Documentation: A slightly modified version of ROBODOC is used to generate documentation for this code. I have modified the headers.c file in the Robodoc source code to et the variable header_markers to equal only /*ROBODOC* as the start of a header marker - this avoids confusion with other strings and comments in PHP code. Robodoc is available at http://www.xs4all.nl/~rfsber/Robo/robodoc.html |
Variable containing text of license / license=" hpcron, Phpcron Admin, and all associated and packaged scripts carry the ollowing license: OPYRIGHT (C) 2001 David Druffner druff@gemini1consulting.com edistribution and use in source and binary forms, with or without odification, are permitted provided that the following conditions are met: 1.Redistributions of source code must retain the above copyright notice, this ist of conditions and the following disclaimer. 2.Redistributions in binary form must reproduce the above copyright notice, his list of conditions and the following disclaimer in the documentation nd/or other materials provided with the distribution. 3.The name of the author may not be used to endorse or promote products erived from this software without specific prior written permission. HIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED ARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO VENT SHALL THE AUTHOR, ANY DISTRIBUTOR, OR ANY DOWNLOAD HOSTING COMPANY BE IABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF UBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS NTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE OSSIBILITY OF SUCH DAMAGE. ; ROBODOC_END*/ |
Variable containing path and filename of file containing information for the process running the phpcron.php script. |
If this file exists, then phpcron.php in non-daemon mode will run the scheduled commands in phpcrontab.conf |
$phpcron_psinfo_file - path and filename of file the existence of which causes phpcron.php to shut down OBODOC_END*/ phpcron_off=$phpcron_directory."phpcron_off"; *ROBODOC*d phpcron_commonlib/MS_WINDOWS |
True if script is read by browser, false if executed on the command line. Set automatically by script on each execution by reading whether $SERVER_PROTOCOL or $HTTP_USER_AGENT is set. |
I'm sure this won't work in all cases, but was the best solution I could come up with. Some web servers might not give out these variables and the script would interpret that to mean that it was being executed on the command line. The main result of this in phpcron.php is that the HTML tags would be stripped from all output (probably leading to a blank screen)and a built-in safeguard against going into daemon mode would be disabled (but there are other safeguards that should still prevent this). |
If phpcron.php is executed in a browser in daemon mode than an httpd process would be spawned that would only be able to be killed by root (or by a self-kill if it detects a phpcron_off file in existence). This is a BAD THING as it could lead to server overload. Thus the daemon mode is shut off if a browser is detected. In addition, phpcron.php has certain self-checks to kill itself if there is another phpcron.php process running in daemon mode. See the function isOtherPhpcrond. |
if ($SERVER_PROTOCOL or $HTTP_USER_AGENT) {
$viewed_by_browser=true;
$slow_debug_scroll=0;
} else {
$viewed_by_browser=false;
}
|
boolean checkPhpVersion(string $required_version, string $warning_string, boolean $quit) |
Verifies that the PHP version running on the Web Server is at least equal to the version required by the script. |
$a, $b, $c -strings containing minimum PHP version needed by the Script,
e.g., 3.0.0. would be 3,0,0
$warning_string -optional parameter to be output to the user if fails
version check
$quit - optional parameter which if true will force the
cript to end
|
function checkPhpVersion ($version_required, $warning_string="/", $quit=false) {
$version_installed=phpversion();
/*Break Up $version_required string by decimal point*/
$version_required=explode(".", $version_required);
if (!ereg( "[[$version_required[0]-9]\.[$version_required[1]-9]\.[$version_required[2]-9].*", $version_installed )){
if ($warning_string !="/") {
sendOutput($warning_string);
}
if ($quit) {
exit;
}
return false;
exit;
} else {
return true;
}
}
|
Handles all output for phpcron.php. If a command line suppression switch has been turned on, then the output is not echoed, unless the $suppress_override parameter is set to true (default is false) - usually done for critical errors. Also, if the $redirect_output flag is true, the output will not be echoed to the screen, but to the $redirect_file. If the output is being sent to the browser, the output is left alone, but if is being printed to the console as the output from a command line script, than all html is stripped. |
$output - string containing output being echoed $suppress_override - optional parameter, if set the echo will occur whether or not the global output suppression has been turned on (see $suppress_output) |
Relies on values in global variables $viewed_by_browser, $suppress_output, $redirect_output, and $redirect_file |
function sendOutput($output_message, $suppress_override=false) {
global $suppress_output;
global $viewed_by_browser;
global $redirect_output;
global $redirect_file;
if(!$suppress_output or $suppress_override) {
//display message
if (!$viewed_by_browser) {
$output_message=strip_tags($output_message);
}
if ($redirect_output) {
$save_results=appendToFile($output_message, $redirect_file);
if (!$save_results[0]) {
//echo error messages
echo "Error: Cannot Append to File $redirect_file.".
"Check filename and permissions.\r\n";
}
} else {
echo $output_message;
}
}
}
|
When called returns information for the process running the PHP script (Unix only). Relies on a ps ef system call. |
Returns a three element string array: $process_info["all"] - all the proces info returned by ps ef $process_info["id"] - gives the $pid of the process $process_info["owner"] - gives the owner of the process |
function getProcessInfo () {
//get process info of current process
global $pid;
//get owner of script process
if (!MS_WINDOWS) { //show pid info if not in windows
exec("ps hefp $pid u", $output, $return_value);
$output=implode(" ", $output);
// get owner of process and put in $matches[1];
preg_match("/(^[A-z0-9A-Z]*\b).*$/",$output,$matches);
$process_info["all"]=$matches[0];
$process_info["owner"]=$matches[1];
$process_info["id"]=$pid;
return $process_info;
}
//return nothing if windows/dos
}
|
boolean isPathbad(string $path_name, [boolean $check_filename, [$file_existing=false)]); |
Checks whether directory and/or filename exists and is readable/writeable (filename checked only if $check_filename is true, the default is false). Can be used both for dos and unix paths. |
$path_name - string containing path name. $check_filename - Optional boolean parameter. Default is false. If true, then will do check on filename as well as directory and will return an error message if no file name was include_onced in the path. $file_existing - optional boolean parameter (requires $check_filname to be set) that tells whether or not the file is existing. |
If there are errors in testing the path, it returns a double array
containing error messges in the format of $file_errors["dir"] and
$file_errors["file"]. If there are no errors, it returns false.
The double array can be extracted using the list command like this:
if($path_errors=isPathbad($path_name)){
while ( list($file_or_dir, $error_messages) = each($path_errors)) {
while (list($each_message) = each($error_messages)) {
echo $path_errors[$file_or_dir][$each_message]."<br>";
}
}
}
|
$path_errors=isPathBad("/test/test.txt", true);
if ($path_errors["directory"] or $path_errors["file"]["write"]) {
$output="Error: Cannot write to test/text.txt. The following errors were
encountered.:<br>\r\n";
while ( list($file_or_dir, $error_messages) = each($path_errors))
{
while (list($each_message) = each($error_messages))
{
$output.= $path_errors[$file_or_dir][$each_message]."<br>\r\n";
}
}
echo $output;
}
|
function isPathbad($path_name, $check_filename=false, $file_existing=false) {
$dir_name=dirname($path_name)."/";
$base_file_name=basename($path_name);
$basename_stripped=formatPath($base_file_name);
$dir_stripped=formatPath($dir_name);
$pathname_stripped=formatPath($path_name);
//Check Directory
if(!file_exists($dir_name)){
$path_errors["directory"]["exist"]="Error: Directory $dir_stripped does not exist. Please Create.<br>";
}
elseif(!is_writeable($dir_name)){
$path_errors["directory"]["write"]="Error: Directory $dir_stripped cannot be written to. Check permissions.<br>";
}
elseif(!is_readable($dir_name)){
$path_errors["directory"]["read"]="Error: Directory $dir_stripped cannot be read from. Check permissions.<br>";
}
//Check File Name
if ($check_filename and !$base_file_name) { //if file name is required but not suppplied, print error
$path_errors["file"]["empty"]="Error: $pathname_stripped is an invalid path. No file name was supplied.<br>";
}
if ($check_filename and $base_file_name) {
//check filename format
if((MS_WINDOWS and !preg_match("/^[-\.a-zA-Z0-9\s_\^\$~!#&\}\{\(\)@'`]+?$/",$base_file_name))or (!MS_WINDOWS and !preg_match("/^.[^\*\?&`'\"\/\>\)\(\]\[\<(\)]+?$/",$base_file_name))) { //check for proper characters in names
$path_errors["file"]["name"] ="\tError: File $pathname_stripped contains invalid characters in file name.\r\n<br>";
}
if ($file_existing) {
if(!file_exists($path_name)){
$path_errors["file"]["exist"]="Error: File $pathname_stripped does not exist.<br>";
} elseif(!is_file($path_name)){
$path_errors["file"]["regular"]="Error: Invalid filename. $basename_stripped is a directory.<br>";
} elseif(!is_writeable($path_name)){
$path_errors["file"]["write"]="Error: File $pathname_stripped cannot be written to. Check permissions on file.<br>";
} elseif(!is_readable($path_name)){
$path_errors["file"]["read"]="Error: File $pathname_stripped is not readable. Check permissions.<br>";
}
}
}
return $path_errors;
}
|
Takes a string containing a path name and makes it conform to the operating specific path format for readability, e.g, for dos "c:/test/test.txt" -> "c:\test\test.txt". This is meant to be used as a filter before the string is output to the screen so it becomes "human readable". This function assumes that the path name is in unix format to begin with, so if used under a unix OS the string returned for "c/test/test.txt" would be the same as the input. In addition, this function also adds the current directory to any path that lacks an absolutte directory, e.g,"test.txt" would become /home/httpd/html/test.txt if the script was being executed in /home/httpd/html/. |
Used as a cross-OS function to format the path name before it is echoed to the user. No matter what the Operating System, the path will be readable to the user when it is echoed to the screen. |
CURRENT_DIRECTORY is a constant which must be defined in the calling script as follows: define ("CURRENT_DIRECTORY",realpath(dirname(__FILE__))); |
function formatPath($path_name) {
//Note for this to work you must define CURRENT_DIRECTORY as follows in main script:
//define ("CURRENT_DIRECTORY",realpath(dirname(__FILE__)));
/* Give a Directory Name if using same directory of script and none is otherwise specified*/
if (dirname($path_name)==".") {
$path_name=CURRENT_DIRECTORY."/".basename($path_name);
}
if(MS_WINDOWS) {
$path_name=stripslashes($path_name);
$path_name=preg_replace("/\//","\\",$path_name); //get rid of any forward slashes
}
return $path_name;
}
|
None known, but since domain formats are constantly changing, there may be some obscure domains that this function will see as incorrect emails and not accept. |
function is_email($email_address) {
if(!preg_match("/[\w\-][^@]+\@[\w\-][^@]+\.[\w\-][^@]+/",$email_address)) {
return false;
} else {
return true;
}
}
|
Appends $new_file_contents to file named by $file_name, if $file_name does not exist, it will be created. |
$new_file_contents - string containing text to be added to file $file_name - path and filename of file to be appended to |
Returns a string array containing error messages; the first element of the array contains a success message, if it was unsuccessful, the first element is empty (false) and the remaining elements (1-last) contain error messages. |
Example 1 - Short form:
$append_results=appendToFile($clear_message,$log_result_file);
$append_results[0]=""; //does not echo success message, but you could
if(trim($append_results)) {
$error_messages.=implode(" ",$append_results);
echo $error_messages;
}
Example 2 - Long form:
$append_results=appendToFile($contents, $filename);
if($append_results[0]) { //this would be successful save
//this collects the success message
$error_messages.=$append_results[0];
} else { //append so collect error messages in elements 1 - last
$index=1;
while($append_results[$index]) {
$error_messages.=$append_results[$index];
$index++;
}
}
echo $error_messages;
|
Relies on these other functions: /phpcron_commonlib/formatPath /phpcron_commonlib/isPathbad |
function appendToFile($new_file_contents, $file_name) {
if(!trim($file_name)) {
$save_results[1]="Error: No File Name Given";
return $save_results;
}
$filename_stripped=formatPath($file_name);
$path_errors=isPathbad($file_name, true, true);
//check if directory is valid and file name is legal
if (!$path_errors["directory"] and !$path_errors["file"]["name"]) {
/* Open for reading and writing, place file pointer at end of file (append)
, if does not exist attempt to create it */
$fp = fopen( $file_name,"a+");
if (!$fp) {
$open_error="Error: File $filename_stripped Cannot Be opened. Check Permissions.<br>\n";
} else {
fwrite($fp,$new_file_contents);
fclose ($fp);
$save_results[0]="<strong>File $filename_stripped has been successfully saved.<strong><br>";
}
} else {
$i=1;
$save_results[1]="Error: Cannot save file $filename_stripped.<br>";
while ( list($file_or_dir, $error_messages) = each($path_errors)) {
while (list($each_message) = each($error_messages)) {
$save_results[$i].= $path_errors[$file_or_dir][$each_message];
$i++;
}
}
}
if ($open_error) {
$save_results[$i]=$open_error;
}
return $save_results;
}
|
Saves $file_contents to file named by $file_name. If $file_name already exists it will be overwritten, if not, it will be created. |
$file_contents - string containing text to be saved $file_name - path and filename of file to be saved |
Returns a string array containing error messages; the first element of the array contains a success message (or false if it failed). If it was unsuccessful, the remaining elements (1-last) contain error messages. |
Example 1 - Short form:
$save_results=saveFile($clear_message,$log_result_file);
$save_results[0]=""; //does not echo success message, but you could
if(trim($save_results)) {
$error_messages.=implode(" ",$save_results);
echo $error_messages;
}
Example 2 - Long form:
$save_results=saveFile($contents, $filename);
if($save_results[0]) { //this would be successful save
//this collects the success message
$error_messages.=$save_results[0];
} else { //save so collect error messages in elements 1 - last
$index=1;
while($save_results[$index]) {
$error_messages.=$save_results[$index];
$index++;
}
}
echo $error_messages;
NOTES:
This is essentially the same as the appendToFile function, but the pointer is
at the beginning, not the end of the file. It relies on these other
functions:
formatPath
isPathbad
|
function saveFile($new_file_contents, $file_name) {
/* Save File over file_name (overwrites);
returns an array of $save_results; $save_results[0] is true on success, false on failure
and failure messages are in remaining elements of array */
$new_file_contents=trim(stripslashes($new_file_contents)); //strip slashes from paths
$filename_stripped=formatPath($file_name);
$path_errors=isPathbad($file_name, true, false);
if (!isset($path_errors)) { //check if directory is valid and file name is legal
$fp = @fopen( $file_name,"w"); //open for writing, place file pointer at beginning of file, if does not exist attempt to create it
if (!$fp) {
$open_error="Error: File $filename_stripped Cannot Be opened. Check Permissions.<br>\n";
} else {
fwrite($fp,$new_file_contents);
fclose ($fp);
$save_results[0]="<strong>File $filename_stripped has been successfully saved.<strong><br>";
}
$i=1;
} else {
$i=2;
$save_results[1]="Error: Cannot save file $filename_stripped.<br>";
while ( list($file_or_dir, $error_message) = each($path_errors)) {
while (list($each_message) = each($error_message)) {
$save_results[$i].= $path_errors[$file_or_dir][$each_message];
$i++;
}
}
}
if ($open_error) {
$save_results[$i]=$open_error;
}
return $save_results;
}
|
Must define MS_WINDOWS constant like so in the calling script:
if(preg_match("/WIN/", PHP_OS)) {
define("MS_WINDOWS",true);
} else {
define("MS_WINDOWS",false);
}
|
function deleteFile($file_name) {
if (!file_exists($file_name)) {
return true; //if file doesn't exist than don't worry about it
}
clearstatcache(); //clear cache since will be checking same file again
$path_errors=isPathBad($file_name, true, true);
if ( !$path_errors["directory"]["write"] and !$path_errors["file"]) {
if(MS_WINDOWS) {
$file_name=formatPath($file_name);
exec("del $file_name");
} else {
unlink($file_name);
}
return true;
} else {
return false; //return false if errors - can't write to path
}
}
|
function isInteger ($integer_string) {
/* It's false if the string is null */
if (!isset($integer_string)) {
return false;
}
$i=0;
$length=strlen($integer_string);
while($i<$length) {
$ch=substr($integer_string,$i,1);
if (ord($ch) < 48 or ord($ch) > 57) { //this tests 0 through 9
return false;
}
$i++;
}
return true;
}
|
Checks whether $integer_string contains an integer equal to or between the values of $low and $high. |
$integer_string - string to be tested $low - integer at low end of range $high - integer at high end of range |
Returns true if tested string is outside of the $low and $high range, false otherwise. Values that equal $low and $high will return true. |
function isIntegerInRange ($integer_string, $low, $high) {
/* range is inclusive, so includes high and low values*/
if (!isInteger($integer_string)) {
return false;
}
$myinteger=intval($integer_string);
if (($myinteger < $low) or ($myinteger > $high)) {
return false;
} else {
return true;
}
}
|
boolean mailAttachment( string $email_address, string $subject, string $body, string $attachment, string $mimetype) |
$email_address - the "To" email address $subject - Subject of email $body - message to be included in the body of the email $attachment - name of file to be attached $mimetype - mimetype of file to be encoded, e.g, "text/english" |
if($mailserver_error=mailAttachment
($admin_email_address, $subject, $body, $attachment, $mimetype)) {
$error_messages.="Error: Unable to Email Log File:<br>\r\n".
$mailserver_error;
} else { //it succeeded
$error_messages.="Emailed Log File to $admin_email_address";
}
echo $error_messages;
|
function mailAttachment( $email_address, $subject, $body, $attachment, $mimetype) {
$boundary = md5(uniqid(time()));
//MIME MUST be first character in headers - no spaces or carriage returns
$headers ="MIME-Version: 1.0
Content-type: multipart/mixed;boundary=\"$boundary\"
Multipart MIME message
\r\n";
$messagebody = "
--$boundary
Content-type: text/plain;charset=us-ascii
Content-transfer-encoding: 8bit
".$body
."\r\n";
$fp = fopen($attachment, "r");
$attached_file = fread($fp, filesize($attachment));
$attached_file = chunk_split(base64_encode($attached_file));
$file_name = basename($attachment);
$messagebody .= "
--$boundary
Content-type: ".$mimetype."; name=\"$file_name\"
Content-transfer-encoding: base64
Content-Disposition: attachment; filename=\"$file_name\"
".$attached_file
."
";
// End of mail
$messagebody .= "--$boundary--";
$mail_result=@mail($email_address, $subject, $messagebody, $headers);
if(!$mail_result) {
$error_message="Mail message could not be sent.\r\n<br>
Make sure you have a mail server installed and running.\r\n<br>";
return $error_message; //returns true if unable to mail
}
}
|
Does a triple check (unix) or single check (dos) to see if another phpcrond daemon is running. In unix and dos it checks to see if the phpcron_psinfo_file exists in the current directory of the script. Under unix,the function will also 1) check the /tmp directory since phpcrond will also generate a file there in unix if the directory exists and is writeable, and 2) grep the ps command to see if it can detect an instance of phpcron. |
It is vital that only one phpcrond daemon run at the same time - especially on a box that is being used by many users (e.g., a virtual hosting box). This function tries its best to detect whether such other instance is running. |
Since it relies on a specific use of the ps, the ps check may not work under some versions of Unix. |
function isOtherPhpcrond() {
/*Triple check done initially in phpcron.php to see if there is another instance running */
global $phpcron_psinfo_file;
$other_instance=false;
$temp_path="$TEMP_DIR/".basename($phpcron_psinfo_file);
if(file_exists($phpcron_psinfo_file)) {
//Check to see if another instance is running
deleteFile($phpcron_psinfo_file);
sleep(1); //wait for phpcron to create again if there is another instance
clearstatcache(); //clear cache since will be checking same file again
if (file_exists($phpcron_psinfo_file)) {
$other_instance=true;
}
}
if(is_writeable("$TEMP_DIR/") and file_exists("$TEMP_DIR/".basename($phpcron_psinfo_file))) {
//Check temp directory to see if a file ps info file is there
deleteFile($temp_path);
sleep(1); //wait for phpcron to create again if there is another instance
clearstatcache(); //clear cache since will be checking same file again
if (file_exists("$TEMP_DIR/".basename($phpcron_psinfo_file))) {
$other_instance=true;
}
}
//check in the tmp directory
exec("ps ef | grep '^*phpcron.php*daemon.*$'",$output,$result_code);
$number_of_instances=count($output);
if($number_of_instances>1) {
$other_instance=true;
}
return $other_instance;
}
|
Stops all Phpcron daemons that may be running. Does so by saving a "stop" file ($phpcron_off) in the phpcron directory and in the $TEMP_DIR which when detected by phpcron.php will stop that process. |
function stopOtherPhpcron(){
/* Stops all phpcron daemons gracefully. */
global $phpcron_off;
$save_errors=saveFile("PHPCRON Stopped",$phpcron_off);
$save_errors=implode("<br>",$save_errors);
// echo "<br>".$save_errors;
saveFile("PHPCRON Stopped","$TEMP_DIR/".basename($phpcron_off));
sleep (1); //wait for it to stop
return !isOtherPhpcrond(); //checks to see if any other phpcrond is still running and returns true/false
}
|
Parses phpcrontab parameter string (minute, hour, date of month, day of week in traditional unix crontab format) and returns true or false whether current time matches. Implements ranges and alternate values and you can mix and match. E.g., you can do this: 18,20-25,20 1-2 * * * |
function parseCronTimeParams($time_param_string) {
/* Parses phpcrontab parameter string (minute, hour, date of month, day of
week in traditional unix crontab format) and returns true or false whether
current time matches. Implements ranges and alternate values and you can mix
and match. E.g., you can do this: 18,20-25,20 1-2 * * * */
/*Separate string by spaces, if it does not equal 5 then can't parse */
if (count($tparams=explode(" ",$time_param_string)) <> 5) {
return false;
}
/* Get Current time in same format as $time_param_string */
$timestamp= trim(date("i H d m w"));
/*Put individual vales of time stamp into sequential array */
$timestamp=explode(" ",$timestamp);
/*Main Loop - Cycle through each time parameter and match
to actual time */
$i=0;
while (isset($tparams[$i])) {
/***********Check for Asterisk************/
if (preg_match("/^\*$/",$tparams[$i])) {
$i++;
continue 1; /*Go to Next Value*/
} elseif (preg_match("/^".$timestamp[$i]."$/",$tparams[$i])) {
/***********Check for Exact Match***********/
$i++;
continue 1; /*Go to Next Value*/
//a # or a range comma optional [repeat one or more times to end]
} elseif (preg_match("/^(([0-9]{1,2}|[0-9]{1,2}-[0-9]{1,2}),?)+$/",$tparams[$i])) {
/**********Check for Comma and Ranges (can be mixed)*************/
/*Separate Out Values Separated by Commas*/
$alternate_values=explode(",",$tparams[$i]);
$i_av=0;
/*Cycle through each value to compare with corresponding time unit*/
while (isset($alternate_values[$i_av])) {
/* Check for individual number match */
if ($alternate_values[$i_av]==$timestamp[$i]) {
/*Continue with outer while loop since we have a match
and try next value */
$i++;
continue 2;
}
/*Check if this alternate value is also a range*/
if (preg_match("/^([0-9]{1,2}-[0-9]{1,2})$/",$alternate_values[$i_av])) {
/*If so, check the range */
/*Separate Out Low and High of Range Separated by Hyphen*/
$range=explode("-",$alternate_values[$i_av]);
if (isIntegerInRange($timestamp[$i], $range[0], $range[1])) {
/* Continue with outer loop if it's within range */
$i++;
continue 2;
}
}
$i_av++; /*Increment $alternate_values[$i_av] */
}
return false; //if it makes it this far there has been no matches
} else {
/* If doesn't match any of the patterns it's non-conforming */
return false;
}
$i++; /* Increment tparams[$i] value */
}
return true;
}
|
Validates phpcrontab parameter string (minute, hour, date of month, day of week in traditional unix crontab format) and returns error messages (true) if string is bad or false if ok. |
string $time_param_string - a parameter string extracted from the
phpcrontab.conf file (e.g., * 2-4,7,12 * * 3)
int $command_number - line number in phpcrontrab.conf containing parameter
string
|
function isCronTimeParamsBad($time_param_string, $command_number) {
/*Separate string by spaces, if it does not equal 5 then can't parse */
if (count($tparams=explode(" ",trim($time_param_string))) <> 5) {
$error_messages.="Error in Command #$command_number: Parameter String Must Have 5 Parameters.<br>";
return $error_messages;
}
/* Set Correct high and low for each parameter */
$correct_range[0]["low"] = 0;
$correct_range[0]["high"] = 59;
$correct_range[0]["unit"] = "Minutes";
$correct_range[1]["low"] = 0;
$correct_range[1]["high"] = 23;
$correct_range[1]["unit"] = "Hour";
$correct_range[2]["low"] = 1;
$correct_range[2]["high"] = 31;
$correct_range[2]["unit"] = "Day of Month";
$correct_range[3]["low"] = 1;
$correct_range[3]["high"] =12;
$correct_range[3]["unit"] = "Month";
$correct_range[4]["low"] = 0;
$correct_range[4]["high"] = 6;
$correct_range[4]["unit"] = "Day of Week";
/*Main Loop - Cycle through each time parameter and validate*/
$i=0;
while (isset($tparams[$i])) {
/***********Check for Asterisk************/
if (preg_match("/^\*$/",$tparams[$i])) {
$i++;
continue 1; /*Go to Next Value*/
} elseif (preg_match("/^[0-9]+$/",trim($tparams[$i]))) {
/***********Check for Single Number***********/
if (isIntegerInRange($tparams[$i], $correct_range[$i]["low"], $correct_range[$i]["high"])) {
/* Continue with loop if it's within range */
$i++;
continue 1;
} else {
$error_messages.="Error in Command #$command_number: ".$tparams[$i]." is an incorrect value for ".$correct_range[$i]["unit"].", it must be between ".$correct_range[$i]["low"]." and ".$correct_range[$i]["high"].".<br>\r\n";
}
} elseif (preg_match("/^(([0-9]{1,2}|[0-9]{1,2}-[0-9]{1,2}),?)+$/",$tparams[$i])) {
/**********Check for Comma and Ranges (can be mixed)*************/
/*Separate Out Values Separated by Commas*/
$tparams[$i]=str_replace(",", " ", $tparams[$i]);
//$error_messages.="Parameter String: $tparams[$i]<br>";
$alternate_values=explode(" ",$tparams[$i]);
$i_av=0;
/*Cycle through each value to compare with corresponding time unit*/
while (isset($alternate_values[$i_av])) {
/*Check if it is a range */
if(preg_match("/^[0-9]{1,2}-[0-9]{1,2}$/",$alternate_values[$i_av])) {
$range=explode("-",$alternate_values[$i_av]);
/*Make Sure High > Low */
if ($range[0]>=$range[1]) {
$error_messages.="Error in Command #$command_number: Low value of range ".$alternate_values[$i_av]." in ".$correct_range[$i]["unit"]." field is greater than or equal to high value.<br>\r\n";
}
$i_range=0;
while(isset($range[$i_range])){
if (!isIntegerInRange($range[$i_range], $correct_range[$i]["low"], $correct_range[$i]["high"])) {
$error_messages.="Error in Command #$command_number: ".$range[$i_range]." is an incorrect value for ".$correct_range[$i]["unit"].", it must be between ".$correct_range[$i]["low"]." and ".$correct_range[$i]["high"].".<br>\r\n";
}
$i_range++;
}
$i_av++;
continue; //continue with while loop
}
/*If not a range, check individual value*/
//$error_messages.="Value: $alternate_values[$i_av]<br>";
if (!isIntegerInRange($alternate_values[$i_av], $correct_range[$i]["low"], $correct_range[$i]["high"])) {
$error_messages.="Error in Command #$command_number: ".$alternate_values[$i_av]." is an incorrect value for ".$correct_range[$i]["unit"].", it must be between ".$correct_range[$i]["low"]." and ".$correct_range[$i]["high"].".<br>\r\n";
}
$i_av++; /*Increment $alternate_values[$i_av] */
}
} else {
/* If doesn't match any of the patterns it's non-conforming */
$error_messages.="Error in Command #$command_number: The time parameters are in incorrect format<br>\r\n";
}
$i++; /* Increment tparams[$i] value */
}
return $error_messages;
}
|
Sends an octet stream header to browser forcing a download of the file found at $download_file_path with the $download_file_name. It needs to be called before headers are sent and should end before any output is sent or use output buffering. |
string $download_file_path - path of the file to be downloaded
string $download_file_name - file name which the download file will be
saved as on the local computer (not the name
of the download file on the server)
|
if($download_log) {
$download_file_name="phpcron_logfile".date("mdy_H_i").".txt";
downloadFile($log_result_file, $download_file_name);
exit;
}
|
function downloadFile($download_file_path, $download_file_name) {
if (!$download_file_path or !file_exists($download_file_path) or !is_readable($download_file_path)) {
return false;
}
$data=file($download_file_path);
$data=trim(implode("",$data));
header ("Content-length: " . strlen($data));
header ("Content-type: application/octetstream");
header ("Content-disposition: inline; filename=$download_file_name");
print($data);
return true;
}
|