[Feature][S300][task-view-993][webui] add web upload upgrade package upgrade function

Change-Id: I4507582b3757791e21bae800968c843b3f8c82fe
diff --git a/lynq/CPE_COMMON/ap/app/cgi/cgi.c b/lynq/CPE_COMMON/ap/app/cgi/cgi.c
index 3aaddd0..7583edb 100755
--- a/lynq/CPE_COMMON/ap/app/cgi/cgi.c
+++ b/lynq/CPE_COMMON/ap/app/cgi/cgi.c
@@ -277,51 +277,32 @@
 	return 0;

 }

 

+static void print_json_response(int success, const char* message)

+{

+    printf("Content-type: application/json\r\n\r\n");

+    printf("{\"success\": %d, \"message\": \"%s\"}\n", success, message);

+}

+

 static void cgi_fota_update_progress()

 {

     int upgradeStatus, result;

 

     system("fota_upi -u verify > /dev/null 2>&1");

-	result = fota_get_update_status(&upgradeStatus);

-	if(result < 0)

-	{

-        printf("<h1 style='color: red;'>Error: Fail to read update file!</h1>");

-	}

-	else if(upgradeStatus != 0)

-	{

-		printf("<h1 style='color: red;'>Error: Verify update file failed!</h1>");

-	}

-	else

-	{

-		printf("<h1 style='color: green;'>File verification successful, start updating...</h1>");

-		system("fota_upi -u recovery &");

-	}

-}

-

-static void html_print_start()

-{

-    printf("Content-type: text/html\r\n\r\n");

-    printf("<!DOCTYPE html>\n");

-    printf("<html lang=\"en\">\n");

-    printf("<head>\n");

-    printf("<meta charset=\"UTF-8\">\n");

-    printf("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n");

-    printf("<title>File Upload Status</title>\n");

-    printf("<style>\n");

-    printf("body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; padding-top: 20px; }\n");

-    printf(".container { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; width: 80%%; max-width: 500px; margin: 0 auto; }\n");

-    printf("h1 { margin: 10px 0; }\n");

-    printf("</style>\n");

-    printf("</head>\n");

-    printf("<body>\n");

-    printf("<div class=\"container\">\n");    

-}

-

-static void html_print_end()

-{

-    printf("</div>\n");

-    printf("</body>\n");

-    printf("</html>\n");

+    result = fota_get_update_status(&upgradeStatus);

+    if(result < 0)

+    {

+        print_json_response(0, "Fail to read update file");

+    }

+    else if(upgradeStatus != 0)

+    {

+        print_json_response(0, "Verify update file failed");

+    }

+    else

+    {

+        print_json_response(1, "File verification successful, start updating...");

+        sleep(1);

+        system("fota_upi -u recovery > /dev/null 2>&1 &");

+    }

 }

 

 int main()

@@ -338,35 +319,28 @@
     content_length_str = getenv("CONTENT_LENGTH");

     if (!content_length_str)

     {

-        printf("Content-type: text/html\r\n\r\n");

-        printf("<h1>Error: Missing CONTENT_LENGTH environment variable</h1>");

+        print_json_response(0, "Missing CONTENT_LENGTH environment variable");

         return 1;

     }

 

     content_length = atoi(content_length_str);

     if (content_length <= 0)

     {

-        printf("Content-type: text/html\r\n\r\n");

-        printf("<h1>Error: Invalid CONTENT_LENGTH</h1>");

+        print_json_response(0, "Invalid CONTENT_LENGTH");

         return 1;

     }

 

     // Call the file upload handling function

     if (handle_file_upload(source_filename, target_filename, content_length) != 0)

     {

-        printf("Content-type: text/html\r\n\r\n");

-        printf("<h1>Error: File upload failed</h1>");

+        print_json_response(0, "File upload failed");

         return 1;

     }

 

     // Output success information

-    html_print_start();

-    printf("<h1 style='color: green;'>File upload successful!</h1>");

-    //printf("<p>The file has been saved to %s</p>", target_filename);

+    //print_json_response(1, "File upload successful");

 

     cgi_fota_update_progress();

 

-    html_print_end();

-

     return 0;

 }