Merge pull request #131 from davyrolink/201409_cli-url
allow urls to be generated from cli, with the help of argument --uri=pull/138/head
commit
9a88b830b6
|
@ -32,6 +32,8 @@ if(!psm_is_cli()) {
|
||||||
die('This script can only be run from the command line.');
|
die('This script can only be run from the command line.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
psm_set_cli_uri();
|
||||||
|
|
||||||
// prevent cron from running twice at the same time
|
// prevent cron from running twice at the same time
|
||||||
// however if the cron has been running for X mins, we'll assume it died and run anyway
|
// however if the cron has been running for X mins, we'll assume it died and run anyway
|
||||||
// if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php.
|
// if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php.
|
||||||
|
|
|
@ -548,6 +548,32 @@ function psm_is_cli() {
|
||||||
return (!isset($_SERVER['SERVER_SOFTWARE']) || php_sapi_name() == 'cli');
|
return (!isset($_SERVER['SERVER_SOFTWARE']) || php_sapi_name() == 'cli');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set _server vars from the cli argument --uri=
|
||||||
|
* Example: php cron/status.cron.php --uri="http://www.phpservermonitor.org/"
|
||||||
|
*/
|
||||||
|
function psm_set_cli_uri() {
|
||||||
|
foreach ($_SERVER['argv'] as $argv) {
|
||||||
|
if (0 === strpos($argv, '--uri=')) {
|
||||||
|
$uriArray = parse_url(substr($argv, 6));
|
||||||
|
if (!empty($uriArray['scheme'])) {
|
||||||
|
$_SERVER['REQUEST_SCHEME'] = $uriArray['scheme'];
|
||||||
|
$_SERVER['SERVER_PORT'] = ($uriArray['scheme'] == 'https') ? 443 : 80;
|
||||||
|
}
|
||||||
|
if (!empty($uriArray['host'])) {
|
||||||
|
$_SERVER['HTTP_HOST'] = $uriArray['host'];
|
||||||
|
}
|
||||||
|
if (!empty($uriArray['port'])) {
|
||||||
|
$_SERVER['SERVER_PORT'] = $uriArray['port'];
|
||||||
|
}
|
||||||
|
if (!empty($uriArray['path'])) {
|
||||||
|
$_SERVER['SCRIPT_NAME'] = $uriArray['path'];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
###############################################
|
###############################################
|
||||||
#
|
#
|
||||||
# Debug functions
|
# Debug functions
|
||||||
|
|
|
@ -245,9 +245,8 @@ class StatusNotifier {
|
||||||
|
|
||||||
$pushover->setTitle(psm_parse_msg($this->status_new, 'pushover_title', $this->server));
|
$pushover->setTitle(psm_parse_msg($this->status_new, 'pushover_title', $this->server));
|
||||||
$pushover->setMessage(str_replace('<br/>', "\n", $message));
|
$pushover->setMessage(str_replace('<br/>', "\n", $message));
|
||||||
// @todo fix url when script is executed via CLI
|
$pushover->setUrl(psm_build_url());
|
||||||
// $pushover->setUrl($url);
|
$pushover->setUrlTitle(psm_get_lang('system', 'title'));
|
||||||
// $pushover->setUrlTitle(psm_get_lang('system', 'title'));
|
|
||||||
|
|
||||||
foreach($users as $user) {
|
foreach($users as $user) {
|
||||||
if(trim($user['pushover_key']) == '') {
|
if(trim($user['pushover_key']) == '') {
|
||||||
|
|
Loading…
Reference in New Issue