1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 09:14:06 +08:00

opt auto.sh

This commit is contained in:
shaoying 2019-11-08 04:00:19 +08:00
parent 1891d89c1b
commit 4b02000c3d
4 changed files with 42 additions and 22 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
if [ "$ctx_dev" = "" ] || [ "$ctx_dev" = "-" ]; then if [ "${ctx_dev}" = "" ] || [ "${ctx_dev}" = "-" ]; then
ctx_dev="http://localhost:9095" ctx_dev="http://localhost:9095"
fi fi
@ -11,26 +11,34 @@ ctx_sid=${ctx_sid:=""}
ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"} ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"}
ctx_goodbye=${ctx_goodbye:="^_^ Welcome to Context world ^_^"} ctx_goodbye=${ctx_goodbye:="^_^ Welcome to Context world ^_^"}
ShyLine() {
echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g'
}
ShyJSON() { ShyJSON() {
[ $# -eq 1 ] && echo \"`ShyLine "$1"`\" && return
echo -n "{" echo -n "{"
[ -n "$1" ] && echo -n \"$1\"\:\"$2\" && shift 2 && while [ -n "$1" ]; do while [ $# -gt 1 ]; do
echo -n \, && echo -n \"$1\"\:\"$2\" && shift 2 echo -n \"`ShyLine "$1"`\"\:\"`ShyLine "$2"`\"
shift 2 && [ $# -gt 1 ] && echo -n ","
done done
echo -n "}" echo -n "}"
} }
ShyPost() { ShyPost() {
ShyJSON "$@" pwd "$(pwd)" sid "${ctx_sid}"| xargs -d'\n' -n1 curl -s "${ctx_url}" -H "${ctx_head}" -d 2>/dev/null local data=`ShyJSON "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
curl -s "${ctx_url}" -H "${ctx_head}" -d "${data}"
} }
ShySync() { ShyWord() {
case "$1" in echo "$*"|sed -e 's/\ /%20/g' -e 's/\n/\\n/g'
"history") tail -n0 -f $HISTFILE | while true; do read line }
ShyPost arg "$line" cmd history SHELL $SHELL ShyForm() {
echo $line while [ $# -gt 1 ]; do
done;; echo -n "`ShyWord "$1"`=`ShyWord "$2"`"
"input") shift 2 && [ $# -gt 1 ] && echo -n "&"
curl -s "${ctx_url}?cmd=input&arg=$READLINE_LINE" &>/dev/null done
;; }
esac ShyGet() {
local data=`ShyForm "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
curl -s "${ctx_url}?${data}"
} }
Shy() { Shy() {
local ctx_res=`ShyPost cmd "$1" arg "$2"` local ctx_res=`ShyPost cmd "$1" arg "$2"`
@ -40,6 +48,18 @@ Shy() {
esac esac
} }
ShySync() {
case "$1" in
"history") tail -n0 -f $HISTFILE | while true; do read line
line=`ShyLine $line`
Shy history "$line"
echo $line
done;;
"input")
ShyGet arg "$READLINE_LINE" cmd "input" SHELL "$SHELL"
;;
esac
}
ShyHistory() { ShyHistory() {
case "$SHELL" in case "$SHELL" in
@ -52,12 +72,13 @@ ShyHistory() {
} }
ShyLogout() { ShyLogout() {
echo ${ctx_goodbye} echo ${ctx_goodbye}
ShyPost cmd logout Shy logout
} }
ShyLogin() { ShyLogin() {
ctx_sid=`ShyPost cmd login pid "$$" pane "${TMUX_PANE}" hostname "$(hostname)" username "${USER}"` HOST=`hostname` ctx_sid=`ShyPost cmd login pid "$$" pane "${TMUX_PANE}" hostname "${HOST}" username "${USER}"`
echo ${ctx_welcome} echo ${ctx_welcome}
echo "sid: ${ctx_sid}" echo "url: ${ctx_url}"
echo "sid: ${ctx_sid:0:6}"
echo "pid: $$" echo "pid: $$"
} }

View File

@ -471,9 +471,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Echo(err.String()) m.Echo(err.String())
return return
} }
if cmd.ProcessState.ExitCode() != 0 {
return
}
// 解析结果 // 解析结果
if format(m, out); m.Has("cmd_select") { if format(m, out); m.Has("cmd_select") {

View File

@ -155,7 +155,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
} }
// 本地用户 // 本地用户
if !msg.Options("username") && kit.IsLocalIP(msg.Option("remote_ip")) && msg.Confs("web.login", "local") { if !msg.Options("username") && kit.IsLocalIP(msg.Option("remote_ip")) && msg.Confs("web.login", "local") && !strings.HasPrefix(msg.Option("agent"), "curl") {
msg.Cmd("aaa.role", "root", "user", msg.Cmdx("ssh.work", "create")) msg.Cmd("aaa.role", "root", "user", msg.Cmdx("ssh.work", "create"))
msg.Log("info", "%s: %s", msg.Option("remote_ip"), msg.Option("username", msg.Conf("runtime", "work.name"))) msg.Log("info", "%s: %s", msg.Option("remote_ip"), msg.Option("username", msg.Conf("runtime", "work.name")))
Cookie(msg, w, r) Cookie(msg, w, r)
@ -169,6 +169,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
defer func() { defer func() {
msg.Log("time", "serve: %v", msg.Format("cost")) msg.Log("time", "serve: %v", msg.Format("cost"))
}() }()
msg.Option("agent", r.Header.Get("User-Agent"))
msg.Option("remote_addr", r.RemoteAddr) msg.Option("remote_addr", r.RemoteAddr)
msg.Option("remote_ip", r.Header.Get("remote_ip")) msg.Option("remote_ip", r.Header.Get("remote_ip"))
msg.Option("index_url", r.Header.Get("index_url")) msg.Option("index_url", r.Header.Get("index_url"))

View File

@ -46,7 +46,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"shy": Dockfile, "shy": Dockfile,
}}, }},
"git": {Name: "git", Help: "记录", Value: map[string]interface{}{ "git": {Name: "git", Help: "记录", Value: map[string]interface{}{
"alias": map[string]interface{}{"s": "status", "b": "branch"}, "alias": map[string]interface{}{"s": "status", "b": "branch"},
"config": []interface{}{map[string]interface{}{"conf": "merge.tool", "value": "vimdiff"}},
}}, }},
"vim": {Name: "vim", Help: "记录", Value: map[string]interface{}{ "vim": {Name: "vim", Help: "记录", Value: map[string]interface{}{
"opens": map[string]interface{}{}, "opens": map[string]interface{}{},