@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | use const rosasurfer\WINDOWS; |
22 | 22 | |
23 | 23 | require(dirname(realpath(__FILE__)).'/../../app/init.php'); |
24 | -!CLI && exit(1|stderr('error: This script must be executed in CLI mode.')); |
|
24 | +!CLI && exit(1 | stderr('error: This script must be executed in CLI mode.')); |
|
25 | 25 | |
26 | 26 | |
27 | 27 | // --- Configuration -------------------------------------------------------------------------------------------------------- |
28 | 28 | |
29 | 29 | |
30 | -set_time_limit(0); // no time limit for CLI |
|
31 | -$quiet = false; // whether or not "quiet" mode is enabled (e.g. for CRON) |
|
30 | +set_time_limit(0); // no time limit for CLI |
|
31 | +$quiet = false; // whether or not "quiet" mode is enabled (e.g. for CRON) |
|
32 | 32 | |
33 | 33 | |
34 | 34 | // --- Parse and validate command line arguments ---------------------------------------------------------------------------- |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $args = array_slice($_SERVER['argv'], 1); |
38 | 38 | |
39 | 39 | foreach ($args as $i => $arg) { |
40 | - if ($arg == '-h') { help(); exit(0); } // help |
|
40 | + if ($arg == '-h') { help(); exit(0); } // help |
|
41 | 41 | if ($arg == '-q') { $quiet = true; unset($args[$i]); continue; } // quiet mode |
42 | 42 | |
43 | 43 | stderr('invalid argument: '.$arg); |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | |
52 | 52 | // (1) define the location of the error log |
53 | 53 | $errorLog = ini_get('error_log'); |
54 | -if (empty($errorLog) || $errorLog=='syslog') { // errors are logged elsewhere |
|
55 | - if (empty($errorLog)) $quiet || echoPre('errors are logged elsewhere ('.(CLI ? 'stderr':'sapi' ).')'); |
|
56 | - else $quiet || echoPre('errors are logged elsewhere ('.(WINDOWS ? 'event log':'syslog').')'); |
|
54 | +if (empty($errorLog) || $errorLog == 'syslog') { // errors are logged elsewhere |
|
55 | + if (empty($errorLog)) $quiet || echoPre('errors are logged elsewhere ('.(CLI ? 'stderr' : 'sapi').')'); |
|
56 | + else $quiet || echoPre('errors are logged elsewhere ('.(WINDOWS ? 'event log' : 'syslog').')'); |
|
57 | 57 | exit(0); |
58 | 58 | } |
59 | 59 | |
60 | 60 | |
61 | 61 | // (2) check log file for existence and process it |
62 | -if (!is_file ($errorLog)) { $quiet || echoPre('error log empty: ' .$errorLog); exit(0); } |
|
62 | +if (!is_file($errorLog)) { $quiet || echoPre('error log empty: '.$errorLog); exit(0); } |
|
63 | 63 | if (!is_writable($errorLog)) { stderr('cannot access log file: '.$errorLog); exit(1); } |
64 | 64 | $errorLog = realpath($errorLog); |
65 | 65 | |
66 | 66 | // rename the file; we don't want to lock it as doing so could block the main app |
67 | 67 | $tempName = tempnam(dirname($errorLog), basename($errorLog).'.'); |
68 | 68 | if (!rename($errorLog, $tempName)) { |
69 | - stderr('cannot rename log file: ' .$errorLog); |
|
69 | + stderr('cannot rename log file: '.$errorLog); |
|
70 | 70 | exit(1); |
71 | 71 | } |
72 | 72 | |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | $hFile = fopen($tempName, 'rb'); |
76 | 76 | $line = $entry = ''; |
77 | 77 | $i = 0; |
78 | -while (($line=fgets($hFile)) !== false) { |
|
78 | +while (($line = fgets($hFile)) !== false) { |
|
79 | 79 | $i++; |
80 | - $line = trim($line, "\r\n"); // PHP doesn't correctly handle EOL_NETSCAPE which is error_log() standard on Windows |
|
80 | + $line = trim($line, "\r\n"); // PHP doesn't correctly handle EOL_NETSCAPE which is error_log() standard on Windows |
|
81 | 81 | if (strStartsWith($line, '[')) { // lines starting with a bracket "[" are considered the start of an entry |
82 | 82 | processEntry($entry); |
83 | 83 | $entry = ''; |
84 | 84 | } |
85 | 85 | $entry .= $line.NL; |
86 | 86 | } |
87 | -processEntry($entry); // process the last entry (if any) |
|
87 | +processEntry($entry); // process the last entry (if any) |
|
88 | 88 | |
89 | 89 | // delete the processed file |
90 | 90 | fclose($hFile); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } // without receivers mail is sent to the system user |
122 | 122 | !$receivers && $receivers[] = strtolower(get_current_user().'@localhost'); |
123 | 123 | |
124 | - $subject = strtok($entry, "\r\n"); // that's CR or LF, not CRLF |
|
124 | + $subject = strtok($entry, "\r\n"); // that's CR or LF, not CRLF |
|
125 | 125 | $message = $entry; |
126 | 126 | $sender = null; |
127 | 127 | $headers = []; |
@@ -52,8 +52,11 @@ discard block |
||
52 | 52 | // (1) define the location of the error log |
53 | 53 | $errorLog = ini_get('error_log'); |
54 | 54 | if (empty($errorLog) || $errorLog=='syslog') { // errors are logged elsewhere |
55 | - if (empty($errorLog)) $quiet || echoPre('errors are logged elsewhere ('.(CLI ? 'stderr':'sapi' ).')'); |
|
56 | - else $quiet || echoPre('errors are logged elsewhere ('.(WINDOWS ? 'event log':'syslog').')'); |
|
55 | + if (empty($errorLog)) { |
|
56 | + $quiet || echoPre('errors are logged elsewhere ('.(CLI ? 'stderr':'sapi' ).')'); |
|
57 | + } else { |
|
58 | + $quiet || echoPre('errors are logged elsewhere ('.(WINDOWS ? 'event log':'syslog').')'); |
|
59 | + } |
|
57 | 60 | exit(0); |
58 | 61 | } |
59 | 62 | |
@@ -105,9 +108,13 @@ discard block |
||
105 | 108 | * @param string $entry - a single log entry |
106 | 109 | */ |
107 | 110 | function processEntry($entry) { |
108 | - if (!is_string($entry)) throw new IllegalTypeException('Illegal type of parameter $entry: '.gettype($entry)); |
|
111 | + if (!is_string($entry)) { |
|
112 | + throw new IllegalTypeException('Illegal type of parameter $entry: '.gettype($entry)); |
|
113 | + } |
|
109 | 114 | $entry = trim($entry); |
110 | - if (!strlen($entry)) return; |
|
115 | + if (!strlen($entry)) { |
|
116 | + return; |
|
117 | + } |
|
111 | 118 | |
112 | 119 | $config = Application::getConfig(); |
113 | 120 | |
@@ -151,8 +158,9 @@ discard block |
||
151 | 158 | * @param string $message [optional] - additional message to display (default: none) |
152 | 159 | */ |
153 | 160 | function help($message = null) { |
154 | - if (isset($message)) |
|
155 | - echo $message.NL; |
|
161 | + if (isset($message)) { |
|
162 | + echo $message.NL; |
|
163 | + } |
|
156 | 164 | |
157 | 165 | $self = basename($_SERVER['PHP_SELF']); |
158 | 166 |
@@ -164,5 +164,5 @@ |
||
164 | 164 | -h This help screen. |
165 | 165 | |
166 | 166 | |
167 | -HELP; |
|
167 | +help; |
|
168 | 168 | } |
@@ -3,16 +3,16 @@ |
||
3 | 3 | use rosasurfer\util\PHP; |
4 | 4 | |
5 | 5 | // class loader |
6 | -require(($appRoot=dirname(__DIR__)).'/vendor/autoload.php'); |
|
6 | +require(($appRoot = dirname(__DIR__)).'/vendor/autoload.php'); |
|
7 | 7 | |
8 | 8 | |
9 | 9 | // php.ini settings |
10 | 10 | error_reporting(E_ALL & ~E_DEPRECATED); |
11 | -PHP::ini_set('log_errors', 1 ); |
|
12 | -PHP::ini_set('error_log', $appRoot.'/etc/log/php-error.log'); |
|
13 | -PHP::ini_set('session.save_path', $appRoot.'/etc/tmp' ); |
|
14 | -PHP::ini_set('default_charset', 'UTF-8' ); |
|
15 | -PHP::ini_set('memory_limit', '128M' ); |
|
11 | +PHP::ini_set('log_errors', 1); |
|
12 | +PHP::ini_set('error_log', $appRoot.'/etc/log/php-error.log'); |
|
13 | +PHP::ini_set('session.save_path', $appRoot.'/etc/tmp'); |
|
14 | +PHP::ini_set('default_charset', 'UTF-8'); |
|
15 | +PHP::ini_set('memory_limit', '128M'); |
|
16 | 16 | |
17 | 17 | |
18 | 18 | // create a new application |
@@ -39,8 +39,7 @@ |
||
39 | 39 | |
40 | 40 | $expires = date('Ymd', time() + 1*MONTH); // extend license for 30 days |
41 | 41 | $reply = $account.'|'.$license.'|A|'.$expires.'|mt4tfv|ok'; |
42 | - } |
|
43 | - else { |
|
42 | + } else { |
|
44 | 43 | $reply = 'ERROR: Unknown or missing account number.|no'; |
45 | 44 | } |
46 | 45 | $knownAccount || Logger::log('reply: '.$reply, L_INFO); // log requests for unknown accounts |
@@ -37,13 +37,13 @@ |
||
37 | 37 | $knownAccount = (bool) ($license = $config->get('bfx.accounts.'.$account, null)); |
38 | 38 | !$license && $license = $config->get('bfx.accounts.default'); |
39 | 39 | |
40 | - $expires = date('Ymd', time() + 1*MONTH); // extend license for 30 days |
|
40 | + $expires = date('Ymd', time() + 1 * MONTH); // extend license for 30 days |
|
41 | 41 | $reply = $account.'|'.$license.'|A|'.$expires.'|mt4tfv|ok'; |
42 | 42 | } |
43 | 43 | else { |
44 | 44 | $reply = 'ERROR: Unknown or missing account number.|no'; |
45 | 45 | } |
46 | - $knownAccount || Logger::log('reply: '.$reply, L_INFO); // log requests for unknown accounts |
|
46 | + $knownAccount || Logger::log('reply: '.$reply, L_INFO); // log requests for unknown accounts |
|
47 | 47 | |
48 | 48 | echo $reply; |
49 | 49 | return null; |