20190620_jeffrey - silenceuncrio/diary GitHub Wiki

0900

繼續 M330 - feature/lighttpd

參考 M300 的 commit

條列一下 M330 的這一大跨步要有什麼

  • /cgi-bin/api.cgi?act=login
    • jweb.api.login()
  • /cgi-bin/api.cgi?act=logout
    • jweb.api.logout()
  • jweb.in.session
    • use cgiGetCookie() to get session at cgi_init_values()
  • jweb.access.filter
    • access_filter()
      • M330 與 M330 的差異在於 M330 不去區分 user 的 level
  • jweb.api.login
    • api_login()
  • jweb.api.logout
    • api_logout()

1040

做了一番修改後得到 api.cgi 以及 sntp.cgi

複製到 window host 上 tftp server 看的到的地方

再來是 M330

先把 /www 複製到 /tmp

cp -r /www /tmp

再透過 tftp client 去跟 tftp server 要 api.cgi 以及 sntp.cgi

記得放到 /tmp/www/cgi-bin

可以做測試了

一樣先利用 M300 產生 certification 的 shell script - web_x509_lighttpd.sh

#!/bin/bash

openssl req -x509 -newkey rsa:2048 -keyout /tmp/icos/web/lighttpd.pem -out /tmp/icos/web/lighttpd.pem -days 3650 -nodes -subj '/CN=localhost'
mv /tmp/icos/web/lighttpd.pem /etc/icos/web/lighttpd.pem
sync

還有 lighttpd 的 config - lighttpd.conf

server.document-root = "/tmp/www/"

server.bind = "0.0.0.0"

server.port = 3000

$SERVER["socket"] == "[::]:3000" { }

$SERVER["socket"] == "0.0.0.0:3443" {
  ssl.engine = "enable"
  ssl.pemfile = "/etc/icos/web/lighttpd.pem"
}
$SERVER["socket"] == "[::]:3443" {
  ssl.engine = "enable"
  ssl.pemfile = "/etc/icos/web/lighttpd.pem"
}

server.modules = ( "mod_rewrite", "mod_cgi" )

index-file.names = ( "index.html" )

mimetype.assign = (
  ".gif"  => "image/gif",
  ".jpg"  => "image/jpeg",
  ".jpeg" => "image/jpeg",
  ".png"  => "image/png",
  ".css"  => "text/css",
  ".html" => "text/html",
  ".htm"  => "text/html",
  ".txt"  => "text/plain",
)

cgi.assign = ( ".cgi" => "" )

url.rewrite = (
  "^/api/([a-zA-Z]+)[0-9a-zA-Z=.?]*$" => "/cgi-bin/api.cgi?act=$1",
  "^/(DO_ON|DO_OFF|DO_PULSE|RESTORE_DO_ALARM)$" => "/cgi-bin/api.cgi?act=$1",
)

注意到 server.document-root = "/tmp/www/"

執行 lighttpd 吧

root@M330:/tmp# lighttpd -f /tmp/lighttpd.conf
root@M330:/tmp# 1970-01-01 18:22:23: (log.c.166) server started

root@M330:/tmp#

點選 System > Time and Date

這會發出以下的 request

  • /cgi-bin/sntp.cgi?act=config
  • /cgi-bin/sntp.cgi?act=help

得到的回應都是 401 這個 http status code

然後 angular 就幫忙開啟 login page 讓我做 login 的動作

失敗

/api/login 這個 POST request 回應 400 這個 http status code

不過看到自己發出的錯誤訊息

這是由 jweb.c 裡的 cgi_init_values() 發出

static void cgi_init_values(void)
{

    ...

    jweb.in.act = cgiGetValue(cgi, "act");
    if (!jweb.in.act)
    {
        http_status(400);
        json_fail("act needed");
    }

    ...

}

這才想到 M300 針對 login 這個 application/x-www-form-urlencoded 特別的 CONTENT_TYPE 需要特殊處理

看起來是成功了

不過注意到前端再 login 之後還會再發 cgi-bin/syslog.cgi?act=gen_log

目的是想讓 iweb 死後復生來得到正常工作的 iweb

現在 lighttpd 已經不需要這個動作了

不過先整理一下目前這個大跨步準備 commit 吧

1155

M330 - feature/lighttpd - session management, login, logout and access filter

