mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 17:44:05 +08:00
opt login
This commit is contained in:
parent
47b61c540a
commit
b278396504
@ -20,20 +20,27 @@ func init() {
|
|||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
FOREVER: {Name: "forever", Help: "启动", Action: map[string]*ice.Action{
|
FOREVER: {Name: "forever", Help: "启动", Action: map[string]*ice.Action{
|
||||||
SERVE: {Name: "serve", Help: "服务", Hand: func(m *ice.Message, arg ...string) {
|
SERVE: {Name: "serve", Help: "服务", Hand: func(m *ice.Message, arg ...string) {
|
||||||
env := []string{PATH, BinPath()}
|
env := []string{PATH, BinPath(), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))}
|
||||||
for _, k := range []string{HOME, CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} {
|
for _, k := range []string{SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} {
|
||||||
env = append(env, k, kit.Env(k))
|
if kit.Env(k) != "" {
|
||||||
|
env = append(env, k, kit.Env(k))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Option(CMD_ENV, env)
|
m.Option(CMD_ENV, env)
|
||||||
|
|
||||||
m.Option(CMD_ERRPUT, kit.Select(ice.BIN_BOOT_LOG, kit.Env(CTX_LOG)))
|
m.Optionv(CMD_INPUT, os.Stdin)
|
||||||
|
m.Optionv(CMD_OUTPUT, os.Stdout)
|
||||||
|
m.Optionv(CMD_ERRPUT, os.Stderr)
|
||||||
|
if p := kit.Env(CTX_LOG); p != "" {
|
||||||
|
m.Optionv(CMD_ERRPUT, p)
|
||||||
|
}
|
||||||
m.Cmdy(FOREVER, kit.Select(os.Args[0], nfs.PWD+ice.BIN_ICE_BIN, kit.FileExists(ice.BIN_ICE_BIN)),
|
m.Cmdy(FOREVER, kit.Select(os.Args[0], nfs.PWD+ice.BIN_ICE_BIN, kit.FileExists(ice.BIN_ICE_BIN)),
|
||||||
SERVE, START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg)
|
SERVE, START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg)
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
for {
|
for {
|
||||||
println(kit.Format("%s run %s", kit.Now(), kit.Join(arg, ice.SP)))
|
println(kit.Format("%s run %s", kit.Now(), kit.Join(arg, ice.SP)))
|
||||||
if m.Sleep("1s"); IsSuccess(m.Cmd(SYSTEM, arg, kit.Dict(CMD_INPUT, os.Stdin, CMD_OUTPUT, os.Stdout))) {
|
if m.Sleep("1s"); IsSuccess(m.Cmd(SYSTEM, arg)) {
|
||||||
println(kit.Format("%s exit", kit.Now()))
|
println(kit.Format("%s exit", kit.Now()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,10 @@ const (
|
|||||||
UBUNTU = "ubuntu"
|
UBUNTU = "ubuntu"
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
USER = "USER"
|
SHELL = "SHELL"
|
||||||
HOME = "HOME"
|
USER = "USER"
|
||||||
PATH = "PATH"
|
HOME = "HOME"
|
||||||
|
PATH = "PATH"
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
CTX_SHY = "ctx_shy"
|
CTX_SHY = "ctx_shy"
|
||||||
@ -156,7 +157,7 @@ func init() {
|
|||||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
RUNTIME: {Name: RUNTIME, Help: "运行环境", Value: kit.Dict()},
|
RUNTIME: {Name: RUNTIME, Help: "运行环境", Value: kit.Dict()},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,bootinfo,diskinfo auto", Help: "运行环境", Action: map[string]*ice.Action{
|
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,bootinfo,diskinfo,env auto", Help: "运行环境", Action: map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
_runtime_init(m)
|
_runtime_init(m)
|
||||||
m.Cmd(RUNTIME, MAXPROCS, "1")
|
m.Cmd(RUNTIME, MAXPROCS, "1")
|
||||||
@ -193,6 +194,13 @@ func init() {
|
|||||||
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_runtime_diskinfo(m)
|
_runtime_diskinfo(m)
|
||||||
}},
|
}},
|
||||||
|
"env": {Name: "env", Help: "环境变量", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
for _, v := range os.Environ() {
|
||||||
|
ls := strings.SplitN(v, "=", 2)
|
||||||
|
m.Push(mdb.NAME, ls[0])
|
||||||
|
m.Push(mdb.VALUE, ls[1])
|
||||||
|
}
|
||||||
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 0 && arg[0] == BOOTINFO {
|
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||||
arg = arg[1:]
|
arg = arg[1:]
|
||||||
|
@ -53,6 +53,8 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
func _system_out(m *ice.Message, out string) io.Writer {
|
func _system_out(m *ice.Message, out string) io.Writer {
|
||||||
|
defer func() { m.Warn(recover(), "output", out) }()
|
||||||
|
|
||||||
if w, ok := m.Optionv(out).(io.Writer); ok {
|
if w, ok := m.Optionv(out).(io.Writer); ok {
|
||||||
return w
|
return w
|
||||||
} else if m.Option(out) == "" {
|
} else if m.Option(out) == "" {
|
||||||
@ -65,6 +67,9 @@ func _system_out(m *ice.Message, out string) io.Writer {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func _system_find(m *ice.Message, bin string, dir ...string) string {
|
func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||||
|
if strings.Contains(bin, ice.DF) {
|
||||||
|
return bin
|
||||||
|
}
|
||||||
if strings.HasPrefix(bin, ice.PS) {
|
if strings.HasPrefix(bin, ice.PS) {
|
||||||
return bin
|
return bin
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,18 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
|
|
||||||
bio.WriteString(l.p)
|
bio.WriteString(l.p)
|
||||||
bio.WriteString(ice.SP)
|
bio.WriteString(ice.SP)
|
||||||
if p, ok := view[PREFIX].(string); ok {
|
if ice.Info.Colors == true {
|
||||||
bio.WriteString(p)
|
if p, ok := view[PREFIX].(string); ok {
|
||||||
|
bio.WriteString(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bio.WriteString(l.l)
|
bio.WriteString(l.l)
|
||||||
bio.WriteString(ice.SP)
|
bio.WriteString(ice.SP)
|
||||||
bio.WriteString(l.s)
|
bio.WriteString(l.s)
|
||||||
if p, ok := view[SUFFIX].(string); ok {
|
if ice.Info.Colors == true {
|
||||||
bio.WriteString(p)
|
if p, ok := view[SUFFIX].(string); ok {
|
||||||
|
bio.WriteString(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bio.WriteString(ice.NL)
|
bio.WriteString(ice.NL)
|
||||||
bio.Flush()
|
bio.Flush()
|
||||||
|
@ -70,7 +70,9 @@ func (f *Frame) prompt(m *ice.Message, list ...string) *Frame {
|
|||||||
case TARGET:
|
case TARGET:
|
||||||
fmt.Fprintf(f.stdout, f.target.Name)
|
fmt.Fprintf(f.stdout, f.target.Name)
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(f.stdout, v)
|
if ice.Info.Colors || v[0] != '\033' {
|
||||||
|
fmt.Fprintf(f.stdout, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
@ -165,7 +167,9 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
|||||||
// continue // 注释
|
// continue // 注释
|
||||||
// }
|
// }
|
||||||
if ps = f.ps1; f.stdout == os.Stdout {
|
if ps = f.ps1; f.stdout == os.Stdout {
|
||||||
f.printf(m, "\033[0m") // 清空格式
|
if ice.Info.Colors {
|
||||||
|
f.printf(m, "\033[0m") // 清空格式
|
||||||
|
}
|
||||||
}
|
}
|
||||||
line = f.parse(m, line)
|
line = f.parse(m, line)
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,24 @@ var rewriteList = []interface{}{}
|
|||||||
|
|
||||||
func AddRewrite(cb interface{}) { rewriteList = append(rewriteList, cb) }
|
func AddRewrite(cb interface{}) { rewriteList = append(rewriteList, cb) }
|
||||||
|
|
||||||
|
func _serve_domain(m *ice.Message) string {
|
||||||
|
if p := m.Config(DOMAIN); p != "" {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
if p := m.R.Header.Get("X-Host"); p != "" {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
if m.R.Method == "POST" {
|
||||||
|
if p := m.R.Header.Get("Referer"); p != "" {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.R.TLS == nil {
|
||||||
|
return kit.Format("http://%s", m.R.Host)
|
||||||
|
} else {
|
||||||
|
return kit.Format("https://%s", m.R.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||||
if r.Header.Get("Index-Module") == "" {
|
if r.Header.Get("Index-Module") == "" {
|
||||||
r.Header.Set("Index-Module", m.Prefix())
|
r.Header.Set("Index-Module", m.Prefix())
|
||||||
@ -135,11 +153,12 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 请求地址
|
// 请求地址
|
||||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Config(DOMAIN), kit.Select(r.Header.Get("Referer"), r.Header.Get("X-Host"))))
|
msg.R, msg.W = r, w
|
||||||
|
msg.Option(ice.MSG_USERWEB, _serve_domain(msg))
|
||||||
msg.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR)))
|
msg.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR)))
|
||||||
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||||
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
|
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
|
||||||
msg.R, msg.W = r, w
|
msg.Debug("what %v", msg.FormatMeta())
|
||||||
|
|
||||||
// 会话别名
|
// 会话别名
|
||||||
if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" {
|
if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" {
|
||||||
|
@ -19,8 +19,7 @@ func _space_link(m *ice.Message, pod string, arg ...interface{}) string {
|
|||||||
return tcp.ReplaceLocalhost(m, kit.MergePOD(m.Option(ice.MSG_USERWEB), pod, arg...))
|
return tcp.ReplaceLocalhost(m, kit.MergePOD(m.Option(ice.MSG_USERWEB), pod, arg...))
|
||||||
}
|
}
|
||||||
func _space_domain(m *ice.Message) (link string) {
|
func _space_domain(m *ice.Message) (link string) {
|
||||||
link = m.Config(DOMAIN)
|
if link = m.Config(DOMAIN); link == "" {
|
||||||
if link == "" {
|
|
||||||
link = m.Cmd(SPACE, ice.DEV, cli.PWD).Append(mdb.LINK)
|
link = m.Cmd(SPACE, ice.DEV, cli.PWD).Append(mdb.LINK)
|
||||||
}
|
}
|
||||||
if link == "" {
|
if link == "" {
|
||||||
@ -29,6 +28,13 @@ func _space_domain(m *ice.Message) (link string) {
|
|||||||
if link == "" {
|
if link == "" {
|
||||||
link = m.Option(ice.MSG_USERWEB)
|
link = m.Option(ice.MSG_USERWEB)
|
||||||
}
|
}
|
||||||
|
if link == "" && m.R != nil && m.R.Host != "" && !tcp.IsLocalHost(m, m.R.Host) {
|
||||||
|
if m.R.TLS == nil {
|
||||||
|
link = kit.Format("http://%s", m.R.Host)
|
||||||
|
} else {
|
||||||
|
link = kit.Format("https://%s", m.R.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
if link == "" {
|
if link == "" {
|
||||||
link = kit.Format("http://localhost:%s", m.Cmd(SERVE).Append(tcp.PORT))
|
link = kit.Format("http://localhost:%s", m.Cmd(SERVE).Append(tcp.PORT))
|
||||||
}
|
}
|
||||||
@ -224,12 +230,14 @@ func _space_fork(m *ice.Message) {
|
|||||||
m.Go(func(msg *ice.Message) {
|
m.Go(func(msg *ice.Message) {
|
||||||
switch m.Option(ice.CMD) {
|
switch m.Option(ice.CMD) {
|
||||||
case cli.PWD:
|
case cli.PWD:
|
||||||
link := kit.MergeURL(_space_domain(msg), aaa.GRANT, name)
|
link := kit.MergeURL(_space_domain(m), aaa.GRANT, name)
|
||||||
msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
||||||
case "sso":
|
case "sso":
|
||||||
link := _space_domain(msg)
|
link := _space_domain(m)
|
||||||
|
m.Debug("what %v", link)
|
||||||
ls := strings.Split(kit.ParseURL(link).Path, ice.PS)
|
ls := strings.Split(kit.ParseURL(link).Path, ice.PS)
|
||||||
link = kit.MergeURL2(_space_domain(msg), "/chat/sso", "space", kit.Select("", ls, 3), "back", m.Option(ice.MSG_USERWEB))
|
link = kit.MergeURL2(_space_domain(m), "/chat/sso", "space", kit.Select("", ls, 3), "back", m.Option(ice.MSG_USERWEB))
|
||||||
|
m.Debug("what %v", link)
|
||||||
msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
||||||
default:
|
default:
|
||||||
msg.Sleep300ms(SPACE, name, cli.PWD, name)
|
msg.Sleep300ms(SPACE, name, cli.PWD, name)
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/tcp"
|
"shylinux.com/x/icebergs/base/tcp"
|
||||||
|
"shylinux.com/x/icebergs/base/web"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,7 +69,12 @@ func init() {
|
|||||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.Config(nfs.PATH))
|
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.Config(nfs.PATH))
|
||||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.PrefixKey())
|
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.PrefixKey())
|
||||||
m.Config(ice.CONTEXTS, _contexts)
|
m.Config(ice.CONTEXTS, _contexts)
|
||||||
|
m.Watch(web.SERVE_START, m.PrefixKey())
|
||||||
}},
|
}},
|
||||||
|
web.SERVE_START: {Name: "serve.start", Help: "服务启动", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_publish_file(m, ice.ICE_BIN)
|
||||||
|
}},
|
||||||
|
|
||||||
ice.VOLCANOS: {Name: "volcanos", Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
ice.VOLCANOS: {Name: "volcanos", Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||||
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
||||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
||||||
|
1
info.go
1
info.go
@ -24,6 +24,7 @@ var Info = struct {
|
|||||||
UserName string
|
UserName string
|
||||||
PassWord string
|
PassWord string
|
||||||
|
|
||||||
|
Colors bool
|
||||||
Domain string
|
Domain string
|
||||||
NodeType string
|
NodeType string
|
||||||
NodeName string
|
NodeName string
|
||||||
|
6
init.go
6
init.go
@ -111,6 +111,12 @@ func Run(arg ...string) string {
|
|||||||
|
|
||||||
switch Index.Merge(Index).Begin(Pulse.Spawn(), arg...); kit.Select("", arg, 0) {
|
switch Index.Merge(Index).Begin(Pulse.Spawn(), arg...); kit.Select("", arg, 0) {
|
||||||
case SERVE, SPACE: // 启动服务
|
case SERVE, SPACE: // 启动服务
|
||||||
|
switch path.Base(os.Getenv("SHELL")) {
|
||||||
|
case "", ".":
|
||||||
|
Info.Colors = false
|
||||||
|
default:
|
||||||
|
Info.Colors = true
|
||||||
|
}
|
||||||
if log.LogDisable = false; Index.Start(Pulse, arg...) {
|
if log.LogDisable = false; Index.Start(Pulse, arg...) {
|
||||||
Pulse.TryCatch(Pulse, true, func(Pulse *Message) { Index.wg.Wait() })
|
Pulse.TryCatch(Pulse, true, func(Pulse *Message) { Index.wg.Wait() })
|
||||||
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
||||||
|
20
logs.go
20
logs.go
@ -20,15 +20,17 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
|
|||||||
|
|
||||||
// 日志颜色
|
// 日志颜色
|
||||||
prefix, suffix := "", ""
|
prefix, suffix := "", ""
|
||||||
switch level {
|
if Info.Colors {
|
||||||
case LOG_CREATE, LOG_INSERT, LOG_MODIFY, LOG_EXPORT, LOG_IMPORT:
|
switch level {
|
||||||
prefix, suffix = "\033[36;44m", "\033[0m"
|
case LOG_CREATE, LOG_INSERT, LOG_MODIFY, LOG_EXPORT, LOG_IMPORT:
|
||||||
case LOG_CMDS, LOG_START, LOG_SERVE:
|
prefix, suffix = "\033[36;44m", "\033[0m"
|
||||||
prefix, suffix = "\033[32m", "\033[0m"
|
case LOG_CMDS, LOG_START, LOG_SERVE:
|
||||||
case LOG_WARN, LOG_ERROR, LOG_CLOSE:
|
prefix, suffix = "\033[32m", "\033[0m"
|
||||||
prefix, suffix = "\033[31m", "\033[0m"
|
case LOG_WARN, LOG_ERROR, LOG_CLOSE:
|
||||||
case LOG_AUTH, LOG_COST:
|
prefix, suffix = "\033[31m", "\033[0m"
|
||||||
prefix, suffix = "\033[33m", "\033[0m"
|
case LOG_AUTH, LOG_COST:
|
||||||
|
prefix, suffix = "\033[33m", "\033[0m"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件行号
|
// 文件行号
|
||||||
|
Loading…
x
Reference in New Issue
Block a user