Browse Source

fix(nginx): panic if sbin path is empty #1178

Jacky 5 days ago
parent
commit
34ef1de236

+ 4 - 28
.github/workflows/build.yml

@@ -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
+ 191 - 178
app/src/language/ar/app.po


File diff suppressed because it is too large
+ 190 - 184
app/src/language/de_DE/app.po


File diff suppressed because it is too large
+ 157 - 141
app/src/language/en/app.po


File diff suppressed because it is too large
+ 186 - 176
app/src/language/es/app.po


File diff suppressed because it is too large
+ 192 - 193
app/src/language/fr_FR/app.po


+ 2 - 0
app/src/language/generate.ts

@@ -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
+ 188 - 224
app/src/language/ja_JP/app.po


File diff suppressed because it is too large
+ 189 - 204
app/src/language/ko_KR/app.po


File diff suppressed because it is too large
+ 157 - 141
app/src/language/messages.pot


File diff suppressed because it is too large
+ 185 - 178
app/src/language/pt_PT/app.po


File diff suppressed because it is too large
+ 190 - 178
app/src/language/ru_RU/app.po


File diff suppressed because it is too large
+ 192 - 185
app/src/language/tr_TR/app.po


File diff suppressed because it is too large
+ 195 - 192
app/src/language/uk_UA/app.po


File diff suppressed because it is too large
+ 190 - 179
app/src/language/vi_VN/app.po


File diff suppressed because it is too large
+ 184 - 189
app/src/language/zh_CN/app.po


File diff suppressed because it is too large
+ 184 - 185
app/src/language/zh_TW/app.po


+ 13 - 2
internal/nginx/resolve_path.go

@@ -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

+ 2 - 2
internal/nginx_log/nginx_log.go

@@ -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)
 

+ 9 - 0
internal/self_check/nginx.go

@@ -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()

+ 6 - 0
internal/self_check/tasks.go

@@ -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"),

Some files were not shown because too many files changed in this diff