diff --git a/LibreNMS/Util/GitHub.php b/LibreNMS/Util/GitHub.php index f15cadae37..eaf660c29e 100644 --- a/LibreNMS/Util/GitHub.php +++ b/LibreNMS/Util/GitHub.php @@ -27,8 +27,7 @@ namespace LibreNMS\Util; use Exception; -use Requests; -use Requests_Response; +use Illuminate\Support\Facades\Http; class GitHub { @@ -112,9 +111,9 @@ class GitHub */ public function getRelease($tag) { - $release = Requests::get($this->github . "/releases/tags/$tag", $this->getHeaders()); + $release = Http::withHeaders($this->getHeaders())->get($this->github . "/releases/tags/$tag"); - return json_decode($release->body, true); + return $release->json(); } /** @@ -122,8 +121,8 @@ class GitHub */ public function getPullRequest() { - $pull_request = Requests::get($this->github . "/pulls/{$this->pr}", $this->getHeaders()); - $this->pr = json_decode($pull_request->body, true); + $pull_request = Http::withHeaders($this->getHeaders())->get($this->github . "/pulls/{$this->pr}"); + $this->pr = $pull_request->json(); } /** @@ -180,9 +179,8 @@ class GitHub } GRAPHQL; - $data = json_encode(['query' => $query]); - $prs = Requests::post($this->graphql, $this->getHeaders(), $data); - $prs = json_decode($prs->body, true); + $prs = Http::withHeaders($this->getHeaders())->post($this->graphql, ['query' => $query]); + $prs = $prs->json(); if (! isset($prs['data'])) { var_dump($prs); } @@ -367,14 +365,14 @@ GRAPHQL; $this->createChangelog(false); } - $release = Requests::post($this->github . '/releases', $this->getHeaders(), json_encode([ + $release = Http::withHeaders($this->getHeaders())->post($this->github . '/releases', [ 'tag_name' => $this->tag, 'target_commitish' => $updated_sha, 'body' => $this->markdown, 'draft' => false, - ])); + ]); - return $release->status_code == 201; + return $release->status() == 201; } /** @@ -420,19 +418,18 @@ GRAPHQL; * @param string $file Path in git repo * @param string $contents new file contents * @param string $message The commit message - * @return Requests_Response */ - private function pushFileContents($file, $contents, $message) + private function pushFileContents($file, $contents, $message): string { - $existing = Requests::get($this->github . '/contents/' . $file, $this->getHeaders()); - $existing_sha = json_decode($existing->body)->sha; + $existing = Http::withHeaders($this->getHeaders())->get($this->github . '/contents/' . $file); + $existing_sha = $existing->json()['sha']; - $updated = Requests::put($this->github . '/contents/' . $file, $this->getHeaders(), json_encode([ + $updated = Http::withHeaders($this->getHeaders())->put($this->github . '/contents/' . $file, [ 'message' => $message, 'content' => base64_encode($contents), 'sha' => $existing_sha, - ])); + ]); - return json_decode($updated->body)->commit->sha; + return $updated->json()['commit']['sha']; } } diff --git a/composer.json b/composer.json index 2a0fae4f43..4de56f68aa 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,6 @@ "php-flasher/flasher-laravel": "^0.9", "phpmailer/phpmailer": "~6.0", "predis/predis": "^1.1", - "rmccue/requests": "^1.7", "symfony/yaml": "^4.0", "tecnickcom/tcpdf": "^6.4", "tightenco/ziggy": "^0.9" diff --git a/composer.lock b/composer.lock index bd0c05ba6e..758b98997a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cba65087f343b0ca7fa81ea5cb3dc1b5", + "content-hash": "17d76cfe55a8adb13cb6df7c52662b86", "packages": [ { "name": "amenadiel/jpgraph", @@ -4657,66 +4657,6 @@ ], "time": "2021-09-25T23:10:38+00:00" }, - { - "name": "rmccue/requests", - "version": "v1.8.1", - "source": { - "type": "git", - "url": "https://github.com/WordPress/Requests.git", - "reference": "82e6936366eac3af4d836c18b9d8c31028fe4cd5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/WordPress/Requests/zipball/82e6936366eac3af4d836c18b9d8c31028fe4cd5", - "reference": "82e6936366eac3af4d836c18b9d8c31028fe4cd5", - "shasum": "" - }, - "require": { - "php": ">=5.2" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7", - "php-parallel-lint/php-console-highlighter": "^0.5.0", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpcompatibility/php-compatibility": "^9.0", - "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5", - "requests/test-server": "dev-master", - "squizlabs/php_codesniffer": "^3.5", - "wp-coding-standards/wpcs": "^2.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "Requests": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "ISC" - ], - "authors": [ - { - "name": "Ryan McCue", - "homepage": "http://ryanmccue.info" - } - ], - "description": "A HTTP library written in PHP, for human beings.", - "homepage": "http://github.com/WordPress/Requests", - "keywords": [ - "curl", - "fsockopen", - "http", - "idna", - "ipv6", - "iri", - "sockets" - ], - "support": { - "issues": "https://github.com/WordPress/Requests/issues", - "source": "https://github.com/WordPress/Requests/tree/v1.8.1" - }, - "time": "2021-06-04T09:56:25+00:00" - }, { "name": "spomky-labs/base64url", "version": "v2.0.4", diff --git a/includes/functions.php b/includes/functions.php index 3a826b1992..3235276104 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -9,6 +9,7 @@ */ use App\Models\Device; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; use LibreNMS\Config; use LibreNMS\Exceptions\HostExistsException; @@ -942,26 +943,6 @@ function set_curl_proxy($curl) \LibreNMS\Util\Proxy::applyToCurl($curl); } -/** - * Return the proxy url in guzzle format - * - * @return 'tcp://' + $proxy - */ -function get_guzzle_proxy() -{ - return \LibreNMS\Util\Proxy::forGuzzle(); -} - -/** - * Return the proxy url - * - * @return array|bool|false|string - */ -function get_proxy() -{ - return \LibreNMS\Util\Proxy::get(); -} - function target_to_id($target) { if ($target[0] . $target[1] == 'g:') { @@ -1436,9 +1417,9 @@ function cache_mac_oui() //$mac_oui_url_mirror = 'https://raw.githubusercontent.com/wireshark/wireshark/master/manuf'; echo ' -> Downloading ...' . PHP_EOL; - $get = Requests::get($mac_oui_url, [], ['proxy' => get_proxy()]); + $get = Http::withOptions(['proxy' => Proxy::forGuzzle()])->get($mac_oui_url); echo ' -> Processing CSV ...' . PHP_EOL; - $csv_data = $get->body; + $csv_data = $get->body(); foreach (explode("\n", $csv_data) as $csv_line) { unset($oui); $entry = str_getcsv($csv_line, "\t"); @@ -1494,8 +1475,8 @@ function cache_peeringdb() $ix_keep = []; foreach (dbFetchRows('SELECT `bgpLocalAs` FROM `devices` WHERE `disabled` = 0 AND `ignore` = 0 AND `bgpLocalAs` > 0 AND (`bgpLocalAs` < 64512 OR `bgpLocalAs` > 65535) AND `bgpLocalAs` < 4200000000 GROUP BY `bgpLocalAs`') as $as) { $asn = $as['bgpLocalAs']; - $get = Requests::get($peeringdb_url . '/net?depth=2&asn=' . $asn, [], ['proxy' => get_proxy()]); - $json_data = $get->body; + $get = Http::withOptions(['proxy' => Proxy::forGuzzle()])->get($peeringdb_url . '/net?depth=2&asn=' . $asn); + $json_data = $get->body(); $data = json_decode($json_data); $ixs = $data->{'data'}[0]->{'netixlan_set'}; foreach ($ixs as $ix) { @@ -1515,8 +1496,8 @@ function cache_peeringdb() $pdb_ix_id = dbInsert($insert, 'pdb_ix'); } $ix_keep[] = $pdb_ix_id; - $get_ix = Requests::get("$peeringdb_url/netixlan?ix_id=$ixid", [], ['proxy' => get_proxy()]); - $ix_json = $get_ix->body; + $get_ix = Http::withOptions(['proxy' => Proxy::forGuzzle()])->get("$peeringdb_url/netixlan?ix_id=$ixid"); + $ix_json = $get_ix->body(); $ix_data = json_decode($ix_json); $peers = $ix_data->{'data'}; foreach ($peers as $index => $peer) { @@ -1706,20 +1687,23 @@ function oxidized_node_update($hostname, $msg, $username = 'not_provided') $postdata = ['user' => $username, 'msg' => $msg]; $oxidized_url = Config::get('oxidized.url'); if (! empty($oxidized_url)) { - Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => Proxy::get($oxidized_url)]); + $response = Http::withOptions(['proxy' => Proxy::forGuzzle($oxidized_url)])->put("$oxidized_url/node/next/$hostname", $postdata); - return true; + if ($response->successful()) { + return true; + } } return false; }//end oxidized_node_update() /** + * Take a BGP error code and subcode to return a string representation of it + * * @params int code * @params int subcode * * @return string - * Take a BGP error code and subcode to return a string representation of it */ function describe_bgp_error_code($code, $subcode) {