20190603_jeffrey - silenceuncrio/diary GitHub Wiki

0910

review

1400

M330 再依據 ariel 的需求稍作修改

commit 97e49da747b10bfa3ae3f0f930dc8a6ec1b6bfad
Refs: [release/v0.03], {origin/release/v0.03}
Author: jeffrey <[email protected]>
Date:   Mon Jun 3 13:59:52 2019 +0800

    LTE mode: Bridge Only, Router Only

    Please check PROSRC_LTE_BRIDGE_ROUTER=y then display BRIDGE+ROUTER

    Please check PROSRC_LTE_ROUTER_ROUTER =y then display ROUTER+ROUTER

    By default, no profile enable these two flags so far

    If both modes are not defined, Please:
    - hide APN2 usage.
    - rename the 'LTE > Dual APN' to 'LTE > APN Config'
    - remove 'APN2' from 'LTE > APN Config'

 proscend/prosrc/www/app/feature/apn_config.html    | 331 +++++++++++++++++++++
 proscend/prosrc/www/app/feature/apn_config.js      | 251 ++++++++++++++++
 proscend/prosrc/www/app/locale-en.json             |   6 +
 proscend/prosrc/www/app/locale-fr.json             |   6 +
 proscend/prosrc/www/app/locale-zh-tw.json          |   6 +
 proscend/prosrc/www/src/index.html.src             |   1 +
 proscend/prosrc/www/src/manual.html.src            |   6 +
 .../prosrc/www/src/manual/lte_apn_config.h.html    | 143 +++++++++
 .../prosrc/www/src/manual/lte_apnx_usage.h.html    |   4 +
 proscend/prosrc/www/src/manual/sidebar.h.html      |  15 +
 proscend/prosrc/www/src/manual/wan_priority.h.html |  16 +-
 proscend/prosrc/www/src/menu.html.src              |   8 +-
 12 files changed, 787 insertions(+), 6 deletions(-)

1405

回到 M300 - feature/lighttpd

上禮拜利用原本的 iweb review 到漏掉了以下這些

    mg_register_http_endpoint(nc, "/api/openvpnUpload", _api_openvpnUpload);
    mg_register_http_endpoint(nc, "/api/ipsecUpload", _api_ipsecUpload);
    mg_register_http_endpoint(nc, "/api/brandTopPngUpload", _api_brandTopPngUpload);
    mg_register_http_endpoint(nc, "/api/customerFileUpload", _api_customerFileUpload);

#if !defined(PROSRC_NO_DIDO) && defined(PROSRC_DO_REMOTE)
    mg_register_http_endpoint(nc, "/DO_ON",             _api_do_on);
    mg_register_http_endpoint(nc, "/DO_OFF",            _api_do_off);
    mg_register_http_endpoint(nc, "/DO_PULSE",          _api_do_pulse);
    mg_register_http_endpoint(nc, "/RESTORE_DO_ALARM",  _api_restore_do_alarm);
#endif

1430

mg_register_http_endpoint(nc, "/api/openvpnUpload", _api_openvpnUpload);

實作前先 refactoring 之前做的

diff --git a/proscend/prosrc/webcgi/api.c b/proscend/prosrc/webcgi/api.c
index b427cba..a9a55c6 100644
--- a/proscend/prosrc/webcgi/api.c
+++ b/proscend/prosrc/webcgi/api.c
@@ -12,11 +12,6 @@ static void _help()

-#define FIRMWARE_PATH       "/tmp/firmware.upload"
-#define CONFIGURATION_PATH  "/tmp/configuration.upload"
-
 int main(void)
 {
     jweb.cgi.init();
@@ -35,64 +30,12 @@ int main(void)
     }
     else if (STRCMP(jweb.in.act, "firmwareUpload"))
     {
-
-        json_object *obj = json_object_new_object();
-
-        s_file *file;
-        char **vars = cgiGetFiles (cgi);
-        if (vars)
-        {
-            // get the first one file from the list of names of all files.
-            file = cgiGetFile (cgi, vars[0]);
-            if (file)
-            {
-                rename(file->tmpfile, FIRMWARE_PATH);
-                jweb.out.json.ok();
-            }
-            else
-            {
-                jweb.out.json.fail("no files");
-            }
-        }
-        else
-        {
-            jweb.out.json.fail("no files");
-        }
-
+        jweb.api.upload_file(FIRMWARE_PATH);
     }
-
     else if (STRCMP(jweb.in.act, "configurationUpload"))
     {
-
-        json_object *obj = json_object_new_object();
-
-        s_file *file;
-        char **vars = cgiGetFiles (cgi);
-        if (vars)
-        {
-            // get the first one file from the list of names of all files.
-            file = cgiGetFile (cgi, vars[0]);
-            if (file)
-            {
-                rename(file->tmpfile, CONFIGURATION_PATH);
-                jweb.out.json.ok();
-            }
-            else
-            {
-                jweb.out.json.fail("no files");
-            }
-        }
-        else
-        {
-            jweb.out.json.fail("no files");
-        }
-
+        jweb.api.upload_file(CONFIGURATION_PATH);
     }
