BPTproto /
BPT-Multi
| 1 | <?php |
||
| 2 | |||
| 3 | namespace BPT; |
||
| 4 | |||
| 5 | use BPT\constants\loggerTypes; |
||
| 6 | use BPT\constants\receiver; |
||
| 7 | use BPT\db\db; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use BPT\exception\bptException; |
||
| 9 | use BPT\receiver\getUpdates; |
||
| 10 | use BPT\receiver\webhook; |
||
| 11 | use CURLFile; |
||
| 12 | use Error; |
||
| 13 | use mysqli; |
||
| 14 | use stdClass; |
||
| 15 | use TypeError; |
||
| 16 | |||
| 17 | class settings {
|
||
| 18 | public static string $token = ''; |
||
| 19 | |||
| 20 | //public static bool $auto_update = true; |
||
| 21 | |||
| 22 | public static bool $logger = true; |
||
| 23 | |||
| 24 | public static int $log_size = 10; |
||
| 25 | |||
| 26 | public static string|CURLFile|null $certificate = null; |
||
| 27 | |||
| 28 | public static bool $handler = true; |
||
| 29 | |||
| 30 | public static bool $security = false; |
||
| 31 | |||
| 32 | public static bool $secure_folder = false; |
||
| 33 | |||
| 34 | //public static bool $array_update = false; |
||
| 35 | |||
| 36 | public static bool $split_update = true; |
||
| 37 | |||
| 38 | public static bool $multi = false; |
||
| 39 | |||
| 40 | //public static bool $debug = false; |
||
| 41 | |||
| 42 | public static bool $telegram_verify = true; |
||
| 43 | |||
| 44 | public static int $max_connection = 40; |
||
| 45 | |||
| 46 | public static string $base_url = 'https://api.telegram.org/bot'; |
||
| 47 | |||
| 48 | public static string $down_url = 'https://api.telegram.org/file/bot'; |
||
| 49 | |||
| 50 | public static int $forgot_time = 100; |
||
| 51 | |||
| 52 | public static string $receiver = receiver::WEBHOOK; |
||
| 53 | |||
| 54 | public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query']; |
||
| 55 | |||
| 56 | public static array|mysqli|null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json']; |
||
| 57 | |||
| 58 | |||
| 59 | public static function init (array|stdClass $settings) {
|
||
| 60 | $settings = (array) $settings; |
||
| 61 | |||
| 62 | if (!(isset($settings['logger']) && $settings['logger'] == false)) {
|
||
| 63 | logger::init(isset($settings['log_size']) && is_numeric($settings['log_size']) ? $settings['log_size'] : self::$log_size); |
||
| 64 | } |
||
| 65 | |||
| 66 | foreach ($settings as $setting => $value) {
|
||
| 67 | try{
|
||
| 68 | self::$$setting = $value; |
||
| 69 | } |
||
| 70 | catch (TypeError){
|
||
| 71 | logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING);
|
||
| 72 | } |
||
| 73 | catch (Error){
|
||
| 74 | logger::write("$setting setting is not one of library settings",loggerTypes::WARNING);
|
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if (self::$token !== '') {
|
||
| 79 | if (tools::isToken(self::$token)) {
|
||
| 80 | self::security(); |
||
| 81 | self::secureFolder(); |
||
| 82 | self::db(); |
||
| 83 | self::$receiver !== receiver::GETUPDATES ? self::webhook() : self::getUpdates(); |
||
| 84 | } |
||
| 85 | else {
|
||
| 86 | logger::write('token format is not right, check it and try again',loggerTypes::ERROR);
|
||
| 87 | throw new bptException('TOKEN_NOT_TRUE');
|
||
| 88 | } |
||
| 89 | } |
||
| 90 | else {
|
||
| 91 | logger::write('You must specify token parameter in settings',loggerTypes::ERROR);
|
||
| 92 | throw new bptException('TOKEN_NOT_FOUND');
|
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | private static function security() {
|
||
| 97 | if (self::$security) {
|
||
| 98 | ini_set('magic_quotes_gpc', 'off');
|
||
| 99 | ini_set('sql.safe_mode', 'on');
|
||
| 100 | ini_set('max_execution_time', 30);
|
||
| 101 | ini_set('max_input_time', 30);
|
||
| 102 | ini_set('memory_limit', '20M');
|
||
| 103 | ini_set('post_max_size', '8K');
|
||
| 104 | ini_set('expose_php', 'off');
|
||
| 105 | ini_set('file_uploads', 'off');
|
||
| 106 | ini_set('display_errors', 0);
|
||
| 107 | ini_set('error_reporting', 0);
|
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | private static function secureFolder() {
|
||
| 112 | if (self::$secure_folder) {
|
||
| 113 | $address = explode('/', $_SERVER['REQUEST_URI']);
|
||
| 114 | unset($address[count($address) - 1]); |
||
| 115 | $address = implode('/', $address) . '/BPT.php';
|
||
| 116 | $text = "ErrorDocument 404 $address\nErrorDocument 403 $address\n Options -Indexes\n Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n<Files *.php>\n Order Allow,Deny\n Allow from all\n</Files>"; |
||
| 117 | if (!file_exists('.htaccess') || filesize('.htaccess') != strlen($text)) {
|
||
| 118 | file_put_contents('.htaccess', $text);
|
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | private static function db() {
|
||
| 124 | if (!empty(self::$db)) {
|
||
| 125 | db::init(self::$db); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | private static function getUpdates() {
|
||
| 130 | if (self::$handler) {
|
||
| 131 | getUpdates::init(); |
||
| 132 | } |
||
| 133 | else {
|
||
| 134 | logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR);
|
||
| 135 | throw new bptException('GETUPDATE_NEED_HANDLER');
|
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | private static function webhook() {
|
||
| 140 | //self::$multi ? multi::init() : self::getUpdates(); |
||
| 141 | webhook::init(); |
||
| 142 | } |
||
| 143 | } |
||
| 144 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths