mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-17 05:53:03 +08:00
🦄 Sync 2026-11-13 03:09:08
This commit is contained in:
1 parent
b8837465cd
commit
be1c08bda8
255 files changed
+45916
-22815
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 9.0 KiB |
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!--
|
||||
Copyright 2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
https://github.com/4IceG
|
||||
MIT License
|
||||
-->
|
||||
<svg
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 48 48"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:c2pa="http://c2pa.org/manifest"><metadata><c2pa:manifest>AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYTozMzVkZWQzOS02MjMzLTRmMGQtOGJkMS0xZDU0NjJmMmUwYmMAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaPBlz1l48br7eDh+mpQ8BkUAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDo3MTEyMzVjYS0wYjg5LTQzYTktYmE5OC1iZjE4YjFlOWFjNzJscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNoG43hR6MDFvqfcIC5zmKzWQAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJseC1zZWxmI2p1bWJmPWMycGEuYXNzZXJ0aW9ucy9jMnBhLmluZ3JlZGllbnQudjNkaGFzaFggtx4rUw0PVjpt4Yvu7+BpM0eLIR18bBSGG6tjMbE9f/OkZmFjdGlvbngdY29tLmFudGhyb3BpYy5jbGF1ZGUucHJvdmlkZWRqcGFyYW1ldGVyc6F4H2NvbS5hbnRocm9waWMub3JpZ2luLWNvbmZpZGVuY2VndW5rbm93bmtkZXNjcmlwdGlvbnhmQ2xhdWRlIHByb3ZpZGVkIHRoaXMgZmlsZSBhdCB0aGUgcmVxdWVzdCBvZiBhIHVzZXIgYW5kIG1heSBoYXZlIGNyZWF0ZWQgb3IgbW9kaWZpZWQgdGhlIGZpbGUgY29udGVudHMubXNvZnR3YXJlQWdlbnShZG5hbWVmQ2xhdWRlcmFsbEFjdGlvbnNJbmNsdWRlZPUAAADIanVtYgAAAEBqdW1kY2JvcgARABCAAACqADibcRNjMnBhLmhhc2guZGF0YQAAAAAYYzJzaPqHgHnRswe+fOViOBfQmC4AAACAY2JvcqVjYWxnZnNoYTI1NmNwYWRMAAAAAAAAAAAAAAAAZGhhc2hYIIV8qbt4ZfO0d9P4BN6ubv5vzfsmsUPTL6Rl17FdhekNZG5hbWVuanVtYmYgbWFuaWZlc3RqZXhjbHVzaW9uc4GiZXN0YXJ0GQFEZmxlbmd0aBkeBAAAAj5qdW1iAAAAJ2p1bWRjMmNsABEAEIAAAKoAOJtxA2MycGEuY2xhaW0udjIAAAACD2Nib3KlY2FsZ2ZzaGEyNTZpc2lnbmF0dXJleE1zZWxmI2p1bWJmPS9jMnBhL3VybjpjMnBhOjMzNWRlZDM5LTYyMzMtNGYwZC04YmQxLTFkNTQ2MmYyZTBiYy9jMnBhLnNpZ25hdHVyZWppbnN0YW5jZUlEeCx4bXA6aWlkOmI1ZDE2NWRkLTEwMDUtNGEzMi1iMWZiLTdhOWZhYjMwYjMxMHJjcmVhdGVkX2Fzc2VydGlvbnODomN1cmx4LXNlbGYjanVtYmY9YzJwYS5hc3NlcnRpb25zL2MycGEuaW5ncmVkaWVudC52M2RoYXNoWCC3HitTDQ9WOm3hi+7v4GkzR4shHXxsFIYbq2MxsT1/86JjdXJseCpzZWxmI2p1bWJmPWMycGEuYXNzZXJ0aW9ucy9jMnBhLmFjdGlvbnMudjJkaGFzaFggNBwvV2XgYxSjd/iM0HrpDW729WRWlD/fDUVh9X2cxsGiY3VybHgpc2VsZiNqdW1iZj1jMnBhLmFzc2VydGlvbnMvYzJwYS5oYXNoLmRhdGFkaGFzaFggLC4J0eG7biwNswIOQRzLeUvYTh+YW/1z+pI1jDtb6mx0Y2xhaW1fZ2VuZXJhdG9yX2luZm+jZG5hbWVvQW50aHJvcGljIEZpbGVzZ3ZlcnNpb25lMS4wLjBrc3BlY1ZlcnNpb25lMi40LjAAABA4anVtYgAAAChqdW1kYzJjcwARABCAAACqADibcQNjMnBhLnNpZ25hdHVyZQAAABAIY2JvctKEWQISogEmGCFZAgowggIGMIIBjaADAgECAhRA5aAK7sI50L64g/oGQgU9Z1UTADAKBggqhkjOPQQDAzBJMRcwFQYDVQQKEw5BbnRocm9waWMsIFBCQzEuMCwGA1UEAxMlQW50aHJvcGljIENvbnRlbnQgQ3JlZGVudGlhbHMgUm9vdCBDQTAeFw0yNjA4MDcxODQzNTZaFw0yODA4MDYxOTQzNTZaMEQxFzAVBgNVBAoTDkFudGhyb3BpYywgUEJDMSkwJwYDVQQDEyBBbnRocm9waWMgQ2xhdWRlIENvbnRlbnQgU2lnbmluZzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJh6CmvLUBgFFNU0vUKlOVtE6djd17L5SuwX0LemFisBM3dkd/3cyjxFA3Qo5S46fX0/ihY0VZ7mfb9KF703t5OjWDBWMA4GA1UdDwEB/wQEAwIHgDAVBgNVHSUEDjAMBgorBgEEAYPoXgIBMAwGA1UdEwEB/wQCMAAwHwYDVR0jBBgwFoAUzlHiBIFOZFsj+OPEz5o+nMHXXMIwCgYIKoZIzj0EAwMDZwAwZAIwMXMdFJ4BetLLVY7ORuE9noqbbAZOZn/aArXyTwFAZfKrPzxF2vPoJNf1+UCdg1XGAjBwX1zd9WGqYkqmL5SFqw1QySjr1zJfpJM9+1rdDwSPLMOPOjKuiXjoU/pUUeG9RwmhY3BhZFkNngAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALine truncated
|
||||
<defs>
|
||||
<filter id="shadowBlur" x="-0.4" y="-0.4" width="1.8" height="1.8" style="color-interpolation-filters:sRGB;">
|
||||
<feGaussianBlur stdDeviation="0.8" />
|
||||
</filter>
|
||||
<filter id="edgeBlur" x="-0.05" y="-0.05" width="1.1" height="1.1" style="color-interpolation-filters:sRGB;">
|
||||
<feGaussianBlur stdDeviation="0" />
|
||||
</filter>
|
||||
<filter id="holeBlur" x="-0.6" y="-0.6" width="2.2" height="2.2" style="color-interpolation-filters:sRGB;">
|
||||
<feGaussianBlur stdDeviation="0.12" />
|
||||
</filter>
|
||||
<linearGradient id="bubbleGrad" x1="10" y1="6" x2="36" y2="42" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#ffffff" />
|
||||
<stop offset="0.55" stop-color="#f7f9ff" />
|
||||
<stop offset="1" stop-color="#e8ecfb" />
|
||||
</linearGradient>
|
||||
<radialGradient id="holeGrad" cx="0.4" cy="0.35" r="0.75">
|
||||
<stop offset="0" stop-color="#5e5e66" />
|
||||
<stop offset="1" stop-color="#48484e" />
|
||||
</radialGradient>
|
||||
</defs>
|
||||
|
||||
<!-- shadow -->
|
||||
<path
|
||||
transform="translate(0.8,2.6) translate(23,24) scale(1.03) translate(-23,-24)"
|
||||
filter="url(#shadowBlur)"
|
||||
opacity="0.45"
|
||||
fill="#000000"
|
||||
d="m 35.73393,44.152618 c -0.876207,-0.187983 -2.050476,-0.711543 -2.966961,-1.322853 -0.261833,-0.174646 -1.012787,-0.714174 -1.668787,-1.19895 -1.098972,-0.812127 -1.208734,-0.879274 -1.396364,-0.854224 -0.112,0.01495 -0.688,0.119706 -1.28,0.232785 -1.894269,0.36183 -2.508437,0.413753 -4.887273,0.413183 -1.889753,-4.53e-4 -2.232559,-0.01526 -3.112647,-0.134484 C 15.746288,40.6547 11.888231,39.060496 8.4143564,36.32639 7.6195404,35.700832 6.1300759,34.216428 5.4743401,33.396364 3.6121942,31.06756 2.3886363,28.389024 1.8863764,25.541818 1.7303585,24.657385 1.6690081,22.558422 1.7690356,21.527273 2.0580798,18.547618 3.3134932,15.524895 5.3574472,12.887273 6.0363941,12.011125 7.5446499,10.499988 8.4945455,9.744182 12.111889,6.8659597 16.674421,5.1277162 21.638264,4.7366582 22.737527,4.6500569 25.559145,4.7011071 26.56,4.825705 c 8.610298,1.071908 15.430308,5.971222 17.984727,12.91975 0.257447,0.700308 0.55447,1.822688 0.72366,2.734545 0.185584,1.000208 0.258121,3.009043 0.148815,4.121246 -0.283159,2.881175 -1.48744,5.870137 -3.364001,8.349273 -1.573764,2.07911 -3.513782,3.769894 -6.082211,5.300831 -0.439956,0.26224 -0.842559,0.51944 -0.894674,0.571555 -0.200676,0.200676 0.03189,1.652865 0.381449,2.381792 0.431962,0.900776 0.928325,1.510423 1.963402,2.411506 0.442958,0.385615 0.588865,0.544551 0.532638,0.580195 -0.129857,0.08232 -1.784178,0.04969 -2.219875,-0.04378 z" />
|
||||
|
||||
<!-- bubble body -->
|
||||
<path
|
||||
style="fill:url(#bubbleGrad);stroke:#8b97e6;stroke-width:0.9;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:stroke fill markers;filter:url(#edgeBlur)"
|
||||
d="m 35.73393,44.152618 c -0.876207,-0.187983 -2.050476,-0.711543 -2.966961,-1.322853 -0.261833,-0.174646 -1.012787,-0.714174 -1.668787,-1.19895 -1.098972,-0.812127 -1.208734,-0.879274 -1.396364,-0.854224 -0.112,0.01495 -0.688,0.119706 -1.28,0.232785 -1.894269,0.36183 -2.508437,0.413753 -4.887273,0.413183 -1.889753,-4.53e-4 -2.232559,-0.01526 -3.112647,-0.134484 C 15.746288,40.6547 11.888231,39.060496 8.4143564,36.32639 7.6195404,35.700832 6.1300759,34.216428 5.4743401,33.396364 3.6121942,31.06756 2.3886363,28.389024 1.8863764,25.541818 1.7303585,24.657385 1.6690081,22.558422 1.7690356,21.527273 2.0580798,18.547618 3.3134932,15.524895 5.3574472,12.887273 6.0363941,12.011125 7.5446499,10.499988 8.4945455,9.744182 12.111889,6.8659597 16.674421,5.1277162 21.638264,4.7366582 22.737527,4.6500569 25.559145,4.7011071 26.56,4.825705 c 8.610298,1.071908 15.430308,5.971222 17.984727,12.91975 0.257447,0.700308 0.55447,1.822688 0.72366,2.734545 0.185584,1.000208 0.258121,3.009043 0.148815,4.121246 -0.283159,2.881175 -1.48744,5.870137 -3.364001,8.349273 -1.573764,2.07911 -3.513782,3.769894 -6.082211,5.300831 -0.439956,0.26224 -0.842559,0.51944 -0.894674,0.571555 -0.200676,0.200676 0.03189,1.652865 0.381449,2.381792 0.431962,0.900776 0.928325,1.510423 1.963402,2.411506 0.442958,0.385615 0.588865,0.544551 0.532638,0.580195 -0.129857,0.08232 -1.784178,0.04969 -2.219875,-0.04378 z" />
|
||||
|
||||
<!-- holes -->
|
||||
<g fill="url(#holeGrad)" stroke="none" filter="url(#holeBlur)">
|
||||
<ellipse cx="12.6" cy="23.25" rx="3.6" ry="3.4" />
|
||||
<ellipse cx="23.5" cy="23.25" rx="3.6" ry="3.4" />
|
||||
<ellipse cx="34.1" cy="23.25" rx="3.6" ry="3.4" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,212 @@
|
||||
'use strict';
|
||||
'require fs';
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require view';
|
||||
|
||||
/*
|
||||
Copyright 2022-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
document.head.append(E('style', {'type': 'text/css'},
|
||||
`
|
||||
#callLogTable {
|
||||
width: 100%;
|
||||
border: 1px solid var(--border-color-medium) !important;
|
||||
}
|
||||
|
||||
#callLogTable th,
|
||||
#callLogTable td {
|
||||
padding: 10px;
|
||||
text-align: justify !important;
|
||||
vertical-align: top !important;
|
||||
}
|
||||
|
||||
#callLogTable tr:nth-child(odd) td {
|
||||
background: var(--background-color-medium) !important;
|
||||
border-bottom: 1px solid var(--border-color-medium) !important;
|
||||
border-top: 1px solid var(--border-color-medium) !important;
|
||||
}
|
||||
|
||||
#callLogTable tr:nth-child(even) td {
|
||||
border-bottom: 1px solid var(--border-color-medium) !important;
|
||||
border-top: 1px solid var(--border-color-medium) !important;
|
||||
}
|
||||
|
||||
#callLogTable .date {
|
||||
width: 25% !important;
|
||||
}
|
||||
|
||||
#callLogTable .call-type {
|
||||
width: 15% !important;
|
||||
}
|
||||
|
||||
#callLogTable .number {
|
||||
width: 25% !important;
|
||||
}
|
||||
|
||||
#callLogTable .duration {
|
||||
width: 15% !important;
|
||||
}
|
||||
|
||||
#callLogTable .name {
|
||||
width: 20% !important;
|
||||
}
|
||||
`));
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
uci.load('sms_tool_js'),
|
||||
L.resolveDefault(fs.read('/tmp/sms_tool_call_log.json'), '{"calls":[]}')
|
||||
]);
|
||||
},
|
||||
|
||||
handleRefresh: function() {
|
||||
location.reload();
|
||||
},
|
||||
|
||||
handleClear: function() {
|
||||
if (confirm(_('Clear all call log entries?'))) {
|
||||
return Promise.all([
|
||||
fs.write('/tmp/sms_tool_call_log.json', '{"calls":[]}'),
|
||||
fs.write('/tmp/sms_tool_call_log.lines', '')
|
||||
]).then(function() {
|
||||
this.handleRefresh();
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
setTableMessage: function(message, spinning) {
|
||||
let table = document.getElementById('callLogTable');
|
||||
if (!table)
|
||||
return;
|
||||
|
||||
while (table.rows.length > 1)
|
||||
table.deleteRow(1);
|
||||
|
||||
let row = table.insertRow(-1);
|
||||
let cell = row.insertCell(0);
|
||||
cell.colSpan = 5;
|
||||
cell.style.textAlign = 'center';
|
||||
cell.appendChild(E('span', spinning ? { 'class': 'spinning' } : {}, message));
|
||||
},
|
||||
|
||||
updateCallLogTable: function(calls) {
|
||||
let table = document.getElementById('callLogTable');
|
||||
if (!table)
|
||||
return;
|
||||
|
||||
while (table.rows.length > 1)
|
||||
table.deleteRow(1);
|
||||
|
||||
if (!calls || !calls.length) {
|
||||
this.setTableMessage(_('No call log entries found'), false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter by type if needed, but for now show all
|
||||
let select = document.getElementById('call-log-type');
|
||||
let filter = select ? select.value : 'all';
|
||||
|
||||
for (let i = 0; i < calls.length; i++) {
|
||||
if (filter !== 'all' && calls[i].type.toLowerCase() !== filter)
|
||||
continue;
|
||||
|
||||
let row = table.insertRow(-1);
|
||||
row.insertCell(0).textContent = calls[i].date;
|
||||
row.insertCell(1).textContent = _(calls[i].type);
|
||||
row.insertCell(2).textContent = calls[i].number;
|
||||
row.insertCell(3).textContent = calls[i].duration;
|
||||
row.insertCell(4).textContent = '-'; // Name lookup could be added later
|
||||
}
|
||||
|
||||
if (table.rows.length === 1) {
|
||||
this.setTableMessage(_('No matching call log entries found'), false);
|
||||
}
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
let callLogData;
|
||||
|
||||
try {
|
||||
callLogData = JSON.parse(data[1] || '{"calls":[]}');
|
||||
}
|
||||
catch (e) {
|
||||
callLogData = { calls: [] };
|
||||
}
|
||||
|
||||
let calls = callLogData.calls || [];
|
||||
|
||||
let calllog_enabled = uci.get('sms_tool_js', '@sms_tool_js[0]', 'calllog_enabled') === '1';
|
||||
|
||||
setTimeout(function() {
|
||||
this.updateCallLogTable(calls);
|
||||
}.bind(this), 100);
|
||||
|
||||
return E([], [
|
||||
E('h2', _('Call Log')),
|
||||
E('div', { 'class': 'cbi-map-descr' }, _('User interface for viewing call logs. The log is collected by a background daemon.')),
|
||||
|
||||
(function() {
|
||||
if (!calllog_enabled) {
|
||||
return E('div', { 'class': 'alert-message warning' }, [
|
||||
E('p', {}, _('Call log daemon is disabled. Please enable it in the configuration to start collecting logs.'))
|
||||
]);
|
||||
}
|
||||
return E('div', { 'style': 'display: none;' });
|
||||
})(),
|
||||
|
||||
E('h3', _('Calls')),
|
||||
E('table', { 'class': 'table' }, [
|
||||
E('tr', { 'class': 'tr' }, [
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ _('Filter call type') ]),
|
||||
E('td', { 'class': 'td' }, [
|
||||
E('select', {
|
||||
'class': 'cbi-input-select',
|
||||
'id': 'call-log-type',
|
||||
'change': function() {
|
||||
this.updateCallLogTable(calls);
|
||||
}.bind(this)
|
||||
}, [
|
||||
E('option', { 'value': 'all' }, _('All calls')),
|
||||
E('option', { 'value': 'missed' }, _('Missed calls')),
|
||||
E('option', { 'value': 'received' }, _('Received calls')),
|
||||
E('option', { 'value': 'dialed' }, _('Dialed calls'))
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
E('div', { 'class': 'right' }, [
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
'click': ui.createHandlerFn(this, 'handleRefresh')
|
||||
}, [ _('Refresh') ]),
|
||||
' ',
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-remove',
|
||||
'click': ui.createHandlerFn(this, 'handleClear')
|
||||
}, [ _('Clear Log') ])
|
||||
]),
|
||||
|
||||
E('p'),
|
||||
|
||||
E('table', { 'class': 'table', 'id': 'callLogTable' }, [
|
||||
E('tr', { 'class': 'tr table-titles' }, [
|
||||
E('th', { 'class': 'th date' }, _('Date')),
|
||||
E('th', { 'class': 'th call-type' }, _('Type')),
|
||||
E('th', { 'class': 'th number' }, _('Number')),
|
||||
E('th', { 'class': 'th duration' }, _('Duration')),
|
||||
E('th', { 'class': 'th name' }, _('Name'))
|
||||
])
|
||||
])
|
||||
]);
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
});
|
||||
@@ -5,13 +5,20 @@
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require view';
|
||||
'require rpc';
|
||||
|
||||
/*
|
||||
Copyright 2022-2025 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Copyright 2022-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
var callForwardSMS = rpc.declare({
|
||||
object: 'sms_forward',
|
||||
method: 'forward',
|
||||
params: ['subject', 'message']
|
||||
});
|
||||
|
||||
document.head.append(E('style', {'type': 'text/css'},
|
||||
`
|
||||
#smsTable {
|
||||
@@ -57,6 +64,15 @@ td input[type="checkbox"] {
|
||||
#smsTable .message {
|
||||
width: 88% !important;
|
||||
}
|
||||
|
||||
.sms-row-icon {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
:root[data-darkmode="true"] .sms-row-icon {
|
||||
opacity: 0.5;
|
||||
}
|
||||
`));
|
||||
|
||||
function msg_bar(v, m) {
|
||||
@@ -69,6 +85,114 @@ pg.firstElementChild.style.width = pc + '%';
|
||||
pg.setAttribute('title', '%s'.format(v) + ' / ' + '%s'.format(m) + ' ('+ pc + '%)');
|
||||
}
|
||||
|
||||
function popTimeout(a, message, timeout, severity) {
|
||||
ui.addTimeLimitedNotification(a, message, timeout, severity);
|
||||
}
|
||||
|
||||
|
||||
function format_with_modem_index(value) {
|
||||
return uci.load('defmodems').then(function() {
|
||||
var defmodemSections = uci.sections('defmodems', 'defmodems');
|
||||
|
||||
if (!defmodemSections || defmodemSections.length === 0) {
|
||||
// old format
|
||||
return value;
|
||||
}
|
||||
|
||||
var serialModems = defmodemSections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) {
|
||||
// old format
|
||||
return value;
|
||||
}
|
||||
|
||||
var currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'readport');
|
||||
|
||||
var modemIndex = -1;
|
||||
for (var i = 0; i < serialModems.length; i++) {
|
||||
if (serialModems[i].comm_port === currentPort) {
|
||||
modemIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (modemIndex === -1) {
|
||||
// old format
|
||||
return value;
|
||||
}
|
||||
|
||||
return 'dfm' + modemIndex + '_' + value;
|
||||
|
||||
}).catch(function() {
|
||||
// old format
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
function update_sms_count_for_modem(newValue) {
|
||||
return uci.load('defmodems').then(function() {
|
||||
var defmodemSections = uci.sections('defmodems', 'defmodems');
|
||||
|
||||
if (!defmodemSections || defmodemSections.length === 0) {
|
||||
// old format
|
||||
return newValue;
|
||||
}
|
||||
|
||||
var serialModems = defmodemSections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) {
|
||||
// old format
|
||||
return newValue;
|
||||
}
|
||||
|
||||
var currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'readport');
|
||||
var currentModemIndex = -1;
|
||||
|
||||
for (var i = 0; i < serialModems.length; i++) {
|
||||
if (serialModems[i].comm_port === currentPort) {
|
||||
currentModemIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentModemIndex === -1) {
|
||||
// old format
|
||||
return newValue;
|
||||
}
|
||||
|
||||
var existingSmsCount = uci.get('sms_tool_js', '@sms_tool_js[0]', 'sms_count') || '';
|
||||
var parts = existingSmsCount.split(' ').filter(function(p) { return p.trim() !== ''; });
|
||||
|
||||
var updated = {};
|
||||
parts.forEach(function(part) {
|
||||
var match = part.match(/^dfm(\d+)_(\d+)$/);
|
||||
if (match) {
|
||||
var modemIdx = parseInt(match[1]);
|
||||
if (modemIdx > 0 && modemIdx <= serialModems.length) {
|
||||
updated[modemIdx] = match[2];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
updated[currentModemIndex] = newValue;
|
||||
|
||||
var result = [];
|
||||
for (var i = 1; i <= serialModems.length; i++) {
|
||||
var count = updated[i] || '0';
|
||||
result.push('dfm' + i + '_' + count);
|
||||
}
|
||||
|
||||
return result.join(' ');
|
||||
|
||||
}).catch(function() {
|
||||
// old format
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
|
||||
function save_count() {
|
||||
uci.load('sms_tool_js').then(function() {
|
||||
@@ -83,9 +207,12 @@ function save_count() {
|
||||
var t = total.replace ( /[^\d.]/g, '' );
|
||||
var used = res.substring(17, res.indexOf("total"));
|
||||
var u = used.replace ( /[^\d.]/g, '' );
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', L.toArray(u).join(' '));
|
||||
uci.save();
|
||||
uci.apply();
|
||||
|
||||
update_sms_count_for_modem(u).then(function(updatedValue) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', updatedValue);
|
||||
uci.save();
|
||||
uci.apply();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -93,7 +220,44 @@ function save_count() {
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
uci.load('sms_tool_js');
|
||||
return Promise.all([
|
||||
uci.load('sms_tool_js'),
|
||||
L.resolveDefault(uci.load('defmodems'))
|
||||
]);
|
||||
},
|
||||
|
||||
handleModemChange: function(ev) {
|
||||
var sections = uci.sections('defmodems', 'defmodems');
|
||||
if (!sections || sections.length === 0) return;
|
||||
|
||||
var serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) return;
|
||||
|
||||
var currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'readport');
|
||||
var currentIndex = serialModems.findIndex(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) currentIndex = 0;
|
||||
|
||||
var direction = ev.currentTarget.classList.contains('next') ? 1 : -1;
|
||||
var newIndex = (currentIndex + direction + serialModems.length) % serialModems.length;
|
||||
var newModem = serialModems[newIndex];
|
||||
|
||||
if (newModem && newModem.comm_port) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'readport', newModem.comm_port);
|
||||
uci.save();
|
||||
uci.apply().then(function() {
|
||||
var modemText = document.querySelector('.modem-display-text');
|
||||
if (modemText) {
|
||||
var label = newModem.modem + (newModem.user_desc ? ' (' + newModem.user_desc + ')' : '');
|
||||
modemText.textContent = label;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
handleSWarea: function(ev) {
|
||||
@@ -111,9 +275,142 @@ return view.extend({
|
||||
}
|
||||
},
|
||||
|
||||
handleForward: function(ev) {
|
||||
var checked = document.querySelectorAll('input[name="smsn"]:checked');
|
||||
|
||||
if (checked.length === 0) {
|
||||
ui.addNotification(null, E('p', _('Please select the message(s) to be forwarded')), 'info');
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
uci.load('sms_tool_js').then(function() {
|
||||
var fwdEnabled = uci.get('sms_tool_js', '@sms_tool_js[0]', 'forward_sms_enabled');
|
||||
|
||||
if (fwdEnabled !== '1') {
|
||||
ui.addNotification(null, E('p', _('SMS forwarding function is not enabled')), 'info');
|
||||
return;
|
||||
}
|
||||
|
||||
var emailSubject = '';
|
||||
var emailBody = '';
|
||||
|
||||
if (checked.length === 1) {
|
||||
var row = checked[0].closest('tr');
|
||||
var cells = row.cells;
|
||||
|
||||
var sender = cells[1].textContent.trim();
|
||||
var timestamp = cells[2].textContent.trim();
|
||||
var message = cells[3].textContent.trim();
|
||||
|
||||
emailSubject = 'SMS ' + timestamp + ' - ' + sender;
|
||||
emailBody = message;
|
||||
|
||||
self.showEmailModal(emailSubject, emailBody);
|
||||
}
|
||||
else {
|
||||
uci.load('system').then(function() {
|
||||
var hostname = uci.get('system', '@system[0]', 'hostname') || _('My Router');
|
||||
|
||||
var messages = [];
|
||||
checked.forEach(function(checkbox) {
|
||||
var row = checkbox.closest('tr');
|
||||
var cells = row.cells;
|
||||
|
||||
var timestamp = cells[2].textContent.trim();
|
||||
var sender = cells[1].textContent.trim();
|
||||
var message = cells[3].textContent.trim();
|
||||
|
||||
messages.push(timestamp + ' - ' + sender + '\n' + message);
|
||||
});
|
||||
|
||||
var emailBody = messages.join('\n\n');
|
||||
|
||||
self.showEmailModal(hostname, emailBody);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showEmailModal: function(defaultSubject, defaultBody) {
|
||||
var self = this;
|
||||
|
||||
ui.showModal(_('Forward SMS to E-mail'), [
|
||||
E('p', _('Subject:')),
|
||||
E('input', {
|
||||
'type': 'text',
|
||||
'id': 'email-subject',
|
||||
'class': 'cbi-input-text',
|
||||
'style': 'width: 100% !important; margin-bottom: 15px;',
|
||||
'value': defaultSubject
|
||||
}),
|
||||
E('p', _('Message text:')),
|
||||
E('textarea', {
|
||||
'id': 'email-body',
|
||||
'class': 'cbi-input-textarea',
|
||||
'style': 'width: 100% !important; height: 30vh; min-height: 250px;',
|
||||
'wrap': 'off',
|
||||
'spellcheck': 'false'
|
||||
}, defaultBody),
|
||||
E('div', { 'class': 'right' }, [
|
||||
E('button', {
|
||||
'class': 'btn',
|
||||
'click': ui.hideModal
|
||||
}, _('Cancel')), ' ',
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-action important',
|
||||
'click': ui.createHandlerFn(this, 'sendEmailFromModal')
|
||||
}, _('Send'))
|
||||
])
|
||||
], 'cbi-modal');
|
||||
},
|
||||
|
||||
sendEmailFromModal: function() {
|
||||
var subject = document.getElementById('email-subject').value;
|
||||
var body = document.getElementById('email-body').value;
|
||||
|
||||
if (!subject || !body) {
|
||||
ui.addNotification(null, E('p', _('Subject and body cannot be empty')), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
ui.hideModal();
|
||||
|
||||
var contentArea = document.getElementById('forward-status');
|
||||
contentArea.style.display = 'block';
|
||||
contentArea.innerHTML = '';
|
||||
contentArea.appendChild(E('div', {'class': 'alert alert-info'},
|
||||
E('span', {'class': 'spinning'}, _('Sending e-mail...'))
|
||||
));
|
||||
|
||||
callForwardSMS(subject, body).then(function(response) {
|
||||
contentArea.innerHTML = '';
|
||||
if (response.success) {
|
||||
popTimeout(null, E('p', _('Message forwarded successfully')), 5000, 'info');
|
||||
setTimeout(function() {
|
||||
if (contentArea) {
|
||||
contentArea.innerHTML = '';
|
||||
contentArea.style.display = 'none';
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
contentArea.innerHTML = '';
|
||||
contentArea.style.display = 'none';
|
||||
ui.addNotification(null, E('p', _('Failed to forward message: %s').format(response.error || 'Unknown error')), 'error');
|
||||
}
|
||||
}).catch(function(err) {
|
||||
contentArea.innerHTML = '';
|
||||
contentArea.style.display = 'none';
|
||||
ui.addNotification(null, E('p', _('Error: %s').format(err.message)), 'error');
|
||||
});
|
||||
},
|
||||
|
||||
handleDelete: function(ev) {
|
||||
if (document.querySelectorAll('input[name="smsn"]:checked').length == 0){
|
||||
ui.addNotification(null, E('p', _('Please select the message(s) to be deleted')), 'info');
|
||||
ui.addNotification(null, E('p', _('Please select the message(s) to be deleted')), 'info');
|
||||
}
|
||||
else {
|
||||
if (document.querySelectorAll('input[name="smsn"]:checked').length === document.querySelectorAll('input[name="smsn"]').length) {
|
||||
@@ -194,14 +491,14 @@ return view.extend({
|
||||
inumber = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var deletelabel = document.getElementById("deleteinfo");
|
||||
deletelabel.style.display = 'block';
|
||||
|
||||
for (var i=0; i < smsnr.length + 2; i++)
|
||||
{
|
||||
(function(i) {
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
smsnr[i] = parseInt(smsnr[i], 10);
|
||||
|
||||
if (!Number.isNaN(smsnr[i]))
|
||||
@@ -216,10 +513,11 @@ return view.extend({
|
||||
var used = res.substring(17, res.indexOf("total"));
|
||||
var u = used.replace ( /[^\d.]/g, '' );
|
||||
msg_bar(Math.floor(u), t);
|
||||
deletelabel.innerHTML = _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages');
|
||||
deletelabel.innerHTML = '';
|
||||
deletelabel.appendChild(E('span', {'class': 'spinning', 'style': 'font-size: inherit;'}, _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages')));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
L.resolveDefault(fs.exec_direct('/usr/bin/sms_tool', [ '-s' , storeL , '-d' , portR , 'status' ]))
|
||||
.then(function(res) {
|
||||
@@ -229,14 +527,34 @@ return view.extend({
|
||||
var used = res.substring(17, res.indexOf("total"));
|
||||
var u = used.replace ( /[^\d.]/g, '' );
|
||||
msg_bar(Math.floor(u), t);
|
||||
deletelabel.innerHTML = _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages');
|
||||
deletelabel.innerHTML = '';
|
||||
deletelabel.appendChild(E('span', {'class': 'spinning', 'style': 'font-size: inherit;'}, _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages')));
|
||||
}
|
||||
});
|
||||
|
||||
if (smsdelcount == smsdeleted) {
|
||||
setTimeout(function() {
|
||||
var hidecount = document.getElementById('deleteinfo');
|
||||
hidecount.style.display = 'none';
|
||||
uci.load('sms_tool_js').then(function() {
|
||||
var savedCount = uci.get('sms_tool_js', '@sms_tool_js[0]', 'sms_count') || '';
|
||||
L.resolveDefault(fs.exec_direct('/usr/bin/sms_tool', [ '-s' , storeL , '-d' , portR , 'status' ]))
|
||||
.then(function(verifyRes) {
|
||||
if (verifyRes) {
|
||||
var verifyUsed = verifyRes.substring(17, verifyRes.indexOf("total"));
|
||||
var verifyU = verifyUsed.replace( /[^\d.]/g, '' );
|
||||
var savedMatch = savedCount.match(/(?:dfm\d+_)?(\d+)(?:\s|$)/);
|
||||
var savedNum = savedMatch ? savedMatch[1] : savedCount.replace(/[^\d]/g, '');
|
||||
if (savedNum !== verifyU) {
|
||||
update_sms_count_for_modem(verifyU).then(function(correctedValue) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', correctedValue);
|
||||
uci.save();
|
||||
uci.apply();
|
||||
});
|
||||
}
|
||||
}
|
||||
hidecount.style.display = 'none';
|
||||
});
|
||||
});
|
||||
save_count();
|
||||
}, 7000);
|
||||
}
|
||||
@@ -250,7 +568,8 @@ return view.extend({
|
||||
var used = res.substring(17, res.indexOf("total"));
|
||||
var u = used.replace ( /[^\d.]/g, '' );
|
||||
msg_bar(Math.floor(u), t);
|
||||
deletelabel.innerHTML = _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages');
|
||||
deletelabel.innerHTML = '';
|
||||
deletelabel.appendChild(E('span', {'class': 'spinning', 'style': 'font-size: inherit;'}, _('Please wait... deleted')+' '+smsdeleted+' '+_('of')+' '+smsdelcount+' '+_('selected messages')));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -271,23 +590,21 @@ return view.extend({
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
handleRefresh: function(ev) {
|
||||
window.location.reload();
|
||||
},
|
||||
|
||||
|
||||
handleSelect: function(ev) {
|
||||
var checkBox = document.getElementById("ch-all");
|
||||
var checkBoxes = document.querySelectorAll('input[type="checkbox"]');
|
||||
var checkBoxes = document.querySelectorAll('input[name="smsn"]');
|
||||
|
||||
if (checkBox.checked == true){
|
||||
for (var i = 0; i < checkBoxes.length; i++)
|
||||
checkBoxes[i].setAttribute('checked', 'true');
|
||||
checkBoxes[i].checked = true;
|
||||
} else {
|
||||
for (var i = 0; i < checkBoxes.length; i++)
|
||||
checkBoxes[i].removeAttribute('checked');
|
||||
checkBoxes[i].checked = false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -313,7 +630,7 @@ return view.extend({
|
||||
<ul><li>1. All ports for communication with the modem.</li><li>2. Additional options specific to the given modem (for handling USSD codes).</li><li> \
|
||||
3. Notification LED (optional).</li><li><ul>')), 'info');
|
||||
}
|
||||
|
||||
|
||||
var sections = uci.sections('sms_tool_js');
|
||||
var led = sections[0].smsled;
|
||||
|
||||
@@ -348,7 +665,7 @@ return view.extend({
|
||||
if (res2) {
|
||||
|
||||
var table = document.getElementById('smsTable');
|
||||
while (table.rows.length > 1) { table.deleteRow(1); }
|
||||
while (table.rows.length > 1) { table.deleteRow(1); }
|
||||
|
||||
var start = res2.substring(7);
|
||||
var end = start.substring(0,start.length-2);
|
||||
@@ -409,7 +726,8 @@ return view.extend({
|
||||
combinedjson[newkey] = { sender, timestamp, total, content, index };
|
||||
}
|
||||
}
|
||||
var result = Object.values(combinedjson); }
|
||||
var result = Object.values(combinedjson);
|
||||
}
|
||||
|
||||
if (algo == "Simple")
|
||||
{
|
||||
@@ -422,7 +740,7 @@ return view.extend({
|
||||
return;
|
||||
}
|
||||
if (this[o.sender].total == o.total && this[o.sender].timestamp == o.timestamp && this[o.sender].sender == o.sender && this[o.sender].part > 0) {
|
||||
this[o.sender].index += '-' + o.index;
|
||||
this[o.sender].index += '-' + o.index;
|
||||
this[o.sender].content += o.content;}
|
||||
else {
|
||||
this[o.sender] = { index: o.index, sender: o.sender, timestamp: o.timestamp, part: o.part, total: o.total, content: o.content };
|
||||
@@ -432,8 +750,7 @@ return view.extend({
|
||||
}, Object.create(null));
|
||||
}
|
||||
if (u){
|
||||
var Lres = L.resource('icons/newdelsms.png');
|
||||
var iconz = String.format('<img style="width: 24px; height: 24px; "src="%s"/>', Lres);
|
||||
var Lres = L.resource('icons/redrawsms.svg');
|
||||
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
var row = table.insertRow(-1);
|
||||
@@ -441,14 +758,27 @@ return view.extend({
|
||||
var cell2 = row.insertCell(0);
|
||||
var cell3 = row.insertCell(0);
|
||||
var cell4 = row.insertCell(0);
|
||||
cell4.innerHTML = "<input type='checkbox' name='smsn' id="+result[i].index+","+" />"+iconz;
|
||||
|
||||
var checkbox = E('input', {
|
||||
'type': 'checkbox',
|
||||
'name': 'smsn',
|
||||
'id': result[i].index + ','
|
||||
});
|
||||
var icon = E('span', { 'class': 'sms-row-icon' }, [
|
||||
E('img', {
|
||||
'src': Lres,
|
||||
'style': 'width: 24px; height: 24px;'
|
||||
})
|
||||
]);
|
||||
cell4.appendChild(checkbox);
|
||||
cell4.appendChild(icon);
|
||||
if (result[i].sender.includes(hide)) {
|
||||
var removeLast5 = result[i].sender.slice(0, -5);
|
||||
cell3.innerHTML = removeLast5 + '#####';
|
||||
} else {
|
||||
cell3.innerHTML = result[i].sender;
|
||||
}
|
||||
|
||||
|
||||
cell2.innerHTML = result[i].timestamp;
|
||||
cell1.innerHTML = result[i].content.replace(/\s+/g, ' ').trim();
|
||||
aidx.push(result[i].index+'-');
|
||||
@@ -458,10 +788,18 @@ return view.extend({
|
||||
axx = axx.replace(/,/g, ' ');
|
||||
axx = axx.replace(/-/g, ' ');
|
||||
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count_index', L.toArray(axx).join(' '));
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', L.toArray(u).join(' '));
|
||||
uci.save();
|
||||
uci.apply();
|
||||
var axx = aidx.toString();
|
||||
axx = axx.replace(/,/g, ' ');
|
||||
axx = axx.replace(/-/g, ' ');
|
||||
|
||||
format_with_modem_index(axx).then(function(formattedIndex) {
|
||||
update_sms_count_for_modem(u).then(function(updatedCount) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count_index', formattedIndex);
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', updatedCount);
|
||||
uci.save();
|
||||
uci.apply();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -469,7 +807,7 @@ return view.extend({
|
||||
|
||||
/* No merging messages */
|
||||
if (smsM == "0") {
|
||||
|
||||
|
||||
/* Sorting messages by delivery time */
|
||||
var sortbyTime = json.sort((function (a, b) { return new Date(b.timestamp) - new Date(a.timestamp) }));
|
||||
|
||||
@@ -484,16 +822,28 @@ return view.extend({
|
||||
|
||||
if (u){
|
||||
|
||||
var Lres = L.resource('icons/newdelsms.png');
|
||||
var iconz = String.format('<img style="width: 24px; height: 24px; "src="%s"/>', Lres);
|
||||
var Lres = L.resource('icons/redrawsms.svg');
|
||||
|
||||
for (var i = 0; i < sortedData.length; i++) {
|
||||
var row = table.insertRow(-1);
|
||||
var row = table.insertRow(-1);
|
||||
var cell1 = row.insertCell(0);
|
||||
var cell2 = row.insertCell(0);
|
||||
var cell3 = row.insertCell(0);
|
||||
var cell4 = row.insertCell(0);
|
||||
cell4.innerHTML = "<input type='checkbox' name='smsn' id="+sortedData[i].index+","+" />"+iconz;
|
||||
|
||||
var checkbox = E('input', {
|
||||
'type': 'checkbox',
|
||||
'name': 'smsn',
|
||||
'id': sortedData[i].index + ','
|
||||
});
|
||||
var icon = E('span', { 'class': 'sms-row-icon' }, [
|
||||
E('img', {
|
||||
'src': Lres,
|
||||
'style': 'width: 24px; height: 24px;'
|
||||
})
|
||||
]);
|
||||
cell4.appendChild(checkbox);
|
||||
cell4.appendChild(icon);
|
||||
if (sortedData[i].sender.includes(hide)) {
|
||||
var removeLast5 = sortedData[i].sender.slice(0, -5);
|
||||
cell3.innerHTML = removeLast5 + '#####';
|
||||
@@ -503,17 +853,21 @@ return view.extend({
|
||||
cell2.innerHTML = sortedData[i].timestamp;
|
||||
cell1.innerHTML = sortedData[i].content.replace(/\s+/g, ' ').trim();
|
||||
aidx.push(sortedData[i].index+'-');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
var axx = aidx.toString();
|
||||
axx = axx.replace(/,/g, ' ');
|
||||
axx = axx.replace(/-/g, ' ');
|
||||
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count_index', L.toArray(axx).join(' '));
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', L.toArray(u).join(' '));
|
||||
uci.save();
|
||||
uci.apply();
|
||||
format_with_modem_index(axx).then(function(formattedIndex) {
|
||||
update_sms_count_for_modem(u).then(function(updatedCount) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count_index', formattedIndex);
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sms_count', updatedCount);
|
||||
uci.save();
|
||||
uci.apply();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -539,8 +893,60 @@ return view.extend({
|
||||
|
||||
E('h3', _('Received Messages')),
|
||||
E('table', { 'class': 'table' }, [
|
||||
E('tr', { 'class': 'tr' }, [
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ _('Message storage area') ]),
|
||||
(function() {
|
||||
var sections = uci.sections('defmodems', 'defmodems');
|
||||
var serialModems = [];
|
||||
|
||||
if (sections && sections.length > 0) {
|
||||
serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
}
|
||||
|
||||
if (serialModems.length > 0) {
|
||||
var currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'readport');
|
||||
var currentModem = serialModems.find(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (!currentModem) currentModem = serialModems[0];
|
||||
|
||||
var label = currentModem.modem + (currentModem.user_desc ? ' (' + currentModem.user_desc + ')' : '');
|
||||
|
||||
var buttonsDisabled = (serialModems.length > 1) ? null : true;
|
||||
|
||||
return E('tr', { 'class': 'tr' }, [
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ _('Select modem') ]),
|
||||
E('td', { 'class': 'td' }, [
|
||||
E('div', { 'class': 'controls' }, [
|
||||
E('div', { 'class': 'pager center', 'style': 'display: flex; align-items: center; gap: 10px;' }, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'aria-label': _('Previous modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'data-tooltip': _('Changing a modem requires refreshing the messages'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ◄ ' ]),
|
||||
E('div', { 'class': 'text modem-display-text', 'style': 'flex: 1; text-align: center;' }, [ label ]),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'aria-label': _('Next modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'data-tooltip': _('Changing a modem requires refreshing the messages'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ► ' ])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
return E('div', { 'style': 'display: none;' });
|
||||
}
|
||||
}.bind(this))(),
|
||||
E('tr', { 'class': 'tr' }, [
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ _('Message storage area') ]),
|
||||
E('td', { 'class': 'td' }, [
|
||||
E('div', [
|
||||
E('label', {
|
||||
@@ -592,19 +998,26 @@ return view.extend({
|
||||
]),
|
||||
]),
|
||||
|
||||
E('div', {'id': 'forward-status', 'style': 'margin: 10px 0; display: none;'}),
|
||||
|
||||
E('div', { 'class': 'right' }, [
|
||||
E('button', {
|
||||
//'class': 'cbi-button cbi-button-negative important',
|
||||
'class': 'cbi-button cbi-button-apply',
|
||||
'id': 'forward',
|
||||
'click': ui.createHandlerFn(this, 'handleForward')
|
||||
}, [ _('Forward SMS') ]),
|
||||
'\xa0\xa0\xa0',
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-remove',
|
||||
'id': 'execute',
|
||||
'click': ui.createHandlerFn(this, 'handleDelete')
|
||||
}, [ _('Delete message(s)') ]),
|
||||
}, [ _('Delete') ]),
|
||||
'\xa0\xa0\xa0',
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-add',
|
||||
'id': 'clr',
|
||||
'click': ui.createHandlerFn(this, 'handleRefresh')
|
||||
}, [ _('Refresh messages') ]),
|
||||
}, [ _('Refresh') ]),
|
||||
|
||||
]),
|
||||
|
||||
@@ -612,7 +1025,7 @@ return view.extend({
|
||||
|
||||
E('table', { 'class': 'table' , 'id' : 'smsTable' }, [
|
||||
E('tr', { 'class': 'tr table-titles' }, [
|
||||
E('th', { 'class': 'th checker' },
|
||||
E('th', { 'class': 'th checker' },
|
||||
E('input', {
|
||||
'id': 'ch-all',
|
||||
'type': 'checkbox',
|
||||
@@ -622,15 +1035,20 @@ return view.extend({
|
||||
'click': ui.createHandlerFn(this, 'handleSelect')
|
||||
}), '',
|
||||
),
|
||||
E('th', { 'class': 'th from' }, _('From')),
|
||||
E('th', { 'class': 'th from' }, _('Sender')),
|
||||
E('th', { 'class': 'th received' }, _('Received')),
|
||||
E('th', { 'class': 'th center message' }, _('Message'))
|
||||
])
|
||||
]),
|
||||
]);
|
||||
|
||||
return v;
|
||||
},
|
||||
|
||||
popTimeout: function(a, message, timeout, severity) {
|
||||
ui.addTimeLimitedNotification(a, message, timeout, severity);
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
|
||||
@@ -7,32 +7,52 @@
|
||||
'require view';
|
||||
|
||||
/*
|
||||
Copyright 2022-2025 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Copyright 2022-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
return view.extend({
|
||||
viewName: 'sendat',
|
||||
|
||||
restoreSettingsFromLocalStorage: function() {
|
||||
try {
|
||||
let selectedFile = localStorage.getItem('luci-app-' + this.viewName + '-selectedFile');
|
||||
return selectedFile;
|
||||
} catch(e) {
|
||||
console.error('localStorage not available:', e);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
saveSettingsToLocalStorage: function(fileName) {
|
||||
try {
|
||||
localStorage.setItem('luci-app-' + this.viewName + '-selectedFile', fileName);
|
||||
} catch(e) {
|
||||
console.error('localStorage not available:', e);
|
||||
}
|
||||
},
|
||||
|
||||
handleCommand: function(exec, args) {
|
||||
let buttons = document.querySelectorAll('.cbi-button');
|
||||
|
||||
for (let i = 0; i < buttons.length; i++)
|
||||
buttons[i].setAttribute('disabled', 'true');
|
||||
|
||||
|
||||
return fs.exec(exec, args).then(function(res) {
|
||||
let out = document.querySelector('.atcommand-output');
|
||||
out.style.display = '';
|
||||
|
||||
res.stdout = res.stdout?.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "") || '';
|
||||
res.stderr = res.stderr?.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "") || '';
|
||||
|
||||
|
||||
if (res.stdout === undefined || res.stderr === undefined || res.stderr.includes('undefined') || res.stdout.includes('undefined')) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
dom.content(out, [ res.stdout || '', res.stderr || '' ]);
|
||||
}
|
||||
|
||||
|
||||
}).catch(function(err) {
|
||||
if (res.stdout === undefined || res.stderr === undefined || res.stderr.includes('undefined') || res.stdout.includes('undefined')) {
|
||||
return;
|
||||
@@ -95,23 +115,215 @@ return view.extend({
|
||||
ov.value = x;
|
||||
},
|
||||
|
||||
handleFileChange: function(ev) {
|
||||
let selectedFile = ev.target.value;
|
||||
let selectElement = document.getElementById('tk');
|
||||
|
||||
if (!selectElement || !selectedFile) return;
|
||||
|
||||
this.saveSettingsToLocalStorage(selectedFile);
|
||||
|
||||
return fs.read_direct('/etc/modem/atcmmds/' + selectedFile).then(function(content) {
|
||||
selectElement.innerHTML = '';
|
||||
|
||||
let commands = (content || '').trim().split('\n');
|
||||
commands.forEach(function(cmd) {
|
||||
if (cmd.trim()) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
let option = document.createElement('option');
|
||||
option.value = code;
|
||||
option.textContent = name;
|
||||
selectElement.appendChild(option);
|
||||
}
|
||||
});
|
||||
|
||||
let cmdInput = document.getElementById('cmdvalue');
|
||||
if (cmdInput) cmdInput.value = '';
|
||||
}).catch(function(err) {
|
||||
console.error('Error loading AT commands file:', err);
|
||||
ui.addNotification(null, E('p', _('Error loading AT commands file: ') + selectedFile), 'error');
|
||||
});
|
||||
},
|
||||
|
||||
handleModemChange: function(ev) {
|
||||
let sections = uci.sections('defmodems', 'defmodems');
|
||||
if (!sections || sections.length === 0) return;
|
||||
|
||||
let serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) return;
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'atport');
|
||||
let currentIndex = serialModems.findIndex(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) currentIndex = 0;
|
||||
|
||||
let direction = ev.currentTarget.classList.contains('next') ? 1 : -1;
|
||||
let newIndex = (currentIndex + direction + serialModems.length) % serialModems.length;
|
||||
let newModem = serialModems[newIndex];
|
||||
|
||||
if (newModem && newModem.comm_port) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'atport', newModem.comm_port);
|
||||
uci.save();
|
||||
uci.apply().then(function() {
|
||||
let modemText = document.querySelector('.modem-display-text');
|
||||
if (modemText) {
|
||||
let label = newModem.modem + (newModem.user_desc ? ' (' + newModem.user_desc + ')' : '');
|
||||
modemText.textContent = label;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
L.resolveDefault(fs.read_direct('/etc/modem/atcmmds.user'), null),
|
||||
uci.load('sms_tool_js')
|
||||
L.resolveDefault(fs.list('/etc/modem/atcmmds'), []),
|
||||
uci.load('sms_tool_js'),
|
||||
L.resolveDefault(uci.load('defmodems'))
|
||||
]);
|
||||
},
|
||||
|
||||
render: function (loadResults) {
|
||||
|
||||
|
||||
let info = _('User interface for sending AT commands using sms-tool. More information about the sms-tool on the %seko.one.pl forum%s.').format('<a href="https://eko.one.pl/?p=openwrt-sms_tool" target="_blank">', '</a>');
|
||||
|
||||
|
||||
let sections = uci.sections('defmodems', 'defmodems');
|
||||
let serialModems = [];
|
||||
|
||||
if (sections && sections.length > 0) {
|
||||
serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
}
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'atport');
|
||||
let currentModem = serialModems.find(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (!currentModem && serialModems.length > 0) currentModem = serialModems[0];
|
||||
|
||||
let atFiles = loadResults[1] || [];
|
||||
let userFiles = atFiles.filter(function(file) {
|
||||
return file.type === 'file' && file.name && file.name.match(/\.user$/);
|
||||
});
|
||||
|
||||
return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
|
||||
E('h2', {}, [ _('AT Commands') ]),
|
||||
E('div', { 'class': 'cbi-map-descr'}, info),
|
||||
E('hr'),
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
E('div', { 'class': 'cbi-section-node' }, [
|
||||
(function() {
|
||||
if (serialModems.length > 0) {
|
||||
let label = currentModem.modem + (currentModem.user_desc ? ' (' + currentModem.user_desc + ')' : '');
|
||||
let buttonsDisabled = (serialModems.length > 1) ? null : true;
|
||||
|
||||
return E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Select modem') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
E('div', { 'class': 'controls' }, [
|
||||
E('div', { 'class': 'pager center', 'style': 'display: flex; align-items: center; gap: 10px;' }, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'aria-label': _('Previous modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ◄ ' ]),
|
||||
E('div', { 'class': 'text modem-display-text', 'style': 'flex: 1; text-align: center;' }, [ label ]),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'aria-label': _('Next modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ► ' ])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
return E('div');
|
||||
}
|
||||
}.bind(this))(),
|
||||
(function() {
|
||||
if (userFiles.length > 0) {
|
||||
let savedFile = this.restoreSettingsFromLocalStorage();
|
||||
let fileToLoad = userFiles[0].name;
|
||||
let checkedIndex = 0;
|
||||
|
||||
if (savedFile) {
|
||||
let foundIndex = userFiles.findIndex(function(f) {
|
||||
return f.name === savedFile;
|
||||
});
|
||||
if (foundIndex !== -1) {
|
||||
fileToLoad = savedFile;
|
||||
checkedIndex = foundIndex;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
L.resolveDefault(fs.read_direct('/etc/modem/atcmmds/' + fileToLoad), '').then(function(content) {
|
||||
let selectElement = document.getElementById('tk');
|
||||
if (!selectElement) return;
|
||||
|
||||
selectElement.innerHTML = '';
|
||||
|
||||
let commands = (content || '').trim().split('\n');
|
||||
commands.forEach(function(cmd) {
|
||||
if (cmd.trim()) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
let option = document.createElement('option');
|
||||
option.value = code;
|
||||
option.textContent = name;
|
||||
selectElement.appendChild(option);
|
||||
}
|
||||
});
|
||||
}).catch(function(err) {
|
||||
console.error('Error loading initial AT commands file:', err);
|
||||
});
|
||||
}, 100);
|
||||
|
||||
return E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Defined AT command files') ]),
|
||||
E('div', { 'class': 'cbi-value-field' },
|
||||
E('div', {},
|
||||
userFiles.map(function(file, index) {
|
||||
let fileName = file.name;
|
||||
let displayName = fileName.replace(/\.user$/, '').toUpperCase();
|
||||
|
||||
return E('label', {
|
||||
'style': 'margin-right: 15px;',
|
||||
'data-tooltip': _('Select file with AT commands to load')
|
||||
}, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'at_file',
|
||||
'value': fileName,
|
||||
'change': ui.createHandlerFn(this, 'handleFileChange'),
|
||||
'checked': index === checkedIndex ? true : null
|
||||
}),
|
||||
' ',
|
||||
displayName
|
||||
]);
|
||||
}.bind(this))
|
||||
)
|
||||
)
|
||||
]);
|
||||
} else {
|
||||
return E('div');
|
||||
}
|
||||
}.bind(this))(),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('User AT commands') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
@@ -121,14 +333,26 @@ return view.extend({
|
||||
'change': ui.createHandlerFn(this, 'handleCopy'),
|
||||
'mousedown': ui.createHandlerFn(this, 'handleCopy')
|
||||
},
|
||||
(loadResults[0] || "").trim().split("\n").map(function(cmd) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
return E('option', { 'value': code }, name );
|
||||
})
|
||||
(function() {
|
||||
let content = '';
|
||||
if (userFiles.length === 0 && loadResults[0]) {
|
||||
content = loadResults[0];
|
||||
}
|
||||
|
||||
if (!content || !content.trim()) {
|
||||
return [E('option', { 'value': '' }, _('No AT commands available'))];
|
||||
}
|
||||
|
||||
return content.trim().split("\n").map(function(cmd) {
|
||||
if (!cmd.trim()) return null;
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
return E('option', { 'value': code }, name );
|
||||
}).filter(function(opt) { return opt !== null; });
|
||||
})()
|
||||
)
|
||||
])
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Command to send') ]),
|
||||
@@ -139,14 +363,14 @@ return view.extend({
|
||||
'id': 'cmdvalue',
|
||||
'data-tooltip': _('Press [Enter] to send the command, press [Delete] to delete the command'),
|
||||
'keydown': function(ev) {
|
||||
if (ev.keyCode === 13)
|
||||
if (ev.keyCode === 13)
|
||||
{
|
||||
let execBtn = document.getElementById('execute');
|
||||
if (execBtn) {
|
||||
execBtn.click();
|
||||
}
|
||||
}
|
||||
if (ev.keyCode === 46)
|
||||
if (ev.keyCode === 46)
|
||||
{
|
||||
let del = document.getElementById('cmdvalue');
|
||||
if (del) {
|
||||
@@ -155,7 +379,7 @@ return view.extend({
|
||||
document.getElementById('cmdvalue').focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
])
|
||||
]),
|
||||
@@ -184,4 +408,4 @@ return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
})
|
||||
});
|
||||
@@ -7,12 +7,224 @@
|
||||
'require view';
|
||||
|
||||
/*
|
||||
Copyright 2022-2025 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Copyright 2022-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
return view.extend({
|
||||
|
||||
isUnicode: function(text) {
|
||||
// Chars GSM-7
|
||||
const gsm7chars = '@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà';
|
||||
const gsm7extended = '^{}\\[~]|€';
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let char = text.charAt(i);
|
||||
if (gsm7chars.indexOf(char) === -1 && gsm7extended.indexOf(char) === -1) {
|
||||
return true; // None GSM-7
|
||||
}
|
||||
}
|
||||
return false; // All GSM-7
|
||||
},
|
||||
|
||||
getGSM7Length: function(text) {
|
||||
const gsm7extended = '^{}\\[~]|€';
|
||||
let length = 0;
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let char = text.charAt(i);
|
||||
if (gsm7extended.indexOf(char) !== -1) {
|
||||
length += 2;
|
||||
} else {
|
||||
length += 1;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
},
|
||||
|
||||
getUnicodeLength: function(text) {
|
||||
let length = 0;
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let charCode = text.charCodeAt(i);
|
||||
|
||||
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
||||
length += 2;
|
||||
i++;
|
||||
} else {
|
||||
length += 1;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
},
|
||||
|
||||
normalizeToGSM7: function(text) {
|
||||
return text
|
||||
// PL
|
||||
.replace(/ą/g, 'a').replace(/Ą/g, 'A')
|
||||
.replace(/ć/g, 'c').replace(/Ć/g, 'C')
|
||||
.replace(/ę/g, 'e').replace(/Ę/g, 'E')
|
||||
.replace(/ł/g, 'l').replace(/Ł/g, 'L')
|
||||
.replace(/ń/g, 'n').replace(/Ń/g, 'N')
|
||||
.replace(/ó/g, 'o').replace(/Ó/g, 'O')
|
||||
.replace(/ś/g, 's').replace(/Ś/g, 'S')
|
||||
.replace(/ż/g, 'z').replace(/Ż/g, 'Z')
|
||||
.replace(/ź/g, 'z').replace(/Ź/g, 'Z')
|
||||
// EU
|
||||
.replace(/á/g, 'a').replace(/Á/g, 'A')
|
||||
.replace(/â/g, 'a').replace(/Â/g, 'A')
|
||||
.replace(/ã/g, 'a').replace(/Ã/g, 'A')
|
||||
.replace(/ā/g, 'a').replace(/Ā/g, 'A')
|
||||
.replace(/č/g, 'c').replace(/Č/g, 'C')
|
||||
.replace(/ď/g, 'd').replace(/Ď/g, 'D')
|
||||
.replace(/đ/g, 'd').replace(/Đ/g, 'D')
|
||||
.replace(/é/g, 'e').replace(/É/g, 'E')
|
||||
.replace(/ě/g, 'e').replace(/Ě/g, 'E')
|
||||
.replace(/ë/g, 'e').replace(/Ë/g, 'E')
|
||||
.replace(/ê/g, 'e').replace(/Ê/g, 'E')
|
||||
.replace(/ē/g, 'e').replace(/Ē/g, 'E')
|
||||
.replace(/í/g, 'i').replace(/Í/g, 'I')
|
||||
.replace(/î/g, 'i').replace(/Î/g, 'I')
|
||||
.replace(/ï/g, 'i').replace(/Ï/g, 'I')
|
||||
.replace(/ī/g, 'i').replace(/Ī/g, 'I')
|
||||
.replace(/ľ/g, 'l').replace(/Ľ/g, 'L')
|
||||
.replace(/ň/g, 'n').replace(/Ň/g, 'N')
|
||||
.replace(/ô/g, 'o').replace(/Ô/g, 'O')
|
||||
.replace(/õ/g, 'o').replace(/Õ/g, 'O')
|
||||
.replace(/ö/g, 'o').replace(/Ö/g, 'O')
|
||||
.replace(/ő/g, 'o').replace(/Ő/g, 'O')
|
||||
.replace(/ř/g, 'r').replace(/Ř/g, 'R')
|
||||
.replace(/š/g, 's').replace(/Š/g, 'S')
|
||||
.replace(/ş/g, 's').replace(/Ş/g, 'S')
|
||||
.replace(/ť/g, 't').replace(/Ť/g, 'T')
|
||||
.replace(/ú/g, 'u').replace(/Ú/g, 'U')
|
||||
.replace(/ů/g, 'u').replace(/Ů/g, 'U')
|
||||
.replace(/û/g, 'u').replace(/Û/g, 'U')
|
||||
.replace(/ü/g, 'u').replace(/Ü/g, 'U')
|
||||
.replace(/ű/g, 'u').replace(/Ű/g, 'U')
|
||||
.replace(/ý/g, 'y').replace(/Ý/g, 'Y')
|
||||
.replace(/ÿ/g, 'y').replace(/Ÿ/g, 'Y')
|
||||
.replace(/ž/g, 'z').replace(/Ž/g, 'Z')
|
||||
// SPECIAL
|
||||
.replace(/–/g, '-').replace(/—/g, '-')
|
||||
.replace(/'/g, '\'').replace(/'/g, '\'')
|
||||
.replace(/"/g, '"').replace(/"/g, '"')
|
||||
.replace(/„/g, '"').replace(/"/g, '"')
|
||||
.replace(/«/g, '"').replace(/»/g, '"')
|
||||
.replace(/…/g, '...').replace(/·/g, '.')
|
||||
.replace(/•/g, '*').replace(/‣/g, '*')
|
||||
.replace(/°/g, 'o').replace(/º/g, 'o')
|
||||
.replace(/†/g, '+').replace(/‡/g, '+')
|
||||
.replace(/¹/g, '1').replace(/²/g, '2').replace(/³/g, '3')
|
||||
.replace(/¼/g, '1/4').replace(/½/g, '1/2').replace(/¾/g, '3/4')
|
||||
.replace(/×/g, 'x').replace(/÷/g, '/')
|
||||
.replace(/±/g, '+/-')
|
||||
.replace(/≈/g, '~').replace(/≠/g, '!=')
|
||||
.replace(/≤/g, '<=').replace(/≥/g, '>=')
|
||||
.replace(/←/g, '<-').replace(/→/g, '->')
|
||||
.replace(/↑/g, '^').replace(/↓/g, 'v')
|
||||
// Emoji, etc.
|
||||
.replace(/[\u{1F600}-\u{1F64F}]/gu, ':)')
|
||||
.replace(/[\u{1F300}-\u{1F5FF}]/gu, '')
|
||||
.replace(/[\u{1F680}-\u{1F6FF}]/gu, '')
|
||||
.replace(/[\u{1F700}-\u{1F77F}]/gu, '')
|
||||
.replace(/[\u{1F780}-\u{1F7FF}]/gu, '')
|
||||
.replace(/[\u{1F800}-\u{1F8FF}]/gu, '')
|
||||
.replace(/[\u{1F900}-\u{1F9FF}]/gu, '')
|
||||
.replace(/[\u{1FA00}-\u{1FA6F}]/gu, '')
|
||||
.replace(/[\u{1FA70}-\u{1FAFF}]/gu, '')
|
||||
.replace(/[\u{2600}-\u{26FF}]/gu, '')
|
||||
.replace(/[\u{2700}-\u{27BF}]/gu, '')
|
||||
// UNSUPPORTED
|
||||
.replace(/[^\x00-\x7F@£$¥èéùìòÇØøÅåΔΦΓΛΩΠΨΣΘΞÆæßÉ¡¤§¿äöñüà^{}\\[\]~|€]/g, '');
|
||||
},
|
||||
|
||||
updateMessageCounter: function() {
|
||||
let textarea = document.getElementById('smstext');
|
||||
let text = textarea.value;
|
||||
let counter = document.getElementById('counter');
|
||||
let gsm7Radio = document.querySelector('input[name="encoding_type"][value="gsm7"]');
|
||||
let unicodeRadio = document.querySelector('input[name="encoding_type"][value="unicode"]');
|
||||
|
||||
if (this.isUnicode(text)) {
|
||||
unicodeRadio.checked = true;
|
||||
let maxLength = 70;
|
||||
let currentLength = this.getUnicodeLength(text);
|
||||
|
||||
if (currentLength > maxLength) {
|
||||
// Multipart SMS
|
||||
counter.innerHTML = _('Not applicable');
|
||||
} else {
|
||||
counter.innerHTML = (maxLength - currentLength);
|
||||
}
|
||||
} else {
|
||||
gsm7Radio.checked = true;
|
||||
let maxLength = 160;
|
||||
let currentLength = this.getGSM7Length(text);
|
||||
counter.innerHTML = (maxLength - currentLength);
|
||||
|
||||
if (currentLength > maxLength) {
|
||||
let newText = '';
|
||||
let length = 0;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let char = text.charAt(i);
|
||||
let charLength = ('^{}\\[~]|€'.indexOf(char) !== -1) ? 2 : 1;
|
||||
if (length + charLength <= maxLength) {
|
||||
newText += char;
|
||||
length += charLength;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
textarea.value = newText;
|
||||
counter.innerHTML = (maxLength - length);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleEncodingChange: function(ev) {
|
||||
let textarea = document.getElementById('smstext');
|
||||
let text = textarea.value;
|
||||
let encodingType = ev.target.value;
|
||||
let counter = document.getElementById('counter');
|
||||
|
||||
if (encodingType === 'gsm7') {
|
||||
textarea.value = this.normalizeToGSM7(text);
|
||||
let currentLength = this.getGSM7Length(textarea.value);
|
||||
let maxLength = 160;
|
||||
|
||||
if (currentLength > maxLength) {
|
||||
let newText = '';
|
||||
let length = 0;
|
||||
for (let i = 0; i < textarea.value.length; i++) {
|
||||
let char = textarea.value.charAt(i);
|
||||
let charLength = ('^{}\\[~]|€'.indexOf(char) !== -1) ? 2 : 1;
|
||||
if (length + charLength <= maxLength) {
|
||||
newText += char;
|
||||
length += charLength;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
textarea.value = newText;
|
||||
currentLength = this.getGSM7Length(textarea.value);
|
||||
}
|
||||
counter.innerHTML = (maxLength - currentLength);
|
||||
} else {
|
||||
let maxLength = 70;
|
||||
let currentLength = this.getUnicodeLength(textarea.value);
|
||||
|
||||
if (currentLength > maxLength) {
|
||||
// Multipart SMS
|
||||
counter.innerHTML = _('Not applicable');
|
||||
} else {
|
||||
counter.innerHTML = (maxLength - currentLength);
|
||||
}
|
||||
}
|
||||
this.updateMessageCounter();
|
||||
},
|
||||
|
||||
handleCommand: function(exec, args) {
|
||||
let buttons = document.querySelectorAll('.cbi-button');
|
||||
|
||||
@@ -26,14 +238,14 @@ return view.extend({
|
||||
res.stdout = res.stdout?.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "") || '';
|
||||
res.stderr = res.stderr?.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "") || '';
|
||||
|
||||
let cut = res.stdout;
|
||||
cut = cut.substr(0, 20);
|
||||
if ( cut == "sms sent sucessfully" ) {
|
||||
res.stdout = _('SMS sent sucessfully');
|
||||
let match = res.stdout.match(/^sms sent suc{1,2}essfully(?:\s*:\s*(\d+))?/i);
|
||||
if ( match ) {
|
||||
let digit = match[1];
|
||||
res.stdout = _('SMS sent sucessfully') + (digit ? ':' + ' ' + digit : '');
|
||||
}
|
||||
|
||||
dom.content(out, [ res.stdout || '', res.stderr || '' ]);
|
||||
|
||||
|
||||
}).catch(function(err) {
|
||||
ui.addNotification(null, E('p', [ err ]))
|
||||
}).finally(function() {
|
||||
@@ -72,7 +284,6 @@ return view.extend({
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// sms_tool -d /dev/ttyUSB1 send 48500500500 "MSG"
|
||||
return this.handleCommand('sms_tool', [ '-d' , port , 'send' , phn , get_smstxt ]);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +308,6 @@ return view.extend({
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// sms_tool -d /dev/ttyUSB1 send 48500500500 "MSG"
|
||||
let xs = document.getElementById('pb');
|
||||
|
||||
let phone, i;
|
||||
@@ -105,7 +315,7 @@ return view.extend({
|
||||
|
||||
for (let i = 0; i < xs.length; i++) {
|
||||
(function(i) {
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
phone = xs.options[i].value;
|
||||
|
||||
let out = document.querySelector('.smscommand-output');
|
||||
@@ -116,8 +326,8 @@ return view.extend({
|
||||
res.stdout += (i+1)+_('/')+xs.length+' * '+_('[Bot] Message sent to number:') + ' ' + phone +'\n';
|
||||
res.stdout = res.stdout.replace(/undefined/g, "");
|
||||
|
||||
dom.content(out, [ res.stdout || '' ]);
|
||||
|
||||
dom.content(out, [ res.stdout || '' ]);
|
||||
|
||||
}, dx * i);
|
||||
})(i);
|
||||
}
|
||||
@@ -137,6 +347,10 @@ return view.extend({
|
||||
|
||||
document.getElementById('counter').innerHTML = '160';
|
||||
|
||||
// Reset to GSM-7
|
||||
let gsm7Radio = document.querySelector('input[name="encoding_type"][value="gsm7"]');
|
||||
if (gsm7Radio) gsm7Radio.checked = true;
|
||||
|
||||
let prefixnum, sections = uci.sections('sms_tool_js');
|
||||
let addprefix = sections[0].prefix;
|
||||
if ( addprefix == '1' )
|
||||
@@ -161,16 +375,52 @@ return view.extend({
|
||||
ov.value = x;
|
||||
},
|
||||
|
||||
handleModemChange: function(ev) {
|
||||
let sections = uci.sections('defmodems', 'defmodems');
|
||||
if (!sections || sections.length === 0) return;
|
||||
|
||||
let serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) return;
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'sendport');
|
||||
let currentIndex = serialModems.findIndex(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) currentIndex = 0;
|
||||
|
||||
let direction = ev.currentTarget.classList.contains('next') ? 1 : -1;
|
||||
let newIndex = (currentIndex + direction + serialModems.length) % serialModems.length;
|
||||
let newModem = serialModems[newIndex];
|
||||
|
||||
if (newModem && newModem.comm_port) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'sendport', newModem.comm_port);
|
||||
uci.save();
|
||||
uci.apply().then(function() {
|
||||
let modemText = document.querySelector('.modem-display-text');
|
||||
if (modemText) {
|
||||
let label = newModem.modem + (newModem.user_desc ? ' (' + newModem.user_desc + ')' : '');
|
||||
modemText.textContent = label;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
L.resolveDefault(fs.read_direct('/etc/modem/phonebook.user'), null),
|
||||
uci.load('sms_tool_js')
|
||||
uci.load('sms_tool_js'),
|
||||
L.resolveDefault(uci.load('defmodems'))
|
||||
]);
|
||||
},
|
||||
|
||||
render: function (loadResults) {
|
||||
|
||||
let group, prefixnum, sections = uci.sections('sms_tool_js');
|
||||
let self = this;
|
||||
|
||||
if ( sections[0].sendingroup == '1' )
|
||||
{
|
||||
@@ -179,22 +429,71 @@ return view.extend({
|
||||
else {
|
||||
group = '';
|
||||
}
|
||||
|
||||
if ( sections[0].prefix == '1' ) {
|
||||
|
||||
if ( sections[0].prefix == '1' ) {
|
||||
prefixnum = sections[0].pnumber;
|
||||
}
|
||||
if ( sections[0].information == '1' ) {
|
||||
ui.addNotification(null, E('p', _('The phone number should be preceded by the country prefix (for Poland it is 48, without +). If the number is 5, 4 or 3 characters, it is treated as.. short and should not be preceded by a country prefix.') ), 'info');
|
||||
}
|
||||
|
||||
|
||||
let info = _('User interface for sending messages using sms-tool. More information about the sms-tool on the %seko.one.pl forum%s.').format('<a href="https://eko.one.pl/?p=openwrt-sms_tool" target="_blank">', '</a>');
|
||||
|
||||
|
||||
let modemSections = uci.sections('defmodems', 'defmodems');
|
||||
let serialModems = [];
|
||||
|
||||
if (modemSections && modemSections.length > 0) {
|
||||
serialModems = modemSections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
}
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'sendport');
|
||||
let currentModem = serialModems.find(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (!currentModem && serialModems.length > 0) currentModem = serialModems[0];
|
||||
|
||||
return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
|
||||
E('h2', {}, [ _('SMS Messages') ]),
|
||||
E('div', { 'class': 'cbi-map-descr'}, info),
|
||||
E('hr'),
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
E('div', { 'class': 'cbi-section-node' }, [
|
||||
(function() {
|
||||
if (serialModems.length > 0) {
|
||||
let label = currentModem.modem + (currentModem.user_desc ? ' (' + currentModem.user_desc + ')' : '');
|
||||
let buttonsDisabled = (serialModems.length > 1) ? null : true;
|
||||
|
||||
return E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Select modem') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
E('div', { 'class': 'controls' }, [
|
||||
E('div', { 'class': 'pager center', 'style': 'display: flex; align-items: center; gap: 10px;' }, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'aria-label': _('Previous modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ◄ ' ]),
|
||||
E('div', { 'class': 'text modem-display-text', 'style': 'flex: 1; text-align: center;' }, [ label ]),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'aria-label': _('Next modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ► ' ])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
return E('div');
|
||||
}
|
||||
}.bind(this))(),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('User contacts') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
@@ -211,7 +510,7 @@ return view.extend({
|
||||
return E('option', { 'value': code }, name );
|
||||
})
|
||||
)
|
||||
])
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Send to') ]),
|
||||
@@ -224,7 +523,7 @@ return view.extend({
|
||||
'oninput': "this.value = this.value.replace(/[^0-9.]/g, '');",
|
||||
'data-tooltip': _('Press [Delete] to delete the phone number'),
|
||||
'keydown': function(ev) {
|
||||
if (ev.keyCode === 46)
|
||||
if (ev.keyCode === 46)
|
||||
{
|
||||
let del = document.getElementById('phonenumber');
|
||||
if (del) {
|
||||
@@ -242,10 +541,43 @@ return view.extend({
|
||||
document.getElementById('phonenumber').focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Encoding standard') ]),
|
||||
E('div', { 'class': 'cbi-value-field', 'style': 'text-align: left;' }, [
|
||||
E('div', { 'style': 'margin: 1px 0; display: inline-block;' }, [
|
||||
E('label', {
|
||||
'data-tooltip': _('GSM-7 encoding (160 characters)')
|
||||
}, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'encoding_type',
|
||||
'value': 'gsm7',
|
||||
'change': ui.createHandlerFn(this, 'handleEncodingChange'),
|
||||
'checked': true
|
||||
}),
|
||||
' ',
|
||||
_('GSM-7 (160 characters)')
|
||||
]),
|
||||
' \u00a0\u00a0\u00a0 ',
|
||||
E('label', {
|
||||
'data-tooltip': _('Unicode encoding (70 characters by default) supports the transmission of national characters and multipart sms messages')
|
||||
}, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'encoding_type',
|
||||
'value': 'unicode',
|
||||
'change': ui.createHandlerFn(this, 'handleEncodingChange')
|
||||
}),
|
||||
' ',
|
||||
_('Unicode (70 characters)')
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Message text') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
@@ -255,35 +587,32 @@ return view.extend({
|
||||
'wrap': 'on',
|
||||
'rows': '3',
|
||||
'placeholder': _(''),
|
||||
'maxlength': '160',
|
||||
'data-tooltip': _('Press [Delete] to delete the content of the message'),
|
||||
'keydown': function(ev) {
|
||||
if (ev.keyCode === 46)
|
||||
if (ev.keyCode === 46)
|
||||
{
|
||||
let del = document.getElementById('smstext');
|
||||
if (del) {
|
||||
let ovtxt = document.getElementById('smstext');
|
||||
ovtxt.value = '';
|
||||
document.getElementById('counter').innerHTML = '160';
|
||||
// Reset to GSM-7
|
||||
let gsm7Radio = document.querySelector('input[name="encoding_type"][value="gsm7"]');
|
||||
if (gsm7Radio) gsm7Radio.checked = true;
|
||||
document.getElementById('smstext').focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
'keyup': function(ev) {
|
||||
document.getElementById('counter').innerHTML = (160 - document.getElementById('smstext').value.length);
|
||||
|
||||
this.value = this.value.replace(/ą/g, 'a').replace(/Ą/g, 'A');
|
||||
this.value = this.value.replace(/ć/g, 'c').replace(/Ć/g, 'C');
|
||||
this.value = this.value.replace(/ę/g, 'e').replace(/Ę/g, 'E');
|
||||
this.value = this.value.replace(/ł/g, 'l').replace(/Ł/g, 'L');
|
||||
this.value = this.value.replace(/ń/g, 'n').replace(/Ń/g, 'N');
|
||||
this.value = this.value.replace(/ó/g, 'o').replace(/Ó/g, 'O');
|
||||
this.value = this.value.replace(/ś/g, 's').replace(/Ś/g, 'S');
|
||||
this.value = this.value.replace(/ż/g, 'z').replace(/Ż/g, 'Z');
|
||||
this.value = this.value.replace(/ź/g, 'z').replace(/Ź/g, 'Z');
|
||||
}
|
||||
}),
|
||||
self.updateMessageCounter();
|
||||
},
|
||||
'input': function(ev) {
|
||||
self.updateMessageCounter();
|
||||
}
|
||||
}),
|
||||
E('div', { 'class': 'left' }, [
|
||||
E('br'),
|
||||
E('label', {}, [ _('Characters remaining:')+' ' ]),
|
||||
E('label', { 'id': 'counter' }, [ _('160') ])
|
||||
])
|
||||
]),
|
||||
@@ -306,24 +635,23 @@ return view.extend({
|
||||
}, {
|
||||
'click': ui.createHandlerFn(this, 'handleGo'),
|
||||
'id': 'execute',
|
||||
'classes': {
|
||||
'send': 'cbi-button cbi-button-action important',
|
||||
'sendg': 'cbi-button cbi-button-action important',
|
||||
},
|
||||
'id': 'execute',
|
||||
}).render() : E('button', {
|
||||
'class': 'cbi-button cbi-button-action important',
|
||||
'id': 'execute',
|
||||
'click': ui.createHandlerFn(this, 'handleGo')
|
||||
}, [ _('Send to number') ]),
|
||||
]),
|
||||
]),
|
||||
E('p', _('Status')),
|
||||
E('pre', { 'class': 'smscommand-output', 'id': 'ans', 'style': 'display:none; border: 1px solid var(--border-color-medium); border-radius: 5px; font-family: monospace' }),
|
||||
]);
|
||||
},
|
||||
'classes': {'send': 'cbi-button cbi-button-action important',
|
||||
'sendg': 'cbi-button cbi-button-action important',
|
||||
},
|
||||
'id': 'execute',
|
||||
}).render() : E('button', {
|
||||
'class': 'cbi-button cbi-button-action important',
|
||||
'id': 'execute',
|
||||
'click': ui.createHandlerFn(this, 'handleGo')
|
||||
}, [ _('Send to number') ]),
|
||||
]),
|
||||
]),
|
||||
E('p', _('Status')),
|
||||
E('pre', { 'class': 'smscommand-output', 'id': 'ans', 'style': 'display:none; border: 1px solid var(--border-color-medium); border-radius: 5px; font-family: monospace' }),
|
||||
]);
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
})
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
});
|
||||
@@ -7,12 +7,32 @@
|
||||
'require view';
|
||||
|
||||
/*
|
||||
Copyright 2022-2025 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
Copyright 2022-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
return view.extend({
|
||||
viewName: 'sendussd',
|
||||
|
||||
restoreSettingsFromLocalStorage: function() {
|
||||
try {
|
||||
let selectedFile = localStorage.getItem('luci-app-' + this.viewName + '-selectedFile');
|
||||
return selectedFile;
|
||||
} catch(e) {
|
||||
console.error('localStorage not available:', e);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
saveSettingsToLocalStorage: function(fileName) {
|
||||
try {
|
||||
localStorage.setItem('luci-app-' + this.viewName + '-selectedFile', fileName);
|
||||
} catch(e) {
|
||||
console.error('localStorage not available:', e);
|
||||
}
|
||||
},
|
||||
|
||||
handleCommand: function(exec, args) {
|
||||
let buttons = document.querySelectorAll('.cbi-button');
|
||||
|
||||
@@ -189,6 +209,38 @@ return view.extend({
|
||||
});
|
||||
},
|
||||
|
||||
handleFileChange: function(ev) {
|
||||
let selectedFile = ev.target.value;
|
||||
let selectElement = document.getElementById('tk');
|
||||
|
||||
if (!selectElement || !selectedFile) return;
|
||||
|
||||
this.saveSettingsToLocalStorage(selectedFile);
|
||||
|
||||
return fs.read_direct('/etc/modem/ussdcodes/' + selectedFile).then(function(content) {
|
||||
selectElement.innerHTML = '';
|
||||
|
||||
let codes = (content || '').trim().split('\n');
|
||||
codes.forEach(function(cmd) {
|
||||
if (cmd.trim()) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
let option = document.createElement('option');
|
||||
option.value = code;
|
||||
option.textContent = name;
|
||||
selectElement.appendChild(option);
|
||||
}
|
||||
});
|
||||
|
||||
let cmdInput = document.getElementById('cmdvalue');
|
||||
if (cmdInput) cmdInput.value = '';
|
||||
}).catch(function(err) {
|
||||
console.error('Error loading USSD file:', err);
|
||||
ui.addNotification(null, E('p', _('Error loading USSD codes file: ') + selectedFile), 'error');
|
||||
});
|
||||
},
|
||||
|
||||
handleGo: function(ev) {
|
||||
let ussd = document.getElementById('cmdvalue').value;
|
||||
let sections = uci.sections('sms_tool_js');
|
||||
@@ -236,7 +288,7 @@ return view.extend({
|
||||
|
||||
document.getElementById('cmdvalue').focus();
|
||||
},
|
||||
|
||||
|
||||
handleClearOut: function(ev) {
|
||||
let out = document.querySelector('.ussdcommand-output');
|
||||
let fullhistory = document.getElementById('history-full')?.checked;
|
||||
@@ -267,11 +319,47 @@ return view.extend({
|
||||
ov.value = x;
|
||||
},
|
||||
|
||||
handleModemChange: function(ev) {
|
||||
let sections = uci.sections('defmodems', 'defmodems');
|
||||
if (!sections || sections.length === 0) return;
|
||||
|
||||
let serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
|
||||
if (serialModems.length === 0) return;
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'ussdport');
|
||||
let currentIndex = serialModems.findIndex(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) currentIndex = 0;
|
||||
|
||||
let direction = ev.currentTarget.classList.contains('next') ? 1 : -1;
|
||||
let newIndex = (currentIndex + direction + serialModems.length) % serialModems.length;
|
||||
let newModem = serialModems[newIndex];
|
||||
|
||||
if (newModem && newModem.comm_port) {
|
||||
uci.set('sms_tool_js', '@sms_tool_js[0]', 'ussdport', newModem.comm_port);
|
||||
uci.save();
|
||||
uci.apply().then(function() {
|
||||
let modemText = document.querySelector('.modem-display-text');
|
||||
if (modemText) {
|
||||
let label = newModem.modem + (newModem.user_desc ? ' (' + newModem.user_desc + ')' : '');
|
||||
modemText.textContent = label;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
load: function() {
|
||||
|
||||
return Promise.all([
|
||||
L.resolveDefault(fs.read_direct('/etc/modem/ussdcodes.user'), null),
|
||||
uci.load('sms_tool_js')
|
||||
L.resolveDefault(fs.list('/etc/modem/ussdcodes'), []),
|
||||
uci.load('sms_tool_js'),
|
||||
L.resolveDefault(uci.load('defmodems'))
|
||||
]);
|
||||
},
|
||||
|
||||
@@ -279,12 +367,136 @@ return view.extend({
|
||||
|
||||
let info = _('User interface for sending USSD codes using sms-tool. More information about the sms-tool on the %seko.one.pl forum%s.').format('<a href="https://eko.one.pl/?p=openwrt-sms_tool" target="_blank">', '</a>');
|
||||
|
||||
let sections = uci.sections('defmodems', 'defmodems');
|
||||
let serialModems = [];
|
||||
|
||||
if (sections && sections.length > 0) {
|
||||
serialModems = sections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
});
|
||||
}
|
||||
|
||||
let currentPort = uci.get('sms_tool_js', '@sms_tool_js[0]', 'ussdport');
|
||||
let currentModem = serialModems.find(function(s) {
|
||||
return s.comm_port === currentPort;
|
||||
});
|
||||
|
||||
if (!currentModem && serialModems.length > 0) currentModem = serialModems[0];
|
||||
|
||||
return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
|
||||
E('h2', {}, [ _('USSD Codes') ]),
|
||||
E('div', { 'class': 'cbi-map-descr'}, info),
|
||||
E('hr'),
|
||||
E('div', { 'class': 'cbi-section' }, [
|
||||
E('div', { 'class': 'cbi-section-node' }, [
|
||||
(function() {
|
||||
if (serialModems.length > 0) {
|
||||
let label = currentModem.modem + (currentModem.user_desc ? ' (' + currentModem.user_desc + ')' : '');
|
||||
let buttonsDisabled = (serialModems.length > 1) ? null : true;
|
||||
|
||||
return E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Select modem') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
E('div', { 'class': 'controls' }, [
|
||||
E('div', { 'class': 'pager center', 'style': 'display: flex; align-items: center; gap: 10px;' }, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'aria-label': _('Previous modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ◄ ' ]),
|
||||
E('div', { 'class': 'text modem-display-text', 'style': 'flex: 1; text-align: center;' }, [ label ]),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'aria-label': _('Next modem'),
|
||||
'click': ui.createHandlerFn(this, 'handleModemChange'),
|
||||
'style': 'min-width: 40px;',
|
||||
'disabled': buttonsDisabled
|
||||
}, [ ' ► ' ])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
return E('div');
|
||||
}
|
||||
}.bind(this))(),
|
||||
(function() {
|
||||
let ussdFiles = loadResults[1] || [];
|
||||
let userFiles = ussdFiles.filter(function(file) {
|
||||
return file.type === 'file' && file.name && file.name.match(/\.user$/);
|
||||
});
|
||||
|
||||
if (userFiles.length > 0) {
|
||||
let savedFile = this.restoreSettingsFromLocalStorage();
|
||||
let fileToLoad = userFiles[0].name;
|
||||
let checkedIndex = 0;
|
||||
|
||||
if (savedFile) {
|
||||
let foundIndex = userFiles.findIndex(function(f) {
|
||||
return f.name === savedFile;
|
||||
});
|
||||
if (foundIndex !== -1) {
|
||||
fileToLoad = savedFile;
|
||||
checkedIndex = foundIndex;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
L.resolveDefault(fs.read_direct('/etc/modem/ussdcodes/' + fileToLoad), '').then(function(content) {
|
||||
let selectElement = document.getElementById('tk');
|
||||
if (!selectElement) return;
|
||||
|
||||
selectElement.innerHTML = '';
|
||||
|
||||
let codes = (content || '').trim().split('\n');
|
||||
codes.forEach(function(cmd) {
|
||||
if (cmd.trim()) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
let option = document.createElement('option');
|
||||
option.value = code;
|
||||
option.textContent = name;
|
||||
selectElement.appendChild(option);
|
||||
}
|
||||
});
|
||||
}).catch(function(err) {
|
||||
console.error('Error loading initial USSD file:', err);
|
||||
});
|
||||
}, 100);
|
||||
|
||||
return E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Defined USSD code files') ]),
|
||||
E('div', { 'class': 'cbi-value-field' },
|
||||
E('div', {},
|
||||
userFiles.map(function(file, index) {
|
||||
let fileName = file.name;
|
||||
let displayName = fileName.replace(/\.user$/, '').toUpperCase();
|
||||
|
||||
return E('label', {
|
||||
'style': 'margin-right: 15px;',
|
||||
'data-tooltip': _('Select file with USSD codes to load')
|
||||
}, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'ussd_file',
|
||||
'value': fileName,
|
||||
'change': ui.createHandlerFn(this, 'handleFileChange'),
|
||||
'checked': index === checkedIndex ? true : null
|
||||
}),
|
||||
' ',
|
||||
displayName
|
||||
]);
|
||||
}.bind(this))
|
||||
)
|
||||
)
|
||||
]);
|
||||
} else {
|
||||
return E('div');
|
||||
}
|
||||
}.bind(this))(),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('User USSD codes') ]),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
@@ -294,14 +506,31 @@ return view.extend({
|
||||
'change': ui.createHandlerFn(this, 'handleCopy'),
|
||||
'mousedown': ui.createHandlerFn(this, 'handleCopy')
|
||||
},
|
||||
(loadResults[0] || "").trim().split("\n").map(function(cmd) {
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
return E('option', { 'value': code }, name );
|
||||
})
|
||||
(function() {
|
||||
let ussdFiles = loadResults[1] || [];
|
||||
let userFiles = ussdFiles.filter(function(file) {
|
||||
return file.type === 'file' && file.name && file.name.match(/\.user$/);
|
||||
});
|
||||
|
||||
let content = '';
|
||||
if (userFiles.length === 0 && loadResults[0]) {
|
||||
content = loadResults[0];
|
||||
}
|
||||
|
||||
if (!content || !content.trim()) {
|
||||
return [E('option', { 'value': '' }, _('No USSD codes available'))];
|
||||
}
|
||||
|
||||
return content.trim().split("\n").map(function(cmd) {
|
||||
if (!cmd.trim()) return null;
|
||||
let fields = cmd.split(/;/);
|
||||
let name = fields[0];
|
||||
let code = fields[1] || fields[0];
|
||||
return E('option', { 'value': code }, name );
|
||||
}).filter(function(opt) { return opt !== null; });
|
||||
})()
|
||||
)
|
||||
])
|
||||
])
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, [ _('Code to send') ]),
|
||||
@@ -382,4 +611,4 @@ return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
'require form';
|
||||
'require fs';
|
||||
'require view';
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require dom';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
/*
|
||||
|
||||
Copyright 2025-2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
|
||||
*/
|
||||
|
||||
function handleOpen(ev) {
|
||||
if (ev === 'ropenissues') { window.open('https://github.com/4IceG/luci-app-sms-tool-js/issues'); return; }
|
||||
if (ev === 'copenissues') { window.open('https://github.com/obsy/sms_tool/issues'); return; }
|
||||
if (ev === 'opendiscussion') { window.open('https://github.com/4IceG/luci-app-sms-tool-js/discussions'); return; }
|
||||
if (ev === 'ropencoffee') { window.open('https://suppi.pl/rafalwabik'); return; }
|
||||
if (ev === 'copencoffee') { window.open('https://buycoffee.to/eko.one.pl'); return; }
|
||||
if (ev === 'opensupport') { window.open('https://github.com/sponsors/4IceG'); return; }
|
||||
if (ev === 'opentopic') { window.open('https://eko.one.pl/forum/viewtopic.php?id=20096&p=10'); return; }
|
||||
}
|
||||
|
||||
return view.extend({
|
||||
load: function () {
|
||||
return uci.load('sms_tool_js');
|
||||
},
|
||||
|
||||
render: function (data) {
|
||||
let m, s, o;
|
||||
let info = _('The tab allows users to support the package.');
|
||||
|
||||
m = new form.Map('sms_tool_js', _('Package update and support'), info);
|
||||
|
||||
s = m.section(form.TypedSection);
|
||||
s.anonymous = true;
|
||||
|
||||
s.tab('info', _('Luci-app-sms-tool-js Info'));
|
||||
|
||||
let packages = [
|
||||
{
|
||||
package: _('Sms-tool'),
|
||||
author: 'Cezary Jackiewicz (obsy)',
|
||||
authorLink: 'https://github.com/obsy',
|
||||
buttons: [
|
||||
{
|
||||
class: 'cbi-button-action important',
|
||||
label: _('Buy a coffee'),
|
||||
tooltip: _('Buy a coffee if you want to support the development of the project and the author'),
|
||||
action: 'copencoffee',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
class: 'cbi-button-remove',
|
||||
label: _('Report a bug'),
|
||||
tooltip: _('Report a bug on the package Github page'),
|
||||
action: 'copenissues',
|
||||
disabled: false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
package: _('Luci-app-sms-tool-js'),
|
||||
author: 'Rafał Wabik (IceG)',
|
||||
authorLink: 'https://github.com/4IceG',
|
||||
buttons: [
|
||||
{
|
||||
class: 'cbi-button-action important',
|
||||
label: _('Buy a coffee'),
|
||||
tooltip: _('Buy a coffee if you want to support the development of the project and the author'),
|
||||
action: 'ropencoffee',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
class: 'cbi-button-action',
|
||||
label: _('Become a sponsor'),
|
||||
tooltip: _('Become a sponsor if you want to support the development of the project and the author'),
|
||||
action: 'opensupport',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
class: 'cbi-button-add',
|
||||
label: _('Write on forum'),
|
||||
tooltip: _('Write in the topic of the package on the forum eko.one.pl'),
|
||||
action: 'opentopic',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
class: 'cbi-button-neutral',
|
||||
label: _('Open discussion'),
|
||||
tooltip: _('Open a package discussion on Github'),
|
||||
action: 'opendiscussion',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
class: 'cbi-button-remove',
|
||||
label: _('Report a bug'),
|
||||
tooltip: _('Report a bug on the package Github page'),
|
||||
action: 'ropenissues',
|
||||
disabled: false
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
let rows = [];
|
||||
let table = E('table', {
|
||||
'class': 'table',
|
||||
'style': 'border:1px solid var(--border-color-medium)!important; table-layout:fixed; border-collapse:collapse; width:100%;'
|
||||
}, [
|
||||
E('tr', { 'class': 'tr table-titles' }, [
|
||||
E('th', { 'class': 'th' }, _('Package name')),
|
||||
E('th', { 'class': 'th' }, _('Author (package maintainer)')),
|
||||
E('th', { 'class': 'th nowrap cbi-section-actions' })
|
||||
])
|
||||
]);
|
||||
|
||||
for (let i = 0; i < packages.length; i++) {
|
||||
let pkg = packages[i];
|
||||
let buttonElements = [];
|
||||
|
||||
for (let j = 0; j < pkg.buttons.length; j++) {
|
||||
let btn = pkg.buttons[j];
|
||||
let buttonAttrs = {
|
||||
'class': 'btn ' + btn.class,
|
||||
'data-tooltip': btn.tooltip
|
||||
};
|
||||
|
||||
if (btn.disabled) {
|
||||
buttonAttrs.disabled = true;
|
||||
} else if (btn.action) {
|
||||
buttonAttrs.click = function() { return handleOpen(btn.action); };
|
||||
}
|
||||
|
||||
buttonElements.push(E('button', buttonAttrs, btn.label));
|
||||
}
|
||||
|
||||
let authorCell = pkg.author ?
|
||||
E('a', { 'href': pkg.authorLink, 'target': '_blank', 'style': 'color:#37c' }, pkg.author) :
|
||||
'';
|
||||
|
||||
rows.push([
|
||||
pkg.package,
|
||||
authorCell,
|
||||
E('div', { 'style': 'display: flex; flex-wrap: wrap; gap: 0.5em;' }, buttonElements)
|
||||
]);
|
||||
}
|
||||
|
||||
cbi_update_table(table, rows);
|
||||
|
||||
o = s.taboption('info', form.DummyValue, '_packages_info');
|
||||
o.render = function() {
|
||||
return E('div', { 'class': 'cbi-section' }, [
|
||||
E('p', {}, _('Information about package author and available support options.')),
|
||||
table
|
||||
]);
|
||||
};
|
||||
|
||||
return m.render();
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
+709
@@ -0,0 +1,709 @@
|
||||
'use strict';
|
||||
'require baseclass';
|
||||
'require dom';
|
||||
'require fs';
|
||||
'require uci';
|
||||
'require poll';
|
||||
'require ui';
|
||||
|
||||
/*
|
||||
Copyright 2026 Rafał Wabik - IceG - From eko.one.pl forum
|
||||
|
||||
Licensed to the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
|
||||
return baseclass.extend({
|
||||
title: _('Modems'),
|
||||
|
||||
checkInterval: 12, // 12 × 5s = 60s
|
||||
|
||||
restoreAlignmentSettings() {
|
||||
let alignment = localStorage.getItem('luci-modem-tiles-alignment');
|
||||
if (alignment === 'left' || alignment === 'center' || alignment === 'right') {
|
||||
return alignment;
|
||||
}
|
||||
return 'left';
|
||||
},
|
||||
|
||||
saveAlignmentSettings(alignment) {
|
||||
localStorage.setItem('luci-modem-tiles-alignment', alignment);
|
||||
},
|
||||
|
||||
getAlignmentStyle(alignment) {
|
||||
switch(alignment) {
|
||||
case 'center':
|
||||
return 'justify-content:center;';
|
||||
case 'right':
|
||||
return 'justify-content:flex-end;';
|
||||
default:
|
||||
return 'justify-content:flex-start;';
|
||||
}
|
||||
},
|
||||
|
||||
showAlignmentModal(container) {
|
||||
let currentAlignment = this.restoreAlignmentSettings();
|
||||
|
||||
let modalContent = E('div', {}, [
|
||||
E('div', { 'class': 'cbi-section', 'style': 'margin-bottom:1em;' }, [
|
||||
E('div', { 'class': 'cbi-section-node' }, [
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title' }, _('Align preview to:')),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
E('div', { 'style': 'display:flex;flex-direction:row;gap:20px;align-items:center;' }, [
|
||||
E('label', { 'style': 'display:flex;align-items:center;cursor:pointer;' }, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'tile-alignment',
|
||||
'value': 'left',
|
||||
'id': 'align-left',
|
||||
'style': 'margin-right:6px;'
|
||||
}),
|
||||
E('span', {}, _('Left'))
|
||||
]),
|
||||
E('label', { 'style': 'display:flex;align-items:center;cursor:pointer;' }, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'tile-alignment',
|
||||
'value': 'center',
|
||||
'id': 'align-center',
|
||||
'style': 'margin-right:6px;'
|
||||
}),
|
||||
E('span', {}, _('Center'))
|
||||
]),
|
||||
E('label', { 'style': 'display:flex;align-items:center;cursor:pointer;' }, [
|
||||
E('input', {
|
||||
'type': 'radio',
|
||||
'name': 'tile-alignment',
|
||||
'value': 'right',
|
||||
'id': 'align-right',
|
||||
'style': 'margin-right:6px;'
|
||||
}),
|
||||
E('span', {}, _('Right'))
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
|
||||
ui.showModal(_('New message information block settings'), [
|
||||
modalContent,
|
||||
E('div', { 'class': 'right' }, [
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-neutral',
|
||||
'click': L.bind(function() {
|
||||
ui.hideModal();
|
||||
}, this)
|
||||
}, _('Cancel')),
|
||||
' ',
|
||||
E('button', {
|
||||
'class': 'cbi-button cbi-button-positive',
|
||||
'click': L.bind(function() {
|
||||
let selectedAlignment = document.querySelector('input[name="tile-alignment"]:checked').value;
|
||||
this.saveAlignmentSettings(selectedAlignment);
|
||||
|
||||
let alignmentStyle = this.getAlignmentStyle(selectedAlignment);
|
||||
container.style.cssText = 'display:flex;flex-wrap:wrap;gap:6px;' + alignmentStyle;
|
||||
|
||||
ui.hideModal();
|
||||
ui.addTimeLimitedNotification(null, E('p', _('Alignment settings saved successfully')), 5000, 'info');
|
||||
}, this)
|
||||
}, _('Save'))
|
||||
])
|
||||
]);
|
||||
|
||||
requestAnimationFrame(function() {
|
||||
let radioToCheck = document.getElementById('align-' + currentAlignment);
|
||||
if (radioToCheck) {
|
||||
radioToCheck.checked = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addStyles: function() {
|
||||
if (document.getElementById('modem-sms-styles')) return;
|
||||
|
||||
const style = document.createElement('style');
|
||||
style.id = 'modem-sms-styles';
|
||||
style.type = 'text/css';
|
||||
style.textContent = `
|
||||
:root {
|
||||
--sms-side-gap: clamp(4px, 3%, 12px);
|
||||
--sms-badge-bg: #34c759;
|
||||
--sms-badge-text: #ffffff;
|
||||
}
|
||||
|
||||
:root[data-darkmode="true"] {
|
||||
--sms-badge-bg: rgba(46, 204, 113, 0.66);
|
||||
--sms-badge-text: #e5e7eb;
|
||||
}
|
||||
|
||||
.modem-sms-badge {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -8px;
|
||||
background-color: var(--sms-badge-bg);
|
||||
color: var(--sms-badge-text);
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.25);
|
||||
padding: 2px 5px;
|
||||
border-radius: 4px;
|
||||
min-width: 18px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
font-size: 11px;
|
||||
display: inline-block;
|
||||
border: 1px solid transparent;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
:root[data-darkmode="true"] .modem-sms-badge {
|
||||
background-color: var(--sms-badge-bg);
|
||||
border: 1px solid rgba(46, 204, 113, 0.6);
|
||||
}
|
||||
|
||||
.sms-icon-no-messages img {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.sms-icon-with-messages img {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
:root[data-darkmode="true"] .sms-icon-no-messages img,
|
||||
:root[data-darkmode="true"] .sms-icon-with-messages img {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.modem-info-box .ifacebox-head,
|
||||
.modem-info-box .ifacebox-body {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.modem-name-truncate {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-content {
|
||||
display: flex !important;
|
||||
flex-direction: row !important;
|
||||
align-items: stretch !important;
|
||||
justify-content: center !important;
|
||||
box-sizing: border-box !important;
|
||||
width: 100% !important;
|
||||
padding-left: var(--sms-side-gap) !important;
|
||||
padding-right: var(--sms-side-gap) !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-cell {
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
box-sizing: border-box !important;
|
||||
min-width: 0 !important;
|
||||
padding: 2px !important;
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-left {
|
||||
flex: 2 1 0 !important;
|
||||
flex-direction: column !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-right {
|
||||
flex: 1 1 0 !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-top {
|
||||
display: flex !important;
|
||||
flex-direction: row !important;
|
||||
flex-wrap: nowrap !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
gap: 4px !important;
|
||||
max-width: 100% !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-top img {
|
||||
display: inline-block !important;
|
||||
flex: 0 0 auto !important;
|
||||
width: 28px !important;
|
||||
height: 28px !important;
|
||||
margin: 0 !important;
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-operator {
|
||||
font-size: 12px !important;
|
||||
white-space: nowrap !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
min-width: 0 !important;
|
||||
}
|
||||
|
||||
.modem-info-box .modem-info-tech {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
font-size: 10px !important;
|
||||
text-align: center !important;
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
},
|
||||
|
||||
getCurrentSmsCount: function(comm_port, storage) {
|
||||
if (!comm_port) return Promise.resolve(0);
|
||||
|
||||
let storageType = storage || 'MS';
|
||||
|
||||
return L.resolveDefault(
|
||||
fs.exec('/usr/bin/sms_tool', ['-s', storageType, '-d', comm_port, 'status']),
|
||||
null
|
||||
).then(function(res) {
|
||||
if (!res || res.code !== 0) return 0;
|
||||
|
||||
try {
|
||||
let output = res.stdout || '';
|
||||
let stx = output.substring(22, 27);
|
||||
let smsCount = parseInt(stx.replace(/[^0-9]/g, '')) || 0;
|
||||
return smsCount;
|
||||
} catch(e) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getModemData: function(comm_port, forced_plmn_op, mbim_op, modemdata) {
|
||||
let script = '';
|
||||
let args = [];
|
||||
|
||||
if (modemdata === 'serial' || modemdata === 'ecm') {
|
||||
script = '/usr/bin/md_serial_ecm';
|
||||
args = [comm_port, '', forced_plmn_op];
|
||||
} else if (modemdata === 'uqmi') {
|
||||
script = '/usr/bin/md_uqmi';
|
||||
args = [comm_port, '', forced_plmn_op, mbim_op];
|
||||
} else if (modemdata === 'mm') {
|
||||
script = '/usr/bin/md_modemmanager';
|
||||
args = [comm_port, '', forced_plmn_op];
|
||||
} else {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return L.resolveDefault(fs.exec_direct(script, args), null).then(function(res) {
|
||||
if (!res) return null;
|
||||
|
||||
try {
|
||||
let jsonraw = JSON.parse(res.replace(/[\u0000-\u001F\u007F-\u009F]/g, ""));
|
||||
let json = Object.values(jsonraw);
|
||||
|
||||
if (!json || json.length < 3 || !json[0] || !json[1] || !json[2]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let signalQuality = 0;
|
||||
if (json[2].csq_per) {
|
||||
signalQuality = parseInt(json[2].csq_per) || 0;
|
||||
} else if (json[2].csq) {
|
||||
let csq = parseInt(json[2].csq);
|
||||
if (!isNaN(csq) && csq >= 0) {
|
||||
signalQuality = Math.min(Math.round((csq / 31) * 100), 100);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
operator: json[2].operator_name || '-',
|
||||
mode: json[2].mode || '-',
|
||||
signalQuality: signalQuality
|
||||
};
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getSignalIcon: function(quality) {
|
||||
let icon;
|
||||
if (quality <= 0)
|
||||
icon = L.resource('icons/mobile-signal-000-000.svg');
|
||||
else if (quality < 20)
|
||||
icon = L.resource('icons/mobile-signal-000-020.svg');
|
||||
else if (quality < 40)
|
||||
icon = L.resource('icons/mobile-signal-020-040.svg');
|
||||
else if (quality < 60)
|
||||
icon = L.resource('icons/mobile-signal-040-060.svg');
|
||||
else if (quality < 80)
|
||||
icon = L.resource('icons/mobile-signal-060-080.svg');
|
||||
else
|
||||
icon = L.resource('icons/mobile-signal-080-100.svg');
|
||||
return icon;
|
||||
},
|
||||
|
||||
formatMode: function(modeRaw) {
|
||||
if (!modeRaw || modeRaw.length <= 1 || modeRaw === '-') {
|
||||
return '-';
|
||||
}
|
||||
|
||||
let modeUp = modeRaw.toUpperCase();
|
||||
let modeDisplay;
|
||||
|
||||
if (modeUp.indexOf('LTE') >= 0 || modeUp.indexOf('5G') >= 0) {
|
||||
let tech = '';
|
||||
if (modeUp.indexOf('LTE') >= 0) {
|
||||
tech = modeRaw.split(' ')[0];
|
||||
}
|
||||
if (modeUp.indexOf('5G') >= 0) {
|
||||
tech = modeRaw.split(' ')[0];
|
||||
if (modeRaw.split(' ')[1]) {
|
||||
tech += ' ' + modeRaw.split(' ')[1];
|
||||
}
|
||||
}
|
||||
|
||||
let count = (modeRaw.match(/\//g) || []).length + 1;
|
||||
modeDisplay = (count > 1) ? (tech + ' (' + count + 'CA)') : tech;
|
||||
} else {
|
||||
modeDisplay = modeRaw.split(' ')[0];
|
||||
}
|
||||
|
||||
modeDisplay = modeDisplay.replace('LTE_A', 'LTE-A');
|
||||
return modeDisplay;
|
||||
},
|
||||
|
||||
renderModemBadge: function(modemData, hasFullData, onHeaderClick) {
|
||||
let operator = modemData.operator || '-';
|
||||
let technology = this.formatMode(modemData.mode);
|
||||
let modemName = modemData.modemName || 'Modem';
|
||||
let smsCount = modemData.smsCount || 0;
|
||||
let signalQuality = modemData.signalQuality || 0;
|
||||
|
||||
let truncatedName = modemName;
|
||||
if (modemName.length > 25) {
|
||||
truncatedName = modemName.substring(0, 22) + '...';
|
||||
}
|
||||
|
||||
let signalIcon = this.getSignalIcon(signalQuality);
|
||||
let smsIconUrl = L.resource('icons/redrawsms.svg');
|
||||
|
||||
|
||||
if (!hasFullData) {
|
||||
return E('div', {
|
||||
'class': 'ifacebox modem-info-box',
|
||||
'style': 'margin:0.2em;flex:1;min-width:80px;max-width:100px;'
|
||||
}, [
|
||||
E('div', {
|
||||
'class': 'ifacebox-head port-label',
|
||||
'style': 'padding:4px 6px;font-weight:normal;font-size:13px;cursor:pointer;',
|
||||
'click': onHeaderClick
|
||||
}, [
|
||||
E('span', { 'class': 'modem-name-truncate' }, _('SMS Info'))
|
||||
]),
|
||||
E('div', {
|
||||
'class': 'ifacebox-body',
|
||||
'style': 'padding:8px;text-align:center;display:block;'
|
||||
}, [
|
||||
E('span', {
|
||||
'title': smsCount > 0 ? '%s: %d'.format(_('New SMS'), smsCount) : _('No new SMS'),
|
||||
'style': 'position:relative;display:inline-block;' + (smsCount === 0 ? 'opacity:1;' : ''),
|
||||
'class': smsCount > 0 ? 'sms-icon-active' : ''
|
||||
}, [
|
||||
E('img', {
|
||||
'src': smsIconUrl,
|
||||
'style': 'width:28px;height:28px;'
|
||||
}),
|
||||
smsCount > 0 ? E('span', {
|
||||
'class': 'modem-sms-badge'
|
||||
}, String(smsCount)) : ''
|
||||
])
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
return E('div', {
|
||||
'class': 'ifacebox modem-info-box',
|
||||
'style': 'margin:0.2em;flex:1;min-width:160px;max-width:220px;'
|
||||
}, [
|
||||
E('div', {
|
||||
'class': 'ifacebox-head port-label',
|
||||
'style': 'padding:4px 6px;font-weight:normal;font-size:13px;cursor:pointer;',
|
||||
'click': onHeaderClick
|
||||
}, [
|
||||
E('span', { 'class': 'modem-name-truncate', 'title': modemName }, truncatedName)
|
||||
]),
|
||||
E('div', {
|
||||
'class': 'ifacebox-body modem-info-content',
|
||||
'style': 'padding-top:8px;padding-bottom:8px;'
|
||||
}, [
|
||||
E('div', {
|
||||
'class': 'modem-info-cell modem-info-left',
|
||||
'style': 'text-align:center;',
|
||||
'title': '%s: %d%%'.format(_('Signal Quality'), signalQuality)
|
||||
}, [
|
||||
E('div', { 'class': 'modem-info-top' }, [
|
||||
E('img', {
|
||||
'src': signalIcon,
|
||||
'style': 'width:28px;height:28px;'
|
||||
}),
|
||||
E('span', { 'class': 'modem-info-operator' }, operator)
|
||||
]),
|
||||
E('small', { 'class': 'modem-info-tech' }, technology)
|
||||
]),
|
||||
E('div', {
|
||||
'class': 'modem-info-cell modem-info-right',
|
||||
'style': 'border-left:1px solid var(--border-color-medium);'
|
||||
}, [
|
||||
E('span', {
|
||||
'title': smsCount > 0 ? '%s: %d'.format(_('New SMS'), smsCount) : _('No new SMS'),
|
||||
'style': 'position:relative;display:inline-block;',
|
||||
'class': smsCount > 0 ? 'sms-icon-with-messages' : 'sms-icon-no-messages'
|
||||
}, [
|
||||
E('img', {
|
||||
'src': smsIconUrl,
|
||||
'style': 'width:28px;height:28px;'
|
||||
}),
|
||||
smsCount > 0 ? E('span', {
|
||||
'class': 'modem-sms-badge'
|
||||
}, String(smsCount)) : ''
|
||||
])
|
||||
])
|
||||
])
|
||||
]);
|
||||
},
|
||||
|
||||
parseSmsCountUniversal: function(smsCountString, modemIndex) {
|
||||
if (!smsCountString) return 0;
|
||||
|
||||
let parts = smsCountString.split(' ').filter(function(p) { return p.trim() !== ''; });
|
||||
|
||||
let dfmParts = {};
|
||||
let hasDfmFormat = false;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
let match = parts[i].match(/^dfm(\d+)_(\d+)$/);
|
||||
if (match) {
|
||||
hasDfmFormat = true;
|
||||
dfmParts[parseInt(match[1])] = parseInt(match[2]) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDfmFormat) {
|
||||
if (modemIndex != null) {
|
||||
return dfmParts[modemIndex] || 0;
|
||||
} else {
|
||||
if (dfmParts[1] != null) {
|
||||
return dfmParts[1];
|
||||
}
|
||||
let keys = Object.keys(dfmParts);
|
||||
if (keys.length > 0) {
|
||||
return dfmParts[parseInt(keys[0])] || 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
let simpleMatch = smsCountString.match(/^(\d+)(\s|$)/);
|
||||
if (simpleMatch) {
|
||||
return parseInt(simpleMatch[1]) || 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
L.resolveDefault(uci.load('sms_tool_js')),
|
||||
L.resolveDefault(uci.load('defmodems'))
|
||||
]).then(L.bind(function() {
|
||||
let onTopSms = uci.get('sms_tool_js', '@sms_tool_js[0]', 'ontopsms');
|
||||
|
||||
if (onTopSms !== '1') {
|
||||
return null;
|
||||
}
|
||||
|
||||
window.modemDetectorCounter = ('modemDetectorCounter' in window) ?
|
||||
++window.modemDetectorCounter : 0;
|
||||
|
||||
if (!('modemDetectorData' in window)) {
|
||||
window.modemDetectorData = null;
|
||||
}
|
||||
|
||||
if (window.modemDetectorData !== null &&
|
||||
window.modemDetectorCounter % this.checkInterval !== 0) {
|
||||
return window.modemDetectorData;
|
||||
}
|
||||
|
||||
window.modemDetectorCache = {};
|
||||
|
||||
let defmodemSections = uci.sections('defmodems', 'defmodems') || [];
|
||||
let smsCountString = uci.get('sms_tool_js', '@sms_tool_js[0]', 'sms_count') || '';
|
||||
let storage = uci.get('sms_tool_js', '@sms_tool_js[0]', 'storage') || 'MS';
|
||||
let readport = uci.get('sms_tool_js', '@sms_tool_js[0]', 'readport') || '/dev/ttyUSB2';
|
||||
|
||||
let serialModems = defmodemSections.filter(function(s) {
|
||||
return s.modemdata === 'serial';
|
||||
}).slice(0, 5);
|
||||
|
||||
let hasDefmodems = serialModems.length > 0;
|
||||
|
||||
if (hasDefmodems) {
|
||||
let modemsToLoad = [];
|
||||
for (let i = 0; i < serialModems.length; i++) {
|
||||
let modem = serialModems[i];
|
||||
modemsToLoad.push({
|
||||
index: i + 1,
|
||||
comm_port: modem.comm_port || '',
|
||||
forced_plmn_op: modem.forced_plmn_op || '0',
|
||||
mbim_op: modem.mbim_op || '0',
|
||||
modemdata: modem.modemdata || 'serial',
|
||||
modemName: modem.modem || (_('Modem') + ' ' + (i + 1)),
|
||||
smsCount: this.parseSmsCountUniversal(smsCountString, i + 1),
|
||||
storage: storage,
|
||||
skipModemData: false
|
||||
});
|
||||
}
|
||||
window.modemDetectorData = {
|
||||
modems: modemsToLoad,
|
||||
mode: 'multi'
|
||||
};
|
||||
return window.modemDetectorData;
|
||||
}
|
||||
|
||||
let savedSmsCount = this.parseSmsCountUniversal(smsCountString, null);
|
||||
|
||||
window.modemDetectorData = {
|
||||
modems: [{
|
||||
index: 1,
|
||||
comm_port: readport,
|
||||
forced_plmn_op: '0',
|
||||
mbim_op: '0',
|
||||
modemdata: 'serial',
|
||||
modemName: 'Modem',
|
||||
smsCount: savedSmsCount,
|
||||
storage: storage,
|
||||
skipModemData: false
|
||||
}],
|
||||
mode: 'sms-only'
|
||||
};
|
||||
return window.modemDetectorData;
|
||||
|
||||
}, this));
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
this.addStyles();
|
||||
|
||||
if (!data || !data.modems || data.modems.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let currentAlignment = this.restoreAlignmentSettings();
|
||||
let alignmentStyle = this.getAlignmentStyle(currentAlignment);
|
||||
|
||||
let container = E('div', {
|
||||
'class': 'network-status-table',
|
||||
'style': 'display:flex;flex-wrap:wrap;gap:6px;' + alignmentStyle
|
||||
});
|
||||
|
||||
let hasDefmodems = data.mode === 'multi';
|
||||
let isSmsOnly = data.mode === 'sms-only';
|
||||
|
||||
let self = this;
|
||||
let onHeaderClick = function(ev) {
|
||||
ev.stopPropagation();
|
||||
self.showAlignmentModal(container);
|
||||
};
|
||||
|
||||
data.modems.forEach(L.bind(function(modem) {
|
||||
let badgeId = 'modem-badge-' + modem.index;
|
||||
let skipModemData = modem.skipModemData || isSmsOnly;
|
||||
|
||||
if (window.modemDetectorCache && window.modemDetectorCache[modem.index]) {
|
||||
let cached = window.modemDetectorCache[modem.index];
|
||||
container.appendChild(this.renderModemBadge(cached, hasDefmodems && !skipModemData, onHeaderClick));
|
||||
} else {
|
||||
let boxStyle = skipModemData
|
||||
? 'margin:0.2em;flex:1;min-width:80px;max-width:100px;'
|
||||
: 'margin:0.2em;flex:1;min-width:160px;max-width:220px;';
|
||||
|
||||
container.appendChild(
|
||||
E('div', {
|
||||
'class': 'ifacebox modem-info-box',
|
||||
'style': boxStyle,
|
||||
'id': badgeId
|
||||
}, [
|
||||
E('div', {
|
||||
'class': 'ifacebox-head port-label',
|
||||
'style': 'padding:4px 6px;font-weight:normal;font-size:13px;cursor:pointer;',
|
||||
'click': onHeaderClick
|
||||
}, [
|
||||
E('span', { 'class': 'modem-name-truncate', 'title': modem.modemName || _('Modem') },
|
||||
modem.modemName || (_('Modem') + ': ' + modem.index))
|
||||
]),
|
||||
E('div', {
|
||||
'class': 'ifacebox-body',
|
||||
'style': 'padding:0 8px;padding-top:16px;text-align:center;display:flex;align-items:center;justify-content:center;gap:6px;'
|
||||
}, [
|
||||
E('span', {'class': 'spinning', 'style': 'display:inline-block;'}),
|
||||
E('span', {'style': 'font-size:12px;'}, _('Loading...'))
|
||||
])
|
||||
])
|
||||
);
|
||||
|
||||
let modemDataPromise = skipModemData
|
||||
? Promise.resolve(null)
|
||||
: this.getModemData(modem.comm_port, modem.forced_plmn_op, modem.mbim_op, modem.modemdata);
|
||||
|
||||
let sleepPromise = new Promise(function(resolve) { setTimeout(resolve, 2000); });
|
||||
|
||||
Promise.all([
|
||||
modemDataPromise,
|
||||
this.getCurrentSmsCount(modem.comm_port, modem.storage),
|
||||
sleepPromise
|
||||
]).then(L.bind(function(results) {
|
||||
let result = results[0];
|
||||
let currentSmsCount = results[1];
|
||||
|
||||
let savedSmsCount = modem.smsCount || 0;
|
||||
let newSmsCount = Math.max(0, currentSmsCount - savedSmsCount);
|
||||
|
||||
let modemInfo = {
|
||||
operator: '-',
|
||||
mode: '-',
|
||||
modemName: modem.modemName || _('Modem'),
|
||||
smsCount: newSmsCount,
|
||||
signalQuality: 0
|
||||
};
|
||||
|
||||
if (result) {
|
||||
modemInfo.operator = result.operator || '-';
|
||||
modemInfo.mode = result.mode || '-';
|
||||
modemInfo.signalQuality = result.signalQuality || 0;
|
||||
}
|
||||
|
||||
if (!window.modemDetectorCache) {
|
||||
window.modemDetectorCache = {};
|
||||
}
|
||||
window.modemDetectorCache[modem.index] = modemInfo;
|
||||
|
||||
let badgeElement = document.getElementById(badgeId);
|
||||
if (badgeElement) {
|
||||
let newBadge = this.renderModemBadge(modemInfo, hasDefmodems && !skipModemData, onHeaderClick);
|
||||
newBadge.id = badgeId;
|
||||
badgeElement.parentNode.replaceChild(newBadge, badgeElement);
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
}, this));
|
||||
|
||||
return container;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user