mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 网站增加 IPV6 监听设置 (#1188)
This commit is contained in:
parent
4b3c9419f3
commit
a48ea497b0
@ -18,6 +18,7 @@ type WebsiteCreate struct {
|
||||
OtherDomains string `json:"otherDomains"`
|
||||
Proxy string `json:"proxy"`
|
||||
WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"`
|
||||
IPV6 bool `json:"IPV6"`
|
||||
|
||||
AppType string `json:"appType" validate:"oneof=new installed"`
|
||||
AppInstall NewAppInstall `json:"appInstall"`
|
||||
@ -51,6 +52,7 @@ type WebsiteUpdate struct {
|
||||
Remark string `json:"remark"`
|
||||
WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"`
|
||||
ExpireDate string `json:"expireDate"`
|
||||
IPV6 bool `json:"IPV6"`
|
||||
}
|
||||
|
||||
type WebsiteDelete struct {
|
||||
|
@ -19,6 +19,7 @@ type Website struct {
|
||||
ErrorLog bool `json:"errorLog"`
|
||||
AccessLog bool `json:"accessLog"`
|
||||
DefaultServer bool `json:"defaultServer"`
|
||||
IPV6 bool `json:"IPV6"`
|
||||
Rewrite string `gorm:"type:varchar" json:"rewrite"`
|
||||
|
||||
WebsiteGroupID uint `gorm:"type:integer" json:"webSiteGroupId"`
|
||||
|
@ -176,6 +176,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
|
||||
SiteDir: "/",
|
||||
AccessLog: true,
|
||||
ErrorLog: true,
|
||||
IPV6: create.IPV6,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -340,6 +341,8 @@ func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error {
|
||||
website.PrimaryDomain = req.PrimaryDomain
|
||||
website.WebsiteGroupID = req.WebsiteGroupID
|
||||
website.Remark = req.Remark
|
||||
website.IPV6 = req.IPV6
|
||||
|
||||
if req.ExpireDate != "" {
|
||||
expireDate, err := time.Parse(constant.DateLayout, req.ExpireDate)
|
||||
if err != nil {
|
||||
|
@ -190,6 +190,9 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
|
||||
for _, domain := range domains {
|
||||
serverNames = append(serverNames, domain.Domain)
|
||||
server.UpdateListen(strconv.Itoa(domain.Port), false)
|
||||
if website.IPV6 {
|
||||
server.UpdateListen("[::]:"+strconv.Itoa(domain.Port), false)
|
||||
}
|
||||
}
|
||||
server.UpdateServerName(serverNames)
|
||||
|
||||
@ -291,6 +294,9 @@ func addListenAndServerName(website model.Website, ports []int, domains []string
|
||||
server := config.FindServers()[0]
|
||||
for _, port := range ports {
|
||||
server.AddListen(strconv.Itoa(port), false)
|
||||
if website.IPV6 {
|
||||
server.UpdateListen("[::]:"+strconv.Itoa(port), false)
|
||||
}
|
||||
}
|
||||
for _, domain := range domains {
|
||||
server.AddServerName(domain)
|
||||
@ -311,6 +317,9 @@ func deleteListenAndServerName(website model.Website, binds []string, domains []
|
||||
server := config.FindServers()[0]
|
||||
for _, bind := range binds {
|
||||
server.DeleteListen(bind)
|
||||
if website.IPV6 {
|
||||
server.DeleteListen("[::]:" + bind)
|
||||
}
|
||||
}
|
||||
for _, domain := range domains {
|
||||
server.DeleteServerName(domain)
|
||||
@ -372,6 +381,9 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
|
||||
config := nginxFull.SiteConfig.Config
|
||||
server := config.FindServers()[0]
|
||||
server.UpdateListen("443", website.DefaultServer, "ssl")
|
||||
if website.IPV6 {
|
||||
server.UpdateListen("[::]:443", website.DefaultServer, "ssl")
|
||||
}
|
||||
|
||||
switch req.HttpConfig {
|
||||
case constant.HTTPSOnly:
|
||||
@ -380,10 +392,16 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
|
||||
server.RemoveDirective("if", []string{"($scheme"})
|
||||
case constant.HTTPToHTTPS:
|
||||
server.UpdateListen("80", website.DefaultServer)
|
||||
if website.IPV6 {
|
||||
server.UpdateListen("[::]:80", website.DefaultServer)
|
||||
}
|
||||
server.AddHTTP2HTTPS()
|
||||
case constant.HTTPAlso:
|
||||
server.UpdateListen("80", website.DefaultServer)
|
||||
server.RemoveDirective("if", []string{"($scheme"})
|
||||
if website.IPV6 {
|
||||
server.UpdateListen("[::]:80", website.DefaultServer)
|
||||
}
|
||||
}
|
||||
|
||||
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||
|
@ -30,6 +30,7 @@ func Init() {
|
||||
migrations.UpdateTableAppDetail,
|
||||
migrations.AddBindAndAllowIPs,
|
||||
migrations.UpdateCronjobWithSecond,
|
||||
migrations.UpdateWebsite,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
@ -367,3 +367,13 @@ var UpdateCronjobWithSecond = &gormigrate.Migration{
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateWebsite = &gormigrate.Migration{
|
||||
ID: "20200530-update-table-website",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.Website{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ export namespace Website {
|
||||
rewrite: string;
|
||||
user: string;
|
||||
group: string;
|
||||
IPV6: boolean;
|
||||
}
|
||||
|
||||
export interface WebsiteDTO extends Website {
|
||||
@ -67,6 +68,7 @@ export namespace Website {
|
||||
remark: string;
|
||||
webSiteGroupId: number;
|
||||
expireDate?: string;
|
||||
IPV6: boolean;
|
||||
}
|
||||
|
||||
export interface WebSiteOp {
|
||||
|
@ -1391,6 +1391,7 @@ const message = {
|
||||
disable: 'not enabled',
|
||||
disableLeechHelper: 'Whether to disable the anti-leech',
|
||||
disableLeech: 'Disable anti-leech',
|
||||
ipv6: 'Listen IPV6',
|
||||
},
|
||||
php: {
|
||||
short_open_tag: 'Short tag support',
|
||||
|
@ -1370,6 +1370,7 @@ const message = {
|
||||
disable: '未启用',
|
||||
disableLeechHelper: '是否禁用防盗链',
|
||||
disableLeech: '禁用防盗链',
|
||||
ipv6: '监听 IPV6 端口',
|
||||
},
|
||||
php: {
|
||||
short_open_tag: '短标签支持',
|
||||
|
@ -166,3 +166,14 @@ onMounted(() => {
|
||||
getWebsites();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tag-button {
|
||||
&.el-button--primary:hover {
|
||||
background-color: var(--el-color-primary) !important;
|
||||
}
|
||||
&.el-button--primary:focus {
|
||||
background-color: var(--el-color-primary) !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-row :gutter="20" v-loading="loading">
|
||||
<el-col :xs="24" :sm="18" :md="14" :lg="14" :xl="14">
|
||||
<el-form ref="httpsForm" label-position="left" label-width="auto" :model="form" :rules="rules">
|
||||
<el-form ref="httpsForm" label-position="right" label-width="auto" :model="form" :rules="rules">
|
||||
<el-form-item prop="enable" :label="$t('website.enableHTTPS')">
|
||||
<el-switch v-model="form.enable" @change="changeEnable"></el-switch>
|
||||
</el-form-item>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<el-row :gutter="20" v-loading="loading">
|
||||
<el-col :xs="24" :sm="18" :md="8" :lg="8" :xl="8">
|
||||
<el-form-item prop="enable" :label="$t('website.enableOrNot')">
|
||||
<el-switch v-model="enable" @change="changeEnable"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form ref="limitForm" label-position="left" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form ref="limitForm" label-position="right" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item prop="enable" :label="$t('website.enableOrNot')">
|
||||
<el-switch v-model="enable" @change="changeEnable"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('website.limit')">
|
||||
<el-select v-model="ruleKey" @change="changeRule(ruleKey)">
|
||||
<el-option :label="$t('website.current')" :value="'current'"></el-option>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-row :gutter="20" v-loading="loading">
|
||||
<el-col :xs="24" :sm="18" :md="8" :lg="8" :xl="8">
|
||||
<el-form ref="websiteForm" label-position="left" label-width="80px" :model="form" :rules="rules">
|
||||
<el-form ref="websiteForm" label-position="right" label-width="80px" :model="form" :rules="rules">
|
||||
<el-form-item :label="$t('website.primaryDomain')" prop="primaryDomain">
|
||||
<el-input v-model="form.primaryDomain" disabled></el-input>
|
||||
</el-form-item>
|
||||
@ -18,6 +18,9 @@
|
||||
<el-form-item :label="$t('website.remark')" prop="remark">
|
||||
<el-input v-model="form.remark"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="IPV6">
|
||||
<el-checkbox v-model="form.IPV6" :label="$t('website.ipv6')" size="large" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submit(websiteForm)" :disabled="loading">
|
||||
{{ $t('commons.button.save') }}
|
||||
@ -48,18 +51,19 @@ const props = defineProps({
|
||||
const websiteId = computed(() => {
|
||||
return Number(props.id);
|
||||
});
|
||||
let loading = ref(false);
|
||||
let form = reactive({
|
||||
const loading = ref(false);
|
||||
const form = reactive({
|
||||
id: websiteId.value,
|
||||
primaryDomain: '',
|
||||
remark: '',
|
||||
webSiteGroupId: 0,
|
||||
IPV6: false,
|
||||
});
|
||||
let rules = ref({
|
||||
const rules = ref({
|
||||
primaryDomain: [Rules.requiredInput],
|
||||
webSiteGroupId: [Rules.requiredSelect],
|
||||
});
|
||||
let groups = ref<Group.GroupInfo[]>([]);
|
||||
const groups = ref<Group.GroupInfo[]>([]);
|
||||
|
||||
const submit = async (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
@ -86,6 +90,7 @@ const search = async () => {
|
||||
form.primaryDomain = res.data.primaryDomain;
|
||||
form.remark = res.data.remark;
|
||||
form.webSiteGroupId = res.data.webSiteGroupId;
|
||||
form.IPV6 = res.data.IPV6;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -252,6 +252,9 @@
|
||||
:placeholder="$t('website.domainHelper')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="IPV6">
|
||||
<el-checkbox v-model="website.IPV6" :label="$t('website.ipv6')" size="large" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('website.alias')" prop="alias">
|
||||
<el-input v-model.trim="website.alias" :placeholder="$t('website.aliasHelper')"></el-input>
|
||||
<div>
|
||||
@ -338,6 +341,7 @@ const website = ref({
|
||||
containerName: '',
|
||||
allowPort: false,
|
||||
},
|
||||
IPV6: false,
|
||||
proxyType: 'tcp',
|
||||
port: 9000,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user