Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vzex committed May 26, 2016
1 parent 3e07769 commit fd34e3c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
19 changes: 19 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import "github.com/yuin/gopher-lua"
import "os/exec"
import "net"
import "encoding/base64"
import "bufio"
import "time"
import "strings"
Expand All @@ -20,6 +21,15 @@ func InitCommon(l *lua.LState, sessionQuitC chan bool) {
RegLuaFuncWithCancel(l, "cmd", cmd, sessionQuitC)
RegLuaFuncWithCancel(l, "bash", bash, sessionQuitC)
RegLuaFuncWithCancel(l, "connect", connect, sessionQuitC)
RegLuaFuncWithCancel(l, "base64", func(l *lua.LState, quit chan bool) int {
l.Push(lua.LString(base64.StdEncoding.EncodeToString([]byte(l.CheckString(1)))))
return 1
}, sessionQuitC)
RegLuaFuncWithCancel(l, "from64", func(l *lua.LState, quit chan bool) int {
s, _ := base64.StdEncoding.DecodeString(l.CheckString(1))
l.Push(lua.LString(s))
return 1
}, sessionQuitC)
}

func connect(l *lua.LState, sessionQuitC chan bool) int {
Expand All @@ -45,6 +55,15 @@ func connect(l *lua.LState, sessionQuitC chan bool) int {
}
return 0
}
go func() {
for {
select {
case <- sessionQuitC:
conn.Close()
return
}
}
}()
newf:=l.NewFunction(f)
l.Push(newf)
l.Push(lua.LString("connected"))
Expand Down
25 changes: 1 addition & 24 deletions logic/group1/button1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,13 @@ if bInit then
return {name="测试1"}
end
if not Single() then return end
--single() check lock, is locked quit
--remote_cmd("ls -l", function(status, recv)
-- print(status, recv)
--end)
--server_upload("/tmp/a.txt", "/home/pangu/a.txt")
--server_download("/home/pangu/a.txt", "/tmp/a.txt")
--
--local_server_download("/tmp/a.txt")
--local_remote_download("/tmp/a.txt", targetNick)
--local_remote_upload("/tmp/a.txt", targetNick) arg1 is target file.this will choose a file from broswer
--local_server_upload("/tmp/a.txt", targetNick)
--local_getinput("ok?")
--local_confirm("ok?")
--local_output("ssss")
--
--global_setmap(key, value)
--global_setmap_ifeq(key, value, old)
--global_getmap(key)
--
--dieafter(10)
--try_dialtimeout(ip+port, 10)
--sleep(10)
--

remote_cmd("sleep 2", function() end)
local endStr = remote_cmd("ls -r", function(aa)
local tbl = MsgPack.unpack(aa)
for a,b in pairs(tbl) do
if type(b) == "string" then
local_msg(b)
local_msg(from64(b))
end
end
end)
Expand Down
2 changes: 1 addition & 1 deletion logic/group1/button2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local endStr = remote_bash("ls -r|wc -l", function(aa)
local tbl = MsgPack.unpack(aa)
for a,b in pairs(tbl) do
if type(b) == "string" then
local_msg(b)
local_msg(from64(b))
end
end
end)
Expand Down
10 changes: 5 additions & 5 deletions logic/internal/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ local m = require "logic/internal/pack"
json = require "logic/internal/json"
-- SendToRemote(str, timeoutsec, callback(data))
function remote_cmd(cmd, callback, timeout)
return SendToRemote(MsgPack.pack({Action="cmd", Cmd=cmd}), timeout or 10, callback)
return SendToRemote(MsgPack.pack({Action="cmd", Cmd=base64(cmd)}), timeout or 10, callback)
end
function remote_bash(cmd, callback, timeout)
return SendToRemote(MsgPack.pack({Action="bash", Cmd=cmd}), timeout or 10, callback)
return SendToRemote(MsgPack.pack({Action="bash", Cmd=base64(cmd)}), timeout or 10, callback)
end
function local_msg(msg)
return SendToLocal(json.encode({Action="msg", Msg=msg}))
return SendToLocal(json.encode({Action="msg", Msg=base64(msg)}))
end
function local_dialog(msg)
return SendToLocal(json.encode({Action="dialog", Msg=msg}))
return SendToLocal(json.encode({Action="dialog", Msg=base64(msg)}))
end
function remote_print(msg)
return SendToRemote(MsgPack.pack({Action="print", Cmd=msg}), timeout or 10, callback)
return SendToRemote(MsgPack.pack({Action="print", Cmd=base64(msg)}), timeout or 10, callback)
end
return m
10 changes: 5 additions & 5 deletions logic_remote/internal/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
local m = require "logic_remote/internal/pack"
function handle_cmd(info)
local commond = info.Cmd
local commond = from64(info.Cmd)
local s, ok = cmd(commond)
SendBack(MsgPack.pack({str=s, ok = ok}))
SendBack(MsgPack.pack({str=base64(s), ok = ok}))
end
function handle_bash(info)
local commond = info.Cmd
local commond = from64(info.Cmd)
local s, ok = bash(commond)
SendBack(MsgPack.pack({str=s, ok = ok}))
SendBack(MsgPack.pack({str=base64(s), ok = ok}))
end
function handle_print(info)
print(info.Cmd)
print(from64(info.Cmd))
end
return m
5 changes: 3 additions & 2 deletions server/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func WSWrite(conn *websocket.Conn, head, b []byte) {
copy(c[6:6+len(head)], head)
copy(c[6+len(head):], b)
websocket.Message.Send(conn, c)
//a:=int(c[0])+int(c[1]>>8)
//g:=int(c[2])+int(c[3]>>8)+int(c[4]>>16)+int(c[5]>>24)
// a:=int(c[0])+int(c[1]>>8)
// g:=int(c[2])+int(c[3]>>8)+int(c[4]>>16)+int(c[5]>>24)


//log.Println("write", len(c), a, g, len(head), len(b))
Expand Down Expand Up @@ -420,6 +420,7 @@ func ServerDownFromRemote(requestid, sessionid int, sessionQuit chan bool, ma *M
l.Push(l.Get(3))
if info.head == "" {
er:=ioutil.WriteFile(to, []byte(info.msg), 0777)
log.Println("writefile", len(info.msg), to)
if er != nil {
l.Push(lua.LString(er.Error()))
} else {
Expand Down
8 changes: 4 additions & 4 deletions website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
}
if (_content.byteLength == 0) return [];
var view = new Uint8Array(_content);
var l1 = view[0] + (view[1] >> 8);
var l2 = view[2] + (view[3] >> 8) + (view[4] >> 16) + (view[5] >> 24);
var l1 = view[0] + Math.pow(2, 8)*view[1];
var l2 = view[2] + Math.pow(2, 8)*view[3] + Math.pow(2, 16)*view[4] + Math.pow(2, 24)*view[5];
var l = l1 + l2 + 6;
//console.log(l1+"s"+l2);
if (_content.length < l) {
Expand Down Expand Up @@ -339,7 +339,7 @@

switch(obj.Action) {
case "dialog": $.confirm({
body: obj.Msg
body: atob(obj.Msg)
,width: 'normal'
,backdrop: true
,bgcolor: 'none'
Expand All @@ -352,7 +352,7 @@
})
break;
case "msg":
appendlog(obj.Msg);
appendlog(atob(obj.Msg));
break;
}

Expand Down

0 comments on commit fd34e3c

Please sign in to comment.