diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 427ddc4457..8693cc5b8c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,58 +1,75 @@ --- -################################# -################################# -## Super Linter GitHub Actions ## -################################# -################################# -name: Lint Code Base - -############################# -# Start the job on all push # -############################# -on: # yamllint disable-line rule:truthy - push: - branches: - - 'master' - - 'releases/**' - pull_request: - types: [opened, edited, synchronize, reopened, review_requested] - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Lint Code Base - # Set the agent to run on - runs-on: ubuntu-latest - - permissions: - contents: read - packages: read - # To report GitHub Actions status checks - statuses: write - - ################## - # Load all steps # - ################## - steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v4 - with: - # Full git history is needed to get a proper list of changed files - # within `super-linter` - fetch-depth: 0 - - ################################ - # Run Linter against code base # - ################################ - - name: Lint Code Base - uses: super-linter/super-linter/slim@v5 - env: - VALIDATE_ALL_CODEBASE: false - DEFAULT_BRANCH: master - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: lint + + on: + push: + branches: + - 'master' + - 'releases/**' + pull_request: + types: [opened, edited, synchronize, reopened, review_requested] + + jobs: + php-lint: + name: PHP lint 8.2 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: PHP syntax checker 8.2 + uses: prestashop/github-action-php-lint/8.2@master + + # phpmd: + # name: PHPMD + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # + # - name: PHP Mess Detector + # uses: php-actions/phpmd@v1 + # with: + # php_version: 8.2 + # path: ./ + # output: text + # ruleset: test/phpmd/ruleset.xml + + phpcs: + name: PHPCS + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: PHP Code Sniffer + uses: php-actions/phpcs@v1 + with: + php_version: 8.2 + path: ./ + standard: PSR12 + ignore: livestats.blade.php,config.blade.php,.js + exclude: Squiz.Functions.MultiLineFunctionDeclaration + + # Figure out later what the correct paths for Heimdall src should be. + # Needed by PHPStan for symbol discovery. + # + # phpstan: + # name: PHPStan + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # with: + # path: src + # + # - name: Checkout Heimdall repo for dependencies + # uses: actions/checkout@v4 + # with: + # repository: linuxserver/Heimdall + # path: ./heimdall-src + # + # - uses: php-actions/phpstan@v3 + # with: + # path: src/ + # configuration: src/phpstan.neon \ No newline at end of file diff --git a/.github/workflows/svgo.config.js b/.github/workflows/svgo.config.js index d39a21787f..0ca2d1e56f 100644 --- a/.github/workflows/svgo.config.js +++ b/.github/workflows/svgo.config.js @@ -1,23 +1,23 @@ // svgo.config.js module.exports = { - multipass: true, // boolean. false by default - js2svg: { - indent: 4, // string with spaces or number of spaces. 4 by default - pretty: false, // boolean, false by default - }, - plugins: [ - // set of built-in plugins enabled by default - "preset-default", + multipass: true, // boolean. false by default + js2svg: { + indent: 4, // string with spaces or number of spaces. 4 by default + pretty: false, // boolean, false by default + }, + plugins: [ + // set of built-in plugins enabled by default + "preset-default", - // enable built-in plugins by name - "removeDimensions", + // enable built-in plugins by name + "removeDimensions", - // or by expanded notation which allows to configure plugin - { - name: "sortAttrs", - params: { - xmlnsOrder: "alphabetical", - }, - }, - ], + // or by expanded notation which allows to configure plugin + { + name: "sortAttrs", + params: { + xmlnsOrder: "alphabetical", + }, + }, + ], }; diff --git a/AMP/AMP.php b/AMP/AMP.php index f95f242c6b..961f9d889c 100644 --- a/AMP/AMP.php +++ b/AMP/AMP.php @@ -1,4 +1,6 @@ - [ - "Content-Type" => "text/xml; charset='utf-8'", + "headers" => [ + "Content-Type" => "text/xml; charset='utf-8'", "SoapAction" => "urn:schemas-upnp-org:service:{$ns}:1#{$verb}", - ], - "body" => " - + ], + "body" => " + ", - ]; + ]; - return $attrs; - } + return $attrs; + } public static function getAvailableStats() - { - return [ - "NewConnectionStatus" => "Status", - "NewUptime" => "Up Time", - "NewLayer1DownstreamMaxBitRate" => "Max Down", - "NewLayer1UpstreamMaxBitRate" => "Max Up", + { + return [ + "NewConnectionStatus" => "Status", + "NewUptime" => "Up Time", + "NewLayer1DownstreamMaxBitRate" => "Max Down", + "NewLayer1UpstreamMaxBitRate" => "Max Up", "NewByteReceiveRate" => "Down", "NewByteSendRate" => "Up", "NewX_AVM_DE_TotalBytesReceived64" => "Received", "NewX_AVM_DE_TotalBytesSent64" => "Send", - ]; - } + ]; + } private static function formatValueUsingStat($stat, $value) - { - if (!isset($value)) { - return "N/A"; - } + { + if (!isset($value)) { + return "N/A"; + } - switch ($stat) { + switch ($stat) { case "NewConnectionStatus": return "{$value}"; case "NewUptime": return self::toTime((int)$value); - case "NewLayer1DownstreamMaxBitRate": - case "NewLayer1UpstreamMaxBitRate": - return format_bytes(((int)$value)/8, false, "", "/s"); + case "NewLayer1DownstreamMaxBitRate": + case "NewLayer1UpstreamMaxBitRate": + return format_bytes(((int)$value) / 8, false, "", "/s"); case "NewByteReceiveRate": case "NewByteSendRate": return format_bytes((int)$value, false, "", "/s"); case "NewX_AVM_DE_TotalBytesReceived64": case "NewX_AVM_DE_TotalBytesSent64": - return format_bytes((int)$value, false, "", ""); - default: - return "{$value}"; - } - } + return format_bytes((int)$value, false, "", ""); + default: + return "{$value}"; + } + } private static function toTime($timestamp) { @@ -89,72 +92,81 @@ private static function toTime($timestamp) $hourDuration = sprintf('%02dh', $hours); $minDuration = sprintf('%02dm', $minutes); $secDuration = sprintf('%02ds', $seconds); - $HourMinSec = $hourDuration.$minDuration.$secDuration; + $HourMinSec = $hourDuration . $minDuration . $secDuration; - if($hourDuration > 0){ + if ($hourDuration > 0) { $hourDuration = $hourDuration; } else { $hourDuration = '00h'; } - if($minDuration > 0){ + if ($minDuration > 0) { $minDuration = $minDuration; } else { $minDuration = '00m'; } - if($secDuration > 0){ + if ($secDuration > 0) { $secDuration = $secDuration; } else { $secDuration = '00s'; } - $HourMinSec = $hourDuration.$minDuration.$secDuration; + $HourMinSec = $hourDuration . $minDuration . $secDuration; return $HourMinSec; } public function test() - { - $test = parent::appTest( + { + $test = parent::appTest( $this->url("statusInfo"), $this->getAttrs("statusInfo") ); - echo $test->status; - } + echo $test->status; + } - public function livestats() - { - $status = "active"; + public function livestats() + { + $status = "active"; $statusInfo = parent::execute( - $this->url("statusInfo"), - $this->getAttrs("statusInfo") - ); - $statusInfoDetails = simplexml_load_string($statusInfo->getBody())->children('s', true)->children('u', true)->children(); + $this->url("statusInfo"), + $this->getAttrs("statusInfo") + ); + $statusInfoDetails = simplexml_load_string($statusInfo->getBody()) + ->children('s', true) + ->children('u', true) + ->children(); $linkProperties = parent::execute( - $this->url("linkProperties"), - $this->getAttrs("linkProperties") - ); - $linkPropertiesDetails = simplexml_load_string($linkProperties->getBody())->children('s', true)->children('u', true)->children(); + $this->url("linkProperties"), + $this->getAttrs("linkProperties") + ); + $linkPropertiesDetails = simplexml_load_string($linkProperties->getBody()) + ->children('s', true) + ->children('u', true) + ->children(); $addonInfo = parent::execute( - $this->url("addonInfo"), - $this->getAttrs("addonInfo") - ); - $addonInfoDetails = simplexml_load_string($addonInfo->getBody())->children('s', true)->children('u', true)->children(); + $this->url("addonInfo"), + $this->getAttrs("addonInfo") + ); + $addonInfoDetails = simplexml_load_string($addonInfo->getBody()) + ->children('s', true) + ->children('u', true) + ->children(); - $data = ["visiblestats" => []]; + $data = ["visiblestats" => []]; - if ($statusInfoDetails && $linkPropertiesDetails && $addonInfoDetails) { - foreach ($this->config->availablestats as $stat) { + if ($statusInfoDetails && $linkPropertiesDetails && $addonInfoDetails) { + foreach ($this->config->availablestats as $stat) { if (!isset(self::getAvailableStats()[$stat])) { - continue; - } + continue; + } $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; + $newstat->title = self::getAvailableStats()[$stat]; switch ($stat) { case "NewConnectionStatus": @@ -187,25 +199,25 @@ public function livestats() ); } - $data["visiblestats"][] = $newstat; - } - } + $data["visiblestats"][] = $newstat; + } + } - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { + public function url($endpoint) + { if ($endpoint == "statusInfo") { $endpoint = "WANIPConn1"; } else { $endpoint = "WANCommonIFC1"; } - - $fritzURL = $this->config->url; - $api_url = "$fritzURL:49000/igdupnp/control/{$endpoint}"; + $fritzURL = $this->config->url; + + $api_url = "$fritzURL:49000/igdupnp/control/{$endpoint}"; - return $api_url; - } + return $api_url; + } } diff --git a/AWX/AWX.php b/AWX/AWX.php index 4308c270c2..af1b020797 100644 --- a/AWX/AWX.php +++ b/AWX/AWX.php @@ -1,35 +1,37 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Ackee/Ackee.php b/Ackee/Ackee.php index 3ba3af6c27..8b68e57218 100644 --- a/Ackee/Ackee.php +++ b/Ackee/Ackee.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("/control/stats")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("/control/stats")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("/control/stats")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("/control/stats")); + $details = json_decode($res->getBody()); - $data = []; - if ($details) { - // format has been changed in AdguardHome v0.99.0 - if (is_array($details->dns_queries)) { - $data["dns_queries"] = number_format( - array_sum($details->dns_queries) - ); - $data["blocked_filtering"] = number_format( - array_sum($details->blocked_filtering) - ); - } else { - $data["dns_queries"] = number_format($details->dns_queries); - $data["blocked_filtering"] = number_format( - $details->blocked_filtering - ); - } - } + $data = []; + if ($details) { + // format has been changed in AdguardHome v0.99.0 + if (is_array($details->dns_queries)) { + $data["dns_queries"] = number_format( + array_sum($details->dns_queries) + ); + $data["blocked_filtering"] = number_format( + array_sum($details->blocked_filtering) + ); + } else { + $data["dns_queries"] = number_format($details->dns_queries); + $data["blocked_filtering"] = number_format( + $details->blocked_filtering + ); + } + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url); - $username = $this->config->username; - $password = $this->config->password; - $rebuild_url = str_replace( - "http://", - "http://" . $username . ":" . $password . "@", - $api_url - ); - $rebuild_url = str_replace( - "https://", - "https://" . $username . ":" . $password . "@", - $rebuild_url - ); - $rebuild_url = rtrim($rebuild_url, "/"); + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url); + $username = $this->config->username; + $password = $this->config->password; + $rebuild_url = str_replace( + "http://", + "http://" . $username . ":" . $password . "@", + $api_url + ); + $rebuild_url = str_replace( + "https://", + "https://" . $username . ":" . $password . "@", + $rebuild_url + ); + $rebuild_url = rtrim($rebuild_url, "/"); - $api_url = $rebuild_url . $endpoint; - return $api_url; - } + $api_url = $rebuild_url . $endpoint; + return $api_url; + } } diff --git a/Adminer/Adminer.php b/Adminer/Adminer.php index e484f90831..aca82f7b6b 100644 --- a/Adminer/Adminer.php +++ b/Adminer/Adminer.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - // $test = parent::appTest($this->url('getSensors.json'), $this->attrs); - $res = parent::execute($this->url("getSensors.json"), $this->attrs); - echo $res->getBody(); - } - - public function livestats() - { - $status = "inactive"; - - $res = parent::execute($this->url("getSensors.json"), $this->attrs); - $details = json_decode($res->getBody()); - $activesensors = 0; - - foreach ($details->sensors as $key => $value) { - if ($value->enabled && $value->alert) { - $activesensors += 1; - } - } - - $data = []; - if ($details->triggered) { - $alarmstatus = "Intruder"; - } elseif ($details->alarmArmed) { - $alarmstatus = "Armed"; - } else { - $alarmstatus = "Disarmed"; - } - $data["alarm_status"] = $alarmstatus; - $data["alarm_sensors"] = $activesensors; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $this->attrs = [ - "auth" => [ - $this->config->username, - $this->config->password, - "Basic", - ], - ]; - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + // $test = parent::appTest($this->url('getSensors.json'), $this->attrs); + $res = parent::execute($this->url("getSensors.json"), $this->attrs); + echo $res->getBody(); + } + + public function livestats() + { + $status = "inactive"; + + $res = parent::execute($this->url("getSensors.json"), $this->attrs); + $details = json_decode($res->getBody()); + $activesensors = 0; + + foreach ($details->sensors as $key => $value) { + if ($value->enabled && $value->alert) { + $activesensors += 1; + } + } + + $data = []; + if ($details->triggered) { + $alarmstatus = "Intruder"; + } elseif ($details->alarmArmed) { + $alarmstatus = "Armed"; + } else { + $alarmstatus = "Disarmed"; + } + $data["alarm_status"] = $alarmstatus; + $data["alarm_sensors"] = $activesensors; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $this->attrs = [ + "auth" => [ + $this->config->username, + $this->config->password, + "Basic", + ], + ]; + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Alertmanager/Alertmanager.php b/Alertmanager/Alertmanager.php index cb2ba9548e..9424108ede 100644 --- a/Alertmanager/Alertmanager.php +++ b/Alertmanager/Alertmanager.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - if (!isset($this->config->password)) { - echo "Invalid password"; - return; - } + public function test() + { + if (!isset($this->config->password)) { + echo "Invalid password"; + return; + } - $test = parent::appTest( - $this->url("status?password=" . $this->config->password) - ); - echo $test->status; - } + $test = parent::appTest( + $this->url("status?password=" . $this->config->password) + ); + echo $test->status; + } - public function livestats() - { - if (!isset($this->config->password)) { - return parent::getLiveStats("Inactive", []); - } - $status = "inactive"; - $res = parent::execute( - $this->url("api/bot/asf?password=" . $this->config->password) - ); - $details = json_decode($res->getBody()); + public function livestats() + { + if (!isset($this->config->password)) { + return parent::getLiveStats("Inactive", []); + } + $status = "inactive"; + $res = parent::execute( + $this->url("api/bot/asf?password=" . $this->config->password) + ); + $details = json_decode($res->getBody()); - $totalSecondsLeft = 0; - $cardToFarmLeft = 0; - foreach ($details->Result as $bot) { - foreach ($bot->CardsFarmer->GamesToFarm as $game) { - $cardToFarmLeft += $game->CardsRemaining; - } - if ( - preg_match( - "@([0-9].*).([0-9]+):([0-9]+):([0-9]+)@", - $bot->CardsFarmer->TimeRemaining, - $matches - ) - ) { - $totalSecondsLeft += $matches[1] * 24 * 60 * 60; // Days - $totalSecondsLeft += $matches[2] * 60 * 60; // Hours - $totalSecondsLeft += $matches[3] * 60; // Minutes - $totalSecondsLeft += $matches[4]; // Seconds - } elseif ( - preg_match( - "@([0-9].*):([0-9]+):([0-9]+)@", - $bot->CardsFarmer->TimeRemaining, - $matches - ) - ) { - $totalSecondsLeft += $matches[1] * 60 * 60; // Hours - $totalSecondsLeft += $matches[2] * 60; // Minutes - $totalSecondsLeft += $matches[3]; // Seconds - } - } + $totalSecondsLeft = 0; + $cardToFarmLeft = 0; + foreach ($details->Result as $bot) { + foreach ($bot->CardsFarmer->GamesToFarm as $game) { + $cardToFarmLeft += $game->CardsRemaining; + } + if ( + preg_match( + "@([0-9].*).([0-9]+):([0-9]+):([0-9]+)@", + $bot->CardsFarmer->TimeRemaining, + $matches + ) + ) { + $totalSecondsLeft += $matches[1] * 24 * 60 * 60; // Days + $totalSecondsLeft += $matches[2] * 60 * 60; // Hours + $totalSecondsLeft += $matches[3] * 60; // Minutes + $totalSecondsLeft += $matches[4]; // Seconds + } elseif ( + preg_match( + "@([0-9].*):([0-9]+):([0-9]+)@", + $bot->CardsFarmer->TimeRemaining, + $matches + ) + ) { + $totalSecondsLeft += $matches[1] * 60 * 60; // Hours + $totalSecondsLeft += $matches[2] * 60; // Minutes + $totalSecondsLeft += $matches[3]; // Seconds + } + } - $d = Carbon::now(); - $d->addSeconds($totalSecondsLeft); - $data = [ - "time_left" => $d->diffForHumans(null, true, true, 3), - "cards_left" => $cardToFarmLeft, - ]; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $d = Carbon::now(); + $d->addSeconds($totalSecondsLeft); + $data = [ + "time_left" => $d->diffForHumans(null, true, true, 3), + "cards_left" => $cardToFarmLeft, + ]; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/ArchiveBox/ArchiveBox.php b/ArchiveBox/ArchiveBox.php index 84f823c007..ff22514dc0 100644 --- a/ArchiveBox/ArchiveBox.php +++ b/ArchiveBox/ArchiveBox.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set - } - - public function test() - { - $attrs = $this->newRequestAttrs("aria2.getVersion"); - $test = parent::appTest($this->url("jsonrpc"), $attrs); - if ($test->code === 200) { - $data = json_decode($test->response); - if (isset($data->result) && isset($data->result->version)) { - $version = $data->result->version; - $test->status = "Connected to Aria2 v$version"; - } else { - $test->status = "Unknown Aria2 version"; - } - } - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $attrs = $this->newRequestAttrs("aria2.getGlobalStat"); - $res = parent::execute($this->url("jsonrpc"), $attrs); - - if ($res == null) { - //Log::debug('Aria2 connection failed'); - return ""; - } - - $details = json_decode($res->getBody()); - if (!isset($details->result)) { - //Log::debug('Failed to fetch data from Aria2'); - return ""; - } - - $downloadSpeed = $details->result->downloadSpeed; - $uploadSpeed = $details->result->uploadSpeed; - - $active = $details->result->numActive; - $stopped = $details->result->numStopped; - $waiting = $details->result->numWaiting; - - if ($active > 0) { - $status = "active"; - } - - $data = []; - $data["download_rate"] = format_bytes( - $downloadSpeed, - false, - " ", - "/s" - ); - $data["upload_rate"] = format_bytes( - $uploadSpeed, - false, - " ", - "/s" - ); - $data["running_count"] = $active + $waiting ?? 0; - $data["stopped_count"] = $stopped ?? 0; - - return parent::getLiveStats($status, $data); - } - - private function newRequestAttrs($rpcMethod) - { - $body = [ - "jsonrpc" => "2.0", - "id" => "qwer", - "method" => $rpcMethod, - ]; - if (isset($this->config->password)) { - $body["params"] = ["token:" . $this->config->password]; - } - - $attrs = [ - "body" => json_encode($body), - "cookies" => $this->jar, - "headers" => [ - "Content-Type" => "application/json", - "Accept" => "application/json", - ], - ]; - - return $attrs; - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + protected $method = "POST"; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + $this->jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set + } + + public function test() + { + $attrs = $this->newRequestAttrs("aria2.getVersion"); + $test = parent::appTest($this->url("jsonrpc"), $attrs); + if ($test->code === 200) { + $data = json_decode($test->response); + if (isset($data->result) && isset($data->result->version)) { + $version = $data->result->version; + $test->status = "Connected to Aria2 v$version"; + } else { + $test->status = "Unknown Aria2 version"; + } + } + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $attrs = $this->newRequestAttrs("aria2.getGlobalStat"); + $res = parent::execute($this->url("jsonrpc"), $attrs); + + if ($res == null) { + //Log::debug('Aria2 connection failed'); + return ""; + } + + $details = json_decode($res->getBody()); + if (!isset($details->result)) { + //Log::debug('Failed to fetch data from Aria2'); + return ""; + } + + $downloadSpeed = $details->result->downloadSpeed; + $uploadSpeed = $details->result->uploadSpeed; + + $active = $details->result->numActive; + $stopped = $details->result->numStopped; + $waiting = $details->result->numWaiting; + + if ($active > 0) { + $status = "active"; + } + + $data = []; + $data["download_rate"] = format_bytes( + $downloadSpeed, + false, + " ", + "/s" + ); + $data["upload_rate"] = format_bytes( + $uploadSpeed, + false, + " ", + "/s" + ); + $data["running_count"] = $active + $waiting ?? 0; + $data["stopped_count"] = $stopped ?? 0; + + return parent::getLiveStats($status, $data); + } + + private function newRequestAttrs($rpcMethod) + { + $body = [ + "jsonrpc" => "2.0", + "id" => "qwer", + "method" => $rpcMethod, + ]; + if (isset($this->config->password)) { + $body["params"] = ["token:" . $this->config->password]; + } + + $attrs = [ + "body" => json_encode($body), + "cookies" => $this->jar, + "headers" => [ + "Content-Type" => "application/json", + "Accept" => "application/json", + ], + ]; + + return $attrs; + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Artifactory/Artifactory.php b/Artifactory/Artifactory.php index 55f4f11c8e..b4b0fb6a11 100644 --- a/Artifactory/Artifactory.php +++ b/Artifactory/Artifactory.php @@ -1,49 +1,51 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $attrs = [ - "headers" => ["X-JFrog-Art-Api" => $this->config->apiKey], - ]; - echo $this->config->apiKey; - $test = parent::appTest($this->url("api/storageinfo"), $attrs); - - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $attrs = [ - "headers" => ["X-JFrog-Art-Api" => $this->config->apiKey], - ]; - $res = parent::execute($this->url("api/storageinfo"), $attrs); - $details = json_decode($res->getBody()); - - $data = []; - if ($details) { - $data["artifacts_size"] = $details->binariesSummary->artifactsSize; - $data["artifacts_count"] = - $details->binariesSummary->artifactsCount; - $status = "active"; - } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $attrs = [ + "headers" => ["X-JFrog-Art-Api" => $this->config->apiKey], + ]; + echo $this->config->apiKey; + $test = parent::appTest($this->url("api/storageinfo"), $attrs); + + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $attrs = [ + "headers" => ["X-JFrog-Art-Api" => $this->config->apiKey], + ]; + $res = parent::execute($this->url("api/storageinfo"), $attrs); + $details = json_decode($res->getBody()); + + $data = []; + if ($details) { + $data["artifacts_size"] = $details->binariesSummary->artifactsSize; + $data["artifacts_count"] = + $details->binariesSummary->artifactsCount; + $status = "active"; + } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/AsrockRackIPMI/AsrockRackIPMI.php b/AsrockRackIPMI/AsrockRackIPMI.php index 1dd5ee3239..95b6e45247 100644 --- a/AsrockRackIPMI/AsrockRackIPMI.php +++ b/AsrockRackIPMI/AsrockRackIPMI.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $attrs = [ - "headers" => ["Accept" => "application/json"], - ]; - $test = parent::appTest($this->url("systemstatus"), $attrs); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - $attrs = [ - "headers" => ["Accept" => "application/json"], - ]; - - $badges = json_decode( - parent::execute($this->url("badges"), $attrs)->getBody() - ); - - $data = []; - - if ($badges) { - $data["movies"] = $badges->movies ?? 0; - $data["series"] = $badges->episodes ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/" . - $endpoint . - "?apikey=" . - $this->config->apikey; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $attrs = [ + "headers" => ["Accept" => "application/json"], + ]; + $test = parent::appTest($this->url("systemstatus"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + $attrs = [ + "headers" => ["Accept" => "application/json"], + ]; + + $badges = json_decode( + parent::execute($this->url("badges"), $attrs)->getBody() + ); + + $data = []; + + if ($badges) { + $data["movies"] = $badges->movies ?? 0; + $data["series"] = $badges->episodes ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/" . + $endpoint . + "?apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/Bitwarden/Bitwarden.php b/Bitwarden/Bitwarden.php index 525e87e564..15110d762c 100644 --- a/Bitwarden/Bitwarden.php +++ b/Bitwarden/Bitwarden.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Booksonic/Booksonic.php b/Booksonic/Booksonic.php index b0bb25dd3f..7deb944050 100644 --- a/Booksonic/Booksonic.php +++ b/Booksonic/Booksonic.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function getHeaders() - { - $api_token = $this->config->api_token . ":" . $this->config->api_secret; - - $attrs["headers"] = ["Authorization" => "Token " . $api_token]; - return $attrs; - } - - public function test() - { - $test = parent::appTest( - $this->url("api/shelves?count=0"), - $this->getHeaders() - ); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - - $attrs = $this->getHeaders(); - - $data = ["visiblestats" => []]; - - foreach ($this->config->availablestats as $stat) { - if (!isset(self::getAvailableStats()[$stat])) { - continue; - } - - $res = parent::execute( - $this->url("api/" . $stat . "?count=0"), - $attrs - ); - $details = json_decode($res->getBody()); - - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = isset($details->total) - ? number_format($details->total) - : "N/A"; - - $data["visiblestats"][] = $newstat; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - rtrim(parent::normaliseurl($this->config->url), "/") . - "/" . - ltrim($endpoint, "/"); - return $api_url; - } - - public static function getAvailableStats() - { - return [ - "shelves" => "Shelves", - "books" => "Books", - "chapters" => "Chapters", - "pages" => "Pages", - ]; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function getHeaders() + { + $api_token = $this->config->api_token . ":" . $this->config->api_secret; + + $attrs["headers"] = ["Authorization" => "Token " . $api_token]; + return $attrs; + } + + public function test() + { + $test = parent::appTest( + $this->url("api/shelves?count=0"), + $this->getHeaders() + ); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + + $attrs = $this->getHeaders(); + + $data = ["visiblestats" => []]; + + foreach ($this->config->availablestats as $stat) { + if (!isset(self::getAvailableStats()[$stat])) { + continue; + } + + $res = parent::execute( + $this->url("api/" . $stat . "?count=0"), + $attrs + ); + $details = json_decode($res->getBody()); + + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = isset($details->total) + ? number_format($details->total) + : "N/A"; + + $data["visiblestats"][] = $newstat; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + rtrim(parent::normaliseurl($this->config->url), "/") . + "/" . + ltrim($endpoint, "/"); + return $api_url; + } + + public static function getAvailableStats() + { + return [ + "shelves" => "Shelves", + "books" => "Books", + "chapters" => "Chapters", + "pages" => "Pages", + ]; + } } diff --git a/Box/Box.php b/Box/Box.php index 5173032cc0..f439b92f74 100644 --- a/Box/Box.php +++ b/Box/Box.php @@ -1,4 +1,6 @@ -url(self::ENDPOINT)); - echo $test->status; - } - - public function livestats() - { - $result = parent::execute($this->url(self::ENDPOINT)); - $services = json_decode($result->getBody()); - - $results = [ - self::STATUS_PASSING => 0, - self::STATUS_WARNING => 0, - self::STATUS_ERROR => 0, - self::STATUS_CRITICAL => 0, - ]; - - foreach ($services as $service) { - $overallStatus = ucfirst( - strtolower($service->overall_status ?? "") - ); - - if (isset($results[$overallStatus])) { - $results[$overallStatus]++; - } - } - - if ($results[self::STATUS_CRITICAL] > 0) { - $status = self::STATUS_CRITICAL; - } elseif ($results[self::STATUS_ERROR] > 0) { - $status = self::STATUS_ERROR; - } elseif ($results[self::STATUS_WARNING] > 0) { - $status = self::STATUS_WARNING; - } else { - $status = self::STATUS_PASSING; - } - - $data["status_output"] = $status; - $data["count_output"] = $results[$status]; - - return parent::getLiveStats("inactive", $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + private const ENDPOINT = "api/services/?format=json"; + + private const STATUS_PASSING = "Passing"; + private const STATUS_WARNING = "Warning"; + private const STATUS_ERROR = "Error"; + private const STATUS_CRITICAL = "Critical"; + + public $config; + + public function test() + { + $test = parent::appTest($this->url(self::ENDPOINT)); + echo $test->status; + } + + public function livestats() + { + $result = parent::execute($this->url(self::ENDPOINT)); + $services = json_decode($result->getBody()); + + $results = [ + self::STATUS_PASSING => 0, + self::STATUS_WARNING => 0, + self::STATUS_ERROR => 0, + self::STATUS_CRITICAL => 0, + ]; + + foreach ($services as $service) { + $overallStatus = ucfirst( + strtolower($service->overall_status ?? "") + ); + + if (isset($results[$overallStatus])) { + $results[$overallStatus]++; + } + } + + if ($results[self::STATUS_CRITICAL] > 0) { + $status = self::STATUS_CRITICAL; + } elseif ($results[self::STATUS_ERROR] > 0) { + $status = self::STATUS_ERROR; + } elseif ($results[self::STATUS_WARNING] > 0) { + $status = self::STATUS_WARNING; + } else { + $status = self::STATUS_PASSING; + } + + $data["status_output"] = $status; + $data["count_output"] = $results[$status]; + + return parent::getLiveStats("inactive", $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/CalibreWeb/CalibreWeb.php b/CalibreWeb/CalibreWeb.php index 9a99ed0487..0051f86a64 100644 --- a/CalibreWeb/CalibreWeb.php +++ b/CalibreWeb/CalibreWeb.php @@ -1,4 +1,6 @@ -url("dvr")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("dvr")); - $details = json_decode($res->getBody(), true); - - $data = []; - - $activity = $details["activity"]; - $recordings = count(preg_grep_keys("/^0-job-/", $activity)); - $streams = count(preg_grep_keys("/^6-stream-/", $activity)); - $data["recordings"] = number_format($recordings); - $data["streams"] = number_format($streams); - $status = "active"; - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url("dvr")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("dvr")); + $details = json_decode($res->getBody(), true); + + $data = []; + + $activity = $details["activity"]; + $recordings = count(preg_grep_keys("/^0-job-/", $activity)); + $streams = count(preg_grep_keys("/^6-stream-/", $activity)); + $data["recordings"] = number_format($recordings); + $data["streams"] = number_format($streams); + $status = "active"; + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Checkmk/Checkmk.php b/Checkmk/Checkmk.php index 3ec691d3a7..2012765e79 100644 --- a/Checkmk/Checkmk.php +++ b/Checkmk/Checkmk.php @@ -1,4 +1,6 @@ -getRequestAttrs(); - $test = parent::appTest($this->url("version"), $attrs); - echo $test->status; - } - - public function livestats() - { - $status = "active"; - $attrs = $this->getRequestAttrs(); - - // Outbound mode - $res = $this->apiCall("configs"); - $outbound_mode = ucfirst($res->mode); - - // Selector value - $sel_name = $this->getConfigValue("sel_name", ""); - $res = $this->apiCall("proxies"); - $sel_value = - isset($res) && - isset($res->proxies) && - isset($res->proxies->{$sel_name}) - ? $res->proxies->{$sel_name}->now - : ""; - - $data = [ - "outbound_mode" => $outbound_mode, - "sel_name" => $sel_name, - "sel_value" => $sel_value, - ]; - - return parent::getLiveStats($status, $data); - } - - // Utils - - public function getRequestAttrs() - { - $token_value = $this->getConfigValue("password", ""); - $auth = "Bearer " . $token_value; - - $attrs["headers"] = [ - "Accept" => "application/json", - "Authorization" => $auth, - ]; - - return $attrs; - } - - public function apiCall($endpoint) - { - $res = parent::execute($this->url($endpoint), $this->getRequestAttrs()); - return json_decode($res->getBody()); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl( - $this->getConfigValue("override_url", $this->config->url) - ) . $endpoint; - return $api_url; - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public $config; + + public function __construct() + { + } + + public function test() + { + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("version"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "active"; + $attrs = $this->getRequestAttrs(); + + // Outbound mode + $res = $this->apiCall("configs"); + $outbound_mode = ucfirst($res->mode); + + // Selector value + $sel_name = $this->getConfigValue("sel_name", ""); + $res = $this->apiCall("proxies"); + $sel_value = + isset($res) && + isset($res->proxies) && + isset($res->proxies->{$sel_name}) + ? $res->proxies->{$sel_name}->now + : ""; + + $data = [ + "outbound_mode" => $outbound_mode, + "sel_name" => $sel_name, + "sel_value" => $sel_value, + ]; + + return parent::getLiveStats($status, $data); + } + + // Utils + + public function getRequestAttrs() + { + $token_value = $this->getConfigValue("password", ""); + $auth = "Bearer " . $token_value; + + $attrs["headers"] = [ + "Accept" => "application/json", + "Authorization" => $auth, + ]; + + return $attrs; + } + + public function apiCall($endpoint) + { + $res = parent::execute($this->url($endpoint), $this->getRequestAttrs()); + return json_decode($res->getBody()); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl( + $this->getConfigValue("override_url", $this->config->url) + ) . $endpoint; + return $api_url; + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } } diff --git a/CloudCMD/CloudCMD.php b/CloudCMD/CloudCMD.php index f0f8aeb436..e095688c54 100644 --- a/CloudCMD/CloudCMD.php +++ b/CloudCMD/CloudCMD.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("app.available")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - - $movies = json_decode( - parent::execute($this->url("movie.list"))->getBody() - ); - $collect = collect($movies->movies); - $missing = $collect->where("status", "!=", "done"); - if ($missing) { - $data["missing"] = $missing->count() ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/" . - $this->config->apikey . - "/" . - $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("app.available")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + + $movies = json_decode( + parent::execute($this->url("movie.list"))->getBody() + ); + $collect = collect($movies->movies); + $missing = $collect->where("status", "!=", "done"); + if ($missing) { + $data["missing"] = $missing->count() ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/" . + $this->config->apikey . + "/" . + $endpoint; + return $api_url; + } } diff --git a/CryptPad/CryptPad.php b/CryptPad/CryptPad.php index 428b481d60..a7331be770 100644 --- a/CryptPad/CryptPad.php +++ b/CryptPad/CryptPad.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set - } + public function __construct() + { + $this->jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set + } - public function login() - { - $password = $this->config->password; - $attrs = [ - "body" => - '{"method": "auth.login", "params": ["' . - $password . - '"], "id": 1}', - "cookies" => $this->jar, - "headers" => [ - "content-type" => "application/json", - "Accept" => "application/json", - ], - ]; - return parent::appTest($this->url("json"), $attrs); - } + public function login() + { + $password = $this->config->password; + $attrs = [ + "body" => + '{"method": "auth.login", "params": ["' . + $password . + '"], "id": 1}', + "cookies" => $this->jar, + "headers" => [ + "content-type" => "application/json", + "Accept" => "application/json", + ], + ]; + return parent::appTest($this->url("json"), $attrs); + } - public function test() - { - $test = $this->login(); - if ($test->code === 200) { - $data = json_decode($test->response); - if ( - !isset($data->result) || - is_null($data->result) || - $data->result == false - ) { - $test->status = "Failed: Invalid Credentials"; - } - } - echo $test->status; - } + public function test() + { + $test = $this->login(); + if ($test->code === 200) { + $data = json_decode($test->response); + if ( + !isset($data->result) || + is_null($data->result) || + $data->result == false + ) { + $test->status = "Failed: Invalid Credentials"; + } + } + echo $test->status; + } - public function livestats() - { - $test = $this->login(); - $status = "inactive"; - $attrs = [ - "body" => - '{"method": "web.update_ui", "params": [["none"], {}], "id": 1}', - "cookies" => $this->jar, - "headers" => [ - "content-type" => "application/json", - "Accept" => "application/json", - ], - ]; - $res = parent::execute($this->url("json"), $attrs); - $details = json_decode($res->getBody()); + public function livestats() + { + $test = $this->login(); + $status = "inactive"; + $attrs = [ + "body" => + '{"method": "web.update_ui", "params": [["none"], {}], "id": 1}', + "cookies" => $this->jar, + "headers" => [ + "content-type" => "application/json", + "Accept" => "application/json", + ], + ]; + $res = parent::execute($this->url("json"), $attrs); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - if ($details) { - $states = $details->result->filters->state; - $download_rate = $details->result->stats->download_rate ?? 0; - $upload_rate = $details->result->stats->upload_rate ?? 0; - $data["download_rate"] = format_bytes( - $download_rate, - false, - " ", - "/s" - ); - $data["upload_rate"] = format_bytes( - $upload_rate, - false, - " ", - "/s" - ); - $data["seed_count"] = self::getState($states, "Seeding"); - $data["leech_count"] = self::getState($states, "Downloading"); - $status = - self::getState($states, "Active") > 0 ? "active" : "inactive"; - } + if ($details) { + $states = $details->result->filters->state; + $download_rate = $details->result->stats->download_rate ?? 0; + $upload_rate = $details->result->stats->upload_rate ?? 0; + $data["download_rate"] = format_bytes( + $download_rate, + false, + " ", + "/s" + ); + $data["upload_rate"] = format_bytes( + $upload_rate, + false, + " ", + "/s" + ); + $data["seed_count"] = self::getState($states, "Seeding"); + $data["leech_count"] = self::getState($states, "Downloading"); + $status = + self::getState($states, "Active") > 0 ? "active" : "inactive"; + } - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } - protected static function getState( - array $states, - string $wantedState, - int $default = 0 - ): int { - $state = Arr::first($states, function (array $state) use ( - $wantedState - ) { - return $state[0] == $wantedState; - }); + protected static function getState( + array $states, + string $wantedState, + int $default = 0 + ): int { + $state = Arr::first($states, function (array $state) use ( + $wantedState + ) { + return $state[0] == $wantedState; + }); - return Arr::get($state, 1, $default); - } + return Arr::get($state, 1, $default); + } } diff --git a/Dillinger/Dillinger.php b/Dillinger/Dillinger.php index 181d0e7a92..539a0f7756 100644 --- a/Dillinger/Dillinger.php +++ b/Dillinger/Dillinger.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("type=command¶m=getversion")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute( - $this->url("type=devices&rid=" . $this->config->deviceidx) - ); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["today"] = $details->result[0]->CounterToday ?? 0; - $data["usage"] = $details->result[0]->Usage ?? 0; - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . "json.htm?" . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("type=command¶m=getversion")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute( + $this->url("type=devices&rid=" . $this->config->deviceidx) + ); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["today"] = $details->result[0]->CounterToday ?? 0; + $data["usage"] = $details->result[0]->Usage ?? 0; + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . "json.htm?" . $endpoint; + return $api_url; + } } diff --git a/DoubleCommander/DoubleCommander.php b/DoubleCommander/DoubleCommander.php index 5f695d3740..7f6b524f89 100644 --- a/DoubleCommander/DoubleCommander.php +++ b/DoubleCommander/DoubleCommander.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("rr_status?type=3")); - $printer_status = $job_progress = 0; - - $details = json_decode($res->getBody()); - - // Get current printer status (only three basic supported (at least for now)) - switch ($details->status) { - case "I": - $printer_status = "Idle"; - break; - case "P": - $printer_status = "Printing"; - break; - case "S": - $printer_status = "Stopped"; - break; - case "B": - $printer_status = "Busy"; - break; - - default: - $printer_status = "Unknown"; - } - - // Get current job percentage - $job_progress = $details->fractionPrinted; - - $data["printer_status"] = $printer_status ?? "Off"; - $data["job_progress"] = $job_progress . "%" ?? "Off"; - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("rr_status?type=3")); + $printer_status = $job_progress = 0; + + $details = json_decode($res->getBody()); + + // Get current printer status (only three basic supported (at least for now)) + switch ($details->status) { + case "I": + $printer_status = "Idle"; + break; + case "P": + $printer_status = "Printing"; + break; + case "S": + $printer_status = "Stopped"; + break; + case "B": + $printer_status = "Busy"; + break; + + default: + $printer_status = "Unknown"; + } + + // Get current job percentage + $job_progress = $details->fractionPrinted; + + $data["printer_status"] = $printer_status ?? "Off"; + $data["job_progress"] = $job_progress . "%" ?? "Off"; + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Duplicacy/Duplicacy.php b/Duplicacy/Duplicacy.php index 090f6a2bbe..8d8bb17bba 100644 --- a/Duplicacy/Duplicacy.php +++ b/Duplicacy/Duplicacy.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); - } + } - public function test() - { - try { - $authResponse = $this->auth(); + public function test() + { + try { + $authResponse = $this->auth(); $serverState = $this->getServerState(); //var_dump($serverState); - echo "Successfully communicated with the API"; - } catch (Exception $err) { - echo "Error connecting to Duplicati: " . $err->getMessage(); - } - } + echo "Successfully communicated with the API"; + } catch (Exception $err) { + echo "Error connecting to Duplicati: " . $err->getMessage(); + } + } - public function auth() - { + public function auth() + { // Auth flow references // https://github.com/duplicati/duplicati/blob/master/Duplicati/Server/webroot/login/login.js // https://github.com/Pectojin/duplicati-client/blob/master/auth.py @@ -52,50 +55,48 @@ public function auth() } return $passResponse; + } - } - - public function livestats() - { - $status = "inactive"; + public function livestats() + { + $status = "inactive"; - $authResponse = $this->auth(); + $authResponse = $this->auth(); $serverState = $this->getServerState(); - + $nextTime = $this->getNextTime($serverState); - if($nextTime == "Running" || str_contains($nextTime, "second")) - { + if ($nextTime == "Running" || str_contains($nextTime, "second")) { $status = "active"; } - $data = [ - "error" => $serverState["HasWarning"] || $serverState["HasError"] ? "Yes" : "No", + $data = [ + "error" => $serverState["HasWarning"] || $serverState["HasError"] ? "Yes" : "No", "nextBackup" => $nextTime - ]; + ]; return parent::getLiveStats($status, $data); - } + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } - private function getNoncedPassword($password) + private function getNoncedPassword($password) { $nonceDetails = $this->getNonce(); $nonce = $nonceDetails["Nonce"]; $salt = $nonceDetails["Salt"]; - + // Prepare nonced+salted password $encodedPassword = mb_convert_encoding($password, 'UTF-8', 'ISO-8859-1'); - $saltedPasssword = $encodedPassword. base64_decode($salt); + $saltedPasssword = $encodedPassword . base64_decode($salt); $hashedSaltedPassword = hash('sha256', $saltedPasssword, true); @@ -106,7 +107,6 @@ private function getNoncedPassword($password) $encodedHashedNoncedPassword = base64_encode($hashedNoncedPassword); return $encodedHashedNoncedPassword; - } private function getNonce() @@ -132,112 +132,106 @@ private function getNonce() $nonceBody = $nonceResponse->getBody(); $nonceBodyData = $nonceBody->read(50 * 1024); - $nonceDetails = json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $nonceBodyData), true ); - - return $nonceDetails; + $nonceDetails = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $nonceBodyData), true); + return $nonceDetails; } private function getServerState() { $attrs = [ - "cookies" => $this->jar, - "headers" => [ + "cookies" => $this->jar, + "headers" => [ "content-type" => "application/json", "X-XSRF-Token" => urldecode($this->jar->getCookieByName("xsrf-token")->getValue()) ], - ]; - $result = parent::execute( - $this->url("api/v1/ServerState"), - $attrs, - null - ); + ]; + $result = parent::execute( + $this->url("api/v1/ServerState"), + $attrs, + null + ); - if (null === $result || $result->getStatusCode() !== 200) { - throw new Exception("Error retrieving server state"); - } + if (null === $result || $result->getStatusCode() !== 200) { + throw new Exception("Error retrieving server state"); + } $serverStateData = $result->getBody()->read(50 * 1024); - $serverState = json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $serverStateData), true ); + $serverState = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $serverStateData), true); return $serverState; } private function getNextTime($serverState) { - if($serverState["ProgramState"] === "Paused") - { + if ($serverState["ProgramState"] === "Paused") { return "Paused"; } - if($serverState["ActiveTask"] !== null) - { + if ($serverState["ActiveTask"] !== null) { return "Running"; } - if(count($serverState["ProposedSchedule"]) === 0) - { + if (count($serverState["ProposedSchedule"]) === 0) { return "None"; } $dates = []; - foreach($serverState["ProposedSchedule"] as $scheduleItem) - { + foreach ($serverState["ProposedSchedule"] as $scheduleItem) { $dates[] = strtotime($scheduleItem["Item2"]); } - return $this->get_date_diff(min($dates), time()); - + return $this->getDateDiff(min($dates), time()); } - private function get_date_diff($time1, $time2, $precision = 1) + private function getDateDiff($time1, $time2, $precision = 1) { // If not numeric then convert timestamps - if( !is_int( $time1 ) ) { - $time1 = strtotime( $time1 ); + if (!is_int($time1)) { + $time1 = strtotime($time1); } - if( !is_int( $time2 ) ) { - $time2 = strtotime( $time2 ); + if (!is_int($time2)) { + $time2 = strtotime($time2); } - + // If time1 > time2 then swap the 2 values - if( $time1 > $time2 ) { + if ($time1 > $time2) { list( $time1, $time2 ) = array( $time2, $time1 ); } - + // Set up intervals and diffs arrays $intervals = array( 'year', 'month', 'day', 'hour', 'minute', 'second' ); $diffs = array(); - - foreach( $intervals as $interval ) { + + foreach ($intervals as $interval) { // Create temp time from time1 and interval - $ttime = strtotime( '+1 ' . $interval, $time1 ); + $ttime = strtotime('+1 ' . $interval, $time1); // Set initial values $add = 1; $looped = 0; // Loop until temp time is smaller than time2 - while ( $time2 >= $ttime ) { + while ($time2 >= $ttime) { // Create new temp time from time1 and interval $add++; - $ttime = strtotime( "+" . $add . " " . $interval, $time1 ); + $ttime = strtotime("+" . $add . " " . $interval, $time1); $looped++; } - - $time1 = strtotime( "+" . $looped . " " . $interval, $time1 ); + + $time1 = strtotime("+" . $looped . " " . $interval, $time1); $diffs[ $interval ] = $looped; } - + $count = 0; $times = array(); - foreach( $diffs as $interval => $value ) { + foreach ($diffs as $interval => $value) { // Break if we have needed precission - if( $count >= $precision ) { + if ($count >= $precision) { break; } // Add value and interval if value is bigger than 0 - if( $value > 0 ) { - if( $value != 1 ){ + if ($value > 0) { + if ($value != 1) { $interval .= "s"; } // Add value and interval to times array @@ -245,9 +239,8 @@ private function get_date_diff($time1, $time2, $precision = 1) $count++; } } - + // Return string with times - return implode( ", ", $times ); + return implode(", ", $times); } - } diff --git a/ESPHome/ESPHome.php b/ESPHome/ESPHome.php index 9a4283973f..3d1f7f2491 100644 --- a/ESPHome/ESPHome.php +++ b/ESPHome/ESPHome.php @@ -1,4 +1,6 @@ -url("System/Info"), $this->getAttrs()); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("System/Info"), $this->getAttrs()); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute( - $this->url("/emby/Items/Counts"), - $this->getAttrs() - ); - $result = json_decode($res->getBody()); - $details = ["visiblestats" => []]; - foreach ($this->config->availablestats as $stat) { - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = $result->{$stat}; - $details["visiblestats"][] = $newstat; - } - return parent::getLiveStats($status, $details); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function livestats() + { + $status = "inactive"; + $res = parent::execute( + $this->url("/emby/Items/Counts"), + $this->getAttrs() + ); + $result = json_decode($res->getBody()); + $details = ["visiblestats" => []]; + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = $result->{$stat}; + $details["visiblestats"][] = $newstat; + } + return parent::getLiveStats($status, $details); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } - private function getAttrs() - { - return [ - "headers" => [ - "X-Emby-Token" => $this->config->password, - ], - ]; - } + private function getAttrs() + { + return [ + "headers" => [ + "X-Emby-Token" => $this->config->password, + ], + ]; + } - public static function getAvailableStats() - { - return [ - "MovieCount" => "Movies", - "SeriesCount" => "Series", - "EpisodeCount" => "Episodes", - "GameCount" => "Games", - "ArtistCount" => "Artists", - "ProgramCount" => "Programs", - "GameSystemCount" => "GameSystems", - "TrailerCount" => "Trailers", - "SongCount" => "Songs", - "AlbumCount" => "Albums", - "MusicVideoCount" => "MusicVideos", - "BoxSetCount" => "BoxSets", - "BookCount" => "Books", - "ItemCount" => "Items", - ]; - } + public static function getAvailableStats() + { + return [ + "MovieCount" => "Movies", + "SeriesCount" => "Series", + "EpisodeCount" => "Episodes", + "GameCount" => "Games", + "ArtistCount" => "Artists", + "ProgramCount" => "Programs", + "GameSystemCount" => "GameSystems", + "TrailerCount" => "Trailers", + "SongCount" => "Songs", + "AlbumCount" => "Albums", + "MusicVideoCount" => "MusicVideos", + "BoxSetCount" => "BoxSets", + "BookCount" => "Books", + "ItemCount" => "Items", + ]; + } } diff --git a/EmbyStat/EmbyStat.php b/EmbyStat/EmbyStat.php index d8c8ade00e..32de929b1d 100644 --- a/EmbyStat/EmbyStat.php +++ b/EmbyStat/EmbyStat.php @@ -1,4 +1,6 @@ -url("/api/status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("/api/status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $data = []; - $url = $this->url("api/status"); - $res = parent::execute($url); + public function livestats() + { + $status = "inactive"; + $data = []; + $url = $this->url("api/status"); + $res = parent::execute($url); - $body = $res->getBody(); - $details = json_decode($body); - if ($details) { - $data["queue"] = $details->queue; - if (strlen($details->time) == 0) { - if ($details->processing == 0) { - $data["second_label"] = "Processed"; - $data["second_value"] = $details->processed; - } else { - $data["second_label"] = "Processing"; - $data["second_value"] = $details->processing; - } - } else { - $data["second_label"] = "Time"; - $data["second_value"] = $details->time; - } - } + $body = $res->getBody(); + $details = json_decode($body); + if ($details) { + $data["queue"] = $details->queue; + if (strlen($details->time) == 0) { + if ($details->processing == 0) { + $data["second_label"] = "Processed"; + $data["second_value"] = $details->processed; + } else { + $data["second_label"] = "Processing"; + $data["second_value"] = $details->processing; + } + } else { + $data["second_label"] = "Time"; + $data["second_value"] = $details->time; + } + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/FileRun/FileRun.php b/FileRun/FileRun.php index fb9e6d9865..e3fe2f6c0b 100644 --- a/FileRun/FileRun.php +++ b/FileRun/FileRun.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $this->setSID(); - $test = parent::appTest($this->url($this->updateURI())); - echo $test->status; - } - public function livestats() - { - $status = "inactive"; - $this->setSID(); - $res = parent::execute($this->url($this->updateURI())); - $details = json_decode($res->getBody(), true); - $status = $details[1][1][0]["status"]; - $progress = isset($details[1][1][0]["percentdone"]) - ? $details[1][1][0]["percentdone"] - : "N/A"; - $eta = isset($details[1][1][0]["eta"]) - ? $details[1][1][0]["eta"] - : "N/A"; + public function test() + { + $this->setSID(); + $test = parent::appTest($this->url($this->updateURI())); + echo $test->status; + } + public function livestats() + { + $status = "inactive"; + $this->setSID(); + $res = parent::execute($this->url($this->updateURI())); + $details = json_decode($res->getBody(), true); + $status = $details[1][1][0]["status"]; + $progress = isset($details[1][1][0]["percentdone"]) + ? $details[1][1][0]["percentdone"] + : "N/A"; + $eta = isset($details[1][1][0]["eta"]) + ? $details[1][1][0]["eta"] + : "N/A"; - $data = [ - "status" => $status, - "progress" => $progress, - "eta" => $eta, - ]; - return parent::getLiveStats($status, $data); - } + $data = [ + "status" => $status, + "progress" => $progress, + "eta" => $eta, + ]; + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - public function setSID() - { - if (empty($this->sid)) { - $rand = mt_rand() / mt_getrandmax(); - $res = parent::execute( - $this->url("api/session?_=" . $rand), - [], - [], - "PUT" - ); - $this->sid = (string) $res->getBody(); + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + public function setSID() + { + if (empty($this->sid)) { + $rand = mt_rand() / mt_getrandmax(); + $res = parent::execute( + $this->url("api/session?_=" . $rand), + [], + [], + "PUT" + ); + $this->sid = (string) $res->getBody(); - $query_data = [ - "sid" => $this->sid, - "update_id" => 0, - "update_rate" => 1, - "update_path" => "/api/basic", - "_" => time(), - ]; - $res2 = parent::execute($this->url("api/updates/set"), [ - "query" => $query_data, - ]); - $query_data2 = [ - "sid" => $this->sid, - "update_id" => 1, - "update_rate" => 1, - "update_path" => "/api/slots", - "_" => time(), - ]; - $res3 = parent::execute($this->url("api/updates/set"), [ - "query" => $query_data2, - ]); - $query_data3 = [ - "sid" => $this->sid, - "_" => time(), - ]; - $res4 = parent::execute($this->url("api/configured"), [ - "query" => $query_data3, - ]); - } - } - public function updateURI() - { - $query_url = "api/updates?sid="; - $query_url .= $this->sid; - $query_url .= "&_="; - $query_url .= time(); - return $query_url; - } + $query_data = [ + "sid" => $this->sid, + "update_id" => 0, + "update_rate" => 1, + "update_path" => "/api/basic", + "_" => time(), + ]; + $res2 = parent::execute($this->url("api/updates/set"), [ + "query" => $query_data, + ]); + $query_data2 = [ + "sid" => $this->sid, + "update_id" => 1, + "update_rate" => 1, + "update_path" => "/api/slots", + "_" => time(), + ]; + $res3 = parent::execute($this->url("api/updates/set"), [ + "query" => $query_data2, + ]); + $query_data3 = [ + "sid" => $this->sid, + "_" => time(), + ]; + $res4 = parent::execute($this->url("api/configured"), [ + "query" => $query_data3, + ]); + } + } + public function updateURI() + { + $query_url = "api/updates?sid="; + $query_url .= $this->sid; + $query_url .= "&_="; + $query_url .= time(); + return $query_url; + } } diff --git a/Forgejo/Forgejo.php b/Forgejo/Forgejo.php index d0b33823ac..5f0a092fe1 100644 --- a/Forgejo/Forgejo.php +++ b/Forgejo/Forgejo.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest( - $this->url("outage/active?limit=1&offset=0&full=false"), - $this->getAttrs() - ); - echo $test->status; - } + public function test() + { + $test = parent::appTest( + $this->url("outage/active?limit=1&offset=0&full=false"), + $this->getAttrs() + ); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; + public function livestats() + { + $status = "inactive"; - $instancesList = json_decode( - parent::execute( - $this->url( - "server?limit=0&offset=0&full=false&status=active&tag_filter_mode=or" - ), - $this->getAttrs() - )->getBody() - ); - $outagesList = json_decode( - parent::execute( - $this->url("outage/active?limit=0&offset=0&full=false"), - $this->getAttrs() - )->getBody() - ); + $instancesList = json_decode( + parent::execute( + $this->url( + "server?limit=0&offset=0&full=false&status=active&tag_filter_mode=or" + ), + $this->getAttrs() + )->getBody() + ); + $outagesList = json_decode( + parent::execute( + $this->url("outage/active?limit=0&offset=0&full=false"), + $this->getAttrs() + )->getBody() + ); - $data = []; - if ($instancesList || $outagesList) { - $data["instances"] = count($instancesList->server_list) ?? 0; - $data["outages"] = count($outagesList->outage_list) ?? 0; - } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . "v2/" . $endpoint; - return $api_url; - } + $data = []; + if ($instancesList || $outagesList) { + $data["instances"] = count($instancesList->server_list) ?? 0; + $data["outages"] = count($outagesList->outage_list) ?? 0; + } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . "v2/" . $endpoint; + return $api_url; + } - private function getAttrs() - { - return [ - "headers" => [ - "Authorization" => "ApiKey " . $this->config->apikey, - ], - ]; - } + private function getAttrs() + { + return [ + "headers" => [ + "Authorization" => "ApiKey " . $this->config->apikey, + ], + ]; + } } diff --git a/FreePBX/FreePBX.php b/FreePBX/FreePBX.php index d1ea3caaa3..3e62e87929 100644 --- a/FreePBX/FreePBX.php +++ b/FreePBX/FreePBX.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("core/ping"), $this->attrs); - if ($test->code === 200) { - $data = $test->response; - if ($test->response != '"pong"') { - $test->status = "Failed: " . $data; - } - } - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - - $res = parent::execute($this->url("system/info"), $this->attrs); - $details = json_decode($res->getBody()); - $seconds = $details->uptime_seconds ?? 0; - $data["uptime"] = $this->uptime($seconds); - - $res = parent::execute($this->url("alert/list"), $this->attrs); - $details = json_decode($res->getBody(), true); - $data["alert_tot"] = $this->alerts($details); - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $this->attrs = [ - "auth" => [ - $this->config->username, - $this->config->password, - "Basic", - ], - ]; - $api_url = - parent::normaliseurl($this->config->url) . "api/v2.0/" . $endpoint; - return $api_url; - } - - public function uptime($inputSeconds) - { - // Adapted from https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds - - $res = ""; - $secondsInAMinute = 60; - $secondsInAnHour = 60 * $secondsInAMinute; - $secondsInADay = 24 * $secondsInAnHour; - - // extract days - $days = floor($inputSeconds / $secondsInADay); - - // extract hours - $hourSeconds = $inputSeconds % $secondsInADay; - $hours = floor($hourSeconds / $secondsInAnHour); - - // extract minutes - $minuteSeconds = $hourSeconds % $secondsInAnHour; - $minutes = floor($minuteSeconds / $secondsInAMinute); - - // extract the remaining seconds - $remainingSeconds = $minuteSeconds % $secondsInAMinute; - $seconds = ceil($remainingSeconds); - - //$res = strval($days).'d '.strval($hours).':'.sprintf('%02d', $minutes).':'.sprintf('%02d', $seconds); - if ($days > 0) { - $res = - strval($days) . - "d " . - strval($hours) . - ":" . - sprintf("%02d", $minutes); - } else { - $res = - strval($hours) . - ":" . - sprintf("%02d", $minutes) . - ":" . - sprintf("%02d", $seconds); - } - return $res; - } - - public function alerts($alert) - { - $count = 0; - foreach ($alert as $key => $value) { - if ($value["dismissed"] == false) { - $count += 1; - } - } - return strval($count); - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("core/ping"), $this->attrs); + if ($test->code === 200) { + $data = $test->response; + if ($test->response != '"pong"') { + $test->status = "Failed: " . $data; + } + } + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + + $res = parent::execute($this->url("system/info"), $this->attrs); + $details = json_decode($res->getBody()); + $seconds = $details->uptime_seconds ?? 0; + $data["uptime"] = $this->uptime($seconds); + + $res = parent::execute($this->url("alert/list"), $this->attrs); + $details = json_decode($res->getBody(), true); + $data["alert_tot"] = $this->alerts($details); + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $this->attrs = [ + "auth" => [ + $this->config->username, + $this->config->password, + "Basic", + ], + ]; + $api_url = + parent::normaliseurl($this->config->url) . "api/v2.0/" . $endpoint; + return $api_url; + } + + public function uptime($inputSeconds) + { + // Adapted from https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds + + $res = ""; + $secondsInAMinute = 60; + $secondsInAnHour = 60 * $secondsInAMinute; + $secondsInADay = 24 * $secondsInAnHour; + + // extract days + $days = floor($inputSeconds / $secondsInADay); + + // extract hours + $hourSeconds = $inputSeconds % $secondsInADay; + $hours = floor($hourSeconds / $secondsInAnHour); + + // extract minutes + $minuteSeconds = $hourSeconds % $secondsInAnHour; + $minutes = floor($minuteSeconds / $secondsInAMinute); + + // extract the remaining seconds + $remainingSeconds = $minuteSeconds % $secondsInAMinute; + $seconds = ceil($remainingSeconds); + + //$res = strval($days).'d '.strval($hours).':'.sprintf('%02d', $minutes).':'.sprintf('%02d', $seconds); + if ($days > 0) { + $res = + strval($days) . + "d " . + strval($hours) . + ":" . + sprintf("%02d", $minutes); + } else { + $res = + strval($hours) . + ":" . + sprintf("%02d", $minutes) . + ":" . + sprintf("%02d", $seconds); + } + return $res; + } + + public function alerts($alert) + { + $count = 0; + foreach ($alert as $key => $value) { + if ($value["dismissed"] == false) { + $count += 1; + } + } + return strval($count); + } } diff --git a/FreshRSS/FreshRSS.php b/FreshRSS/FreshRSS.php index d203022f72..5cff35904f 100644 --- a/FreshRSS/FreshRSS.php +++ b/FreshRSS/FreshRSS.php @@ -1,89 +1,91 @@ - false, - "timeout" => 15, - "connect_timeout" => 15, - "verify" => false, - ]; + private $clientVars = [ + "http_errors" => false, + "timeout" => 15, + "connect_timeout" => 15, + "verify" => false, + ]; - public function test() - { - $attrs = [ - "body" => "api_key=" . $this->getApiKey(), - "headers" => [ - "Content-Type" => "application/x-www-form-urlencoded", - ], - ]; + public function test() + { + $attrs = [ + "body" => "api_key=" . $this->getApiKey(), + "headers" => [ + "Content-Type" => "application/x-www-form-urlencoded", + ], + ]; - $res = parent::execute( - $this->url("api/fever.php?api"), - $attrs, - $this->clientVars, - "POST" - ); + $res = parent::execute( + $this->url("api/fever.php?api"), + $attrs, + $this->clientVars, + "POST" + ); - if ($res->getStatusCode() == 200) { - $data = json_decode($res->getBody()); - if ($data != null && $data->auth === 1) { - echo "Welcome " . - $this->config->username . - ", you are connected to API v" . - $data->api_version; - } - } - } + if ($res->getStatusCode() == 200) { + $data = json_decode($res->getBody()); + if ($data != null && $data->auth === 1) { + echo "Welcome " . + $this->config->username . + ", you are connected to API v" . + $data->api_version; + } + } + } - public function livestats() - { - $status = "inactive"; - $data = []; + public function livestats() + { + $status = "inactive"; + $data = []; - $attrs = [ - "body" => "api_key=" . $this->getApiKey(), - "headers" => [ - "Content-Type" => "application/x-www-form-urlencoded", - ], - ]; + $attrs = [ + "body" => "api_key=" . $this->getApiKey(), + "headers" => [ + "Content-Type" => "application/x-www-form-urlencoded", + ], + ]; - $res = parent::execute( - $this->url("api/fever.php?api&unread_item_ids"), - $attrs, - $this->clientVars, - "POST" - ); - if ($res->getStatusCode() == 200) { - $body = json_decode($res->getBody()); - if ($body->auth === 1) { - if ($body->unread_item_ids != "") { - $data["unread"] = count( - explode(",", $body->unread_item_ids) - ); - } else { - $data["unread"] = 0; - } - } - } + $res = parent::execute( + $this->url("api/fever.php?api&unread_item_ids"), + $attrs, + $this->clientVars, + "POST" + ); + if ($res->getStatusCode() == 200) { + $body = json_decode($res->getBody()); + if ($body->auth === 1) { + if ($body->unread_item_ids != "") { + $data["unread"] = count( + explode(",", $body->unread_item_ids) + ); + } else { + $data["unread"] = 0; + } + } + } - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } - public function getApiKey() - { - return md5($this->config->username . ":" . $this->config->apikey); - } + public function getApiKey() + { + return md5($this->config->username . ":" . $this->config->apikey); + } } diff --git a/Frigate/Frigate.php b/Frigate/Frigate.php index 710585f269..5ae6c9e003 100644 --- a/Frigate/Frigate.php +++ b/Frigate/Frigate.php @@ -1,4 +1,6 @@ -url("solar_api/GetAPIVersion.cgi")); - echo $test->status; - } - - public function livestats() - { - $status = "active"; - - $attrs["query"] = ["Scope" => "System"]; - $res = parent::execute( - $this->url("solar_api/v1/GetInverterRealtimeData.cgi"), - $attrs - ); - $details = json_decode($res->getBody()); - - $data = []; - $data["PAC"] = 0; - foreach ($details->Body->Data->PAC->Values as $key => $pac) { - $data["PAC"] += round($pac,0,PHP_ROUND_HALF_UP); - } - $data["PAC_UNIT"] = $details->Body->Data->PAC->Unit; - - $data["DAY_ENERGY"] = 0; - foreach ($details->Body->Data->DAY_ENERGY->Values as $key => $ev) { - $data["DAY_ENERGY"] += round($ev,0,PHP_ROUND_HALF_UP); - } - $data["DAY_ENERGY_UNIT"] = $details->Body->Data->DAY_ENERGY->Unit; - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url("solar_api/GetAPIVersion.cgi")); + echo $test->status; + } + + public function livestats() + { + $status = "active"; + + $attrs["query"] = ["Scope" => "System"]; + $res = parent::execute( + $this->url("solar_api/v1/GetInverterRealtimeData.cgi"), + $attrs + ); + $details = json_decode($res->getBody()); + + $data = []; + $data["PAC"] = 0; + foreach ($details->Body->Data->PAC->Values as $key => $pac) { + $data["PAC"] += round($pac, 0, PHP_ROUND_HALF_UP); + } + $data["PAC_UNIT"] = $details->Body->Data->PAC->Unit; + + $data["DAY_ENERGY"] = 0; + foreach ($details->Body->Data->DAY_ENERGY->Values as $key => $ev) { + $data["DAY_ENERGY"] += round($ev, 0, PHP_ROUND_HALF_UP); + } + $data["DAY_ENERGY_UNIT"] = $details->Body->Data->DAY_ENERGY->Unit; + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Funkwhale/Funkwhale.php b/Funkwhale/Funkwhale.php index 797125de07..5e72a9aa3c 100644 --- a/Funkwhale/Funkwhale.php +++ b/Funkwhale/Funkwhale.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set } public function test() { - $test = parent::appTest($this->url('/v2/version'), ['auth' => [$this->config->username, $this->config->password]]); + $test = parent::appTest($this->url('/v2/version'), ['auth' => [$this->config->username, + $this->config->password]]); $details = json_decode($test->response); if ($details && isset($details->version)) { echo $test->status . "\nServer version: " . $details->version; @@ -25,13 +29,14 @@ public function test() public function livestats() { $status = 'inactive'; - $res = parent::execute($this->url('/v2/projects'), ['auth' => [$this->config->username, $this->config->password]]); + $res = parent::execute($this->url('/v2/projects'), ['auth' => [$this->config->username, + $this->config->password]]); $details = json_decode($res->getBody()); $data = []; $data["opened"] = 0; $data["closed"] = 0; - + foreach ($details as $project) { if ($project->status == "opened") { $data["opened"]++; @@ -39,13 +44,12 @@ public function livestats() $data["closed"]++; } } - + return parent::getLiveStats($status, $data); - } public function url($endpoint) { - $api_url = parent::normaliseurl($this->config->url, false).$endpoint; + $api_url = parent::normaliseurl($this->config->url, false) . $endpoint; return $api_url; } } diff --git a/Gardener/Gardener.php b/Gardener/Gardener.php index 21820caed0..d64d7cc3ab 100644 --- a/Gardener/Gardener.php +++ b/Gardener/Gardener.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set - $this->authorized = false; - } - - public function test() - { - try { - $this->auth(); - echo "Successfully communicated with the API"; - } catch (Exception $err) { - echo "Error connecting to Ghost: " . $err->getMessage(); - } - } - - public function auth() - { - if ($this->authorized) { - return; - } - - $this->authorized = false; - - $attrs = [ - "cookies" => $this->jar, - "headers" => ["content-type" => "application/json"], - ]; - $body["username"] = $this->config->username; - $body["password"] = $this->config->password; - $vars = [ - "http_errors" => false, - "timeout" => 5, - "body" => json_encode($body), - ]; - - $result = parent::execute( - $this->url("ghost/api/v3/admin/session"), - $attrs, - $vars, - "POST" - ); - - if (null === $result) { - throw new Exception("Error contacting the API"); - } - - if ($result->getStatusCode() !== 201) { - switch ($result->getStatusCode()) { - case 404: - throw new Exception("User is not found"); - case 422: - throw new Exception("Invalid credentials"); - } - - throw new Exception("Unknown error"); - } - - $this->authorized = true; - return $result; - } - - public function livestats() - { - $status = "inactive"; - - $this->auth(); - - $attrs = [ - "cookies" => $this->jar, - "headers" => ["content-type" => "application/json"], - ]; - $result = parent::execute( - $this->url("ghost/api/v3/admin/posts/"), - $attrs, - [] - ); - if (null === $result) { - throw new Exception("Could not connect to Ghost"); - } - - $response = json_decode($result->getBody()); - $posts = $response->posts; - $statuses = array_count_values(array_column($posts, "status")); - - $data = [ - "draft" => isset($statuses["draft"]) ? $statuses["draft"] : 0, - "scheduled" => isset($statuses["scheduled"]) - ? $statuses["scheduled"] - : 0, - "published" => isset($statuses["published"]) - ? $statuses["published"] - : 0, - ]; - $status = "active"; - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + public function __construct() + { + $this->jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set + $this->authorized = false; + } + + public function test() + { + try { + $this->auth(); + echo "Successfully communicated with the API"; + } catch (Exception $err) { + echo "Error connecting to Ghost: " . $err->getMessage(); + } + } + + public function auth() + { + if ($this->authorized) { + return; + } + + $this->authorized = false; + + $attrs = [ + "cookies" => $this->jar, + "headers" => ["content-type" => "application/json"], + ]; + $body["username"] = $this->config->username; + $body["password"] = $this->config->password; + $vars = [ + "http_errors" => false, + "timeout" => 5, + "body" => json_encode($body), + ]; + + $result = parent::execute( + $this->url("ghost/api/v3/admin/session"), + $attrs, + $vars, + "POST" + ); + + if (null === $result) { + throw new Exception("Error contacting the API"); + } + + if ($result->getStatusCode() !== 201) { + switch ($result->getStatusCode()) { + case 404: + throw new Exception("User is not found"); + case 422: + throw new Exception("Invalid credentials"); + } + + throw new Exception("Unknown error"); + } + + $this->authorized = true; + return $result; + } + + public function livestats() + { + $status = "inactive"; + + $this->auth(); + + $attrs = [ + "cookies" => $this->jar, + "headers" => ["content-type" => "application/json"], + ]; + $result = parent::execute( + $this->url("ghost/api/v3/admin/posts/"), + $attrs, + [] + ); + if (null === $result) { + throw new Exception("Could not connect to Ghost"); + } + + $response = json_decode($result->getBody()); + $posts = $response->posts; + $statuses = array_count_values(array_column($posts, "status")); + + $data = [ + "draft" => isset($statuses["draft"]) ? $statuses["draft"] : 0, + "scheduled" => isset($statuses["scheduled"]) + ? $statuses["scheduled"] + : 0, + "published" => isset($statuses["published"]) + ? $statuses["published"] + : 0, + ]; + $status = "active"; + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/GitHub/GitHub.php b/GitHub/GitHub.php index 28ed37e4d8..29a0314dd8 100644 --- a/GitHub/GitHub.php +++ b/GitHub/GitHub.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - if (!empty($this->config->health_apikey)) { - $test = parent::appTest( - $this->url( - "/-/readiness?token=" . - $this->config->health_apikey . - "&all=1" - ) - ); - echo $test->status; - } else { - echo "Health API key missing!"; - } - } + public function test() + { + if (!empty($this->config->health_apikey)) { + $test = parent::appTest( + $this->url( + "/-/readiness?token=" . + $this->config->health_apikey . + "&all=1" + ) + ); + echo $test->status; + } else { + echo "Health API key missing!"; + } + } - public function livestats() - { - $status = "inactive"; - $data = []; + public function livestats() + { + $status = "inactive"; + $data = []; - if (!empty($this->config->health_apikey)) { - $res1 = parent::execute( - $this->url( - "/-/readiness?token=" . - $this->config->health_apikey . - "&all=1" - ) - ); - $details1 = json_decode($res1->getBody()); - if ($details1) { - $data["status"] = $details1->status; - $status = $details1->status; - } - } + if (!empty($this->config->health_apikey)) { + $res1 = parent::execute( + $this->url( + "/-/readiness?token=" . + $this->config->health_apikey . + "&all=1" + ) + ); + $details1 = json_decode($res1->getBody()); + if ($details1) { + $data["status"] = $details1->status; + $status = $details1->status; + } + } - if (!empty($this->config->private_apikey)) { - $call_header["headers"] = [ - "PRIVATE-TOKEN" => $this->config->private_apikey, - ]; - $res2 = parent::execute( - $this->url("/api/v4/application/statistics"), - $call_header - ); - $details2 = json_decode($res2->getBody()); - if ( - $details2 && - isset($details2->projects) && - isset($details2->active_users) - ) { - $data["count_projects"] = $details2->projects; - $data["count_users"] = $details2->active_users; - } - } + if (!empty($this->config->private_apikey)) { + $call_header["headers"] = [ + "PRIVATE-TOKEN" => $this->config->private_apikey, + ]; + $res2 = parent::execute( + $this->url("/api/v4/application/statistics"), + $call_header + ); + $details2 = json_decode($res2->getBody()); + if ( + $details2 && + isset($details2->projects) && + isset($details2->active_users) + ) { + $data["count_projects"] = $details2->projects; + $data["count_users"] = $details2->active_users; + } + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Gitea/Gitea.php b/Gitea/Gitea.php index d1b91f4669..a7c6f1e789 100644 --- a/Gitea/Gitea.php +++ b/Gitea/Gitea.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - //echo $this->url('lineup.json?show=found'); - $test = parent::appTest($this->url("lineup.json?show=found")); - echo $test->status; - } + public function test() + { + //echo $this->url('lineup.json?show=found'); + $test = parent::appTest($this->url("lineup.json?show=found")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("lineup.json?show=found")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("lineup.json?show=found")); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - if ($details) { - $channel_count = count($details); - $data["number_of_channels"] = number_format($channel_count); - $status = "active"; - } + if ($details) { + $channel_count = count($details); + $data["number_of_channels"] = number_format($channel_count); + $status = "active"; + } - $res = parent::execute($this->url("tuners.html")); - $tunersBody = $res->getBody(); - if ($tunersBody) { - $exp = "/\\s*([^<]+)<\/td>\\s*([^<]+)<\/td><\/tr>/mi"; - preg_match_all($exp, $tunersBody, $matches, PREG_SET_ORDER, 0); - $inUse = 0; - $totalTuners = 0; - $match_count = count($matches); - for ($i = 0; $i < $match_count; $i++) { - if (count($matches[$i]) >= 2) { - if ( - $matches[$i][2] != "none" && - $matches[$i][2] != "not in use" - ) { - $inUse++; - } - } - $totalTuners++; - } - $data["tuners_in_use"] = number_format($inUse); - $data["tuners_total"] = number_format($totalTuners); - $status = "active"; - } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $res = parent::execute($this->url("tuners.html")); + $tunersBody = $res->getBody(); + if ($tunersBody) { + $exp = "/\\s*([^<]+)<\/td>\\s*([^<]+)<\/td><\/tr>/mi"; + preg_match_all($exp, $tunersBody, $matches, PREG_SET_ORDER, 0); + $inUse = 0; + $totalTuners = 0; + $match_count = count($matches); + for ($i = 0; $i < $match_count; $i++) { + if (count($matches[$i]) >= 2) { + if ( + $matches[$i][2] != "none" && + $matches[$i][2] != "not in use" + ) { + $inUse++; + } + } + $totalTuners++; + } + $data["tuners_in_use"] = number_format($inUse); + $data["tuners_total"] = number_format($totalTuners); + $status = "active"; + } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Handbrake/Handbrake.php b/Handbrake/Handbrake.php index 227c0e10a9..0dc6b2df49 100644 --- a/Handbrake/Handbrake.php +++ b/Handbrake/Handbrake.php @@ -1,4 +1,6 @@ -url('health')); - echo $test->status; - } - - public function livestats() - { - $status = 'inactive'; - $res = parent::execute($this->url('health')); - - if ($res->getStatusCode() > 299) { - $data = [ - 'error' => true, - 'statusCode' => $res->getStatusCode(), - 'items' => 0, - 'users' => 0, - ]; - return parent::getLiveStats($status, $data); - } - - $details = json_decode($res->getBody()); - - $data = [ - 'error' => false, - 'statusCode' => $res->getStatusCode(), - 'items' => $details->items, - 'users' => $details->users, - ]; - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url('health')); + echo $test->status; + } + + public function livestats() + { + $status = 'inactive'; + $res = parent::execute($this->url('health')); + + if ($res->getStatusCode() > 299) { + $data = [ + 'error' => true, + 'statusCode' => $res->getStatusCode(), + 'items' => 0, + 'users' => 0, + ]; + return parent::getLiveStats($status, $data); + } + + $details = json_decode($res->getBody()); + + $data = [ + 'error' => false, + 'statusCode' => $res->getStatusCode(), + 'items' => $details->items, + 'users' => $details->users, + ]; + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/HomeAssistant/HomeAssistant.php b/HomeAssistant/HomeAssistant.php index d259a21718..d49f929b4a 100644 --- a/HomeAssistant/HomeAssistant.php +++ b/HomeAssistant/HomeAssistant.php @@ -1,87 +1,89 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $attrs = [ - "headers" => [ - "Accept" => "application/json", - "Authorization" => "Bearer " . $this->config->token, - ], - ]; + public function test() + { + $attrs = [ + "headers" => [ + "Accept" => "application/json", + "Authorization" => "Bearer " . $this->config->token, + ], + ]; - $test = parent::appTest($this->url("api/"), $attrs); - echo $test->status; - } + $test = parent::appTest($this->url("api/"), $attrs); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; + public function livestats() + { + $status = "inactive"; - $first_stat_label = isset($this->config->first_stat_label) - ? $this->config->first_stat_label - : "Total lights"; - $first_stat_template = isset($this->config->first_stat_template) - ? $this->config->first_stat_template - : "{{ states.light | count}}"; - $second_stat_label = isset($this->config->second_stat_label) - ? $this->config->second_stat_label - : "Total lights On"; - $second_stat_template = isset($this->config->second_stat_template) - ? $this->config->second_stat_template - : '{{ states.light | selectattr(\'state\',\'equalto\',\'on\') | list | count }}'; + $first_stat_label = isset($this->config->first_stat_label) + ? $this->config->first_stat_label + : "Total lights"; + $first_stat_template = isset($this->config->first_stat_template) + ? $this->config->first_stat_template + : "{{ states.light | count}}"; + $second_stat_label = isset($this->config->second_stat_label) + ? $this->config->second_stat_label + : "Total lights On"; + $second_stat_template = isset($this->config->second_stat_template) + ? $this->config->second_stat_template + : '{{ states.light | selectattr(\'state\',\'equalto\',\'on\') | list | count }}'; - $first_attrs = [ - "headers" => [ - "Accept" => "application/json", - "Authorization" => "Bearer " . $this->config->token, - ], - "body" => json_encode(["template" => $first_stat_template]), - ]; - $first_res = parent::execute( - $this->url("api/template"), - $first_attrs, - null, - "POST" - ); - $first_value = $first_res->getBody(); + $first_attrs = [ + "headers" => [ + "Accept" => "application/json", + "Authorization" => "Bearer " . $this->config->token, + ], + "body" => json_encode(["template" => $first_stat_template]), + ]; + $first_res = parent::execute( + $this->url("api/template"), + $first_attrs, + null, + "POST" + ); + $first_value = $first_res->getBody(); - $second_attrs = [ - "headers" => [ - "Accept" => "application/json", - "Authorization" => "Bearer " . $this->config->token, - ], - "body" => json_encode(["template" => $second_stat_template]), - ]; - $second_res = parent::execute( - $this->url("api/template"), - $second_attrs, - null, - "POST" - ); - $second_value = $second_res->getBody(); + $second_attrs = [ + "headers" => [ + "Accept" => "application/json", + "Authorization" => "Bearer " . $this->config->token, + ], + "body" => json_encode(["template" => $second_stat_template]), + ]; + $second_res = parent::execute( + $this->url("api/template"), + $second_attrs, + null, + "POST" + ); + $second_value = $second_res->getBody(); - return parent::getLiveStats($status, [ - "first_stat_label" => $first_stat_label, - "first_stat_value" => $first_value, - "second_stat_label" => $second_stat_label, - "second_stat_value" => $second_value, - ]); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, [ + "first_stat_label" => $first_stat_label, + "first_stat_value" => $first_value, + "second_stat_label" => $second_stat_label, + "second_stat_value" => $second_value, + ]); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Homebox/Homebox.php b/Homebox/Homebox.php index 46933ebe6d..644a8fa1b6 100644 --- a/Homebox/Homebox.php +++ b/Homebox/Homebox.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $attrs = $this->getAttrs(); + public function livestats() + { + $status = "inactive"; + $attrs = $this->getAttrs(); - $res = parent::execute( - $this->url("api/status/server-information"), - $attrs - ); - $serverInfo = json_decode($res->getBody()); - $res = parent::execute($this->url("api/status/cpu"), $attrs); - $cpu = json_decode($res->getBody()); - $res = parent::execute($this->url("api/status/ram"), $attrs); - $memory = json_decode($res->getBody()); + $res = parent::execute( + $this->url("api/status/server-information"), + $attrs + ); + $serverInfo = json_decode($res->getBody()); + $res = parent::execute($this->url("api/status/cpu"), $attrs); + $cpu = json_decode($res->getBody()); + $res = parent::execute($this->url("api/status/ram"), $attrs); + $memory = json_decode($res->getBody()); - if ($serverInfo->time->uptime > 0) { - $status = "active"; - } + if ($serverInfo->time->uptime > 0) { + $status = "active"; + } - $data = [ - "cpu" => intval($cpu->cpuTemperature->main) . " °C", - "ram" => - format_bytes($memory->mem->used) . - " / " . - format_bytes($memory->mem->total), - ]; + $data = [ + "cpu" => intval($cpu->cpuTemperature->main) . " °C", + "ram" => + format_bytes($memory->mem->used) . + " / " . + format_bytes($memory->mem->total), + ]; - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function getAttrs() - { - if (strlen($this->config->username) == 0) { - return []; - } - $attrs = [ - "body" => json_encode([ - "username" => $this->config->username, - "password" => $this->config->password, - ]), - "headers" => ["content-type" => "application/json"], - ]; - $res = parent::execute( - $this->url("api/auth/login"), - $attrs, - null, - "POST" - ); - $auth = json_decode($res->getBody()); - return [ - "headers" => ["authorization" => "Bearer " . $auth->access_token], - ]; - } + public function getAttrs() + { + if (strlen($this->config->username) == 0) { + return []; + } + $attrs = [ + "body" => json_encode([ + "username" => $this->config->username, + "password" => $this->config->password, + ]), + "headers" => ["content-type" => "application/json"], + ]; + $res = parent::execute( + $this->url("api/auth/login"), + $attrs, + null, + "POST" + ); + $auth = json_decode($res->getBody()); + return [ + "headers" => ["authorization" => "Bearer " . $auth->access_token], + ]; + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Homer/Homer.php b/Homer/Homer.php index 90b1748132..516038dba8 100644 --- a/Homer/Homer.php +++ b/Homer/Homer.php @@ -1,4 +1,6 @@ -url, "/"); - $q = urlencode($query); - return redirect($url . "#search=" . $q); - } + public $type = "external"; // Whether to go to the external site or display results locally + public function getResults($query, $provider) + { + $url = rtrim($provider->url, "/"); + $q = urlencode($query); + return redirect($url . "#search=" . $q); + } } diff --git a/Jaeger/Jaeger.php b/Jaeger/Jaeger.php index 27a1b6093c..37f08cda1b 100644 --- a/Jaeger/Jaeger.php +++ b/Jaeger/Jaeger.php @@ -1,97 +1,99 @@ -config->service; - $operation = $this->config->operation; - $tags = $this->config->tags; - $lookback = $this->config->lookback; - $minDuration = $this->config->minDuration; - $maxDuration = $this->config->maxDuration; - $limit = $this->config->limit; + private function tracesUrl() + { + $service = $this->config->service; + $operation = $this->config->operation; + $tags = $this->config->tags; + $lookback = $this->config->lookback; + $minDuration = $this->config->minDuration; + $maxDuration = $this->config->maxDuration; + $limit = $this->config->limit; - $endpoint = "api/traces?service=" . urlencode($service); - if (!empty($operation)) { - $endpoint .= "&operation=" . urlencode($operation); - } - if (!empty($tags)) { - $endpoint .= "&tags=" . urlencode($tags); - } - if (!empty($lookback)) { - $lookbackFormatted = str_replace( - "d", - " days", - str_replace("h", " hours", $lookback) - ); - $timestampForOffset = time(); - $offset = - $timestampForOffset - - strtotime("-" . $lookbackFormatted, $timestampForOffset); + $endpoint = "api/traces?service=" . urlencode($service); + if (!empty($operation)) { + $endpoint .= "&operation=" . urlencode($operation); + } + if (!empty($tags)) { + $endpoint .= "&tags=" . urlencode($tags); + } + if (!empty($lookback)) { + $lookbackFormatted = str_replace( + "d", + " days", + str_replace("h", " hours", $lookback) + ); + $timestampForOffset = time(); + $offset = + $timestampForOffset - + strtotime("-" . $lookbackFormatted, $timestampForOffset); - $timestamp = microtime(true); - $end = sprintf("%0.0f", $timestamp * 1000000); - $start = sprintf("%0.0f", ($timestamp - $offset) * 1000000); - $endpoint .= "&lookback=" . urlencode($lookback); - $endpoint .= "&start=" . $start; - $endpoint .= "&end=" . $end; - } - if (!empty($minDuration)) { - $endpoint .= "&minDuration=" . urlencode($minDuration); - } - if (!empty($maxDuration)) { - $endpoint .= "&maxDuration=" . urlencode($maxDuration); - } - if (!empty($limit)) { - $endpoint .= "&limit=" . urlencode($limit); - } - return $this->url($endpoint); - } + $timestamp = microtime(true); + $end = sprintf("%0.0f", $timestamp * 1000000); + $start = sprintf("%0.0f", ($timestamp - $offset) * 1000000); + $endpoint .= "&lookback=" . urlencode($lookback); + $endpoint .= "&start=" . $start; + $endpoint .= "&end=" . $end; + } + if (!empty($minDuration)) { + $endpoint .= "&minDuration=" . urlencode($minDuration); + } + if (!empty($maxDuration)) { + $endpoint .= "&maxDuration=" . urlencode($maxDuration); + } + if (!empty($limit)) { + $endpoint .= "&limit=" . urlencode($limit); + } + return $this->url($endpoint); + } - public function test() - { - $test = parent::appTest($this->tracesUrl()); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->tracesUrl()); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->tracesUrl()); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->tracesUrl()); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - if ($details) { - $status = "active"; - $data["traces"] = count($details->data); - $data["avg_duration"] = 0; - if ($data["traces"] > 0) { - $durations = array_map(function ($dataItem) { - $max = 0; - foreach ($dataItem->spans as $spanItem) { - $max = max($max, $spanItem->duration); - } - return $max; - }, $details->data); - $data["avg_duration"] = round( - array_sum($durations) / $data["traces"] / 1000, - 1 - ); - } - } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + if ($details) { + $status = "active"; + $data["traces"] = count($details->data); + $data["avg_duration"] = 0; + if ($data["traces"] > 0) { + $durations = array_map(function ($dataItem) { + $max = 0; + foreach ($dataItem->spans as $spanItem) { + $max = max($max, $spanItem->duration); + } + return $max; + }, $details->data); + $data["avg_duration"] = round( + array_sum($durations) / $data["traces"] / 1000, + 1 + ); + } + } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Jeedom/Jeedom.php b/Jeedom/Jeedom.php index fe63ea19d4..647d749221 100644 --- a/Jeedom/Jeedom.php +++ b/Jeedom/Jeedom.php @@ -1,4 +1,6 @@ -url("System/Info/Public"), - $this->getAttrs() - ); - echo $test->status; - } + public function test() + { + $test = parent::appTest( + $this->url("System/Info/Public"), + $this->getAttrs() + ); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("Items/Counts"), $this->getAttrs()); - $result = json_decode($res->getBody()); - $details = ["visiblestats" => []]; - foreach ($this->config->availablestats as $stat) { - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = $result->{$stat}; - $details["visiblestats"][] = $newstat; - } - return parent::getLiveStats($status, $details); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("Items/Counts"), $this->getAttrs()); + $result = json_decode($res->getBody()); + $details = ["visiblestats" => []]; + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = $result->{$stat}; + $details["visiblestats"][] = $newstat; + } + return parent::getLiveStats($status, $details); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } - private function getAttrs() - { - return [ - "headers" => [ - "X-MediaBrowser-Token" => $this->config->password, - ], - ]; - } + private function getAttrs() + { + return [ + "headers" => [ + "X-MediaBrowser-Token" => $this->config->password, + ], + ]; + } - public static function getAvailableStats() - { - return [ - "MovieCount" => "Movies", - "SeriesCount" => "Series", - "EpisodeCount" => "Episodes", - "ArtistCount" => "Artists", - "ProgramCount" => "Programs", - "TrailerCount" => "Trailers", - "SongCount" => "Songs", - "AlbumCount" => "Albums", - "MusicVideoCount" => "MusicVideos", - "BoxSetCount" => "BoxSets", - "BookCount" => "Books", - "ItemCount" => "Items", - ]; - } + public static function getAvailableStats() + { + return [ + "MovieCount" => "Movies", + "SeriesCount" => "Series", + "EpisodeCount" => "Episodes", + "ArtistCount" => "Artists", + "ProgramCount" => "Programs", + "TrailerCount" => "Trailers", + "SongCount" => "Songs", + "AlbumCount" => "Albums", + "MusicVideoCount" => "MusicVideos", + "BoxSetCount" => "BoxSets", + "BookCount" => "Books", + "ItemCount" => "Items", + ]; + } } diff --git a/Jellyseerr/Jellyseerr.php b/Jellyseerr/Jellyseerr.php index 7524a6d38e..b5db9eed94 100644 --- a/Jellyseerr/Jellyseerr.php +++ b/Jellyseerr/Jellyseerr.php @@ -1,13 +1,16 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set } @@ -33,8 +36,7 @@ public function livestats() parent::execute($this->url("issue/count"), $attrs)->getBody() ); - if ($requestsCount || $issuesCount) - { + if ($requestsCount || $issuesCount) { $data["requests"] = $requestsCount->$requestsType ?? 0; $data["issues"] = $issuesCount->$issuesType ?? 0; } diff --git a/Jenkins/Jenkins.php b/Jenkins/Jenkins.php index 53a47bb896..4f1b89e95b 100644 --- a/Jenkins/Jenkins.php +++ b/Jenkins/Jenkins.php @@ -1,61 +1,64 @@ -config->username != "" || $this->config->password != "") { - $this->attrs = [ - "auth" => [ - $this->config->username, - $this->config->password, - "Basic", - ], - ]; - } - $test = parent::appTest($this->url("api/json"), $this->attrs); - echo $test->status; - } + public function test() + { + if ($this->config->username != "" || $this->config->password != "") { + $this->attrs = [ + "auth" => [ + $this->config->username, + $this->config->password, + "Basic", + ], + ]; + } + $test = parent::appTest($this->url("api/json"), $this->attrs); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $data = []; - $data["TotalRunningJobs"] = 0; - if ($this->config->username != "" || $this->config->password != "") { - $this->attrs = [ - "auth" => [ - $this->config->username, - $this->config->password, - "Basic", - ], - ]; - } - $res = parent::execute( - $this->url( - "computer/api/xml?tree=computer[executors[currentExecutable[url]]]&depth=1&xpath=//url&wrapper=buildUrls" - ), - $this->attrs - ); + public function livestats() + { + $status = "inactive"; + $data = []; + $data["TotalRunningJobs"] = 0; + if ($this->config->username != "" || $this->config->password != "") { + $this->attrs = [ + "auth" => [ + $this->config->username, + $this->config->password, + "Basic", + ], + ]; + } + $res = parent::execute( + $this->url( + "computer/api/xml?tree=computer[executors[currentExecutable[url]]]&depth=1" + . "&xpath=//url&wrapper=buildUrls" + ), + $this->attrs + ); - try { - $value = simplexml_load_string($res->getBody()); - $data["TotalRunningJobs"] = count($value->url) ?? 0; - } catch (\ErrorException $e) { - $data["TotalRunningJobs"] = 0; - } + try { + $value = simplexml_load_string($res->getBody()); + $data["TotalRunningJobs"] = count($value->url) ?? 0; + } catch (\ErrorException $e) { + $data["TotalRunningJobs"] = 0; + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Jira/Jira.php b/Jira/Jira.php index 5e997f3eea..cdb82d6771 100644 --- a/Jira/Jira.php +++ b/Jira/Jira.php @@ -1,4 +1,6 @@ -config->url) . - 'jsonrpc?request={"id":1,"jsonrpc":"2.0","method":"' . - $endpoint . - '"}'; - return $api_url; - } + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + 'jsonrpc?request={"id":1,"jsonrpc":"2.0","method":"' . + $endpoint . + '"}'; + return $api_url; + } - private function getAttrs() - { - return [ - "headers" => [ - "Authorization" => - "Basic " . - base64_encode( - $this->config->username . ":" . $this->config->password - ), - ], - ]; - } + private function getAttrs() + { + return [ + "headers" => [ + "Authorization" => + "Basic " . + base64_encode( + $this->config->username . ":" . $this->config->password + ), + ], + ]; + } - public function test() - { - $test = parent::appTest( - $this->url("JSONRPC.Introspect"), - $this->getAttrs() - ); - echo $test->status; - } + public function test() + { + $test = parent::appTest( + $this->url("JSONRPC.Introspect"), + $this->getAttrs() + ); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $data = ["visiblestats" => []]; - foreach ($this->config->availablestats as $method) { - $res = parent::execute($this->url($method), $this->getAttrs()); - $result = json_decode($res->getBody()); - if (isset($result->result) && isset($result->result->limits)) { - $stat = new \stdClass(); - $stat->title = self::getAvailableStats()[$method]; - $stat->value = $result->result->limits->total; - $data["visiblestats"][] = $stat; - } - } - return parent::getLiveStats($status, $data); - } + public function livestats() + { + $status = "inactive"; + $data = ["visiblestats" => []]; + foreach ($this->config->availablestats as $method) { + $res = parent::execute($this->url($method), $this->getAttrs()); + $result = json_decode($res->getBody()); + if (isset($result->result) && isset($result->result->limits)) { + $stat = new \stdClass(); + $stat->title = self::getAvailableStats()[$method]; + $stat->value = $result->result->limits->total; + $data["visiblestats"][] = $stat; + } + } + return parent::getLiveStats($status, $data); + } - public static function getAvailableStats() - { - return [ - "VideoLibrary.GetMovies" => "Movies", - "VideoLibrary.GetMovieSets" => "Movie Sets", - "VideoLibrary.GetTVShows" => "TV Shows", - "VideoLibrary.GetEpisodes" => "Episodes", - "PVR.GetRecordings" => "PVR Rec", - "AudioLibrary.GetArtists" => "Artists", - "AudioLibrary.GetAlbums" => "Albums", - "AudioLibrary.GetSongs" => "Songs", - "VideoLibrary.GetMusicVideos" => "Music Vids", - ]; - } + public static function getAvailableStats() + { + return [ + "VideoLibrary.GetMovies" => "Movies", + "VideoLibrary.GetMovieSets" => "Movie Sets", + "VideoLibrary.GetTVShows" => "TV Shows", + "VideoLibrary.GetEpisodes" => "Episodes", + "PVR.GetRecordings" => "PVR Rec", + "AudioLibrary.GetArtists" => "Artists", + "AudioLibrary.GetAlbums" => "Albums", + "AudioLibrary.GetSongs" => "Songs", + "VideoLibrary.GetMusicVideos" => "Music Vids", + ]; + } } diff --git a/Komga/Komga.php b/Komga/Komga.php index 9e802a06a8..f5124b851e 100644 --- a/Komga/Komga.php +++ b/Komga/Komga.php @@ -1,35 +1,37 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Kopia/Kopia.php b/Kopia/Kopia.php index 9cda40ad01..a100207c89 100644 --- a/Kopia/Kopia.php +++ b/Kopia/Kopia.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("system/status")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $missing = json_decode( - parent::execute($this->url("wanted/missing"))->getBody() - ); - $queue = json_decode(parent::execute($this->url("queue"))->getBody()); - - if ($missing || $queue) { - $data["missing"] = $missing->totalRecords ?? 0; - $data["queue"] = $queue->totalRecords ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/v1/" . - $endpoint . - "?apikey=" . - $this->config->apikey; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("system/status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $missing = json_decode( + parent::execute($this->url("wanted/missing"))->getBody() + ); + $queue = json_decode(parent::execute($this->url("queue"))->getBody()); + + if ($missing || $queue) { + $data["missing"] = $missing->totalRecords ?? 0; + $data["queue"] = $queue->totalRecords ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/v1/" . + $endpoint . + "?apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/LinkAce/LinkAce.php b/LinkAce/LinkAce.php index 7cf9d5c606..563d6e0a46 100644 --- a/LinkAce/LinkAce.php +++ b/LinkAce/LinkAce.php @@ -1,63 +1,65 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api/v1/links")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - - $res_links = parent::execute( - $this->url("api/v1/links"), - $this->attrs() - ); - $links = json_decode($res_links->getBody(), true); - - $res_tags = parent::execute($this->url("api/v1/tags"), $this->attrs()); - $tags = json_decode($res_tags->getBody(), true); - - $data = []; - - if ($links) { - $data["links"] = $links["total"] ?? 0; - } - - if ($tags) { - $data["tags"] = $tags["total"] ?? 0; - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public function attrs() - { - $apikey = $this->config->apikey; - $attrs = [ - "headers" => [ - "content-type" => "application/json", - "Authorization" => "Bearer " . $apikey, - ], - ]; - return $attrs; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api/v1/links")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + + $res_links = parent::execute( + $this->url("api/v1/links"), + $this->attrs() + ); + $links = json_decode($res_links->getBody(), true); + + $res_tags = parent::execute($this->url("api/v1/tags"), $this->attrs()); + $tags = json_decode($res_tags->getBody(), true); + + $data = []; + + if ($links) { + $data["links"] = $links["total"] ?? 0; + } + + if ($tags) { + $data["tags"] = $tags["total"] ?? 0; + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public function attrs() + { + $apikey = $this->config->apikey; + $attrs = [ + "headers" => [ + "content-type" => "application/json", + "Authorization" => "Bearer " . $apikey, + ], + ]; + return $attrs; + } } diff --git a/Lychee/Lychee.php b/Lychee/Lychee.php index f1011af005..a4f2caa0f7 100644 --- a/Lychee/Lychee.php +++ b/Lychee/Lychee.php @@ -1,4 +1,6 @@ -config->username != "" || $this->config->password != "") { - $this->attrs = [ - "auth" => [$this->config->username, $this->config->password], - ]; - } - } - - public function test() - { - $this->setClientOptions(); - $test = parent::appTest($this->url(self::ENDPOINT), $this->attrs); - echo $test->status; - } - - public function livestats() - { - $this->setClientOptions(); - $res = parent::execute($this->url(self::ENDPOINT), $this->attrs); - $details = json_decode($res->getBody()); - - $data["count_unread"] = $details->total; - return parent::getLiveStats("inactive", $data); - } - - public function url($endpoint) - { - return parent::normaliseurl($this->config->url) . $endpoint; - } + private const ENDPOINT = "v1/entries?status=unread"; + + public $config; + public $attrs = []; + + public function __construct() + { + } + + private function setClientOptions() + { + if ($this->config->username != "" || $this->config->password != "") { + $this->attrs = [ + "auth" => [$this->config->username, $this->config->password], + ]; + } + } + + public function test() + { + $this->setClientOptions(); + $test = parent::appTest($this->url(self::ENDPOINT), $this->attrs); + echo $test->status; + } + + public function livestats() + { + $this->setClientOptions(); + $res = parent::execute($this->url(self::ENDPOINT), $this->attrs); + $details = json_decode($res->getBody()); + + $data["count_unread"] = $details->total; + return parent::getLiveStats("inactive", $data); + } + + public function url($endpoint) + { + return parent::normaliseurl($this->config->url) . $endpoint; + } } diff --git a/Minio/Minio.php b/Minio/Minio.php index 57323d79b5..0805aa7492 100644 --- a/Minio/Minio.php +++ b/Minio/Minio.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api/contacts")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("api/contacts"), $this->attrs()); - $details = json_decode($res->getBody(), true); - - $data = []; - - if ($details) { - $data["contacts"] = $details["meta"]["total"] ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public function attrs() - { - $apikey = $this->config->apikey; - $attrs = [ - "headers" => [ - "content-type" => "application/json", - "Authorization" => "Bearer " . $apikey, - ], - ]; - return $attrs; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api/contacts")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("api/contacts"), $this->attrs()); + $details = json_decode($res->getBody(), true); + + $data = []; + + if ($details) { + $data["contacts"] = $details["meta"]["total"] ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public function attrs() + { + $apikey = $this->config->apikey; + $attrs = [ + "headers" => [ + "content-type" => "application/json", + "Authorization" => "Bearer " . $apikey, + ], + ]; + return $attrs; + } } diff --git a/Monit/Monit.php b/Monit/Monit.php index ebcbd46b3d..e146bb6bd0 100644 --- a/Monit/Monit.php +++ b/Monit/Monit.php @@ -1,35 +1,37 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/MotionEye/MotionEye.php b/MotionEye/MotionEye.php index a7b87cb25f..9a3e17f6aa 100644 --- a/MotionEye/MotionEye.php +++ b/MotionEye/MotionEye.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("getVersion")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - - $missing = json_decode( - parent::execute($this->url("getWanted"))->getBody() - ); - $upcoming = json_decode( - parent::execute($this->url("getUpcoming"))->getBody() - ); - - $data = []; - - $data["missing"] = count($missing->issues) ?? 0; - $data["upcoming"] = count($upcoming) ?? 0; - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api?apikey=" . - $this->config->apikey . - "&cmd=" . - $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("getVersion")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + + $missing = json_decode( + parent::execute($this->url("getWanted"))->getBody() + ); + $upcoming = json_decode( + parent::execute($this->url("getUpcoming"))->getBody() + ); + + $data = []; + + $data["missing"] = count($missing->issues) ?? 0; + $data["upcoming"] = count($upcoming) ?? 0; + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api?apikey=" . + $this->config->apikey . + "&cmd=" . + $endpoint; + return $api_url; + } } diff --git a/N8n/N8n.php b/N8n/N8n.php index de1e380ec3..545d4555ef 100644 --- a/N8n/N8n.php +++ b/N8n/N8n.php @@ -1,4 +1,6 @@ - [ "endpoint" => "/api/1/alert/?page_size=1", "title" => "Alerts", - "short" => "", + "short" => "" . + "", ], "devices" => [ "endpoint" => "/api/1/netbox/?page_size=1", @@ -25,14 +35,16 @@ class NAV extends \App\SupportedApps implements \App\EnhancedApps { //protected $login_first = true; // Uncomment if api requests need to be authed first //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST - function __construct() { + public function __construct() + { //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set } public function test() { if (!empty($this->config->apikey)) { - $test = parent::appTest($this->url('/api/'), ['headers' => ['Authorization' => 'Token '.$this->config->apikey]]); + $test = parent::appTest($this->url('/api/'), ['headers' => ['Authorization' => 'Token ' . + $this->config->apikey]]); echo $test->status; } else { echo "API key missing!"; @@ -43,11 +55,12 @@ public function livestats() { $status = 'inactive'; $data = ["stats" => []]; - + foreach ($this->stats as $stat => $conf) { - $res = parent::execute($this->url($conf["endpoint"]), ['headers' => ['Authorization' => 'Token '.$this->config->apikey]]); + $res = parent::execute($this->url($conf["endpoint"]), ['headers' => ['Authorization' => 'Token ' . + $this->config->apikey]]); $details = json_decode($res->getBody()); - + if ($details && isset($details->count)) { array_push($data["stats"], [ "title" => $conf["title"], @@ -56,13 +69,13 @@ public function livestats() ]); } } - + return parent::getLiveStats($status, $data); } - + public function url($endpoint) { - $api_url = parent::normaliseurl($this->config->url).$endpoint; + $api_url = parent::normaliseurl($this->config->url) . $endpoint; return $api_url; } } diff --git a/NZBHydra/NZBHydra.php b/NZBHydra/NZBHydra.php index 806aa780c0..27d1f2f9fe 100644 --- a/NZBHydra/NZBHydra.php +++ b/NZBHydra/NZBHydra.php @@ -1,12 +1,14 @@ -url, "/"); - $q = urlencode($query); - return redirect($url . "/?category=All&mode=search&query=" . $q); - } + public $type = "external"; // Whether to go to the external site or display results locally + public function getResults($query, $provider) + { + $url = rtrim($provider->url, "/"); + $q = urlencode($query); + return redirect($url . "/?category=All&mode=search&query=" . $q); + } } diff --git a/Nagios/Nagios.php b/Nagios/Nagios.php index 5000d60f5d..50db5ced14 100644 --- a/Nagios/Nagios.php +++ b/Nagios/Nagios.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + // $this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest( - $this->url("rest/ping"), - $this->getAttributes() - ); - if ($test->code === 200) { - $result = json_decode($test->response); - if ($result->{'subsonic-response'}->status != "ok") { - $test->status = $result->{'subsonic-response'}->error->message; - } - } - echo $test->status; - } + public function test() + { + $test = parent::appTest( + $this->url("rest/ping"), + $this->getAttributes() + ); + if ($test->code === 200) { + $result = json_decode($test->response); + if ($result->{'subsonic-response'}->status != "ok") { + $test->status = $result->{'subsonic-response'}->error->message; + } + } + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute( - $this->url("rest/getNowPlaying"), - $this->getAttributes() - ); - $result = json_decode($res->getBody(), true); + public function livestats() + { + $status = "inactive"; + $res = parent::execute( + $this->url("rest/getNowPlaying"), + $this->getAttributes() + ); + $result = json_decode($res->getBody(), true); - $data["now_playing"] = !$result["subsonic-response"]["nowPlaying"] - ? 0 - : count($result["subsonic-response"]["nowPlaying"]); - return parent::getLiveStats($status, $data); - } + $data["now_playing"] = !$result["subsonic-response"]["nowPlaying"] + ? 0 + : count($result["subsonic-response"]["nowPlaying"]); + return parent::getLiveStats($status, $data); + } - private function getAttributes() - { - $salt = "omHQfVJ"; - $authToken = md5($this->config->password . $salt); - return [ - "query" => [ - "u" => $this->config->username, // username - "t" => $authToken, // token - "s" => $salt, // salt - "v" => "1.16.1", // subsonic API version - "c" => "heimdall", // client name - "f" => "json", // request data format - ], - ]; - } + private function getAttributes() + { + $salt = "omHQfVJ"; + $authToken = md5($this->config->password . $salt); + return [ + "query" => [ + "u" => $this->config->username, // username + "t" => $authToken, // token + "s" => $salt, // salt + "v" => "1.16.1", // subsonic API version + "c" => "heimdall", // client name + "f" => "json", // request data format + ], + ]; + } - public function url($endpoint) - { - $apiUrl = parent::normaliseurl($this->config->url) . $endpoint; - return $apiUrl; - } + public function url($endpoint) + { + $apiUrl = parent::normaliseurl($this->config->url) . $endpoint; + return $apiUrl; + } } diff --git a/Nessus/Nessus.php b/Nessus/Nessus.php index 290c595bce..77b3240809 100644 --- a/Nessus/Nessus.php +++ b/Nessus/Nessus.php @@ -1,84 +1,86 @@ - false, - "timeout" => 15, - "connect_timeout" => 15, - "verify" => false, - ]; + public $config; + private $clientVars = [ + "http_errors" => false, + "timeout" => 15, + "connect_timeout" => 15, + "verify" => false, + ]; - function __construct() - { - } + public function __construct() + { + } - private function acquireToken() - { - $username = $this->config->username; - $password = $this->config->password; - $attrs = [ - "body" => json_encode([ - "username" => $username, - "password" => $password, - ]), - "headers" => ["content-type" => "application/json"], - ]; - $res = parent::execute( - $this->url("session"), - $attrs, - $this->clientVars, - "POST" - ); - switch ($res->getStatusCode()) { - case 200: - $details = json_decode($res->getBody()); - return $details->token; - case 400: - throw new \Exception("Invalid username format"); - case 401: - throw new \Exception("Invalid username/password"); - } + private function acquireToken() + { + $username = $this->config->username; + $password = $this->config->password; + $attrs = [ + "body" => json_encode([ + "username" => $username, + "password" => $password, + ]), + "headers" => ["content-type" => "application/json"], + ]; + $res = parent::execute( + $this->url("session"), + $attrs, + $this->clientVars, + "POST" + ); + switch ($res->getStatusCode()) { + case 200: + $details = json_decode($res->getBody()); + return $details->token; + case 400: + throw new \Exception("Invalid username format"); + case 401: + throw new \Exception("Invalid username/password"); + } - throw new \Exception("Error connecting to Nessus"); - } + throw new \Exception("Error connecting to Nessus"); + } - public function test() - { - try { - $this->acquireToken(); - } catch (\Throwable $e) { - echo $e->getMessage(); - return; - } - echo "Successfully communicated with the API"; - } + public function test() + { + try { + $this->acquireToken(); + } catch (\Throwable $e) { + echo $e->getMessage(); + return; + } + echo "Successfully communicated with the API"; + } - public function livestats() - { - $token = $this->acquireToken(); - $status = "inactive"; - $attrs = [ - "headers" => ["X-Cookie" => "token=" . $token], - ]; - $res = parent::execute($this->url("scans"), $attrs, $this->clientVars); - $details = json_decode($res->getBody()); - $data = []; - if ($details && !isset($details->error)) { - foreach ($details->scans as $scan) { - if ($scan->status == "running") { - $data["scanner"] = $scan->name; - $status = "active"; - break; - } - } - } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function livestats() + { + $token = $this->acquireToken(); + $status = "inactive"; + $attrs = [ + "headers" => ["X-Cookie" => "token=" . $token], + ]; + $res = parent::execute($this->url("scans"), $attrs, $this->clientVars); + $details = json_decode($res->getBody()); + $data = []; + if ($details && !isset($details->error)) { + foreach ($details->scans as $scan) { + if ($scan->status == "running") { + $data["scanner"] = $scan->name; + $status = "active"; + break; + } + } + } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/NetBox/NetBox.php b/NetBox/NetBox.php index 8331654fdc..38abffadd9 100644 --- a/NetBox/NetBox.php +++ b/NetBox/NetBox.php @@ -1,4 +1,6 @@ -url(self::ENDPOINT)); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url(self::ENDPOINT)); - $res = parent::execute($this->url(self::ENDPOINT)); - $details = json_decode($res->getBody()); - - $data = [ - "count_warning" => $details->alarms->warning, - "count_critical" => $details->alarms->critical, - ]; - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + private const ENDPOINT = "api/v1/info"; + + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url(self::ENDPOINT)); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url(self::ENDPOINT)); + $res = parent::execute($this->url(self::ENDPOINT)); + $details = json_decode($res->getBody()); + + $data = [ + "count_warning" => $details->alarms->warning, + "count_critical" => $details->alarms->critical, + ]; + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/NetgearOrbi/NetgearOrbi.php b/NetgearOrbi/NetgearOrbi.php index 4d43aec37f..4b1333d0a0 100644 --- a/NetgearOrbi/NetgearOrbi.php +++ b/NetgearOrbi/NetgearOrbi.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function getHeaders() - { - $username = $this->config->username; - $password = $this->config->password; - - $attrs["headers"] = [ - "Authorization" => - "Basic " . base64_encode($username . ":" . $password), - "OCS-APIRequest" => "true", - ]; - return $attrs; - } - - public function test() - { - $username = $this->config->username; - - $test = parent::appTest( - $this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"), - $this->getHeaders() - ); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - - $username = $this->config->username; - $res = parent::execute( - $this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"), - $this->getHeaders() - ); - $details = json_decode($res->getBody()); - - $data = ["visiblestats" => []]; - - if ($details) { - foreach ($this->config->availablestats as $stat) { - if (!isset(self::getAvailableStats()[$stat])) { - continue; - } - - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = self::formatNumberUsingStat( - $stat, - $details->ocs->data->quota->{$stat} - ); - - $data["visiblestats"][] = $newstat; - } - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url); - return $api_url . $endpoint; - } - - public static function getAvailableStats() - { - return [ - "relative" => "Usage", - "used" => "Used Space", - "free" => "Free Space", - "total" => "Total Space", - ]; - } - - private static function formatNumberUsingStat($stat, $number) - { - if (!isset($number)) { - return "N/A"; - } - - switch ($stat) { - case "free": - case "used": - case "total": - return format_bytes($number, false, "", ""); - case "relative": - return number_format($number, 1) . "%"; - default: - return number_format($number); - } - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function getHeaders() + { + $username = $this->config->username; + $password = $this->config->password; + + $attrs["headers"] = [ + "Authorization" => + "Basic " . base64_encode($username . ":" . $password), + "OCS-APIRequest" => "true", + ]; + return $attrs; + } + + public function test() + { + $username = $this->config->username; + + $test = parent::appTest( + $this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"), + $this->getHeaders() + ); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + + $username = $this->config->username; + $res = parent::execute( + $this->url("/ocs/v1.php/cloud/users/" . $username . "?format=json"), + $this->getHeaders() + ); + $details = json_decode($res->getBody()); + + $data = ["visiblestats" => []]; + + if ($details) { + foreach ($this->config->availablestats as $stat) { + if (!isset(self::getAvailableStats()[$stat])) { + continue; + } + + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = self::formatNumberUsingStat( + $stat, + $details->ocs->data->quota->{$stat} + ); + + $data["visiblestats"][] = $newstat; + } + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url); + return $api_url . $endpoint; + } + + public static function getAvailableStats() + { + return [ + "relative" => "Usage", + "used" => "Used Space", + "free" => "Free Space", + "total" => "Total Space", + ]; + } + + private static function formatNumberUsingStat($stat, $number) + { + if (!isset($number)) { + return "N/A"; + } + + switch ($stat) { + case "free": + case "used": + case "total": + return format_bytes($number, false, "", ""); + case "relative": + return number_format($number, 1) . "%"; + default: + return number_format($number); + } + } } diff --git a/NexusRepositoryManagerOSS3x/NexusRepositoryManagerOSS3x.php b/NexusRepositoryManagerOSS3x/NexusRepositoryManagerOSS3x.php index 93469b2bd0..eee7a02859 100644 --- a/NexusRepositoryManagerOSS3x/NexusRepositoryManagerOSS3x.php +++ b/NexusRepositoryManagerOSS3x/NexusRepositoryManagerOSS3x.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $auth_attrs = [ - "headers" => [ - "Accept" => "application/json", - "Content-Type" => "application/json", - ], - "body" => json_encode([ - "identity" => $this->config->email, - "secret" => $this->config->password, - ]), - ]; - $auth_res = parent::execute( - $this->url("api/tokens"), - $auth_attrs, - null, - "POST" - ); - $auth_data = json_decode($auth_res->getBody(), true); - $token = $auth_data["token"]; - - $attrs = [ - "headers" => [ - "Accept" => "application/json", - "Authorization" => "Bearer " . $token, - ], - ]; - $res = parent::execute($this->url("api/reports/hosts"), $attrs); - $data = json_decode($res->getBody(), true); - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $auth_attrs = [ + "headers" => [ + "Accept" => "application/json", + "Content-Type" => "application/json", + ], + "body" => json_encode([ + "identity" => $this->config->email, + "secret" => $this->config->password, + ]), + ]; + $auth_res = parent::execute( + $this->url("api/tokens"), + $auth_attrs, + null, + "POST" + ); + $auth_data = json_decode($auth_res->getBody(), true); + $token = $auth_data["token"]; + + $attrs = [ + "headers" => [ + "Accept" => "application/json", + "Authorization" => "Bearer " . $token, + ], + ]; + $res = parent::execute($this->url("api/reports/hosts"), $attrs); + $data = json_decode($res->getBody(), true); + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Nightscout/Nightscout.php b/Nightscout/Nightscout.php index 62ac57b141..dc5506ddc0 100644 --- a/Nightscout/Nightscout.php +++ b/Nightscout/Nightscout.php @@ -1,5 +1,7 @@ -url("status")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $size = $details->result->RemainingSizeMB; - $rate = $details->result->DownloadRate; - $data["queue_size"] = format_bytes( - $size * 1000 * 1000, - false, - " ", - "" - ); - $data["current_speed"] = format_bytes($rate, false, " "); - $status = $size > 0 || $rate > 0 ? "active" : "inactive"; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url); - $username = urlencode($this->config->username); - $password = urlencode($this->config->password); - $rebuild_url = str_replace( - "http://", - "http://" . $username . ":" . $password . "@", - $api_url - ); - $rebuild_url = str_replace( - "https://", - "https://" . $username . ":" . $password . "@", - $rebuild_url - ); - $rebuild_url = rtrim($rebuild_url, "/"); - - $api_url = $rebuild_url . "/jsonrpc/" . $endpoint; - return $api_url; - } + public $config; + + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $size = $details->result->RemainingSizeMB; + $rate = $details->result->DownloadRate; + $data["queue_size"] = format_bytes( + $size * 1000 * 1000, + false, + " ", + "" + ); + $data["current_speed"] = format_bytes($rate, false, " "); + $status = $size > 0 || $rate > 0 ? "active" : "inactive"; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url); + $username = urlencode($this->config->username); + $password = urlencode($this->config->password); + $rebuild_url = str_replace( + "http://", + "http://" . $username . ":" . $password . "@", + $api_url + ); + $rebuild_url = str_replace( + "https://", + "https://" . $username . ":" . $password . "@", + $rebuild_url + ); + $rebuild_url = rtrim($rebuild_url, "/"); + + $api_url = $rebuild_url . "/jsonrpc/" . $endpoint; + return $api_url; + } } diff --git a/OPNsense/OPNsense.php b/OPNsense/OPNsense.php index 756bc9364f..38417be4c2 100644 --- a/OPNsense/OPNsense.php +++ b/OPNsense/OPNsense.php @@ -1,4 +1,6 @@ - $this->config->apikey]; - $test = parent::appTest($this->url("api/version"), $attrs); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $attrs["headers"] = ["X-Api-Key" => $this->config->apikey]; - $res = parent::execute($this->url("api/job"), $attrs); - if (!$res) { - return parent::getLiveStats($status, ["error" => "Connection"]); - } - $details = json_decode($res->getBody()); - - $data = []; - - $progress = $details->progress->completion; - - $data["progress"] = @round($progress) ?? 0; - $seconds = $details->progress->printTimeLeft; - if ($seconds === null) { - $data["estimated"] = "N/A"; - } elseif ($seconds > 0) { - $data["estimated"] = Carbon::now() - ->addSeconds($seconds) - ->diffForHumans(); - } else { - $data["estimated"] = "N/A"; - } - - $status = - $data["progress"] < 100 && $progress !== null - ? "active" - : "inactive"; - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + } + + public function test() + { + $attrs["headers"] = ["X-Api-Key" => $this->config->apikey]; + $test = parent::appTest($this->url("api/version"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $attrs["headers"] = ["X-Api-Key" => $this->config->apikey]; + $res = parent::execute($this->url("api/job"), $attrs); + if (!$res) { + return parent::getLiveStats($status, ["error" => "Connection"]); + } + $details = json_decode($res->getBody()); + + $data = []; + + $progress = $details->progress->completion; + + $data["progress"] = @round($progress) ?? 0; + $seconds = $details->progress->printTimeLeft; + if ($seconds === null) { + $data["estimated"] = "N/A"; + } elseif ($seconds > 0) { + $data["estimated"] = Carbon::now() + ->addSeconds($seconds) + ->diffForHumans(); + } else { + $data["estimated"] = "N/A"; + } + + $status = + $data["progress"] < 100 && $progress !== null + ? "active" + : "inactive"; + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/OliveTin/OliveTin.php b/OliveTin/OliveTin.php index 19c9f7035c..d41981be5f 100644 --- a/OliveTin/OliveTin.php +++ b/OliveTin/OliveTin.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("api/v1/status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("api/v1/status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $this->attrs["headers"] = ["ApiKey" => $this->config->apikey]; - $res = parent::execute( - $this->url("api/v1/request/count"), - $this->attrs - ); - $details = json_decode($res->getBody(), true); + public function livestats() + { + $status = "inactive"; + $this->attrs["headers"] = ["ApiKey" => $this->config->apikey]; + $res = parent::execute( + $this->url("api/v1/request/count"), + $this->attrs + ); + $details = json_decode($res->getBody(), true); - return parent::getLiveStats($status, $details); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $details); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/OnlyOffice/OnlyOffice.php b/OnlyOffice/OnlyOffice.php index c61dec4432..b9c6f39fc6 100644 --- a/OnlyOffice/OnlyOffice.php +++ b/OnlyOffice/OnlyOffice.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $this->attrs["headers"] = [ - "accept" => "application/json", - "X-Api-Key" => $this->config->apikey, - ]; - $test = parent::appTest($this->url("api/v1/auth/me"), $this->attrs); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $this->attrs["headers"] = [ - "accept" => "application/json", - "X-Api-Key" => $this->config->apikey, - ]; - $res = parent::execute( - $this->url("api/v1/request/count"), - $this->attrs - ); - $details = json_decode($res->getBody(), true); - - return parent::getLiveStats($status, $details); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $this->attrs["headers"] = [ + "accept" => "application/json", + "X-Api-Key" => $this->config->apikey, + ]; + $test = parent::appTest($this->url("api/v1/auth/me"), $this->attrs); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $this->attrs["headers"] = [ + "accept" => "application/json", + "X-Api-Key" => $this->config->apikey, + ]; + $res = parent::execute( + $this->url("api/v1/request/count"), + $this->attrs + ); + $details = json_decode($res->getBody(), true); + + return parent::getLiveStats($status, $details); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/OwnPhotos/OwnPhotos.php b/OwnPhotos/OwnPhotos.php index 39370c4f37..66247389a9 100644 --- a/OwnPhotos/OwnPhotos.php +++ b/OwnPhotos/OwnPhotos.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $username = $this->config->username; - $passhash = $this->config->passhash; - $test = parent::appTest( - $this->url( - "api/getstatus.htm?id=0&username=" . - $username . - "&passhash=" . - $passhash - ) - ); - echo $test->status; - } + public function test() + { + $username = $this->config->username; + $passhash = $this->config->passhash; + $test = parent::appTest( + $this->url( + "api/getstatus.htm?id=0&username=" . + $username . + "&passhash=" . + $passhash + ) + ); + echo $test->status; + } - public function livestats() - { - $username = $this->config->username; - $passhash = $this->config->passhash; - $status = "inactive"; - $res = parent::execute( - $this->url( - "api/getstatus.htm?id=0&username=" . - $username . - "&passhash=" . - $passhash - ) - ); - $details = json_decode($res->getBody()); + public function livestats() + { + $username = $this->config->username; + $passhash = $this->config->passhash; + $status = "inactive"; + $res = parent::execute( + $this->url( + "api/getstatus.htm?id=0&username=" . + $username . + "&passhash=" . + $passhash + ) + ); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - if ($details) { - if (empty($details->Alarms)) { - $data["alarms"] = 0; - } else { - $data["alarms"] = number_format($details->Alarms); - } - if (empty($details->AckAlarms)) { - $data["alarmsack"] = 0; - } else { - $data["alarmsack"] = number_format($details->AckAlarms); - } - if (empty($details->WarnSens)) { - $data["warnings"] = 0; - } else { - $data["warnings"] = number_format($details->WarnSens); - } - if (empty($details->UnusualSens)) { - $data["unusuals"] = 0; - } else { - $data["unusuals"] = number_format($details->UnusualSens); - } - if (empty($details->UpSens)) { - $data["ups"] = 0; - } else { - $data["ups"] = number_format($details->UpSens); - } - } + if ($details) { + if (empty($details->Alarms)) { + $data["alarms"] = 0; + } else { + $data["alarms"] = number_format($details->Alarms); + } + if (empty($details->AckAlarms)) { + $data["alarmsack"] = 0; + } else { + $data["alarmsack"] = number_format($details->AckAlarms); + } + if (empty($details->WarnSens)) { + $data["warnings"] = 0; + } else { + $data["warnings"] = number_format($details->WarnSens); + } + if (empty($details->UnusualSens)) { + $data["unusuals"] = 0; + } else { + $data["unusuals"] = number_format($details->UnusualSens); + } + if (empty($details->UpSens)) { + $data["ups"] = 0; + } else { + $data["ups"] = number_format($details->UpSens); + } + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/PaloAltoNetworks/PaloAltoNetworks.php b/PaloAltoNetworks/PaloAltoNetworks.php index c93575cab5..b9638ccaa1 100644 --- a/PaloAltoNetworks/PaloAltoNetworks.php +++ b/PaloAltoNetworks/PaloAltoNetworks.php @@ -1,4 +1,6 @@ -getConfigValue("apikey", null); + public function getRequestAttrs() + { + $apikey = $this->getConfigValue("apikey", null); - $attrs["headers"] = [ - "Accept" => "application/json", - "Authorization" => "Token " . $apikey, - ]; + $attrs["headers"] = [ + "Accept" => "application/json", + "Authorization" => "Token " . $apikey, + ]; - return $attrs; - } + return $attrs; + } - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } - public function test() - { - $attrs = $this->getRequestAttrs(); - $test = parent::appTest($this->url("documents"), $attrs); - echo $test->status; - } + public function test() + { + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("documents"), $attrs); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $data = []; - $attrs = $this->getRequestAttrs(); + public function livestats() + { + $status = "inactive"; + $data = []; + $attrs = $this->getRequestAttrs(); - $documents = json_decode( - parent::execute($this->url("documents"), $attrs)->getBody() - ); + $documents = json_decode( + parent::execute($this->url("documents"), $attrs)->getBody() + ); - $data = [ - "documentCount" => $documents->count ?? 0, - ]; + $data = [ + "documentCount" => $documents->count ?? 0, + ]; - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/" . - $endpoint . - "/"; - return $api_url; - } + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/" . + $endpoint . + "/"; + return $api_url; + } } diff --git a/Papermerge/Papermerge.php b/Papermerge/Papermerge.php index 0e7c8214f7..57811bc9c2 100644 --- a/Papermerge/Papermerge.php +++ b/Papermerge/Papermerge.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api/v1/config")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("api/v1/config")); - $details = json_decode($res->getBody(), true); - - $data = []; - - if ($details) { - $data["photos"] = number_format($details["count"]["photos"]) ?? 0; - $data["videos"] = number_format($details["count"]["videos"]) ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api/v1/config")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("api/v1/config")); + $details = json_decode($res->getBody(), true); + + $data = []; + + if ($details) { + $data["photos"] = number_format($details["count"]["photos"]) ?? 0; + $data["videos"] = number_format($details["count"]["videos"]) ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Photonix/Photonix.php b/Photonix/Photonix.php index 3c50747237..ae22f20e65 100644 --- a/Photonix/Photonix.php +++ b/Photonix/Photonix.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("data/aircraft.json")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("data/aircraft.json")); - $details = json_decode($res->getBody(), true); - - $data = []; - - if ($details) { - $filtered_total = array_filter($details["aircraft"], function ( - $element - ) { - return $element["seen"] <= 58; - }); - $data["total"] = count($filtered_total); - $filtered_positions = array_filter($filtered_total, function ( - $element - ) { - return array_key_exists("seen_pos", $element) && - $element["seen_pos"] < 60; - }); - $data["positions"] = count($filtered_positions); - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("data/aircraft.json")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("data/aircraft.json")); + $details = json_decode($res->getBody(), true); + + $data = []; + + if ($details) { + $filtered_total = array_filter($details["aircraft"], function ( + $element + ) { + return $element["seen"] <= 58; + }); + $data["total"] = count($filtered_total); + $filtered_positions = array_filter($filtered_total, function ( + $element + ) { + return array_key_exists("seen_pos", $element) && + $element["seen_pos"] < 60; + }); + $data["positions"] = count($filtered_positions); + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/PiKVM/PiKVM.php b/PiKVM/PiKVM.php index 6622acff9f..2cffdddf64 100644 --- a/PiKVM/PiKVM.php +++ b/PiKVM/PiKVM.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api.php?summaryRaw")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("api.php?summaryRaw")); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["ads_blocked_today"] = number_format( - $details->ads_blocked_today - ); - $data["ads_percentage_today"] = number_format( - $details->ads_percentage_today, - 1 - ); - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $apiKey = $this->config->apikey; - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - - if($apiKey) { - $api_url .= "&auth=" . $apiKey; - } - - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api.php?summaryRaw")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("api.php?summaryRaw")); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["ads_blocked_today"] = number_format( + $details->ads_blocked_today + ); + $data["ads_percentage_today"] = number_format( + $details->ads_percentage_today, + 1 + ); + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $apiKey = $this->config->apikey; + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + + if ($apiKey) { + $api_url .= "&auth=" . $apiKey; + } + + return $api_url; + } } diff --git a/Piwigo/Piwigo.php b/Piwigo/Piwigo.php index 5099925e84..ea3f191582 100644 --- a/Piwigo/Piwigo.php +++ b/Piwigo/Piwigo.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest( - $this->url("/library/recentlyAdded"), - $this->attrs() - ); - echo $test->status; - } + public function test() + { + $test = parent::appTest( + $this->url("/library/recentlyAdded"), + $this->attrs() + ); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute( - $this->url("/library/recentlyAdded"), - $this->attrs() - ); - $body = $res->getBody(); + public function livestats() + { + $status = "inactive"; + $res = parent::execute( + $this->url("/library/recentlyAdded"), + $this->attrs() + ); + $body = $res->getBody(); $xml = simplexml_load_string( - $body, - "SimpleXMLElement", - LIBXML_NOCDATA | LIBXML_NOBLANKS - ); + $body, + "SimpleXMLElement", + LIBXML_NOCDATA | LIBXML_NOBLANKS + ); - $data = []; + $data = []; - if ($xml) { - $data["recently_added"] = $xml["size"]; - $status = "active"; - } + if ($xml) { + $data["recently_added"] = $xml["size"]; + $status = "active"; + } - $res = parent::execute($this->url("/library/onDeck")); + $res = parent::execute($this->url("/library/onDeck")); - $res = parent::execute($this->url("/library/onDeck"), $this->attrs()); + $res = parent::execute($this->url("/library/onDeck"), $this->attrs()); - $body = $res->getBody(); - $xml = simplexml_load_string( - $body, - "SimpleXMLElement", - LIBXML_NOCDATA | LIBXML_NOBLANKS - ); - if ($xml) { - $data["on_deck"] = $xml["size"]; - $status = "active"; - } + $body = $res->getBody(); + $xml = simplexml_load_string( + $body, + "SimpleXMLElement", + LIBXML_NOCDATA | LIBXML_NOBLANKS + ); + if ($xml) { + $data["on_deck"] = $xml["size"]; + $status = "active"; + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $url = parse_url(parent::normaliseurl($this->config->url)); - $scheme = $url["scheme"]; - $domain = $url["host"]; - $port = isset($url["port"]) ? $url["port"] : "32400"; - $api_url = - $scheme . - "://" . - $domain . - ":" . - $port . - $endpoint . - "?X-Plex-Token=" . - $this->config->token; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $url = parse_url(parent::normaliseurl($this->config->url)); + $scheme = $url["scheme"]; + $domain = $url["host"]; + $port = isset($url["port"]) ? $url["port"] : "32400"; + $api_url = + $scheme . + "://" . + $domain . + ":" . + $port . + $endpoint . + "?X-Plex-Token=" . + $this->config->token; + return $api_url; + } - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } - public function attrs() - { - $ignoreTls = $this->getConfigValue("ignore_tls", false); - if ($ignoreTls) { - $attrs["verify"] = false; - } else { - $attrs = []; - } + public function attrs() + { + $ignoreTls = $this->getConfigValue("ignore_tls", false); + if ($ignoreTls) { + $attrs["verify"] = false; + } else { + $attrs = []; + } - return $attrs; - } + return $attrs; + } } diff --git a/PlexRequests/PlexRequests.php b/PlexRequests/PlexRequests.php index ecbb636ece..a278c2a45b 100644 --- a/PlexRequests/PlexRequests.php +++ b/PlexRequests/PlexRequests.php @@ -1,4 +1,6 @@ -auth(); - echo "Successfully communicated with the API"; - } catch (Exception $err) { - echo $err->getMessage(); - } - } - - public function auth() - { - $body["username"] = $this->config->username; - $body["password"] = $this->config->password; - $vars = [ - "http_errors" => false, - "timeout" => 5, - "body" => json_encode($body), - ]; - - $result = parent::execute( - $this->url("api/auth"), - $this->getAttrs(), - $vars, - "POST" - ); - if (null === $result) { - throw new Exception("Could not connect to Portainer"); - } - - $response = json_decode($result->getBody()); - - if (!isset($response->jwt)) { - throw new Exception("Invalid credentials"); - } - - return $response->jwt; - } - - public function livestats() - { - $status = "inactive"; - $running = 0; - $stopped = 0; - - $token = $this->auth(); - $headers = [ - "Authorization" => "Bearer " . $token, - "Accept" => "application/json", - ]; - - $attrs = $this->getAttrs(); - - $attrs["headers"] = $headers; - - $result = parent::execute( - $this->url("api/endpoints?limit=100&start=0"), - $attrs, - [] - ); - if (null === $result) { - throw new Exception("Could not connect to Portainer"); - } - - $response = json_decode($result->getBody()); - if (count($response) === 0) { - throw new Exception("No endpoints"); - } - - foreach ($response as $endpoint) { - if (count($endpoint->Snapshots) === 0) { - throw new Exception("No snapshots"); - } - - $snapshot = $endpoint->Snapshots[0]; - $data = [ - ($running += $snapshot->RunningContainerCount), - ($stopped += $snapshot->StoppedContainerCount), - ]; - } - - $data = [ - "running" => $running, - "stopped" => $stopped, - ]; - if ($running || $stopped) { - $status = "active"; - } - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } - - public function getAttrs() - { - $ignoreTls = $this->getConfigValue("ignore_tls", false); - if ($ignoreTls) { - $attrs["verify"] = false; - } else { - $attrs = []; - } - - return $attrs; - } + public $config; + + public function __construct() + { + } + + public function test() + { + try { + $token = $this->auth(); + echo "Successfully communicated with the API"; + } catch (Exception $err) { + echo $err->getMessage(); + } + } + + public function auth() + { + $body["username"] = $this->config->username; + $body["password"] = $this->config->password; + $vars = [ + "http_errors" => false, + "timeout" => 5, + "body" => json_encode($body), + ]; + + $result = parent::execute( + $this->url("api/auth"), + $this->getAttrs(), + $vars, + "POST" + ); + if (null === $result) { + throw new Exception("Could not connect to Portainer"); + } + + $response = json_decode($result->getBody()); + + if (!isset($response->jwt)) { + throw new Exception("Invalid credentials"); + } + + return $response->jwt; + } + + public function livestats() + { + $status = "inactive"; + $running = 0; + $stopped = 0; + + $token = $this->auth(); + $headers = [ + "Authorization" => "Bearer " . $token, + "Accept" => "application/json", + ]; + + $attrs = $this->getAttrs(); + + $attrs["headers"] = $headers; + + $result = parent::execute( + $this->url("api/endpoints?limit=100&start=0"), + $attrs, + [] + ); + if (null === $result) { + throw new Exception("Could not connect to Portainer"); + } + + $response = json_decode($result->getBody()); + if (count($response) === 0) { + throw new Exception("No endpoints"); + } + + foreach ($response as $endpoint) { + if (count($endpoint->Snapshots) === 0) { + throw new Exception("No snapshots"); + } + + $snapshot = $endpoint->Snapshots[0]; + $data = [ + ($running += $snapshot->RunningContainerCount), + ($stopped += $snapshot->StoppedContainerCount), + ]; + } + + $data = [ + "running" => $running, + "stopped" => $stopped, + ]; + if ($running || $stopped) { + $status = "active"; + } + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } + + public function getAttrs() + { + $ignoreTls = $this->getConfigValue("ignore_tls", false); + if ($ignoreTls) { + $attrs["verify"] = false; + } else { + $attrs = []; + } + + return $attrs; + } } diff --git a/Portainer/config.blade.php b/Portainer/config.blade.php index 409be5f3bd..60df5f46d2 100644 --- a/Portainer/config.blade.php +++ b/Portainer/config.blade.php @@ -1,36 +1,36 @@

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

- -
- - {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} -
-
- - {!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!} -
-
- - {!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!} -
-
- -
- {!! Form::hidden('config[ignore_tls]', 0, ['class' => 'config-item', 'data-config' => 'ignore_tls']) !!} - -
-
-
- -
+ +
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!} +
+
+ + {!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!} +
+
+ +
+ {!! Form::hidden('config[ignore_tls]', 0, ['class' => 'config-item', 'data-config' => 'ignore_tls']) !!} + +
+
+
+ +
diff --git a/Poste/Poste.php b/Poste/Poste.php index 46b5f5fb54..a8137548bd 100644 --- a/Poste/Poste.php +++ b/Poste/Poste.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("system/status")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - - $indexers = json_decode( - parent::execute($this->url("indexer"))->getBody() - ); - $failures = json_decode( - parent::execute($this->url("indexerstatus"))->getBody() - ); - - $collect = collect($indexers); - $enabled = $collect->where("enable", true); - - $data = []; - if ($indexers || $failures) { - $data["enabled_count"] = $enabled->count() ?? 0; - $data["indexer_count"] = count($indexers) ?? 0; - $data["failure_count"] = count($failures) ?? 0; - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/v1/" . - $endpoint . - "?apikey=" . - $this->config->apikey; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("system/status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + + $indexers = json_decode( + parent::execute($this->url("indexer"))->getBody() + ); + $failures = json_decode( + parent::execute($this->url("indexerstatus"))->getBody() + ); + + $collect = collect($indexers); + $enabled = $collect->where("enable", true); + + $data = []; + if ($indexers || $failures) { + $data["enabled_count"] = $enabled->count() ?? 0; + $data["indexer_count"] = count($indexers) ?? 0; + $data["failure_count"] = count($failures) ?? 0; + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/v1/" . + $endpoint . + "?apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/Proxmox/Proxmox.php b/Proxmox/Proxmox.php index 7ebcbfe480..17595ed9df 100644 --- a/Proxmox/Proxmox.php +++ b/Proxmox/Proxmox.php @@ -1,117 +1,119 @@ -getConfigValue("token_id", null); - $token_value = $this->getConfigValue("token_value", null); - $ignoreTls = $this->getConfigValue("ignore_tls", false); - - $auth = "PVEAPIToken=" . $token_id . "=" . $token_value; - - $attrs["headers"] = [ - "Accept" => "application/json", - "Authorization" => $auth, - ]; - if ($ignoreTls) { - $attrs["verify"] = false; - } - - return $attrs; - } - - function __construct() - { - } - - public function test() - { - $attrs = $this->getRequestAttrs(); - $test = parent::appTest($this->url("version"), $attrs); - echo $test->status; - } - - public function livestats() - { - $status = "active"; - $attrs = $this->getRequestAttrs(); - - $nodes = explode(",", $this->getConfigValue("nodes", "")); - - if ($nodes == [""]) { - $nodes = array_map(function ($v) { - return $v->node; - }, $this->apiCall("nodes")); - } - - $vm_running = 0; - $vm_total = 0; - $container_running = 0; - $container_total = 0; - $cpu_percent_sum = 0.0; - $memory_total = 0.0; - $memory_used = 0.0; - foreach ($nodes as $node) { - $node_status = $this->apiCall("nodes/" . $node . "/status"); - $cpu_percent_sum += $node_status->cpu; - $memory_used += $node_status->memory->used; - $memory_total += $node_status->memory->total; - - $vm_stats = $this->apiCall("nodes/" . $node . "/qemu"); - $vm_total += count($vm_stats); - $vm_running += count( - array_filter($vm_stats, function ($v) { - return $v->status == "running"; - }) - ); - - $container_stats = $this->apiCall("nodes/" . $node . "/lxc"); - $container_total += count($container_stats); - $container_running += count( - array_filter($container_stats, function ($v) { - return $v->status == "running"; - }) - ); - } - - $res = parent::execute($this->url("version"), $attrs); - $details = json_decode($res->getBody())->data; - - $data = [ - "vm_running" => $vm_running, - "vm_total" => $vm_total, - "container_running" => $container_running, - "container_total" => $container_total, - "cpu_percent" => ($cpu_percent_sum / count($nodes)) * 100, - "memory_percent" => (100 / $memory_total) * $memory_used, - ]; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_stub = "api2/json/"; - $api_url = - parent::normaliseurl( - $this->getConfigValue("override_url", $this->config->url) - ) . - $api_stub . - $endpoint; - return $api_url; - } - - public function apiCall($endpoint) - { - $res = parent::execute($this->url($endpoint), $this->getRequestAttrs()); - return json_decode($res->getBody())->data; - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public $config; + + public function getRequestAttrs() + { + $token_id = $this->getConfigValue("token_id", null); + $token_value = $this->getConfigValue("token_value", null); + $ignoreTls = $this->getConfigValue("ignore_tls", false); + + $auth = "PVEAPIToken=" . $token_id . "=" . $token_value; + + $attrs["headers"] = [ + "Accept" => "application/json", + "Authorization" => $auth, + ]; + if ($ignoreTls) { + $attrs["verify"] = false; + } + + return $attrs; + } + + public function __construct() + { + } + + public function test() + { + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("version"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "active"; + $attrs = $this->getRequestAttrs(); + + $nodes = explode(",", $this->getConfigValue("nodes", "")); + + if ($nodes == [""]) { + $nodes = array_map(function ($v) { + return $v->node; + }, $this->apiCall("nodes")); + } + + $vm_running = 0; + $vm_total = 0; + $container_running = 0; + $container_total = 0; + $cpu_percent_sum = 0.0; + $memory_total = 0.0; + $memory_used = 0.0; + foreach ($nodes as $node) { + $node_status = $this->apiCall("nodes/" . $node . "/status"); + $cpu_percent_sum += $node_status->cpu; + $memory_used += $node_status->memory->used; + $memory_total += $node_status->memory->total; + + $vm_stats = $this->apiCall("nodes/" . $node . "/qemu"); + $vm_total += count($vm_stats); + $vm_running += count( + array_filter($vm_stats, function ($v) { + return $v->status == "running"; + }) + ); + + $container_stats = $this->apiCall("nodes/" . $node . "/lxc"); + $container_total += count($container_stats); + $container_running += count( + array_filter($container_stats, function ($v) { + return $v->status == "running"; + }) + ); + } + + $res = parent::execute($this->url("version"), $attrs); + $details = json_decode($res->getBody())->data; + + $data = [ + "vm_running" => $vm_running, + "vm_total" => $vm_total, + "container_running" => $container_running, + "container_total" => $container_total, + "cpu_percent" => ($cpu_percent_sum / count($nodes)) * 100, + "memory_percent" => (100 / $memory_total) * $memory_used, + ]; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_stub = "api2/json/"; + $api_url = + parent::normaliseurl( + $this->getConfigValue("override_url", $this->config->url) + ) . + $api_stub . + $endpoint; + return $api_url; + } + + public function apiCall($endpoint) + { + $res = parent::execute($this->url($endpoint), $this->getRequestAttrs()); + return json_decode($res->getBody())->data; + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } } diff --git a/PsiTransfer/PsiTransfer.php b/PsiTransfer/PsiTransfer.php index e38e57be90..42396d0698 100644 --- a/PsiTransfer/PsiTransfer.php +++ b/PsiTransfer/PsiTransfer.php @@ -1,4 +1,6 @@ -url("api/overview"), - $this->apiRequestAttributes() - ); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute( - $this->url("api/overview"), - $this->apiRequestAttributes() - ); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["in"] = number_format( - $details->message_stats->publish_details->rate + - $details->message_stats->redeliver_details->rate, - 1 - ); - $data["total"] = number_format($details->queue_totals->messages); - $data["out"] = number_format( - $details->message_stats->deliver_details->rate + - $details->message_stats->ack_details->rate, - 1 - ); - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - private function apiRequestAttributes(): array - { - return [ - "headers" => [ - "Authorization" => - "Basic " . - base64_encode( - $this->config->username . ":" . $this->config->password - ), - ], - ]; - } + public $config; + + public function test() + { + $test = parent::appTest( + $this->url("api/overview"), + $this->apiRequestAttributes() + ); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute( + $this->url("api/overview"), + $this->apiRequestAttributes() + ); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["in"] = number_format( + $details->message_stats->publish_details->rate + + $details->message_stats->redeliver_details->rate, + 1 + ); + $data["total"] = number_format($details->queue_totals->messages); + $data["out"] = number_format( + $details->message_stats->deliver_details->rate + + $details->message_stats->ack_details->rate, + 1 + ); + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + private function apiRequestAttributes(): array + { + return [ + "headers" => [ + "Authorization" => + "Basic " . + base64_encode( + $this->config->username . ":" . $this->config->password + ), + ], + ]; + } } diff --git a/Radarr/Radarr.php b/Radarr/Radarr.php index e0e958fc33..2ad29ff54f 100644 --- a/Radarr/Radarr.php +++ b/Radarr/Radarr.php @@ -1,51 +1,53 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("system/status")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - - $movies = json_decode(parent::execute($this->url("movie"))->getBody()); - $queue = json_decode(parent::execute($this->url("queue"))->getBody()); - - $collect = collect($movies); - $missing = $collect->where("monitored", true)->where("isAvailable", true)->where("hasFile", false); - - $data = []; - if ($missing || $queue) { - $data["missing"] = $missing->count() ?? 0; - $data["queue"] = count($queue->records) ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/v3/" . - $endpoint . - "?apikey=" . - $this->config->apikey; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("system/status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + + $movies = json_decode(parent::execute($this->url("movie"))->getBody()); + $queue = json_decode(parent::execute($this->url("queue"))->getBody()); + + $collect = collect($movies); + $missing = $collect->where("monitored", true)->where("isAvailable", true)->where("hasFile", false); + + $data = []; + if ($missing || $queue) { + $data["missing"] = $missing->count() ?? 0; + $data["queue"] = count($queue->records) ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/v3/" . + $endpoint . + "?apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/Rainloop/Rainloop.php b/Rainloop/Rainloop.php index 018d9f1c25..2f4803f1ca 100644 --- a/Rainloop/Rainloop.php +++ b/Rainloop/Rainloop.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("system/status?")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("system/status?")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $data = []; + public function livestats() + { + $status = "inactive"; + $data = []; - $missing = json_decode( - parent::execute($this->url("wanted/missing?"))->getBody() - ); + $missing = json_decode( + parent::execute($this->url("wanted/missing?"))->getBody() + ); - $nextmonth = date( - "Y-m-d", - mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")) - ); - $tomorrow = date( - "Y-m-d", - mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")) - ); + $nextmonth = date( + "Y-m-d", + mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")) + ); + $tomorrow = date( + "Y-m-d", + mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")) + ); - $queue = json_decode( - parent::execute( - $this->url( - "calendar?start=" . $tomorrow . "&end=" . $nextmonth . "&" - ) - )->getBody() - ); - $collect = collect($queue); - $upcoming = $collect->where("hasFile", false); + $queue = json_decode( + parent::execute( + $this->url( + "calendar?start=" . $tomorrow . "&end=" . $nextmonth . "&" + ) + )->getBody() + ); + $collect = collect($queue); + $upcoming = $collect->where("hasFile", false); - $data = []; + $data = []; - //$date = new DateTime('NOW'); - if ($missing || $queue) { - $data["missing"] = $missing->{"totalRecords"} ?? 0; - $data["upcoming"] = $upcoming->count() ?? 0; - } + //$date = new DateTime('NOW'); + if ($missing || $queue) { + $data["missing"] = $missing->{"totalRecords"} ?? 0; + $data["upcoming"] = $upcoming->count() ?? 0; + } - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/v1/" . - $endpoint . - "apikey=" . - $this->config->apikey; - return $api_url; - } + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/v1/" . + $endpoint . + "apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/Recalbox/Recalbox.php b/Recalbox/Recalbox.php index 46e441e670..a46fe94131 100644 --- a/Recalbox/Recalbox.php +++ b/Recalbox/Recalbox.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("currentsong")); - - $array = explode("\n", $res->getBody()); - foreach ($array as $item) { - $item_array = explode(": ", $item); - if ($item_array[0] == "Artist") { - $artist = $item_array[1]; - } elseif ($item_array[0] == "Title") { - $song_title = $item_array[1]; - } - } - - $data = []; - - $data["artist"] = $artist ?? "None"; - $data["song_title"] = $song_title ?? "None"; - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "command/?cmd=" . - $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("currentsong")); + + $array = explode("\n", $res->getBody()); + foreach ($array as $item) { + $item_array = explode(": ", $item); + if ($item_array[0] == "Artist") { + $artist = $item_array[1]; + } elseif ($item_array[0] == "Title") { + $song_title = $item_array[1]; + } + } + + $data = []; + + $data["artist"] = $artist ?? "None"; + $data["song_title"] = $song_title ?? "None"; + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "command/?cmd=" . + $endpoint; + return $api_url; + } } diff --git a/SABnzbd/SABnzbd.php b/SABnzbd/SABnzbd.php index 534ed5ea61..42179ef5a5 100644 --- a/SABnzbd/SABnzbd.php +++ b/SABnzbd/SABnzbd.php @@ -1,67 +1,69 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("queue")); - if ($test->code === 200) { - $data = json_decode($test->response); - if (isset($data->error) && !empty($data->error)) { - $test->status = "Failed: " . $data->error; - } - } + public function test() + { + $test = parent::appTest($this->url("queue")); + if ($test->code === 200) { + $data = json_decode($test->response); + if (isset($data->error) && !empty($data->error)) { + $test->status = "Failed: " . $data->error; + } + } - echo $test->status; - } + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("queue")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("queue")); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - if ($details) { - $size = $details->queue->mbleft; - $rate = $details->queue->kbpersec; - $data["queue_size"] = format_bytes( - $size * 1000 * 1000, - false, - " ", - "" - ); - $data["current_speed"] = format_bytes( - $rate * 1000, - false, - " ", - "/s" - ); - $status = $size > 0 || $rate > 0 ? "active" : "inactive"; - } + if ($details) { + $size = $details->queue->mbleft; + $rate = $details->queue->kbpersec; + $data["queue_size"] = format_bytes( + $size * 1000 * 1000, + false, + " ", + "" + ); + $data["current_speed"] = format_bytes( + $rate * 1000, + false, + " ", + "/s" + ); + $status = $size > 0 || $rate > 0 ? "active" : "inactive"; + } - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $apikey = $this->config->apikey; - $api_url = - parent::normaliseurl($this->config->url) . - "api?output=json&apikey=" . - $apikey . - "&mode=" . - $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $apikey = $this->config->apikey; + $api_url = + parent::normaliseurl($this->config->url) . + "api?output=json&apikey=" . + $apikey . + "&mode=" . + $endpoint; + return $api_url; + } } diff --git a/SOGo/SOGo.php b/SOGo/SOGo.php index 0808d272f6..75fce96c38 100644 --- a/SOGo/SOGo.php +++ b/SOGo/SOGo.php @@ -1,4 +1,6 @@ -url, "/"); - $q = urlencode($query); - return redirect($url . "/search?q=" . $q); - } + public $type = "external"; // Whether to go to the external site or display results locally + public function getResults($query, $provider) + { + $url = rtrim($provider->url, "/"); + $q = urlencode($query); + return redirect($url . "/search?q=" . $q); + } } diff --git a/Server/Server.php b/Server/Server.php index d1dba8b00d..655c6b60a5 100644 --- a/Server/Server.php +++ b/Server/Server.php @@ -1,4 +1,6 @@ - 0){ + if ($hourDuration > 0) { $hourDuration = $hourDuration; } else { $hourDuration = '00h'; } - if($minDuration > 0){ + if ($minDuration > 0) { $minDuration = $minDuration; } else { $minDuration = '00m'; } - if($secDuration > 0){ + if ($secDuration > 0) { $secDuration = $secDuration; } else { $secDuration = '00s'; } - $HourMinSec = $hourDuration.$minDuration.$secDuration; + $HourMinSec = $hourDuration . $minDuration . $secDuration; return $HourMinSec; } @@ -169,7 +172,7 @@ public function livestats() public function url($endpoint) { - $api_url = parent::normaliseurl($this->config->url)."rpc/".$endpoint; + $api_url = parent::normaliseurl($this->config->url) . "rpc/" . $endpoint; return $api_url; } } diff --git a/Shinobi/Shinobi.php b/Shinobi/Shinobi.php index d0095150e8..31a69f09b8 100644 --- a/Shinobi/Shinobi.php +++ b/Shinobi/Shinobi.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $attrs = [ - "headers" => ["Accept" => "application/json"], - ]; - $test = parent::appTest($this->url("system/status"), $attrs); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - $attrs = [ - "headers" => ["Accept" => "application/json"], - ]; - - $missing = json_decode( - parent::execute($this->url("wanted/missing"), $attrs)->getBody() - ); - $queue = json_decode( - parent::execute($this->url("queue"), $attrs)->getBody() - ); - - $data = []; - - if ($missing || $queue) { - $data["missing"] = $missing->totalRecords ?? 0; - $data["queue"] = $queue->totalRecords ?? 0; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . - "api/v3/" . - $endpoint . - "?sortKey=series.title&apikey=" . - $this->config->apikey; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $attrs = [ + "headers" => ["Accept" => "application/json"], + ]; + $test = parent::appTest($this->url("system/status"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + $attrs = [ + "headers" => ["Accept" => "application/json"], + ]; + + $missing = json_decode( + parent::execute($this->url("wanted/missing"), $attrs)->getBody() + ); + $queue = json_decode( + parent::execute($this->url("queue"), $attrs)->getBody() + ); + + $data = []; + + if ($missing || $queue) { + $data["missing"] = $missing->totalRecords ?? 0; + $data["queue"] = $queue->totalRecords ?? 0; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . + "api/v3/" . + $endpoint . + "?sortKey=series.title&apikey=" . + $this->config->apikey; + return $api_url; + } } diff --git a/Sourcegraph/Sourcegraph.php b/Sourcegraph/Sourcegraph.php index f8b3b5138e..fe929f9cd2 100644 --- a/Sourcegraph/Sourcegraph.php +++ b/Sourcegraph/Sourcegraph.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("api/speedtest/latest/")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("api/speedtest/latest/")); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["ping"] = number_format($details->data->ping); - $data["download"] = number_format($details->data->download, 1); - $data["upload"] = number_format($details->data->upload, 1); - foreach ($this->config->availablestats as $stat) { - if (!isset(self::getAvailableStats()[$stat])) { - continue; - } - - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = self::formatUsingStat( - $stat, - $details->data->{$stat} - ); - - $data["visiblestats"][] = $newstat; - } - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public static function getAvailableStats() - { - return [ - "ping" => "Ping", - "download" => "Down", - "upload" => "Up", - "created_at" => "Time", - ]; - } - - private static function formatUsingStat($stat, $number) - { - if (!isset($number)) { - return "N/A"; - } - - switch ($stat) { - case "download": - case "upload": - return number_format($number) . "Mbit/s"; - case "ping": - return number_format($number) . "ms"; - case "created_at": - return (new \DateTime($number))->format("H:i"); - default: - return $number; - } - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("api/speedtest/latest/")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("api/speedtest/latest/")); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["ping"] = number_format($details->data->ping); + $data["download"] = number_format($details->data->download, 1); + $data["upload"] = number_format($details->data->upload, 1); + foreach ($this->config->availablestats as $stat) { + if (!isset(self::getAvailableStats()[$stat])) { + continue; + } + + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = self::formatUsingStat( + $stat, + $details->data->{$stat} + ); + + $data["visiblestats"][] = $newstat; + } + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public static function getAvailableStats() + { + return [ + "ping" => "Ping", + "download" => "Down", + "upload" => "Up", + "created_at" => "Time", + ]; + } + + private static function formatUsingStat($stat, $number) + { + if (!isset($number)) { + return "N/A"; + } + + switch ($stat) { + case "download": + case "upload": + return number_format($number) . "Mbit/s"; + case "ping": + return number_format($number) . "ms"; + case "created_at": + return (new \DateTime($number))->format("H:i"); + default: + return $number; + } + } } diff --git a/Splunk/Splunk.php b/Splunk/Splunk.php index c4f3f19f1e..f6469ccf7b 100644 --- a/Splunk/Splunk.php +++ b/Splunk/Splunk.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); - } + public function __construct() + { + $this->jar = new \GuzzleHttp\Cookie\CookieJar(); + } - public function login() - { - $username = $this->config->username; - $password = $this->config->password; + public function login() + { + $username = $this->config->username; + $password = $this->config->password; - if ( - !isset($username) || - empty($username) || - !isset($password) || - empty($password) - ) { - return; - } + if ( + !isset($username) || + empty($username) || + !isset($password) || + empty($password) + ) { + return; + } - $attrs = [ - "cookies" => $this->jar, - ]; - $res = parent::execute($this->url("?page=login"), $attrs); - $content = (string) $res->getBody(true); - preg_match( - "/name=\"loginform\[xsrfid\]\" value=\"([^\"]+)/", - $content, - $matches - ); - $xsrfid = $matches[1]; + $attrs = [ + "cookies" => $this->jar, + ]; + $res = parent::execute($this->url("?page=login"), $attrs); + $content = (string) $res->getBody(true); + preg_match( + "/name=\"loginform\[xsrfid\]\" value=\"([^\"]+)/", + $content, + $matches + ); + $xsrfid = $matches[1]; - $attrs = [ - "form_params" => [ - "loginform" => [ - "username" => $username, - "password" => $password, - "xsrfid" => $xsrfid, - "submitlogin" => "Login", - ], - ], - "cookies" => $this->jar, - "headers" => [ - "content-type" => "application/x-www-form-urlencoded", - ], - ]; - $res = parent::execute( - $this->url("?page=login"), - $attrs, - null, - "POST" - ); - } + $attrs = [ + "form_params" => [ + "loginform" => [ + "username" => $username, + "password" => $password, + "xsrfid" => $xsrfid, + "submitlogin" => "Login", + ], + ], + "cookies" => $this->jar, + "headers" => [ + "content-type" => "application/x-www-form-urlencoded", + ], + ]; + $res = parent::execute( + $this->url("?page=login"), + $attrs, + null, + "POST" + ); + } - public function test() - { - $this->login(); + public function test() + { + $this->login(); - $attrs = [ - "cookies" => $this->jar, - ]; - $test = parent::appTest($this->url("?page=statistics"), $attrs); - echo $test->status; - } + $attrs = [ + "cookies" => $this->jar, + ]; + $test = parent::appTest($this->url("?page=statistics"), $attrs); + echo $test->status; + } - public function livestats() - { - $this->login(); + public function livestats() + { + $this->login(); - $status = "inactive"; - $attrs = [ - "cookies" => $this->jar, - ]; - $res = parent::execute($this->url("?page=statistics"), $attrs); - $content = (string) $res->getBody(true); + $status = "inactive"; + $attrs = [ + "cookies" => $this->jar, + ]; + $res = parent::execute($this->url("?page=statistics"), $attrs); + $content = (string) $res->getBody(true); - $data = []; - if ( - preg_match("/Last update: ([^\<]+)/", $content, $matches) && - count($matches) > 1 - ) { - $status = "active"; - $data["last_update"] = trim($matches[1]); - } - return parent::getLiveStats($status, $data); - } + $data = []; + if ( + preg_match("/Last update: ([^\<]+)/", $content, $matches) && + count($matches) > 1 + ) { + $status = "active"; + $data["last_update"] = trim($matches[1]); + } + return parent::getLiveStats($status, $data); + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Squidex/Squidex.php b/Squidex/Squidex.php index 9806d56433..322954ff96 100644 --- a/Squidex/Squidex.php +++ b/Squidex/Squidex.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $apiKey = $this->config->apikey; - - $attrs = []; - $data = []; - $vars = [ - "body" => '{ "query": "{ systemStatus { status } }" }', - "headers" => [ - "Content-Type" => "application/json", - ], - ]; - - if ($apiKey) { - $vars["headers"]["ApiKey"] = $apiKey; - } - - $res = parent::execute( - $this->url("graphql"), - $attrs, - $vars - ); - - if ($res->getStatusCode() == 200) { - $details = json_decode($res->getBody()); - - if ($details != null && $details->data->systemStatus->status == "OK") { - echo "Welcome! You are connected to API."; - return true; - } - } - } - - - public function livestats() - { - $status = "inactive"; - $apiKey = $this->config->apikey; - - $attrs = []; - $data = []; - $vars = [ - "body" => '{ "query": "{ stats { scene_count scenes_size } }" }', - "headers" => [ - "Content-Type" => "application/json", - ], - ]; - - if ($apiKey) { - $vars["headers"]["ApiKey"] = $apiKey; - } - - $res = parent::execute( - $this->url("graphql"), - $attrs, - $vars - ); - - if ($res->getStatusCode() == 200) { - $status = "active"; - $details = json_decode($res->getBody()); - - if ($details) { - $data["scene_count"] = number_format($details->data->stats->scene_count); - $data["scenes_size"] = $this->formatBytes($details->data->stats->scenes_size); - } - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public function formatBytes($bytes, $precision = 2) - { - $units = ["B", "KB", "MB", "GB", "TB"]; - - $bytes = max($bytes, 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); - - $bytes /= pow(1024, $pow); - - return round($bytes, $precision) . " " . $units[$pow]; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $apiKey = $this->config->apikey; + + $attrs = []; + $data = []; + $vars = [ + "body" => '{ "query": "{ systemStatus { status } }" }', + "headers" => [ + "Content-Type" => "application/json", + ], + ]; + + if ($apiKey) { + $vars["headers"]["ApiKey"] = $apiKey; + } + + $res = parent::execute( + $this->url("graphql"), + $attrs, + $vars + ); + + if ($res->getStatusCode() == 200) { + $details = json_decode($res->getBody()); + + if ($details != null && $details->data->systemStatus->status == "OK") { + echo "Welcome! You are connected to API."; + return true; + } + } + } + + + public function livestats() + { + $status = "inactive"; + $apiKey = $this->config->apikey; + + $attrs = []; + $data = []; + $vars = [ + "body" => '{ "query": "{ stats { scene_count scenes_size } }" }', + "headers" => [ + "Content-Type" => "application/json", + ], + ]; + + if ($apiKey) { + $vars["headers"]["ApiKey"] = $apiKey; + } + + $res = parent::execute( + $this->url("graphql"), + $attrs, + $vars + ); + + if ($res->getStatusCode() == 200) { + $status = "active"; + $details = json_decode($res->getBody()); + + if ($details) { + $data["scene_count"] = number_format($details->data->stats->scene_count); + $data["scenes_size"] = $this->formatBytes($details->data->stats->scenes_size); + } + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public function formatBytes($bytes, $precision = 2) + { + $units = ["B", "KB", "MB", "GB", "TB"]; + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . " " . $units[$pow]; + } } diff --git a/Statping/Statping.php b/Statping/Statping.php index fdd307e348..3dec282522 100644 --- a/Statping/Statping.php +++ b/Statping/Statping.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - function get_request_attrs() - { - $attrs["headers"] = ["X-API-Key" => $this->config->apikey]; - return $attrs; - } + private function getRequestAttrs() + { + $attrs["headers"] = ["X-API-Key" => $this->config->apikey]; + return $attrs; + } - public function test() - { - $attrs = $this->get_request_attrs(); - $test = parent::appTest($this->url("/rest/system/version"), $attrs); - echo $test->status; - } + public function test() + { + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("/rest/system/version"), $attrs); + echo $test->status; + } public function livestats() { @@ -31,7 +33,7 @@ public function livestats() $needed_files = 0; $needed_bytes = 0; $status = 'inactive'; - $attrs = $this->get_request_attrs(); + $attrs = $this->getRequestAttrs(); # first get a list of folders $res = parent::execute($this->url('/rest/stats/folder'), $attrs); @@ -40,11 +42,11 @@ public function livestats() foreach ($details as $folder => $folder_status) { $folder_db_res = parent::execute($this->url("/rest/db/status?folder={$folder}"), $attrs); $folder_db = json_decode($folder_db_res->getBody()); - + if ($folder_db) { $needed_files += $folder_db->needFiles; $needed_bytes += $folder_db->needBytes; - } + } } if ($needed_files || $needed_bytes) { @@ -55,9 +57,9 @@ public function livestats() $data['needed_bytes'] = $needed_bytes; return parent::getLiveStats($status, $data); } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Synology/Synology.php b/Synology/Synology.php index 85980cc3cf..420e785a25 100644 --- a/Synology/Synology.php +++ b/Synology/Synology.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("data/stats.json")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("data/stats.json")); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["aircraft_with_pos"] = number_format( - $details->aircraft_with_pos - ); - $data["aircraft_without_pos"] = number_format( - $details->aircraft_without_pos - ); - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("data/stats.json")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("data/stats.json")); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["aircraft_with_pos"] = number_format( + $details->aircraft_with_pos + ); + $data["aircraft_without_pos"] = number_format( + $details->aircraft_without_pos + ); + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Tartube/Tartube.php b/Tartube/Tartube.php index 6eb7063812..454f6786e0 100644 --- a/Tartube/Tartube.php +++ b/Tartube/Tartube.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("cm?cmnd=Status 8")); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("cm?cmnd=Status 8")); - $details = json_decode($res->getBody()); - - $data = []; - - if ($details) { - $data["temperature"] = number_format( - $details->StatusSNS->AM2301->Temperature, - 1 - ); - $data["humidity"] = number_format( - $details->StatusSNS->AM2301->Humidity, - 1 - ); - $data["dewpoint"] = number_format( - $details->StatusSNS->AM2301->DewPoint, - 1 - ); - } - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("cm?cmnd=Status 8")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("cm?cmnd=Status 8")); + $details = json_decode($res->getBody()); + + $data = []; + + if ($details) { + $data["temperature"] = number_format( + $details->StatusSNS->AM2301->Temperature, + 1 + ); + $data["humidity"] = number_format( + $details->StatusSNS->AM2301->Humidity, + 1 + ); + $data["dewpoint"] = number_format( + $details->StatusSNS->AM2301->DewPoint, + 1 + ); + } + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Tautulli/Tautulli.php b/Tautulli/Tautulli.php index fcebee9dfb..931f6186b9 100644 --- a/Tautulli/Tautulli.php +++ b/Tautulli/Tautulli.php @@ -1,50 +1,52 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("arnold")); - if ($test->code === 200) { - $data = json_decode($test->response); - if (isset($data->error) && !empty($data->error)) { - $test->status = "Failed: " . $data->error; - } - } - - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("get_activity")); - $details = json_decode($res->getBody()); - - $data["stream_count"] = $details->response->data->stream_count ?? 0; - - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $apikey = $this->config->apikey; - $api_url = - parent::normaliseurl($this->config->url) . - "api/v2?apikey=" . - $apikey . - "&cmd=" . - $endpoint; - - return $api_url; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("arnold")); + if ($test->code === 200) { + $data = json_decode($test->response); + if (isset($data->error) && !empty($data->error)) { + $test->status = "Failed: " . $data->error; + } + } + + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("get_activity")); + $details = json_decode($res->getBody()); + + $data["stream_count"] = $details->response->data->stream_count ?? 0; + + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $apikey = $this->config->apikey; + $api_url = + parent::normaliseurl($this->config->url) . + "api/v2?apikey=" . + $apikey . + "&cmd=" . + $endpoint; + + return $api_url; + } } diff --git a/Tdarr/Tdarr.php b/Tdarr/Tdarr.php index cfc1d983b9..f12b5dfcb2 100644 --- a/Tdarr/Tdarr.php +++ b/Tdarr/Tdarr.php @@ -1,78 +1,80 @@ -url("api/v2/status/"); - $test = parent::appTest($url); + public function test() + { + $url = $this->url("api/v2/status/"); + $test = parent::appTest($url); - echo $test->status; - } + echo $test->status; + } - public function livestats() - { - $status = "inactive"; + public function livestats() + { + $status = "inactive"; - $reqData = [ - "data" => [ - "collection" => "StatisticsJSONDB", - "mode" => "getById", - "docID" => "statistics", - ], - ]; + $reqData = [ + "data" => [ + "collection" => "StatisticsJSONDB", + "mode" => "getById", + "docID" => "statistics", + ], + ]; - $url = $this->url("api/v2/cruddb/"); - // Setup cURL - $ch = curl_init($url); - curl_setopt_array($ch, [ - CURLOPT_POST => true, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => ["Content-Type: application/json"], - CURLOPT_POSTFIELDS => json_encode($reqData), - ]); + $url = $this->url("api/v2/cruddb/"); + // Setup cURL + $ch = curl_init($url); + curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ["Content-Type: application/json"], + CURLOPT_POSTFIELDS => json_encode($reqData), + ]); - // Send the request - $response = curl_exec($ch); + // Send the request + $response = curl_exec($ch); - // Check for errors - if ($response === false) { - die(curl_error($ch)); - } + // Check for errors + if ($response === false) { + die(curl_error($ch)); + } - $details = []; - // Decode the response - $details = json_decode($response, true); + $details = []; + // Decode the response + $details = json_decode($response, true); - $data = []; - $data["queue"] = ""; - $data["processed"] = ""; - $data["errored"] = ""; + $data = []; + $data["queue"] = ""; + $data["processed"] = ""; + $data["errored"] = ""; - if ($details) { - $data["queue"] = $details["table1Count"] + $details["table4Count"]; - $data["processed"] = - $details["table2Count"] + $details["table5Count"]; - $errored = $details["table3Count"] + $details["table6Count"]; - if ($errored > 0) { - $data["errored"] = $errored; - } - } + if ($details) { + $data["queue"] = $details["table1Count"] + $details["table4Count"]; + $data["processed"] = + $details["table2Count"] + $details["table5Count"]; + $errored = $details["table3Count"] + $details["table6Count"]; + if ($errored > 0) { + $data["errored"] = $errored; + } + } - // Close the cURL handler - curl_close($ch); + // Close the cURL handler + curl_close($ch); - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/TechnitiumDNS/TechnitiumDNS.php b/TechnitiumDNS/TechnitiumDNS.php index 3f7c989464..0459e69bf1 100644 --- a/TechnitiumDNS/TechnitiumDNS.php +++ b/TechnitiumDNS/TechnitiumDNS.php @@ -1,4 +1,6 @@ -getConfigValue("username", null); - $password = $this->getConfigValue("password", null); - $ignoreTls = $this->getConfigValue("ignore_tls", false); - - $isLoginNeeded = - !is_null($username) && - !empty($username) && - !is_null($password) && - !empty($password); - - $attrs["headers"] = ["Accept" => "application/json"]; - if ($isLoginNeeded) { - $attrs["auth"] = [$username, $password]; - } - if ($ignoreTls) { - $attrs["verify"] = false; - } - - return $attrs; - } - - public function test() - { - $attrs = $this->getRequestAttrs(); - $test = parent::appTest($this->url("api/version"), $attrs); - - echo $test->status; - } - - public function livestats() - { - $apiEndpoints = collect([ - "httpRouters" => "api/http/routers", - "httpServices" => "api/http/services", - "tcpRouters" => "api/tcp/routers", - "tcpServices" => "api/tcp/services", - ]); - - $status = "active"; - $attrs = $this->getRequestAttrs(); - - $responses = $apiEndpoints->mapWithKeys(function ($endpoint, $key) use ( - $attrs - ) { - $response = parent::execute($this->url($endpoint), $attrs); - $body = json_decode($response->getBody()); - $bodyCollection = collect($body); - - return [ - $key => [ - "data" => $bodyCollection - ->filter(function ($value, $key) { - return $value->status === "enabled"; - }) - ->count(), - "total" => $bodyCollection->count(), - ], - ]; - }); - - $data = $this->getViewData( - $this->getConfigValue("fields", "E"), - $responses - ); - return parent::getLiveStats($status, $data); - } - - public function getViewData($config, $responses) - { - $nullValue = ["data" => 0, "total" => 0]; - - switch ($config) { - /* HTTP routers/services only */ - case "H": - return [ - "left" => [ - "title" => "Routers", - "data" => $responses->get("httpRouters", $nullValue)[ - "data" - ], - "total" => $responses->get("httpRouters", $nullValue)[ - "total" - ], - ], - "right" => [ - "title" => "Services", - "data" => $responses->get("httpServices", $nullValue)[ - "data" - ], - "total" => $responses->get("httpServices", $nullValue)[ - "total" - ], - ], - ]; - break; - - /* TCP routers/services only */ - case "T": - return [ - "left" => [ - "title" => "Routers", - "data" => $responses->get("tcpRouters", $nullValue)[ - "data" - ], - "total" => $responses->get("tcpRouters", $nullValue)[ - "total" - ], - ], - "right" => [ - "title" => "Services", - "data" => $responses->get("tcpServices", $nullValue)[ - "data" - ], - "total" => $responses->get("tcpServices", $nullValue)[ - "total" - ], - ], - ]; - - /* Routers only */ - case "R": - return [ - "left" => [ - "title" => "HTTP", - "data" => $responses->get("httpRouters", $nullValue)[ - "data" - ], - "total" => $responses->get("httpRouters", $nullValue)[ - "total" - ], - ], - "right" => [ - "title" => "TCP", - "data" => $responses->get("tcpRouters", $nullValue)[ - "data" - ], - "total" => $responses->get("tcpRouters", $nullValue)[ - "total" - ], - ], - ]; - - /* Services only */ - case "S": - return [ - "left" => [ - "title" => "HTTP", - "data" => $responses->get("httpServices", $nullValue)[ - "data" - ], - "total" => $responses->get("httpServices", $nullValue)[ - "total" - ], - ], - "right" => [ - "title" => "TCP", - "data" => $responses->get("tcpServices", $nullValue)[ - "data" - ], - "total" => $responses->get("tcpServices", $nullValue)[ - "total" - ], - ], - ]; - - /* Everything */ - default: - return [ - "left" => [ - "title" => "Routers", - "data" => - $responses->get("httpRouters", $nullValue)["data"] + - $responses->get("tcpRouters", $nullValue)["data"], - "total" => - $responses->get("httpRouters", $nullValue)[ - "total" - ] + - $responses->get("tcpRouters", $nullValue)["total"], - ], - "right" => [ - "title" => "Services", - "data" => - $responses->get("httpServices", $nullValue)[ - "data" - ] + - $responses->get("tcpServices", $nullValue)["data"], - "total" => - $responses->get("httpServices", $nullValue)[ - "total" - ] + - $responses->get("tcpServices", $nullValue)["total"], - ], - ]; - } - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public function getRequestAttrs() + { + $username = $this->getConfigValue("username", null); + $password = $this->getConfigValue("password", null); + $ignoreTls = $this->getConfigValue("ignore_tls", false); + + $isLoginNeeded = + !is_null($username) && + !empty($username) && + !is_null($password) && + !empty($password); + + $attrs["headers"] = ["Accept" => "application/json"]; + if ($isLoginNeeded) { + $attrs["auth"] = [$username, $password]; + } + if ($ignoreTls) { + $attrs["verify"] = false; + } + + return $attrs; + } + + public function test() + { + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("api/version"), $attrs); + + echo $test->status; + } + + public function livestats() + { + $apiEndpoints = collect([ + "httpRouters" => "api/http/routers", + "httpServices" => "api/http/services", + "tcpRouters" => "api/tcp/routers", + "tcpServices" => "api/tcp/services", + ]); + + $status = "active"; + $attrs = $this->getRequestAttrs(); + + $responses = $apiEndpoints->mapWithKeys(function ( + $endpoint, + $key + ) use ( + $attrs + ) { + $response = parent::execute($this->url($endpoint), $attrs); + $body = json_decode($response->getBody()); + $bodyCollection = collect($body); + + return [ + $key => [ + "data" => $bodyCollection + ->filter(function ($value, $key) { + return $value->status === "enabled"; + }) + ->count(), + "total" => $bodyCollection->count(), + ], + ]; + }); + + $data = $this->getViewData( + $this->getConfigValue("fields", "E"), + $responses + ); + return parent::getLiveStats($status, $data); + } + + public function getViewData($config, $responses) + { + $nullValue = ["data" => 0, "total" => 0]; + + switch ($config) { + /* HTTP routers/services only */ + case "H": + return [ + "left" => [ + "title" => "Routers", + "data" => $responses->get("httpRouters", $nullValue)[ + "data" + ], + "total" => $responses->get("httpRouters", $nullValue)[ + "total" + ], + ], + "right" => [ + "title" => "Services", + "data" => $responses->get("httpServices", $nullValue)[ + "data" + ], + "total" => $responses->get("httpServices", $nullValue)[ + "total" + ], + ], + ]; + break; + + /* TCP routers/services only */ + case "T": + return [ + "left" => [ + "title" => "Routers", + "data" => $responses->get("tcpRouters", $nullValue)[ + "data" + ], + "total" => $responses->get("tcpRouters", $nullValue)[ + "total" + ], + ], + "right" => [ + "title" => "Services", + "data" => $responses->get("tcpServices", $nullValue)[ + "data" + ], + "total" => $responses->get("tcpServices", $nullValue)[ + "total" + ], + ], + ]; + + /* Routers only */ + case "R": + return [ + "left" => [ + "title" => "HTTP", + "data" => $responses->get("httpRouters", $nullValue)[ + "data" + ], + "total" => $responses->get("httpRouters", $nullValue)[ + "total" + ], + ], + "right" => [ + "title" => "TCP", + "data" => $responses->get("tcpRouters", $nullValue)[ + "data" + ], + "total" => $responses->get("tcpRouters", $nullValue)[ + "total" + ], + ], + ]; + + /* Services only */ + case "S": + return [ + "left" => [ + "title" => "HTTP", + "data" => $responses->get("httpServices", $nullValue)[ + "data" + ], + "total" => $responses->get("httpServices", $nullValue)[ + "total" + ], + ], + "right" => [ + "title" => "TCP", + "data" => $responses->get("tcpServices", $nullValue)[ + "data" + ], + "total" => $responses->get("tcpServices", $nullValue)[ + "total" + ], + ], + ]; + + /* Everything */ + default: + return [ + "left" => [ + "title" => "Routers", + "data" => + $responses->get("httpRouters", $nullValue)["data"] + + $responses->get("tcpRouters", $nullValue)["data"], + "total" => + $responses->get("httpRouters", $nullValue)[ + "total" + ] + + $responses->get("tcpRouters", $nullValue)["total"], + ], + "right" => [ + "title" => "Services", + "data" => + $responses->get("httpServices", $nullValue)[ + "data" + ] + + $responses->get("tcpServices", $nullValue)["data"], + "total" => + $responses->get("httpServices", $nullValue)[ + "total" + ] + + $responses->get("tcpServices", $nullValue)["total"], + ], + ]; + } + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } } diff --git a/Transmission/Transmission.php b/Transmission/Transmission.php index f25f2784e0..1e93de7a60 100644 --- a/Transmission/Transmission.php +++ b/Transmission/Transmission.php @@ -1,166 +1,168 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - $body["method"] = "torrent-get"; - $body["arguments"] = [ - "fields" => ["percentDone", "status", "rateDownload", "rateUpload"], - ]; - $this->vars = [ - "http_errors" => false, - "timeout" => 5, - "body" => json_encode($body), - ]; - } - - public function test() - { - $test = $this->sendTest(); - - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $res = $this->sendRequest(); - if ($res == null) { - //Log::debug('Transmission connection failed'); - return ""; - } - - $details = json_decode($res->getBody()); - if (!isset($details->arguments)) { - //Log::debug('Failed to fetch data from Transmission'); - return ""; - } - - $data = []; - - $torrents = $details->arguments->torrents; - $seeding_torrents = 0; - $leeching_torrents = 0; - $rateDownload = $rateUpload = 0; - - foreach ($torrents as $thisTorrent) { - $rateDownload += $thisTorrent->rateDownload; - $rateUpload += $thisTorrent->rateUpload; - if ($thisTorrent->status == 6) { - $seeding_torrents += 1; - } - if($thisTorrent->status == 4) { - $leeching_torrents += 1; - } - } - - if ($leeching_torrents > 0) { - $status = "active"; - } - - $data["download_rate"] = format_bytes( - $rateDownload, - false, - " ", - "/s" - ); - $data["upload_rate"] = format_bytes( - $rateUpload, - false, - " ", - "/s" - ); - $data["seed_count"] = $seeding_torrents; - $data["leech_count"] = $leeching_torrents; - - return parent::getLiveStats($status, $data); - } - - private function sendTest() - { - $this->setClientOptions(); - $test = parent::appTest( - $this->url("transmission/rpc"), - $this->attrs, - $this->vars - ); - if ($test->code === 409) { - $this->setClientOptions(); - $test = parent::appTest( - $this->url("transmission/rpc"), - $this->attrs, - $this->vars - ); - } - return $test; - } - - private function sendRequest() - { - $this->setClientOptions(); - $res = parent::execute( - $this->url("transmission/rpc"), - $this->attrs, - $this->vars - ); - if ($res->getStatusCode() === 409) { - $this->setClientOptions(); - $res = parent::execute( - $this->url("transmission/rpc"), - $this->attrs, - $this->vars - ); - } - return $res; - } - - private function setClientOptions() - { - if ($this->config->username != "" || $this->config->password != "") { - $this->attrs = [ - "auth" => [ - $this->config->username, - $this->config->password, - "Basic", - ], - ]; - } - $res = parent::execute( - $this->url("transmission/rpc"), - $this->attrs, - $this->vars - ); - - try { - //print_r($res); - $xtId = $res->getHeaderLine("X-Transmission-Session-Id"); - if ($xtId != null) { - $this->attrs["headers"] = [ - "X-Transmission-Session-Id" => $xtId, - ]; - } else { - //Log::error("Unable to get Transmission session information"); - //Log::debug("Status Code: ".$res->getStatusCode()); - } - } catch (\GuzzleHttp\Exception\ConnectException $e) { - //Log::error("Failed connection to Transmission"); - return false; - } - return true; - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public $config; + public $attrs = []; + public $vars; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + protected $method = "POST"; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + $body["method"] = "torrent-get"; + $body["arguments"] = [ + "fields" => ["percentDone", "status", "rateDownload", "rateUpload"], + ]; + $this->vars = [ + "http_errors" => false, + "timeout" => 5, + "body" => json_encode($body), + ]; + } + + public function test() + { + $test = $this->sendTest(); + + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $res = $this->sendRequest(); + if ($res == null) { + //Log::debug('Transmission connection failed'); + return ""; + } + + $details = json_decode($res->getBody()); + if (!isset($details->arguments)) { + //Log::debug('Failed to fetch data from Transmission'); + return ""; + } + + $data = []; + + $torrents = $details->arguments->torrents; + $seeding_torrents = 0; + $leeching_torrents = 0; + $rateDownload = $rateUpload = 0; + + foreach ($torrents as $thisTorrent) { + $rateDownload += $thisTorrent->rateDownload; + $rateUpload += $thisTorrent->rateUpload; + if ($thisTorrent->status == 6) { + $seeding_torrents += 1; + } + if ($thisTorrent->status == 4) { + $leeching_torrents += 1; + } + } + + if ($leeching_torrents > 0) { + $status = "active"; + } + + $data["download_rate"] = format_bytes( + $rateDownload, + false, + " ", + "/s" + ); + $data["upload_rate"] = format_bytes( + $rateUpload, + false, + " ", + "/s" + ); + $data["seed_count"] = $seeding_torrents; + $data["leech_count"] = $leeching_torrents; + + return parent::getLiveStats($status, $data); + } + + private function sendTest() + { + $this->setClientOptions(); + $test = parent::appTest( + $this->url("transmission/rpc"), + $this->attrs, + $this->vars + ); + if ($test->code === 409) { + $this->setClientOptions(); + $test = parent::appTest( + $this->url("transmission/rpc"), + $this->attrs, + $this->vars + ); + } + return $test; + } + + private function sendRequest() + { + $this->setClientOptions(); + $res = parent::execute( + $this->url("transmission/rpc"), + $this->attrs, + $this->vars + ); + if ($res->getStatusCode() === 409) { + $this->setClientOptions(); + $res = parent::execute( + $this->url("transmission/rpc"), + $this->attrs, + $this->vars + ); + } + return $res; + } + + private function setClientOptions() + { + if ($this->config->username != "" || $this->config->password != "") { + $this->attrs = [ + "auth" => [ + $this->config->username, + $this->config->password, + "Basic", + ], + ]; + } + $res = parent::execute( + $this->url("transmission/rpc"), + $this->attrs, + $this->vars + ); + + try { + //print_r($res); + $xtId = $res->getHeaderLine("X-Transmission-Session-Id"); + if ($xtId != null) { + $this->attrs["headers"] = [ + "X-Transmission-Session-Id" => $xtId, + ]; + } else { + //Log::error("Unable to get Transmission session information"); + //Log::debug("Status Code: ".$res->getStatusCode()); + } + } catch (\GuzzleHttp\Exception\ConnectException $e) { + //Log::error("Failed connection to Transmission"); + return false; + } + return true; + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/Trilium/Trilium.php b/Trilium/Trilium.php index 7c9ef0700a..d2ee364062 100644 --- a/Trilium/Trilium.php +++ b/Trilium/Trilium.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } - - public function test() - { - $test = parent::appTest($this->url("core/ping"), $this->attrs()); - if ($test->code === 200) { - $data = $test->response; - if ($test->response != '"pong"') { - $test->status = "Failed: " . $data; - } - } - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - $data = []; - - $res = parent::execute($this->url("system/info"), $this->attrs()); - $details = json_decode($res->getBody()); - $seconds = $details->uptime_seconds ?? 0; - $data["uptime"] = $this->uptime($seconds); - - $res = parent::execute($this->url("alert/list"), $this->attrs()); - $details = json_decode($res->getBody(), true); - list($data["alert_tot"], $data["alert_crit"]) = $this->alerts($details); - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $api_url = - parent::normaliseurl($this->config->url) . "api/v2.0/" . $endpoint; - return $api_url; - } - - public function attrs() - { - $ignoreTls = $this->getConfigValue("ignore_tls", false); - $apikey = $this->config->apikey; - $attrs["headers"] = [ - "content-type" => "application/json", - "Authorization" => "Bearer " . $apikey, - ]; - - if ($ignoreTls) { - $attrs["verify"] = false; - } - - return $attrs; - } - - public function uptime($inputSeconds) - { - // Adapted from https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds - - $res = ""; - $secondsInAMinute = 60; - $secondsInAnHour = 60 * $secondsInAMinute; - $secondsInADay = 24 * $secondsInAnHour; - - // extract days - $days = floor($inputSeconds / $secondsInADay); - - // extract hours - $hourSeconds = $inputSeconds % $secondsInADay; - $hours = floor($hourSeconds / $secondsInAnHour); - - // extract minutes - $minuteSeconds = $hourSeconds % $secondsInAnHour; - $minutes = floor($minuteSeconds / $secondsInAMinute); - - // extract the remaining seconds - $remainingSeconds = $minuteSeconds % $secondsInAMinute; - $seconds = ceil($remainingSeconds); - - //$res = strval($days).'d '.strval($hours).':'.sprintf('%02d', $minutes).':'.sprintf('%02d', $seconds); - if ($days > 0) { - $res = - strval($days) . - "d " . - strval($hours) . - ":" . - sprintf("%02d", $minutes); - } else { - $res = - strval($hours) . - ":" . - sprintf("%02d", $minutes) . - ":" . - sprintf("%02d", $seconds); - } - return $res; - } - - public function alerts($alert) - { - $count_total = $count_critical = 0; - foreach ($alert as $key => $value) { - if ($value["dismissed"] == false) { - $count_total += 1; - if (!in_array($value["level"], array("NOTICE", "INFO"))) { - $count_critical += 1; - } - } - } - - return array(strval($count_total), strval($count_critical)); - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } + public $config; + + //protected $login_first = true; // Uncomment if api requests need to be authed first + //protected $method = 'POST'; // Uncomment if requests to the API should be set by POST + + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url("core/ping"), $this->attrs()); + if ($test->code === 200) { + $data = $test->response; + if ($test->response != '"pong"') { + $test->status = "Failed: " . $data; + } + } + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + + $res = parent::execute($this->url("system/info"), $this->attrs()); + $details = json_decode($res->getBody()); + $seconds = $details->uptime_seconds ?? 0; + $data["uptime"] = $this->uptime($seconds); + + $res = parent::execute($this->url("alert/list"), $this->attrs()); + $details = json_decode($res->getBody(), true); + list($data["alert_tot"], $data["alert_crit"]) = $this->alerts($details); + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = + parent::normaliseurl($this->config->url) . "api/v2.0/" . $endpoint; + return $api_url; + } + + public function attrs() + { + $ignoreTls = $this->getConfigValue("ignore_tls", false); + $apikey = $this->config->apikey; + $attrs["headers"] = [ + "content-type" => "application/json", + "Authorization" => "Bearer " . $apikey, + ]; + + if ($ignoreTls) { + $attrs["verify"] = false; + } + + return $attrs; + } + + public function uptime($inputSeconds) + { + // Adapted from https://stackoverflow.com/questions/8273804/convert-seconds-into-days-hours-minutes-and-seconds + + $res = ""; + $secondsInAMinute = 60; + $secondsInAnHour = 60 * $secondsInAMinute; + $secondsInADay = 24 * $secondsInAnHour; + + // extract days + $days = floor($inputSeconds / $secondsInADay); + + // extract hours + $hourSeconds = $inputSeconds % $secondsInADay; + $hours = floor($hourSeconds / $secondsInAnHour); + + // extract minutes + $minuteSeconds = $hourSeconds % $secondsInAnHour; + $minutes = floor($minuteSeconds / $secondsInAMinute); + + // extract the remaining seconds + $remainingSeconds = $minuteSeconds % $secondsInAMinute; + $seconds = ceil($remainingSeconds); + + //$res = strval($days).'d '.strval($hours).':'.sprintf('%02d', $minutes).':'.sprintf('%02d', $seconds); + if ($days > 0) { + $res = + strval($days) . + "d " . + strval($hours) . + ":" . + sprintf("%02d", $minutes); + } else { + $res = + strval($hours) . + ":" . + sprintf("%02d", $minutes) . + ":" . + sprintf("%02d", $seconds); + } + return $res; + } + + public function alerts($alert) + { + $count_total = $count_critical = 0; + foreach ($alert as $key => $value) { + if ($value["dismissed"] == false) { + $count_total += 1; + if (!in_array($value["level"], array("NOTICE", "INFO"))) { + $count_critical += 1; + } + } + } + + return array(strval($count_total), strval($count_critical)); + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } } diff --git a/TrueNASSCALE/TrueNASSCALE.php b/TrueNASSCALE/TrueNASSCALE.php index 8a2c1a5947..1319ba5f18 100644 --- a/TrueNASSCALE/TrueNASSCALE.php +++ b/TrueNASSCALE/TrueNASSCALE.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); + } + + public function test() + { + $test = parent::appTest( + $this->url("/api/auth/login"), + $this->getLoginAttributes(), + ); - function __construct() - { - $this->jar = new \GuzzleHttp\Cookie\CookieJar; - } + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + + parent::execute( + $this->url("/api/auth/login"), + $this->getLoginAttributes(), + null, + 'POST' + ); - public function test() - { - $test = parent::appTest( - $this->url("/api/auth/login"), - $this->getLoginAttributes(), + $res = parent::execute( + $this->url("/proxy/network/api/s/default/stat/health"), + $this->getAttributes(), + null, + 'GET' ); - echo $test->status; - } - - public function livestats() - { - $status = "inactive"; - - parent::execute( - $this->url("/api/auth/login"), - $this->getLoginAttributes(), - null, - 'POST' - ); - - $res = parent::execute( - $this->url("/proxy/network/api/s/default/stat/health"), - $this->getAttributes(), - null, - 'GET' - ); - - $details = json_decode($res->getBody()); - - $data = []; - - if (isset($details->data)) { - $data['error'] = false; - foreach ($details->data as $key => $detail) { - if ($detail->subsystem === 'wlan') { - $data['wlan_users'] = $detail->num_user; - $data['wlan_ap'] = $detail->num_ap; - $data['wlan_dc'] = $detail->num_disconnected; - } - - if ($detail->subsystem === 'lan') { - $data['lan_users'] = $detail->num_user; - } - - if ($detail->subsystem === 'wan') { - $data['wan_avail'] = number_format($detail->uptime_stats->WAN->availability,0); - } - } - } else { - $data['error'] = true; - } - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - $url = parse_url(parent::normaliseurl($this->config->url)); - $scheme = $url["scheme"]; - $domain = $url["host"]; - $port = isset($url["port"]) ? $url["port"] : "443"; - - $api_url = - $scheme . - "://" . - $domain . - ":" . - $port . - $endpoint; - - return $api_url; - } - - public function getConfigValue($key, $default = null) - { - return isset($this->config) && isset($this->config->$key) - ? $this->config->$key - : $default; - } - - public function getLoginAttributes() - { - $ignoreTls = $this->getConfigValue("ignore_tls", false); - $username = $this->config->username; - $password = $this->config->password; - - $body = [ - "username" => $username, - "password" => $password, - ]; - - $attrs = [ - "body" => json_encode($body), - "cookies" => $this->jar, - "headers" => [ - "Content-Type" => "application/json" - ] - ]; - - if ($ignoreTls) { - $attrs["verify"] = false; - } - - return $attrs; - } - - public function getAttributes() - { - $attrs = [ - "cookies" => $this->jar, - ]; - - $ignoreTls = $this->getConfigValue("ignore_tls", false); - - if ($ignoreTls) { - $attrs["verify"] = false; - } - - return $attrs; - } + $details = json_decode($res->getBody()); + + $data = []; + + if (isset($details->data)) { + $data['error'] = false; + foreach ($details->data as $key => $detail) { + if ($detail->subsystem === 'wlan') { + $data['wlan_users'] = $detail->num_user; + $data['wlan_ap'] = $detail->num_ap; + $data['wlan_dc'] = $detail->num_disconnected; + } + + if ($detail->subsystem === 'lan') { + $data['lan_users'] = $detail->num_user; + } + + if ($detail->subsystem === 'wan') { + $data['wan_avail'] = number_format($detail->uptime_stats->WAN->availability, 0); + } + } + } else { + $data['error'] = true; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $url = parse_url(parent::normaliseurl($this->config->url)); + $scheme = $url["scheme"]; + $domain = $url["host"]; + $port = isset($url["port"]) ? $url["port"] : "443"; + + $api_url = + $scheme . + "://" . + $domain . + ":" . + $port . + $endpoint; + + return $api_url; + } + + public function getConfigValue($key, $default = null) + { + return isset($this->config) && isset($this->config->$key) + ? $this->config->$key + : $default; + } + + public function getLoginAttributes() + { + $ignoreTls = $this->getConfigValue("ignore_tls", false); + $username = $this->config->username; + $password = $this->config->password; + + $body = [ + "username" => $username, + "password" => $password, + ]; + + $attrs = [ + "body" => json_encode($body), + "cookies" => $this->jar, + "headers" => [ + "Content-Type" => "application/json" + ] + ]; + + if ($ignoreTls) { + $attrs["verify"] = false; + } + + return $attrs; + } + + public function getAttributes() + { + $attrs = [ + "cookies" => $this->jar, + ]; + + $ignoreTls = $this->getConfigValue("ignore_tls", false); + + if ($ignoreTls) { + $attrs["verify"] = false; + } + + return $attrs; + } } diff --git a/UniFiProtect/UniFiProtect.php b/UniFiProtect/UniFiProtect.php index be0511edd0..f8cc2c4c8f 100644 --- a/UniFiProtect/UniFiProtect.php +++ b/UniFiProtect/UniFiProtect.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/VMwareESXi/VMwareESXi.php b/VMwareESXi/VMwareESXi.php index cd53f6d89f..50caf5905b 100644 --- a/VMwareESXi/VMwareESXi.php +++ b/VMwareESXi/VMwareESXi.php @@ -1,35 +1,37 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/VMwarevCenter/VMwarevCenter.php b/VMwarevCenter/VMwarevCenter.php index 3667bd4cf7..5706b1a5a8 100644 --- a/VMwarevCenter/VMwarevCenter.php +++ b/VMwarevCenter/VMwarevCenter.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set } @@ -25,27 +28,23 @@ public function livestats() $data = []; - if($details) - { - foreach($details as $data_point) - { - if($data_point->type == "time") - { - $data["last_session_time"] = number_format($data_point->value / 60); - } - if($data_point->type == "area") - { - $area = $data_point->value / 10000; - $data["last_session_area"] = number_format($area, 2); - } + if ($details) { + foreach ($details as $data_point) { + if ($data_point->type == "time") { + $data["last_session_time"] = number_format($data_point->value / 60); + } + if ($data_point->type == "area") { + $area = $data_point->value / 10000; + $data["last_session_area"] = number_format($area, 2); } + } } return parent::getLiveStats($status, $data); } public function url($endpoint) { - $api_url = parent::normaliseurl($this->config->url).$endpoint; + $api_url = parent::normaliseurl($this->config->url) . $endpoint; return $api_url; } -} \ No newline at end of file +} diff --git a/Vault/Vault.php b/Vault/Vault.php index b82a205bae..51ad00f510 100644 --- a/Vault/Vault.php +++ b/Vault/Vault.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/VuPlus/VuPlus.php b/VuPlus/VuPlus.php index a1eaa98c40..0a740af9ee 100644 --- a/VuPlus/VuPlus.php +++ b/VuPlus/VuPlus.php @@ -1,42 +1,44 @@ -url("api/about")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("api/about")); + echo $test->status; + } - public function livestats() - { - $res = parent::execute($this->url("api/about")); - $content = (string) $res->getBody(true); - $result_data = json_decode($content); - if ( - !isset($result_data) || - !isset($result_data->service) || - !$result_data->service->result - ) { - return parent::getLiveStats("inactive", ["channel" => "Standby"]); - } + public function livestats() + { + $res = parent::execute($this->url("api/about")); + $content = (string) $res->getBody(true); + $result_data = json_decode($content); + if ( + !isset($result_data) || + !isset($result_data->service) || + !$result_data->service->result + ) { + return parent::getLiveStats("inactive", ["channel" => "Standby"]); + } - $data = [ - "channel" => $result_data->service->name, - ]; - return parent::getLiveStats("active", $data); - } + $data = [ + "channel" => $result_data->service->name, + ]; + return parent::getLiveStats("active", $data); + } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/WLED/WLED.php b/WLED/WLED.php index 9cd310d8e4..aae3564cfd 100644 --- a/WLED/WLED.php +++ b/WLED/WLED.php @@ -1,4 +1,6 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - /** - * Try to obtain user information to test login - */ - public function login() - { - $api_token = $this->config->username; - $attrs = [ - "headers" => ["Authorization" => "Bearer " . $api_token], - ]; - return parent::execute($this->url("user"), $attrs, null, "GET"); - } + /** + * Try to obtain user information to test login + */ + public function login() + { + $api_token = $this->config->username; + $attrs = [ + "headers" => ["Authorization" => "Bearer " . $api_token], + ]; + return parent::execute($this->url("user"), $attrs, null, "GET"); + } - /** - * "Login" the user and return the username - */ - public function test() - { - $test = $this->login(); - if ($test->getStatusCode() === 200 && $test->getBody()) { - $wk_resp = json_decode($test->getBody()); - echo "Hello " . $wk_resp->data->username; - } else { - echo "Failed"; - } - } + /** + * "Login" the user and return the username + */ + public function test() + { + $test = $this->login(); + if ($test->getStatusCode() === 200 && $test->getBody()) { + $wk_resp = json_decode($test->getBody()); + echo "Hello " . $wk_resp->data->username; + } else { + echo "Failed"; + } + } - /** - * Obtain the user summary and return the total of Reviews and Lessons - */ - public function livestats() - { - $status = "inactive"; - $now = \Carbon\Carbon::now(); - $api_token = $this->config->username; - $attrs = [ - "headers" => ["Authorization" => "Bearer " . $api_token], - ]; - $res = parent::execute($this->url("summary"), $attrs, null, "GET"); - $details = json_decode($res->getBody()); - $data = ["lessons" => 0, "reviews" => 0]; - foreach ($details->data->lessons as $lesson) { - $available_at = \Carbon\Carbon::createFromTimeString( - $lesson->available_at - ); - if ($now >= $available_at) { - $data["lessons"] += count($lesson->subject_ids); - } - } - foreach ($details->data->reviews as $review) { - $available_at = \Carbon\Carbon::createFromTimeString( - $review->available_at - ); - if ($now >= $available_at) { - $data["reviews"] += count($review->subject_ids); - } - } + /** + * Obtain the user summary and return the total of Reviews and Lessons + */ + public function livestats() + { + $status = "inactive"; + $now = \Carbon\Carbon::now(); + $api_token = $this->config->username; + $attrs = [ + "headers" => ["Authorization" => "Bearer " . $api_token], + ]; + $res = parent::execute($this->url("summary"), $attrs, null, "GET"); + $details = json_decode($res->getBody()); + $data = ["lessons" => 0, "reviews" => 0]; + foreach ($details->data->lessons as $lesson) { + $available_at = \Carbon\Carbon::createFromTimeString( + $lesson->available_at + ); + if ($now >= $available_at) { + $data["lessons"] += count($lesson->subject_ids); + } + } + foreach ($details->data->reviews as $review) { + $available_at = \Carbon\Carbon::createFromTimeString( + $review->available_at + ); + if ($now >= $available_at) { + $data["reviews"] += count($review->subject_ids); + } + } - return parent::getLiveStats($status, $data); - } + return parent::getLiveStats($status, $data); + } - /** - * Build api url - */ - public function url($endpoint) - { - $api_url = - parent::normaliseurl("https://api.wanikani.com/v2/") . $endpoint; - return $api_url; - } + /** + * Build api url + */ + public function url($endpoint) + { + $api_url = + parent::normaliseurl("https://api.wanikani.com/v2/") . $endpoint; + return $api_url; + } } diff --git a/WatchYourLAN/WatchYourLAN.php b/WatchYourLAN/WatchYourLAN.php index b1a16ba1cd..60d204d3ab 100644 --- a/WatchYourLAN/WatchYourLAN.php +++ b/WatchYourLAN/WatchYourLAN.php @@ -1,5 +1,7 @@ -url, "/"); - $q = urlencode($query); - return redirect($url . "/search?q=" . $q); - } + public function getResults($query, $provider) + { + $url = rtrim($provider->url, "/"); + $q = urlencode($query); + return redirect($url . "/search?q=" . $q); + } } diff --git a/Wikijs/Wikijs.php b/Wikijs/Wikijs.php index 32aea5cd65..c76a113839 100644 --- a/Wikijs/Wikijs.php +++ b/Wikijs/Wikijs.php @@ -1,4 +1,6 @@ - { - global.appUnderTest = `${appDirectory}`; - - const appJson = getAppJson(appDirectory); - const iconName = appJson.icon || ""; - - // Icon tests - test("should have an icon file", () => { - return existsSync(`${appDirectory}/${iconName}`); - }); - - test("should have .png or .svg as icon file", () => { - return iconName.endsWith(".svg") || iconName.endsWith(".png"); - }); - - test("should have an Icon with max width 275px and max height 275px when PNG", () => { - if (iconName.endsWith(".png")) { - const iconSize = getIconSizePNG(`${appDirectory}/${iconName}`); - - const isWidthTooBig = iconSize.width > ICON_WIDTH_MAX; - const isHeightTooBig = iconSize.height > ICON_HEIGHT_MAX; - if (isWidthTooBig || isHeightTooBig) { - console.log("Icon is too big:", iconSize); - } - - return !isWidthTooBig && !isHeightTooBig; - } - return true; - }); - - test("should have an Icon with min width 100px and min height 100px when PNG", () => { - if (iconName.endsWith(".png")) { - const iconSize = getIconSizePNG(`${appDirectory}/${iconName}`); - - const isWidthTooSmall = iconSize.width < ICON_WIDTH_MIN; - const isHeightTooSmall = iconSize.height < ICON_HEIGHT_MIN; - if (isWidthTooSmall || isHeightTooSmall) { - console.log("Icon is too small:", iconSize); - } - - return !isWidthTooSmall && !isHeightTooSmall; - } - return true; - }); - - // app.json tests - test("should have app.json file", () => { - return existsSync(`${appDirectory}/app.json`); - }); - - test("should have name defined in app.json", () => { - return typeof appJson.name === "string" && appJson !== ""; - }); - - test("should have name matching the app directory name normalized", () => { - return appJson.name.replaceAll(/[ -.:@]/g, "") === appDirectory; - }); - - // PHP file - test("should have a php file", () => { - return existsSync(`${appDirectory}/${appDirectory}.php`); - }); - - test("should have a Class with same name as directory", () => { - const phpFile = `${appDirectory}/${appDirectory}.php`; - if (!existsSync(phpFile)) { - return false; - } - - const phpFileContent = readFileSync( - `${appDirectory}/${appDirectory}.php` - ).toString(); - - return phpFileContent.indexOf(`class ${appDirectory}`) !== -1; - }); - - test("should have the namespace based on the class name", () => { - const phpFile = `${appDirectory}/${appDirectory}.php`; - if (!existsSync(phpFile)) { - return false; - } - - const phpFileContent = readFileSync( - `${appDirectory}/${appDirectory}.php` - ).toString(); - - return ( - phpFileContent.indexOf( - `namespace App\\SupportedApps\\${appDirectory}` - ) !== -1 - ); - }); + global.appUnderTest = `${appDirectory}`; + + const appJson = getAppJson(appDirectory); + const iconName = appJson.icon || ""; + + // Icon tests + test("should have an icon file", () => { + return existsSync(`${appDirectory}/${iconName}`); + }); + + test("should have .png or .svg as icon file", () => { + return iconName.endsWith(".svg") || iconName.endsWith(".png"); + }); + + test("should have an Icon with max width 275px and max height 275px when PNG", () => { + if (iconName.endsWith(".png")) { + const iconSize = getIconSizePNG(`${appDirectory}/${iconName}`); + + const isWidthTooBig = iconSize.width > ICON_WIDTH_MAX; + const isHeightTooBig = iconSize.height > ICON_HEIGHT_MAX; + if (isWidthTooBig || isHeightTooBig) { + console.log("Icon is too big:", iconSize); + } + + return !isWidthTooBig && !isHeightTooBig; + } + return true; + }); + + test("should have an Icon with min width 100px and min height 100px when PNG", () => { + if (iconName.endsWith(".png")) { + const iconSize = getIconSizePNG(`${appDirectory}/${iconName}`); + + const isWidthTooSmall = iconSize.width < ICON_WIDTH_MIN; + const isHeightTooSmall = iconSize.height < ICON_HEIGHT_MIN; + if (isWidthTooSmall || isHeightTooSmall) { + console.log("Icon is too small:", iconSize); + } + + return !isWidthTooSmall && !isHeightTooSmall; + } + return true; + }); + + // app.json tests + test("should have app.json file", () => { + return existsSync(`${appDirectory}/app.json`); + }); + + test("should have name defined in app.json", () => { + return typeof appJson.name === "string" && appJson !== ""; + }); + + test("should have name matching the app directory name normalized", () => { + return appJson.name.replaceAll(/[ -.:@]/g, "") === appDirectory; + }); + + // PHP file + test("should have a php file", () => { + return existsSync(`${appDirectory}/${appDirectory}.php`); + }); + + test("should have a Class with same name as directory", () => { + const phpFile = `${appDirectory}/${appDirectory}.php`; + if (!existsSync(phpFile)) { + return false; + } + + const phpFileContent = readFileSync( + `${appDirectory}/${appDirectory}.php` + ).toString(); + + return phpFileContent.indexOf(`class ${appDirectory}`) !== -1; + }); + + test("should have the namespace based on the class name", () => { + const phpFile = `${appDirectory}/${appDirectory}.php`; + if (!existsSync(phpFile)) { + return false; + } + + const phpFileContent = readFileSync( + `${appDirectory}/${appDirectory}.php` + ).toString(); + + return ( + phpFileContent.indexOf( + `namespace App\\SupportedApps\\${appDirectory}` + ) !== -1 + ); + }); }; module.exports = { - testApp, + testApp, }; diff --git a/authentik/authentik.php b/authentik/authentik.php index 6fbd527b2b..8a21c74ecf 100644 --- a/authentik/authentik.php +++ b/authentik/authentik.php @@ -1,5 +1,7 @@ - { - if (file !== parsed.icon) { - let filedata = fs.readFileSync(folder + "/" + file); - zip.file(folder + "/" + file, filedata); - } - }); - zip.generateNodeStream({ type: "nodebuffer", streamFiles: true }) - .pipe(fs.createWriteStream(dir + "/files/" + parsed.sha + ".zip")) - .on("finish", function () { - // JSZip generates a readable stream with a "end" event, - // but is piped here in a writable stream which emits a "finish" event. - console.log(parsed.sha + ".zip written."); - }); - } + var zip = new JSZip(); + fs.readdirSync(folder).forEach((file) => { + if (file !== parsed.icon) { + let filedata = fs.readFileSync(folder + "/" + file); + zip.file(folder + "/" + file, filedata); + } + }); + zip.generateNodeStream({ type: "nodebuffer", streamFiles: true }) + .pipe(fs.createWriteStream(dir + "/files/" + parsed.sha + ".zip")) + .on("finish", function () { + // JSZip generates a readable stream with a "end" event, + // but is piped here in a writable stream which emits a "finish" event. + console.log(parsed.sha + ".zip written."); + }); + } - let json = { - appcount: apptotal, - apps: apps, - }; + let json = { + appcount: apptotal, + apps: apps, + }; - let data = JSON.stringify(json); + let data = JSON.stringify(json); - fs.writeFileSync(dir + "/list.json", data); - fs.createReadStream("CNAME").pipe(fs.createWriteStream(dir + "/CNAME")); + fs.writeFileSync(dir + "/list.json", data); + fs.createReadStream("CNAME").pipe(fs.createWriteStream(dir + "/CNAME")); }); diff --git a/ioBroker/ioBroker.php b/ioBroker/ioBroker.php index 6178a698be..a6e5fb68bb 100644 --- a/ioBroker/ioBroker.php +++ b/ioBroker/ioBroker.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set - } + public function __construct() + { + //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } - public function test() - { - $test = parent::appTest($this->url("status")); - echo $test->status; - } + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } - public function livestats() - { - $status = "inactive"; - $res = parent::execute($this->url("status")); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $res = parent::execute($this->url("status")); + $details = json_decode($res->getBody()); - $data = []; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + $data = []; + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/openHAB/openHAB.php b/openHAB/openHAB.php index c031f3ef08..dcec4f4e6b 100644 --- a/openHAB/openHAB.php +++ b/openHAB/openHAB.php @@ -1,5 +1,7 @@ -cookie = new \GuzzleHttp\Cookie\CookieJar(); - } - - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . "rpc.php"; - return $api_url; - } - - private function request($service, $method, $params = []) - { - $attrs = [ - "json" => [ - "service" => $service, - "method" => $method, - "params" => $params, - ], - "cookies" => $this->cookie, - ]; - - // @see \App\SupportedApps\execute($url, $attrs = [], $overridevars=false, $overridemethod=false) - $result = parent::execute($this->url(false), $attrs, null, "POST"); - if (null === $result) { - throw new Exception("OMV error: Could not connect"); - } - - $response = json_decode($result->getBody()); - - if (is_null($response->response) && isset($response->error->message)) { - throw new Exception( - sprintf("OMV error: %s", $response->error->message) - ); - } elseif (is_null($response->response)) { - throw new Exception("OMV error: Empty response"); - } - return $response->response; - } - - private function auth() - { - $result = $this->request("session", "login", [ - "username" => $this->config->username, - "password" => $this->config->password, - ]); - return $result->authenticated; - } - - public function test() - { - try { - $token = $this->auth(); - echo "Successfully communicated with the API"; - } catch (Exception $err) { - echo $err->getMessage(); - } - } - - private function symbol($bool) - { - return true === $bool ? "✓" : "✗"; - } - - public function livestats() - { - $status = "inactive"; - $token = $this->auth(); - $data = ["visiblestats" => []]; - - $info = $this->request("system", "getInformation"); - $stats = $this->request("system", "getCpuStats"); - $data["CPU"] = sprintf("%.1f%%", $stats->utilization); - $data["RAM"] = sprintf( - "%.1f%%", - ($info->memUsed / $info->memTotal) * 100 - ); - $data["Pkgs"] = $this->symbol(!$info->availablePkgUpdates); - - $services = $this->request("services", "getStatus"); - foreach ($services->data as $service) { - $k = explode(" ", $service->title)[0]; - $data[$k] = sprintf( - "%s | %s", - $this->symbol($service->enabled), - $this->symbol($service->running) - ); - } - - foreach ($this->config->availablestats as $stat) { - $newstat = new \stdClass(); - $newstat->title = self::getAvailableStats()[$stat]; - $newstat->value = $data[$stat]; - $data["visiblestats"][] = $newstat; - } - $status = "active"; - return parent::getLiveStats($status, $data); - } - - public static function getAvailableStats() - { - return [ - "CPU" => "CPU", - "RAM" => "RAM", - "NFS" => "NFS", - "FTP" => "FTP", - "RSync" => "RSync", - "SMB/CIFS" => "SMB/CIFS", - "SSH" => "SSH", - "Pkgs" => "Pkgs", - ]; - } + public $config; + + private $cookie; + + public function __construct() + { + $this->cookie = new \GuzzleHttp\Cookie\CookieJar(); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . "rpc.php"; + return $api_url; + } + + private function request($service, $method, $params = []) + { + $attrs = [ + "json" => [ + "service" => $service, + "method" => $method, + "params" => $params, + ], + "cookies" => $this->cookie, + ]; + + // @see \App\SupportedApps\execute($url, $attrs = [], $overridevars=false, $overridemethod=false) + $result = parent::execute($this->url(false), $attrs, null, "POST"); + if (null === $result) { + throw new Exception("OMV error: Could not connect"); + } + + $response = json_decode($result->getBody()); + + if (is_null($response->response) && isset($response->error->message)) { + throw new Exception( + sprintf("OMV error: %s", $response->error->message) + ); + } elseif (is_null($response->response)) { + throw new Exception("OMV error: Empty response"); + } + return $response->response; + } + + private function auth() + { + $result = $this->request("session", "login", [ + "username" => $this->config->username, + "password" => $this->config->password, + ]); + return $result->authenticated; + } + + public function test() + { + try { + $token = $this->auth(); + echo "Successfully communicated with the API"; + } catch (Exception $err) { + echo $err->getMessage(); + } + } + + private function symbol($bool) + { + return true === $bool ? "✓" : "✗"; + } + + public function livestats() + { + $status = "inactive"; + $token = $this->auth(); + $data = ["visiblestats" => []]; + + $info = $this->request("system", "getInformation"); + $stats = $this->request("system", "getCpuStats"); + $data["CPU"] = sprintf("%.1f%%", $stats->utilization); + $data["RAM"] = sprintf( + "%.1f%%", + ($info->memUsed / $info->memTotal) * 100 + ); + $data["Pkgs"] = $this->symbol(!$info->availablePkgUpdates); + + $services = $this->request("services", "getStatus"); + foreach ($services->data as $service) { + $k = explode(" ", $service->title)[0]; + $data[$k] = sprintf( + "%s | %s", + $this->symbol($service->enabled), + $this->symbol($service->running) + ); + } + + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $newstat->title = self::getAvailableStats()[$stat]; + $newstat->value = $data[$stat]; + $data["visiblestats"][] = $newstat; + } + $status = "active"; + return parent::getLiveStats($status, $data); + } + + public static function getAvailableStats() + { + return [ + "CPU" => "CPU", + "RAM" => "RAM", + "NFS" => "NFS", + "FTP" => "FTP", + "RSync" => "RSync", + "SMB/CIFS" => "SMB/CIFS", + "SSH" => "SSH", + "Pkgs" => "Pkgs", + ]; + } } diff --git a/openvscodeserver/openvscodeserver.php b/openvscodeserver/openvscodeserver.php index 56f05f2145..b78b7fee89 100644 --- a/openvscodeserver/openvscodeserver.php +++ b/openvscodeserver/openvscodeserver.php @@ -1,5 +1,7 @@ -jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set - } + public function __construct() + { + $this->jar = new \GuzzleHttp\Cookie\CookieJar(); // Uncomment if cookies need to be set + } - public function test() - { - $test = $this->login(); - $attrs = [ + public function test() + { + $test = $this->login(); + $attrs = [ "cookies" => $this->jar, ]; - - #$test = parent::appTest($this->url('version/api')); - $test = parent::appTest($this->url("api/v2/app/version"), $attrs); - echo $test->status; - } - public function login() - { - $username = urlencode($this->config->username); - $password = urlencode($this->config->password); - $attrs = [ - "body" => "username=" . $username . "&password=" . $password, - "cookies" => $this->jar, - "headers" => [ - "content-type" => "application/x-www-form-urlencoded", - ], - ]; - #return parent::execute($this->url('login'), $attrs, false, 'POST'); - return parent::execute( - $this->url("api/v2/auth/login"), - $attrs, - null, - "POST" - ); - } + #$test = parent::appTest($this->url('version/api')); + $test = parent::appTest($this->url("api/v2/app/version"), $attrs); + echo $test->status; + } + + public function login() + { + $username = urlencode($this->config->username); + $password = urlencode($this->config->password); + $attrs = [ + "body" => "username=" . $username . "&password=" . $password, + "cookies" => $this->jar, + "headers" => [ + "content-type" => "application/x-www-form-urlencoded", + ], + ]; + #return parent::execute($this->url('login'), $attrs, false, 'POST'); + return parent::execute( + $this->url("api/v2/auth/login"), + $attrs, + null, + "POST" + ); + } - public function livestats() - { - $status = "inactive"; - $this->login(); - $attrs = [ - "cookies" => $this->jar, - ]; - #$res = parent::execute($this->url('query/torrents'), $attrs); - $res = parent::execute($this->url("api/v2/torrents/info"), $attrs); - $details = json_decode($res->getBody()); + public function livestats() + { + $status = "inactive"; + $this->login(); + $attrs = [ + "cookies" => $this->jar, + ]; + #$res = parent::execute($this->url('query/torrents'), $attrs); + $res = parent::execute($this->url("api/v2/torrents/info"), $attrs); + $details = json_decode($res->getBody()); - $data = []; + $data = []; - $torrents = $details; - $torrentCount = count($torrents); - $rateDownload = $rateUpload = $completedTorrents = 0; - foreach ($torrents as $thisTorrent) { - $rateDownload += $thisTorrent->dlspeed; - $rateUpload += $thisTorrent->upspeed; - if ($thisTorrent->progress == 1) { - $completedTorrents += 1; - } - } - $leech = $torrentCount - $completedTorrents; - if ($leech > 0) { - $status = "active"; - } + $torrents = $details; + $torrentCount = count($torrents); + $rateDownload = $rateUpload = $completedTorrents = 0; + foreach ($torrents as $thisTorrent) { + $rateDownload += $thisTorrent->dlspeed; + $rateUpload += $thisTorrent->upspeed; + if ($thisTorrent->progress == 1) { + $completedTorrents += 1; + } + } + $leech = $torrentCount - $completedTorrents; + if ($leech > 0) { + $status = "active"; + } - $data["download_rate"] = format_bytes( - $rateDownload, - false, - " ", - "/s" - ); - $data["upload_rate"] = format_bytes( - $rateUpload, - false, - " ", - "/s" - ); - $data["seed_count"] = $completedTorrents ?? 0; - $data["leech_count"] = $leech ?? 0; + $data["download_rate"] = format_bytes( + $rateDownload, + false, + " ", + "/s" + ); + $data["upload_rate"] = format_bytes( + $rateUpload, + false, + " ", + "/s" + ); + $data["seed_count"] = $completedTorrents ?? 0; + $data["leech_count"] = $leech ?? 0; - return parent::getLiveStats($status, $data); - } - public function url($endpoint) - { - $api_url = parent::normaliseurl($this->config->url) . $endpoint; - return $api_url; - } + return parent::getLiveStats($status, $data); + } + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } } diff --git a/ruTorrent/ruTorrent.php b/ruTorrent/ruTorrent.php index 2e7f8633e7..163af585da 100644 --- a/ruTorrent/ruTorrent.php +++ b/ruTorrent/ruTorrent.php @@ -1,110 +1,112 @@ -getXMLRPCData("throttle.global_down.rate"); - if ( - !isset($data) || - $data == "Err" || - $data == null || - !is_object($data) - ) { - echo 'There is an issue connecting to "' . - $this->url("RPC2") . - '". Please respect URL format "http(s)://IP:PORT". ' . - $data; - } else { - echo "Connection successful!"; - } - } - - public function livestats() - { - $status = "inactive"; - - $data = []; - $data["down_rate"] = $this->formatBytes( - (float) $this->getXMLRPCData("throttle.global_down.rate")->params - ->param->value->i8, - 1 - ); - - $data["up_rate"] = $this->formatBytes( - (float) $this->getXMLRPCData("throttle.global_up.rate")->params - ->param->value->i8, - 1 - ); - - return parent::getLiveStats($status, $data); - } - - public function url($endpoint) - { - return parent::normaliseurl($this->config->url) . $endpoint; - } - - public function getXMLRPCData($method) - { - $value = ""; - - $body = - "" . $method . ""; - - $this->vars = ["http_errors" => false, "timeout" => 5, "body" => $body]; - $this->attrs = []; - $this->attrs["headers"] = ["Content-Type" => "text/xml"]; - - if (isset($this->config->username) && isset($this->config->password)) { - $this->attrs["headers"]["Authorization"] = - "Basic " . - base64_encode( - $this->config->username . ":" . $this->config->password - ); - } - - try { - $res = parent::execute( - $this->url("RPC2"), - $this->attrs, - $this->vars - ); - } catch (\GuzzleHttp\Exception\RequestException $e) { - return ""; // Connection failed, display default response - } - - if (function_exists("simplexml_load_string")) { - try { - $value = simplexml_load_string($res->getBody()->getContents()); - } catch (\ErrorException $e) { - $value = "Unexpected response. Are credentials correct?"; - } - } else { - $value = 'simplexml_load_string doesn\'t exist.'; - } - - return $value; - } - - public function formatBytes($bytes, $precision = 2) - { - $units = ["B", "KB", "MB", "GB", "TB"]; - - $bytes = max($bytes, 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); - - $bytes /= pow(1024, $pow); - - return round($bytes, $precision) . " " . $units[$pow] . "/s"; - } + public $config; + + public function __construct() + { + } + + public function test() + { + $data = $this->getXMLRPCData("throttle.global_down.rate"); + if ( + !isset($data) || + $data == "Err" || + $data == null || + !is_object($data) + ) { + echo 'There is an issue connecting to "' . + $this->url("RPC2") . + '". Please respect URL format "http(s)://IP:PORT". ' . + $data; + } else { + echo "Connection successful!"; + } + } + + public function livestats() + { + $status = "inactive"; + + $data = []; + $data["down_rate"] = $this->formatBytes( + (float) $this->getXMLRPCData("throttle.global_down.rate")->params + ->param->value->i8, + 1 + ); + + $data["up_rate"] = $this->formatBytes( + (float) $this->getXMLRPCData("throttle.global_up.rate")->params + ->param->value->i8, + 1 + ); + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + return parent::normaliseurl($this->config->url) . $endpoint; + } + + public function getXMLRPCData($method) + { + $value = ""; + + $body = + "" . $method . ""; + + $this->vars = ["http_errors" => false, "timeout" => 5, "body" => $body]; + $this->attrs = []; + $this->attrs["headers"] = ["Content-Type" => "text/xml"]; + + if (isset($this->config->username) && isset($this->config->password)) { + $this->attrs["headers"]["Authorization"] = + "Basic " . + base64_encode( + $this->config->username . ":" . $this->config->password + ); + } + + try { + $res = parent::execute( + $this->url("RPC2"), + $this->attrs, + $this->vars + ); + } catch (\GuzzleHttp\Exception\RequestException $e) { + return ""; // Connection failed, display default response + } + + if (function_exists("simplexml_load_string")) { + try { + $value = simplexml_load_string($res->getBody()->getContents()); + } catch (\ErrorException $e) { + $value = "Unexpected response. Are credentials correct?"; + } + } else { + $value = 'simplexml_load_string doesn\'t exist.'; + } + + return $value; + } + + public function formatBytes($bytes, $precision = 2) + { + $units = ["B", "KB", "MB", "GB", "TB"]; + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . " " . $units[$pow] . "/s"; + } } diff --git a/sftpgo/sftpgo.php b/sftpgo/sftpgo.php index 30261d9064..ebd8ff022c 100644 --- a/sftpgo/sftpgo.php +++ b/sftpgo/sftpgo.php @@ -1,5 +1,7 @@ - { - try { - if (!callback()) { - console.log(`\nTesting ${global.appUnderTest}`); - console.log(`Failed: ${description}`); - global.passed = false; - } - } catch (e) { - console.log(`\nTesting ${global.appUnderTest}`); - console.log(`Failed: ${description}`); - global.passed = false; - } + try { + if (!callback()) { + console.log(`\nTesting ${global.appUnderTest}`); + console.log(`Failed: ${description}`); + global.passed = false; + } + } catch (e) { + console.log(`\nTesting ${global.appUnderTest}`); + console.log(`Failed: ${description}`); + global.passed = false; + } }; const getAppJson = (appDirectory) => { - const appJsonPath = `${appDirectory}/app.json`; - if (!existsSync(appJsonPath)) { - return {}; - } + const appJsonPath = `${appDirectory}/app.json`; + if (!existsSync(appJsonPath)) { + return {}; + } - return JSON.parse(readFileSync(appJsonPath).toString()); + return JSON.parse(readFileSync(appJsonPath).toString()); }; const getIconSizePNG = (fileName) => { - const HEADER_LENGTH = 24; - const OFFSET = 16; + const HEADER_LENGTH = 24; + const OFFSET = 16; - if (!existsSync(fileName)) { - return { width: 0, height: 0 }; - } + if (!existsSync(fileName)) { + return { width: 0, height: 0 }; + } - const fileDescriptor = openSync(fileName, "r"); - const myBuffer = Buffer.alloc(HEADER_LENGTH); + const fileDescriptor = openSync(fileName, "r"); + const myBuffer = Buffer.alloc(HEADER_LENGTH); - try { - readSync(fileDescriptor, myBuffer, 0, HEADER_LENGTH, 0); + try { + readSync(fileDescriptor, myBuffer, 0, HEADER_LENGTH, 0); - closeSync(fileDescriptor); - } catch (e) { - closeSync(fileDescriptor); - return { width: 0, height: 0 }; - } + closeSync(fileDescriptor); + } catch (e) { + closeSync(fileDescriptor); + return { width: 0, height: 0 }; + } - return { - width: myBuffer.readUInt32BE(OFFSET), - height: myBuffer.readUInt32BE(4 + OFFSET), - }; + return { + width: myBuffer.readUInt32BE(OFFSET), + height: myBuffer.readUInt32BE(4 + OFFSET), + }; }; module.exports = { - test, - getAppJson, - getIconSizePNG, + test, + getAppJson, + getIconSizePNG, }; diff --git a/testRunner.js b/testRunner.js index aada50ec8e..058e9e3a13 100644 --- a/testRunner.js +++ b/testRunner.js @@ -2,28 +2,28 @@ const { testApp } = require("./apps.tests"); const { readdirSync } = require("fs"); const getDirectories = (source) => - readdirSync(source, { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name) - .filter((dir) => !dir.startsWith(".")) - .filter((dir) => dir !== "node_modules"); + readdirSync(source, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map((dirent) => dirent.name) + .filter((dir) => !dir.startsWith(".")) + .filter((dir) => dir !== "node_modules"); // .slice(0, 10); global.passed = true; function main() { - const directories = getDirectories(process.cwd()); + const directories = getDirectories(process.cwd()); - console.log("Running Tests"); - directories.forEach(testApp); - console.log(""); + console.log("Running Tests"); + directories.forEach(testApp); + console.log(""); - if (!global.passed) { - console.error("Some Tests Failed!"); - process.exit(1); - } + if (!global.passed) { + console.error("Some Tests Failed!"); + process.exit(1); + } - console.log("All Tests Passed!"); + console.log("All Tests Passed!"); } main(); diff --git a/vmwarehorizon/vmwarehorizon.php b/vmwarehorizon/vmwarehorizon.php index 0378178d28..d12dcc706c 100644 --- a/vmwarehorizon/vmwarehorizon.php +++ b/vmwarehorizon/vmwarehorizon.php @@ -1,5 +1,7 @@ -