/
cigar
executable file
路98 lines (74 loc) 路 2.71 KB
/
cigar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env php
<?php
define('CIGAR_VERSION', '1.9.0');
$start = microtime(true);
foreach (['/../../..', '/../..', '/../vendor', '/vendor'] as $autoloadFileDirectory) {
if (file_exists(__DIR__ . $autoloadFileDirectory . '/autoload.php')) {
require __DIR__ . $autoloadFileDirectory . '/autoload.php';
break;
}
}
use Brunty\Cigar\AsyncChecker;
use Brunty\Cigar\Outputter;
use Brunty\Cigar\Parser;
use Brunty\Cigar\Result;
$options = getopt('c:ia:u:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:']);
if (isset($options['help'])) {
$content = <<<HELP
\033[33mUsage:\033[0m
cigar [options]
\033[33mOptions:\033[0m
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076"
\033[32m --quiet\033[0m Do not output any message
\033[32m --version\033[0m Print the version of Cigar
Created by Matt Brunt
E: matt@mfyu.co.uk
T: twitter.com/Brunty
G: github.com/brunty/cigar
HELP;
echo $content;
exit(0);
}
if (isset($options['version'])) {
$version = CIGAR_VERSION;
$content = <<<VERSION
____ ___ ____ _ ____
/ ___|_ _/ ___| / \ | _ \
| | | | | _ / _ \ | |_) |
| |___ | | |_| |/ ___ \| _ <
\____|___\____/_/ \_\_| \_\
\033[0;90;49mThe simple smoke testing tool.\033[0m
Version \033[36m{$version}\033[0m
For additional help use \033[36m--help\033[0m
VERSION;
echo $content;
exit(0);
}
$outputter = new Outputter(isset($options['quiet']));
$file = $options['c'] ?? ($options['config'] ?? '.cigar.json');
$baseUrl = $options['u'] ?? ($options['url'] ?? null);
if ( ! file_exists($file)) {
$outputter->writeErrorLine('Could not find configuration file: ' . $file);
exit(1);
}
try {
$domains = (new Parser($baseUrl))->parse($file);
} catch (\Throwable $e) {
$outputter->writeErrorLine('Unable to parse .cigar.json file');
exit(1);
}
$secure = ! (isset($options['i']) || isset($options['insecure']));
$authorization = $options['a'] ?? $options['auth'] ?? null;
$results = (new AsyncChecker($secure, $authorization))->check($domains);
$passedResults = array_filter($results, function (Result $result) {
return $result->hasPassed();
});
$outputter->outputResults($results);
$outputter->outputStats($passedResults, $results, $start);
if (count($passedResults) !== count($results)) {
exit(1);
}
exit(0);