diff --git a/back.go b/back.go index 7ca7301..78b033b 100644 --- a/back.go +++ b/back.go @@ -109,7 +109,7 @@ func HandlePost(c *gin.Context) { h["Title"] = "撰写文章 | " + Ei.BTitle } h["Path"] = c.Request.URL.Path - h["Domain"] = setting.Conf.Mode.Domain + h["Domain"] = setting.Conf.Mode.Domains[0] h["Series"] = Ei.Series var tags []T for tag, _ := range Ei.Tags { diff --git a/conf/app.yml b/conf/app.yml index 629e19d..0bb73ce 100644 --- a/conf/app.yml +++ b/conf/app.yml @@ -15,7 +15,7 @@ pingrpcs: - http://ping.baidu.com/ping/RPC2 - http://blogsearch.google.com/ping/RPC2 - http://rpc.pingomatic.com/ -# 一般配置 +# 常规配置 general: # 首页展示文章数量 pagenum: 10 @@ -57,13 +57,17 @@ kodo: secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf # 运行模式 mode: + # http server enablehttp: true httpport: 9000 - enablehttps: false - httpsport: 443 - certfile: conf/certs/domain.pem - keyfile: conf/certs/domain.key - domain: deepzz.com + # https server + enablehttps: true + autocert: true + httpsport: 9001 + certfile: conf/ssl/domain.rsa.pem + keyfile: conf/ssl/domain.rsa.key + domains: + - deepzz.com # twitter地址: twitter.com/chenqijing2 twitter: card: summary @@ -71,8 +75,7 @@ twitter: image: st.deepzz.com/static/img/avatar.jpg address: twitter.com/chenqijing2 -# 以下数据项供初始化使用,仅首次运行有效。 -# 若需要修改,请到博客后台操作。 +# 数据初始化操作,可到博客后台修改 account: # *后台登录用户名 username: deepzz diff --git a/conf/blackip.yml b/conf/blackip.yml index e69de29..05e61e2 100644 --- a/conf/blackip.yml +++ b/conf/blackip.yml @@ -0,0 +1 @@ +# like 192.168.99.100:true diff --git a/front.go b/front.go index 2ee5262..6e35bad 100644 --- a/front.go +++ b/front.go @@ -55,14 +55,15 @@ func StaticVersion(c *gin.Context) (version int) { func GetBase() gin.H { return gin.H{ - "BlogName": Ei.BlogName, - "SubTitle": Ei.SubTitle, - "Twitter": setting.Conf.Twitter, - "CopyYear": time.Now().Year(), - "BTitle": Ei.BTitle, - "BeiAn": Ei.BeiAn, - "Domain": setting.Conf.Mode.Domain, - "Kodo": setting.Conf.Kodo, + "BlogName": Ei.BlogName, + "SubTitle": Ei.SubTitle, + "Twitter": setting.Conf.Twitter, + "CopyYear": time.Now().Year(), + "BTitle": Ei.BTitle, + "BeiAn": Ei.BeiAn, + "Domain": setting.Conf.Mode.Domains[0], + "Kodo": setting.Conf.Kodo, + "ShortName": setting.Conf.Disqus.ShortName, } } diff --git a/glide.lock b/glide.lock index 608b16b..575d85e 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: bd360fa297ed66950543990f9433cdcdf13c29dd99d9a01b49027e236b2cb9da -updated: 2017-07-08T12:15:52.531289524+08:00 +updated: 2017-07-08T14:52:31.866715976+08:00 imports: - name: github.com/boj/redistore version: 4562487a4bee9a7c272b72bfaeda4917d0a47ab9 @@ -8,7 +8,7 @@ imports: - name: github.com/eiblog/blackfriday version: c0ec111761ae784fe31cc076f2fa0e2d2216d623 - name: github.com/eiblog/utils - version: ad2f63940c4f16d0dbfc3f4df59e8cb7af0f80ec + version: 5699bde749ca1053867528834492263f841620ad subpackages: - logd - mgo diff --git a/ping.go b/ping.go index 190a7ff..6de8e54 100644 --- a/ping.go +++ b/ping.go @@ -25,7 +25,7 @@ func (*superfeedr) PingFunc(slug string) { } vals := url.Values{} vals.Set("hub.mode", "publish") - vals.Add("hub.url", "https://"+setting.Conf.Mode.Domain+"/post/"+slug+".html") + vals.Add("hub.url", "https://"+setting.Conf.Mode.Domains[0]+"/post/"+slug+".html") res, err := http.PostForm(setting.Conf.FeedrURL, vals) if err != nil { logd.Error(err) @@ -64,7 +64,7 @@ func (p *pingRPC) PingFunc(slug string) { if len(setting.Conf.PingRPCs) == 0 { return } - p.Params.Param[1].Value = "https://" + setting.Conf.Mode.Domain + "/post/" + slug + ".html" + p.Params.Param[1].Value = "https://" + setting.Conf.Mode.Domains[0] + "/post/" + slug + ".html" buf := &bytes.Buffer{} buf.WriteString(xml.Header) enc := xml.NewEncoder(buf) @@ -98,9 +98,9 @@ func init() { pr := &pingRPC{MethodName: "weblogUpdates.extendedPing"} pr.Params.Param = [4]rpcValue{ 0: rpcValue{Value: Ei.BTitle}, - 1: rpcValue{Value: "https://" + setting.Conf.Mode.Domain}, + 1: rpcValue{Value: "https://" + setting.Conf.Mode.Domains[0]}, 2: rpcValue{}, - 3: rpcValue{Value: "https://" + setting.Conf.Mode.Domain + "/rss.html"}, + 3: rpcValue{Value: "https://" + setting.Conf.Mode.Domains[0] + "/rss.html"}, } Pings = append(Pings, pr) } diff --git a/ping_test.go b/ping_test.go index f4137eb..984896e 100644 --- a/ping_test.go +++ b/ping_test.go @@ -18,7 +18,7 @@ func TestPingRPC(t *testing.T) { } pr.Params.Param = [4]rpcValue{ rpcValue{Value: Ei.BTitle}, - rpcValue{Value: "https://" + setting.Conf.Mode.Domain}, + rpcValue{Value: "https://" + setting.Conf.Mode.Domains[0]}, rpcValue{Value: "https://deepzz.com/post/gdb-debug.html"}, rpcValue{Value: "https://deepzz.com/rss.html"}, } diff --git a/router.go b/router.go index 609adc6..df3b033 100644 --- a/router.go +++ b/router.go @@ -9,6 +9,7 @@ import ( "github.com/eiblog/eiblog/setting" "github.com/eiblog/utils/logd" "github.com/eiblog/utils/tmpl" + "github.com/gin-gonic/autotls" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" ) @@ -104,15 +105,27 @@ func Run() { }() } if setting.Conf.Mode.EnableHttps { - go func() { - logd.Infof("https server Running on %d\n", setting.Conf.Mode.HttpsPort) - err = router.RunTLS(fmt.Sprintf(":%d", setting.Conf.Mode.HttpsPort), setting.Conf.Mode.CertFile, setting.Conf.Mode.KeyFile) - if err != nil { - logd.Info("ListenAndServe: ", err) - time.Sleep(100 * time.Microsecond) - endRunning <- true - } - }() + if setting.Conf.Mode.AutoCert { + go func() { + logd.Info("https server Running on 443") + err = autotls.Run(router, setting.Conf.Mode.Domains...) + if err != nil { + logd.Info("ListenAndServe: ", err) + time.Sleep(100 * time.Microsecond) + endRunning <- true + } + }() + } else { + go func() { + logd.Infof("https server Running on %d\n", setting.Conf.Mode.HttpsPort) + err = router.RunTLS(fmt.Sprintf(":%d", setting.Conf.Mode.HttpsPort), setting.Conf.Mode.CertFile, setting.Conf.Mode.KeyFile) + if err != nil { + logd.Info("ListenAndServe: ", err) + time.Sleep(100 * time.Microsecond) + endRunning <- true + } + }() + } } <-endRunning } diff --git a/setting/setting.go b/setting/setting.go index 8dde068..4d2a1ec 100644 --- a/setting/setting.go +++ b/setting/setting.go @@ -9,8 +9,8 @@ import ( ) const ( - DEV = "dev" - PROD = "prod" + DEV = "dev" // 该模式会输出 debug 等信息 + PROD = "prod" // 该模式用于生产环境 ) var ( @@ -63,7 +63,8 @@ type Config struct { HttpsPort int CertFile string KeyFile string - Domain string + AutoCert bool + Domains []string } Twitter struct { // twitter信息 Card string diff --git a/views/homeLayout.html b/views/homeLayout.html index 0af980e..f1b1e95 100644 --- a/views/homeLayout.html +++ b/views/homeLayout.html @@ -1 +1 @@ -
{{.SubTitle}}
{{.SubTitle}}
本文目前还没有人评论~
')},o=function(){if(!r){r=!0;var a;a=s?"/disqus/"+n+"/"+encodeURIComponent(s):"/disqus/"+n,$.get(a,{},function(a){var n;r=!1,a&&0==a.errno?(s?l(a.data.comments):(i(a.data),l(a.data.comments),$(t).trigger("hashchange","scrollIntoView")),n=e.find(".load-more a"),a.data.next?n.removeClass("busy"):n.hide(),s=a.data.next,$(t).trigger("scroll")):e.html('获取数据失败,请稍后再试!
')})}},e.on("click",".load-more a",function(t){t.preventDefault(),$(this).addClass("busy"),o()}).on("click","a.time-ago",function(t){t.preventDefault(),location.hash="comment-"+$(this).data("id")}).on("click","a.reload",function(a){a.preventDefault(),t.TotalThread.clear(),location.hash="comments",location.reload()}).on("click","a.reply, button.create-post",function(a){var n,i,o,r,s,c,l,d,u;a.preventDefault(),n=e.data("identifier"),i=e.data("thread"),o=$(this).data("next"),r=$(this).data("id"),s=420,c=520,l=t.screen.width-s/2,d=t.screen.height-c/2,u=[n,i,r,o].join("|"),t.open("/disqus/form/"+encodeURIComponent(u)+"/","_create_post","width="+s+",height="+c+",location=1,status=1,resizable=1,scrollbars=1,left="+l+",top="+d)}),$(t).on("hashchange",function(a,n){var i,o=location.hash.match(/#comment\-(\d+)/);o&&(i=e.find("#post-"+o[1]),i.length&&(e.find(".post-content.target").removeClass("target"),i.find("> .post-content").addClass("target"),n&&$(t).scrollTop(i.offset().top-90)))}),/(iPhone|Android)/.test(navigator.userAgent)&&e.addClass("mobile"),o()};return{id:"simple_thread",check:function(t){t(0)},load:function(){e||(e=!0,n(this.elThread,this.identifier))},init:function(t,a,e){t.html("评论基础模式加载中...本文目前还没有人评论~
')},o=function(){if(!r){r=!0;var a;a=s?"/disqus/"+n+"/"+encodeURIComponent(s):"/disqus/"+n,$.get(a,{},function(a){var n;r=!1,a&&0==a.errno?(s?l(a.data.comments):(i(a.data),l(a.data.comments),$(t).trigger("hashchange","scrollIntoView")),n=e.find(".load-more a"),a.data.next?n.removeClass("busy"):n.hide(),s=a.data.next,$(t).trigger("scroll")):e.html('获取数据失败,请稍后再试!
')})}},e.on("click",".load-more a",function(t){t.preventDefault(),$(this).addClass("busy"),o()}).on("click","a.time-ago",function(t){t.preventDefault(),location.hash="comment-"+$(this).data("id")}).on("click","a.reload",function(a){a.preventDefault(),t.TotalThread.clear(),location.hash="comments",location.reload()}).on("click","a.reply, button.create-post",function(a){var n,i,o,r,s,c,l,d,u;a.preventDefault(),n=e.data("identifier"),i=e.data("thread"),o=$(this).data("next"),r=$(this).data("id"),s=420,c=520,l=t.screen.width-s/2,d=t.screen.height-c/2,u=[n,i,r,o].join("|"),t.open("/disqus/form/"+encodeURIComponent(u)+"/","_create_post","width="+s+",height="+c+",location=1,status=1,resizable=1,scrollbars=1,left="+l+",top="+d)}),$(t).on("hashchange",function(a,n){var i,o=location.hash.match(/#comment\-(\d+)/);o&&(i=e.find("#post-"+o[1]),i.length&&(e.find(".post-content.target").removeClass("target"),i.find("> .post-content").addClass("target"),n&&$(t).scrollTop(i.offset().top-90)))}),/(iPhone|Android)/.test(navigator.userAgent)&&e.addClass("mobile"),o()};return{id:"simple_thread",check:function(t){t(0)},load:function(){e||(e=!0,n(this.elThread,this.identifier))},init:function(t,a,e){t.html("评论基础模式加载中...