Commit 6b87ce1d authored by zdc's avatar zdc

fixed bug, extended config processing

* fixed typo in regex (func GetRouterCommands)
* added ability to change order for actions in list
* added ability to set names for command
* changed timeout in nginx template (support for long-time operations)
* changed README
parent 9a7b9b82
...@@ -9,7 +9,7 @@ It can run configured command through SSH and show results in web browser. ...@@ -9,7 +9,7 @@ It can run configured command through SSH and show results in web browser.
#### **Building** #### **Building**
To build **lookis** you need: To build **lookis** you need:
* [**install Go language**](https://golang.org/doc/install) on your computer; * [**install Go language**](https://golang.org/doc/install) on your computer.
* install dependencies: * install dependencies:
``` ```
user@pc:/tmp$ go get "github.com/spf13/viper" user@pc:/tmp$ go get "github.com/spf13/viper"
...@@ -54,6 +54,19 @@ Now all work was done. You can test your installation. ...@@ -54,6 +54,19 @@ Now all work was done. You can test your installation.
--- ---
#### **Custom commands**
You can add custom commands for any router:
* open **`config.toml`** for edit.
* add next lines for needed section:
```
command_XX = "command to be executed"
command_XX_name = "command name to show in list"
command_XX_suffix = "suffix to command" (if needed)
```
where "XX" is number for this command in dropdown list.
---
#### **Сertain users / demo** #### **Сertain users / demo**
You can see **lookis** in work here: You can see **lookis** in work here:
......
...@@ -10,9 +10,14 @@ address = "127.0.0.1" ...@@ -10,9 +10,14 @@ address = "127.0.0.1"
port = "22" port = "22"
user = "lookis" user = "lookis"
password = "" password = ""
command_ping = "ping count 5" command_01 = "ping count 5"
command_traceroute = "traceroute as-number-lookup no-resolve" command_01_name = "ping"
command_showroute = "show route all" command_02 = "traceroute as-number-lookup no-resolve"
command_02_name = "traceroute"
command_03 = "show route all"
command_03_name = "show route"
command_04 = "new command"
command_04_name = "new command 01"
[router02] [router02]
enabled = "yes" enabled = "yes"
...@@ -22,10 +27,13 @@ address = "127.0.0.2" ...@@ -22,10 +27,13 @@ address = "127.0.0.2"
port = "22" port = "22"
user = "lookis" user = "lookis"
password = "" password = ""
command_ping = "/opt/vyatta/bin/ping" command_01 = "/opt/vyatta/bin/ping"
command_ping_suffix = "count 5" command_01_name = "ping"
command_traceroute = "traceroute" command_01_suffix = "count 5"
command_showroute = "/opt/vyatta/bin/vtyshow.pl show ip route" command_02 = "traceroute"
command_02_name = "traceroute"
command_03 = "/opt/vyatta/bin/vtyshow.pl show ip route"
command_03_name = "show route"
[router03] [router03]
enabled = "no" enabled = "no"
...@@ -35,7 +43,10 @@ address = "127.0.0.3" ...@@ -35,7 +43,10 @@ address = "127.0.0.3"
port = "22" port = "22"
user = "lookis" user = "lookis"
password = "" password = ""
command_ping = "ping count=5" command_01 = "ping count=5"
command_traceroute = "tool traceroute count=1" command_01_name = "ping"
command_showroute = "ip route print where" command_02 = "tool traceroute count=1"
command_showroute_suffix = "in dst-address and active" command_02_name = "traceroute"
command_03 = "ip route print where"
command_03_name = "show route"
command_03_suffix = "in dst-address and active"
...@@ -10,6 +10,7 @@ server { ...@@ -10,6 +10,7 @@ server {
location / { location / {
proxy_redirect off; proxy_redirect off;
proxy_read_timeout 300s;
limit_req zone=lookis_lim burst=20 nodelay; limit_req zone=lookis_lim burst=20 nodelay;
if (!-f $request_filename) { if (!-f $request_filename) {
......
...@@ -19,10 +19,15 @@ var AllConfigKeys []string ...@@ -19,10 +19,15 @@ var AllConfigKeys []string
var datapath string var datapath string
var RouterList []Router var RouterList []Router
// declare type for router commands
type RouterCommands struct {
CommandId, CommandName string
}
// declare type for routers list // declare type for routers list
type Router struct { type Router struct {
RouterId, RouterName string RouterId, RouterName string
RouterCommands []string RouterCommands []RouterCommands
} }
// declare variables for page template // declare variables for page template
...@@ -56,13 +61,13 @@ func ByteToString (byteinput []byte) string { ...@@ -56,13 +61,13 @@ func ByteToString (byteinput []byte) string {
// check for correct action and return command for it // check for correct action and return command for it
func GetCommand (router, command string) (string, bool) { func GetCommand (router, command string) (string, bool) {
var AvalList []string var AvalList []RouterCommands
var Command string var Command string
var CommandState bool var CommandState bool
AvalList = GetRouterCommands(router) AvalList = GetRouterCommands(router)
for i := range AvalList { for i := range AvalList {
if AvalList[i] == command { if AvalList[i].CommandId == command {
Command = viper.GetString(router+".command_"+command) Command = viper.GetString(router+".command_"+command)
CommandState = true CommandState = true
} }
...@@ -128,18 +133,21 @@ func GetRouterName (RouterId string) string { ...@@ -128,18 +133,21 @@ func GetRouterName (RouterId string) string {
} }
// get command list for router from config file // get command list for router from config file
func GetRouterCommands (RouterId string) []string { func GetRouterCommands (RouterId string) []RouterCommands {
var CommandList []string var CommandList []RouterCommands
for i := range AllConfigKeys { for i := range AllConfigKeys {
// find those, who match RouterId.command_XXX // find those, who match RouterId.command_XXX
matchstring := RouterId+`.command_\w*[^(suffix)]$` matchstring := RouterId+`.command_[(\d)]*$`
matched, _ := regexp.MatchString(matchstring, AllConfigKeys[i]) matched, _ := regexp.MatchString(matchstring, AllConfigKeys[i])
if matched == true { if matched == true {
//get command name //get command name
var strip = regexp.MustCompile(RouterId+".command_") var strip = regexp.MustCompile(RouterId+".command_")
command := strip.ReplaceAllString(AllConfigKeys[i], "") var ListEntry RouterCommands
CommandList = append(CommandList, command) id := strip.ReplaceAllString(AllConfigKeys[i], "")
name := viper.GetString(RouterId+".command_"+id+"_name")
ListEntry = RouterCommands{id, name}
CommandList = append(CommandList, ListEntry)
} }
} }
......
...@@ -76,11 +76,14 @@ ...@@ -76,11 +76,14 @@
FillInAction(); FillInAction();
}); });
function addAction(OptionName, index, array) { function addAction(OptionData, index, array) {
var option = document.createElement("option"); var option = document.createElement("option");
option.text = OptionName; $.each(OptionData, function() {
action.add(option); option.value = OptionData.CommandId;
option.text = OptionData.CommandName;
action.add(option);
});
} }
function FillInAction() { function FillInAction() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment