add: sshsvc support telnet server
This commit is contained in:
@@ -129,6 +129,10 @@ func XCoreDB() *core.DB {
|
||||
return xEngine.DB()
|
||||
}
|
||||
|
||||
func XEngDB() *xorm.Engine {
|
||||
return xEngine
|
||||
}
|
||||
|
||||
func ConstructInsertSQL(tableName string, insertData interface{}) (string, []string) {
|
||||
log.Debug("ConstructInsertSQL processing... ")
|
||||
log.Debug("Request insertData:", insertData)
|
||||
|
||||
@@ -46,6 +46,7 @@ type MmlVar struct {
|
||||
Authorization string `josn:"authorization"`
|
||||
HttpUri string `json:"httpUri"`
|
||||
UserAgent string `json:"userAgent"`
|
||||
TagNE string `json:"tagNE"`
|
||||
}
|
||||
|
||||
// func init() {
|
||||
|
||||
@@ -51,7 +51,7 @@ type YamlConfig struct {
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
AuthType string `yaml:"authType"`
|
||||
OMCUrl string `yaml:"omcUrl"`
|
||||
TagNE string `yaml:"tagNE"`
|
||||
} `yaml:"sshd"`
|
||||
|
||||
TelnetServer struct {
|
||||
@@ -64,7 +64,7 @@ type YamlConfig struct {
|
||||
UserName string `yaml:"userName"`
|
||||
Password string `yaml:"password"`
|
||||
AuthType string `yaml:"authType"`
|
||||
OMCUrl string `yaml:"omcUrl"`
|
||||
TagNE string `yaml:"tagNE"`
|
||||
} `yaml:"telnetServer"`
|
||||
|
||||
Database DbConfig `yaml:"database"`
|
||||
|
||||
@@ -21,7 +21,7 @@ logmml:
|
||||
# ssh service listen ipv4/v6 and port, support multiple routines
|
||||
# ip: 0.0.0.0 or ::0, support IPv4/v6
|
||||
# session: single/multiple session for one user
|
||||
# authType: local/omc
|
||||
# authType: local/radius
|
||||
sshd:
|
||||
listenAddr: 0.0.0.0
|
||||
listenPort: 32222
|
||||
@@ -32,8 +32,8 @@ sshd:
|
||||
mmlHome: ./mmlhome
|
||||
userName: manager
|
||||
password: pass123
|
||||
authType: local
|
||||
omcUrl:
|
||||
authType: radius
|
||||
tagNE: hlr
|
||||
|
||||
# authType: local/omc
|
||||
telnetServer:
|
||||
@@ -45,16 +45,16 @@ telnetServer:
|
||||
mmlHome: ./mmlhome
|
||||
userName: manager
|
||||
password: pass123
|
||||
authType: local
|
||||
omcUrl:
|
||||
authType: radius
|
||||
tagNE: hlr
|
||||
|
||||
database:
|
||||
type: mysql
|
||||
user: root
|
||||
password: 1000omc@kp!
|
||||
host: 127.0.0.1
|
||||
port: 33066
|
||||
name: omc_db
|
||||
user: administrator
|
||||
password: "*86#ROtartsinim"
|
||||
host: 192.168.13.117
|
||||
port: 3306
|
||||
name: OMC_PUB
|
||||
connParam: charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&interpolateParams=True
|
||||
|
||||
omc:
|
||||
|
||||
@@ -144,7 +144,14 @@ func handleAuth(authType, userName, password string) bool {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
case "radius":
|
||||
exist, err := dborm.XEngDB().Table("OMC_PUB.sysUser").Where("userName=? AND password=md5(?)", userName, password).Exist()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return exist
|
||||
case "omc":
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -236,7 +243,7 @@ func handleTelnetConnection(conn net.Conn) {
|
||||
if handleAuth(conf.TelnetServer.AuthType, user, pass) {
|
||||
writer.WriteString("\nAuthentication successful!\n")
|
||||
writer.Flush()
|
||||
handleCommands(user, reader, writer)
|
||||
handleCommands(user, conf.TelnetServer.TagNE, reader, writer)
|
||||
} else {
|
||||
writer.WriteString("\nAuthentication failed!\n")
|
||||
writer.Flush()
|
||||
@@ -244,8 +251,8 @@ func handleTelnetConnection(conn net.Conn) {
|
||||
}
|
||||
|
||||
// 处理命令输入
|
||||
func handleCommands(user string, reader *bufio.Reader, writer *bufio.Writer) {
|
||||
header := fmt.Sprintf("[%s@omc]> ", user)
|
||||
func handleCommands(user, tag string, reader *bufio.Reader, writer *bufio.Writer) {
|
||||
header := fmt.Sprintf("[%s@%s]> ", user, tag)
|
||||
for {
|
||||
command, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
@@ -368,7 +375,7 @@ func handleSSHShell(sshConn *ssh.ServerConn, channel ssh.Channel) {
|
||||
// 检查通道是否支持终端
|
||||
|
||||
omcMmlVar := &mmlp.MmlVar{
|
||||
Version: "16.1.1",
|
||||
Version: global.Version,
|
||||
Output: mmlp.DefaultFormatType,
|
||||
MmlHome: conf.Sshd.MmlHome,
|
||||
Limit: 50,
|
||||
@@ -376,9 +383,10 @@ func handleSSHShell(sshConn *ssh.ServerConn, channel ssh.Channel) {
|
||||
SessionToken: fmt.Sprintf("%x", sshConn.SessionID()),
|
||||
HttpUri: conf.OMC.HttpUri,
|
||||
UserAgent: config.GetDefaultUserAgent(),
|
||||
TagNE: conf.Sshd.TagNE,
|
||||
}
|
||||
|
||||
term := term.NewTerminal(channel, fmt.Sprintf("[%s@omc]> ", omcMmlVar.User))
|
||||
term := term.NewTerminal(channel, fmt.Sprintf("[%s@%s]> ", omcMmlVar.User, omcMmlVar.TagNE))
|
||||
// 启动交互式shell会话
|
||||
for {
|
||||
line, err := term.ReadLine()
|
||||
|
||||
Reference in New Issue
Block a user