1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-03-31 04:43:58 +08:00
parent 9ed01c06a9
commit 0028f79073
5 changed files with 26 additions and 10 deletions

View File

@ -23,6 +23,7 @@ const (
AVATAR = "avatar" AVATAR = "avatar"
GENDER = "gender" GENDER = "gender"
MOBILE = "mobile" MOBILE = "mobile"
PHONE = "phone"
SECRET = "secret" SECRET = "secret"
THEME = "theme" THEME = "theme"

View File

@ -236,7 +236,7 @@ func init() {
}}, }},
SERVE_START: {Hand: func(m *ice.Message, arg ...string) { SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
Count(m, m.ActionKey(), m.Option(tcp.PORT)) Count(m, m.ActionKey(), m.Option(tcp.PORT))
m.Cmd(SPIDE, mdb.CREATE, kit.Format("http://localhost:%s", m.Option(tcp.PORT)), ice.OPS, nfs.USR_ICONS_CONTEXTS, nfs.REPOS, "") m.Cmd(SPIDE, mdb.CREATE, HostPort(m, "localhost", m.Option(tcp.PORT)), ice.OPS, nfs.USR_ICONS_CONTEXTS, nfs.REPOS, "")
m.Cmds(SPIDE).Table(func(value ice.Maps) { m.Cmds(SPIDE).Table(func(value ice.Maps) {
kit.If(value[CLIENT_NAME] != ice.OPS && value[TOKEN] != "", func() { kit.If(value[CLIENT_NAME] != ice.OPS && value[TOKEN] != "", func() {
m.Cmd(SPACE, tcp.DIAL, ice.DEV, value[CLIENT_NAME], TOKEN, value[TOKEN], mdb.TYPE, SERVER) m.Cmd(SPACE, tcp.DIAL, ice.DEV, value[CLIENT_NAME], TOKEN, value[TOKEN], mdb.TYPE, SERVER)

View File

@ -2,6 +2,7 @@ package web
import ( import (
"bytes" "bytes"
"crypto/tls"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil" "io/ioutil"
@ -183,7 +184,12 @@ func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map
}) })
} }
func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) { func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) {
client := mdb.HashSelectTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client) client := mdb.HashSelectTarget(m, name, func() ice.Any {
if name == ice.OPS {
return &http.Client{Timeout: kit.Duration(timeout), Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
}
return &http.Client{Timeout: kit.Duration(timeout)}
}).(*http.Client)
return client.Do(req) return client.Do(req)
} }
func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) { func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {

View File

@ -39,9 +39,9 @@ func init() {
aaa.Index.MergeCommands(ice.Commands{ aaa.Index.MergeCommands(ice.Commands{
CERT: {Name: "cert path auto", Help: "证书", Actions: ice.MergeActions(ice.Actions{ CERT: {Name: "cert path auto", Help: "证书", Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create name* country province city street postal company year month=1 day", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create name* country province city street postal company year month=1 day", Hand: func(m *ice.Message, arg ...string) {
if nfs.Exists(m, filepath(m, m.Option(mdb.NAME)+nfs.PT+PEM)) { if nfs.Exists(m, CertPath(m, m.Option(mdb.NAME)), func(p string) {
m.Push(PEM, filepath(m, m.Option(mdb.NAME)+nfs.PT+PEM)) m.Push(PEM, p).Push(KEY, kit.ExtChange(p, KEY))
m.Push(KEY, filepath(m, m.Option(mdb.NAME)+nfs.PT+KEY)) }) {
return return
} }
cert := &x509.Certificate{ cert := &x509.Certificate{
@ -123,8 +123,8 @@ func init() {
}}, }},
}) })
} }
func filepath(m *ice.Message, file string) string { func CertPath(m *ice.Message, domain string) string {
return path.Join(ETC_CERT + file) return path.Join(ETC_CERT+domain) + nfs.PT + PEM
} }
func loadBlock(m *ice.Message, p string) []byte { func loadBlock(m *ice.Message, p string) []byte {
block, _ := pem.Decode([]byte(m.Cmdx(nfs.CAT, p))) block, _ := pem.Decode([]byte(m.Cmdx(nfs.CAT, p)))

View File

@ -265,6 +265,10 @@ func (s relay) Pushkey(m *ice.Message, arg ...string) {
} }
} }
func (s relay) Pushbin(m *ice.Message, arg ...string) { func (s relay) Pushbin(m *ice.Message, arg ...string) {
if kit.HasPrefixList(arg, ctx.RUN) {
m.ProcessXterm("", nil, arg...)
return
}
bin := "ice" bin := "ice"
switch strings.ToLower(m.Option(KERNEL)) { switch strings.ToLower(m.Option(KERNEL)) {
case cli.LINUX: case cli.LINUX:
@ -285,14 +289,19 @@ func (s relay) Pushbin(m *ice.Message, arg ...string) {
m.Options(nfs.FROM, ice.USR_PUBLISH+bin, nfs.PATH, path.Base(kit.Path("")), nfs.FILE, ice.BIN_ICE_BIN) m.Options(nfs.FROM, ice.USR_PUBLISH+bin, nfs.PATH, path.Base(kit.Path("")), nfs.FILE, ice.BIN_ICE_BIN)
}) })
m.Cmd(SSH_TRANS, tcp.SEND) m.Cmd(SSH_TRANS, tcp.SEND)
if m.Option(web.PORTAL) == tcp.PORT_443 { if m.OptionDefault(web.PORTAL, tcp.PORT_9020) == tcp.PORT_443 {
for i := 0; i < 30; i++ {
if m.Exists(ssh.CertPath(m.Message, m.Option(tcp.HOST))) {
break
}
m.Sleep("5s")
}
msg := m.Cmd(ssh.CERT, mdb.CREATE, m.Option(tcp.HOST)) msg := m.Cmd(ssh.CERT, mdb.CREATE, m.Option(tcp.HOST))
m.Cmd(SSH_TRANS, tcp.SEND, nfs.FROM, msg.Append(ssh.KEY), nfs.PATH, m.Option(web.DREAM), nfs.FILE, nfs.ETC_CERT_KEY) m.Cmd(SSH_TRANS, tcp.SEND, nfs.FROM, msg.Append(ssh.KEY), nfs.PATH, m.Option(web.DREAM), nfs.FILE, nfs.ETC_CERT_KEY)
m.Cmd(SSH_TRANS, tcp.SEND, nfs.FROM, msg.Append(ssh.PEM), nfs.PATH, m.Option(web.DREAM), nfs.FILE, nfs.ETC_CERT_PEM) m.Cmd(SSH_TRANS, tcp.SEND, nfs.FROM, msg.Append(ssh.PEM), nfs.PATH, m.Option(web.DREAM), nfs.FILE, nfs.ETC_CERT_PEM)
} }
cmd := m.Template(PUSHBIN_SH) + lex.SP + kit.JoinCmds(ice.DEV, m.Option(ice.DEV), tcp.PORT, m.Option(web.PORTAL), tcp.NODENAME, m.OptionDefault(tcp.NODENAME, m.Option(MACHINE))) cmd := "export ctx_dev=" + m.SpideOrigin(ice.DEV) + "; " + m.Template(PUSHBIN_SH) + lex.SP + kit.JoinCmds(ice.DEV, m.Option(ice.DEV), tcp.PORT, m.Option(web.PORTAL), tcp.NODENAME, m.OptionDefault(tcp.NODENAME, m.Option(MACHINE)))
s.shell(m, cmd, arg...) s.shell(m, cmd, arg...)
m.OptionDefault(web.PORTAL, tcp.PORT_9020)
s.Modify(m, kit.Simple(m.OptionSimple(MACHINE, web.DREAM, web.PORTAL))...) s.Modify(m, kit.Simple(m.OptionSimple(MACHINE, web.DREAM, web.PORTAL))...)
} }