commit a89235402b1ace758d295d6503e6a60e597de37f
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 11:56:11 2019 +0800

    feature/lighttpd - session management, login, logout and access filter
    - jweb.access.filter
      - for multi-user with different level
      - only one user for M330 - root with level ATTVAL_SYSTEM_LEVEL3
    - jweb.api.login
      - create a new session for the user and send a cookie to the client
      - cgi_init() do 3 more things:
        - icos_users_init()
          - init the user information form MODULE_SYSTEM
        - init_session_store()
          - we need keep session information at ram
        - check_sessions()
          - trigger this at each time any CGI invoked
          - Cleans up sessions that have been idle for too long
      - use UUID library to generate unique session id
    - jweb.api.logout
      - destroy the current session

 proscend/prosrc/webcgi/Makefile |   9 +-
 proscend/prosrc/webcgi/api.c    |  42 ++++
 proscend/prosrc/webcgi/jweb.c   | 441 +++++++++++++++++++++++++++++++++++++++-
 proscend/prosrc/webcgi/jweb.h   |  66 +++++-
 proscend/prosrc/webcgi/sntp.c   |   8 +-
 5 files changed, 557 insertions(+), 9 deletions(-)

1305

整理一下這禮拜的進度

  • M300 - release/v2.00
    • change wording ETH First to Auto at
  • M300 - feature/lighttpd
    • our lighttpd support IPv6 now
  • M300 - feature/web_ui_intro
    • web introduction 01
    • web introduction 02
  • M330 - release/v0.03
    • change wording "LTE APN1 DNS" to "WAN DNS" at status page
    • change wording Auto (ETH -> LTE) to Auto
    • display the operator name without according to the value of vm.top.lte_cur_proto_state
  • M330 - feature/lighttpd
    • use lighttpd to replace the current web server iweb(mongoose)
    • session management, login, logout and access filter

1350

M330 - feature/lighttpd - no more the workaround

commit c731b2bebe9a1bffaa9ec2c744e4743d7d78aea4
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 13:46:27 2019 +0800

    feature/lighttpd - no more the workaroud
    - let iweb be killed once at the first time after power on
    - the icos.syslog.gen_log() action cause iweb be killed

 proscend/prosrc/www/app/feature/login.js | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

1400

M330 - feature/lighttpd - 'System > Logging'

commit 328adc25caedf502fbd01a6c7e6207e479fa75cc
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 13:58:17 2019 +0800

    feature/lighttpd - 'System > Logging'
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _gen_log);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _clear_log);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

    use the full path of `ParseSyslog.sh` or cgi with lighttpd will fail

 proscend/prosrc/webcgi/syslog.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

M330 - feature/lighttpd - 'System > Alarm'

commit 39d0beac79c2a8e73c833e8939da7eef622c786a
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 14:06:33 2019 +0800

    feature/lighttpd - 'System > Alarm'
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_users);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_user);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, act_delete_users);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_groups);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_group);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, act_delete_group);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_schedules);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, act_sms);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, act_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/alarm.c | 76 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 64 insertions(+), 12 deletions(-)

1420

M330 - feature/lighttpd - 'System > Ethernet Ports'

commit ffb4cf8dbace3c00e6f1b2fd3923acb82b84249e
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 14:21:32 2019 +0800

    feature/lighttpd - 'System > Ethernet Ports'
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _status);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/switch.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

M330 - feature/lighttpd - 'System > Client List'

commit 014e15ac38c95523d9eab43fc3adc2bb304dc8be
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 14:30:07 2019 +0800

    feature/lighttpd - 'System > Client List'
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _lan);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/dhcp_client_list.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

1445

commit 1b652eea8eb0169cca63b409d52223a15b19d93d
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 14:42:49 2019 +0800

    feature/lighttpd - 'WAN > Priority'
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _ping_health_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _ping_health_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _chg_wproto_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _chg_wproto_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _chg_wan_net_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _chg_wan_net_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/connmgr.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

1520

M330 - feature/lighttpd - 'WAN > Ethernet'

commit 422fe5fce3e9ac2f73a6eb81d2e6680af633e84d
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 15:20:34 2019 +0800

    feature/lighttpd - 'WAN > Ethernet'

    dns.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

    ipv6lan.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _default);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

    pppoe.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _set);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

    wanst.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/dns.c     |  38 ++---
 proscend/prosrc/webcgi/ipv6lan.c |  10 +-
 proscend/prosrc/webcgi/pppoe.c   | 292 +++++++++++++++++++--------------------
 proscend/prosrc/webcgi/wanst.c   | 227 ++++++++++++++++--------------
 4 files changed, 294 insertions(+), 273 deletions(-)

