1 | <?php |
||
2 | /** |
||
3 | * API - Timed Asynchron Services for eGroupWare |
||
4 | * |
||
5 | * @link http://www.egroupware.org |
||
6 | * @author Ralf Becker <RalfBecker-AT-outdoor-training.de> |
||
7 | * @copyright Ralf Becker <RalfBecker-AT-outdoor-training.de> |
||
8 | * |
||
9 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
10 | * @package api |
||
11 | * @access public |
||
12 | * @version $Id$ |
||
13 | */ |
||
14 | |||
15 | use EGroupware\Api\Asyncservice; |
||
16 | |||
17 | if (!isset($_REQUEST['domain'])) $_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default'; |
||
18 | $path_to_egroupware = realpath(__DIR__.'/..'); // need to be adapted if this script is moved somewhere else |
||
19 | |||
20 | // remove the comment from one of the following lines to enable loging |
||
21 | // define('ASYNC_LOG','C:\\async.log'); // Windows |
||
22 | // define('ASYNC_LOG','/tmp/async.log'); // Linux, Unix, ... |
||
23 | // ini_set('error_log','/var/lib/egroupware/cron.log'); // log regular errors and error_log only |
||
24 | |||
25 | if (defined('ASYNC_LOG')) |
||
26 | { |
||
27 | $msg = date('Y/m/d H:i:s ').$_REQUEST['domain'].": asyncservice started\n"; |
||
28 | $f = fopen(ASYNC_LOG,'a+'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
29 | fwrite($f,$msg); |
||
30 | fclose($f); |
||
31 | } |
||
32 | $GLOBALS['egw_info']['flags'] = array( |
||
33 | 'currentapp' => 'login', |
||
34 | 'noapi' => True // this stops header.inc.php to include phpgwapi/inc/function.inc.php |
||
35 | ); |
||
36 | if (!is_readable($path_to_egroupware.'/header.inc.php')) |
||
37 | { |
||
38 | $msg = "asyncservice.php: Could not find '$path_to_egroupware/header.inc.php', exiting !!!\n"; |
||
39 | |||
40 | if (isset($_SERVER['HTTP_HOST'])) |
||
41 | { |
||
42 | header("HTTP/1.1 500 $msg"); |
||
43 | } |
||
44 | if (defined('ASYNC_LOG')) |
||
45 | { |
||
46 | $f = fopen(ASYNC_LOG,'a+'); |
||
47 | fwrite($f,$msg); |
||
48 | fclose($f); |
||
49 | } |
||
50 | die($msg); |
||
51 | } |
||
52 | include($path_to_egroupware.'/header.inc.php'); |
||
53 | unset($GLOBALS['egw_info']['flags']['noapi']); |
||
54 | |||
55 | $db_type = $GLOBALS['egw_domain'][$_REQUEST['domain']]['db_type']; |
||
56 | if (!isset($GLOBALS['egw_domain'][$_REQUEST['domain']]) || empty($db_type)) |
||
57 | { |
||
58 | $msg = "asyncservice.php: Domain '$_REQUEST[domain]' is not configured or renamed, exiting !!!\n"; |
||
59 | |||
60 | if (isset($_SERVER['HTTP_HOST'])) |
||
61 | { |
||
62 | header("HTTP/1.1 500 $msg"); |
||
63 | } |
||
64 | if (defined('ASYNC_LOG')) |
||
65 | { |
||
66 | $f = fopen(ASYNC_LOG,'a+'); |
||
67 | fwrite($f,$msg); |
||
68 | fclose($f); |
||
69 | } |
||
70 | die($msg); |
||
71 | } |
||
72 | |||
73 | include(EGW_SERVER_ROOT.'/api/src/loader.php'); |
||
74 | |||
75 | $async = new Asyncservice(); |
||
76 | $num = $async->check_run(isset($_REQUEST['run_by']) ? $_REQUEST['run_by'] : 'crontab'); |
||
77 | |||
78 | $msg = date('Y/m/d H:i:s ').$_REQUEST['domain'].': '.($num === false ? 'An error occured: can not obtain semaphore!' : |
||
79 | ($num ? "$num job(s) executed" : 'Nothing to execute'))."\n\n"; |
||
80 | |||
81 | if (isset($_SERVER['HTTP_HOST'])) |
||
82 | { |
||
83 | header($num === false ? "HTTP/1.1 500 Can NOT obtain semaphore" : "HTTP/1.1 200 ".($num ? "$num job(s) executed" : 'Nothing to execute')); |
||
84 | } |
||
85 | // if the following comment got removed, you will get an email from cron for every check performed (*nix only) |
||
86 | //echo $msg; |
||
87 | |||
88 | if (defined('ASYNC_LOG')) |
||
89 | { |
||
90 | $f = fopen(ASYNC_LOG,'a+'); |
||
91 | fwrite($f,$msg); |
||
92 | fclose($f); |
||
93 | } |
||
94 |