View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012130 | mantisbt | plug-ins | public | 2010-07-01 13:38 | 2013-05-22 11:09 |
| Reporter | haruka | Assigned To | grangeway | ||
| Priority | normal | Severity | minor | Reproducibility | N/A |
| Status | closed | Resolution | won't fix | ||
| Summary | 0012130: plugin_cli.php | ||||
| Description | I would like to have something like the attached file(*) in the mantis core. With the attached file you can call a plugin by: (* It's just a modified copy of plugin.php) | ||||
| Tags | No tags attached. | ||||
| Attached Files | plugin_cli.php (824 bytes)
<?php
require_once( 'core.php' );
$t_plugin_path = config_get( 'plugin_path' );
if ($argv != null) {
foreach ($argv as $arg) {
if (strpos($arg, "page=") === 0) {
$f_page = str_replace("page=", "", $arg);
}
}
}
$t_matches = array();
if ( !preg_match( '/^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+[\/a-zA-Z0-9_-]*)/', $f_page, $t_matches ) ) {
trigger_error( ERROR_GENERIC, ERROR );
}
$t_basename = $t_matches[1];
$t_action = $t_matches[2];
global $g_plugin_cache;
if ( !isset( $g_plugin_cache[$t_basename] ) ) {
trigger_error( ERROR_PLUGIN_NOT_REGISTERED, ERROR );
}
$t_page = $t_plugin_path.$t_basename.DIRECTORY_SEPARATOR.
'pages'.DIRECTORY_SEPARATOR.$t_action.'.php';
if ( !is_file( $t_page ) ) {
trigger_error( ERROR_PLUGIN_PAGE_NOT_FOUND, ERROR );
}
plugin_push_current( $t_basename );
include( $t_page );
plugin_cli2.php (1,003 bytes)
<?php
# Make sure this script doesn't run via the webserver
if ( php_sapi_name() != 'cli' ) {
echo "plugin_cli.php is not allowed to run through the webserver.\n";
exit( 1 );
}
require_once( 'core.php' );
$t_plugin_path = config_get( 'plugin_path' );
if ($argv != null) {
foreach ($argv as $arg) {
if (strpos($arg, "page=") === 0) {
$f_page = str_replace("page=", "", $arg);
}
}
}
$t_matches = array();
if ( !preg_match( '/^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+[\/a-zA-Z0-9_-]*)/', $f_page, $t_matches ) ) {
trigger_error( ERROR_GENERIC, ERROR );
}
$t_basename = $t_matches[1];
$t_action = $t_matches[2];
global $g_plugin_cache;
if ( !isset( $g_plugin_cache[$t_basename] ) ) {
trigger_error( ERROR_PLUGIN_NOT_REGISTERED, ERROR );
}
$t_page = $t_plugin_path.$t_basename.DIRECTORY_SEPARATOR.
'pages'.DIRECTORY_SEPARATOR.$t_action.'.php';
if ( !is_file( $t_page ) ) {
trigger_error( ERROR_PLUGIN_PAGE_NOT_FOUND, ERROR );
}
plugin_push_current( $t_basename );
include( $t_page );
| ||||
|
Mh, just for information... am I the only one who is interested in a feature like this? |
|
|
I've just had a quick look. It's missing checks to ensure that the script is being executed from the command line. See scripts/send_emails.php for an example check. However more to the point, can you please explain how this approach increases security? |
|
Added this check. I thought my script more as an idea/example than a finished script.
Ok, I have to add a CLI-Check in the plugin to be save, too. But I don't see this as a problem. |
|
|
Removed assignment. dhx will not contribute to this issue in near future. |
|
|
Hi, I don't think this is something that we would include in the core distribution. If a plugin needed to implement a cron job, it would be better providing a cron job + setup steps for it. If someone wants to write a 'cronjob-scheduler' type engine, where someone could set 'cronjob.php' to run every 5 minutes, and then check to see what tasks should be run at this time, that would make more sense. A plugin could then "register" a cronjob task - for the mantis cron job scheduler to pick up. At the same time, given that someone might want to write a cronjob in a different language etc, I'm still probably inclined to think it's something that should be configured by the server admin outside of mantis. Paul |
|