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.
#### **Building**
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:
```
user@pc:/tmp$ go get "github.com/spf13/viper"
......@@ -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**
You can see **lookis** in work here:
......
......@@ -10,9 +10,14 @@ address = "127.0.0.1"
port = "22"
user = "lookis"
password = ""
command_ping = "ping count 5"
command_traceroute = "traceroute as-number-lookup no-resolve"
command_showroute = "show route all"
command_01 = "ping count 5"
command_01_name = "ping"
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]
enabled = "yes"
......@@ -22,10 +27,13 @@ address = "127.0.0.2"
port = "22"
user = "lookis"
password = ""
command_ping = "/opt/vyatta/bin/ping"
command_ping_suffix = "count 5"
command_traceroute = "traceroute"
command_showroute = "/opt/vyatta/bin/vtyshow.pl show ip route"
command_01 = "/opt/vyatta/bin/ping"
command_01_name = "ping"
command_01_suffix = "count 5"
command_02 = "traceroute"
command_02_name = "traceroute"
command_03 = "/opt/vyatta/bin/vtyshow.pl show ip route"
command_03_name = "show route"
[router03]
enabled = "no"
......@@ -35,7 +43,10 @@ address = "127.0.0.3"
port = "22"
user = "lookis"
password = ""
command_ping = "ping count=5"
command_traceroute = "tool traceroute count=1"
command_showroute = "ip route print where"
command_showroute_suffix = "in dst-address and active"
command_01 = "ping count=5"
command_01_name = "ping"
command_02 = "tool traceroute count=1"
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 {
location / {
proxy_redirect off;
proxy_read_timeout 300s;
limit_req zone=lookis_lim burst=20 nodelay;
if (!-f $request_filename) {
......
......@@ -19,10 +19,15 @@ var AllConfigKeys []string
var datapath string
var RouterList []Router
// declare type for router commands
type RouterCommands struct {
CommandId, CommandName string
}
// declare type for routers list
type Router struct {
RouterId, RouterName string
RouterCommands []string
RouterCommands []RouterCommands
}
// declare variables for page template
......@@ -56,13 +61,13 @@ func ByteToString (byteinput []byte) string {
// check for correct action and return command for it
func GetCommand (router, command string) (string, bool) {
var AvalList []string
var AvalList []RouterCommands
var Command string
var CommandState bool
AvalList = GetRouterCommands(router)
for i := range AvalList {
if AvalList[i] == command {
if AvalList[i].CommandId == command {
Command = viper.GetString(router+".command_"+command)
CommandState = true
}
......@@ -128,18 +133,21 @@ func GetRouterName (RouterId string) string {
}
// get command list for router from config file
func GetRouterCommands (RouterId string) []string {
var CommandList []string
func GetRouterCommands (RouterId string) []RouterCommands {
var CommandList []RouterCommands
for i := range AllConfigKeys {
// find those, who match RouterId.command_XXX
matchstring := RouterId+`.command_\w*[^(suffix)]$`
matchstring := RouterId+`.command_[(\d)]*$`
matched, _ := regexp.MatchString(matchstring, AllConfigKeys[i])
if matched == true {
//get command name
var strip = regexp.MustCompile(RouterId+".command_")
command := strip.ReplaceAllString(AllConfigKeys[i], "")
CommandList = append(CommandList, command)
var ListEntry RouterCommands
id := strip.ReplaceAllString(AllConfigKeys[i], "")
name := viper.GetString(RouterId+".command_"+id+"_name")
ListEntry = RouterCommands{id, name}
CommandList = append(CommandList, ListEntry)
}
}
......
......@@ -76,11 +76,14 @@
FillInAction();
});
function addAction(OptionName, index, array) {
function addAction(OptionData, index, array) {
var option = document.createElement("option");
option.text = OptionName;
$.each(OptionData, function() {
option.value = OptionData.CommandId;
option.text = OptionData.CommandName;
action.add(option);
});
}
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