-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.php
113 lines (75 loc) · 2.66 KB
/
cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
*
* CLI.php is called from command line to start the various application service daemons
*
* @version services v1
* @level1 cli.php <script name>
*
* @category PHP Execution File
* @author Noah Spirakus
* @Create 2011/11/11
* @Modify 2013/02/13
* @Project ---
* @link php cli.php
*/
//Allows for interception of POSIX commands like kill
declare(ticks = 1);
/* make sure this isn't being called by a web browser */
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
//Minimum settings used by cron
set_time_limit(0);
ini_set('memory_limit', '256M');
//set some constants
global $servicepleasestop; //Used by POSIX commands
$servicepleasestop = false; //Used by POSIX commands
define('CMD', 1);
$_SERVER['DOCUMENT_ROOT'] = __DIR__;
$_GET = '';
if(!isset($_SERVER['argv'][1])){
die('Incorrect Arguments.');
// ============ DAEMONS ============
}elseif($_SERVER['argv'][1] == "daemon_cron"){ // Does some things for overall system
$_SERVER['PATH_INFO'] = 'daemon_cron/queue';
$_SERVER['REQUEST_URI'] = 'daemon_cron/queue';
$_SERVER['QUERY_STRING'] = 'daemon_cron/queue';
}elseif($_SERVER['argv'][1] == "daemon_db"){ // Does something based on records in DB
$_SERVER['PATH_INFO'] = 'daemon_db/queue';
$_SERVER['REQUEST_URI'] = 'daemon_db/queue';
$_SERVER['QUERY_STRING'] = 'daemon_db/queue';
// ============ CLI Tools ============
}elseif($_SERVER['argv'][1] == "search"){ // Used for command line searching for domains
$_SERVER['PATH_INFO'] = 'cli_tools/search/'.$_SERVER['argv'][2];
$_SERVER['REQUEST_URI'] = 'cli_tools/search/'.$_SERVER['argv'][2];
$_SERVER['QUERY_STRING'] = 'cli_tools/search/'.$_SERVER['argv'][2];
}elseif($_SERVER['argv'][1] == "where"){ // Used to verify where current server is.
$_SERVER['PATH_INFO'] = 'cli_tools/where';
$_SERVER['REQUEST_URI'] = 'cli_tools/where';
$_SERVER['QUERY_STRING'] = 'cli_tools/where';
}else{
die('Unknown Service Requested.');
}
//Attach script to listen to POSIX (kill) commands
if(function_exists('pcntl_signal')){
pcntl_signal(SIGTERM, 'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
}else{
//echo 'WARNING: No PCNTL module Installed.'.chr(10);
}
//Signal handler function
function sig_handler($signo)
{
switch ($signo) {
case SIGTERM:
case SIGINT:
global $servicepleasestop;
$servicepleasestop = true;
break;
default:
echo 'Unknown Signal from POSIX ['.$signno.']';
}
}
//Off we go into the framework
include('www/index.php');
/* End of file cli.php */
/* Location: ./cli.php */