forked from x/ContextOS
ops some
Change-Id: I75d31caba4e19130509a6ba80e781f2c8c3bdb7b
This commit is contained in:
parent
bd27df6493
commit
55b0c02e25
@ -1,6 +1,6 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
export ctx_dev=${ctx_dev:="https://shylinux.com"}
|
export ctx_dev=${ctx_dev:="-"}
|
||||||
export ctx_root="/usr/local/context"
|
export ctx_root="/usr/local/context"
|
||||||
export ctx_home=~/context
|
export ctx_home=~/context
|
||||||
export ctx_bin="bench"
|
export ctx_bin="bench"
|
||||||
@ -48,17 +48,19 @@ action() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
while true; do
|
while true; do
|
||||||
|
cp -r var/log var/log_$(date +%Y%m%d_%H%M%S)
|
||||||
$ctx_bin "$@" 2>var/log/boot.log && break
|
$ctx_bin "$@" 2>var/log/boot.log && break
|
||||||
log "restarting..." && sleep 3
|
log "restarting..." && sleep 3
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
dir=$ctx_root
|
dir=$ctx_root
|
||||||
|
dir=./
|
||||||
[ -d "$1" ] && dir=$1 && shift
|
[ -d "$1" ] && dir=$1 && shift
|
||||||
[ -d "$dir" ] && cd $dir
|
[ -d "$dir" ] && cd $dir
|
||||||
[ -f bin/bench ] && ctx_bin=bin/bench
|
[ -f bin/bench ] && ctx_bin=bin/bench
|
||||||
pid=`cat var/run/bench.pid`
|
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
|
case $1 in
|
||||||
install) shift; prepare && install "$@";;
|
install) shift; prepare && install "$@";;
|
||||||
|
@ -99,7 +99,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"runtime": &ctx.Config{Name: "runtime", Value: map[string]interface{}{
|
"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"},
|
"boot": map[string]interface{}{"web_port": ":9094", "ssh_port": ":9090"},
|
||||||
}, Help: "运行环境"},
|
}, Help: "运行环境"},
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
|
|
||||||
// 运行命令
|
// 运行命令
|
||||||
if e := cmd.Run(); e != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
text := strings.Join(arg, " ")
|
text := strings.Join(arg, " ")
|
||||||
if !strings.HasPrefix(text, "sess") {
|
if !strings.HasPrefix(text, "sess") && m.Options("remote") {
|
||||||
text = m.Current(text)
|
text = m.Current(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,6 +832,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
}
|
}
|
||||||
return
|
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
|
all := false
|
||||||
if len(arg) > 0 && arg[0] == "all" {
|
if len(arg) > 0 && arg[0] == "all" {
|
||||||
|
@ -1488,7 +1488,11 @@ func (m *Message) Cmdy(args ...interface{}) *Message {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Cmdx(args ...interface{}) string {
|
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 {
|
func (m *Message) Cmds(args ...interface{}) bool {
|
||||||
return m.Cmd(args...).Results(0)
|
return m.Cmd(args...).Results(0)
|
||||||
|
@ -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)) {
|
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.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
|
||||||
m.Log("warning", "node error")
|
m.Log("warning", "node error")
|
||||||
|
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "node", "delete")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -348,7 +349,11 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
if m.Options("remote_code") {
|
if m.Options("remote_code") {
|
||||||
m.Log("info", "username %s", m.Option("user.name"))
|
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"))
|
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"))
|
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"))
|
m.Echo("no right of %s", m.Option("text.route"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
m.Log("info", "skip verify user of node %s", m.Option("node.route"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建会话
|
// 创建会话
|
||||||
|
@ -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")) {
|
if msg.Confs("skip_login", msg.Option("path")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if msg.Confs("login", "cas_url") && !msg.Confs("login", "skip_cas") {
|
if msg.Confs("login", "cas") {
|
||||||
if !cas.IsAuthenticated(r) {
|
if !cas.IsAuthenticated(r) {
|
||||||
r.URL, _ = r.URL.Parse(r.Header.Get("index_url"))
|
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)
|
cas.RedirectToLogin(w, r)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -336,10 +336,10 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// SSO认证
|
// SSO认证
|
||||||
m.Log("info", "web: %s", m.Conf("login", "cas_url"))
|
|
||||||
var handler http.Handler
|
var handler http.Handler
|
||||||
if cas_url, e := url.Parse(m.Conf("login", "cas_url")); e == nil && m.Confs("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", m.Conf("login", "cas_url"))
|
m.Log("info", "cas url: %s", cas_url)
|
||||||
|
m.Conf("login", "cas", "true")
|
||||||
client := cas.NewClient(&cas.Options{URL: cas_url})
|
client := cas.NewClient(&cas.Options{URL: cas_url})
|
||||||
handler = client.Handle(web)
|
handler = client.Handle(web)
|
||||||
} else {
|
} else {
|
||||||
@ -397,7 +397,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{
|
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{
|
||||||
"check": true,
|
"check": true,
|
||||||
"sess_void": false,
|
"sess_void": false,
|
||||||
"cas_url": "",
|
|
||||||
"cas_uuid": "email",
|
"cas_uuid": "email",
|
||||||
}, Help: "认证配置"},
|
}, Help: "认证配置"},
|
||||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
"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{
|
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) {
|
"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")))
|
m.Cmd("web.spide", "dev", "client", "new", kit.Select(m.Conf("runtime", "boot.ctx_dev"), m.Conf("runtime", "boot.ctx_box")))
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
@ -613,13 +613,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
// 响应失败
|
// 响应失败
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
m.Echo("%d: %s", res.StatusCode, res.Status)
|
m.Echo("%d: %s", res.StatusCode, res.Status)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 响应cookie
|
// 响应cookie
|
||||||
for _, v := range res.Cookies() {
|
for _, v := range res.Cookies() {
|
||||||
m.Magic("user", []string{"cookie", which, v.Name}, v.Value)
|
if m.Log("info", "get-cookie %s: %v", v.Name, v.Value); v.Value != "" {
|
||||||
m.Log("info", "get-cookie %s: %v", v.Name, 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 order != "" || kit.Right(val["pre_run"]) {
|
||||||
if msg.Cmd(arg); m.Options("bench") {
|
if msg.Cmd(arg); m.Options("bench") {
|
||||||
|
@ -169,6 +169,9 @@ func Format(arg ...interface{}) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(result, "")
|
return strings.Join(result, "")
|
||||||
}
|
}
|
||||||
|
func Simple(str string) string {
|
||||||
|
return strings.Replace(strings.TrimSpace(str), "\n", "\\n", -1)
|
||||||
|
}
|
||||||
func Formats(arg ...interface{}) string {
|
func Formats(arg ...interface{}) string {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
for _, v := range arg {
|
for _, v := range arg {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user