Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ repos:
name: PHP Lint Checking
entry: composer run-script lint
language: system
files: ^app/
always_run: true

- id: phpcsfixer
name: PHP CS Fixer Validation
entry: composer run-script phpcsfixer
language: system
files: ^app/
always_run: true

- id: phpstan
name: PHPStan Validation
entry: composer run-script phpstan
language: system
files: ^app/
always_run: true
40 changes: 23 additions & 17 deletions cli/add_site.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@
case '--version':
case '-V':
case '-v':
displayVersion();
display_version();

exit;
case '--help':
case '-H':
case '-h':
displayHelp();
display_help();

exit;

default:
echoQuiet("ERROR: Invalid Argument: ($arg)\n\n" . PHP_EOL . PHP_EOL);
displayHelp();
display_help();

exit(1);
}
Expand All @@ -215,7 +215,7 @@
}
}
} else {
displayHelp();
display_help();

exit(0);
}
Expand Down Expand Up @@ -437,7 +437,11 @@ function geocodeAddress(string $siteAddr1, string $siteAddr2, string $siteCity,

if (!$geocodeApiKey) {
// Dont even try without the key
displayHelp('Error: --geocode-api-key must be given with --geocode-address');
print 'Error: --geocode-api-key must be given with --geocode-address' . PHP_EOL;

display_help();

exit(1);
}

$requestUrl = sprintf('%s?address=%s,%s,%s,%s&key=%s', $googleApiUrl, urlencode($siteAddr1), urlencode($siteAddr2), urlencode($siteCity), urlencode($siteCountry), $geocodeApiKey);
Expand Down Expand Up @@ -511,12 +515,16 @@ function fetchCurl(string $url) : string|false {
global $verbose, $debug, $httpsProxy;

if (!function_exists('curl_init')) {
displayHelp('Error: cURL must be enabled in PHP if --geocode is specified.' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help.' . PHP_EOL);
print 'Error: cURL must be enabled in PHP if --geocode is specified.' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help.' . PHP_EOL;

display_help();

exit(1);
}

$curl = curl_init();
$header[0] = 'Accept: text/xml,application/xml,application/json,application/xhtml+xml,';
$header[0] .= 'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$curl = curl_init();

$header[] = 'Accept: text/xml,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[] = 'Cache-Control: max-age=0';
$header[] = 'Connection: keep-alive';
$header[] = 'Keep-Alive: 300';
Expand All @@ -535,13 +543,15 @@ function fetchCurl(string $url) : string|false {
if ($verbose || $debug) {
echoQuiet("Using HTTPS proxy: $httpsProxy" . PHP_EOL);
}

curl_setopt($curl, CURLOPT_PROXY, $httpsProxy);
}

$buffer = curl_exec($curl);

if ($buffer === false) {
$error = curl_error($curl);

echoQuiet('Error: cURL request failed: ' . $error . PHP_EOL);

return false;
Expand All @@ -551,11 +561,11 @@ function fetchCurl(string $url) : string|false {
}

/**
* displayVersion - displays version information
* display_version - displays version information
*
* @return void
*/
function displayVersion() : void {
function display_version() : void {
$version = get_cacti_cli_version();
echoQuiet("Cacti Add Site Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL);
}
Expand All @@ -565,14 +575,10 @@ function displayVersion() : void {
*
* @return void
*/
function displayHelp(mixed $errorMessage = null) : void {
function display_help() : void {
global $log;
$log = false;
displayVersion();

if ($errorMessage) {
echoQuiet("$errorMessage" . PHP_EOL . PHP_EOL);
}
display_version();

echoQuiet(PHP_EOL);
echoQuiet('Usage: add_site.php [site-options] [--quiet]' . PHP_EOL . PHP_EOL);
Expand Down
4 changes: 2 additions & 2 deletions lib/html_utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,9 @@ function get_order_string_page() : string {
*
* @param string $regex The regular expression to validate.
*
* @return true|string Returns true if the regular expression is valid, otherwise returns an error message string.
* @return bool|string Returns true if the regular expression is valid, otherwise returns an error message string.
*/
function validate_is_regex(string $regex) : true|string {
function validate_is_regex(string $regex) : bool|string {
if ($regex == '') {
return true;
}
Expand Down
Loading