-
     else if (STRCMP(jweb.in.act, "help"))
     {
         _help();
diff --git a/proscend/prosrc/webcgi/jweb.c b/proscend/prosrc/webcgi/jweb.c
index bbd7cee..5a7dbea 100644
--- a/proscend/prosrc/webcgi/jweb.c
+++ b/proscend/prosrc/webcgi/jweb.c
@@ -18,9 +18,11 @@

-static void api_login(void);

+static void api_login(void);
 static void api_whoAmI(void);
+static void api_logout(void);
+static void api_upload_file(const char *path);

@@ -129,9 +131,6 @@ static void api_login(void)
-
 static void api_whoAmI(void)
 {
     session_t *session = get_session();
@@ -151,9 +150,6 @@ static void api_whoAmI(void)
-
 static void api_logout(void)
 {
     session_t *session = get_session();
@@ -171,6 +167,31 @@ static void api_logout(void)

+static void api_upload_file(const char *path)
+{
+    char **vars = cgiGetFiles (cgi);
+    if (vars)
+    {
+        // get the first one file from the list of names of all files.
+        s_file *file = cgiGetFile (cgi, vars[0]);
+        if (file)
+        {
+            rename(file->tmpfile, path);
+            jweb.out.json.ok();
+        }
+        else
+        {
+            jweb.out.json.fail("no files");
+        }
+    }
+    else
+    {
+        jweb.out.json.fail("no files");
+    }
+}

@@ -658,6 +679,7 @@ static void cgi_init(void)
         sprintf(QUERY_STRING, "%s&%s", getenv("QUERY_STRING"), x_www_form_urlencoded_payload);
         setenv("REQUEST_METHOD", "GET", 1);
         setenv("QUERY_STRING", QUERY_STRING, 1);
+        free(x_www_form_urlencoded_payload);
     }

@@ -895,6 +917,7 @@ jweb_t jweb =
     .api.login = api_login,
     .api.whoAmI = api_whoAmI,
     .api.logout = api_logout,
+    .api.upload_file = api_upload_file,

 };

diff --git a/proscend/prosrc/webcgi/jweb.h b/proscend/prosrc/webcgi/jweb.h
index dd7f817..29db246 100644
--- a/proscend/prosrc/webcgi/jweb.h
+++ b/proscend/prosrc/webcgi/jweb.h
@@ -31,6 +31,12 @@

+/*
+** file upload path
+** same as functions in iweb
+*/
+#define FIRMWARE_PATH       "/tmp/firmware.upload"
+#define CONFIGURATION_PATH  "/tmp/configuration.upload"

@@ -136,6 +142,7 @@ typedef struct
         void    (*login)(void);
         void    (*whoAmI)(void);
         void    (*logout)(void);
+        void    (*upload_file)(const char *path);
     } api;

整理成 static void api_upload_file(const char *path)

封裝進 jweb - jweb.api.upload_file(const char *path)

這樣一來後續 file upload 相關的 api 就好做了

commit d9d983b846950699fd79e74c6a0db037851fd978
Refs: [feature/lighttpd]
Author: jeffrey <[email protected]>
Date:   Mon Jun 3 14:51:15 2019 +0800

    refactoring
    - add jweb.api.upload_file(const char *path) for file upload

 proscend/prosrc/webcgi/api.c  | 61 ++-----------------------------------------
 proscend/prosrc/webcgi/jweb.c | 37 +++++++++++++++++++++-----
 proscend/prosrc/webcgi/jweb.h |  7 +++++
 3 files changed, 39 insertions(+), 66 deletions(-)

1630

upload 相關的一次完成

commit 4f817b9190b610e835111499057612c8c1a99e9d
Refs: [feature/lighttpd]
Author: jeffrey <[email protected]>
Date:   Mon Jun 3 16:28:06 2019 +0800

    offer CGI for upload
    - openvpnUpload - POST /cgi-bin/api/cgi?act=openvpnUpload
      - before rewrite - /api/openvpnUpload
      - jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=openvpnUpload"
    - ipsecUpload - POST /cgi-bin/api/cgi?act=ipsecUpload
      - before rewrite - /api/ipsecUpload
      - jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=ipsecUpload"
    - brandTopPngUpload - POST /cgi-bin/api/cgi?act=brandTopPngUpload
      - before rewrite - /api/brandTopPngUpload
      - jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=brandTopPngUpload"
    - customerFileUpload - POST /cgi-bin/api/cgi?act=customerFileUpload
      - before rewrite - /api/customerFileUpload
      - jweb need further handle when REQUEST_METHOD="POST" and QUERY_STRING="act=customerFileUpload"

 proscend/prosrc/webcgi/api.c  | 20 ++++++++++++++++++--
 proscend/prosrc/webcgi/jweb.c | 20 ++++++++++++++++++++
 proscend/prosrc/webcgi/jweb.h | 19 +++++++++++++++++--
 3 files changed, 55 insertions(+), 4 deletions(-)