mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-05-06 22:12:23 +08:00
fix(nginx): panic if sbin path is empty #1178
This commit is contained in:
32
.github/workflows/build.yml
vendored
32
.github/workflows/build.yml
vendored
@@ -288,39 +288,15 @@ jobs:
|
||||
- name: Upload to R2
|
||||
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/dev'
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
env:
|
||||
WRANGLER_LOG: debug
|
||||
with:
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
apiToken: ${{ secrets.CF_R2_API_TOKEN }}
|
||||
wranglerVersion: "4.21.1"
|
||||
command: |
|
||||
retry_upload() {
|
||||
local file_path="$1"
|
||||
local remote_path="$2"
|
||||
local max_attempts=3
|
||||
local attempt=1
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
echo "Attempt $attempt of $max_attempts: Uploading $file_path to $remote_path"
|
||||
if r2 object put "$remote_path" --file "$file_path" --remote; then
|
||||
echo "Successfully uploaded $file_path on attempt $attempt"
|
||||
return 0
|
||||
else
|
||||
echo "Failed to upload $file_path on attempt $attempt"
|
||||
if [ $attempt -lt $max_attempts ]; then
|
||||
echo "Waiting 5 seconds before retry..."
|
||||
sleep 5
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Failed to upload $file_path after $max_attempts attempts"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Upload files with retry
|
||||
retry_upload ./${{ env.DIST }}.tar.gz nginx-ui-dev-build/${{ env.DIST }}.tar.gz
|
||||
retry_upload ./${{ env.DIST }}.tar.gz.digest nginx-ui-dev-build/${{ env.DIST }}.tar.gz.digest
|
||||
r2 object put nginx-ui-dev-build/${{ env.DIST }}.tar.gz --file ./${{ env.DIST }}.tar.gz --remote
|
||||
r2 object put nginx-ui-dev-build/${{ env.DIST }}.tar.gz.digest --file ./${{ env.DIST }}.tar.gz.digest --remote
|
||||
|
||||
docker-build:
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ export const msg = [
|
||||
$gettext('Check if the nginx configuration directory exists'),
|
||||
$gettext('Check if the nginx configuration entry file exists'),
|
||||
$gettext('Check if the nginx error log path exists. By default, this path is obtained from \'nginx -V\'. If it cannot be obtained or the obtained path does not point to a valid, existing file, an error will be reported. In this case, you need to modify the configuration file to specify the error log path. Refer to the docs for more details: https://nginxui.com/zh_CN/guide/config-nginx.html#errorlogpath'),
|
||||
$gettext('Check if the nginx sbin path exists'),
|
||||
$gettext('Check if the nginx.conf includes the conf.d directory'),
|
||||
$gettext('Check if the nginx.conf includes the sites-enabled directory'),
|
||||
$gettext('Check if the nginx.conf includes the streams-enabled directory'),
|
||||
@@ -23,6 +24,7 @@ export const msg = [
|
||||
$gettext('Nginx configuration directory exists'),
|
||||
$gettext('Nginx configuration entry file exists'),
|
||||
$gettext('Nginx error log path exists'),
|
||||
$gettext('Nginx sbin path exists'),
|
||||
$gettext('Nginx.conf includes conf.d directory'),
|
||||
$gettext('Nginx.conf includes sites-enabled directory'),
|
||||
$gettext('Nginx.conf includes streams-enabled directory'),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,10 @@ import (
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
nginxPrefix string
|
||||
)
|
||||
|
||||
// Returns the directory containing the nginx executable
|
||||
func GetNginxExeDir() string {
|
||||
return filepath.Dir(getNginxSbinPath())
|
||||
@@ -32,14 +36,21 @@ func resolvePath(path string) string {
|
||||
|
||||
// GetPrefix returns the prefix of the nginx executable
|
||||
func GetPrefix() string {
|
||||
if nginxPrefix != "" {
|
||||
return nginxPrefix
|
||||
}
|
||||
|
||||
out := getNginxV()
|
||||
r, _ := regexp.Compile(`--prefix=(\S+)`)
|
||||
match := r.FindStringSubmatch(out)
|
||||
if len(match) < 1 {
|
||||
logger.Error("nginx.GetPrefix len(match) < 1")
|
||||
return "/usr/local/nginx"
|
||||
nginxPrefix = "/usr/local/nginx"
|
||||
return nginxPrefix
|
||||
}
|
||||
return resolvePath(match[1])
|
||||
|
||||
nginxPrefix = resolvePath(match[1])
|
||||
return nginxPrefix
|
||||
}
|
||||
|
||||
// GetConfPath returns the path of the nginx configuration file
|
||||
|
||||
@@ -17,18 +17,17 @@ import (
|
||||
// Regular expression for log directives - matches access_log or error_log
|
||||
var (
|
||||
logDirectiveRegex = regexp.MustCompile(`(?m)(access_log|error_log)\s+([^\s;]+)(?:\s+[^;]+)?;`)
|
||||
prefix = ""
|
||||
)
|
||||
|
||||
// Use init function to automatically register callback
|
||||
func init() {
|
||||
prefix = nginx.GetPrefix()
|
||||
// Register the callback directly with the global registry
|
||||
cache.RegisterCallback(scanForLogDirectives)
|
||||
}
|
||||
|
||||
// scanForLogDirectives scans and parses configuration files for log directives
|
||||
func scanForLogDirectives(configPath string, content []byte) error {
|
||||
prefix := nginx.GetPrefix()
|
||||
// First, remove all log paths that came from this config file
|
||||
// This ensures that removed log directives are properly cleaned up
|
||||
RemoveLogPathsFromConfig(configPath)
|
||||
@@ -147,6 +146,7 @@ func isValidLogPath(logPath string) bool {
|
||||
|
||||
// IsLogPathUnderWhiteList checks if a log path is under one of the paths in LogDirWhiteList
|
||||
func IsLogPathUnderWhiteList(path string) bool {
|
||||
prefix := nginx.GetPrefix()
|
||||
cacheKey := fmt.Sprintf("isLogPathUnderWhiteList:%s", path)
|
||||
res, ok := cache.Get(cacheKey)
|
||||
|
||||
|
||||
@@ -38,6 +38,15 @@ func CheckPIDPath() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckSbinPath checks if the sbin path exists
|
||||
func CheckSbinPath() error {
|
||||
path := nginx.GetSbinPath()
|
||||
if path == "" {
|
||||
return ErrSbinPathNotExist
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckAccessLogPath checks if the access log path exists
|
||||
func CheckAccessLogPath() error {
|
||||
path := nginx.GetAccessLogPath()
|
||||
|
||||
@@ -82,6 +82,12 @@ var selfCheckTasks = []*Task{
|
||||
"Refer to the docs for more details: https://nginxui.com/zh_CN/guide/config-nginx.html#pidpath"),
|
||||
CheckFunc: CheckPIDPath,
|
||||
},
|
||||
{
|
||||
Key: "NginxSbin-Path",
|
||||
Name: translation.C("Nginx sbin path exists"),
|
||||
Description: translation.C("Check if the nginx sbin path exists"),
|
||||
CheckFunc: CheckSbinPath,
|
||||
},
|
||||
{
|
||||
Key: "NginxAccessLog-Path",
|
||||
Name: translation.C("Nginx access log path exists"),
|
||||
|
||||
Reference in New Issue
Block a user