mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-01 03:24:14 +08:00
feat: Modified the logic for AI Tool (#7894)
This commit is contained in:
parent
10a7fb3be2
commit
e492c6573c
@ -14,8 +14,8 @@ type OllamaBindDomain struct {
|
|||||||
Domain string `json:"domain" validate:"required"`
|
Domain string `json:"domain" validate:"required"`
|
||||||
AppInstallID uint `json:"appInstallID" validate:"required"`
|
AppInstallID uint `json:"appInstallID" validate:"required"`
|
||||||
SSLID uint `json:"sslID"`
|
SSLID uint `json:"sslID"`
|
||||||
AllowIPs []string `json:"allowIPs"`
|
|
||||||
WebsiteID uint `json:"websiteID"`
|
WebsiteID uint `json:"websiteID"`
|
||||||
|
IPList string `json:"ipList"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OllamaBindDomainReq struct {
|
type OllamaBindDomainReq struct {
|
||||||
|
@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -203,6 +204,16 @@ func (u *AIToolService) BindDomain(req dto.OllamaBindDomain) error {
|
|||||||
if nginxInstall.ID == 0 {
|
if nginxInstall.ID == 0 {
|
||||||
return buserr.New("ErrOpenrestyInstall")
|
return buserr.New("ErrOpenrestyInstall")
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
|
ipList []string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if len(req.IPList) > 0 {
|
||||||
|
ipList, err = common.HandleIPList(req.IPList)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
createWebsiteReq := request.WebsiteCreate{
|
createWebsiteReq := request.WebsiteCreate{
|
||||||
PrimaryDomain: req.Domain,
|
PrimaryDomain: req.Domain,
|
||||||
Alias: strings.ToLower(req.Domain),
|
Alias: strings.ToLower(req.Domain),
|
||||||
@ -218,9 +229,11 @@ func (u *AIToolService) BindDomain(req dto.OllamaBindDomain) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = ConfigAllowIPs(req.AllowIPs, website); err != nil {
|
if len(ipList) > 0 {
|
||||||
|
if err = ConfigAllowIPs(ipList, website); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if req.SSLID > 0 {
|
if req.SSLID > 0 {
|
||||||
sslReq := request.WebsiteHTTPSOp{
|
sslReq := request.WebsiteHTTPSOp{
|
||||||
WebsiteID: website.ID,
|
WebsiteID: website.ID,
|
||||||
@ -263,12 +276,22 @@ func (u *AIToolService) UpdateBindDomain(req dto.OllamaBindDomain) error {
|
|||||||
if nginxInstall.ID == 0 {
|
if nginxInstall.ID == 0 {
|
||||||
return buserr.New("ErrOpenrestyInstall")
|
return buserr.New("ErrOpenrestyInstall")
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
|
ipList []string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if len(req.IPList) > 0 {
|
||||||
|
ipList, err = common.HandleIPList(req.IPList)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
websiteService := NewIWebsiteService()
|
websiteService := NewIWebsiteService()
|
||||||
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
|
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = ConfigAllowIPs(req.AllowIPs, website); err != nil {
|
if err = ConfigAllowIPs(ipList, website); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req.SSLID > 0 {
|
if req.SSLID > 0 {
|
||||||
|
@ -3,6 +3,7 @@ package common
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
mathRand "math/rand"
|
mathRand "math/rand"
|
||||||
@ -351,3 +352,22 @@ func GetLang(c *gin.Context) string {
|
|||||||
}
|
}
|
||||||
return lang
|
return lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleIPList(content string) ([]string, error) {
|
||||||
|
ipList := strings.Split(content, "\n")
|
||||||
|
var res []string
|
||||||
|
for _, ip := range ipList {
|
||||||
|
if ip == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if net.ParseIP(ip) != nil {
|
||||||
|
res = append(res, ip)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, _, err := net.ParseCIDR(ip); err != nil {
|
||||||
|
return nil, buserr.New("ErrParseIP")
|
||||||
|
}
|
||||||
|
res = append(res, ip)
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
@ -83,7 +83,7 @@ export namespace AI {
|
|||||||
export interface BindDomain {
|
export interface BindDomain {
|
||||||
domain: string;
|
domain: string;
|
||||||
sslID: number;
|
sslID: number;
|
||||||
allowIPs: string[];
|
ipList: string;
|
||||||
appInstallID: number;
|
appInstallID: number;
|
||||||
websiteID?: number;
|
websiteID?: number;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
:rows="3"
|
:rows="3"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
clearable
|
clearable
|
||||||
v-model.trim="req.ipList"
|
v-model="req.ipList"
|
||||||
:placeholder="$t('xpack.waf.ipGroupHelper')"
|
:placeholder="$t('xpack.waf.ipGroupHelper')"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -128,7 +128,7 @@ const req = ref({
|
|||||||
websiteID: 0,
|
websiteID: 0,
|
||||||
});
|
});
|
||||||
const rules = reactive<FormRules>({
|
const rules = reactive<FormRules>({
|
||||||
domain: [Rules.requiredInput],
|
domain: [Rules.domainWithPort],
|
||||||
});
|
});
|
||||||
const emit = defineEmits(['search']);
|
const emit = defineEmits(['search']);
|
||||||
|
|
||||||
@ -196,7 +196,6 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(async (valid) => {
|
formEl.validate(async (valid) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
req.value.allowIPs = req.value.ipList.split('\n');
|
|
||||||
if (operate.value === 'update') {
|
if (operate.value === 'update') {
|
||||||
await updateBindDomain(req.value);
|
await updateBindDomain(req.value);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user