diff --git a/assets/etcdkeeper/framework/custom/js/common.js b/assets/etcdkeeper/framework/custom/js/common.js index 1aedeee..37a0c4e 100644 --- a/assets/etcdkeeper/framework/custom/js/common.js +++ b/assets/etcdkeeper/framework/custom/js/common.js @@ -1,10 +1,10 @@ /** - * 时间对象的格式化 + * date format */ Date.prototype.format = function(format) { /* - * format="yyyy-MM-dd hh:mm:ss"; - */ + * format="yyyy-MM-dd hh:mm:ss"; + */ var o = { "M+" : this.getMonth() + 1, "d+" : this.getDate(), @@ -17,20 +17,20 @@ Date.prototype.format = function(format) { if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "") - .substr(4 - RegExp.$1.length)); + .substr(4 - RegExp.$1.length)); } - for ( var k in o) { + for (var k in o) { if (new RegExp("(" + k + ")").test(format)) { - format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] - : ("00" + o[k]).substr(("" + o[k]).length)); + format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] + : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }; /** - * format date long to HH:ss + * format date long to HH:mm * @param dl * @returns {String} */ @@ -38,50 +38,53 @@ function getTime(dl) { var date = new Date(Number(dl)); var hour = date.getHours(); var min = date.getMinutes(); - if(hour < 10) + if (hour < 10) { hour = "0" + hour; - if(min < 10) + } + if (min < 10) { min = "0" + min; + } return hour + ":" + min; } /** - * format date long to yyyy年MM月dd日 + * format date long to yyyy-MM-dd * @param dl * @returns {String} */ function getDate(dl) { var date = new Date(Number(dl)); var year = date.getFullYear(); - var month = date.getMonth()+1; + var month = date.getMonth() + 1; var day = date.getDate(); - return year+"-"+month+"-"+day; + return year + "-" + month + "-" + day; } /** - * get date id format:yyyyMMdd - * @returns + * get date id format: yyyyMMdd + * @returns {String} */ function getDateId() { var date = new Date(); var year = date.getFullYear(); - var month = date.getMonth()+1; + var month = date.getMonth() + 1; var day = date.getDate(); - return year+month+day; + return year + month + day; } /** - * get date by custom day - * @returns yyyy-MM-dd + * get date by custom day + * @param date + * @param i + * @returns {String} yyyy-MM-dd */ -function getNextDay(date,i) { +function getNextDay(date, i) { var a = new Date(date); a = a.valueOf(); a = a + i * 24 * 60 * 60 * 1000; a = new Date(a); - //初始化时间 var year = a.getFullYear(); - var month = a.getMonth() + 1; + var month = a.getMonth() + 1; var day = a.getDate(); var currentDate = year + "-"; if (month > 9) { @@ -100,30 +103,38 @@ function getNextDay(date,i) { /** * format number to 12,345,678 * @param amount - * @returns + * @returns {String} */ function CommaFormatted(amount) { - var delimiter = ","; // replace comma if desired - amount = new String(amount); - var a = amount.split('.',2); - var d = a[1]; - var i = parseInt(a[0]); - if(isNaN(i)) { return ''; } - var minus = ''; - if(i < 0) { minus = '-'; } - i = Math.abs(i); - var n = new String(i); - var a = []; - while(n.length > 3) - { - var nn = n.substr(n.length-3); - a.unshift(nn); - n = n.substr(0,n.length-3); - } - if(n.length > 0) { a.unshift(n); } - n = a.join(delimiter); - if(d == null || d.length < 1) { amount = n; } - else { amount = n + '.' + d; } - amount = minus + amount; - return amount; -} \ No newline at end of file + var delimiter = ","; + amount = new String(amount); + var a = amount.split('.', 2); + var d = a[1]; + var i = parseInt(a[0], 10); + if (isNaN(i)) { + return ''; + } + var minus = ''; + if (i < 0) { + minus = '-'; + } + i = Math.abs(i); + var n = new String(i); + var arr = []; + while (n.length > 3) { + var nn = n.substr(n.length - 3); + arr.unshift(nn); + n = n.substr(0, n.length - 3); + } + if (n.length > 0) { + arr.unshift(n); + } + n = arr.join(delimiter); + if (d == null || d.length < 1) { + amount = n; + } else { + amount = n + '.' + d; + } + amount = minus + amount; + return amount; +} diff --git a/assets/etcdkeeper/index.html b/assets/etcdkeeper/index.html index ed03bc5..3fa5fab 100644 --- a/assets/etcdkeeper/index.html +++ b/assets/etcdkeeper/index.html @@ -7,7 +7,7 @@ - + @@ -23,789 +23,907 @@ right: 15px; bottom: 40px; left: 15px; - border:1px solid #ddd; - font-size: 13px!important; + border: 1px solid #ddd; + font-size: 13px !important; } -

ETCD Keeper v3

-
- - +

+ + ETCD Keeper + v3 +

+
+ + + Logout +
+
+
+
+
    -
    -
    -
    -
      -
      -
      -
      -
      -
      - - -
      - - -
      -
      - Mode - - -
      -
      -
      Create Node
      -
      Remove Node
      -
      -
      -
      Remove Node
      -
      - -
      -
      -
      - - - - - - - - - - - - - - - - - -
      Name:
      Dir: - -
      TTL:
      Value:
      -
      -
      - Submit -
      -
      +
      +
      - -
      -
      +
      + + +
      + + +
      +
      + Mode + + +
      +
      +
      Create Node
      +
      Remove Node
      +
      +
      +
      Remove Node
      +
      + +
      +
      +
      - - + + + + + + - - + + + + + +
      Username:Name:
      Dir: + +
      Password:TTL:
      Value:
      -
      - Submit -
      -
      -
      - -
      - - - - ETCD Keeper 0.7.8 + +
      + Submit +
      - -
      -
      text
      -
      toml
      -
      ini
      -
      yaml
      -
      xml
      -
      lua
      -
      javascript
      -
      json
      +
      + +
      +
      + + + + + + + + + + + + + +
      Username:
      Password:
      + +
      +
      + Submit +
      +
      + +
      + + + + ETCD Keeper 0.7.8 +
      + +
      +
      text
      +
      toml
      +
      ini
      +
      yaml
      +
      xml
      +
      lua
      +
      javascript
      +
      json
      +
      + +
      +
      version 3
      +
      version 2
      +
      + + + function userOK() { + $('#userinfo').window('close'); + connect(); + } + diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/src/etcdkeeper/go.mod b/src/etcdkeeper/go.mod index 1bf6ea4..6087357 100644 --- a/src/etcdkeeper/go.mod +++ b/src/etcdkeeper/go.mod @@ -1,6 +1,6 @@ module etcdkeeper -go 1.20 +go 1.21 require ( github.com/coreos/etcd v3.3.15+incompatible diff --git a/src/etcdkeeper/go.sum b/src/etcdkeeper/go.sum index b8e93dd..dcdf3e8 100644 --- a/src/etcdkeeper/go.sum +++ b/src/etcdkeeper/go.sum @@ -13,6 +13,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -33,6 +34,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk= @@ -93,6 +95,8 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/etcdkeeper/main.go b/src/etcdkeeper/main.go index a64e534..2792950 100644 --- a/src/etcdkeeper/main.go +++ b/src/etcdkeeper/main.go @@ -8,9 +8,6 @@ import ( _ "etcdkeeper/session/providers/memory" "flag" "fmt" - "github.com/coreos/etcd/pkg/transport" - "go.etcd.io/etcd/client/v2" - "go.etcd.io/etcd/client/v3" "io" "log" "net/http" @@ -21,6 +18,10 @@ import ( "strings" "sync" "time" + + "github.com/coreos/etcd/pkg/transport" + "go.etcd.io/etcd/client/v2" + "go.etcd.io/etcd/client/v3" ) var ( @@ -53,6 +54,16 @@ func main() { port := flag.Int("p", 8080, "port") flag.CommandLine.Parse(os.Args[1:]) + + if v := os.Getenv("ETCD_KEEPER_AUTH"); v != "" { + parsed, err := strconv.ParseBool(v) + if err != nil { + log.Printf("invalid ETCD_KEEPER_AUTH value %q, expected true/false; fallback to -auth=%v", v, *useAuth) + } else { + *useAuth = parsed + } + } + separator = *sep middleware := func(fns ...func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) { @@ -70,7 +81,7 @@ func main() { http.HandleFunc("/v2/put", middleware(nothing, putV2)) http.HandleFunc("/v2/get", middleware(nothing, getV2)) http.HandleFunc("/v2/delete", middleware(nothing, delV2)) - // dirctory mode + // directory mode http.HandleFunc("/v2/getpath", middleware(nothing, getPathV2)) // v3 @@ -79,7 +90,7 @@ func main() { http.HandleFunc("/v3/put", middleware(nothing, put)) http.HandleFunc("/v3/get", middleware(nothing, get)) http.HandleFunc("/v3/delete", middleware(nothing, del)) - // dirctory mode + // directory mode http.HandleFunc("/v3/getpath", middleware(nothing, getPath)) wd, err := os.Executable()