elvish_config/aliases/digall.elv

106 lines
2.0 KiB
Plaintext
Raw Normal View History

2021-12-11 21:09:02 +00:00
edit:add-var digall~ {|@argv|
2020-07-22 09:24:43 +00:00
use moi/util/list
use moi/util/strutil
2020-07-22 09:24:43 +00:00
use str
var default_records = [
2020-07-22 09:24:43 +00:00
A
AAAA
CNAME
PTR
TXT
MX
SRV
NAPTR
NS
SOA
]
var cols = [
[&min=24]
[&min=8]
[&min=10]
]
var records servers = [] []
2021-10-13 18:43:40 +00:00
var flags = [
2020-07-22 09:24:43 +00:00
+noall
+answer
]
var domains use_dig = [] $true
2020-07-22 09:24:43 +00:00
2021-12-11 21:09:02 +00:00
fn init {||
if (and (> (count $argv) 0) (is $argv[0] -d)) {
2021-10-13 18:43:40 +00:00
set use_dig = $false
set argv = $argv[1:]
}
2021-12-11 21:09:02 +00:00
each {|e|
2020-07-22 09:24:43 +00:00
if (is $e[0] '+') {
2021-10-13 18:43:40 +00:00
set flags = [ (all $flags) $e ]
2020-07-22 09:24:43 +00:00
} elif (is $e[0] @) {
2021-10-13 18:43:40 +00:00
set servers = [ (all $servers) $e ]
2020-07-22 09:24:43 +00:00
} elif (list:includes $e $default_records) {
2021-10-13 18:43:40 +00:00
set records = [ (all $records) $e ]
2020-07-22 09:24:43 +00:00
} else {
2021-10-13 18:43:40 +00:00
set domains = [ (all $domains) $e ]
2020-07-22 09:24:43 +00:00
}
} $argv
2020-07-22 09:24:43 +00:00
if (== (count $records) 0) {
2021-10-13 18:43:40 +00:00
set records = $default_records
2020-07-22 09:24:43 +00:00
}
}
2021-12-11 21:09:02 +00:00
fn format {|results|
eawk {|_ @args|
put [ $args[0] (all $args[2..]) ]
2021-12-11 21:09:02 +00:00
} $results | list:remove-duplicate | list:sort {|l1 l2|
var c = (str:compare $l1[0] $l2[0])
if (== $c 0) {
2021-10-13 18:43:40 +00:00
set c = (str:compare $l1[2] $l2[2])
}
} | strutil:format &col=$cols | str:join "\n"
}
2021-12-11 21:09:02 +00:00
fn drillr {|d @args|
var results = [ (peach {|r|
e:drill $@args $r $d | list:filter {|e|
and (> (count $e) 2) (not (is $e[:2] ';;'))
}
} $records) ]
format $results
}
2020-07-22 09:24:43 +00:00
2021-12-11 21:09:02 +00:00
fn digr {|d @args|
var results = [ (peach {|r|
2020-07-22 09:24:43 +00:00
e:dig $@args $r $d $@flags
} $records) ]
format $results
2020-07-22 09:24:43 +00:00
}
2021-12-11 21:09:02 +00:00
fn req {|d @args|
if $use_dig {
digr $d $@args
} else {
drillr $d $@args
}
}
2020-07-22 09:24:43 +00:00
2021-12-11 21:09:02 +00:00
fn digs {|s d|
put (echo (styled $s bright-yellow))
req $d $s
2020-07-22 09:24:43 +00:00
}
2021-12-11 21:09:02 +00:00
fn digd {|d|
var results = [ (echo (styled 'Domaine: '$d bright-green)) ]
2020-07-22 09:24:43 +00:00
if (> (count $servers) 0) {
2021-12-11 21:09:02 +00:00
each {|s|
2021-10-13 18:43:40 +00:00
set @results = $@results (digs $s $d)
2020-07-22 09:24:43 +00:00
} $servers
} else {
2021-10-13 18:43:40 +00:00
set @results = $@results (req $d)
2020-07-22 09:24:43 +00:00
}
echo (str:join "\n" $results)
2020-07-22 09:24:43 +00:00
}
init
peach $digd~ $domains
2020-07-22 09:24:43 +00:00
}