2022-08-27 09:57:06 +00:00
|
|
|
|
use str
|
|
|
|
|
use framagit.org/benjamin.vaudour/elv-lib/mods/list
|
|
|
|
|
|
|
|
|
|
var vpnType = [
|
|
|
|
|
&wireguard=$nil
|
|
|
|
|
&vpn=$nil
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
var shortcut = [
|
|
|
|
|
&ca=ca.kaosx.cf
|
|
|
|
|
&fr=fr.kaosx.cf
|
|
|
|
|
&lu=luence-wg
|
|
|
|
|
&lu2=luence-ovpn
|
2022-09-02 13:53:03 +00:00
|
|
|
|
&cli=luence-client
|
2022-09-01 10:17:24 +00:00
|
|
|
|
&nl=proton_nl5
|
|
|
|
|
&jp=proton_jp2
|
|
|
|
|
&us=proton_us3
|
2022-08-27 09:57:06 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
var next = [
|
|
|
|
|
&ca.kaosx.cf=fr.kaosx.cf
|
|
|
|
|
&fr.kaosx.cf=luence-wg
|
|
|
|
|
&luence-wg=luence-client
|
|
|
|
|
&luence-ovpn=luence-client
|
2023-03-20 09:26:02 +00:00
|
|
|
|
# &luence-client=proton_nl5
|
|
|
|
|
# &proton_nl5=proton_us3
|
|
|
|
|
# &proton_us3=proton_jp2
|
2022-08-27 09:57:06 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
fn -list {|&active=$false|
|
|
|
|
|
var @argv = connection show
|
|
|
|
|
if $active {
|
|
|
|
|
set @argv = $@argv --active
|
|
|
|
|
}
|
|
|
|
|
nmcli $@argv | eawk {|_ @name uuid tpe dev|
|
|
|
|
|
if (has-key $vpnType $tpe) {
|
|
|
|
|
str:join ' ' $name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -up {|name|
|
|
|
|
|
nmcli connection up $name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -down {|name|
|
|
|
|
|
nmcli connection down $name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -active {||
|
|
|
|
|
-list &active=$true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -is-active {|name|
|
|
|
|
|
-active | list:contains $name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -next {||
|
|
|
|
|
var @n = (-active | list:first {|e| has-key $next $e })
|
|
|
|
|
if (== 1 (count $n)) {
|
|
|
|
|
put $next[$n[0]]
|
|
|
|
|
} else {
|
|
|
|
|
put ca.kaosx.cf
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -vpn-stop {||
|
|
|
|
|
var @a = (-active)
|
|
|
|
|
if (== (count $a) 0) {
|
|
|
|
|
echo 'Aucune connexion active'
|
|
|
|
|
} else {
|
|
|
|
|
-active | each $-down~
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -vpn-start {|name|
|
|
|
|
|
if (has-key $shortcut $name) {
|
|
|
|
|
set name = $shortcut[$name]
|
|
|
|
|
}
|
|
|
|
|
if (not (-list | list:contains $name)) {
|
|
|
|
|
printf "Le VPN “%s” n’èxiste pas\n" $name
|
|
|
|
|
} else {
|
|
|
|
|
-active | each $-down~
|
|
|
|
|
-up $name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -vpn-list {||
|
|
|
|
|
var @act = (-active)
|
|
|
|
|
-list | each {|n|
|
|
|
|
|
if (list:contains $n $act) {
|
|
|
|
|
echo (styled $n green)
|
|
|
|
|
} else {
|
|
|
|
|
echo $n
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -vpn-help {||
|
|
|
|
|
echo 'vpn: Active ou désactive les connections VPN'
|
|
|
|
|
echo 'Usage:'
|
|
|
|
|
echo ' help Affiche cette aide'
|
|
|
|
|
echo ' list Liste les VPN disponibles'
|
|
|
|
|
echo ' stop Arrête toutes les connexions VPN actives'
|
|
|
|
|
echo ' <vpn> Active la connexion VPN donnée et désactive les autres'
|
|
|
|
|
echo ' (sans argument) Active la prochaine connexion VPN et désactive les autres'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn -vpn {||
|
|
|
|
|
-vpn-start (-next)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edit:add-var vpn~ {|@argv|
|
|
|
|
|
var c = (count $argv)
|
|
|
|
|
if (== $c 0) {
|
|
|
|
|
-vpn
|
|
|
|
|
} elif (!= $c 1) {
|
|
|
|
|
-vpn-help
|
|
|
|
|
fail 'Arguments invalides'
|
|
|
|
|
} else {
|
|
|
|
|
var e = $argv[0]
|
|
|
|
|
if (eq $e help) {
|
|
|
|
|
-vpn-help
|
|
|
|
|
} elif (eq $e list) {
|
|
|
|
|
-vpn-list
|
|
|
|
|
} elif (eq $e stop) {
|
|
|
|
|
-vpn-stop
|
|
|
|
|
} else {
|
|
|
|
|
-vpn-start $e
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|