Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Dec 12, 2020
2 parents 777450a + a2f4b42 commit 858f525
Show file tree
Hide file tree
Showing 16 changed files with 1,328 additions and 1,040 deletions.
2,121 changes: 1,110 additions & 1,011 deletions assets.go

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

const (
// Version of the application
Version = "1.7.0"
Version = "1.8.0"
// DefPort is the default web-server port
DefPort = 3234
// DefTheme is the default web-server theme
Expand Down Expand Up @@ -48,12 +48,15 @@ type AppInfo struct {
Issue string
}

var VerType string
var (
VerType string
CompileDate string
)

func GetVersion() string {
ret := Version
if VerType == `beta` {
ret += `b`
}
return ret + `+1`
return ret
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/alecthomas/chroma v0.8.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gentee/gentee v1.19.0
github.com/getlantern/systray v1.1.0
github.com/gorilla/websocket v1.4.2
github.com/kataras/golog v0.1.5
github.com/labstack/echo/v4 v4.1.17
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ github.com/gentee/gentee v1.18.0 h1:VZyItV5JqkV7hmsJwH3WS5eENKyRktNzK9NWse7rbKc=
github.com/gentee/gentee v1.18.0/go.mod h1:Qyf1jQ8a/yUyPEHrl1RTHKNSTJ923lsPnghIawrdDN4=
github.com/gentee/gentee v1.19.0 h1:REr9QHbOdPhV2mSYiGgVsmtgyJUrXD4K4ouuPQp8CQ8=
github.com/gentee/gentee v1.19.0/go.mod h1:Qyf1jQ8a/yUyPEHrl1RTHKNSTJ923lsPnghIawrdDN4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
github.com/getlantern/systray v1.1.0 h1:U0wCEqseLi2ok1fE6b88gJklzriavPJixZysZPkZd/Y=
github.com/getlantern/systray v1.1.0/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/gorilla/csrf v1.6.0/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI=
Expand Down Expand Up @@ -62,6 +78,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -105,6 +123,7 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ func main() {
if install {
return
}
hideConsole()
LoadUsers()
defer CloseLog()
if err := LoadCustomAsset(cfg.AssetsDir, cfg.HTTP.Theme); err != nil {
golog.Fatal(err)
}
InitScripts()
CreateSysTray()
e = RunServer(WebSettings{
Port: cfg.HTTP.Port,
Open: cfg.HTTP.Open,
Expand Down
2 changes: 1 addition & 1 deletion make.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run {

$ /home/ak/go/bin/esc -ignore "\.git|LICENSE|README.md" -o assets.go ../eonza-assets
// $ go install -ldflags "-s -w" -tags "eonza standard"
$ go install -ldflags "-s -w -X main.VerType=%{vertype}"
$ go install -tags tray -ldflags "-s -w -X main.VerType=%{vertype} -X main.CompileDate=%{Format(`YYYY-MM-DD`,Now())}"
$ cp ${GOPATH}/bin/eonza /home/ak/app/eonza-dev/eonza
$ cp ${GOPATH}/bin/eonza /home/ak/app/eonza/eonza
$ /home/ak/app/eonza-dev/eonza
Expand Down
10 changes: 10 additions & 0 deletions notray.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2020 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

// +build !tray

package main

func CreateSysTray() {
}
11 changes: 11 additions & 0 deletions notwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

// +build !windows

package main

func hideConsole() {

}
25 changes: 16 additions & 9 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"eonza/lib"
"fmt"
"html/template"
"os"
"strings"
"time"

Expand All @@ -17,15 +18,18 @@ import (
)

type Render struct {
App AppInfo
Version string
Develop bool
Playground bool
Langs map[string]string
Lang string
Login bool
Localhost bool
PortShift int64
App AppInfo
AppPath string
Version string
CompileDate string
Title string
Develop bool
Playground bool
Langs map[string]string
Lang string
Login bool
Localhost bool
PortShift int64
// Port int
/* Params map[string]string
Url string
Expand Down Expand Up @@ -119,7 +123,10 @@ func RenderPage(c echo.Context, url string) (string, error) {
data = renderScript
} else {
render.App = appInfo
render.AppPath = strings.Join(os.Args, ` `)
render.Version = GetVersion()
render.CompileDate = CompileDate
render.Title = storage.Settings.Title
render.Develop = cfg.develop
render.Playground = cfg.playground
render.Lang = GetLangCode(c.(*Auth).User)
Expand Down
5 changes: 5 additions & 0 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
type scriptSettings struct {
Name string `json:"name" yaml:"name"`
Title string `json:"title" yaml:"title"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Desc string `json:"desc,omitempty" yaml:"desc,omitempty"`
LogLevel int `json:"loglevel" yaml:"loglevel"`
Unrun bool `json:"unrun,omitempty" yaml:"unrun,omitempty"`
Expand Down Expand Up @@ -159,6 +160,10 @@ func (script *Script) Validate() error {
if len(script.Settings.Title) == 0 {
return fmt.Errorf(Lang(DefLang, `invalidfield`), Lang(DefLang, `title`))
}
if len(script.Settings.Path) > 0 {
script.Settings.Path = strings.ReplaceAll(script.Settings.Path, "\\", "/")
script.Settings.Path = strings.Trim(script.Settings.Path, "/")
}
return nil
}

Expand Down
7 changes: 3 additions & 4 deletions script/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,15 @@ func IsCond(rt *vm.Runtime, item *ConditionItem) (err error) {
return
}
if len(item.Var) > 0 {
if varVal, err = GetVar(item.Var); err != nil {
if !strings.ContainsAny(item.Var, ` #[.`) {
return
}
if varVal, err = GetVar(item.Var); err != nil || (IsVar(item.Var) == 0 &&
strings.ContainsAny(item.Var, ` #[.`)) {
var found bool
if varVal, found = ReplaceObj(item.Var); !found {
if varVal, err = Macro(item.Var); err != nil {
return
}
}
err = nil
}
}
switch item.Cmp {
Expand Down
2 changes: 2 additions & 0 deletions scriptapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ScriptItem struct {
Name string `json:"name"`
Title string `json:"title"`
Desc string `json:"desc,omitempty"`
Path string `json:"path,omitempty"`
Help string `json:"help,omitempty"`
HelpLang string `json:"helplang,omitempty"`
Unrun bool `json:"unrun,omitempty"`
Expand Down Expand Up @@ -155,6 +156,7 @@ func ScriptToItem(c echo.Context, script *Script) ScriptItem {
Name: script.Settings.Name,
Title: es.ReplaceVars(script.Settings.Title, script.Langs[lang], glob),
Desc: es.ReplaceVars(script.Settings.Desc, script.Langs[lang], glob),
Path: es.ReplaceVars(script.Settings.Path, script.Langs[lang], glob),
Unrun: script.Settings.Unrun,
Help: script.Settings.Help,
HelpLang: script.Settings.HelpLang,
Expand Down
30 changes: 18 additions & 12 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func exitHandle(c echo.Context) error {
if cfg.playground {
return jsonError(c, `Access denied`)
}
golog.Info(`Finish`)
golog.Info(`Shutdown`)
stopchan <- os.Interrupt
return c.JSON(http.StatusOK, Response{Success: true})
}
Expand Down Expand Up @@ -261,25 +261,31 @@ func RunServer(options WebSettings) *echo.Echo {
if IsScript {
setStatus(TaskFailed, err)
}
if cfg.HTTP.Access != AccessHost && pingHost(options.Port) {
lib.Open(fmt.Sprintf("http://%s:%d", Localhost, options.Port))
}
golog.Fatal(err)
}
}()
if options.Open {
go func() {
var (
body []byte
)
url := fmt.Sprintf("http://%s:%d", Localhost, options.Port)
for string(body) != Success {
for !pingHost(options.Port) {
time.Sleep(100 * time.Millisecond)
resp, err := http.Get(url + `/ping`)
if err == nil {
body, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close()
}
}
lib.Open(url)
lib.Open(fmt.Sprintf("http://%s:%d", Localhost, options.Port))
}()
}
return e
}

func pingHost(port int) bool {
var (
body []byte
)
resp, err := http.Get(fmt.Sprintf("http://%s:%d/ping", Localhost, port))
if err == nil {
body, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close()
}
return string(body) == Success
}
2 changes: 2 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Settings struct {
Constants map[string]string `json:"constants"`
PasswordHash []byte `json:"passwordhash"`
NotAskPassword bool `json:"notaskpassword"`
Title string `json:"title"`
HideTray bool `json:"hidetray"`
}

// Storage contains all application data
Expand Down
54 changes: 54 additions & 0 deletions tray.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2020 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

// +build tray

package main

import (
"eonza/lib"
"fmt"
"os"

"github.com/getlantern/systray"
"github.com/kataras/golog"
)

func CreateSysTray() {
if storage.Settings.HideTray /*|| cfg.HTTP.Access == AccessHost*/ {
return
}
go systray.Run(TrayReady, TrayExit)
}

func TrayExit() {
}

func TrayReady() {
systray.SetIcon(WebAsset(`favicon.ico`))
title := storage.Settings.Title
if len(title) == 0 {
title = fmt.Sprintf("%s:%d", appInfo.Title, cfg.HTTP.Port)
}
systray.SetTitle(title)
systray.SetTooltip(appInfo.Title)

open := Lang(0, `openbrowser`)
mOpen := systray.AddMenuItem(open, open)
systray.AddSeparator()
shutdown := Lang(0, `shutdown`)
mQuit := systray.AddMenuItem(shutdown, shutdown)
go func() {
for {
select {
case <-mOpen.ClickedCh:
lib.Open(fmt.Sprintf("http://%s:%d", Localhost, cfg.HTTP.Port))
case <-mQuit.ClickedCh:
golog.Info(`Tray shutdown`)
stopchan <- os.Interrupt
systray.Quit()
}
}
}()
}
Loading

0 comments on commit 858f525

Please sign in to comment.