Fixed ui, fixed lpac loop
This commit is contained in:
parent
ca0119ddb3
commit
fcd2b86ba1
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"write": {
|
"write": {
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"esim-tools": [ "run", "at", "config_set" ]
|
"esim-tools": [ "run", "cancel", "at", "config_set" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ var callModem = rpc.declare({ object: 'esim-tools', method: 'modem', expect: { '
|
|||||||
var callProfiles = rpc.declare({ object: 'esim-tools', method: 'profiles', expect: { '': {} } });
|
var callProfiles = rpc.declare({ object: 'esim-tools', method: 'profiles', expect: { '': {} } });
|
||||||
var callJob = rpc.declare({ object: 'esim-tools', method: 'job', expect: { '': {} } });
|
var callJob = rpc.declare({ object: 'esim-tools', method: 'job', expect: { '': {} } });
|
||||||
var callRun = rpc.declare({ object: 'esim-tools', method: 'run', params: [ 'cmd', 'a', 'b', 'c', 'flag' ], expect: { '': {} } });
|
var callRun = rpc.declare({ object: 'esim-tools', method: 'run', params: [ 'cmd', 'a', 'b', 'c', 'flag' ], expect: { '': {} } });
|
||||||
|
var callCancel = rpc.declare({ object: 'esim-tools', method: 'cancel', expect: { '': {} } });
|
||||||
var callAt = rpc.declare({ object: 'esim-tools', method: 'at', params: [ 'cmd' ], expect: { '': {} } });
|
var callAt = rpc.declare({ object: 'esim-tools', method: 'at', params: [ 'cmd' ], expect: { '': {} } });
|
||||||
var callConfigSet = rpc.declare({ object: 'esim-tools', method: 'config_set', params: [ 'at_port', 'wdm', 'iface' ], expect: { '': {} } });
|
var callConfigSet = rpc.declare({ object: 'esim-tools', method: 'config_set', params: [ 'at_port', 'wdm', 'iface' ], expect: { '': {} } });
|
||||||
var callUpdateCheck = rpc.declare({ object: 'esim-tools', method: 'update_check', expect: { '': {} } });
|
var callUpdateCheck = rpc.declare({ object: 'esim-tools', method: 'update_check', expect: { '': {} } });
|
||||||
@ -230,9 +231,9 @@ return view.extend({
|
|||||||
'style': 'width:24px;height:24px;vertical-align:middle;margin-right:.4em' }) : '';
|
'style': 'width:24px;height:24px;vertical-align:middle;margin-right:.4em' }) : '';
|
||||||
rows.push(E('tr', { 'class': 'tr' }, [
|
rows.push(E('tr', { 'class': 'tr' }, [
|
||||||
E('td', { 'class': 'td' }, on ? E('strong', { 'style': GREEN }, '● включён') : E('span', '○ выключен')),
|
E('td', { 'class': 'td' }, on ? E('strong', { 'style': GREEN }, '● включён') : E('span', '○ выключен')),
|
||||||
E('td', { 'class': 'td' }, [ icon, E('strong', pr.profileNickname || pr.serviceProviderName || '—'),
|
E('td', { 'class': 'td' }, [].concat(icon, E('strong', pr.profileNickname || pr.serviceProviderName || '—'),
|
||||||
pr.profileNickname && pr.serviceProviderName ? [ E('br'), desc(pr.serviceProviderName) ] : '',
|
pr.profileNickname && pr.serviceProviderName ? [ E('br'), desc(pr.serviceProviderName) ] : [],
|
||||||
pr.profileName && pr.profileName != pr.serviceProviderName ? [ E('br'), desc(pr.profileName) ] : '' ]),
|
pr.profileName && pr.profileName != pr.serviceProviderName ? [ E('br'), desc(pr.profileName) ] : [])),
|
||||||
E('td', { 'class': 'td' }, E('code', pr.iccid)),
|
E('td', { 'class': 'td' }, E('code', pr.iccid)),
|
||||||
E('td', { 'class': 'td right', 'style': 'white-space:nowrap' }, [
|
E('td', { 'class': 'td right', 'style': 'white-space:nowrap' }, [
|
||||||
on
|
on
|
||||||
@ -446,7 +447,7 @@ return view.extend({
|
|||||||
E('table', { 'class': 'table' }, [
|
E('table', { 'class': 'table' }, [
|
||||||
row('AT-порт', portText(st.at_info)),
|
row('AT-порт', portText(st.at_info)),
|
||||||
row('MBIM (lpac)', portText(st.wdm_info)),
|
row('MBIM (lpac)', portText(st.wdm_info)),
|
||||||
row('Интерфейс ' + st.iface, [ ifState, st.iface_proto ? desc(' (' + st.iface_proto + ')') : '' ]),
|
row('Интерфейс ' + st.iface, [].concat(ifState, st.iface_proto ? desc(' (' + st.iface_proto + ')') : '')),
|
||||||
row('ModemManager', st.mm_running ? 'работает' : E('strong', { 'style': RED },
|
row('ModemManager', st.mm_running ? 'работает' : E('strong', { 'style': RED },
|
||||||
st.busy ? 'остановлен на время операции' : 'остановлен')),
|
st.busy ? 'остановлен на время операции' : 'остановлен')),
|
||||||
row('APN', [ apn, ' ', this.button('Применить', 'apply', 'apn', function() {
|
row('APN', [ apn, ' ', this.button('Применить', 'apply', 'apn', function() {
|
||||||
@ -520,6 +521,7 @@ return view.extend({
|
|||||||
var state = j.running ? E('em', 'выполняется…')
|
var state = j.running ? E('em', 'выполняется…')
|
||||||
: j.rc === 0 ? E('strong', { 'style': GREEN }, 'готово') : E('strong', { 'style': RED }, 'ошибка (код ' + j.rc + ')');
|
: j.rc === 0 ? E('strong', { 'style': GREEN }, 'готово') : E('strong', { 'style': RED }, 'ошибка (код ' + j.rc + ')');
|
||||||
dom.content(this.jobTitle, [ 'Последняя команда: ', E('code', j.cmd), ' — ', state ]);
|
dom.content(this.jobTitle, [ 'Последняя команда: ', E('code', j.cmd), ' — ', state ]);
|
||||||
|
this.cancelBtn.style.display = j.running ? '' : 'none';
|
||||||
this.jobLog.textContent = j.log || '';
|
this.jobLog.textContent = j.log || '';
|
||||||
this.jobLog.scrollTop = this.jobLog.scrollHeight;
|
this.jobLog.scrollTop = this.jobLog.scrollHeight;
|
||||||
},
|
},
|
||||||
@ -593,7 +595,16 @@ return view.extend({
|
|||||||
this.maintBox = box();
|
this.maintBox = box();
|
||||||
this.jobTitle = E('h3');
|
this.jobTitle = E('h3');
|
||||||
this.jobLog = E('pre', { 'style': 'white-space:pre-wrap;max-height:24em;overflow:auto' });
|
this.jobLog = E('pre', { 'style': 'white-space:pre-wrap;max-height:24em;overflow:auto' });
|
||||||
this.jobBox = E('div', { 'class': 'cbi-section' }, [ this.jobTitle, this.jobLog ]);
|
this.cancelBtn = E('button', { 'class': 'btn cbi-button cbi-button-negative', 'style': 'display:none',
|
||||||
|
'click': ui.createHandlerFn(this, function() {
|
||||||
|
if (!window.confirm('Прервать команду? Скрипт остановится и запустит ModemManager обратно.'))
|
||||||
|
return;
|
||||||
|
return callCancel().then(function(r) {
|
||||||
|
if (r.error)
|
||||||
|
ui.addNotification(null, E('p', r.error), 'warning');
|
||||||
|
});
|
||||||
|
}) }, 'Прервать');
|
||||||
|
this.jobBox = E('div', { 'class': 'cbi-section' }, [ this.jobTitle, this.jobLog, E('div', { 'class': 'right' }, this.cancelBtn) ]);
|
||||||
|
|
||||||
this.renderAll(data[0], data[1]);
|
this.renderAll(data[0], data[1]);
|
||||||
this.showJob(data[2]);
|
this.showJob(data[2]);
|
||||||
|
|||||||
32
luci/rpcd.sh
32
luci/rpcd.sh
@ -7,6 +7,7 @@
|
|||||||
# profiles cached lpac answers (profile list, chip info) with their age
|
# profiles cached lpac answers (profile list, chip info) with their age
|
||||||
# run start a whitelisted esim command as the background job
|
# run start a whitelisted esim command as the background job
|
||||||
# job the job's command, state, exit code and output
|
# job the job's command, state, exit code and output
|
||||||
|
# cancel stop the job: esim gets TERM and still restarts ModemManager
|
||||||
# at one raw AT command to AT_PORT
|
# at one raw AT command to AT_PORT
|
||||||
# config_set AT_PORT / WDM / IFACE into /etc/esim-tools/esim.conf
|
# config_set AT_PORT / WDM / IFACE into /etc/esim-tools/esim.conf
|
||||||
# update_check latest commit on the git server vs the installed one
|
# update_check latest commit on the git server vs the installed one
|
||||||
@ -245,6 +246,34 @@ start_job() {
|
|||||||
json_dump
|
json_dump
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# children <pid>: direct children from /proc (no pgrep -P in busybox by default)
|
||||||
|
children() {
|
||||||
|
for s in /proc/[0-9]*/stat; do
|
||||||
|
read -r p _ _ pp _ < "$s" 2>/dev/null && [ "$pp" = "$1" ] && echo "$p"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# kill_tree <pid>: children first, so esim's own TERM trap (restore) runs
|
||||||
|
# once its foreground lpac/sleep is gone
|
||||||
|
kill_tree() {
|
||||||
|
for c in $(children "$1"); do
|
||||||
|
kill_tree "$c"
|
||||||
|
done
|
||||||
|
kill -TERM "$1" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
m_cancel() {
|
||||||
|
job_running || reply_error "ничего не выполняется"
|
||||||
|
echo ">> прервано со страницы" >> "$JOB/log"
|
||||||
|
# the job's subshell itself stays: it writes rc and the history line
|
||||||
|
for c in $(children "$(cat "$JOB/pid")"); do
|
||||||
|
kill_tree "$c"
|
||||||
|
done
|
||||||
|
json_init
|
||||||
|
json_add_boolean cancelled 1
|
||||||
|
json_dump
|
||||||
|
}
|
||||||
|
|
||||||
m_job() {
|
m_job() {
|
||||||
json_init
|
json_init
|
||||||
json_add_string cmd "$(cat "$JOB/cmd" 2>/dev/null)"
|
json_add_string cmd "$(cat "$JOB/cmd" 2>/dev/null)"
|
||||||
@ -300,7 +329,7 @@ m_update_check() {
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
list)
|
list)
|
||||||
echo '{"status":{},"modem":{},"profiles":{},"job":{},"run":{"cmd":"str","a":"str","b":"str","c":"str","flag":true},"at":{"cmd":"str"},"config_set":{"at_port":"str","wdm":"str","iface":"str"},"update_check":{}}'
|
echo '{"status":{},"modem":{},"profiles":{},"job":{},"cancel":{},"run":{"cmd":"str","a":"str","b":"str","c":"str","flag":true},"at":{"cmd":"str"},"config_set":{"at_port":"str","wdm":"str","iface":"str"},"update_check":{}}'
|
||||||
;;
|
;;
|
||||||
call)
|
call)
|
||||||
case "$2" in
|
case "$2" in
|
||||||
@ -308,6 +337,7 @@ case "$1" in
|
|||||||
modem) m_modem ;;
|
modem) m_modem ;;
|
||||||
profiles) m_profiles ;;
|
profiles) m_profiles ;;
|
||||||
job) m_job ;;
|
job) m_job ;;
|
||||||
|
cancel) m_cancel ;;
|
||||||
run) m_run ;;
|
run) m_run ;;
|
||||||
at) m_at ;;
|
at) m_at ;;
|
||||||
config_set) m_config_set ;;
|
config_set) m_config_set ;;
|
||||||
|
|||||||
@ -35,8 +35,13 @@ UQMI_BIN="$(PATH=/usr/sbin:/usr/bin:/sbin:/bin command -v uqmi)"
|
|||||||
PREPARED=0
|
PREPARED=0
|
||||||
|
|
||||||
# зависший порт не должен вешать скрипт (и страницу LuCI)
|
# зависший порт не должен вешать скрипт (и страницу LuCI)
|
||||||
TO=
|
# lpac через uqmi -m может повиснуть на cdc-wdm навсегда, если MBIM не готов
|
||||||
command -v timeout >/dev/null 2>&1 && TO="timeout 5"
|
TO= LTO= LTO_DL=
|
||||||
|
if command -v timeout >/dev/null 2>&1; then
|
||||||
|
TO="timeout 5"
|
||||||
|
LTO="timeout 90"
|
||||||
|
LTO_DL="timeout 300"
|
||||||
|
fi
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@ -97,6 +102,16 @@ reset_modem() {
|
|||||||
sleep 5
|
sleep 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# после перезагрузки модема cdc-wdm появляется позже AT-порта
|
||||||
|
wait_wdm() {
|
||||||
|
i=0
|
||||||
|
while [ ! -e "$WDM" ]; do
|
||||||
|
[ $i -ge 20 ] && die "нет $WDM после перезагрузки модема"
|
||||||
|
sleep 2
|
||||||
|
i=$((i + 1))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
ensure_esim_slot() {
|
ensure_esim_slot() {
|
||||||
if ! at "AT^SWITCH_SLOT?" | grep -q "SIM2 ENABLE"; then
|
if ! at "AT^SWITCH_SLOT?" | grep -q "SIM2 ENABLE"; then
|
||||||
msg "переключаю модем на eSIM (SIM2)"
|
msg "переключаю модем на eSIM (SIM2)"
|
||||||
@ -121,8 +136,9 @@ prepare() {
|
|||||||
[ -n "$UQMI_BIN" ] || die "не найдено: uqmi (opkg install uqmi)"
|
[ -n "$UQMI_BIN" ] || die "не найдено: uqmi (opkg install uqmi)"
|
||||||
|
|
||||||
wait_modem
|
wait_modem
|
||||||
ensure_esim_slot
|
|
||||||
|
|
||||||
|
# ModemManager - до переключения слота: иначе после перезагрузки модема он
|
||||||
|
# начинает его опрашивать, и uqmi -m потом висит на cdc-wdm
|
||||||
msg "останавливаю ModemManager"
|
msg "останавливаю ModemManager"
|
||||||
PREPARED=1
|
PREPARED=1
|
||||||
trap restore EXIT
|
trap restore EXIT
|
||||||
@ -132,6 +148,9 @@ prepare() {
|
|||||||
killall mbim-proxy uqmi 2>/dev/null
|
killall mbim-proxy uqmi 2>/dev/null
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
|
ensure_esim_slot
|
||||||
|
wait_wdm
|
||||||
|
|
||||||
mkdir -p "$WRAP_DIR"
|
mkdir -p "$WRAP_DIR"
|
||||||
printf '#!/bin/sh\nexec %s -m "$@"\n' "$UQMI_BIN" > "$WRAP_DIR/uqmi"
|
printf '#!/bin/sh\nexec %s -m "$@"\n' "$UQMI_BIN" > "$WRAP_DIR/uqmi"
|
||||||
chmod +x "$WRAP_DIR/uqmi"
|
chmod +x "$WRAP_DIR/uqmi"
|
||||||
@ -144,7 +163,10 @@ prepare() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_lpac() {
|
run_lpac() {
|
||||||
lpac "$@" > "$LOG" 2>&1
|
$LTO lpac "$@" > "$LOG" 2>&1
|
||||||
|
rc=$?
|
||||||
|
# 124 - timeout (coreutils), 143 - TERM (busybox)
|
||||||
|
case $rc in 124 | 143) echo "lpac $1 $2: нет ответа от чипа за 90 с" >> "$LOG" ;; esac
|
||||||
tail -n1 "$LOG" | grep -q '"message":"success"'
|
tail -n1 "$LOG" | grep -q '"message":"success"'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +189,7 @@ cache_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifications() {
|
notifications() {
|
||||||
lpac notification process -a -r >/dev/null 2>&1
|
$LTO lpac notification process -a -r >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
profile_state() {
|
profile_state() {
|
||||||
@ -208,6 +230,7 @@ cmd_at() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_info() {
|
cmd_info() {
|
||||||
|
msg "читаю данные чипа"
|
||||||
run_lpac chip info || die "чип не отвечает: $(lpac_err)"
|
run_lpac chip info || die "чип не отвечает: $(lpac_err)"
|
||||||
save_cache chip
|
save_cache chip
|
||||||
d="$(tail -n1 "$LOG")"
|
d="$(tail -n1 "$LOG")"
|
||||||
@ -217,6 +240,7 @@ cmd_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_list() {
|
cmd_list() {
|
||||||
|
msg "читаю список профилей"
|
||||||
run_lpac profile list || die "не удалось получить список: $(lpac_err)"
|
run_lpac profile list || die "не удалось получить список: $(lpac_err)"
|
||||||
save_cache profiles
|
save_cache profiles
|
||||||
data="$(tail -n1 "$LOG")"
|
data="$(tail -n1 "$LOG")"
|
||||||
@ -283,7 +307,7 @@ cmd_add() {
|
|||||||
[ -n "$cc" ] && set -- "$@" -c "$cc"
|
[ -n "$cc" ] && set -- "$@" -c "$cc"
|
||||||
|
|
||||||
msg "скачиваю профиль, это может занять до минуты"
|
msg "скачиваю профиль, это может занять до минуты"
|
||||||
lpac "$@" 2>&1 | tee "$LOG" | while read -r line; do
|
$LTO_DL lpac "$@" 2>&1 | tee "$LOG" | while read -r line; do
|
||||||
step="$(echo "$line" | jsonfilter -e '@.payload.message' 2>/dev/null)"
|
step="$(echo "$line" | jsonfilter -e '@.payload.message' 2>/dev/null)"
|
||||||
[ -n "$step" ] && echo " $step"
|
[ -n "$step" ] && echo " $step"
|
||||||
done
|
done
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user