1540

M330 - feature/lighttpd - 'LTE > LTE Config'

commit 7a15106ff9df2d212c49752b013fac6bd21a8645
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 15:38:42 2019 +0800

    feature/lighttpd - 'LTE > LTE Config'

    lte.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _modem_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _modem_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _sim_pin_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _sim_pin_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _gps_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _gps_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _sms_action_config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _sms_action_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _query_eng);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _neighbor_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _neighbor_pci_test);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _unlock_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _lock_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _lock_pci_conf);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _lock_pci_conf_apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _multi_neighbor_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _get_multi_lock_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _get_multi_lock_pci_conf_opt);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply_multi_lock_pci);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply_multi_lock_pci_conf_opt);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _get_band_hint);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _get_multi_band_conf_opt);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply_multi_band_conf_opt);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply_multi_lock_band);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _reset_default_band);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _clear_sms);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _get_operator_list);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/lte.c | 62 ++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

1555

M330 - feature/lighttpd - 'LTE > APN1 Usage'/'LTE > APN2 Usage'

commit 6bc8303072f57375d4bec318423552e3261c9f0e
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 15:55:59 2019 +0800

    feature/lighttpd - 'LTE > APN1 Usage'/'LTE > APN2 Usage'

    usage_display.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _hourly);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _daily);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _weekly);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _monthly);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _real_time);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _info);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/usage_display.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

1610

M330 - feature/lighttpd - 'LTE > Serving Cell'

commit b364972c2e0b098699141cf1c3739ed16849cfbb
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 16:08:46 2019 +0800

    feature/lighttpd - 'LTE > Serving Cell'
    - use 'cgi-bin/configuration.cgi?act=help' as the resolver of angular routeProvider
      - make sure user have been login

    configuration.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _backup);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _restore);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/configuration.c          |  8 ++++----
 proscend/prosrc/www/app/feature/serving_cell.js | 11 ++++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

1625

M330 - feature/lighttpd - 'LAN > IPv4'

commit 95be8eb66feda6e3fc2ce62db50abcd802ace9d4
Refs: [feature/lighttpd], {origin/feature/lighttpd}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 16:26:09 2019 +0800

    feature/lighttpd - 'LAN > IPv4'

    lan_control.cgi
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _config);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL2, _apply);
    - jweb.access.filter(ATTVAL_SYSTEM_LEVEL1, _help);

 proscend/prosrc/webcgi/lan_control.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

1630

M330 - develop 有 ui 工作需求

Vendor/Products = GENERIC/2_GENERIC_BG96

這個 profile 的 PROSRC_SMS 和其它 profile 不同

# PROSRC_SMS is not set

這是因為 BG96 並沒有電話簡訊等功能

所以要依賴這個 flag 來連動 ui

收工

commit 32d9baa17244da3afa168d6e75f68ad5c8fd727d
Refs: [develop], {origin/develop}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 17:06:42 2019 +0800

    according to compile flag PROSRC_SMS to show the web ui

 proscend/prosrc/www/app/locale-en.json             |  2 ++
 proscend/prosrc/www/app/locale-fr.json             |  2 ++
 proscend/prosrc/www/app/locale-zh-tw.json          |  2 ++
 proscend/prosrc/www/src/app/feature/alarm.html.src | 16 ++++++++++++++++
 proscend/prosrc/www/src/manual.html.src            |  4 ++++
 proscend/prosrc/www/src/manual/sidebar.h.html      |  3 +++
 proscend/prosrc/www/src/manual/system_alarm.h.html | 14 +++++++++++++-
 proscend/prosrc/www/src/menu.html.src              |  3 +++
 8 files changed, 45 insertions(+), 1 deletion(-)

build 個完整的 image 檢查一下

1720

online manual 上還有 SMS 字眼

再修一下

commit e4d371152ed239c6fb7eb80a58102092c3afdabb
Refs: [develop], {origin/develop}
Author: jeffrey <[email protected]>
Date:   Thu Jun 20 17:20:31 2019 +0800

    according to compile flag PROSRC_SMS to show the online manual for 'Management > Contacts / On Duty'

 proscend/prosrc/www/src/manual/management_contacts.h.html | 5 +++++
 1 file changed, 5 insertions(+)

1725

回來 M330 - feature/lighttpd

Products/Vendor 選擇 M330/1_WIFI

先 build 個 image