Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加系统URL,让管理员可以设置统一的网站URL,避免依赖于浏览器URL的安全问题 #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/controllers/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,26 @@ func (this *PageController) Modify() {
this.jsonError("修改文档失败!")
}

// get system url
configs, err := models.ConfigModel.GetConfigs()
if err != nil {
this.ErrorLog("获取配置信息失败: " + err.Error())
this.jsonError("获取配置出错!")
}
var system_url string
for _, config := range configs {
if len(config) == 0 {
continue
}
if config["key"] == models.ConfigKeySystemUrl {
system_url = config["value"]
}
}

// send email to follow user
if isNoticeUser == "1" {
logInfo := this.GetLogInfoByCtx()
url := fmt.Sprintf("%s:%d/document/index?document_id=%s", this.Ctx.Input.Site(), this.Ctx.Input.Port(), documentId)
url := fmt.Sprintf("%s/document/index?document_id=%s", system_url, documentId)
go func(documentId string, username string, comment string, url string) {
err := sendEmail(documentId, username, comment, url)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions app/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
ConfigKeyFulltextSearch = "fulltext_search_open"
ConfigKeyDocSearchTimer = "doc_search_timer"
ConfigKeySystemName = "system_name"
ConfigKeySystemUrl = "system_url"
)

type Config struct {
Expand Down
2 changes: 2 additions & 0 deletions app/modules/system/controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (this *ConfigController) Modify() {
fulltextSearch := strings.TrimSpace(this.GetString(models.ConfigKeyFulltextSearch, "0"))
docSearchTimer := strings.TrimSpace(this.GetString(models.ConfigKeyDocSearchTimer, "3600"))
systemName := strings.TrimSpace(this.GetString(models.ConfigKeySystemName, "Markdown Mini Wiki"))
systemUrl := strings.TrimSpace(this.GetString(models.ConfigKeySystemUrl, "http://localhost:8080"))

if sendEmailOpen == "1" {
email, err := models.EmailModel.GetUsedEmail()
Expand Down Expand Up @@ -82,6 +83,7 @@ func (this *ConfigController) Modify() {
models.ConfigKeyFulltextSearch: fulltextSearch,
models.ConfigKeyDocSearchTimer: docSearchTimer,
models.ConfigKeySystemName: systemName,
models.ConfigKeySystemUrl: systemUrl,
}
// 有修改再更新
configs, err := models.ConfigModel.GetConfigs()
Expand Down
21 changes: 20 additions & 1 deletion app/modules/system/controllers/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,33 @@ func (this *EmailController) Test() {
"is_ssl": isSsl,
}

configs, err := models.ConfigModel.GetConfigs()
if err != nil {
this.ErrorLog("获取配置信息失败: " + err.Error())
this.jsonError("获取配置出错!")
}
var system_name string
var system_url string
for _, config := range configs {
if len(config) == 0 {
continue
}
if config["key"] == models.ConfigKeySystemName {
system_name = config["value"]
}
if config["key"] == models.ConfigKeySystemUrl {
system_url = config["value"]
}
}

to := strings.Split(emails, ";")
documentValue := map[string]string{
"name": "MM-Wiki测试邮件",
"username": this.User["username"],
"update_time": fmt.Sprintf("%d", time.Now().Unix()),
"comment": "",
"document_url": "",
"content": "欢迎使用 <a href='https://github.com/phachon/mm-wiki'>MM-Wiki</a>,这是一封测试邮件,请勿回复!",
"content": fmt.Sprintf("欢迎使用 <a href='%s'>%s MM-Wiki</a>,这是一封测试邮件,请勿回复!", system_url, system_name),
}

emailTemplate := beego.BConfig.WebConfig.ViewsPath + "/system/email/template_test.html"
Expand Down
1 change: 1 addition & 0 deletions docs/databases/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ INSERT INTO `mw_config` VALUES ('5', '是否开启统一登录', 'sso_open', '',
INSERT INTO `mw_config` (name, `key`, value, create_time, update_time) VALUES ('开启全文搜索', 'fulltext_search_open', '1', unix_timestamp(now()), unix_timestamp(now()));
INSERT INTO `mw_config` (name, `key`, value, create_time, update_time) VALUES ('索引更新间隔', 'doc_search_timer', '3600', unix_timestamp(now()), unix_timestamp(now()));
INSERT INTO `mw_config` (name, `key`, value, create_time, update_time) VALUES ('系统名称', 'system_name', 'Markdown Mini Wiki', unix_timestamp(now()), unix_timestamp(now()));
INSERT INTO `mw_config` (name, `key`, value, create_time, update_time) VALUES ('系统URL', 'system_url', 'http://localhost:8080', unix_timestamp(now()), unix_timestamp(now()));
6 changes: 6 additions & 0 deletions views/system/config/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<input type="text" name="system_name" class="form-control" value="{{.configValue.system_name}}" placeholder="请输入系统名称">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span class="text-danger"> * </span>系统网址</label>
<div class="col-sm-4">
<input type="text" name="system_url" class="form-control" value="{{.configValue.system_url}}" placeholder="请输入系统网址,用于外部访问">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span class="text-danger"> * </span>主页标题</label>
<div class="col-sm-4">
Expand Down