8. Command Line Interface
CLI – interfejs linii komend oferuje jednolity interfejs kontrolujący router i może być wykorzystany do pobrania/wysłania parametrów, wprowadzenia zmian, restartów serwisów albo do przeprowadzenia innych zadań systemowych. CLI powinno być uruchomione z komendy cli -i z shella systemowego albo kiedy zalogowany jest użytkownik root. Lista dostępnych komend może być wyświetlona przez wpisanie cli –l. Lista komend pokaże się automatycznie w trybie interaktywnym kiedy zaloguje się użytkownik admin.
~ $ cli
Name:
cli (Command Line Utility)
Usage:
[-ilh] <command>
|
~ $ cli -i MIDGE Command Line Interface (version 0.1) (C) Copyright RACOM s.r.o, Czech Republic Enter 'help' for a list of available commands or hit the TAB key for auto-completion. Ready to serve. > |
Listę komend CLI obsługuje dodatkowo klawisz TAB, jeśli wprowadzisz fragment słowa i nadusisz klawisz TAB system rozszerzy / wyświetli dodatkowe komendy powiązane z hasłem.
Każda sesja CLI automatycznie wyloguje się po pewnym czasie bezczynności, domyślnie 10 minut. Aby automatyczne wylogowanie wyłączyć wprowadź komendę no-autologout.
Z CLI wychodzimy komendą exit.
8.1 Użycie CLI
Podczas użycia CLI w trybie interaktywnym każda komend musi być potwierdzona klawiszem RETURN (enter). Możesz poruszać się klawiszem Left (lewo) i Right (prawo) aby przemieszczać się pomiędzy znakami, Up (góra) i Down (dół) aby przeglądać historię wybranych komend. Naduszenie CTRL-d dwa razy spowoduje zamknięcie CLI.
Oobsługiwane Klawisze
| Sekwencja | Działanie |
|---|---|
| CTRL-a | Przenosi się na początek bieżącej linii |
| CTRL-e | Przenosi się na koniec bieżącej linii |
| CTRL-f | Przenosi znak do przodu |
| CTRL-b | Przenosi znak do tył |
| ALT-f | Przenosi na koniec całe słowo |
| ALT-b | Przenosi na początek całe słowo |
| CTRL-l | Czyści ekran |
| CTRL-p | Przywołanie poprzedniej komendy z historii |
| CTRL-n | Przywołanie następnej komendy z historii |
| ALT-< | Przesunięcie się do pierwszej linii z historii |
| ALT-> | Przesunięcie się do ostatniej linii z historii |
| CTRL-r | Szukanie wstecz od bieżącej linii i przesuwanie przez historię |
| CTRL-s | Sesja zostanie zamrożona |
| CTRL-q | Reaktywacja zamrożonej sesji |
| CTRL-d | Usunięcie znaku przy kursorze albo wyjście z CLI na początku linii |
| CTRL-t | Przesuwanie znaku przez kursor równocześnie przesuwając kursor do przodu. Jeśli kursor jest na końcu linii, zostanie przeniesiony dwa znaki przed kursor |
| ALT-t | Przeniesie słowo przed kursor. Jeśli kursor jest na końcu linii przenosi dwa ostatnie znaki przed kursor |
| CTRL-k | Usuwa tekst od kursora do końca linii |
| CTRL-y | Przesuwa usunięty tekst do bufora |
8.2 Pomoc
Komenda help (pomoc) wyświetli listę dostępnych komend jeśli zostanie wywołana bez parametrów, z nazwą komendy wydrukuje opis komendy.
> help
Usage:
help [<command>]
Available commands:
get Get config parameters
set Set config parameters
status Get status information
send Send message or mail
update Update system facilities
restart Restart service
reset Reset system to factory defaults
reboot Reboot system
shell Run shell command
help Print help for command
no−autologout Turn off auto−logout
exit Exit
|
8.3 Pobieranie parametrów konfiguracji
Komenda Get (pobierz) jest używana do pobierania wartości konfiguracyjnych (nie wartości bieżących).
> get −h
Usage:
get [−hsvlc] <parameter> [<parameter>..]
Options:
−s generate sourceable output
−v validate config parameter
−l use legacy syntax with '&' separator
−c show configuration sections (can match a pattern)
|
Oto przykład pobrania wartości DIO
> get dio.out1 dio.out1=on > get dio.out2 dio.out2=on |
8.4 Ustawianie parametrów konfiguracyjnych
Komenda set (ustaw) jest używana do ustawienia wartości konfiguracyjnych.
> set −h
Usage:
set [−hvl] <parameter>=<value> [<parameter>=<value>..]
Options:
−v validate config parameter
−l use legacy syntax with '&' separator
|
Przykład użycia komendy
Obie wartości będą przestawione na „off” także będą przestawione/zapamiętane na „off” przy następnym uruchomieniu.
> set dio.out1=off > set dio.out2=off |
8.5 Pobieranie informacji statusowych
Komendą status pobieramy informacje o systemie
> status −h
Usage:
status [−hs] <section>
Options:
−s generate sourceable output
Available sections:
config Current configuration
summary Short status summary
system System information
license License information
wwan WWAN module status
wlan WLAN module status
gnss GNSS (GPS) module status
lan LAN interface status
wan WAN interface status
openvpn OpenVPN connection status
ipsec IPsec connection status
pptp PPTP connection status
dialin Dial−In connection status
dio Digital IO status
neigh Neighborhood status
location Current Location
|
W przykładzie odczytujemy wartości DIO. Pamiętaj że bieżący stan nie odpowiada konfiguracji wartości set z komendy „set Dio.out”
> status dio === DIGITAL IO INFORMATION === IN1: off IN2: on OUT1: on OUT2: off |
8.6 Wysyłanie email lub SMS
Komenda send (wyślij) jest używana do wysyłania e-mail/sms na wybrany adres lub telefon
> send −h
Name:
cli−send (Send message or mail)
Usage:
send [−h] <type> <dest> <msg>
Options:
<type> type of message to be sent (mail or sms)
<dest> destination of message (mail−address or phone−number)
<msg> message to be sent
|
Przykład użycia
Aby wysłać SMS z linii komend, np. przez telent lub SSH:
send sms +48123456789 'hello world'
8.7 Aktualizacja systemu
Polecenie update (aktualizuj) jest wykorzystywane do przeprowadzania różnych aktualizacji systemu.
> update −h
Usage:
update [−hr] <software|config|license|sshkeys> <URL>
Options:
−r reboot after update
Available actions:
software Perform software update
config Update configuration
license Update licenses
sshkeys Install SSH authorized keys
You may run 'update software latest' to install the latest version.
|
8.8 Restart usług
Komenda restart jest używana do restartu serwisów systemowych.
> restart −h
Usage:
restart [−h] <service>
Available services:
link−manager WAN links
wwan−manager WWAN manager
wlan WLAN interfaces
network Networking
dnsmasq DNS/DHCP server
configd Configuration daemon
firewall Firewall and NAPT
lighttpd HTTP server
openvpn OpenVPN connections
ipsec IPsec connections
pptp PPTP connections
snmpd SNMP daemon
syslog Syslog daemon
telnet Telnet server
dropbear SSH server
vrrpd VRRP daemon
usbipd USB/IP daemon
surveyor Supervision daemon
voiced Voice daemon
gpsd GPS daemon
smsd SMS daemon
|
8.9 Resetowanie systemu
Komenda reset jest używana do resetu routera do ustawień fabrycznych.
> reset −h
Usage:
reset [−h ]
|
8.10 Reboot systemu
Komenda reboot służy do ponownego uruchomienia routera.
> reboot −h
Usage:
reboot [−h]
|
8.11 Uruchomianie komend w shell
Komenda shell uruchamia shell systemowy w celu uruchomienia dowolnej aplikacji.
> shell −h
Usage:
shell [−h] [<cmd>]
|
8.12 CLI–PHP
CLI-PHP to interfejs http aplikacji CLI. Jest używany do konfiguracji i kontroli routera zdalnie. Jest uruchomiony w konfiguracji fabrycznej, może być używaniu do celów wdrożeniowych, ale jest wyłączany jak tylko konto admina zostanie stworzone. Serwis może być potem wyłączony/włączony przez ustawienie parametru cliphp.status:
> get cliphp.status cliphp.status=0 >set cli.php.status=1 > get cliphp.status cliphp.status=1 |
cliphp.status=0 Service is disabled
cliphp.status=1 Service is enabled
|
Ta sekcja opisuje interfejs CLI-PHP w wersji 2, przykłady użycia:
Usage:
http (s)://cli.php?<key1>=<value1>&<key2>=<value2>..<keyN>=<
valueN>
Available keys:
output Output format ( html, plain )
usr Username to be used for authentication
pwd Password to be used for authentication
commandV Command to be executed
arg0..arg31 Arguments passed to commands
Notes:
The commands correspond to CLI commands as seen by 'cli −l', the
arguments
(arg0..arg31) will be directly passed to the cli application
Thus, an URL containing the following sequence:
command=get&arg0=admin.password&arg1=admin.debug&arg2=admin.access
will lead to cli being called as:
$ cli get "admin.password" "admin.debug" "admin.access"
It supports whitespaces but please be aware that any special
characters in the URL
must be specified according to RFC1738 (which usually done by
common clients such
as wget, lynx, curl).
Response:
The returned response will always contain a status line in the
format:
<return>: <msg>
with return values of OK if succeeded and ERROR if failed. Any
output
from the commands will be appended
Examples:
OK: status command successful
ERROR: authentication failed
|
Status - wyświetlanie informacji statusowych
Key usage:
command=status[&arg0=<section>]
Notes:
Available sections can be retrieved by running command=
status&arg0=−h.
System status can be displayed without authentication.
Examples:
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=status&arg0=−h
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=status&arg0=summary
http://192.168.1.1/cli.php?version=2&output=html&command=status
|
Get – parametry konfiguracyjne funkcji Get (pobierz)
Key usage:
command=get&arg0=<config−key>[&arg1=<config−key>..]
Examples:
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=get&arg0=config.version
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=get&arg0=openvpn.status&arg1=snmp.status&arg2=ipsec.status
|
Set – parametry konfiguracyjne funkcji set (ustaw)
Key usage:
command=set&arg0=<config−key>&arg1=<config−value>[&arg2=<config
−key>&arg3=<config−value>..]
Notes :
In contrast to the other commands, this command requires a set
of tuples because of the reserved '=' char, i.e.
[arg0=key0, arg1=val0], [arg2=key1, arg3=val1], [arg4=key2, arg5=val2], etc
Examples:
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=set&arg0=snmp.status&arg1=1
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=set&arg0=snmp.status&arg1=0&arg2=openvpn.status&arg3=1
|
Restart – restart serwisów systemowych
Key usage:
command=restart&arg0=<service>
Notes:
Available services can be retrieved by running 'command=restart&arg0=−h'
Examples:
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=restart&arg0=−h
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=restart&arg0=link−manager
|
Reboot – wyzwalanie rebootu systemu
Key usage :
command=reboot
Examples :
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=reboot
|
Reset – uruchamia reset fabryczny
Key usage :
command=reset
Examples :
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=reset
|
Update – aktualizacja systemu
Key usage :
command=update&arg0=<facility>&arg1=<URL>
Notes :
Available facilities can be retrieved by running 'command=update
&arg0=−h'
Examples:
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=127
admin01&command=update&arg0=software&arg1=tftp://192.168.1.254/latest
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=update&arg0=config&arg1=tftp://192.168.1.254/user−
config.zip
http://192.168.1.1/cli.php?version=2&output=html&usr=admin&pwd=
admin01&command=update&arg0=license&arg1=http://192.168.1.254/xxx.lic
|
