Passed
Push — main ( e8ebe8...e1a2dc )
by Miaad
01:30
created

exec::getUpdate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace BPT\receiver\multi;
4
5
use BPT\BPT;
6
use BPT\lock;
7
use BPT\logger;
8
use BPT\receiver\webhook;
9
use BPT\settings;
10
11
class exec extends webhook {
12
    public static function init(): string {
13
        return self::getUpdate();
14
    }
15
16
    private static function getUpdate (): string {
17
        $up = glob('*.update');
18
        if (isset($up[0])) {
19
            $up = end($up);
20
            $ip = explode('-', $up)[0];
21
            webhook::telegramVerify($ip);
22
            $update = file_get_contents($up);
23
            unlink($up);
24
            return $update;
25
        }
26
        else {
27
            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown','error');
28
            BPT::exit();
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
29
        }
30
    }
31
32
    public static function support(): bool {
33
        return function_exists('exec')
34
            && !in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions'))))
35
            && strtolower(ini_get('safe_mode')) != 1;
36
    }
37
38
    public static function install() {
39
        $urls = self::setURLS();
40
        $url = $urls['url'];
41
        self::create($urls['file']);
42
        self::setWebhook($url);
43
        lock::set('BPT-MULTI-EXEC');
44
    }
45
46
    private static function create($file) {
47
        file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");');
48
    }
49
50
    private static function setURLS(): array {
51
        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
52
        $file = basename($_SERVER['REQUEST_URI']);
53
        return [
54
            'url'=>str_replace($file, 'receiver.php', $base_url),
55
            'file'=>$file
56
        ];
57
    }
58
}