mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-10 04:16:29 +08:00
feat(website): fix issues with create website with ftp failed (#8272)
This commit is contained in:
parent
5ee392b11e
commit
c7b6e15c1d
11 changed files with 76 additions and 49 deletions
|
|
@ -264,6 +264,12 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
|
|||
}
|
||||
return syncAppInstallStatus(&install, false)
|
||||
case constant.Restart:
|
||||
if install.App.Key == "openresty" {
|
||||
websites, _ := websiteRepo.GetBy()
|
||||
if len(websites) > 0 {
|
||||
_ = createAllWebsitesWAFConfig(websites)
|
||||
}
|
||||
}
|
||||
out, err := compose.Restart(dockerComposePath)
|
||||
if err != nil {
|
||||
return handleErr(install, err, out)
|
||||
|
|
|
|||
|
|
@ -331,20 +331,25 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, oldEnv string, rebu
|
|||
if out, err := compose.Up(composePath); err != nil {
|
||||
runtime.Status = constant.StatusStartErr
|
||||
runtime.Message = out
|
||||
} else {
|
||||
extensions := getRuntimeEnv(runtime.Env, "PHP_EXTENSIONS")
|
||||
if extensions != "" {
|
||||
installCmd := fmt.Sprintf("docker exec -i %s %s %s", runtime.ContainerName, "install-ext", extensions)
|
||||
err = cmd2.ExecWithLogFile(installCmd, 60*time.Minute, logPath)
|
||||
if err != nil {
|
||||
runtime.Status = constant.StatusError
|
||||
runtime.Message = buserr.New("ErrImageBuildErr").Error() + ":" + err.Error()
|
||||
_ = runtimeRepo.Save(runtime)
|
||||
return
|
||||
}
|
||||
}
|
||||
runtime.Status = constant.StatusRunning
|
||||
_ = runtimeRepo.Save(runtime)
|
||||
}
|
||||
extensions := getRuntimeEnv(runtime.Env, "PHP_EXTENSIONS")
|
||||
if extensions != "" {
|
||||
installCmd := fmt.Sprintf("docker exec -i %s %s %s", runtime.ContainerName, "install-ext", extensions)
|
||||
err = cmd2.ExecWithLogFile(installCmd, 60*time.Minute, logPath)
|
||||
if err != nil {
|
||||
runtime.Status = constant.StatusError
|
||||
runtime.Message = buserr.New("ErrImageBuildErr").Error() + ":" + err.Error()
|
||||
_ = runtimeRepo.Save(runtime)
|
||||
return
|
||||
}
|
||||
}
|
||||
if out, err := compose.DownAndUp(composePath); err != nil {
|
||||
runtime.Status = constant.StatusStartErr
|
||||
runtime.Message = out
|
||||
_ = runtimeRepo.Save(runtime)
|
||||
}
|
||||
runtime.Status = constant.StatusRunning
|
||||
}
|
||||
_ = runtimeRepo.Save(runtime)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -410,26 +410,6 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
|
|||
website.ParentWebsiteID = parentWebsite.ID
|
||||
}
|
||||
|
||||
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
|
||||
createFtpUser := func(t *task.Task) error {
|
||||
indexDir := GetSitePath(*website, SiteIndexDir)
|
||||
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
|
||||
if err != nil {
|
||||
createTask.Log(fmt.Sprintf("create ftp for website failed, err: %v", err))
|
||||
}
|
||||
website.FtpID = itemID
|
||||
return nil
|
||||
}
|
||||
deleteFtpUser := func(t *task.Task) {
|
||||
if website.FtpID > 0 {
|
||||
if err = NewIFtpService().Delete(dto.BatchDeleteReq{Ids: []uint{website.FtpID}}); err != nil {
|
||||
createTask.Log(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
createTask.AddSubTask(i18n.GetWithName("ConfigFTP", create.FtpUser), createFtpUser, deleteFtpUser)
|
||||
}
|
||||
|
||||
configNginx := func(t *task.Task) error {
|
||||
if err = configDefaultNginx(website, domains, appInstall, runtime); err != nil {
|
||||
return err
|
||||
|
|
@ -488,6 +468,19 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
|
|||
createTask.AddSubTaskWithIgnoreErr(i18n.GetMsgByKey("EnableSSL"), enableSSL)
|
||||
}
|
||||
|
||||
if len(create.FtpUser) != 0 && len(create.FtpPassword) != 0 {
|
||||
createFtpUser := func(t *task.Task) error {
|
||||
indexDir := GetSitePath(*website, SiteIndexDir)
|
||||
itemID, err := NewIFtpService().Create(dto.FtpCreate{User: create.FtpUser, Password: create.FtpPassword, Path: indexDir})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
website.FtpID = itemID
|
||||
return nil
|
||||
}
|
||||
createTask.AddSubTaskWithIgnoreErr(i18n.GetWithName("ConfigFTP", create.FtpUser), createFtpUser)
|
||||
}
|
||||
|
||||
return createTask.Execute()
|
||||
}
|
||||
|
||||
|
|
@ -2061,7 +2054,7 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo
|
|||
}
|
||||
directives := config.Directives
|
||||
location, _ := directives[0].(*components.Location)
|
||||
pathAuth.Path = location.Match
|
||||
pathAuth.Path = strings.TrimPrefix(location.Match, "^")
|
||||
passPath := path.Join(passDir, fmt.Sprintf("%s.pass", name))
|
||||
authContent, err = fileOp.GetContent(passPath)
|
||||
if err != nil {
|
||||
|
|
@ -2130,7 +2123,7 @@ func (w WebsiteService) UpdatePathAuthBasic(req request.NginxPathAuthUpdate) err
|
|||
directives := config.Directives
|
||||
location, _ := directives[0].(*components.Location)
|
||||
location.UpdateDirective("auth_basic_user_file", []string{fmt.Sprintf("/www/sites/%s/path_auth/pass/%s", website.Alias, fmt.Sprintf("%s.pass", req.Name))})
|
||||
location.ChangePath("~*", req.Path)
|
||||
location.ChangePath("~*", fmt.Sprintf("^%s", req.Path))
|
||||
var passwdHash []byte
|
||||
passwdHash, err = bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ import (
|
|||
"github.com/1Panel-dev/1Panel/agent/init/viper"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
|
||||
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,18 @@ func DumpBlock(b components.IBlock, style *Style, startLine int) string {
|
|||
}
|
||||
|
||||
directives := b.GetDirectives()
|
||||
|
||||
var sortDirectives []components.IDirective
|
||||
var proxyIncludes []components.IDirective
|
||||
for _, directive := range directives {
|
||||
if directive.GetName() == "include" && strings.Contains(strings.Join(directive.GetParameters(), " "), "/proxy/") {
|
||||
proxyIncludes = append(proxyIncludes, directive)
|
||||
} else {
|
||||
sortDirectives = append(sortDirectives, directive)
|
||||
}
|
||||
}
|
||||
directives = append(sortDirectives, proxyIncludes...)
|
||||
|
||||
for i, directive := range directives {
|
||||
|
||||
if directive.GetLine() > line {
|
||||
|
|
|
|||
|
|
@ -517,19 +517,19 @@ func (u *SettingService) GenerateApiKey() (string, error) {
|
|||
}
|
||||
|
||||
func (u *SettingService) UpdateApiConfig(req dto.ApiInterfaceConfig) error {
|
||||
if err := settingRepo.Update("ApiInterfaceStatus", req.ApiInterfaceStatus); err != nil {
|
||||
if err := settingRepo.UpdateOrCreate("ApiInterfaceStatus", req.ApiInterfaceStatus); err != nil {
|
||||
return err
|
||||
}
|
||||
global.Api.ApiInterfaceStatus = req.ApiInterfaceStatus
|
||||
if err := settingRepo.Update("ApiKey", req.ApiKey); err != nil {
|
||||
if err := settingRepo.UpdateOrCreate("ApiKey", req.ApiKey); err != nil {
|
||||
return err
|
||||
}
|
||||
global.Api.ApiKey = req.ApiKey
|
||||
if err := settingRepo.Update("IpWhiteList", req.IpWhiteList); err != nil {
|
||||
if err := settingRepo.UpdateOrCreate("IpWhiteList", req.IpWhiteList); err != nil {
|
||||
return err
|
||||
}
|
||||
global.Api.IpWhiteList = req.IpWhiteList
|
||||
if err := settingRepo.Update("ApiKeyValidityTime", req.ApiKeyValidityTime); err != nil {
|
||||
if err := settingRepo.UpdateOrCreate("ApiKeyValidityTime", req.ApiKeyValidityTime); err != nil {
|
||||
return err
|
||||
}
|
||||
global.Api.ApiKeyValidityTime = req.ApiKeyValidityTime
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ func Proxy() gin.HandlerFunc {
|
|||
currentNode = c.Request.Header.Get("CurrentNode")
|
||||
}
|
||||
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api/v2/") && !checkSession(c) {
|
||||
apiReq := c.GetBool("API_AUTH")
|
||||
|
||||
if !apiReq && strings.HasPrefix(c.Request.URL.Path, "/api/v2/") && !checkSession(c) {
|
||||
data, _ := res.ErrorMsg.ReadFile("html/401.html")
|
||||
c.Data(401, "text/html; charset=utf-8", data)
|
||||
c.Abort()
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ func ApiAuth() gin.HandlerFunc {
|
|||
helper.BadAuth(c, "ErrApiConfigIPInvalid", nil)
|
||||
return
|
||||
}
|
||||
c.Set("API_AUTH", true)
|
||||
c.Next()
|
||||
return
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -355,11 +355,6 @@ export const Algorithms = [
|
|||
value: 'least_conn',
|
||||
placeHolder: i18n.global.t('website.leastConnHelper'),
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('website.leastTime'),
|
||||
value: 'least_time',
|
||||
placeHolder: i18n.global.t('website.leastTimeHelper'),
|
||||
},
|
||||
];
|
||||
|
||||
export const StatusStrategy = [
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
/>
|
||||
</ComplexTable>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('website.path')">
|
||||
<el-tab-pane :label="$t('website.path')" v-if="showPath">
|
||||
<ComplexTable :data="pathData" @search="searchPath" v-loading="loading" :heightDiff="420">
|
||||
<template #toolbar>
|
||||
<el-button type="primary" plain @click="openCreate('path')">
|
||||
|
|
@ -54,7 +54,13 @@
|
|||
|
||||
<script lang="ts" setup name="proxy">
|
||||
import { Website } from '@/api/interface/website';
|
||||
import { operateAuthConfig, getAuthConfig, getPathAuthConfig, operatePathAuthConfig } from '@/api/modules/website';
|
||||
import {
|
||||
operateAuthConfig,
|
||||
getAuthConfig,
|
||||
getPathAuthConfig,
|
||||
operatePathAuthConfig,
|
||||
getWebsite,
|
||||
} from '@/api/modules/website';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import i18n from '@/lang';
|
||||
import Create from './create/index.vue';
|
||||
|
|
@ -80,6 +86,7 @@ const createRef = ref();
|
|||
const enable = ref(false);
|
||||
const opRef = ref();
|
||||
const pathData = ref([]);
|
||||
const showPath = ref(false);
|
||||
|
||||
const buttons = [
|
||||
{
|
||||
|
|
@ -207,7 +214,14 @@ const searchAll = () => {
|
|||
searchPath();
|
||||
};
|
||||
|
||||
const getSiteDetail = async () => {
|
||||
getWebsite(id.value).then(async (res) => {
|
||||
showPath.value = res.data.type !== 'proxy' && res.data.type !== 'deployment';
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getSiteDetail();
|
||||
searchAll();
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ const acceptParams = async (req: LoadBalanceOperate) => {
|
|||
});
|
||||
item.value.servers = servers;
|
||||
} else {
|
||||
item.value.name = '';
|
||||
item.value.servers = [initServer()];
|
||||
}
|
||||
open.value = true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue