forked from x/icebergs
opt island
This commit is contained in:
parent
bbb4994422
commit
1f0a904767
@ -33,17 +33,19 @@ func BasicSess(m *ice.Message) {
|
||||
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
aaa.SessCheck(m, m.Option(ice.MSG_SESSID))
|
||||
}
|
||||
func BasicCheck(m *ice.Message, realm string) bool {
|
||||
func BasicCheck(m *ice.Message, realm string, check ...func(*ice.Message) bool) bool {
|
||||
switch ls := kit.Split(m.R.Header.Get(html.Authorization)); kit.Select("", ls, 0) {
|
||||
case html.Basic:
|
||||
if buf, err := base64.StdEncoding.DecodeString(kit.Select("", ls, 1)); !m.Warn(err) {
|
||||
if ls := strings.SplitN(string(buf), ":", 2); !m.Warn(len(ls) < 2 || ls[1] == "", ice.ErrNotValid, html.Basic) {
|
||||
if msg := m.Cmd(TOKEN, ls[1]); !m.Warn(msg.Time() > msg.Append(mdb.TIME), ice.ErrNotValid) {
|
||||
if len(check) == 0 || check[0](msg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m.W.Header().Add("WWW-Authenticate", kit.Format(`Basic realm="%s"`, realm))
|
||||
m.RenderStatusUnauthorized()
|
||||
return false
|
||||
|
@ -140,9 +140,9 @@ func ToastSuccess(m *ice.Message, arg ...ice.Any) {
|
||||
func ToastFailure(m *ice.Message, arg ...ice.Any) {
|
||||
Toast(m, toastContent(m, ice.FAILURE, arg...), "", m.OptionDefault(ice.TOAST_DURATION, "3s")).Sleep(m.OptionDefault(ice.TOAST_DURATION, "3s"))
|
||||
}
|
||||
func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
|
||||
func ToastProcess(m *ice.Message, arg ...ice.Any) func(...ice.Any) {
|
||||
Toast(m, toastContent(m, ice.PROCESS, arg...), "", "30s")
|
||||
return func() { Toast(m, toastContent(m, ice.SUCCESS, arg...), "", "1s") }
|
||||
return func(arg ...ice.Any) { Toast(m, toastContent(m, ice.SUCCESS, arg...), "", "1s") }
|
||||
}
|
||||
func GoToast(m *ice.Message, title string, cb func(toast func(name string, count, total int)) []string) *ice.Message {
|
||||
_total := 0
|
||||
|
@ -69,23 +69,22 @@ func _space_fork(m *ice.Message) {
|
||||
addr := kit.Select(m.R.RemoteAddr, m.R.Header.Get(ice.MSG_USERADDR))
|
||||
text := strings.ReplaceAll(kit.Select(addr, m.Option(mdb.TEXT)), "%2F", nfs.PS)
|
||||
name := kit.ReplaceAll(kit.Select(addr, m.Option(mdb.NAME)), "[", "_", "]", "_", nfs.DF, "_", nfs.PT, "_")
|
||||
if kit.IsIn(m.Option(mdb.TYPE), WORKER) && IsLocalHost(m) || m.Option(TOKEN) != "" && m.Cmdv(TOKEN, m.Option(TOKEN), mdb.TIME) > m.Time() {
|
||||
if kit.IsIn(m.Option(mdb.TYPE), WORKER) && IsLocalHost(m) {
|
||||
|
||||
} else if kit.IsIn(m.Option(mdb.TYPE), PORTAL, aaa.LOGIN) && len(name) == 32 && kit.IsIn(mdb.HashSelects(m.Spawn(), name).Append(aaa.IP), "", m.Option(ice.MSG_USERIP)) {
|
||||
|
||||
} else {
|
||||
name, text = kit.Hashs(name), kit.Select(addr, m.Option(mdb.NAME), m.Option(mdb.TEXT))
|
||||
}
|
||||
|
||||
if kit.IsIn(m.Option(mdb.TYPE), WORKER, PORTAL) {
|
||||
if m.Option(ice.MSG_USERNAME, ""); kit.IsIn(m.Option(mdb.TYPE), WORKER, PORTAL) {
|
||||
if tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
aaa.SessAuth(m, kit.Dict(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME, ice.Info.Username)).AppendSimple()))
|
||||
}
|
||||
} else if m.Option(TOKEN) != "" {
|
||||
msg := m.Cmd(TOKEN, m.Option(TOKEN))
|
||||
if msg := m.Cmd(TOKEN, m.Option(TOKEN)); msg.Append(mdb.TIME) > m.Time() && msg.Append(mdb.TYPE) == SERVER {
|
||||
aaa.SessAuth(m, kit.Dict(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME, msg.Append(mdb.NAME))).AppendSimple()))
|
||||
} else {
|
||||
m.Option(ice.MSG_USERNAME, "")
|
||||
name = kit.Select(name, msg.Append(mdb.TEXT))
|
||||
}
|
||||
}
|
||||
if m.Option(mdb.TYPE) == WORKER {
|
||||
if p := nfs.USR_LOCAL_WORK + m.Option(mdb.NAME); nfs.Exists(m, p) {
|
||||
@ -115,10 +114,11 @@ func _space_fork(m *ice.Message) {
|
||||
m.Go(func() {
|
||||
m.Cmd(SPACE, name, cli.PWD, name, kit.Dict(nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), AGENT, "Go-http-client", cli.SYSTEM, runtime.GOOS))
|
||||
m.Cmd(SPACE).Table(func(value ice.Maps) {
|
||||
if kit.IsIn(value[mdb.TYPE], WORKER, SERVER) {
|
||||
if kit.IsIn(value[mdb.TYPE], WORKER, SERVER) && value[mdb.NAME] != name {
|
||||
m.Cmd(SPACE, value[mdb.NAME], gdb.EVENT, gdb.HAPPEN, gdb.EVENT, OPS_SERVER_OPEN, args, kit.Dict(ice.MSG_USERROLE, aaa.TECH))
|
||||
}
|
||||
})
|
||||
m.Cmd(gdb.EVENT, gdb.HAPPEN, gdb.EVENT, OPS_SERVER_OPEN, args, kit.Dict(ice.MSG_USERROLE, aaa.TECH))
|
||||
})
|
||||
}
|
||||
_space_handle(m, false, name, c)
|
||||
@ -226,7 +226,9 @@ func _space_send(m *ice.Message, name string, arg ...string) (h string) {
|
||||
}
|
||||
}
|
||||
}) {
|
||||
kit.If(m.IsDebug(), func() {
|
||||
m.Warn(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, ice.ErrNotFound, SPACE, name)
|
||||
})
|
||||
} else if withecho {
|
||||
m.Warn(!wait(), "time out")
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd("", mdb.CREATE, mdb.TYPE, m.Option(mdb.TYPE), mdb.NAME, m.Option(ice.MSG_USERNAME), mdb.TEXT, m.Option(tcp.HOST))
|
||||
m.ProcessReplace(kit.MergeURL2(m.Option(tcp.HOST), kit.MergeURL(C(m.PrefixKey()), ctx.ACTION, SET),
|
||||
m.ProcessReplace(kit.MergeURL2(m.Option(tcp.HOST), C(m.PrefixKey()), ctx.ACTION, SET,
|
||||
TOKEN, strings.Replace(UserHost(m), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), msg.Result()), 1)))
|
||||
}},
|
||||
SET: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -21,9 +21,8 @@ func _action_exec(m *ice.Message, river, storm, index string, arg ...string) {
|
||||
}).Length() == 0, ice.ErrNotRight, index, arg) {
|
||||
return
|
||||
}
|
||||
kit.If(!ctx.PodCmd(m, index, arg), func() {
|
||||
m.Cmdy(index, arg)
|
||||
})
|
||||
kit.If(index == "web.chat.island.portal", func() { m.Option(ice.MSG_USERROLE, aaa.VOID) })
|
||||
kit.If(!ctx.PodCmd(m, index, arg), func() { m.Cmdy(index, arg) })
|
||||
}
|
||||
func _action_auth(m *ice.Message, share string) *ice.Message {
|
||||
msg := m.Cmd(web.SHARE, share)
|
||||
@ -82,9 +81,6 @@ func init() {
|
||||
ctx.OptionFromConfig(m, MENUS)
|
||||
_action_list(m, arg[0], arg[1])
|
||||
} else {
|
||||
if arg[2] == "web.chat.island.portal" {
|
||||
m.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||
}
|
||||
_action_exec(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}
|
||||
}},
|
||||
|
@ -126,7 +126,7 @@ func _repos_each_origin(m *ice.Message, title string, cb func(*git.Repository, s
|
||||
_repos_each(m, title, func(repos *git.Repository, value ice.Maps) error {
|
||||
remote := _repos_remote(m, _repos_origin(m, repos))
|
||||
auth := _repos_auth(m, remote)
|
||||
m.Info("%s: %s %s", m.ActionKey(), auth.Username, remote)
|
||||
m.Info("%s: %s %s %v", m.ActionKey(), auth.Username, remote, auth)
|
||||
return cb(repos, remote, auth, value)
|
||||
})
|
||||
}
|
||||
@ -543,7 +543,12 @@ func init() {
|
||||
PUSH: {Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
_repos_each_origin(m, "", func(repos *git.Repository, remoteURL string, auth *http.BasicAuth, value ice.Maps) error {
|
||||
defer _git_cmd(m.Spawn(kit.Dict(cli.CMD_DIR, value[nfs.PATH])), PUSH, "--tags")
|
||||
return repos.Push(&git.PushOptions{RemoteURL: remoteURL, Auth: auth, FollowTags: true})
|
||||
err := repos.Push(&git.PushOptions{RemoteURL: remoteURL, Auth: auth, FollowTags: true})
|
||||
switch kit.Format(err) {
|
||||
case "empty input":
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
})
|
||||
}},
|
||||
STATUS: {Help: "状态", Icon: "bi bi-app-indicator", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -124,14 +124,18 @@ func init() {
|
||||
}
|
||||
switch repos, service := _service_param(m, arg...); service {
|
||||
case RECEIVE_PACK:
|
||||
if !web.BasicCheck(m, "git server") {
|
||||
if !web.BasicCheck(m, "git server", func(msg *ice.Message) bool {
|
||||
return msg.Append(mdb.TYPE) == "web.code.git.status" || (msg.Append(mdb.TYPE) == web.SERVER && msg.Append(mdb.TEXT) == path.Base(repos))
|
||||
}) {
|
||||
return
|
||||
} else if !nfs.Exists(m, repos) {
|
||||
m.Cmd(Prefix(SERVICE), mdb.CREATE, mdb.NAME, path.Base(repos))
|
||||
}
|
||||
case UPLOAD_PACK:
|
||||
if mdb.Conf(m, Prefix(SERVICE), kit.Keym(aaa.AUTH)) == aaa.PRIVATE {
|
||||
if !web.BasicCheck(m, "git server") {
|
||||
if !web.BasicCheck(m, "git server", func(msg *ice.Message) bool {
|
||||
return msg.Append(mdb.TYPE) == "web.code.git.status" || msg.Append(mdb.TYPE) == web.SERVER && msg.Append(mdb.TEXT) == path.Base(repos)
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func init() {
|
||||
}},
|
||||
OAUTH: {Name: "oauth remote", Help: "授权", Icon: "bi bi-person-check", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessOpen(kit.MergeURL2(kit.Select(ice.Info.Make.Domain, m.Cmdx(REPOS, REMOTE_URL), m.Option(REMOTE)),
|
||||
web.ChatCmdPath(m, web.TOKEN, "gen"), mdb.TYPE, web.CODE_GIT_STATUS, tcp.HOST, web.UserHost(m)))
|
||||
web.C(web.TOKEN), ctx.ACTION, "gen", mdb.TYPE, web.CODE_GIT_STATUS, tcp.HOST, web.UserHost(m)))
|
||||
}},
|
||||
CONFIGS: {Name: "configs email* username*", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DEFS, kit.HomePath(_GITCONFIG), kit.Format(nfs.Template(m, "gitconfig"), m.Option(aaa.USERNAME), m.Option(aaa.EMAIL)))
|
||||
|
@ -114,7 +114,9 @@ func (m *Message) RenderJson(arg ...Any) *Message {
|
||||
func (m *Message) RenderVoid(arg ...Any) *Message {
|
||||
return m.Render(RENDER_VOID, arg...)
|
||||
}
|
||||
|
||||
func (m *Message) IsDebug() bool {
|
||||
return m.Option(MSG_DEBUG) == TRUE
|
||||
}
|
||||
func (m *Message) IsCliUA() bool {
|
||||
return m.Option(MSG_USERUA) == "" || !strings.HasPrefix(m.Option(MSG_USERUA), "Mozilla")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user