mml
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -23,7 +23,11 @@ restagent/upload/
|
|||||||
restagent/software/
|
restagent/software/
|
||||||
restagent/database/
|
restagent/database/
|
||||||
restagent/restagent
|
restagent/restagent
|
||||||
|
|
||||||
sshsvc/sshsvc
|
sshsvc/sshsvc
|
||||||
|
sshsvc/mmllog/
|
||||||
|
sshsvc/mmlhome/
|
||||||
|
sshsvc/log/
|
||||||
|
|
||||||
tools/loadmconf/loadmconf
|
tools/loadmconf/loadmconf
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ mml:
|
|||||||
sleep: 200
|
sleep: 200
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
|
mmlHome: ./mmlhome
|
||||||
|
|
||||||
ne:
|
ne:
|
||||||
user: root
|
user: root
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ func PostMMLToOMC(w http.ResponseWriter, r *http.Request) {
|
|||||||
omcMmlVar := &mmlp.MmlVar{
|
omcMmlVar := &mmlp.MmlVar{
|
||||||
Version: "16.1.1",
|
Version: "16.1.1",
|
||||||
Output: mmlp.DefaultFormatType,
|
Output: mmlp.DefaultFormatType,
|
||||||
|
MmlHome: config.GetYamlConfig().MML.MmlHome,
|
||||||
Limit: 50,
|
Limit: 50,
|
||||||
User: "",
|
User: "",
|
||||||
SessionToken: token,
|
SessionToken: token,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
"ems.agt/lib/dborm"
|
"ems.agt/lib/dborm"
|
||||||
"ems.agt/lib/global"
|
"ems.agt/lib/global"
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
|
"ems.agt/lib/run"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ type MmlCommand struct {
|
|||||||
type MmlVar struct {
|
type MmlVar struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Output string `json:"output"`
|
Output string `json:"output"`
|
||||||
|
MmlHome string `json:"mmlHome"`
|
||||||
Limit int `json:"limit"`
|
Limit int `json:"limit"`
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
SessionToken string `josn:"sessionToken"`
|
SessionToken string `josn:"sessionToken"`
|
||||||
@@ -437,8 +438,10 @@ func RunShellCommand(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOu
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd := exec.Command("/bin/bash", "-c", command)
|
out, err := run.ExecCmd(command, omcMmlVar.MmlHome)
|
||||||
out, err := cmd.CombinedOutput()
|
//cmd := exec.Command("/bin/bash", "-c", command)
|
||||||
|
|
||||||
|
//out, err := cmd.CombinedOutput()
|
||||||
log.Tracef("Exec output: %v", string(out))
|
log.Tracef("Exec output: %v", string(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("exe cmd error: ", err)
|
log.Error("exe cmd error: ", err)
|
||||||
|
|||||||
56
lib/run/exec_linux.go
Normal file
56
lib/run/exec_linux.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
//go:build linux
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package run
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"ems.agt/lib/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExecCmd(command, path string) ([]byte, error) {
|
||||||
|
log.Debug("Exec command:", command)
|
||||||
|
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", command)
|
||||||
|
cmd.Dir = path
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecShell(command string) error {
|
||||||
|
in := bytes.NewBuffer(nil)
|
||||||
|
cmd := exec.Command("sh")
|
||||||
|
cmd.Stdin = in
|
||||||
|
in.WriteString(command)
|
||||||
|
in.WriteString("exit\n")
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecOsCmd(command, os string) error {
|
||||||
|
log.Debugf("Exec %s command:%s", os, command)
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch os {
|
||||||
|
case "Linux":
|
||||||
|
cmd = exec.Command(command)
|
||||||
|
case "Windows":
|
||||||
|
cmd = exec.Command("cmd", "/C", command)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
log.Tracef("Exec output: %v", string(out))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("exe cmd error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
45
lib/run/exec_windows.go
Normal file
45
lib/run/exec_windows.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package run
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"ems.agt/lib/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExecCmd(command, path string) ([]byte, error) {
|
||||||
|
log.Debug("Exec command:", command)
|
||||||
|
|
||||||
|
cmd := exec.Command("cmd", "/C", command)
|
||||||
|
cmd.Dir = path
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
log.Tracef("Exec output: %v", string(out))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("exe cmd error: ", err)
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecOsCmd(command, os string) error {
|
||||||
|
log.Debugf("Exec %s command:%s", os, command)
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch os {
|
||||||
|
case "Linux":
|
||||||
|
cmd = exec.Command(command)
|
||||||
|
case "Windows":
|
||||||
|
cmd = exec.Command("cmd", "/C", command)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
log.Tracef("Exec output: %v", string(out))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("exe cmd error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -84,6 +84,7 @@ type YamlConfig struct {
|
|||||||
Sleep int64 `yaml:"sleep"`
|
Sleep int64 `yaml:"sleep"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Password string `ymal:"password"`
|
Password string `ymal:"password"`
|
||||||
|
MmlHome string `yaml:"mmlHome"`
|
||||||
} `yaml:"mml"`
|
} `yaml:"mml"`
|
||||||
|
|
||||||
NE struct {
|
NE struct {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ mml:
|
|||||||
sleep: 200
|
sleep: 200
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
|
mmlHome: ./mmlhome
|
||||||
|
|
||||||
ne:
|
ne:
|
||||||
user: root
|
user: root
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ mml:
|
|||||||
sleep: 200
|
sleep: 200
|
||||||
user: admin
|
user: admin
|
||||||
password: admin
|
password: admin
|
||||||
|
mmlHome: ./mmlhome
|
||||||
|
|
||||||
ne:
|
ne:
|
||||||
user: root
|
user: root
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type YamlConfig struct {
|
|||||||
MaxConnNum uint8 `yaml:"maxConnNum"`
|
MaxConnNum uint8 `yaml:"maxConnNum"`
|
||||||
Timeout uint16 `yaml:"timeout"`
|
Timeout uint16 `yaml:"timeout"`
|
||||||
Session string `yaml:"session"`
|
Session string `yaml:"session"`
|
||||||
|
MmlHome string `yaml:"mmlHome"`
|
||||||
} `yaml:"sshd"`
|
} `yaml:"sshd"`
|
||||||
|
|
||||||
Database struct {
|
Database struct {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ sshd:
|
|||||||
maxConnNum: 20
|
maxConnNum: 20
|
||||||
timeout: 1800
|
timeout: 1800
|
||||||
session: multiple
|
session: multiple
|
||||||
|
mmlHome: ./mmlhome
|
||||||
|
|
||||||
database:
|
database:
|
||||||
type: mysql
|
type: mysql
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ func handleSSHShell(sshConn *ssh.ServerConn, channel ssh.Channel) {
|
|||||||
omcMmlVar := &mmlp.MmlVar{
|
omcMmlVar := &mmlp.MmlVar{
|
||||||
Version: "16.1.1",
|
Version: "16.1.1",
|
||||||
Output: mmlp.DefaultFormatType,
|
Output: mmlp.DefaultFormatType,
|
||||||
|
MmlHome: conf.Sshd.MmlHome,
|
||||||
Limit: 50,
|
Limit: 50,
|
||||||
User: sshConn.User(),
|
User: sshConn.User(),
|
||||||
SessionToken: fmt.Sprintf("%x", sshConn.SessionID()),
|
SessionToken: fmt.Sprintf("%x", sshConn.SessionID()),
|
||||||
|
|||||||
Reference in New Issue
Block a user