1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-28 02:02:02 +08:00

opt web.share.proxy

This commit is contained in:
shylinux 2020-08-24 17:50:38 +08:00
parent 96ad7ec058
commit a5cab33b8f
8 changed files with 58 additions and 22 deletions

View File

@ -35,9 +35,9 @@ func _sess_check(m *ice.Message, sessid string) {
}
}
m.Log_AUTH(
USERROLE, m.Option(ice.MSG_USERROLE, kit.Select(UserRole(m, value[USERNAME]))),
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
USERROLE, m.Option(ice.MSG_USERROLE, kit.Select(UserRole(m, value[USERNAME]))),
)
})
})

View File

@ -332,13 +332,13 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
}},
DIR: {Name: "dir path=auto field... 查看:button=auto 返回 上传", Help: "目录", Action: map[string]*ice.Action{
"upload": {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy("cache", "upload"); m.Option("pod") == "" {
m.Cmdy("cache", "watch", m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
return
if len(arg) > 0 {
m.Cmdy("spide", "dev", "cache", "GET", kit.MergeURL(arg[2], "path", arg[1], "name", arg[0]))
m.Option("name", arg[0])
} else {
m.Cmdy("cache", "upload")
}
m.Cmdy("space", m.Option("pod"), "spide", "dev", "save", path.Join(m.Option("path"), m.Option("name")),
kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/share/local/", m.Option("data"))))
m.Cmdy("cache", "watch", m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)

View File

@ -21,7 +21,7 @@ const LOGIN = "_login"
func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
msg.Option(ice.MSG_USERNAME, "")
msg.Option(ice.MSG_USERROLE, "")
msg.Option(ice.MSG_USERROLE, "void")
if msg.Options(ice.MSG_SESSID) {
// 会话认证
@ -82,6 +82,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
}
// 用户请求
msg.Option(ice.MSG_METHOD, r.Method)
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, "meta.domain"), r.Header.Get("Referer")))
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
@ -118,6 +119,9 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
// 请求参数
for k, v := range r.Form {
for i, p := range v {
v[i], _ = url.QueryUnescape(p)
}
if msg.Optionv(k, v); k == ice.MSG_SESSID {
msg.Render(COOKIE, v[0])
}

View File

@ -9,6 +9,7 @@ import (
kit "github.com/shylinux/toolkits"
"fmt"
"net/http"
"os"
"path"
"strings"
@ -69,32 +70,45 @@ func _share_repos(m *ice.Message, repos string, arg ...string) {
}
func _share_local(m *ice.Message, arg ...string) {
p := path.Join(arg...)
switch ls := strings.Split(p, "/"); ls[0] {
case "etc", "var":
// 私有文件
m.Render(STATUS, http.StatusUnauthorized, "not auth")
return
default:
if m.Warn(!m.Right(ls), ice.ErrNotAuth, m.Option(ice.MSG_USERROLE), " of ", p) {
m.Render(STATUS, http.StatusUnauthorized, "not auth")
return
}
}
if m.Option("pod") != "" {
// 远程文件
pp := path.Join("var/proxy", m.Option("pod"), p)
cache := time.Now().Add(-time.Hour * 240000)
if s, e := os.Stat(pp); e == nil {
cache = s.ModTime()
}
m.Cmdy(SPACE, m.Option("pod"), SPIDE, "dev", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
m.Cmdy(SPACE, m.Option("pod"), SPIDE, "dev", "raw", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
"part", "pod", m.Option("pod"), "path", p, "cache", cache.Format(ice.MOD_TIME), "upload", "@"+p)
m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", m.Option("pod"), p))
return
}
switch ls := strings.Split(p, "/"); ls[0] {
case "etc", "var":
// 私有文件
return
}
// 本地文件
m.Render(ice.RENDER_DOWNLOAD, p)
}
func _share_proxy(m *ice.Message, arg ...string) {
m.Cmdy(CACHE, UPLOAD)
m.Cmdy(CACHE, WATCH, m.Option("data"), path.Join("var/proxy", m.Option("pod"), m.Option("path")))
switch m.Option(ice.MSG_METHOD) {
case http.MethodGet:
m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", path.Join(m.Option("pod"), m.Option("path"), m.Option("name"))))
case http.MethodPost:
m.Cmdy(CACHE, UPLOAD)
m.Cmdy(CACHE, WATCH, m.Option("data"), path.Join("var/proxy", m.Option("pod"), m.Option("path")))
m.Render(ice.RENDER_RESULT, m.Option("path"))
}
}
func _share_remote(m *ice.Message, pod string, arg ...string) {
m.Cmdy(SPACE, pod, "web./publish/", arg)

View File

@ -321,8 +321,10 @@ func init() {
m.Echo(m.Append(DATA))
case SPIDE_SAVE:
if f, p, e := kit.Create(save); m.Assert(e) {
io.Copy(f, res.Body)
m.Echo(p)
if n, e := io.Copy(f, res.Body); m.Assert(e) {
m.Log_EXPORT(kit.MDB_SIZE, n, kit.MDB_FILE, p)
m.Echo(p)
}
}
case SPIDE_RAW:
if b, e := ioutil.ReadAll(res.Body); m.Assert(e) {

View File

@ -42,6 +42,7 @@ const ( // MSG
MSG_RIVER = "sess.river"
MSG_STORM = "sess.storm"
MSG_ACTIVE = "sess.active"
MSG_METHOD = "sess.method"
)
const ( // CTX
CTX_STREAM = "stream"

View File

@ -1,15 +1,15 @@
package chat
import (
"strings"
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/ctx"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"path"
"strconv"
"strings"
)
func _action_share_create(m *ice.Message, name, text string, arg ...string) {
@ -145,6 +145,21 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
m.Render("status", 403, "not auth")
return
}
m.Debug("what %v", cmds)
if p := m.Option(POD); p != "" {
if len(cmds) > 1 && cmds[1] == "action" {
switch cmds[2] {
case "upload":
msg := m.Cmd(web.CACHE, web.UPLOAD)
file := path.Join("var/proxy", p, msg.Option("path"), msg.Option("name"))
m.Cmd("cache", "watch", msg.Option("data"), file)
m.Cmdy(_action_proxy(m), cmds[0], "action", "upload", msg.Append("name"), msg.Option("path"),
kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/", "pod", p))
return
}
}
}
m.Cmdy(_action_proxy(m), cmds)
}
func _action_proxy(m *ice.Message) (proxy []string) {

View File

@ -45,7 +45,7 @@ func (m *Message) Event(key string, arg ...string) *Message {
return m
}
func (m *Message) Right(arg ...interface{}) bool {
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", ErrNotAuth, strings.Join(kit.Simple(arg), "."))
return m.Option(MSG_USERROLE) == "root" || !m.Warn(m.Cmdx("aaa.role", "right", m.Option(MSG_USERROLE), kit.Keys(arg...)) != "ok", ErrNotAuth, m.Option(MSG_USERROLE), " of ", strings.Join(kit.Simple(arg), "."))
}
func (m *Message) Space(arg interface{}) []string {
if arg == nil || arg == "" || kit.Format(arg) == m.Conf("cli.runtime", "node.name") {