@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $syslog_file = '/var/log/messages'; |
| 26 | 26 | $log_file = self::getSyslogFile(); |
| 27 | - if ( ! file_exists($syslog_file)) { |
|
| 27 | + if (!file_exists($syslog_file)) { |
|
| 28 | 28 | file_put_contents($syslog_file, ''); |
| 29 | 29 | } |
| 30 | 30 | $syslogdPath = Util::which('syslogd'); |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | $logreadPath = Util::which('logread'); |
| 33 | 33 | $killPath = Util::which('kill'); |
| 34 | 34 | $pid = Processes::getPidOfProcess($syslogdPath); |
| 35 | - if ( ! empty($pid)) { |
|
| 35 | + if (!empty($pid)) { |
|
| 36 | 36 | $options = file_exists($log_file) ? '>' : ''; |
| 37 | - Processes::mwExec("{$busyboxPath} {$logreadPath} 2> /dev/null >" . $options . $log_file); |
|
| 37 | + Processes::mwExec("{$busyboxPath} {$logreadPath} 2> /dev/null >".$options.$log_file); |
|
| 38 | 38 | // Завершаем процесс. |
| 39 | 39 | Processes::mwExec("{$busyboxPath} {$killPath} '$pid'"); |
| 40 | 40 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public static function getSyslogFile(): string |
| 51 | 51 | { |
| 52 | - $logdir = System::getLogDir() . '/system'; |
|
| 52 | + $logdir = System::getLogDir().'/system'; |
|
| 53 | 53 | Util::mwMkdir($logdir); |
| 54 | 54 | return "$logdir/messages"; |
| 55 | 55 | } |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | while (true) { |
| 39 | 39 | $pid = Processes::getPidOfProcess('beanstalkd'); |
| 40 | 40 | if (empty($pid)) { |
| 41 | - Util::echoWithSyslog(' - Wait for start beanstalkd deamon ...' . PHP_EOL); |
|
| 41 | + Util::echoWithSyslog(' - Wait for start beanstalkd deamon ...'.PHP_EOL); |
|
| 42 | 42 | sleep(2); |
| 43 | 43 | } else { |
| 44 | 44 | break; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public function configure() |
| 33 | 33 | { |
| 34 | 34 | $lofFile = '/var/log/lastlog'; |
| 35 | - if(!file_exists($lofFile)){ |
|
| 35 | + if (!file_exists($lofFile)) { |
|
| 36 | 36 | file_put_contents($lofFile, ''); |
| 37 | 37 | } |
| 38 | 38 | $dropbear_dir = '/etc/dropbear'; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $dropbearkeyPath = Util::which('dropbearkey'); |
| 48 | 48 | $dropbearPath = Util::which('dropbear'); |
| 49 | 49 | foreach ($keytypes as $keytype => $db_key) { |
| 50 | - $res_keyfilepath = "{$dropbear_dir}/dropbear_" . $keytype . "_host_key"; |
|
| 50 | + $res_keyfilepath = "{$dropbear_dir}/dropbear_".$keytype."_host_key"; |
|
| 51 | 51 | $key = $this->mikoPBXConfig->getGeneralSettings($db_key); |
| 52 | 52 | $key = (isset($key) && is_string($key)) ? trim($key) : ""; |
| 53 | 53 | if (strlen($key) > 100) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | file_put_contents($res_keyfilepath, base64_decode($key)); |
| 56 | 56 | } |
| 57 | 57 | // If key not exists, we will generate and store new one into file and database |
| 58 | - if ( ! file_exists($res_keyfilepath)) { |
|
| 58 | + if (!file_exists($res_keyfilepath)) { |
|
| 59 | 59 | // Generation |
| 60 | 60 | Processes::mwExec("{$dropbearkeyPath} -t $keytype -f $res_keyfilepath"); |
| 61 | 61 | // Storing |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | echo $killPath.' -QUIT '.$pid."\n"; |
| 65 | 65 | } |
| 66 | 66 | $timeStart = time(); |
| 67 | - while (true){ |
|
| 68 | - if(time() - $timeStart > 20){ |
|
| 67 | + while (true) { |
|
| 68 | + if (time() - $timeStart > 20) { |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | 71 | usleep(50000); |
| 72 | 72 | $pid = Processes::getPidOfProcess('nginx: master process'); |
| 73 | - if($pid !== ''){ |
|
| 73 | + if ($pid !== '') { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | $result = Processes::mwExec($NginxPath); |
| 77 | - if($result === 0){ |
|
| 77 | + if ($result === 0) { |
|
| 78 | 78 | break; |
| 79 | 79 | } |
| 80 | 80 | echo "RESULT -- $result\n"; |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | $RedirectToHttps = $this->mikoPBXConfig->getGeneralSettings('RedirectToHttps'); |
| 114 | 114 | if ($RedirectToHttps === '1' && $not_ssl === false) { |
| 115 | - $conf_data = 'if ( $remote_addr != "127.0.0.1" ) {' . PHP_EOL |
|
| 116 | - . ' ' . 'return 301 https://$host:' . $WEBHTTPSPort . '$request_uri;' . PHP_EOL |
|
| 117 | - . ' }' . PHP_EOL; |
|
| 115 | + $conf_data = 'if ( $remote_addr != "127.0.0.1" ) {'.PHP_EOL |
|
| 116 | + . ' '.'return 301 https://$host:'.$WEBHTTPSPort.'$request_uri;'.PHP_EOL |
|
| 117 | + . ' }'.PHP_EOL; |
|
| 118 | 118 | $config = str_replace('include mikopbx/locations/*.conf;', $conf_data, $config); |
| 119 | 119 | } |
| 120 | 120 | file_put_contents($httpConfigFile, $config); |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | $WEBHTTPSPrivateKey = $this->mikoPBXConfig->getGeneralSettings('WEBHTTPSPrivateKey'); |
| 125 | 125 | if ( |
| 126 | 126 | $not_ssl === false |
| 127 | - && ! empty($WEBHTTPSPublicKey) |
|
| 128 | - && ! empty($WEBHTTPSPrivateKey) |
|
| 127 | + && !empty($WEBHTTPSPublicKey) |
|
| 128 | + && !empty($WEBHTTPSPrivateKey) |
|
| 129 | 129 | ) { |
| 130 | 130 | $public_filename = '/etc/ssl/certs/nginx.crt'; |
| 131 | 131 | $private_filename = '/etc/ssl/private/nginx.key'; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // Test work |
| 142 | 142 | $currentConfigIsGood = $this->testCurrentNginxConfig(); |
| 143 | - if ($level < 1 && ! $currentConfigIsGood) { |
|
| 143 | + if ($level < 1 && !$currentConfigIsGood) { |
|
| 144 | 144 | ++$level; |
| 145 | 145 | Util::sysLogMsg('nginx', 'Failed test config file. SSL will be disable...'); |
| 146 | 146 | $this->generateConf(true, $level); |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function generateModulesConf(): void |
| 171 | 171 | { |
| 172 | - $locationsPath = self::MODULES_LOCATIONS_PATH; |
|
| 173 | - if (!is_dir($locationsPath)){ |
|
| 174 | - Util::mwMkdir($locationsPath,true); |
|
| 172 | + $locationsPath = self::MODULES_LOCATIONS_PATH; |
|
| 173 | + if (!is_dir($locationsPath)) { |
|
| 174 | + Util::mwMkdir($locationsPath, true); |
|
| 175 | 175 | } |
| 176 | 176 | $additionalModules = $this->di->getShared('pbxConfModules'); |
| 177 | 177 | $rmPath = Util::which('rm'); |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | foreach ($additionalModules as $appClass) { |
| 180 | 180 | if (method_exists($appClass, 'createNginxLocations')) { |
| 181 | 181 | $locationContent = $appClass->createNginxLocations(); |
| 182 | - if ( ! empty($locationContent)) { |
|
| 182 | + if (!empty($locationContent)) { |
|
| 183 | 183 | $confFileName = "{$locationsPath}/{$appClass->moduleUniqueId}.conf"; |
| 184 | 184 | file_put_contents($confFileName, $locationContent); |
| 185 | - if ( ! $this->testCurrentNginxConfig()) { |
|
| 185 | + if (!$this->testCurrentNginxConfig()) { |
|
| 186 | 186 | Processes::mwExec("{$rmPath} {$confFileName}"); |
| 187 | - Util::sysLogMsg('nginx', 'Failed test config file for module' . $appClass->moduleUniqueId); |
|
| 187 | + Util::sysLogMsg('nginx', 'Failed test config file for module'.$appClass->moduleUniqueId); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | public function start($argv): void |
| 22 | 22 | { |
| 23 | 23 | $settings_file = trim($argv[1]); |
| 24 | - if ( ! file_exists($settings_file)) { |
|
| 24 | + if (!file_exists($settings_file)) { |
|
| 25 | 25 | Util::sysLogMsg(__CLASS__, 'File with settings not found'); |
| 26 | 26 | |
| 27 | 27 | return; |
| 28 | 28 | } |
| 29 | 29 | $settings = json_decode(file_get_contents($settings_file), true); |
| 30 | - $progress_file = $settings['tempDir'] . '/merging_progress'; |
|
| 30 | + $progress_file = $settings['tempDir'].'/merging_progress'; |
|
| 31 | 31 | $this->mergeFilesInDirectory( |
| 32 | 32 | $settings['tempDir'], |
| 33 | 33 | $settings['resumableFilename'], |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | // Check filesize is equal uploaded size |
| 40 | 40 | $resultFileSize = filesize($settings['fullUploadedFileName']); |
| 41 | - if ((int)$settings['resumableTotalSize'] === $resultFileSize) { |
|
| 41 | + if ((int) $settings['resumableTotalSize'] === $resultFileSize) { |
|
| 42 | 42 | file_put_contents($progress_file, '100'); |
| 43 | 43 | } else { |
| 44 | 44 | Util::sysLogMsg( |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | // Delete uploaded file after 10 minutes |
| 51 | 51 | Processes::mwExecBg( |
| 52 | - '/sbin/shell_functions.sh killprocesses ' . $settings['tempDir'] . ' -TERM 0;rm -rf ' . $settings['tempDir'], |
|
| 52 | + '/sbin/shell_functions.sh killprocesses '.$settings['tempDir'].' -TERM 0;rm -rf '.$settings['tempDir'], |
|
| 53 | 53 | '/dev/null', |
| 54 | 54 | 600 |
| 55 | 55 | ); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // Restore original file from chunks |
| 76 | 76 | if (($fp = fopen($result_file, 'w')) !== false) { |
| 77 | 77 | for ($i = 1; $i <= $total_files; $i++) { |
| 78 | - $tmp_file = $tempDir . '/' . $fileName . '.part' . $i; |
|
| 78 | + $tmp_file = $tempDir.'/'.$fileName.'.part'.$i; |
|
| 79 | 79 | fwrite($fp, file_get_contents($tmp_file)); |
| 80 | 80 | unlink($tmp_file); |
| 81 | 81 | $currentProgress = round($i / $total_files * 100); |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | fclose($fp); |
| 86 | 86 | } else { |
| 87 | - Util::sysLogMsg('UploadFile', 'cannot create the destination file - ' . $result_file); |
|
| 87 | + Util::sysLogMsg('UploadFile', 'cannot create the destination file - '.$result_file); |
|
| 88 | 88 | |
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | - Util::sysLogMsg('UploadFile', 'destination file - ' . $result_file); |
|
| 91 | + Util::sysLogMsg('UploadFile', 'destination file - '.$result_file); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
@@ -76,35 +76,35 @@ discard block |
||
| 76 | 76 | { |
| 77 | 77 | $res = new PBXApiResult(); |
| 78 | 78 | $res->processor = __METHOD__; |
| 79 | - $filename = System::getLogDir() . '/' . $filename; |
|
| 80 | - if ( ! file_exists($filename)) { |
|
| 79 | + $filename = System::getLogDir().'/'.$filename; |
|
| 80 | + if (!file_exists($filename)) { |
|
| 81 | 81 | $res->success = false; |
| 82 | - $res->messages[] = 'No access to the file ' . $filename; |
|
| 82 | + $res->messages[] = 'No access to the file '.$filename; |
|
| 83 | 83 | } else { |
| 84 | 84 | $res->success = true; |
| 85 | 85 | $head = Util::which('head'); |
| 86 | 86 | $grep = Util::which('grep'); |
| 87 | 87 | $tail = Util::which('tail'); |
| 88 | 88 | $filter = escapeshellarg($filter); |
| 89 | - $offset = (int)$offset; |
|
| 90 | - $lines = (int)$lines; |
|
| 91 | - $linesPlusOffset = $lines+$offset; |
|
| 89 | + $offset = (int) $offset; |
|
| 90 | + $lines = (int) $lines; |
|
| 91 | + $linesPlusOffset = $lines + $offset; |
|
| 92 | 92 | |
| 93 | 93 | $di = Di::getDefault(); |
| 94 | 94 | $dirsConfig = $di->getShared('config'); |
| 95 | - $filenameTmp = $dirsConfig->path('www.downloadCacheDir') . '/' . __FUNCTION__ . '_' . time() . '.log'; |
|
| 96 | - if (empty($filter)){ |
|
| 95 | + $filenameTmp = $dirsConfig->path('www.downloadCacheDir').'/'.__FUNCTION__.'_'.time().'.log'; |
|
| 96 | + if (empty($filter)) { |
|
| 97 | 97 | $cmd = "{$tail} -n {$linesPlusOffset} {$filename}"; |
| 98 | 98 | } else { |
| 99 | 99 | $cmd = "{$grep} -F {$filter} {$filename} | $tail -n {$linesPlusOffset}"; |
| 100 | 100 | } |
| 101 | - if ($offset>0){ |
|
| 101 | + if ($offset > 0) { |
|
| 102 | 102 | $cmd .= " | {$head} -n {$lines}"; |
| 103 | 103 | } |
| 104 | 104 | $cmd .= " > $filenameTmp"; |
| 105 | 105 | |
| 106 | 106 | Processes::mwExec("$cmd; chown www:www $filenameTmp"); |
| 107 | - $res->data['cmd']=$cmd; |
|
| 107 | + $res->data['cmd'] = $cmd; |
|
| 108 | 108 | $res->data['filename'] = $filenameTmp; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $systemInfoFile = "{$logDir}/system-information.log"; |
| 163 | 163 | file_put_contents($systemInfoFile, SysinfoManagementProcessor::prepareSysyinfoContent()); |
| 164 | 164 | |
| 165 | - $futureFileName = $temp_dir . '/temp-all-log-' . time() . '.zip'; |
|
| 165 | + $futureFileName = $temp_dir.'/temp-all-log-'.time().'.zip'; |
|
| 166 | 166 | $res->data['filename'] = $futureFileName; |
| 167 | 167 | $res->success = true; |
| 168 | 168 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $res->processor = __METHOD__; |
| 199 | 199 | |
| 200 | 200 | $progress_file = "{$resultFile}.progress"; |
| 201 | - if ( ! file_exists($progress_file)) { |
|
| 201 | + if (!file_exists($progress_file)) { |
|
| 202 | 202 | $res->messages[] = 'Archive does not exist. Try again!'; |
| 203 | 203 | } elseif (file_exists($progress_file) && file_get_contents($progress_file) === '100') { |
| 204 | 204 | $uid = Util::generateRandomString(36); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $downloadLink = $di->getShared('config')->path('www.downloadCacheDir'); |
| 207 | 207 | $result_dir = "{$downloadLink}/{$uid}"; |
| 208 | 208 | Util::mwMkdir($result_dir); |
| 209 | - $link_name = 'MikoPBXLogs_' . basename($resultFile); |
|
| 209 | + $link_name = 'MikoPBXLogs_'.basename($resultFile); |
|
| 210 | 210 | Util::createUpdateSymlink($resultFile, "{$result_dir}/{$link_name}"); |
| 211 | 211 | Util::addRegularWWWRights("{$result_dir}/{$link_name}"); |
| 212 | 212 | $res->success = true; |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $res = new PBXApiResult(); |
| 234 | 234 | $res->processor = __METHOD__; |
| 235 | - $filename = System::getLogDir() . '/' . $filename; |
|
| 236 | - if ( ! file_exists($filename)) { |
|
| 235 | + $filename = System::getLogDir().'/'.$filename; |
|
| 236 | + if (!file_exists($filename)) { |
|
| 237 | 237 | $res->success = false; |
| 238 | - $res->messages[] = 'File does not exist ' . $filename; |
|
| 238 | + $res->messages[] = 'File does not exist '.$filename; |
|
| 239 | 239 | } else { |
| 240 | 240 | $uid = Util::generateRandomString(36); |
| 241 | 241 | $di = Di::getDefault(); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | continue; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $relativePath = str_ireplace($logDir . '/', '', $entry); |
|
| 279 | + $relativePath = str_ireplace($logDir.'/', '', $entry); |
|
| 280 | 280 | $fileSizeKB = ceil($fileSize / 1024); |
| 281 | 281 | $filesList[$relativePath] = |
| 282 | 282 | [ |
@@ -313,11 +313,11 @@ discard block |
||
| 313 | 313 | continue; |
| 314 | 314 | } |
| 315 | 315 | //if current file ($d) is a directory, call scanDirRecursively |
| 316 | - if (is_dir($dir . '/' . $d)) { |
|
| 317 | - $list[] = self::scanDirRecursively($dir . '/' . $d); |
|
| 316 | + if (is_dir($dir.'/'.$d)) { |
|
| 317 | + $list[] = self::scanDirRecursively($dir.'/'.$d); |
|
| 318 | 318 | //otherwise, add the file to the list |
| 319 | - } elseif (is_file($dir . '/' . $d) || is_link($dir . '/' . $d)) { |
|
| 320 | - $list[] = $dir . '/' . $d; |
|
| 319 | + } elseif (is_file($dir.'/'.$d) || is_link($dir.'/'.$d)) { |
|
| 320 | + $list[] = $dir.'/'.$d; |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $res->success = true; |
| 65 | 65 | $di = Di::getDefault(); |
| 66 | 66 | $dirsConfig = $di->getShared('config'); |
| 67 | - $filenameTmp = $dirsConfig->path('www.downloadCacheDir') . '/' . __FUNCTION__ . '_' . time() . '.txt'; |
|
| 67 | + $filenameTmp = $dirsConfig->path('www.downloadCacheDir').'/'.__FUNCTION__.'_'.time().'.txt'; |
|
| 68 | 68 | |
| 69 | 69 | $content = self::prepareSysyinfoContent(); |
| 70 | 70 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $content .= self::getAsteriskInfo(); |
| 99 | 99 | $content .= self::getChangedConfigFiles(); |
| 100 | 100 | $content .= self::getCorruptedFiles(); |
| 101 | - $content .= PHP_EOL . PHP_EOL; |
|
| 101 | + $content .= PHP_EOL.PHP_EOL; |
|
| 102 | 102 | |
| 103 | 103 | return $content; |
| 104 | 104 | } |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | public static function getDate(): string |
| 112 | 112 | { |
| 113 | 113 | $content = '───────────────────────────────────────── Date ─────────────────────────────────────────'; |
| 114 | - $content .= PHP_EOL . PHP_EOL; |
|
| 114 | + $content .= PHP_EOL.PHP_EOL; |
|
| 115 | 115 | $datePath = Util::which('date'); |
| 116 | 116 | $ut = []; |
| 117 | 117 | Processes::mwExec($datePath, $ut); |
| 118 | - $content .= implode(PHP_EOL, $ut). PHP_EOL; |
|
| 119 | - $content .= PHP_EOL . PHP_EOL; |
|
| 118 | + $content .= implode(PHP_EOL, $ut).PHP_EOL; |
|
| 119 | + $content .= PHP_EOL.PHP_EOL; |
|
| 120 | 120 | return $content; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | $version = PbxSettings::getValueByKey('PBXVersion'); |
| 131 | 131 | $content = '─────────────────────────────────────── PBXVersion ───────────────────────────────────────'; |
| 132 | - $content .= PHP_EOL . PHP_EOL; |
|
| 133 | - $content .= $version . PHP_EOL; |
|
| 134 | - $content .= PHP_EOL . PHP_EOL; |
|
| 132 | + $content .= PHP_EOL.PHP_EOL; |
|
| 133 | + $content .= $version.PHP_EOL; |
|
| 134 | + $content .= PHP_EOL.PHP_EOL; |
|
| 135 | 135 | return $content; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | public static function getUpTime(): string |
| 144 | 144 | { |
| 145 | 145 | $content = '───────────────────────────────────────── Uptime ─────────────────────────────────────────'; |
| 146 | - $content .= PHP_EOL . PHP_EOL; |
|
| 146 | + $content .= PHP_EOL.PHP_EOL; |
|
| 147 | 147 | $uptimePath = Util::which('uptime'); |
| 148 | 148 | $ut = []; |
| 149 | 149 | Processes::mwExec($uptimePath, $ut); |
| 150 | - $uptime = implode(PHP_EOL, $ut); |
|
| 151 | - $content .= $uptime . PHP_EOL; |
|
| 152 | - $content .= PHP_EOL . PHP_EOL; |
|
| 150 | + $uptime = implode(PHP_EOL, $ut); |
|
| 151 | + $content .= $uptime.PHP_EOL; |
|
| 152 | + $content .= PHP_EOL.PHP_EOL; |
|
| 153 | 153 | return $content; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | public static function getCpu(): string |
| 162 | 162 | { |
| 163 | 163 | $content = '───────────────────────────────────────── CPU load ───────────────────────────────────────'; |
| 164 | - $content .= PHP_EOL . PHP_EOL; |
|
| 164 | + $content .= PHP_EOL.PHP_EOL; |
|
| 165 | 165 | $ut = []; |
| 166 | 166 | $grepPath = Util::which('grep'); |
| 167 | 167 | $mpstatPath = Util::which('mpstat'); |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | $rv = 100; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $content .= round($rv, 2) . PHP_EOL; |
|
| 177 | - $content .= PHP_EOL . PHP_EOL; |
|
| 176 | + $content .= round($rv, 2).PHP_EOL; |
|
| 177 | + $content .= PHP_EOL.PHP_EOL; |
|
| 178 | 178 | return $content; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public static function getMemInfo(): string |
| 187 | 187 | { |
| 188 | 188 | $content = '───────────────────────────────────────── MemInfo ────────────────────────────────────────'; |
| 189 | - $content .= PHP_EOL . PHP_EOL; |
|
| 189 | + $content .= PHP_EOL.PHP_EOL; |
|
| 190 | 190 | $out = []; |
| 191 | 191 | $catPath = Util::which('cat'); |
| 192 | 192 | $grepPath = Util::which('grep'); |
@@ -194,19 +194,19 @@ discard block |
||
| 194 | 194 | $freePath = Util::which('free'); |
| 195 | 195 | Processes::mwExec("{$catPath} /proc/meminfo | {$grepPath} -C 0 'Inactive:' | {$awkPath} '{print $2}'", $out); |
| 196 | 196 | $inactive = round((1 * implode($out)) / 1024, 2); |
| 197 | - $content .= "inactive = {$inactive}" . PHP_EOL; |
|
| 197 | + $content .= "inactive = {$inactive}".PHP_EOL; |
|
| 198 | 198 | Processes::mwExec("{$catPath} /proc/meminfo | {$grepPath} -C 0 'MemFree:' | {$awkPath} '{print $2}'", $out); |
| 199 | 199 | $free = round((1 * implode($out)) / 1024, 2); |
| 200 | - $content .= "free = {$free}" . PHP_EOL; |
|
| 200 | + $content .= "free = {$free}".PHP_EOL; |
|
| 201 | 201 | Processes::mwExec("{$catPath} /proc/meminfo | {$grepPath} -C 0 'MemTotal:' | {$awkPath} '{print $2}'", $out); |
| 202 | 202 | $total = round((1 * implode($out)) / 1024, 2); |
| 203 | - $content .= "total = {$total}" . PHP_EOL . PHP_EOL; |
|
| 203 | + $content .= "total = {$total}".PHP_EOL.PHP_EOL; |
|
| 204 | 204 | |
| 205 | 205 | $content .= '────────────────────────────────────────── Free ─────────────────────────────────────────'; |
| 206 | - $content .= PHP_EOL . PHP_EOL; |
|
| 206 | + $content .= PHP_EOL.PHP_EOL; |
|
| 207 | 207 | Processes::mwExec($freePath, $out); |
| 208 | - $content .= implode(PHP_EOL, $out) . PHP_EOL; |
|
| 209 | - $content .= PHP_EOL . PHP_EOL; |
|
| 208 | + $content .= implode(PHP_EOL, $out).PHP_EOL; |
|
| 209 | + $content .= PHP_EOL.PHP_EOL; |
|
| 210 | 210 | return $content; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -218,13 +218,13 @@ discard block |
||
| 218 | 218 | private static function getStorageInfo(): string |
| 219 | 219 | { |
| 220 | 220 | $content = '─────────────────────────────────────────── df ───────────────────────────────────────────'; |
| 221 | - $content .= PHP_EOL . PHP_EOL; |
|
| 221 | + $content .= PHP_EOL.PHP_EOL; |
|
| 222 | 222 | $dfPath = Util::which('df'); |
| 223 | 223 | $out = []; |
| 224 | 224 | Processes::mwExec("{$dfPath} -h", $out); |
| 225 | 225 | $dfOut = implode(PHP_EOL, $out); |
| 226 | - $content .= $dfOut . PHP_EOL; |
|
| 227 | - $content .= PHP_EOL . PHP_EOL; |
|
| 226 | + $content .= $dfOut.PHP_EOL; |
|
| 227 | + $content .= PHP_EOL.PHP_EOL; |
|
| 228 | 228 | return $content; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -236,13 +236,13 @@ discard block |
||
| 236 | 236 | private static function getIfconfigInfo(): string |
| 237 | 237 | { |
| 238 | 238 | $content = '─────────────────────────────────────── ifconfig ──────────────────────────────────────'; |
| 239 | - $content .= PHP_EOL . PHP_EOL; |
|
| 239 | + $content .= PHP_EOL.PHP_EOL; |
|
| 240 | 240 | $ifconfigPath = Util::which('ifconfig'); |
| 241 | 241 | $out = []; |
| 242 | 242 | Processes::mwExec($ifconfigPath, $out); |
| 243 | 243 | $ifconfigOut = implode(PHP_EOL, $out); |
| 244 | - $content .= $ifconfigOut . PHP_EOL; |
|
| 245 | - $content .= PHP_EOL . PHP_EOL; |
|
| 244 | + $content .= $ifconfigOut.PHP_EOL; |
|
| 245 | + $content .= PHP_EOL.PHP_EOL; |
|
| 246 | 246 | return $content; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | private static function getArpInfo(): string |
| 255 | 255 | { |
| 256 | 256 | $content = '─────────────────────────────────────────── arp ──────────────────────────────────────────'; |
| 257 | - $content .= PHP_EOL . PHP_EOL; |
|
| 257 | + $content .= PHP_EOL.PHP_EOL; |
|
| 258 | 258 | $arpPath = Util::which('arp'); |
| 259 | 259 | $out = []; |
| 260 | 260 | Processes::mwExec($arpPath, $out); |
| 261 | 261 | $arpOut = implode(PHP_EOL, $out); |
| 262 | - $content .= $arpOut . PHP_EOL; |
|
| 263 | - $content .= PHP_EOL . PHP_EOL; |
|
| 262 | + $content .= $arpOut.PHP_EOL; |
|
| 263 | + $content .= PHP_EOL.PHP_EOL; |
|
| 264 | 264 | return $content; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | private static function getRouteInfo(): string |
| 273 | 273 | { |
| 274 | 274 | $content = '────────────────────────────────────────── route ─────────────────────────────────────────'; |
| 275 | - $content .= PHP_EOL . PHP_EOL; |
|
| 275 | + $content .= PHP_EOL.PHP_EOL; |
|
| 276 | 276 | $routePath = Util::which('route'); |
| 277 | 277 | $out = []; |
| 278 | 278 | Processes::mwExec($routePath, $out); |
| 279 | 279 | $routeOut = implode(PHP_EOL, $out); |
| 280 | - $content .= $routeOut . PHP_EOL; |
|
| 281 | - $content .= PHP_EOL . PHP_EOL; |
|
| 280 | + $content .= $routeOut.PHP_EOL; |
|
| 281 | + $content .= PHP_EOL.PHP_EOL; |
|
| 282 | 282 | return $content; |
| 283 | 283 | } |
| 284 | 284 | |
@@ -290,13 +290,13 @@ discard block |
||
| 290 | 290 | private static function getIptablesInfo(): string |
| 291 | 291 | { |
| 292 | 292 | $content = '────────────────────────────────────────── iptables ──────────────────────────────────────'; |
| 293 | - $content .= PHP_EOL . PHP_EOL; |
|
| 293 | + $content .= PHP_EOL.PHP_EOL; |
|
| 294 | 294 | $iptablesPath = Util::which('iptables'); |
| 295 | 295 | $out = []; |
| 296 | 296 | Processes::mwExec("{$iptablesPath} -S", $out); |
| 297 | 297 | $iptablesOut = implode(PHP_EOL, $out); |
| 298 | - $content .= $iptablesOut . PHP_EOL; |
|
| 299 | - $content .= PHP_EOL . PHP_EOL; |
|
| 298 | + $content .= $iptablesOut.PHP_EOL; |
|
| 299 | + $content .= PHP_EOL.PHP_EOL; |
|
| 300 | 300 | return $content; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -308,17 +308,17 @@ discard block |
||
| 308 | 308 | private static function getPingInfo(): string |
| 309 | 309 | { |
| 310 | 310 | $content = '──────────────────────────────────────────── ping ────────────────────────────────────────'; |
| 311 | - $content .= PHP_EOL . PHP_EOL; |
|
| 311 | + $content .= PHP_EOL.PHP_EOL; |
|
| 312 | 312 | $pingPath = Util::which('ping'); |
| 313 | 313 | $out = []; |
| 314 | 314 | Processes::mwExec("{$pingPath} 8.8.8.8 -w 2", $out); |
| 315 | 315 | $pingOut = implode(PHP_EOL, $out); |
| 316 | 316 | Processes::mwExec("{$pingPath} ya.ru -w 2", $out); |
| 317 | 317 | $ping2Out = implode(PHP_EOL, $out); |
| 318 | - $content .= $pingOut . PHP_EOL; |
|
| 319 | - $content .= PHP_EOL . PHP_EOL; |
|
| 320 | - $content .= $ping2Out . PHP_EOL; |
|
| 321 | - $content .= PHP_EOL . PHP_EOL; |
|
| 318 | + $content .= $pingOut.PHP_EOL; |
|
| 319 | + $content .= PHP_EOL.PHP_EOL; |
|
| 320 | + $content .= $ping2Out.PHP_EOL; |
|
| 321 | + $content .= PHP_EOL.PHP_EOL; |
|
| 322 | 322 | return $content; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -332,12 +332,12 @@ discard block |
||
| 332 | 332 | $opensslPath = Util::which('openssl'); |
| 333 | 333 | |
| 334 | 334 | $content = '─────────────────────────────────────── openssl ─────────────────────────────────────────'; |
| 335 | - $content .= PHP_EOL . PHP_EOL; |
|
| 335 | + $content .= PHP_EOL.PHP_EOL; |
|
| 336 | 336 | $out = []; |
| 337 | 337 | Processes::mwExec("{$opensslPath} s_client -connect lic.miko.ru:443", $out); |
| 338 | 338 | $opensslOut = implode(PHP_EOL, $out); |
| 339 | - $content .= $opensslOut . PHP_EOL; |
|
| 340 | - $content .= PHP_EOL . PHP_EOL; |
|
| 339 | + $content .= $opensslOut.PHP_EOL; |
|
| 340 | + $content .= PHP_EOL.PHP_EOL; |
|
| 341 | 341 | return $content; |
| 342 | 342 | } |
| 343 | 343 | |
@@ -351,23 +351,23 @@ discard block |
||
| 351 | 351 | $asteriskPath = Util::which('asterisk'); |
| 352 | 352 | |
| 353 | 353 | $content = '────────────────────────────────── asterisk registrations ────────────────────────────────'; |
| 354 | - $content .= PHP_EOL . PHP_EOL; |
|
| 354 | + $content .= PHP_EOL.PHP_EOL; |
|
| 355 | 355 | Processes::mwExec("{$asteriskPath} -rx 'pjsip show registrations' ", $out); |
| 356 | 356 | $asteriskOut = implode(PHP_EOL, $out); |
| 357 | - $content .= $asteriskOut . PHP_EOL; |
|
| 357 | + $content .= $asteriskOut.PHP_EOL; |
|
| 358 | 358 | |
| 359 | 359 | $content .= '────────────────────────────────── asterisk endpoints ───────────────────────────────────'; |
| 360 | - $content .= PHP_EOL . PHP_EOL; |
|
| 360 | + $content .= PHP_EOL.PHP_EOL; |
|
| 361 | 361 | Processes::mwExec("{$asteriskPath} -rx 'pjsip show endpoints' ", $out); |
| 362 | 362 | $asteriskOut = implode(PHP_EOL, $out); |
| 363 | - $content .= $asteriskOut . PHP_EOL; |
|
| 363 | + $content .= $asteriskOut.PHP_EOL; |
|
| 364 | 364 | |
| 365 | 365 | $content .= '─────────────────────────────────── asterisk contacts ───────────────────────────────────'; |
| 366 | - $content .= PHP_EOL . PHP_EOL; |
|
| 366 | + $content .= PHP_EOL.PHP_EOL; |
|
| 367 | 367 | Processes::mwExec("{$asteriskPath} -rx 'pjsip show contacts' ", $out); |
| 368 | 368 | $asteriskOut = implode(PHP_EOL, $out); |
| 369 | - $content .= $asteriskOut . PHP_EOL; |
|
| 370 | - $content .= PHP_EOL . PHP_EOL; |
|
| 369 | + $content .= $asteriskOut.PHP_EOL; |
|
| 370 | + $content .= PHP_EOL.PHP_EOL; |
|
| 371 | 371 | return $content; |
| 372 | 372 | } |
| 373 | 373 | |
@@ -379,12 +379,12 @@ discard block |
||
| 379 | 379 | private static function getChangedConfigFiles(): string |
| 380 | 380 | { |
| 381 | 381 | $content = '────────────────────────────────── Changed config files ─────────────────────────────────'; |
| 382 | - $content .= PHP_EOL . PHP_EOL; |
|
| 382 | + $content .= PHP_EOL.PHP_EOL; |
|
| 383 | 383 | $files = CustomFiles::find('mode!="none"'); |
| 384 | 384 | foreach ($files as $file) { |
| 385 | - $content .= "({$file->mode}){$file->filepath}" . PHP_EOL; |
|
| 385 | + $content .= "({$file->mode}){$file->filepath}".PHP_EOL; |
|
| 386 | 386 | } |
| 387 | - $content .= PHP_EOL . PHP_EOL; |
|
| 387 | + $content .= PHP_EOL.PHP_EOL; |
|
| 388 | 388 | return $content; |
| 389 | 389 | } |
| 390 | 390 | |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | private static function getCorruptedFiles(): string |
| 397 | 397 | { |
| 398 | 398 | $content = '──────────────────────────────────── Corrupted files ────────────────────────────────────'; |
| 399 | - $content .= PHP_EOL . PHP_EOL; |
|
| 399 | + $content .= PHP_EOL.PHP_EOL; |
|
| 400 | 400 | $files = Main::checkForCorruptedFiles(); |
| 401 | 401 | foreach ($files as $file) { |
| 402 | - $content .= $file . PHP_EOL; |
|
| 402 | + $content .= $file.PHP_EOL; |
|
| 403 | 403 | } |
| 404 | - $content .= PHP_EOL . PHP_EOL; |
|
| 404 | + $content .= PHP_EOL.PHP_EOL; |
|
| 405 | 405 | return $content; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | $response = json_decode($resultrequest, true); |
| 440 | 440 | $res->data['ip'] = $response['ip']; |
| 441 | 441 | } else { |
| 442 | - $res->messages[] = 'Error format data ' . $resultrequest; |
|
| 442 | + $res->messages[] = 'Error format data '.$resultrequest; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | return $res; |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | $res->data['message'] = 'In progress...'; |
| 160 | 160 | |
| 161 | 161 | |
| 162 | - if ( ! file_exists($tempFilename)) { |
|
| 162 | + if (!file_exists($tempFilename)) { |
|
| 163 | 163 | $res->success = false; |
| 164 | 164 | $res->messages[] = "Update file '{$tempFilename}' not found."; |
| 165 | 165 | |
| 166 | 166 | return $res; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( ! file_exists('/var/etc/cfdevice')) { |
|
| 169 | + if (!file_exists('/var/etc/cfdevice')) { |
|
| 170 | 170 | $res->success = false; |
| 171 | 171 | $res->messages[] = "The system is not installed"; |
| 172 | 172 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $res = new PBXApiResult(); |
| 196 | 196 | $res->processor = __METHOD__; |
| 197 | 197 | $moduleMetadata = FilesManagementProcessor::getMetadataFromModuleFile($filePath); |
| 198 | - if ( ! $moduleMetadata->success) { |
|
| 198 | + if (!$moduleMetadata->success) { |
|
| 199 | 199 | return $moduleMetadata; |
| 200 | 200 | } else { |
| 201 | 201 | $moduleUniqueID = $moduleMetadata->data['uniqid']; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | if (class_exists($pbxExtensionSetupClass) |
| 235 | 235 | && method_exists($pbxExtensionSetupClass, 'installModule')) { |
| 236 | 236 | $setup = new $pbxExtensionSetupClass($moduleUniqueID); |
| 237 | - if ( ! $setup->installModule()) { |
|
| 237 | + if (!$setup->installModule()) { |
|
| 238 | 238 | $res->success = false; |
| 239 | 239 | $res->messages[] = $setup->getMessages(); |
| 240 | 240 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $setup->unregisterModule(); |
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | - $res->success = true; |
|
| 298 | + $res->success = true; |
|
| 299 | 299 | return $res; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -371,15 +371,15 @@ discard block |
||
| 371 | 371 | [IncomingRoutingTable::class => ''], |
| 372 | 372 | [OutWorkTimes::class => ''], |
| 373 | 373 | [AsteriskManagerUsers::class => ''], |
| 374 | - [Extensions::class => 'type="' . Extensions::TYPE_IVR_MENU . '"'], // IVR Menu |
|
| 375 | - [Extensions::class => 'type="' . Extensions::TYPE_CONFERENCE . '"'], // CONFERENCE |
|
| 376 | - [Extensions::class => 'type="' . Extensions::TYPE_QUEUE . '"'], // QUEUE |
|
| 374 | + [Extensions::class => 'type="'.Extensions::TYPE_IVR_MENU.'"'], // IVR Menu |
|
| 375 | + [Extensions::class => 'type="'.Extensions::TYPE_CONFERENCE.'"'], // CONFERENCE |
|
| 376 | + [Extensions::class => 'type="'.Extensions::TYPE_QUEUE.'"'], // QUEUE |
|
| 377 | 377 | ]; |
| 378 | 378 | |
| 379 | 379 | foreach ($clearThisModels as $modelParams) { |
| 380 | 380 | foreach ($modelParams as $key => $value) { |
| 381 | 381 | $records = call_user_func([$key, 'find'], $value); |
| 382 | - if ( ! $records->delete()) { |
|
| 382 | + if (!$records->delete()) { |
|
| 383 | 383 | $res->messages[] = $records->getMessages(); |
| 384 | 384 | $res->success = false; |
| 385 | 385 | } |
@@ -387,13 +387,13 @@ discard block |
||
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Other extensions |
| 390 | - $parameters = [ |
|
| 390 | + $parameters = [ |
|
| 391 | 391 | 'conditions' => 'not number IN ({ids:array})', |
| 392 | 392 | 'bind' => [ |
| 393 | 393 | 'ids' => [ |
| 394 | 394 | '000063', // Reads back the extension |
| 395 | 395 | '000064', // 0000MILLI |
| 396 | - '10003246',// Echo test |
|
| 396 | + '10003246', // Echo test |
|
| 397 | 397 | '10000100' // Voicemail |
| 398 | 398 | ], |
| 399 | 399 | ], |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | $stopDeleting = true; |
| 408 | 408 | continue; |
| 409 | 409 | } |
| 410 | - if ( ! $record->delete()) { |
|
| 410 | + if (!$record->delete()) { |
|
| 411 | 411 | $deleteAttempts += 1; |
| 412 | 412 | } |
| 413 | 413 | if ($deleteAttempts > $countRecords * 10) { |
@@ -423,12 +423,12 @@ discard block |
||
| 423 | 423 | 'custom' => SoundFiles::CATEGORY_CUSTOM, |
| 424 | 424 | ], |
| 425 | 425 | ]; |
| 426 | - $records = SoundFiles::find($parameters); |
|
| 426 | + $records = SoundFiles::find($parameters); |
|
| 427 | 427 | |
| 428 | 428 | foreach ($records as $record) { |
| 429 | 429 | if (stripos($record->path, '/storage/usbdisk1/mikopbx') !== false) { |
| 430 | 430 | Processes::mwExec("{$rm} -rf {$record->path}"); |
| 431 | - if ( ! $record->delete()) { |
|
| 431 | + if (!$record->delete()) { |
|
| 432 | 432 | $res->messages[] = $record->getMessages(); |
| 433 | 433 | $res->success = false; |
| 434 | 434 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | foreach ($records as $record) { |
| 441 | 441 | $moduleDir = PbxExtensionUtils::getModuleDir($record->uniqid); |
| 442 | 442 | Processes::mwExec("{$rm} -rf {$moduleDir}"); |
| 443 | - if ( ! $record->delete()) { |
|
| 443 | + if (!$record->delete()) { |
|
| 444 | 444 | $res->messages[] = $record->getMessages(); |
| 445 | 445 | $res->success = false; |
| 446 | 446 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | |
| 449 | 449 | // Delete CallRecords |
| 450 | 450 | $records = CallDetailRecords::find(); |
| 451 | - if ( ! $records->delete()) { |
|
| 451 | + if (!$records->delete()) { |
|
| 452 | 452 | $res->messages[] = $records->getMessages(); |
| 453 | 453 | $res->success = false; |
| 454 | 454 | } |
@@ -473,14 +473,14 @@ discard block |
||
| 473 | 473 | { |
| 474 | 474 | $res = new PBXApiResult(); |
| 475 | 475 | $res->processor = __METHOD__; |
| 476 | - if ( ! file_exists($filename)) { |
|
| 476 | + if (!file_exists($filename)) { |
|
| 477 | 477 | $res->success = false; |
| 478 | 478 | $res->messages[] = "File '{$filename}' not found."; |
| 479 | 479 | |
| 480 | 480 | return $res; |
| 481 | 481 | } |
| 482 | 482 | $out = []; |
| 483 | - $tmp_filename = '/tmp/' . time() . "_" . basename($filename); |
|
| 483 | + $tmp_filename = '/tmp/'.time()."_".basename($filename); |
|
| 484 | 484 | if (false === copy($filename, $tmp_filename)) { |
| 485 | 485 | $res->success = false; |
| 486 | 486 | $res->messages[] = "Unable to create temporary file '{$tmp_filename}'."; |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | // Принудительно устанавливаем расширение файла в wav. |
| 492 | - $n_filename = Util::trimExtensionForFile($filename) . ".wav"; |
|
| 493 | - $n_filename_mp3 = Util::trimExtensionForFile($filename) . ".mp3"; |
|
| 492 | + $n_filename = Util::trimExtensionForFile($filename).".wav"; |
|
| 493 | + $n_filename_mp3 = Util::trimExtensionForFile($filename).".mp3"; |
|
| 494 | 494 | // Конвертируем файл. |
| 495 | 495 | $tmp_filename = escapeshellcmd($tmp_filename); |
| 496 | 496 | $n_filename = escapeshellcmd($n_filename); |
@@ -91,18 +91,18 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | $parameters['uploadDir'] = $di->getShared('config')->path('www.uploadDir'); |
| 93 | 93 | $parameters['tempDir'] = "{$parameters['uploadDir']}/{$parameters['resumableIdentifier']}"; |
| 94 | - if ( ! Util::mwMkdir($parameters['tempDir'])) { |
|
| 95 | - $res->messages[] = 'Temp dir does not exist ' . $parameters['tempDir']; |
|
| 94 | + if (!Util::mwMkdir($parameters['tempDir'])) { |
|
| 95 | + $res->messages[] = 'Temp dir does not exist '.$parameters['tempDir']; |
|
| 96 | 96 | |
| 97 | 97 | return $res; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $fileName = pathinfo($parameters['resumableFilename'], PATHINFO_FILENAME); |
| 101 | - $fileName = preg_replace( '/[\W]/', '', $fileName); |
|
| 102 | - if (strlen($fileName)<10){ |
|
| 101 | + $fileName = preg_replace('/[\W]/', '', $fileName); |
|
| 102 | + if (strlen($fileName) < 10) { |
|
| 103 | 103 | $fileName = ''.md5(time()).'-'.$fileName; |
| 104 | 104 | } |
| 105 | - $fileName .= '.'.pathinfo($parameters['resumableFilename'], PATHINFO_EXTENSION); |
|
| 105 | + $fileName .= '.'.pathinfo($parameters['resumableFilename'], PATHINFO_EXTENSION); |
|
| 106 | 106 | $parameters['resumableFilename'] = $fileName; |
| 107 | 107 | $parameters['fullUploadedFileName'] = "{$parameters['tempDir']}/{$fileName}"; |
| 108 | 108 | |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | foreach ($parameters['files'] as $file_data) { |
| 119 | - if ( ! self::moveUploadedPartToSeparateDir($parameters, $file_data)) { |
|
| 120 | - $res->messages[] = 'Does not found any uploaded chunks on with path ' . $file_data['file_path']; |
|
| 119 | + if (!self::moveUploadedPartToSeparateDir($parameters, $file_data)) { |
|
| 120 | + $res->messages[] = 'Does not found any uploaded chunks on with path '.$file_data['file_path']; |
|
| 121 | 121 | |
| 122 | 122 | return $res; |
| 123 | 123 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | private static function moveUploadedPartToSeparateDir(array $parameters, array $file_data): bool |
| 147 | 147 | { |
| 148 | - if ( ! file_exists($file_data['file_path'])) { |
|
| 148 | + if (!file_exists($file_data['file_path'])) { |
|
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | $factory = new StreamFactory(); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | { |
| 179 | 179 | $totalFilesOnServerSize = 0; |
| 180 | 180 | foreach (scandir($parameters['tempDir']) as $file) { |
| 181 | - $totalFilesOnServerSize += filesize($parameters['tempDir'] . '/' . $file); |
|
| 181 | + $totalFilesOnServerSize += filesize($parameters['tempDir'].'/'.$file); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | if ($totalFilesOnServerSize >= $parameters['resumableTotalSize']) { |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | 'resumableTotalSize' => $parameters['resumableTotalSize'], |
| 191 | 191 | 'resumableTotalChunks' => $parameters['resumableTotalChunks'], |
| 192 | 192 | ]; |
| 193 | - $settings_file = "{$parameters['tempDir']}/merge_settings"; |
|
| 193 | + $settings_file = "{$parameters['tempDir']}/merge_settings"; |
|
| 194 | 194 | file_put_contents( |
| 195 | 195 | $settings_file, |
| 196 | 196 | json_encode($merge_settings, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) |
@@ -227,22 +227,22 @@ discard block |
||
| 227 | 227 | $uploadDir = $di->getShared('config')->path('www.uploadDir'); |
| 228 | 228 | |
| 229 | 229 | $upload_id = $postData['id'] ?? null; |
| 230 | - $progress_dir = $uploadDir . '/' . $upload_id; |
|
| 231 | - $progress_file = $progress_dir . '/merging_progress'; |
|
| 230 | + $progress_dir = $uploadDir.'/'.$upload_id; |
|
| 231 | + $progress_file = $progress_dir.'/merging_progress'; |
|
| 232 | 232 | if (empty($upload_id)) { |
| 233 | 233 | $res->success = false; |
| 234 | 234 | $res->data['d_status_progress'] = '0'; |
| 235 | 235 | $res->data['d_status'] = 'ID_NOT_SET'; |
| 236 | 236 | $res->messages[] = 'Upload ID does not set'; |
| 237 | - } elseif ( ! file_exists($progress_file) && file_exists($progress_dir)) { |
|
| 237 | + } elseif (!file_exists($progress_file) && file_exists($progress_dir)) { |
|
| 238 | 238 | $res->success = true; |
| 239 | 239 | $res->data['d_status_progress'] = '0'; |
| 240 | 240 | $res->data['d_status'] = 'INPROGRESS'; |
| 241 | - } elseif ( ! file_exists($progress_dir)) { |
|
| 241 | + } elseif (!file_exists($progress_dir)) { |
|
| 242 | 242 | $res->success = false; |
| 243 | 243 | $res->data['d_status_progress'] = '0'; |
| 244 | 244 | $res->data['d_status'] = 'NOT_FOUND'; |
| 245 | - $res->messages[] = 'Does not found anything with path: ' . $progress_dir; |
|
| 245 | + $res->messages[] = 'Does not found anything with path: '.$progress_dir; |
|
| 246 | 246 | } elseif ('100' === file_get_contents($progress_file)) { |
| 247 | 247 | $res->success = true; |
| 248 | 248 | $res->data['d_status_progress'] = '100'; |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | $res = new PBXApiResult(); |
| 269 | 269 | $res->processor = __METHOD__; |
| 270 | 270 | $extension = Util::getExtensionOfFile($filePath); |
| 271 | - if ( ! in_array($extension, ['mp3', 'wav', 'alaw'])) { |
|
| 271 | + if (!in_array($extension, ['mp3', 'wav', 'alaw'])) { |
|
| 272 | 272 | $res->success = false; |
| 273 | 273 | $res->messages[] = "It is forbidden to remove the file type $extension."; |
| 274 | 274 | |
| 275 | 275 | return $res; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( ! file_exists($filePath)) { |
|
| 278 | + if (!file_exists($filePath)) { |
|
| 279 | 279 | $res->success = true; |
| 280 | 280 | $res->data['message'] = "File '{$filePath}' already deleted"; |
| 281 | 281 | |
@@ -285,13 +285,13 @@ discard block |
||
| 285 | 285 | $out = []; |
| 286 | 286 | |
| 287 | 287 | $arrDeletedFiles = [ |
| 288 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".wav"), |
|
| 289 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".mp3"), |
|
| 290 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".alaw"), |
|
| 288 | + escapeshellarg(Util::trimExtensionForFile($filePath).".wav"), |
|
| 289 | + escapeshellarg(Util::trimExtensionForFile($filePath).".mp3"), |
|
| 290 | + escapeshellarg(Util::trimExtensionForFile($filePath).".alaw"), |
|
| 291 | 291 | ]; |
| 292 | 292 | |
| 293 | 293 | $rmPath = Util::which('rm'); |
| 294 | - Processes::mwExec("{$rmPath} -rf " . implode(' ', $arrDeletedFiles), $out); |
|
| 294 | + Processes::mwExec("{$rmPath} -rf ".implode(' ', $arrDeletedFiles), $out); |
|
| 295 | 295 | if (file_exists($filePath)) { |
| 296 | 296 | $res->success = false; |
| 297 | 297 | $res->messages = $out; |
@@ -324,13 +324,13 @@ discard block |
||
| 324 | 324 | $cat = Util::which('cat'); |
| 325 | 325 | $di = Di::getDefault(); |
| 326 | 326 | $dirsConfig = $di->getShared('config'); |
| 327 | - $filenameTmp = $dirsConfig->path('www.downloadCacheDir') . '/' . __FUNCTION__ . '_' . time() . '.conf'; |
|
| 327 | + $filenameTmp = $dirsConfig->path('www.downloadCacheDir').'/'.__FUNCTION__.'_'.time().'.conf'; |
|
| 328 | 328 | $cmd = "{$cat} {$filename} > {$filenameTmp}"; |
| 329 | 329 | Processes::mwExec("{$cmd}; chown www:www {$filenameTmp}"); |
| 330 | 330 | $res->data['filename'] = $filenameTmp; |
| 331 | 331 | } else { |
| 332 | 332 | $res->success = false; |
| 333 | - $res->messages[] = 'No access to the file ' . $filename; |
|
| 333 | + $res->messages[] = 'No access to the file '.$filename; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return $res; |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $res->success = true; |
| 400 | 400 | |
| 401 | 401 | $firmwareDirTmp = dirname($imgFileName); |
| 402 | - $progress_file = $firmwareDirTmp . '/progress'; |
|
| 402 | + $progress_file = $firmwareDirTmp.'/progress'; |
|
| 403 | 403 | |
| 404 | 404 | // Wait until download process started |
| 405 | 405 | $d_pid = Processes::getPidOfProcess("{$firmwareDirTmp}/download_settings.json"); |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | $error = trim(file_get_contents("{$firmwareDirTmp}/error")); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if ( ! file_exists($progress_file)) { |
|
| 414 | + if (!file_exists($progress_file)) { |
|
| 415 | 415 | $res->data['d_status_progress'] = '0'; |
| 416 | 416 | $res->messages[] = 'NOT_FOUND'; |
| 417 | 417 | $res->success = false; |
@@ -515,11 +515,11 @@ discard block |
||
| 515 | 515 | } else { |
| 516 | 516 | $tempDir = '/tmp'; |
| 517 | 517 | } |
| 518 | - $moduleDirTmp = $tempDir . '/' . $moduleUniqueID; |
|
| 519 | - $progress_file = $moduleDirTmp . '/progress'; |
|
| 518 | + $moduleDirTmp = $tempDir.'/'.$moduleUniqueID; |
|
| 519 | + $progress_file = $moduleDirTmp.'/progress'; |
|
| 520 | 520 | $error = ''; |
| 521 | - if (file_exists($moduleDirTmp . '/error')) { |
|
| 522 | - $error = trim(file_get_contents($moduleDirTmp . '/error')); |
|
| 521 | + if (file_exists($moduleDirTmp.'/error')) { |
|
| 522 | + $error = trim(file_get_contents($moduleDirTmp.'/error')); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | // Wait until download process started |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | usleep(500000); |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - if ( ! file_exists($progress_file)) { |
|
| 531 | + if (!file_exists($progress_file)) { |
|
| 532 | 532 | $res->data['d_status_progress'] = '0'; |
| 533 | 533 | $res->data['d_status'] = 'NOT_FOUND'; |
| 534 | 534 | $res->success = false; |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | $res->data['d_status'] = 'DOWNLOAD_ERROR'; |
| 537 | 537 | $res->data['d_status_progress'] = file_get_contents($progress_file); |
| 538 | 538 | $res->data['d_error'] = $error; |
| 539 | - $res->messages[] = file_get_contents($moduleDirTmp . '/error'); |
|
| 539 | + $res->messages[] = file_get_contents($moduleDirTmp.'/error'); |
|
| 540 | 540 | $res->success = false; |
| 541 | 541 | } elseif ('100' === file_get_contents($progress_file)) { |
| 542 | 542 | $res->data['d_status_progress'] = '100'; |
@@ -545,11 +545,11 @@ discard block |
||
| 545 | 545 | $res->success = true; |
| 546 | 546 | } else { |
| 547 | 547 | $res->data['d_status_progress'] = file_get_contents($progress_file); |
| 548 | - $d_pid = Processes::getPidOfProcess($moduleDirTmp . '/download_settings.json'); |
|
| 548 | + $d_pid = Processes::getPidOfProcess($moduleDirTmp.'/download_settings.json'); |
|
| 549 | 549 | if (empty($d_pid)) { |
| 550 | 550 | $res->data['d_status'] = 'DOWNLOAD_ERROR'; |
| 551 | - if (file_exists($moduleDirTmp . '/error')) { |
|
| 552 | - $res->messages[] = file_get_contents($moduleDirTmp . '/error'); |
|
| 551 | + if (file_exists($moduleDirTmp.'/error')) { |
|
| 552 | + $res->messages[] = file_get_contents($moduleDirTmp.'/error'); |
|
| 553 | 553 | } else { |
| 554 | 554 | $res->messages[] = "Download process interrupted at {$res->data['d_status_progress']}%"; |
| 555 | 555 | } |
@@ -580,13 +580,13 @@ discard block |
||
| 580 | 580 | $grepPath = Util::which('grep'); |
| 581 | 581 | $echoPath = Util::which('echo'); |
| 582 | 582 | $awkPath = Util::which('awk'); |
| 583 | - $cmd = 'f="' . $filePath . '"; p=`' . $sevenZaPath . ' l $f | ' . $grepPath . ' module.json`;if [ "$?" == "0" ]; then ' . $sevenZaPath . ' -so e -y -r $f `' . $echoPath . ' $p | ' . $awkPath . ' -F" " \'{print $6}\'`; fi'; |
|
| 583 | + $cmd = 'f="'.$filePath.'"; p=`'.$sevenZaPath.' l $f | '.$grepPath.' module.json`;if [ "$?" == "0" ]; then '.$sevenZaPath.' -so e -y -r $f `'.$echoPath.' $p | '.$awkPath.' -F" " \'{print $6}\'`; fi'; |
|
| 584 | 584 | |
| 585 | 585 | Processes::mwExec($cmd, $out); |
| 586 | 586 | $settings = json_decode(implode("\n", $out), true); |
| 587 | 587 | |
| 588 | 588 | $moduleUniqueID = $settings['moduleUniqueID'] ?? null; |
| 589 | - if ( ! $moduleUniqueID) { |
|
| 589 | + if (!$moduleUniqueID) { |
|
| 590 | 590 | $res->messages[] = 'The" moduleUniqueID " in the module file is not described.the json or file does not exist.'; |
| 591 | 591 | |
| 592 | 592 | return $res; |