Last active
September 27, 2017 13:05
-
-
Save clonemeagain/1dce622af9ee5d4c256bf4ceecf04f45 to your computer and use it in GitHub Desktop.
Example Remote osTicket Cron script, with instructions on how to call it remotely.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
/********************************************************************* | |
rcron.php | |
PHP script used for remote cron calls. | |
To make this work, setup an API key for localhost with ip: 127.0.0.1 | |
Put this script in the root of your webserver, then call it | |
remotely like: | |
wget -q http://server.tld/rcron.php?key=YOURKEY -O/dev/null | |
If your install is in a subdirectory, like https://server/support/ | |
Then you'll need to add it below before /api | |
Peter Rotich <peter@osticket.com> | |
Copyright (c) 2006-2013 osTicket | |
http://www.osticket.com | |
Released under the GNU General Public License WITHOUT ANY WARRANTY. | |
See LICENSE.TXT for details. | |
vim: expandtab sw=4 ts=4 sts=4: | |
**********************************************************************/ | |
# Configuration: Enter the url and key. That is it. | |
# url => URL to api/task/cron e.g http://yourdomain.com/support/api/tasks/cron | |
# key => API's Key (see admin panel on how to generate a key) | |
# | |
#Ensure only we can trigger this | |
$config = array( | |
'url'=>'http://127.0.0.1/api/tasks/cron', | |
'key'=> $_GET['key'] | |
); | |
#pre-checks | |
function_exists('curl_version') or die('CURL support required'); | |
#set timeout | |
set_time_limit(30); | |
#curl post | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $config['url']); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, ''); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7'); | |
curl_setopt($ch, CURLOPT_HEADER, TRUE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key'])); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$result=curl_exec($ch); | |
curl_close($ch); | |
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200) | |
exit(0); | |
echo $result; | |
exit(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment