1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace rosasurfer\bfx\controller\actions; |
5
|
|
|
|
6
|
|
|
use rosasurfer\ministruts\config\ConfigInterface as Config; |
7
|
|
|
use rosasurfer\ministruts\log\Logger; |
8
|
|
|
use rosasurfer\ministruts\struts\Action; |
9
|
|
|
use rosasurfer\ministruts\struts\Request; |
10
|
|
|
use rosasurfer\ministruts\struts\Response; |
11
|
|
|
|
12
|
|
|
use function rosasurfer\ministruts\strIsDigits; |
13
|
|
|
|
14
|
|
|
use const rosasurfer\ministruts\L_INFO; |
15
|
|
|
use const rosasurfer\ministruts\MONTH; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* CheckLicenseAction |
20
|
|
|
*/ |
21
|
|
|
class CheckLicenseAction extends Action { |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function execute(Request $request, Response $response) { |
28
|
|
|
/** @var Config $config */ |
29
|
|
|
$config = $this->di()['config']; |
30
|
|
|
|
31
|
|
|
// request: GET /Paypal/TFV/index.php?id=TSR&lic={encoded-license}&rn=9&mt4={account}&ec=1 |
32
|
|
|
// response: {account}|{plain-license}|A|{expiration}|mt4tfv|ok |
33
|
|
|
// or: ERROR: {error-msg}|no |
34
|
|
|
|
35
|
|
|
$knownAccount = false; |
36
|
|
|
$input = $request->input(); |
37
|
|
|
$account = $input->get('mt4', ''); |
38
|
|
|
|
39
|
|
|
if (strIsDigits($account)) { |
|
|
|
|
40
|
|
|
$license = $config->get('bfx.accounts.'.$account, null); |
41
|
|
|
$knownAccount = !is_null($license); |
42
|
|
|
$license = $license ?: $config->get('bfx.accounts.default'); |
43
|
|
|
$expires = date('Ymd', time() + 1*MONTH); // extend license for 30 days |
44
|
|
|
$reply = $account.'|'.$license.'|A|'.$expires.'|mt4tfv|ok'; |
45
|
|
|
} |
46
|
|
|
else { |
47
|
|
|
$reply = 'ERROR: '.($account=="" ? 'Missing':'Invalid').' account number.|no'; |
48
|
|
|
} |
49
|
|
|
$knownAccount || Logger::log('reply: '.$reply, L_INFO); // log requests for unknown accounts |
50
|
|
|
|
51
|
|
|
echo $reply; |
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|