feat: implement SMS storage management

This commit is contained in:
fujr 2025-02-04 15:40:55 +08:00
parent 71315c9ba8
commit e8994ab107
5 changed files with 233 additions and 4 deletions

View File

@ -537,18 +537,71 @@ class ModemSMS {
this.modem_cfg_list = []; this.modem_cfg_list = [];
this.sms_recvbox_table = new LuciTable(); this.sms_recvbox_table = new LuciTable();
this.sms_send_table = new LuciTable(); this.sms_send_table = new LuciTable();
this.sms_storage_table = new LuciTable();
this.sms_send_table.title = "<%:Send SMS%>"; this.sms_send_table.title = "<%:Send SMS%>";
this.cbi_map = document.querySelector('.cbi-map'); this.cbi_map = document.querySelector('.cbi-map');
this.cbi_map.appendChild(this.sms_storage_table.fieldset);
this.cbi_map.appendChild(this.sms_recvbox_table.fieldset); this.cbi_map.appendChild(this.sms_recvbox_table.fieldset);
this.cbi_map.appendChild(this.sms_send_table.fieldset); this.cbi_map.appendChild(this.sms_send_table.fieldset);
this.modem_selector = document.getElementById('modem_selector'); this.modem_selector = document.getElementById('modem_selector');
this.create_modem_cfg_selector(); this.create_modem_cfg_selector();
this.update_modem_cfg_list(); this.update_modem_cfg_list();
this.init_send_table_view(); this.init_send_table_view();
this.init_msg_box(); this.init_msg_box();
this.init_sms_storage_table();
} }
init_sms_storage_table() {
const createOption = (value, text, disabled = false, selected = false) => {
const opt = document.createElement('option');
opt.value = value;
opt.innerHTML = text;
opt.disabled = disabled;
opt.selected = selected;
return opt;
};
const reading_storage = document.createElement('select');
const writing_storage = document.createElement('select');
const etc_storage = document.createElement('select');
const set_storage_btn = document.createElement('input');
set_storage_btn.type = "button";
set_storage_btn.value = "Set";
set_storage_btn.onclick = () => this.set_sms_storage();
const opt_mt = createOption("ME", "<%: Mobile equipment message storage %>");
const opt_sm = createOption("SM", "<%: (U)SIM message storage %>");
const opt_loading = createOption("Loading", "<%: Loading... %>", true, true);
const storages = [reading_storage, writing_storage, etc_storage];
storages.forEach(storage => {
storage.appendChild(opt_mt.cloneNode(true));
storage.appendChild(opt_sm.cloneNode(true));
storage.appendChild(opt_loading.cloneNode(true));
storage.options[2].selected = true;
});
const data = [
{ "col": 2, "left": document.createTextNode("<%: Reading Storage%>"), "right": reading_storage },
{ "col": 2, "left": document.createTextNode("<%: Writing Storage%>"), "right": writing_storage },
{ "col": 2, "left": document.createTextNode("<%: ETC Storage%>"), "right": etc_storage },
{ "col": 2, "left": document.createTextNode("<%: Set Storage%>"), "right": set_storage_btn }
];
this.sms_storage_table.title = "<%:SMS Storage%>";
this.sms_storage_table.data = data;
this.reading_storage = reading_storage;
this.writing_storage = writing_storage;
this.etc_storage = etc_storage;
this.opt_mt1 = storages[0].querySelector('option[value="ME"]');
this.opt_sm1 = storages[0].querySelector('option[value="SM"]');
this.opt_mt2 = storages[1].querySelector('option[value="ME"]');
this.opt_sm2 = storages[1].querySelector('option[value="SM"]');
this.opt_mt3 = storages[2].querySelector('option[value="ME"]');
this.opt_sm3 = storages[2].querySelector('option[value="SM"]');
}
init_msg_box() init_msg_box()
{ {
var warn_msg_box = document.createElement('div'); var warn_msg_box = document.createElement('div');
@ -640,6 +693,26 @@ class ModemSMS {
}); });
} }
set_sms_storage(){
let payload;
let mem1,mem2,mem3;
mem1 = this.reading_storage.value;
mem2 = this.writing_storage.value;
mem3 = this.etc_storage.value;
payload = {
"mem1": mem1,
"mem2": mem2,
"mem3": mem3,
}
XHR.get('<%=luci.dispatcher.build_url("admin", "modem", "qmodem", "modem_ctrl")%>', {
"cfg": this.cfg_id,
"action":"set_sms_storage",
"params": JSON.stringify(JSON.stringify(payload))
},(x,data)=>{
this.update();
});
}
lock(){ lock(){
var delete_btns = document.querySelectorAll('input[value="<%:Delete%>"]'); var delete_btns = document.querySelectorAll('input[value="<%:Delete%>"]');
for (let btn of delete_btns) { for (let btn of delete_btns) {
@ -697,7 +770,6 @@ class ModemSMS {
} }
XHR.poll(10,'<%=luci.dispatcher.build_url("admin", "modem", "qmodem", "get_sms")%>',{ XHR.poll(10,'<%=luci.dispatcher.build_url("admin", "modem", "qmodem", "get_sms")%>',{
"cfg": this.cfg_id, "cfg": this.cfg_id,
}, (x,data) => { }, (x,data) => {
this.combine_messages(data); this.combine_messages(data);
}); });
@ -708,6 +780,7 @@ class ModemSMS {
"cfg": this.cfg_id, "cfg": this.cfg_id,
}, (x,data) => { }, (x,data) => {
this.combine_messages(data); this.combine_messages(data);
this.update_sms_capabilities(data);
}); });
} }
@ -797,6 +870,40 @@ class ModemSMS {
} }
update_sms_capabilities(data) {
const sms_capabilities = data.sms_capabilities;
const storages = [
{ mem: sms_capabilities.mem1, storage: this.reading_storage, opts: ['opt_mt1', 'opt_sm1'] },
{ mem: sms_capabilities.mem2, storage: this.writing_storage, opts: ['opt_mt2', 'opt_sm2'] },
{ mem: sms_capabilities.mem3, storage: this.etc_storage, opts: ['opt_mt3', 'opt_sm3'] }
];
const updateStorage = (mem, storage, mtOpt, smOpt) => {
let mt = "", sm = "";
if (mem === "MT" || mem === "ME") {
if (storage.value === "Loading") storage.value = "ME";
mt = "[<%:Using%>]";
} else if (mem === "SM") {
if (storage.value === "Loading") storage.value = "SM";
sm = "[<%:Using%>]";
} else {
storage.value = "Loading";
}
this[mtOpt].innerHTML = mt + me_message_text;
this[smOpt].innerHTML = sm + sm_message_text;
};
const me_message_text = sms_capabilities.ME.used
? `<%: Mobile equipment message storage %> <%: (Used/Total) %>(${sms_capabilities.ME.used}/${sms_capabilities.ME.total})`
: "<%: Mobile equipment message storage %>";
const sm_message_text = sms_capabilities.SM.used
? `<%: (U)SIM message storage %> <%: (Used/Total) %>(${sms_capabilities.SM.used}/${sms_capabilities.SM.total})`
: "<%: (U)SIM message storage %>";
storages.forEach(({ mem, storage, opts }) => updateStorage(mem, storage, opts[0], opts[1]));
}
set cfg_options(value){ set cfg_options(value){
var longger = this.modem_cfg_list.length > value.length ? this.modem_cfg_list : value; var longger = this.modem_cfg_list.length > value.length ? this.modem_cfg_list : value;
if (longger.length == 0) { if (longger.length == 0) {
@ -910,6 +1017,7 @@ window.onload = function(){
<div> <div>
<div class="cbi-map"> <div class="cbi-map">
<fieldset class="cbi-section"> <fieldset class="cbi-section">
<table class="table"> <table class="table">
<tbody> <tbody>
<tr class="tr"> <tr class="tr">

View File

@ -25,3 +25,33 @@ msgstr "短信内容"
msgid "Phone Number" msgid "Phone Number"
msgstr "电话号码" msgstr "电话号码"
msgid "Send SMS Failed"
msgstr "发送短信失败"
msgid "Send SMS Success"
msgstr "发送短信成功"
msgid "SMS Storage"
msgstr "短信存储"
msgid "Set Storage"
msgstr "设置存储"
msgid "ETC Storage"
msgstr "ETC存储"
msgid "Writing Storage"
msgstr "写入存储"
msgid "Reading Storage"
msgstr "读取存储"
msgid "Loading..."
msgstr "加载中..."
msgid "(U)SIM message storage"
msgstr "(U)SIM短信存储"
msgid "Mobile equipment message storage"
msgstr "移动设备短信存储"

View File

@ -31,3 +31,27 @@ msgstr "发送短信失败"
msgid "Send SMS Success" msgid "Send SMS Success"
msgstr "发送短信成功" msgstr "发送短信成功"
msgid "SMS Storage"
msgstr "短信存储"
msgid "Set Storage"
msgstr "设置存储"
msgid "ETC Storage"
msgstr "ETC存储"
msgid "Writing Storage"
msgstr "写入存储"
msgid "Reading Storage"
msgstr "读取存储"
msgid "Loading..."
msgstr "加载中..."
msgid "(U)SIM message storage"
msgstr "(U)SIM短信存储"
msgid "Mobile equipment message storage"
msgstr "移动设备短信存储"

View File

@ -379,6 +379,69 @@ get_modem_disabled_features()
config_list_foreach $config_section disabled_features _add_disabled_features config_list_foreach $config_section disabled_features _add_disabled_features
} }
get_sms_capabilities() {
local res sms_cap
res=$(at $at_port "AT+CPMS?" | grep "CPMS:" | xargs)
[ -z "$res" ] && return
sms_cap=${res##*+CPMS:}
set -- $(echo "$sms_cap" | tr ',' ' ')
local mem1=$1 used1=$2 total1=$3
local mem2=$4 used2=$5 total2=$6
local mem3=$7 used3=$8 total3=$9
json_add_object "sms_capabilities"
json_add_string "mem1" "$mem1"
json_add_string "mem2" "$mem2"
json_add_string "mem3" "$mem3"
json_add_object "ME"
json_close_object
json_add_object "SM"
json_close_object
for idx in 1 2 3; do
eval "mem=\$mem$idx"
eval "used=\$used$idx"
eval "total=\$total$idx"
case "$mem" in
"SM")
json_select "SM"
;;
"MT"|"ME")
json_select "ME"
;;
*)
continue
;;
esac
json_add_string "used" "$used"
json_add_string "total" "$total"
json_close_object
done
}
set_sms_storage()
{
mem1=$(echo $1 | jq -r '.mem1')
mem2=$(echo $1 | jq -r '.mem2')
mem3=$(echo $1 | jq -r '.mem3')
json_add_string "raw" "$1"
if [ -z "$mem1" ] || [ -z "$mem2" ]; then
return
fi
if [ "$mem3" == "Loading" ];then
res=$(at $at_port "AT+CPMS=\"$mem1\",\"$mem2\"")
else
res=$(at $at_port "AT+CPMS=\"$mem1\",\"$mem2\",\"$mem3\"")
fi
json_select "result"
json_add_string "result" "$res"
}
get_global_disabled_features() get_global_disabled_features()
{ {
. /lib/functions.sh . /lib/functions.sh

View File

@ -55,13 +55,14 @@ get_sms(){
current_time=$(date +%s) current_time=$(date +%s)
file_time=$(stat -t $cache_file | awk '{print $14}') file_time=$(stat -t $cache_file | awk '{print $14}')
[ -z "$file_time" ] && file_time=0 [ -z "$file_time" ] && file_time=0
get_sms_capabilities
if [ ! -f $cache_file ] || [ $(($current_time - $file_time)) -gt $cache_timeout ]; then if [ ! -f $cache_file ] || [ $(($current_time - $file_time)) -gt $cache_timeout ]; then
touch $cache_file touch $cache_file
#sms_tool_q -d $at_port -j recv > $cache_file #sms_tool_q -d $at_port -j recv > $cache_file
tom_modem -d $at_port -o r > $cache_file tom_modem -d $at_port -o r > $cache_file
cat $cache_file echo $(cat $cache_file ; json_dump) | jq -s 'add'
else else
cat $cache_file echo $(cat $cache_file ; json_dump) | jq -s 'add'
fi fi
} }
@ -170,6 +171,9 @@ case $method in
"set_neighborcell") "set_neighborcell")
set_neighborcell $3 set_neighborcell $3
;; ;;
"set_sms_storage")
set_sms_storage $3
;;
"base_info") "base_info")
cache_file="/tmp/cache_$1_$2" cache_file="/tmp/cache_$1_$2"
try_cache 10 $cache_file base_info try_cache 10 $cache_file base_info