1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 01:04:06 +08:00
Change-Id: I75d31caba4e19130509a6ba80e781f2c8c3bdb7b
This commit is contained in:
shaoying 2019-03-31 20:29:38 +08:00
parent bd27df6493
commit 55b0c02e25
7 changed files with 38 additions and 18 deletions

View File

@ -1,6 +1,6 @@
#! /bin/bash
export ctx_dev=${ctx_dev:="https://shylinux.com"}
export ctx_dev=${ctx_dev:="-"}
export ctx_root="/usr/local/context"
export ctx_home=~/context
export ctx_bin="bench"
@ -48,17 +48,19 @@ action() {
main() {
while true; do
cp -r var/log var/log_$(date +%Y%m%d_%H%M%S)
$ctx_bin "$@" 2>var/log/boot.log && break
log "restarting..." && sleep 3
done
}
dir=$ctx_root
dir=./
[ -d "$1" ] && dir=$1 && shift
[ -d "$dir" ] && cd $dir
[ -f bin/bench ] && ctx_bin=bin/bench
pid=`cat var/run/bench.pid`
log "dir: $dir\nbench: $ctx_bin\npid: $pid"
log "dev:$ctx_dev\ndir: $dir\nbench: $ctx_bin\npid: $pid"
case $1 in
install) shift; prepare && install "$@";;

View File

@ -99,7 +99,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
},
Configs: map[string]*ctx.Config{
"runtime": &ctx.Config{Name: "runtime", Value: map[string]interface{}{
"init_env": []interface{}{"ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"},
"init_env": []interface{}{"ctx_cas", "ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"},
"boot": map[string]interface{}{"web_port": ":9094", "ssh_port": ":9090"},
}, Help: "运行环境"},
@ -338,7 +338,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
// 运行命令
if e := cmd.Run(); e != nil {
m.Echo("error: ").Echo("%s\n", e).Echo(err.String())
m.Echo("error: ").Echo(kit.Select(e.Error(), err.String()))
return
}
@ -434,7 +434,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}
text := strings.Join(arg, " ")
if !strings.HasPrefix(text, "sess") {
if !strings.HasPrefix(text, "sess") && m.Options("remote") {
text = m.Current(text)
}

View File

@ -832,6 +832,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
}
return
}
if len(arg) > 1 && arg[1] == "map" {
for i := 2; i < len(arg)-1; i += 2 {
m.Confv(arg[0], arg[i], arg[i+1])
}
return
}
all := false
if len(arg) > 0 && arg[0] == "all" {

View File

@ -1488,7 +1488,11 @@ func (m *Message) Cmdy(args ...interface{}) *Message {
return m
}
func (m *Message) Cmdx(args ...interface{}) string {
return m.Cmd(args...).Result(0)
msg := m.Cmd(args...)
if msg.Result(0) == "error: " {
return msg.Result(1)
}
return msg.Result(0)
}
func (m *Message) Cmds(args ...interface{}) bool {
return m.Cmd(args...).Results(0)

View File

@ -281,6 +281,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
if !m.Cmds("aaa.rsa", "verify", m.Option("node.cert"), m.Option("node.sign"), m.Option("text.hash", hash)) {
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
m.Log("warning", "node error")
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "node", "delete")
return
}
} else {
@ -348,7 +349,11 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
if m.Options("remote_code") {
m.Log("info", "username %s", m.Option("user.name"))
if m.Option("username", m.Option("user.name")); !m.Confs("trust", m.Option("node.route")) {
if m.Option("username", m.Option("user.name")); m.Confs("trust", m.Option("node.route")) {
m.Log("info", "skip verify user of node %s", m.Option("node.route"))
} else if m.Confs("trust", "up") && strings.HasPrefix(m.Conf("runtime", "node.route"), m.Option("node.route")) {
m.Log("info", "skip verify user of up node %s", m.Option("node.route"))
} else {
// 用户签名
hash, _ := kit.Hash("rand", m.Option("text.time", m.Time("stamp")), m.Option("node.route"))
m.Option("user.cert", m.Cmd("aaa.auth", "username", m.Option("user.name"), "cert").Append("meta"))
@ -360,8 +365,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Echo("no right of %s", m.Option("text.route"))
return
}
} else {
m.Log("info", "skip verify user of node %s", m.Option("node.route"))
}
// 创建会话

View File

@ -92,10 +92,10 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
if msg.Confs("skip_login", msg.Option("path")) {
return true
}
if msg.Confs("login", "cas_url") && !msg.Confs("login", "skip_cas") {
if msg.Confs("login", "cas") {
if !cas.IsAuthenticated(r) {
r.URL, _ = r.URL.Parse(r.Header.Get("index_url"))
msg.Log("info", "cas_login %v %v", r.URL, msg.Conf("login", "cas_url"))
msg.Log("info", "cas_login %v %v", r.URL, msg.Conf("spide", "cas.client.url"))
cas.RedirectToLogin(w, r)
return false
}
@ -336,10 +336,10 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool {
})
// SSO认证
m.Log("info", "web: %s", m.Conf("login", "cas_url"))
var handler http.Handler
if cas_url, e := url.Parse(m.Conf("login", "cas_url")); e == nil && m.Confs("login", "cas_url") {
m.Log("info", "cas url: %s", m.Conf("login", "cas_url"))
if cas_url, e := url.Parse(m.Cmdx("web.spide", "cas", "client", "url")); e == nil && cas_url.Host != "" {
m.Log("info", "cas url: %s", cas_url)
m.Conf("login", "cas", "true")
client := cas.NewClient(&cas.Options{URL: cas_url})
handler = client.Handle(web)
} else {
@ -397,7 +397,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{
"check": true,
"sess_void": false,
"cas_url": "",
"cas_uuid": "email",
}, Help: "认证配置"},
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
@ -414,6 +413,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
},
Commands: map[string]*ctx.Command{
"init": &ctx.Command{Name: "init", Help: "post请求", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Cmd("web.spide", "cas", "client", "new", m.Conf("runtime", "boot.ctx_cas"))
m.Cmd("web.spide", "dev", "client", "new", kit.Select(m.Conf("runtime", "boot.ctx_dev"), m.Conf("runtime", "boot.ctx_box")))
return
}},
@ -613,13 +613,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
// 响应失败
if res.StatusCode != http.StatusOK {
m.Echo("%d: %s", res.StatusCode, res.Status)
return nil
}
// 响应cookie
for _, v := range res.Cookies() {
m.Magic("user", []string{"cookie", which, v.Name}, v.Value)
m.Log("info", "get-cookie %s: %v", v.Name, v.Value)
if m.Log("info", "get-cookie %s: %v", v.Name, v.Value); v.Value != "" {
m.Magic("user", []string{"cookie", which, v.Name}, v.Value)
}
}
// 解析响应
@ -970,6 +970,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}
}
m.Option("remote", "true")
// 执行命令
if order != "" || kit.Right(val["pre_run"]) {
if msg.Cmd(arg); m.Options("bench") {

View File

@ -169,6 +169,9 @@ func Format(arg ...interface{}) string {
}
return strings.Join(result, "")
}
func Simple(str string) string {
return strings.Replace(strings.TrimSpace(str), "\n", "\\n", -1)
}
func Formats(arg ...interface{}) string {
result := []string{}
for _, v := range arg {