feat: support auto check upgrade (#53)

This commit is contained in:
Li4n0
2022-01-09 23:51:46 +08:00
committed by GitHub
parent 30f9069e45
commit f6afe0fa12
16 changed files with 216 additions and 32 deletions
+1
View File
@@ -13,6 +13,7 @@ database: revsuit.db # Database connection information, support
# database: "postgres://host=127.0.0.1 user=root password=password dbname=revsuit port=5432 sslmode=disable TimeZone=Asia/Shanghai"
log_level: info # Output log levels, divided into: debug, info, warning, error, fatal
check_upgrade: true # Whether to automatically check for updates
ip_location_database: # IP database related configuration
database: "qqwry" # qqwry or geoip.
+1
View File
@@ -12,6 +12,7 @@ database: revsuit.db # 数据库连接信息 支持Sqlite3、My
# database: "postgres://host=127.0.0.1 user=root password=password dbname=revsuit port=5432 sslmode=disable TimeZone=Asia/Shanghai"
log_level: info # 输出日志的级别,分为:debug、info、warning、error、fatal
check_upgrade: false # 是否自动检查更新
ip_location_database: # IP 数据库相关配置
database: "qqwry" # qqwry 或者 geoip.
+14 -15
View File
@@ -19,7 +19,7 @@
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/cli-service": "^4.5.11",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
@@ -4810,8 +4810,7 @@
"node_modules/de-indent": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/de-indent/download/de-indent-1.0.2.tgz",
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
"dev": true
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0="
},
"node_modules/debug": {
"version": "4.3.1",
@@ -6899,7 +6898,6 @@
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/he/download/he-1.2.0.tgz",
"integrity": "sha1-hK5l+n6vsWX922FWauFLrwVmTw8=",
"dev": true,
"bin": {
"he": "bin/he"
}
@@ -13521,7 +13519,6 @@
"version": "2.6.12",
"resolved": "https://registry.npm.taobao.org/vue-template-compiler/download/vue-template-compiler-2.6.12.tgz",
"integrity": "sha1-lH7XGWdEyKUoXr4SM/6WBDf8xX4=",
"dev": true,
"dependencies": {
"de-indent": "^1.0.2",
"he": "^1.1.0"
@@ -16436,7 +16433,8 @@
"version": "4.5.11",
"resolved": "https://registry.npm.taobao.org/@vue/cli-plugin-vuex/download/@vue/cli-plugin-vuex-4.5.11.tgz?cache=0&sync_timestamp=1615453605559&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fcli-plugin-vuex%2Fdownload%2F%40vue%2Fcli-plugin-vuex-4.5.11.tgz",
"integrity": "sha1-9vYZvPtmyGzEU0DXMVKERjXlSL0=",
"dev": true
"dev": true,
"requires": {}
},
"@vue/cli-service": {
"version": "4.5.11",
@@ -16590,7 +16588,8 @@
"version": "1.1.2",
"resolved": "https://registry.npm.taobao.org/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz",
"integrity": "sha1-zrkktOyzucQ4ccekKaAvhCPmIas=",
"dev": true
"dev": true,
"requires": {}
},
"@vue/web-component-wrapper": {
"version": "1.3.0",
@@ -16805,7 +16804,8 @@
"version": "5.3.1",
"resolved": "https://registry.npm.taobao.org/acorn-jsx/download/acorn-jsx-5.3.1.tgz",
"integrity": "sha1-/IZh4Rt6wVOcR9v+oucrOvNNJns=",
"dev": true
"dev": true,
"requires": {}
},
"acorn-walk": {
"version": "7.2.0",
@@ -16853,13 +16853,15 @@
"version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/ajv-errors/download/ajv-errors-1.0.1.tgz?cache=0&sync_timestamp=1615411237786&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-errors%2Fdownload%2Fajv-errors-1.0.1.tgz",
"integrity": "sha1-81mGrOuRr63sQQL72FAUlQzvpk0=",
"dev": true
"dev": true,
"requires": {}
},
"ajv-keywords": {
"version": "3.5.2",
"resolved": "https://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-3.5.2.tgz?cache=0&sync_timestamp=1615647295573&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-keywords%2Fdownload%2Fajv-keywords-3.5.2.tgz",
"integrity": "sha1-MfKdpatuANHC0yms97WSlhTVAU0=",
"dev": true
"dev": true,
"requires": {}
},
"alphanum-sort": {
"version": "1.0.2",
@@ -18899,8 +18901,7 @@
"de-indent": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/de-indent/download/de-indent-1.0.2.tgz",
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
"dev": true
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0="
},
"debug": {
"version": "4.3.1",
@@ -20633,8 +20634,7 @@
"he": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/he/download/he-1.2.0.tgz",
"integrity": "sha1-hK5l+n6vsWX922FWauFLrwVmTw8=",
"dev": true
"integrity": "sha1-hK5l+n6vsWX922FWauFLrwVmTw8="
},
"hex-color-regex": {
"version": "1.1.0",
@@ -26188,7 +26188,6 @@
"version": "2.6.12",
"resolved": "https://registry.npm.taobao.org/vue-template-compiler/download/vue-template-compiler-2.6.12.tgz",
"integrity": "sha1-lH7XGWdEyKUoXr4SM/6WBDf8xX4=",
"dev": true,
"requires": {
"de-indent": "^1.0.2",
"he": "^1.1.0"
+1 -1
View File
@@ -19,7 +19,7 @@
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/cli-service": "^4.5.11",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
+23 -8
View File
@@ -22,7 +22,7 @@
<router-link to="/logs/rmi">RMI Logs</router-link>
</a-menu-item>
<a-menu-item key="/logs/ldap">
<router-link to="/logs/ldap">Ldap Logs</router-link>
<router-link to="/logs/ldap">LDAP Logs</router-link>
</a-menu-item>
<a-menu-item key="/logs/mysql">
<router-link to="/logs/mysql">MySQL Logs</router-link>
@@ -43,7 +43,7 @@
<router-link to="/rules/rmi">RMI Rules</router-link>
</a-menu-item>
<a-menu-item key="/rules/ldap">
<router-link to="/rules/ldap">Ldap Rules</router-link>
<router-link to="/rules/ldap">LDAP Rules</router-link>
</a-menu-item>
<a-menu-item key="/rules/mysql">
<router-link to="/rules/mysql">MySQL Rules</router-link>
@@ -118,10 +118,17 @@
</transition>
</a-layout-content>
<div class="copyright">
<p class="">
RevSuit Current Version: {{ this.version }} &copy;2021 <a href="https://github.com/Li4n0">Li4n0</a>. <a
<p v-if="!this.upgrade.upgradeable">
RevSuit Current Version: {{ this.version }}&copy; 2021 <a href="https://github.com/Li4n0">Li4n0</a><a
href="https://github.com/Li4n0/revsuit">GitHub</a>
</p>
<p v-else>
RevSuit {{ this.version }}(Upgrade Available: <a
target="_blank"
:href="this.upgrade.release">v{{ this.upgrade.version }}</a>)&copy; 2021 <a
href="https://github.com/Li4n0">Li4n0</a><a href="https://github.com/Li4n0/revsuit">GitHub</a>
</p>
</div>
</a-layout>
<Auth></Auth>
@@ -130,7 +137,7 @@
<script>
import Auth from '@/components/Auth'
import RuleIcon from "@/components/Icon";
import {getVersion} from "@/api/auth";
import {getVersion, getUpgrade} from "@/api/version";
import {store} from "@/main";
@@ -146,6 +153,7 @@ export default {
showLogNum: false,
openKeys: [],
version: "",
upgrade: {},
};
},
computed: {
@@ -162,11 +170,16 @@ export default {
this.$refs.content.fetch()
}, this.refreshInterval * 1000)
},
GetVersion() {
_getVersion() {
getVersion().then(res => {
this.version = res.data.result
})
},
_getUpgrade() {
getUpgrade().then(res => {
this.upgrade = res.data.result
})
},
deleteLogs() {
this.$refs.content.delete()
},
@@ -180,7 +193,8 @@ export default {
if (localStorage.getItem("autoRefresh") === null) {
this.autoRefresh = true;
}
this.GetVersion()
this._getVersion()
this._getUpgrade()
},
created() {
let unwatch = this.$watch('$route', function (to, from) {
@@ -224,7 +238,8 @@ export default {
'store.authed'(val) {
if (val) {
this.$refs.content.fetch()
this.GetVersion()
this._getVersion()
this._getUpgrade()
}
},
'store.pageSize'() {
-7
View File
@@ -7,10 +7,3 @@ export function auth(token) {
headers: {"Token": token},
})
}
export function getVersion() {
return request({
url: '/version',
method: 'get',
})
}
+15
View File
@@ -0,0 +1,15 @@
import request from "@/api/index";
export function getVersion() {
return request({
url: '/version',
method: 'get',
})
}
export function getUpgrade() {
return request({
url: '/getUpgrade',
method: 'get',
})
}
+2
View File
@@ -4,6 +4,7 @@ go 1.16
require (
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/fatih/color v1.10.0 // indirect
github.com/gabriel-vasile/mimetype v1.2.0
github.com/gin-gonic/gin v1.7.2
@@ -18,6 +19,7 @@ require (
github.com/oschwald/geoip2-golang v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sinlov/qqwry-golang v0.0.0-20191204062238-bea9868bbbf4
github.com/stretchr/testify v1.7.0
+20
View File
@@ -75,6 +75,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/buger/jsonparser v0.0.0-20200322175846-f7e751efca13/go.mod h1:tgcrVJ81GPSF0mz+0nu1Xaz0fazGPrmmJfJtxjbHhUQ=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -254,6 +255,9 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v27 v27.0.4/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0=
github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo=
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -328,6 +332,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428/go.mod h1:uhpZMVGznybq1itEKXj6RYw9I71qK4kH+OGMjRC4KEo=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
@@ -499,7 +505,9 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02/go.mod h1:JNdpVEzCpXBgIiv4ds+TzhN1hrtxq6ClLrTlT9OQRSc=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
@@ -552,6 +560,8 @@ github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqn
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rhysd/go-github-selfupdate v1.2.3 h1:iaa+J202f+Nc+A8zi75uccC8Wg3omaM7HDeimXA22Ag=
github.com/rhysd/go-github-selfupdate v1.2.3/go.mod h1:mp/N8zj6jFfBQy/XMYoWsmfzxazpPAODuqarmPDe2Rg=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
@@ -613,6 +623,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tchap/go-patricia v0.0.0-20160729071656-dd168db6051b/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw=
github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE=
github.com/tebeka/selenium v0.9.9/go.mod h1:5Fr8+pUvU6B1OiPfkdCKdXZyr5znvVkxuPd0NOdZCQc=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
@@ -629,6 +641,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ=
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
@@ -678,6 +692,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
@@ -735,7 +750,9 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -795,6 +812,7 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
@@ -853,8 +871,10 @@ google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEn
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
+14
View File
@@ -42,6 +42,15 @@ func Start() {
Usage: "load configuration from FILE (default: config.yaml)",
},
},
Commands: []*cli.Command{
{
Name: "upgrade",
Action: func(c *cli.Context) error {
checkUpdateFromCli()
return nil
},
},
},
Action: func(c *cli.Context) error {
var configFile = "config.yaml"
if c.Path("config") != "" {
@@ -81,6 +90,11 @@ func Start() {
if c.String("log") != "" {
conf.LogLevel = c.String("log")
}
if conf.CheckUpgrade {
checkUpdateFromCli()
}
server.New(conf).Run()
return nil
},
+1
View File
@@ -6,6 +6,7 @@ external_ip: # You need to make sure that your target can
admin_path_prefix: "/revsuit"
database: revsuit.db
log_level: info
check_upgrade: true
ip_location_database:
database: "qqwry" # qqwry or geoip.
+56
View File
@@ -0,0 +1,56 @@
package cli
import (
"fmt"
"os"
"strings"
"github.com/li4n0/revsuit/internal/update"
"github.com/li4n0/revsuit/pkg/server"
"github.com/pkg/errors"
"github.com/rhysd/go-github-selfupdate/selfupdate"
log "unknwon.dev/clog/v2"
)
func checkUpdateFromCli() {
log.Info("Checking for updates...")
if upgradeable, release, err := update.CheckUpgrade(server.VERSION); err != nil {
log.Warn(err.Error())
} else if upgradeable {
err := updateFromCli(release)
if err != nil {
log.Warn(err.Error())
}
} else {
log.Info("The current version is the latest")
}
}
func updateFromCli(release *selfupdate.Release) error {
releaseNotes := release.ReleaseNotes
releaseNotes = strings.Replace(releaseNotes, "\n\n", "\n", -1)
releaseNotes = strings.Replace(releaseNotes, "\r\n\r\n", "\n", -1)
releaseNotes = strings.Replace(releaseNotes, "**", "", -1)
log.Info("New version detected: %s\n%s", release.URL, releaseNotes)
log.Warn("Do you want to update to v%s?[Y/n]:", release.Version)
var upgrade string
_, _ = fmt.Scanln(&upgrade)
if upgrade != "n" {
exe, err := os.Executable()
if err != nil {
log.Error("error when locate executable path, err: %v", err)
}
assetURL := "https://upgrade.revsuit.pro" + strings.TrimPrefix(release.AssetURL, "https://github.com/Li4n0/revsuit/releases") + "?from=" + server.VERSION
log.Info("Downloading from %s", assetURL)
if err := selfupdate.UpdateTo(assetURL, exe); err != nil {
return errors.Wrap(err, "error when download asset")
}
log.Info("Successfully updated to v%s", release.Version)
return nil
}
return nil
}
+25
View File
@@ -0,0 +1,25 @@
package update
import (
"strings"
"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/rhysd/go-github-selfupdate/selfupdate"
)
func CheckUpgrade(currentVersion string) (bool, *selfupdate.Release, error) {
latest, found, err := selfupdate.DetectLatest("Li4n0/revsuit")
if err != nil {
return false, nil, errors.Wrap(err, "error when detecting version")
}
v, err := semver.Parse(strings.TrimPrefix(currentVersion, "v"))
if err != nil {
return false, nil, errors.Wrap(err, "error when parse version")
}
if !found || latest.Version.LTE(v) {
return false, nil, nil
}
return true, latest, nil
}
+1
View File
@@ -26,6 +26,7 @@ type Config struct {
AdminPathPrefix string `yaml:"admin_path_prefix"`
Database string
LogLevel string `yaml:"log_level"`
CheckUpgrade bool `yaml:"check_upgrade"`
IpLocationDatabase ipinfo.Config `yaml:"ip_location_database"`
Notice noticeConfig
HTTP rhttp.Config
+40
View File
@@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/li4n0/revsuit/internal/recycler"
"github.com/li4n0/revsuit/internal/update"
log "unknwon.dev/clog/v2"
)
@@ -88,3 +89,42 @@ func version(c *gin.Context) {
"result": VERSION,
})
}
func (revsuit *Revsuit) getUpgrade(c *gin.Context) {
if !revsuit.config.CheckUpgrade {
c.JSON(200, gin.H{
"status": "succeed",
"error": nil,
"result": gin.H{
"upgradeable": false,
"message": "config of check upgrade is false",
},
})
return
}
if upgradeable, release, err := update.CheckUpgrade(VERSION); err == nil && upgradeable {
c.JSON(200, gin.H{
"status": "succeed",
"error": nil,
"result": gin.H{
"upgradeable": true,
"version": release.Version,
"release": release.URL,
},
})
} else {
message := VERSION + " is the latest"
if err != nil {
message = err.Error()
}
c.JSON(200, gin.H{
"status": "succeed",
"error": nil,
"result": gin.H{
"upgradeable": false,
"message": message,
},
})
}
}
+1
View File
@@ -48,6 +48,7 @@ func (revsuit *Revsuit) registerPlatformRouter() {
api.GET("/events", revsuit.events)
api.GET("/ping", ping)
api.GET("/version", version)
api.GET("/getUpgrade", revsuit.getUpgrade)
}
func (revsuit *Revsuit) registerHttpRouter() {