mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-31 12:05:13 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,18 @@
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI for DroidNet
|
||||
LUCI_DEPENDS:=+adb +curl +screen
|
||||
LUCI_DESCRIPTION:=Manage Android modem and optimize network settings.
|
||||
|
||||
PKG_MAINTAINER:=Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
PKG_VERSION:=1.1
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
@@ -0,0 +1,97 @@
|
||||
<div align="center">
|
||||
<h1>LuCI support for Android Modem</h1>
|
||||
<h3>Manage Android modem and optimize network settings.</h3>
|
||||
</div>
|
||||
<hr/>
|
||||
<div align="center">
|
||||
<img alt="License" src="https://img.shields.io/github/license/animegasan/luci-app-droidmodem?style=for-the-badge">
|
||||
<img alt="Forks" src="https://img.shields.io/github/forks/animegasan/luci-app-droidmodem?style=for-the-badge">
|
||||
<img alt="Release" src="https://img.shields.io/github/v/release/animegasan/luci-app-droidmodem?style=for-the-badge">
|
||||
<img alt="Downloads" src="https://img.shields.io/github/downloads/animegasan/luci-app-droidmodem/total?style=for-the-badge">
|
||||
</div>
|
||||
<br/>
|
||||
<div align="center">
|
||||
<a target="_blank" href="https://saweria.co/animegasan" alt="Saweria"><img src="https://img.shields.io/badge/saweria-donation?style=for-the-badge&logo=adobeindesign&labelColor=black&color=%23FFA401"></a>
|
||||
<a target="_blank" href="https://www.paypal.com/paypalme/animegasan" alt="PayPal"><img src="https://img.shields.io/badge/paypal-donation?style=for-the-badge&logo=paypal&labelColor=black&color=%23003087"></a>
|
||||
<a target="_blank" href="https://www.buymeacoffee.com/animegasan" alt="BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donation?style=for-the-badge&logo=buymeacoffee&labelColor=black&color=%23FFDD00"></a>
|
||||
</div>
|
||||
<hr/>
|
||||
|
||||
DroidModem is an application designed specifically for managing and optimizing network settings on Android modems. With advanced features, DroidModem allows users to have full control over their network connectivity and modem performance, ensuring a better user experience and more stable connections.
|
||||
|
||||
## 📥 | Install via Terminal
|
||||
```
|
||||
curl -s https://raw.githubusercontent.com/animegasan/luci-app-droidmodem/master/install | sh
|
||||
```
|
||||
|
||||
## 📱 | Supported Devices
|
||||
- Android version 10 or greater
|
||||
- Rooted Android for version 10 and lower
|
||||
|
||||
## 🎯 | Recommended Magisk Modules
|
||||
<table>
|
||||
<thead align="center">
|
||||
<tr border: none;>
|
||||
<td><b>📦 Name</b></td>
|
||||
<td><b>✍️ Description</b></td>
|
||||
<td><b>⬇️ Downloads</b></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><b>ADB Root Enabler</b></td>
|
||||
<td>Enable unauthenticated adb daemon, useful for devices with a broken screen!</td>
|
||||
<td><a target="_blank" href="https://github.com/anasfanani/Adb-Root-Enabler"><img alt="Downloads" src="https://img.shields.io/github/downloads/anasfanani/Adb-Root-Enabler/total?style=flat-square&label=Downloads&labelColor=343b41"/></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Magisk Autoboot</b></td>
|
||||
<td>Enable automatic booting of your Android device when it's connected to a charger or USB.</td>
|
||||
<td><a target="_blank" href="https://github.com/anasfanani/magisk-autoboot"><img alt="Downloads" src="https://img.shields.io/github/downloads/anasfanani/magisk-autoboot/total?style=flat-square&label=Downloads&labelColor=343b41"/></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Input Power Control</b></td>
|
||||
<td>Automatically switches charging off when battery level reaches a certain disable threshold and back on as soon as it drowns to enable threshold.</td>
|
||||
<td><a target="_blank" href="https://github.com/Magisk-Modules-Repo/IPControl"><img alt="Downloads" src="https://img.shields.io/github/downloads/Magisk-Modules-Repo/IPControl/latest/total?style=flat-square&label=Downloads&labelColor=343b41"/></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## ✨ | Features
|
||||
### 📊 | Monitoring Service
|
||||
Tracks network activity on Android modem, automatically restarts networks including tunnel services such as Neko, OpenClash, Passwall, and V2Ray based on predefined configurations. Supports ping via methods such as HTTP, HTTPS, TCP, and ICMP. Continuous monitoring can maintain optimal network connectivity, reducing risk of disruption and downtime.
|
||||
|
||||
### ℹ️ | Information Service
|
||||
Provides comprehensive information about various aspects of Android modem, ensuring access to important details about device performance and connectivity. This includes device details such as model, manufacturer, and operating system version, battery information such as current charge level and battery health, insights about wireless connectivity such as Wi-Fi networks, and information about cellular connectivity such as network provider.
|
||||
<details><summary>Screenshoot</summary>
|
||||
<p>
|
||||
<img src="https://github.com/animegasan/luci-app-droidmodem/assets/14136053/5a1129a5-1106-4e69-8222-848228e43e6b">
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### 📶 | Mobile Network
|
||||
Displays IP address of Android modem, status of wireless connection, mobile data, and airplane mode. Ypu can manually enable or disable wireless connection, mobile data, and airplane mode as needed.
|
||||
<details><summary>Screenshoot</summary>
|
||||
<p>
|
||||
<img src="https://github.com/animegasan/luci-app-droidmodem/assets/14136053/d9451e7a-9117-45b2-8944-9eab5cf97da0">
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### ⚡ | Power Options and Application Manager
|
||||
- Power Options<br>
|
||||
Gives full control over power operations of Android modem, allowing management of different power modes from one easily accessible place. You can shut down device, restart it, reboot device to enter fastboot mode, and reboot device to enter recovery mode.
|
||||
- Application Manager<br>
|
||||
Manage applications installed on Android modem, adding necessary applications to enhance functionality or support specific needs and removing unnecessary applications for optimal device performance.
|
||||
<details><summary>Screenshoot</summary>
|
||||
<p>
|
||||
<img src="https://github.com/animegasan/luci-app-droidmodem/assets/14136053/8ae4f4e4-1e87-4462-9fb1-11c879bcc4d4">
|
||||
</p>
|
||||
</details>
|
||||
|
||||
### 📩 | Inbox Messages
|
||||
View all incoming messages received by Android modem, including sender information, message content, and reception date. Useful for monitoring important messages without need for a separate device. Using [ShellMS](https://github.com/try2codesecure/ShellMS) for efficient messaging, leveraging its capabilities to enhance communication directly from the development environment.
|
||||
|
||||
<details><summary>Screenshoot</summary>
|
||||
<p>
|
||||
<img src="https://github.com/animegasan/luci-app-droidmodem/assets/14136053/8816329b-f8eb-47a0-a292-bb6bf8073f4d">
|
||||
</p>
|
||||
</details>
|
||||
@@ -0,0 +1,275 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require fs';
|
||||
'require ui';
|
||||
|
||||
return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null,
|
||||
load: function() {
|
||||
return uci.load('droidnet').then(function() {
|
||||
var device = uci.get('droidnet', 'device', 'id');
|
||||
return Promise.all([
|
||||
fs.exec('adb', ['-s', device, 'shell', 'getprop']).then(function(result) {
|
||||
var deviceInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
var properties = {
|
||||
'ro.serialno': 'device_id',
|
||||
'ro.product.brand': 'device_brand',
|
||||
'ro.product.model': 'device_model',
|
||||
'ro.product.device': 'device_code',
|
||||
'ro.board.platform': 'device_soc',
|
||||
'dalvik.vm.isa.arm.variant': 'device_cpu',
|
||||
'ro.build.version.release': 'device_version',
|
||||
'ro.build.version.sdk': 'device_sdk',
|
||||
'ro.build.version.security_patch': 'device_security'
|
||||
};
|
||||
if (stderr) {
|
||||
deviceInfo['device_section'] = stderr.trim();
|
||||
} else {
|
||||
var lines = stdout.split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
for (var property in properties) {
|
||||
if (lines[i].includes('[' + property + ']')) {
|
||||
var parts = lines[i].split(']: [');
|
||||
var value = parts[1].substring(0, parts[1].length - 1);
|
||||
if (value.includes(',')) {
|
||||
value = value.split(',').map(function(item) {return item.trim();});
|
||||
};
|
||||
deviceInfo[properties[property]] = value;
|
||||
break;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
return deviceInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'uptime']).then(function(result) {
|
||||
var uptimeInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
uptimeInfo['uptime_section'] = stderr.trim();
|
||||
} else {
|
||||
var parts = stdout.trim().split(/\s+/);
|
||||
var uptimeParts = parts.slice(0, 4);
|
||||
uptimeInfo['device_uptime'] = uptimeParts.join(' ').replace(/,$/, '');
|
||||
};
|
||||
return uptimeInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'uname', '-a']).then(function(result) {
|
||||
var kernelInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
kernelInfo['uname_section'] = stderr.trim();
|
||||
} else {
|
||||
var parts = stdout.trim().split(/\s+/);
|
||||
kernelInfo['device_uname'] = {'kernel': parts[2], 'arch': parts[12]};
|
||||
};
|
||||
return kernelInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'cat', '/proc/meminfo']).then(function(result) {
|
||||
var memmoryInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
memmoryInfo['memory_section'] = stderr.trim();
|
||||
} else {
|
||||
var parts = stdout.trim().split(/\s+/);
|
||||
var kbValue = parseInt(parts[1]) + parseInt(parts[4]);
|
||||
var gbValue = kbValue / (1024 * 1024);
|
||||
memmoryInfo['device_memory'] = gbValue.toFixed(0) + ' GB';
|
||||
};
|
||||
return memmoryInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'dumpsys', 'battery']).then(function(result) {
|
||||
var batteryInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
var properties = {
|
||||
'level': 'battery_level',
|
||||
'voltage': 'battery_voltage',
|
||||
'technology': 'battery_technology',
|
||||
'temperature': 'battery_temperature',
|
||||
'Charge counter': 'battery_counter'
|
||||
};
|
||||
if (stderr) {
|
||||
batteryInfo['battery_section'] = stderr.trim();
|
||||
} else {
|
||||
var lines = stdout.split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
for (var property in properties) {
|
||||
if (line.startsWith(property + ':')) {
|
||||
var parts = line.split(':');
|
||||
var value = parts[1].trim();
|
||||
if (property === 'level') {
|
||||
value = parseInt(value) + ' %';
|
||||
} else if (property === 'voltage') {
|
||||
value = (parseInt(value) / 1000).toFixed(2) + ' V';
|
||||
} else if (property === 'temperature') {
|
||||
value = (parseInt(value) / 10) + ' °C';
|
||||
} else if (property === 'Charge counter') {
|
||||
value = parseInt(value) / 1000 + ' μAh';
|
||||
};
|
||||
batteryInfo[properties[property]] = value;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
return batteryInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'su', '-v']).then(function(result) {
|
||||
var rootInfo = {};
|
||||
var stdout = result.stdout ? result.stdout.trim() : '';
|
||||
var stderr = result.stderr;
|
||||
if (stderr || stdout === '/system/bin/sh: su: not found' || stdout === '/system/bin/sh: su: inaccessible or not found') {
|
||||
rootInfo['device_root'] = false;
|
||||
} else {
|
||||
var parts = stdout.split(':');
|
||||
rootInfo['device_root'] = {'version': parts[0], 'name': parts[1]};
|
||||
};
|
||||
return rootInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
})
|
||||
]).then(function(results) {
|
||||
var deviceInfo = results[0];
|
||||
var uptimeInfo = results[1];
|
||||
var kernelInfo = results[2];
|
||||
var memmoryInfo = results[3];
|
||||
var batteryInfo = results[4];
|
||||
var rootInfo = results[5];
|
||||
if (device && deviceInfo && uptimeInfo && kernelInfo && memmoryInfo && batteryInfo && rootInfo) {
|
||||
return Object.assign({}, {device: device}, deviceInfo, uptimeInfo, kernelInfo, memmoryInfo, batteryInfo, rootInfo)
|
||||
} else {
|
||||
throw new Error(_('Failed to get complete device information.'));
|
||||
};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
render: function(data) {
|
||||
var header = [
|
||||
E('h2', {'class': 'section-title'}, _('DroidNet')),
|
||||
E('div', {'class': 'cbi-map-descr'}, _('Manage Android modem and optimize network settings.'))
|
||||
];
|
||||
if (data.device_section) {
|
||||
ui.addNotification(_('Error: Device conflict!'),
|
||||
E('p', _('Please check your settings, the configured device and ADB devices are conflicting.')), 'danger'
|
||||
);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('div', {'class': 'cbi-value', 'style': 'text-align: center; display: block;'}, [
|
||||
E('em', _('No device detected or connected.'))
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
var device = [
|
||||
E('h3', {'class': 'section-title'}, _('Device Information')),
|
||||
E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-title', 'style': 'display: none;'}),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Device ID')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_id || '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Processors')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_cpu ? (data.device_cpu.toUpperCase()) : '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Root status')),
|
||||
E('td', {'class': 'td left', 'width': '25%'},
|
||||
data.device_root === false ? _('Non-root') :
|
||||
data.device_root ? (_('Root with %s (%s)').format(data.device_root.name, data.device_root.version)) :
|
||||
'-'
|
||||
),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('RAM')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_memory || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Brand name')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_brand ? (data.device_brand.charAt(0).toUpperCase() + data.device_brand.slice(1)) : '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Architecture')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_uname ? (data.device_uname.arch) : '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Code name')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_code || '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Android version')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_version || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Model number')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_model ? (data.device_model.charAt(0).toUpperCase() + data.device_model.slice(1)) : '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('SDK version')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_sdk || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Used time')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_uptime || '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Security patch level')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_security || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('System on Chip (SoC)')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_soc ? (data.device_soc.toUpperCase()) : '-'),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, _('Kernel version')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.device_uname ? (data.device_uname.kernel) : '-')
|
||||
])
|
||||
])
|
||||
];
|
||||
var battery = [
|
||||
E('h3', {'class': 'section-title'}, _('Battery Information')),
|
||||
E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-title', 'style': 'display: none;'}),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Level')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.battery_level || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Charge counter')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.battery_counter || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Voltage')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.battery_voltage || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Temperature')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.battery_temperature || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Technology')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.battery_technology || '-')
|
||||
]),
|
||||
])
|
||||
];
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, device),
|
||||
E('div', {'class': 'cbi-section'}, battery)
|
||||
]);
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,228 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require fs';
|
||||
'require ui';
|
||||
|
||||
var page = 1;
|
||||
function renderTable(data, display) {
|
||||
var startIndex = (page - 1) * display;
|
||||
var endIndex = Math.min(startIndex + display, data.length);
|
||||
var currentPageData = data.slice(startIndex, endIndex);
|
||||
var tableRows = currentPageData.map(function(inbox, index) {
|
||||
var rowClass = index % 2 === 0 ? 'cbi-rowstyle-1' : 'cbi-rowstyle-2';
|
||||
var message = inbox.message.replace(/\n/g, '<br>');
|
||||
return E('tr', {'class': 'tr ' + rowClass }, [
|
||||
E('td', {'class': 'td'}, inbox.received.date),
|
||||
E('td', {'class': 'td'}, inbox.address),
|
||||
E('td', {'class': 'td'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(inbox.address, [
|
||||
E('p', [
|
||||
E('em', `${inbox.received.date} - ${inbox.received.time}`)
|
||||
]),
|
||||
E('p', message),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('button', {
|
||||
'class': 'btn',
|
||||
'click': ui.hideModal
|
||||
}, _('OK'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('View'))
|
||||
])
|
||||
]);
|
||||
});
|
||||
return E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-titles'}, [
|
||||
E('th', {'class': 'th'}, _('Date')),
|
||||
E('th', {'class': 'th'}, _('Address')),
|
||||
E('th', {'class': 'th'})
|
||||
]),
|
||||
E(tableRows)
|
||||
]);
|
||||
};
|
||||
function updateTable(data, display) {
|
||||
var container = document.getElementsByClassName('table-container');
|
||||
var prev = document.querySelector('.prev');
|
||||
var next = document.querySelector('.next');
|
||||
for (var i = 0; i < container.length; i++) {
|
||||
container[i].innerHTML = '';
|
||||
var table = renderTable(data, display);
|
||||
container[i].appendChild(table);
|
||||
};
|
||||
var total = data.length;
|
||||
var pages = Math.ceil(total / display);
|
||||
if (pages <= 1) {
|
||||
prev.disabled = true;
|
||||
next.disabled = true;
|
||||
} else if (page <= 1) {
|
||||
prev.disabled = true;
|
||||
next.disabled = false;
|
||||
} else if (page >= pages) {
|
||||
prev.disabled = false;
|
||||
next.disabled = true;
|
||||
} else {
|
||||
prev.disabled = false;
|
||||
next.disabled = false;
|
||||
};
|
||||
var start = (page - 1) * display + 1;
|
||||
var end = Math.min(start + display - 1, total);
|
||||
document.getElementById('page-info').innerText = _('Displaying %s - %s of %s').format(start, end, total);
|
||||
};
|
||||
|
||||
return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null,
|
||||
load: function() {
|
||||
return uci.load('droidnet').then(function() {
|
||||
var device = uci.get('droidnet', 'device', 'id');
|
||||
var display = uci.get('droidnet', 'device', 'display_msg');
|
||||
return Promise.all([
|
||||
fs.exec('adb', ['-s', device, 'shell', 'content', 'query', '--uri', 'content://sms', '--projection', 'date_sent,date,address,body']).then(function(result) {
|
||||
var messages = [];
|
||||
var stdout = result.stdout;
|
||||
var stderr = result.stderr;
|
||||
if (stderr) {
|
||||
messages['messages_section'] = stderr.trim();
|
||||
} else if (stdout.includes('Error')) {
|
||||
messages['messages_info'] = stdout.trim();
|
||||
} else {
|
||||
var lines = stdout.trim().split('Row: ');
|
||||
lines.shift();
|
||||
var properties = {
|
||||
'body': 'message',
|
||||
'address': 'address',
|
||||
'date': 'received'
|
||||
};
|
||||
lines.forEach(function(line) {
|
||||
var pairs = line.split(',');
|
||||
var inbox = [];
|
||||
pairs.forEach(function(pair) {
|
||||
var keyValue = pair.split('=');
|
||||
if (keyValue.length === 2) {
|
||||
var key = keyValue[0].trim();
|
||||
var value = keyValue[1].trim();
|
||||
if (properties.hasOwnProperty(key)) {
|
||||
if (key === 'body') {
|
||||
var start = line.indexOf('body=') + 5;
|
||||
var message = line.substring(start);
|
||||
inbox[properties[key]] = message;
|
||||
} else if (key === 'date') {
|
||||
var timestamp = parseInt(value);
|
||||
var date = new Date(timestamp).toLocaleDateString(undefined, {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: '2-digit'
|
||||
});
|
||||
var time = new Date(timestamp).toLocaleTimeString(undefined, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
inbox[properties[key]] = {'date': date, 'time': time}
|
||||
} else {
|
||||
inbox[properties[key]] = value;
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
messages.push(inbox);
|
||||
});
|
||||
};
|
||||
return messages;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
})
|
||||
]).then(function(result) {
|
||||
var messages = result[0];
|
||||
if (device && display && messages) {
|
||||
return Object.assign({device: device}, {display: display}, messages);
|
||||
} else {
|
||||
throw new Error(_('Failed to get complete device information.'));
|
||||
};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
render: function(data) {
|
||||
var header = [
|
||||
E('h2', {'class': 'section-title'}, _('DroidNet')),
|
||||
E('div', {'class': 'cbi-map-descr'}, _('Manage Android modem and optimize network settings.'))
|
||||
];
|
||||
if (data.messages_section) {
|
||||
ui.addNotification(_('Error: Device conflict!'),
|
||||
E('p', _('Please check your settings, the configured device and ADB devices are conflicting.')), 'danger'
|
||||
);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('div', {'class': 'cbi-value', 'style': 'text-align: center; display: block;'}, [
|
||||
E('em', _('No device detected or connected.'))
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else if (data.messages_info) {
|
||||
ui.addNotification(_('Error: Device not supported!'),
|
||||
E('p', _('Unable to read message because the device version cannot execute the command. Please ensure the device is rooted or has Android version 10 or above.')), 'danger'
|
||||
);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('h3', {'class': 'section-title'}, _('Error Information')),
|
||||
E('textarea', {
|
||||
'id': 'syslog',
|
||||
'class': 'cbi-input-textarea',
|
||||
'style': 'height: 500px; overflow-y: scroll;',
|
||||
'readonly': 'readonly',
|
||||
'wrap': 'off',
|
||||
'rows': 1
|
||||
}, data.messages_info)
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
var value = Object.values(data).filter(function(obj) {
|
||||
return typeof obj === 'object' && !('device' in obj);
|
||||
});
|
||||
var display = parseInt(data.display);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('h3', {'class': 'section-title'}, _('Inbox Messages')),
|
||||
E('div', {'class': 'cbi-section-descr'}, _('Displays incoming messages with sender, subject, content, and date and time of receipt.')),
|
||||
E('div', {'class': 'controls', 'style': 'display: flex; flex-wrap: wrap; justify-content: space-around; padding: 1em 0;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'style': 'flex-basis: 20%; text-align: center;',
|
||||
'disabled': true,
|
||||
'click': function() {
|
||||
page--;
|
||||
updateTable(value, display);
|
||||
}
|
||||
}, '«'),
|
||||
E('div', {'class': 'text', 'id': 'page-info', 'style': 'flex-grow: 1; align-self: center; text-align: center;'}, _('Displaying 1-%s of %s').format(display, value.length)),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'style': 'flex-basis: 20%; text-align: center;',
|
||||
'click': function() {
|
||||
page++;
|
||||
updateTable(value, display);
|
||||
}
|
||||
}, '»')
|
||||
]),
|
||||
E('div', {'class': 'table-container'}, renderTable(value, display))
|
||||
])
|
||||
]);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require fs';
|
||||
'require ui';
|
||||
'require poll';
|
||||
|
||||
return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null,
|
||||
load: function() {
|
||||
var notification = false;
|
||||
return Promise.all([
|
||||
poll.add(function() {
|
||||
fs.read('/var/log/droidnet.log').then(function(result) {
|
||||
if (!result || result.trim() === '') {
|
||||
ui.addNotification(_('Error: Read log file!'),
|
||||
E('p', _('Unable to read the interface info from /var/log/droidnet.log.')), 'danger'
|
||||
);
|
||||
notification = true;
|
||||
} else {
|
||||
var data = result.trim();
|
||||
var syslog = document.getElementById('syslog');
|
||||
var filter = document.getElementById('log-filter').value;
|
||||
var direction = document.getElementById('log-direction').value;
|
||||
if (filter !== 'all') {
|
||||
var value = data.split('\n').filter(function(log) {
|
||||
return log.includes(filter);
|
||||
}).join('\n');
|
||||
data = value;
|
||||
};
|
||||
if (direction === 'up') {
|
||||
var value = data.split('\n').reverse().join('\n');
|
||||
syslog.innerHTML = value;
|
||||
} else {
|
||||
syslog.innerHTML = data;
|
||||
};
|
||||
notification = false;
|
||||
};
|
||||
}).catch(function(error) {
|
||||
ui.addNotification(_('Error: Read log file!'),
|
||||
E('p', _('An error occurred while reading the file') + `: ${error}`), 'danger'
|
||||
);
|
||||
notification = true;
|
||||
});
|
||||
})
|
||||
]);
|
||||
},
|
||||
render: function() {
|
||||
var header = [
|
||||
E('h2', {'class': 'section-title'}, _('DroidNet')),
|
||||
E('div', {'class': 'cbi-map-descr'}, _('Manage Android modem and optimize network settings.'))
|
||||
];
|
||||
var menu = [
|
||||
E('label', {'for': 'log-filter', 'style': 'margin-right: 8px;'}, _('Filter by service') + ' : '),
|
||||
E('select', {'id': 'log-filter', 'style': 'margin: 8px 8px 8px 0;'}, [
|
||||
E('option', {'value': 'all', 'selected': 'selected'}, _('All')),
|
||||
E('option', {'value': 'Application' }, _('Application')),
|
||||
E('option', {'value': 'Monitoring' }, _('Monitoring')),
|
||||
E('option', {'value': 'Network' }, _('Network')),
|
||||
E('option', {'value': 'Power' }, _('Power'))
|
||||
]),
|
||||
E('label', {'for': 'log-direction', 'style': 'margin-right: 8px;'}, _('Log direction') + ' : '),
|
||||
E('select', {'id': 'log-direction', 'style': 'margin: 8px 8px 8px 0;'}, [
|
||||
E('option', {'value': 'down', 'selected': 'selected'}, _('Down')),
|
||||
E('option', {'value': 'up' }, _('Up'))
|
||||
]),
|
||||
E('div', {'class': 'log-button', 'style': 'display: inline-block; margin: 0 8px 8px 0;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin-right: 10px',
|
||||
'click': function() {
|
||||
fs.read('/var/log/droidnet.log').then(function(result) {
|
||||
var message = _('DroidNet logs have been successfully cleared.');
|
||||
var date = new Date().toLocaleDateString(undefined, {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: '2-digit'
|
||||
});
|
||||
var time = new Date().toLocaleTimeString(undefined, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
var notif = `${date}, ${time} - ${message}\n`;
|
||||
fs.write('/var/log/droidnet.log', notif);
|
||||
});
|
||||
}
|
||||
}, _('Clear')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-save',
|
||||
'click': function() {
|
||||
var logs = document.getElementById('syslog').value;
|
||||
var blob = new Blob([logs], {type: 'text/plain'});
|
||||
var link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = 'droidnet.log';
|
||||
link.click();
|
||||
}
|
||||
}, _('Download'))
|
||||
])
|
||||
];
|
||||
var body = [
|
||||
E('textarea', {
|
||||
'id': 'syslog',
|
||||
'class': 'cbi-input-textarea',
|
||||
'style': 'height: 500px; overflow-y: scroll;',
|
||||
'readonly': 'readonly',
|
||||
'wrap': 'off',
|
||||
'rows': 1
|
||||
})
|
||||
];
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('div', {'class': 'cbi-control'}, menu),
|
||||
E('div', {'class': 'cbi-body'}, body)
|
||||
])
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,589 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>, Anas Fanani <anas@anasfanani.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require fs';
|
||||
'require ui';
|
||||
|
||||
function closeUi(type) {
|
||||
if (type === 'OK') {
|
||||
return E('button', {
|
||||
'class': 'btn',
|
||||
'click': function() {
|
||||
return window.location.reload();
|
||||
}
|
||||
}, _('OK'));
|
||||
} else {
|
||||
return E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin-right: 10px',
|
||||
'click': ui.hideModal
|
||||
}, _('Cancel'));
|
||||
};
|
||||
};
|
||||
function writeLog(message) {
|
||||
var logFile = '/var/log/droidnet.log';
|
||||
fs.read(logFile).then(function(result) {
|
||||
var service = _('Network service');
|
||||
var date = new Date().toLocaleDateString(undefined, {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: '2-digit'
|
||||
});
|
||||
var time = new Date().toLocaleTimeString(undefined, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
var notif = `${date}, ${time} - ${service}: ${message}`;
|
||||
var newData = result.trim() + '\n' + notif;
|
||||
return fs.write(logFile, newData);
|
||||
});
|
||||
};
|
||||
function renderTableCell(data, id) {
|
||||
if (id === 'sim-1') {
|
||||
var tab = 1;
|
||||
var sim = 0;
|
||||
var display = 'table';
|
||||
var imei = data.imei_sim01;
|
||||
} else {
|
||||
var tab = 2;
|
||||
var sim = 1;
|
||||
var display = 'none';
|
||||
var imei = data.imei_sim02;
|
||||
};
|
||||
return E('table', {'class': 'table cbi-section-table', 'id': `sim-${tab}`, 'style': `display: ${display}`}, [
|
||||
E('tr', {'class': 'tr table-titles', 'style': 'display: none;'}),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Operator name')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.operator[sim] || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Network type')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.signal[sim] || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Roaming mode')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.roaming[sim] === 'true' ? _('On') :
|
||||
_('Off')
|
||||
)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('MCC')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.mcc[sim] || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('IMEI')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, imei || '-')
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Driver')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, data.driver || '-')
|
||||
])
|
||||
]);
|
||||
};
|
||||
function renderTableWiFi(device) {
|
||||
fs.exec('adb', ['-s', device, 'shell', 'dumpsys', 'wifi', '|', 'grep', 'mWifiInfo SSID']).then(function(result) {
|
||||
var table, wifiInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
var properties = {
|
||||
'mWifiInfo SSID': 'ssid',
|
||||
'BSSID': 'bssid',
|
||||
'MAC': 'mac',
|
||||
'RSSI': 'rssi',
|
||||
'Link speed': 'speed',
|
||||
'Frequency': 'frequency'
|
||||
};
|
||||
if (stderr) {
|
||||
table = E('p', stderr);
|
||||
} else {
|
||||
var lines = stdout.trim().split('\n')[0];
|
||||
var parts = lines.split(', ');
|
||||
parts.forEach(function(part) {
|
||||
var keyValue = part.split(': ');
|
||||
var key = keyValue[0].trim();
|
||||
var value = keyValue[1].replace(/"/g, '');
|
||||
if (properties[key]) {
|
||||
if (key === 'Frequency' || key === 'Link speed') {
|
||||
value = value.replace(/(\d+)([A-Za-z]+)/g, '$1 $2');
|
||||
};
|
||||
if (key === 'RSSI') {
|
||||
value += ' dBm';
|
||||
};
|
||||
wifiInfo[properties[key]] = value;
|
||||
};
|
||||
});
|
||||
};
|
||||
table = [
|
||||
E('h3', {'class': 'section-title'}, _('Wireless Information')),
|
||||
E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-titles', 'style': 'display: none;'}),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('SSID')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.ssid)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('BSSID')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.bssid)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('MAC address')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.mac)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('RSSI')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.rssi)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Link speed')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.speed)
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Frequency')),
|
||||
E('td', {'class': 'td left', 'width': '50%'}, wifiInfo.frequency)
|
||||
])
|
||||
])
|
||||
];
|
||||
return document.getElementById('wirelessMenu').append(...table);
|
||||
}).catch(function(error) {
|
||||
var message = E('p', error);
|
||||
return document.getElementById('wirelessMenu').append(...message);
|
||||
});
|
||||
};
|
||||
|
||||
return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null,
|
||||
load: function() {
|
||||
return uci.load('droidnet').then(function() {
|
||||
var device = uci.get('droidnet', 'device', 'id');
|
||||
return Promise.all([
|
||||
fs.exec('adb', ['-s', device, 'shell', 'getprop']).then(function(result) {
|
||||
var networkInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
var properties = {
|
||||
'gsm.operator.alpha': 'operator',
|
||||
'gsm.network.type': 'signal',
|
||||
'gsm.version.ril-impl': 'driver',
|
||||
'gsm.operator.isroaming': 'roaming',
|
||||
'gsm.sim.operator.numeric': 'mcc'
|
||||
};
|
||||
if (stderr) {
|
||||
networkInfo['network_section'] = stderr.trim();
|
||||
} else {
|
||||
var lines = stdout.split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
for (var property in properties) {
|
||||
if (lines[i].includes('[' + property + ']')) {
|
||||
var parts = lines[i].split(']: [');
|
||||
var value = parts[1].substring(0, parts[1].length - 1);
|
||||
if (value.includes(',')) {
|
||||
value = value.split(',').map(function(item) {
|
||||
return item.trim();
|
||||
});
|
||||
}else {
|
||||
value = [value.trim(), ''];
|
||||
};
|
||||
networkInfo[properties[property]] = value;
|
||||
break;
|
||||
};
|
||||
if (!networkInfo.hasOwnProperty(properties[property])) {
|
||||
networkInfo[properties[property]] = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
return networkInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'service', 'call', 'iphonesubinfo', '1', 's16', 'com.android.shell']).then(function(result) {
|
||||
var imeisim01Info = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
imeisim01Info['imei_sim01_section'] = stderr.trim();
|
||||
} else {
|
||||
var matches = stdout.match(/'([^']+)'/g);
|
||||
var value = matches.map(function(match) {
|
||||
return match.slice(1, -1);
|
||||
});
|
||||
var combined = value.join('');
|
||||
var imei = combined.replace(/[.\s]/g, '');
|
||||
imeisim01Info['imei_sim01'] = imei;
|
||||
};
|
||||
return imeisim01Info;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'ip', 'route']).then(function(result) {
|
||||
var ipInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (result && stderr) {
|
||||
ipInfo['ip_section'] = stderr.trim();
|
||||
} else if (result && stdout) {
|
||||
var parts = stdout.trim().split(/\s+/);
|
||||
var value = parts.slice(-1)[0];
|
||||
ipInfo['ip'] = value;
|
||||
} else {
|
||||
ipInfo['ip'] = false;
|
||||
};
|
||||
return ipInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'dumpsys', 'wifi', '|', 'grep', 'Wi-Fi is']).then(function(result) {
|
||||
var wifiInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
wifiInfo['wifi_section'] = stderr.trim();
|
||||
} else {
|
||||
var status = stdout.trim() === 'Wi-Fi is enabled' ? true : false;
|
||||
wifiInfo['wifi'] = status;
|
||||
};
|
||||
return wifiInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'dumpsys', 'telephony.registry', '|', 'grep', 'mDataConnectionState=']).then(function(result) {
|
||||
var dataInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
dataInfo['data_section'] = stderr.trim();
|
||||
} else {
|
||||
if (stdout.includes('mDataConnectionState=2')) {
|
||||
var dataStatus = true;
|
||||
} else {
|
||||
var dataStatus = false;
|
||||
};
|
||||
dataInfo['data'] = dataStatus;
|
||||
};
|
||||
return dataInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'settings', 'get', 'global', 'airplane_mode_on']).then(function(result) {
|
||||
var airplaneInfo = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
airplaneInfo['airplane_section'] = stderr.trim();
|
||||
} else {
|
||||
var status = stdout.trim() === '1' ? true : false;
|
||||
airplaneInfo['airplane'] = status;
|
||||
};
|
||||
return airplaneInfo;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
]).then(function(results) {
|
||||
var networkInfo = results[0];
|
||||
var imeisim01Info = results[1];
|
||||
var ipInfo = results[2];
|
||||
var wifiInfo = results[3];
|
||||
var dataInfo = results[4];
|
||||
var airplaneInfo = results[5];
|
||||
if (device && networkInfo && imeisim01Info && ipInfo && wifiInfo && dataInfo && airplaneInfo) {
|
||||
return Object.assign({device: device}, networkInfo, imeisim01Info, ipInfo, wifiInfo, dataInfo, airplaneInfo);
|
||||
} else {
|
||||
throw new Error(_('Failed to get complete device information.'));
|
||||
};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
render: function(data) {
|
||||
var header = [
|
||||
E('h2', {'class': 'section-title'}, _('DroidNet')),
|
||||
E('div', {'class': 'cbi-map-descr'}, _('Manage Android modem and optimize network settings.'))
|
||||
];
|
||||
if (data.network_section) {
|
||||
ui.addNotification(_('Error: Device conflict!'),
|
||||
E('p', _('Please check your settings, the configured device and ADB devices are conflicting.')), 'danger'
|
||||
);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('div', {'class': 'cbi-value', 'style': 'text-align: center; display: block;'}, [
|
||||
E('em', _('No device detected or connected.'))
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
var networkMenu = [
|
||||
E('h3', {'class': 'section-title'}, _('Mobile Network')),
|
||||
E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-titles', 'style': 'display: none;'}),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('IP address')),
|
||||
E('td', {'class': 'td left'}, data.ip || '-'),
|
||||
E('td', {'class': 'td'})
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2', 'style': 'display: table-row;'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Wireless connection')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.wifi === true ? _('On') :
|
||||
_('Off')
|
||||
),
|
||||
E('td', {'class': 'td center', 'width': '25%'}, [
|
||||
data.wifi === false ? E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Wireless network'), [
|
||||
E('p', _('Are you sure want to switched on wireless connection?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Turning on wireless connection '), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for wireless connection to be turned on…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'svc', 'wifi', 'enable']);
|
||||
writeLog(_('Wireless connection has been switched on.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Wireless connection has been switched on'), [
|
||||
E('p', _('Wireless connection has been successfully switched on.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Enable')) :
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'click': function() {
|
||||
ui.showModal(_('Wireless network'), [
|
||||
E('p', _('Are you sure want to switched off wireless connection?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Turning off wireless connection '), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for wireless connection to be turned off…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'svc', 'wifi', 'disable']);
|
||||
writeLog(_('Wireless connection has been switched off.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Wireless connection has been switched off'), [
|
||||
E('p', _('Wireless connection has been successfully switched off.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Disable'))
|
||||
])
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-1', 'style': 'display: table-row;'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Mobile data')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.data === true ? _('On') :
|
||||
_('Off')
|
||||
),
|
||||
E('td', {'class': 'td center', 'width': '25%'}, [
|
||||
data.data === false ? E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Mobile network'), [
|
||||
E('p', _('Are you sure want to switched on mobile data?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
if (data.airplane === true) {
|
||||
ui.showModal(_('Failed to switch on mobile data'), [
|
||||
E('p', _('Failed to switch on mobile data because the airplane mode is active.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
writeLog(_('Failed to swich on mobile data because the airplane mode is active.'));
|
||||
} else {
|
||||
ui.showModal(_('Turning on mobile data'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for mobile data to be turned on…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'svc', 'data', 'enable']);
|
||||
writeLog(_('Mobile data has been switched on.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Mobile data has been switched on'), [
|
||||
E('p', _('Mobile data has been successfully switched on.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
};
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Enable')) :
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'click': function() {
|
||||
ui.showModal(_('Mobile network'), [
|
||||
E('p', _('Are you sure want to switched off mobile data?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Turning off mobile data'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for mobile data to be turned off…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'svc', 'data', 'disable']);
|
||||
writeLog(_('Mobile data has been switched off.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Mobile data has been switched off'), [
|
||||
E('p', _('Mobile data has been successfully switched off.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Disable'))
|
||||
])
|
||||
]),
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2', 'style': 'display: table-row;'}, [
|
||||
E('td', {'class': 'td left', 'width': '50%'}, _('Airplane mode')),
|
||||
E('td', {'class': 'td left', 'width': '25%'}, data.airplane === true ? _('On') :
|
||||
_('Off')
|
||||
),
|
||||
E('td', {'class': 'td center', 'width': '25%'}, [
|
||||
data.airplane === false ? E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Airplane mode'), [
|
||||
E('p', _('Are you sure want to switched on airplane mode?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'cmd', 'connectivity', 'airplane-mode', 'enable']).then(function(result) {
|
||||
if (result.stdout) {
|
||||
ui.showModal(_('Failed to switch on aiplane mode'), [
|
||||
E('p', _('Failed to switch on airplane mode because device version cannot execute the command, make sure device is rooted or android version is 10 or above.')),
|
||||
E('em', {'style': 'color: red;'}, result.stdout),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
writeLog(_('Failed to switch on airplane mode because android version is below 10.'));
|
||||
} else {
|
||||
ui.showModal(_('Turning on airplane mode'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for airplane mode to be turned on…'))
|
||||
]);
|
||||
writeLog(_('Airplane mode has been switched on.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Airplane mode has been switched on'), [
|
||||
E('p', _('Airplane mode has been successfully switched on.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
};
|
||||
});
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Enable')) :
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'click': function() {
|
||||
ui.showModal(_('Airplane mode'), [
|
||||
E('p', _('Are you sure want to switched off airplane mode?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'cmd', 'connectivity', 'airplane-mode', 'disable']).then(function(result) {
|
||||
if (result.stdout) {
|
||||
ui.showModal(_('Failed to switch off aiplane mode'), [
|
||||
E('p', _('Failed to switch off airplane mode because device version cannot execute the command, make sure device is rooted or android version is 10 or above.')),
|
||||
E('em', {'style': 'color: red;'}, result.stdout),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
writeLog(_('Failed to switch off airplane mode because android version is below 10.'));
|
||||
} else {
|
||||
ui.showModal(_('Turning off Airplane mode'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for airplane mode to be turned off…'))
|
||||
]);
|
||||
writeLog(_('Airplane mode has been switched off.'));
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Airplane mode has been switched off'), [
|
||||
E('p', _('Airplane mode has been successfully switched off.')),
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
]);
|
||||
}, 5000);
|
||||
};
|
||||
});
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Disable'))
|
||||
])
|
||||
])
|
||||
])
|
||||
];
|
||||
var cellularMenu = [
|
||||
E('h3', {'class': 'section-title'}, _('Cellular Information')),
|
||||
E('ul', {'class': 'cbi-tabmenu'}, [
|
||||
data.operator && data.operator[0] ? E('li', {'class': 'cbi-tab', 'id': 'tab-1'}, [
|
||||
E('a', {
|
||||
'href': '#',
|
||||
'click': function() {
|
||||
document.getElementById('tab-1').className = 'cbi-tab';
|
||||
document.getElementById('tab-2').className = 'cbi-tab-disabled';
|
||||
document.getElementById('sim-1').style.display = 'table';
|
||||
document.getElementById('sim-2').style.display = 'none';
|
||||
}
|
||||
}, _('SIM 1'))
|
||||
]) : '',
|
||||
data.operator && data.operator[1] ? E('li', {'class': 'cbi-tab-disabled', 'id': 'tab-2'}, [
|
||||
E('a', {
|
||||
'href': '#',
|
||||
'click': function() {
|
||||
document.getElementById('tab-1').className = 'cbi-tab-disabled';
|
||||
document.getElementById('tab-2').className = 'cbi-tab';
|
||||
document.getElementById('sim-1').style.display = 'none';
|
||||
document.getElementById('sim-2').style.display = 'table';
|
||||
}
|
||||
}, _('SIM 2'))
|
||||
]) : ''
|
||||
]),
|
||||
E(renderTableCell(data, 'sim-1')),
|
||||
E(renderTableCell(data, 'sim-2'))
|
||||
];
|
||||
var wirelessMenu = [
|
||||
data.wifi === true ? E('div', {'id': 'wirelessMenu'}, renderTableWiFi(data.device)) : ''
|
||||
];
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, networkMenu),
|
||||
E('div', {'class': 'cbi-section'}, wirelessMenu),
|
||||
E('div', {'class': 'cbi-section'}, cellularMenu)
|
||||
]);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,546 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require fs';
|
||||
'require ui';
|
||||
|
||||
var page = 1;
|
||||
var filter = '';
|
||||
var apkFile = '/tmp/upload.apk';
|
||||
function closeUi(type) {
|
||||
if (type === 'OK') {
|
||||
return E('button', {
|
||||
'class': 'btn',
|
||||
'click': function() {
|
||||
return window.location.reload();
|
||||
}
|
||||
}, _('OK'));
|
||||
} else {
|
||||
return E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin-right: 10px',
|
||||
'click': ui.hideModal
|
||||
}, _('Cancel'));
|
||||
};
|
||||
};
|
||||
function writeLog(message, service, error) {
|
||||
var logFile = '/var/log/droidnet.log';
|
||||
if (service === 'power') {
|
||||
var serviceName = _('Power service');
|
||||
} else {
|
||||
var serviceName = _('Application service');
|
||||
};
|
||||
fs.read(logFile).then(function(result) {
|
||||
var date = new Date().toLocaleDateString(undefined, {
|
||||
weekday: 'short',
|
||||
month: 'short',
|
||||
day: '2-digit'
|
||||
});
|
||||
var time = new Date().toLocaleTimeString(undefined, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
if (error === false) {
|
||||
var notif = `${date}, ${time} - ${serviceName}: ${message}`;
|
||||
} else {
|
||||
var notif = `${date}, ${time} - ${serviceName}: ${message}: ${error}`;
|
||||
};
|
||||
var newData = result.trim() + '\n' + notif;
|
||||
return fs.write(logFile, newData);
|
||||
});
|
||||
};
|
||||
function renderTable(data, display) {
|
||||
var tableRows, value = data.application;
|
||||
var start = (page - 1) * display;
|
||||
var packages = value.filter(function(item) {
|
||||
return item.toLowerCase().includes(filter.toLowerCase());
|
||||
});
|
||||
var end = Math.min(start + display, packages.length);
|
||||
var current = packages.slice(start, end);
|
||||
if (packages.length === 0) {
|
||||
tableRows = [
|
||||
E('tr', {'class': 'tr cbi-rowstyle-2'}, [
|
||||
E('td', {'class': 'td center', 'colspan': '2'}, [
|
||||
E('em', _('Application not found'))
|
||||
])
|
||||
])
|
||||
];
|
||||
} else {
|
||||
tableRows = current.map(function(value, index) {
|
||||
var rowClass = index % 2 === 0 ? 'cbi-rowstyle-1' : 'cbi-rowstyle-2';
|
||||
return E('tr', {'class': 'tr ' + rowClass }, [
|
||||
E('td', {'class': 'td left'}, value),
|
||||
E('td', {'class': 'td right'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'click': function() {
|
||||
ui.showModal(_('Remove application') + ` ${value}`, [
|
||||
E('p', _('Are you sure want to remove this application?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Removing application'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for application removal to complete…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'pm', 'uninstall', '-k', '--user', '0', value]).then(function(result) {
|
||||
var stdout = result.stdout;
|
||||
if (stdout.trim() !== 'Success') {
|
||||
writeLog(_('Failed to remove %s application.').format(value), 'application', stdout);
|
||||
ui.showModal(_('Package removal failed'), [
|
||||
E('p', _('Failed to remove <em>%s</em> application.').format(value)),
|
||||
E('em', {'style': 'color: red;'}, stdout),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('button', {'class': 'btn', 'click': ui.hideModal}, _('OK'))
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
writeLog(_('Removing %s application successfully.').format(value), 'application', false);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Removing application completed'), [
|
||||
E('p', _('Application <em>%s</em> has been successfully removed.').format(value)),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 10000);
|
||||
};
|
||||
});
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Remove'))
|
||||
])
|
||||
]);
|
||||
});
|
||||
};
|
||||
return E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr table-titles'}, [
|
||||
E('th', {'class': 'th left'}, _('Application name')),
|
||||
E('th', {'class': 'th'})
|
||||
]),
|
||||
E(tableRows)
|
||||
]);
|
||||
};
|
||||
function updateTable(data, display) {
|
||||
var value = data.application;
|
||||
var container = document.getElementsByClassName('table-container');
|
||||
var prev = document.querySelector('.prev');
|
||||
var next = document.querySelector('.next');
|
||||
for (var i = 0; i < container.length; i++) {
|
||||
container[i].innerHTML = '';
|
||||
var table = renderTable(data, display);
|
||||
container[i].appendChild(table);
|
||||
};
|
||||
var packages = value.filter(function(item) {
|
||||
return item.toLowerCase().includes(filter.toLowerCase());
|
||||
});
|
||||
var total = packages.length;
|
||||
var pages = Math.ceil(total / display);
|
||||
if (pages <= 1) {
|
||||
prev.disabled = true;
|
||||
next.disabled = true;
|
||||
} else if (page <= 1) {
|
||||
prev.disabled = true;
|
||||
next.disabled = false;
|
||||
} else if (page >= pages) {
|
||||
prev.disabled = false;
|
||||
next.disabled = true;
|
||||
} else {
|
||||
prev.disabled = false;
|
||||
next.disabled = false;
|
||||
};
|
||||
var start = (page - 1) * display + 1;
|
||||
var end = Math.min(start + display - 1, total);
|
||||
document.getElementById('page-info').innerText = _('Displaying %s - %s of %s').format(start, end, total);
|
||||
};
|
||||
|
||||
return view.extend({
|
||||
handleSaveApply: null,
|
||||
handleSave: null,
|
||||
handleReset: null,
|
||||
load: function() {
|
||||
return uci.load('droidnet').then(function() {
|
||||
var device = uci.get('droidnet', 'device', 'id');
|
||||
var display = uci.get('droidnet', 'device', 'display_app');
|
||||
return Promise.all([
|
||||
fs.exec('adb', ['-s', device, 'shell', 'df', 'sdcard', '-h']).then(function(result) {
|
||||
var storage = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
var properties = {
|
||||
'Size': 'size',
|
||||
'Used': 'use',
|
||||
'Avail': 'free',
|
||||
'Use%': 'percentage',
|
||||
'Mounted': 'mounted'
|
||||
};
|
||||
if (stderr) {
|
||||
storage['storage_section'] = stderr.trim();
|
||||
} else {
|
||||
var data = [];
|
||||
var lines = stdout.split('\n');
|
||||
var header = lines[0].split(/\s+/);
|
||||
var value = lines[1].split(/\s+/);
|
||||
for (var i = 0; i < header.length; i++) {
|
||||
var property = properties[header[i]];
|
||||
if (property) {
|
||||
data[property] = value[i];
|
||||
};
|
||||
};
|
||||
storage['storage'] = data;
|
||||
};
|
||||
return storage;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('adb', ['-s', device, 'shell', 'pm', 'list', 'packages']).then(function(result) {
|
||||
var application = {};
|
||||
var stderr = result.stderr;
|
||||
var stdout = result.stdout;
|
||||
if (stderr) {
|
||||
application['application_section'] = stderr.trim();
|
||||
} else {
|
||||
var parts = stdout.trim().split('\n').map(function(line) {
|
||||
return line.replace('package:', '');
|
||||
});
|
||||
application['application'] = parts;
|
||||
};
|
||||
return application;
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
})
|
||||
]).then(function(results) {
|
||||
var storage = results[0];
|
||||
var application = results[1];
|
||||
if (device && display && storage && application) {
|
||||
return Object.assign({device: device}, {display: display}, storage, application)
|
||||
} else {
|
||||
throw new Error(_('Failed to get complete device information.'));
|
||||
};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
render: function(data) {
|
||||
var display = parseInt(data.display);
|
||||
var application = data.application;
|
||||
var header = [
|
||||
E('h2', {'class': 'section-title'}, _('DroidNet')),
|
||||
E('div', {'class': 'cbi-map-descr'}, _('Manage Android modem and optimize network settings.'))
|
||||
];
|
||||
if (data.storage_section) {
|
||||
ui.addNotification(_('Error: Device conflict!'),
|
||||
E('p', _('Please check your settings, the configured device and ADB devices are conflicting.')), 'danger'
|
||||
);
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, [
|
||||
E('div', {'class': 'cbi-value', 'style': 'text-align: center; display: block;'}, [
|
||||
E('em', _('No device detected or connected.'))
|
||||
])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
var powerMenu = [
|
||||
E('h3', {'class': 'section-title'}, _('Power Options')),
|
||||
E('div', {'class': 'cbi-section-descr'}, _('Let you shutdown, restart, access fastboot mode or recovery mode, all in one place.')),
|
||||
E('table', {'class': 'table cbi-section-table'}, [
|
||||
E('tr', {'class': 'tr'}, [
|
||||
E('td', {'class': 'td center', 'style': 'border: none;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-save',
|
||||
'style': 'margin: 10px 0!important;',
|
||||
'click': function() {
|
||||
ui.showModal(_('Fastboot mode'), [
|
||||
E('p', _('Are you sure want rebooting device to fastboot mode?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Rebooting to fastboot mode'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for device to reboot into fastboot mode…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'reboot', 'bootloader']);
|
||||
writeLog(_('Device entered fastboot mode.'), 'power', false);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Fastboot mode completed'), [
|
||||
E('p', _('Device has been successfully to fastboot mode.')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 10000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Fastboot mode'))
|
||||
]),
|
||||
E('td', {'class': 'td center', 'style': 'border: none;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-save',
|
||||
'style': 'margin: 10px 0!important;',
|
||||
'click': function() {
|
||||
ui.showModal(_('Recovery mode'), [
|
||||
E('p', _('Are you sure want rebooting device to recovery mode?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Rebooting to recovery mode'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for device to reboot into recovery mode…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'reboot', 'recovery']);
|
||||
writeLog(_('Device entered recovery mode.'), 'power', false);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Recovery mode completed'), [
|
||||
E('p', _('Device has been successfully to recovery mode.')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 10000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Recovery mode'))
|
||||
]),
|
||||
E('td', {'class': 'td center', 'style': 'border: none;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin: 10px 0!important;',
|
||||
'click': function() {
|
||||
ui.showModal(_('Restart device'), [
|
||||
E('p', _('Are you sure want to restart device?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Restarting device'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for device restart to complete…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'reboot']);
|
||||
writeLog(_('Device restarted successfully.'), 'power', false);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Device restart completed'), [
|
||||
E('p', _('Device has been successfully restarted.')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 30000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Restart'))
|
||||
]),
|
||||
E('td', {'class': 'td center', 'style': 'border: none;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin: 10px 0!important;',
|
||||
'click': function() {
|
||||
ui.showModal(_('Shutdown device'), [
|
||||
E('p', _('Are you sure want to shutdown device?')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E(closeUi('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Shutting down device'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for device to shut down…'))
|
||||
]);
|
||||
fs.exec('adb', ['-s', data.device, 'shell', 'reboot', '-p']);
|
||||
writeLog(_('Device powered off successfully.'), 'power', false);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Device shutdown completed'), [
|
||||
E('p', _('Device has been successfully shut down.')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 15000);
|
||||
}
|
||||
}, _('Yes'))
|
||||
])
|
||||
]);
|
||||
}
|
||||
}, _('Shutdown'))
|
||||
])
|
||||
])
|
||||
])
|
||||
];
|
||||
var applicationMenu = [
|
||||
E('h3', {'class': 'section-title'}, _('Application Manager')),
|
||||
E('div', {'class': 'cbi-section-descr'}, _('Lists installed apps on device.')),
|
||||
E('div', {'class': 'controls', 'style': 'display: flex; flex-wrap: wrap;'}, [
|
||||
E('div', {'class': 'disk-application', 'style': 'flex-basis: 100%; min-width: 250px; padding: .25em;'}, [
|
||||
E('label', _('Disk space') + ' : '),
|
||||
E('div', {'class': 'cbi-progressbar', 'title': _('%s used (%s used of %s, %s free)').format(data.storage.percentage, data.storage.use, data.storage.size, data.storage.free)}, [
|
||||
E('div', {'style': `width: ${data.storage.percentage};`}, ' ')
|
||||
])
|
||||
]),
|
||||
E('div', {'class': 'filter-application', 'style': 'padding: .25em;'}, [
|
||||
E('label', _('Filter') + ' : '),
|
||||
E('span', {'class': 'control-group', 'style': 'display: flex;'}, [
|
||||
E('input', {
|
||||
'type': 'text',
|
||||
'class': 'filter-input',
|
||||
'placeholder': 'Type to filter…',
|
||||
'keyup': function(event) {
|
||||
filter = event.target.value;
|
||||
page = 1;
|
||||
updateTable(data, display);
|
||||
}
|
||||
}),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button',
|
||||
'click': function() {
|
||||
filter = '';
|
||||
page = 1;
|
||||
updateTable(data, display);
|
||||
document.querySelector('.filter-input').value = '';
|
||||
}
|
||||
}, _('Clear'))
|
||||
])
|
||||
]),
|
||||
E('div', {'class': 'action-application', 'style': 'padding: .25em;'}, [
|
||||
E('label', _('Actions') + ' : '),
|
||||
E('span', {'class': 'control-group', 'style': 'display: flex;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-save',
|
||||
'style': 'margin-right: 10px',
|
||||
'click': function() {
|
||||
ui.showModal(_('Updating application list'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for update application list command to complete…'))
|
||||
]);
|
||||
setTimeout(function() {
|
||||
ui.showModal(_('Update application list completed'), [
|
||||
E('p', _('Application list has been successfully updated.')),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
}, 10000);
|
||||
}
|
||||
}, _('Update list')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.uploadFile(apkFile).then(function(result) {
|
||||
var apkName = result.name;
|
||||
ui.showModal(_('Install application'), [
|
||||
E('p', _('Installing application from untrusted sources is a potential security risk, really attempt to install <em>%s</em>?').format(apkName)),
|
||||
E('ul', [
|
||||
result.size ? E('li', '%s: %1024.2mB'.format(_('Size'), result.size)) : '',
|
||||
result.checksum ? E('li', '%s: %s'.format(_('MD5'), result.checksum)) : '',
|
||||
result.sha256sum ? E('li', '%s: %s'.format(_('SHA256'), result.sha256sum)) : ''
|
||||
]),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-remove',
|
||||
'style': 'margin-right: 10px',
|
||||
'click': function() {
|
||||
fs.remove(apkFile);
|
||||
ui.hideModal();
|
||||
}
|
||||
}, _('Cancel')),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button cbi-button-action',
|
||||
'click': function() {
|
||||
ui.showModal(_('Installing application'), [
|
||||
E('p', {'class': 'spinning'}, _('Waiting for application installation to complete…'))
|
||||
]);
|
||||
fs.exec_direct('adb', ['-s', data.device, 'install', apkFile]).then(function(result) {
|
||||
var apk = result.trim();
|
||||
if (apk === 'Success') {
|
||||
writeLog(_('Application %s has been successfully installed.').format(apkName), 'application', false);
|
||||
ui.showModal(_('Application installation completed'), [
|
||||
E('p', _('Application <em>%s</em> has been successfully installed.').format(apkName)),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
} else {
|
||||
writeLog(_('Failed to install %s application').format(apkName), 'application', apk);
|
||||
ui.showModal(_('Application installation failed'), [
|
||||
E('p', _('Failed to install <em>%s</em> application.').format(apkName)),
|
||||
E('em', {'style': 'color: red;'}, apk),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
};
|
||||
return fs.remove(apkFile);
|
||||
});
|
||||
}
|
||||
}, _('Install'))
|
||||
])
|
||||
])
|
||||
}).catch(function(error) {
|
||||
if (error.message === 'Upload has been cancelled') {
|
||||
ui.hideModal();
|
||||
} else {
|
||||
writeLog(_('Failed to upload %s application.').format(apkName), 'application', error);
|
||||
ui.showModal(_('Error uploading application'), [
|
||||
E('p', _('Failed to upload <em>%s</em> application.').format(apkName)),
|
||||
E('em', {'style': 'color: red;'}, error),
|
||||
E('div', {'class': 'right'}, [
|
||||
E('div', {'class': 'right'}, [E(closeUi('OK'))])
|
||||
])
|
||||
]);
|
||||
};
|
||||
});
|
||||
}
|
||||
}, _('Upload application'))
|
||||
])
|
||||
])
|
||||
]),
|
||||
E('div', {'class': 'controls', 'style': 'display: flex; flex-wrap: wrap; justify-content: space-around; padding: 1em 0;'}, [
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral prev',
|
||||
'style': 'flex-basis: 20%; text-align: center;',
|
||||
'disabled': true,
|
||||
'click': function() {
|
||||
page--;
|
||||
updateTable(data, display);
|
||||
}
|
||||
}, '«'),
|
||||
E('div', {'class': 'text', 'id': 'page-info', 'style': 'flex-grow: 1; align-self: center; text-align: center;'}, _('Displaying 1 - %s of %s').format(display, application.length)),
|
||||
E('button', {
|
||||
'class': 'btn cbi-button-neutral next',
|
||||
'style': 'flex-basis: 20%; text-align: center;',
|
||||
'click': function() {
|
||||
page++;
|
||||
updateTable(data, display);
|
||||
}
|
||||
}, '»')
|
||||
]),
|
||||
E('div', {'class': 'table-container'}, renderTable(data, display))
|
||||
];
|
||||
return E('div', {'class': 'cbi-map'}, [
|
||||
E(header),
|
||||
E('div', {'class': 'cbi-section'}, powerMenu),
|
||||
E('div', {'class': 'cbi-section'}, applicationMenu)
|
||||
]);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/* This is free software, licensed under the Apache License, Version 2.0
|
||||
*
|
||||
* Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'require view';
|
||||
'require form';
|
||||
'require uci';
|
||||
'require fs';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
return view.extend({
|
||||
load: function() {
|
||||
return uci.load('droidnet').then(function() {
|
||||
return Promise.all([
|
||||
fs.exec('adb', ['devices', '-l']).then(function(result) {
|
||||
var devices = {};
|
||||
var stdout = result.stdout;
|
||||
var stderr = result.stderr;
|
||||
if (stderr || stdout === 'List of devices attached \n\n') {
|
||||
devices = false;
|
||||
} else {
|
||||
var lines = stdout.trim().split('\n');
|
||||
lines.shift();
|
||||
lines.forEach(function(line) {
|
||||
var model = '';
|
||||
var parts = line.split(/\s+/);
|
||||
var device = parts[0].trim();
|
||||
parts.forEach(function(part) {
|
||||
if (part.startsWith('model:')) {
|
||||
model = part.substring(6);
|
||||
};
|
||||
});
|
||||
devices[device] = model;
|
||||
});
|
||||
};
|
||||
return {devices};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.list('/etc/init.d').then(function(result) {
|
||||
var tunnelService = {};
|
||||
var fileNames = {
|
||||
'neko': 'Neko',
|
||||
'openclash': 'OpenClash',
|
||||
'passwall': 'PassWall',
|
||||
'v2ray': 'V2Ray'
|
||||
};
|
||||
result.forEach(function(file) {
|
||||
if (fileNames[file.name]) {
|
||||
tunnelService[file.name] = fileNames[file.name];
|
||||
};
|
||||
});
|
||||
if (Object.keys(tunnelService).length === 0) {
|
||||
tunnelService = false;
|
||||
}
|
||||
return {tunnelService};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
}),
|
||||
fs.exec('pgrep', ['-f', '/usr/share/droidnet/monitoring']).then(function(result) {
|
||||
var status = {};
|
||||
if (result && result.code === 1) {
|
||||
status = false;
|
||||
} else {
|
||||
status = true;
|
||||
};
|
||||
return {status};
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
})
|
||||
]).then(function(results) {
|
||||
var devices = results[0];
|
||||
var tunnelService = results[1];
|
||||
var status = results[2];
|
||||
return Object.assign(devices, tunnelService, status)
|
||||
}).catch(function(error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
render: function(data) {
|
||||
var m, s, o;
|
||||
m = new form.Map('droidnet', _('DroidNet'),
|
||||
_('Manage Android modem and optimize network settings.'));
|
||||
|
||||
s = m.section(form.NamedSection, 'device', 'droidnet', _('Base Setting'));
|
||||
if (data.devices == false) {
|
||||
o = s.option(form.DummyValue, 'dummy', _('Device'));
|
||||
o.default = _('No device detected.');
|
||||
} else {
|
||||
o = s.option(form.ListValue, 'id', _('Device'));
|
||||
Object.keys(data.devices).forEach(function(deviceID) {
|
||||
o.value(deviceID, data.devices[deviceID]);
|
||||
});
|
||||
o.rmempty = false;
|
||||
};
|
||||
o = s.option(form.Value, 'display_app', _('Application limit'),
|
||||
_('Set display limit per page for application manager.'));
|
||||
o.placeholder = _('1 - 100');
|
||||
o.datatype = 'range(1,100)';
|
||||
o.rmempty = false;
|
||||
o = s.option(form.Value, 'display_msg', _('Messages limit'),
|
||||
_('Set display limit per page for messages information.'));
|
||||
o.placeholder = _('1 - 100');
|
||||
o.datatype = 'range(1,100)';
|
||||
o.rmempty = false;
|
||||
|
||||
s = m.section(form.NamedSection, 'monitoring', 'droidnet', _('Monitoring Service'),
|
||||
_('Monitor network performance on android modem to ensure optimal connectivity stability.'));
|
||||
o = s.option(form.DummyValue, 'dummy', _('Status'));
|
||||
o.rawhtml = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
var span = '<b><span style="color:%s">%s</span></b>';
|
||||
var renderHTML = data.status ?
|
||||
String.format(span, 'green', _('Running')) :
|
||||
String.format(span, 'red', _('Not Running'));
|
||||
return renderHTML;
|
||||
};
|
||||
o = s.option(form.Flag, 'enable', _('Enable'));
|
||||
o.rmempty = false;
|
||||
o = s.option(form.ListValue, 'ping', _('Ping method'),
|
||||
_('Set method for pinging host address.'));
|
||||
o.value('http', _('HTTP'));
|
||||
o.value('https', _('HTTPS'));
|
||||
o.value('icmp', _('ICMP'));
|
||||
o.value('tcp', _('TCP'));
|
||||
o.rmempty = false;
|
||||
o = s.option(form.Value, 'host', _('Host'),
|
||||
_('Host address you want to ping. Recommended to use bug on Tun.'));
|
||||
o.placeholder = _('Host address');
|
||||
o.rmempty = false;
|
||||
o = s.option(form.ListValue, 'success_limit', _('Max ping successes'),
|
||||
_('Maximum number of successful ping attempts to log "Host reachable" message.'));
|
||||
o.value('1', _('1 successes'));
|
||||
o.value('2', _('2 successes'));
|
||||
o.value('3', _('3 successes'));
|
||||
o.value('4', _('4 successes'));
|
||||
o.value('5', _('5 successes'));
|
||||
o.value('unlimited', _('Unlimited'));
|
||||
o.rmempty = false;
|
||||
o = s.option(form.ListValue, 'failure_limit', _('Max ping attempts'),
|
||||
_('Maximum number of unsuccessful ping attempts to trigger service.'));
|
||||
o.value('1', _('1 attempts'));
|
||||
o.value('2', _('2 attempts'));
|
||||
o.value('3', _('3 attempts'));
|
||||
o.value('4', _('4 attempts'));
|
||||
o.value('5', _('5 attempts'));
|
||||
o.rmempty = false;
|
||||
o = s.option(form.ListValue, 'wait_time', _('Waiting time'),
|
||||
_('Time to wait (in seconds) before activating airplane mode after ping failure.'));
|
||||
o.value('1', _('1 seconds'));
|
||||
o.value('2', _('2 seconds'));
|
||||
o.value('3', _('3 seconds'));
|
||||
o.value('4', _('4 seconds'));
|
||||
o.value('5', _('5 seconds'));
|
||||
o.rmempty = false;
|
||||
o = s.option(widgets.NetworkSelect, 'interface', _('Interface'),
|
||||
_('Name of interface to be restarted.'));
|
||||
o.nocreate = true;
|
||||
o.rmempty = false;
|
||||
o = s.option(form.Flag, 'restart', _('Restart the tunnel'),
|
||||
_('Enable to automatically restart tunneling tool.'));
|
||||
o.rmempty = false;
|
||||
if (data.tunnelService === false) {
|
||||
o = s.option(form.DummyValue, 'dummy', _('Tunneling tool'),
|
||||
_('Set tunneling tool to be restarted.'));
|
||||
o.default = _('No tunneling tools found.');
|
||||
} else {
|
||||
o = s.option(form.ListValue, 'tunnel_service', _('Tunneling tool'),
|
||||
_('Set tunneling tool to be restarted.'));
|
||||
Object.keys(data.tunnelService).forEach(function(pathID) {
|
||||
o.value(pathID, data.tunnelService[pathID]);
|
||||
});
|
||||
};
|
||||
return m.render();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
|
||||
apk_name="luci-app-droidnet"
|
||||
version="1.1"
|
||||
|
||||
echo -e "\033[34m🔄 Updating OPKG \033[0m"
|
||||
if ! opkg update > /dev/null; then
|
||||
echo -e "\033[31m❌ Failed to update OPKG \033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\033[34m📥 Downloading packages \033[0m"
|
||||
if ! curl -s -o "/tmp/${apk_name}_${version}_all.ipk" -LO "https://github.com/animegasan/$apk_name/releases/download/$version/${apk_name}_${version}_all.ipk"; then
|
||||
echo -e "\033[31m❌ Failed to download packages \033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\033[34m📦 Installing $apk_name \033[0m"
|
||||
if ! opkg install "/tmp/${apk_name}_${version}_all.ipk" > /dev/null; then
|
||||
echo -e "\033[31m❌ Failed to install $apk_name \033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\033[32m✅ Process completed. $apk_name ver $version has been installed. \033[0m"
|
||||
@@ -0,0 +1,15 @@
|
||||
config droidnet 'device'
|
||||
option id 'id'
|
||||
option display_app '100'
|
||||
option display_msg '10'
|
||||
|
||||
config droidnet 'monitoring'
|
||||
option enable '0'
|
||||
option ping 'http'
|
||||
option host 'google.com'
|
||||
option success_limit '5'
|
||||
option failure_limit '3'
|
||||
option wait_time '3'
|
||||
option interface 'wan'
|
||||
option restart '0'
|
||||
option tunnel_service 'tunnel'
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
STOP=10
|
||||
NAME=droidnet
|
||||
LOG_FILE=/var/log/droidnet.log
|
||||
MONITORING_SERVICE=/usr/share/droidnet/monitoring
|
||||
|
||||
start_service() {
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Activating DroidNet service." >> $LOG_FILE
|
||||
config_load $NAME
|
||||
config_get enable monitoring enable
|
||||
if [ $enable = 1 ]; then
|
||||
screen -dmS droidnet $MONITORING_SERVICE start
|
||||
fi
|
||||
}
|
||||
|
||||
# stop_service() {
|
||||
# echo "$(date +"%a, %b %d, %I:%M %p") - Deactivating DroidNet service." >> $LOG_FILE
|
||||
# echo "$(date +"%a, %b %d, %I:%M %p") - Monitoring service: Stopping service." >> $LOG_FILE
|
||||
# $MONITORING_SERVICE stop
|
||||
# }
|
||||
stop_service() {
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Deactivating DroidNet service." >> $LOG_FILE
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Monitoring service: Stopping service." >> $LOG_FILE
|
||||
session=$(screen -ls | awk '/droidnet/ {print $1}')
|
||||
screen -X -S $session quit
|
||||
screen -wipe
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop_service
|
||||
start_service
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger $NAME
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
stop_service
|
||||
start_service
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-droidnet.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-droidnet.json << EEOF
|
||||
{
|
||||
"config": "droidnet",
|
||||
"init": "droidnet"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@droidnet[-1]
|
||||
add ucitrack droidnet
|
||||
set ucitrack.@droidnet[-1].init=droidnet
|
||||
commit ucitrack
|
||||
EOF
|
||||
rm -rf /tmp/luci*
|
||||
exit 0
|
||||
@@ -0,0 +1,304 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>, Anas Fanani <anas@anasfanani.com>
|
||||
|
||||
# Environment
|
||||
COUNT_FAILURE=0
|
||||
COUNT_SUCCESS=0
|
||||
DEVICES_FOUND=0
|
||||
COMMAND_FOUND=0
|
||||
DEVICES_ROOT=0
|
||||
FAILURE_LIMIT=$(uci get droidnet.monitoring.failure_limit)
|
||||
SUCCESS_LIMIT=$(uci get droidnet.monitoring.success_limit)
|
||||
DEVICES_ID=$(uci get droidnet.device.id)
|
||||
WAIT_TIME=$(uci get droidnet.monitoring.wait_time)
|
||||
HOST=$(uci get droidnet.monitoring.host)
|
||||
PORT=$(uci get droidnet.monitoring.ping)
|
||||
INTERFACE_NAME=$(uci get droidnet.monitoring.interface)
|
||||
RESTART_TUNNEL=$(uci get droidnet.monitoring.restart)
|
||||
TOOL_TUNNELING=$(uci get droidnet.monitoring.tunnel_service)
|
||||
PING_SUCCESS="Ping to '$HOST' using '$PORT' succeeded."
|
||||
PING_BACKGROUND="Ping to '$HOST' using '$PORT' successfuly, starting continuous ping in the background."
|
||||
|
||||
# Functions
|
||||
log() {
|
||||
echo "$(date +"%a, %b %d, %I:%M:%S %p") - Monitoring service: $1" >> /var/log/droidnet.log
|
||||
}
|
||||
|
||||
check_devices() {
|
||||
log "Checking devices."
|
||||
for DEVICE in $(adb devices -l | awk 'NR>1 && /device/ {print $1}'); do
|
||||
if [ $DEVICE = $DEVICES_ID ]; then
|
||||
DEVICES_FOUND=1
|
||||
log "Device found in the list of connected devices."
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $DEVICES_FOUND -eq 1 ]; then
|
||||
log "Checking root status on device."
|
||||
if adb -s $DEVICES_ID shell su -v 2>&1 | grep -q "/system/bin/sh: su: not found"; then
|
||||
INFO_ROOT="Non-root"
|
||||
log "Device not rooted."
|
||||
else
|
||||
INFO_ROOT="Rooted"
|
||||
DEVICES_ROOT=1
|
||||
log "Device is rooted."
|
||||
fi
|
||||
log "Checking availability of airplane mode command on device."
|
||||
INFO_ANDROID=$(adb -s $DEVICES_ID shell getprop ro.build.version.release)
|
||||
INFO_VERSION=${INFO_ANDROID%%.*}
|
||||
if [ $INFO_VERSION -lt 10 ]; then
|
||||
if [ $DEVICES_ROOT -eq 1 ]; then
|
||||
COMMAND_FOUND=1
|
||||
log "Airplane mode can be turned on."
|
||||
else
|
||||
log "Airplane mode can't be turned on."
|
||||
fi
|
||||
else
|
||||
COMMAND_FOUND=1
|
||||
log "Airplane mode can be turned on."
|
||||
fi
|
||||
log "Device information"
|
||||
GET_INFO=$(adb devices -l | grep $DEVICES_ID)
|
||||
INFO_USB=$(echo $GET_INFO | awk '{for(i=1;i<=NF;i++) if($i ~ /^usb:/) print $i}')
|
||||
INFO_MODEL=$(echo $GET_INFO | awk '{for(i=1;i<=NF;i++) if($i ~ /^model:/) {split($i, a, ":"); print a[2]}}')
|
||||
log "ID: $DEVICES_ID, Model: $INFO_MODEL, Android: $INFO_ANDROID, Status: $INFO_ROOT, Connection: $INFO_USB"
|
||||
else
|
||||
log "Device not found in the list of connected devices."
|
||||
fi
|
||||
}
|
||||
|
||||
enable_airplane_mode() {
|
||||
log "Turning on Airplane mode."
|
||||
if [ $DEVICES_ROOT -eq 1 ] && [ $INFO_VERSION -lt 10 ]; then
|
||||
adb -s $DEVICES_ID shell su -c 'settings put global airplane_mode_on 1'
|
||||
adb -s $DEVICES_ID shell su -c 'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true'
|
||||
else
|
||||
adb -s $DEVICES_ID shell cmd connectivity airplane-mode enable
|
||||
fi
|
||||
}
|
||||
|
||||
disable_airplane_mode() {
|
||||
log "Turning off Airplane mode."
|
||||
if [ $DEVICES_ROOT -eq 1 ] && [ $INFO_VERSION -lt 10 ]; then
|
||||
adb -s $DEVICES_ID shell su -c 'settings put global airplane_mode_on 0'
|
||||
adb -s $DEVICES_ID shell su -c 'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false'
|
||||
else
|
||||
adb -s $DEVICES_ID shell cmd connectivity airplane-mode disable
|
||||
fi
|
||||
}
|
||||
|
||||
restart_interface() {
|
||||
log "Restarting interface $INTERFACE_NAME."
|
||||
ifup $INTERFACE_NAME
|
||||
}
|
||||
|
||||
disable_neko() {
|
||||
log "Disabling Neko."
|
||||
/etc/init.d/neko stop
|
||||
}
|
||||
|
||||
enable_neko() {
|
||||
log "Enabling Neko."
|
||||
/etc/init.d/neko start
|
||||
}
|
||||
|
||||
disable_openclash() {
|
||||
log "Disabling OpenClash."
|
||||
/etc/init.d/openclash stop
|
||||
}
|
||||
|
||||
enable_openclash() {
|
||||
log "Enabling OpenClash."
|
||||
/etc/init.d/openclash start
|
||||
}
|
||||
|
||||
disable_passwall() {
|
||||
log "Disabling PassWall."
|
||||
/etc/init.d/passwall stop
|
||||
}
|
||||
|
||||
enable_passwall() {
|
||||
log "Enabling PassWall."
|
||||
/etc/init.d/passwall start
|
||||
}
|
||||
|
||||
disable_v2ray() {
|
||||
log "Disabling V2Ray."
|
||||
start-stop-daemon -K -p /var/run/v2raya.pid
|
||||
}
|
||||
|
||||
enable_v2ray() {
|
||||
log "Enabling V2Ray."
|
||||
start-stop-daemon -b -S -m -p /var/run/v2raya.pid -x /usr/bin/enable_v2rayA
|
||||
}
|
||||
|
||||
reconnection() {
|
||||
log "Starting connection update service on the device."
|
||||
if [ $RESTART_TUNNEL = 1 ]; then
|
||||
log "Disabling tunneling tool."
|
||||
if [ $TOOL_TUNNELING = "neko" ]; then
|
||||
disable_neko
|
||||
elif [ $TOOL_TUNNELING = "openclash" ]; then
|
||||
disable_openclash
|
||||
elif [ $TOOL_TUNNELING = "passwall" ]; then
|
||||
disable_passwall
|
||||
elif [ $TOOL_TUNNELING = "v2ray" ]; then
|
||||
disable_v2ray
|
||||
else
|
||||
log "Tunneling tool '$TOOL_TUNNELING' not found, please install it first."
|
||||
fi
|
||||
elif [ $RESTART_TUNNEL = 0 ]; then
|
||||
log "Skipping disabling tunneling tool."
|
||||
fi
|
||||
enable_airplane_mode
|
||||
sleep $WAIT_TIME
|
||||
disable_airplane_mode
|
||||
sleep $WAIT_TIME
|
||||
restart_interface
|
||||
if [ $RESTART_TUNNEL = 1 ]; then
|
||||
log "Enabling tunneling tool."
|
||||
if [ $TOOL_TUNNELING = "neko" ]; then
|
||||
enable_neko
|
||||
elif [ $TOOL_TUNNELING = "openclash" ]; then
|
||||
enable_openclash
|
||||
elif [ $TOOL_TUNNELING = "passwall" ]; then
|
||||
enable_passwall
|
||||
elif [ $TOOL_TUNNELING = "v2ray" ]; then
|
||||
enable_v2ray
|
||||
else
|
||||
log "Tunneling tool '$TOOL_TUNNELING' not found, please install it first."
|
||||
fi
|
||||
elif [ $RESTART_TUNNEL = 0 ]; then
|
||||
log "Skipping enabling tunneling tool."
|
||||
fi
|
||||
log "Connection update service on the device has completed."
|
||||
COUNT_FAILURE=0
|
||||
}
|
||||
|
||||
ping_else() {
|
||||
log "Ping to '$HOST' using '$PORT' failed."
|
||||
COUNT_FAILURE=$((COUNT_FAILURE + 1))
|
||||
COUNT_SUCCESS=0
|
||||
if [ $COUNT_FAILURE -ge $FAILURE_LIMIT ]; then
|
||||
log "Failed ping to '$HOST' using '$PORT' $FAILURE_LIMIT times."
|
||||
reconnection
|
||||
fi
|
||||
}
|
||||
|
||||
ping_http() {
|
||||
if curl -Is "http://$HOST:80" > /dev/null; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_https() {
|
||||
if curl -Is "https://$HOST:443" > /dev/null; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_icmp() {
|
||||
ping -q -c 3 -W 3 -p 0 $HOST > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_tcp() {
|
||||
if nc -zvw 1 $HOST 80 2>&1 | grep -q succeeded; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
log "Starting service."
|
||||
check_devices
|
||||
if [ $DEVICES_FOUND -eq 1 ] && [ $COMMAND_FOUND -eq 1 ]; then
|
||||
log "Starting ping to '$HOST' using '$PORT'."
|
||||
while true; do
|
||||
if [ $PORT = "http" ]; then
|
||||
ping_http
|
||||
elif [ $PORT = "https" ]; then
|
||||
ping_https
|
||||
elif [ $PORT = "icmp" ]; then
|
||||
ping_icmp
|
||||
elif [ $PORT = "tcp" ]; then
|
||||
ping_tcp
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
else
|
||||
log "Failed to start service."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
log "Stopping service."
|
||||
SERVICE_PID=$(pgrep -f /usr/share/droidnet/monitoring)
|
||||
kill $SERVICE_PID
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
log "Restarting service."
|
||||
SERVICE_PID=$(pgrep -f /usr/share/droidnet/monitoring | head -n 1)
|
||||
start_service
|
||||
}
|
||||
|
||||
# Main script
|
||||
if [ "$1" = "start" ]; then
|
||||
start_service
|
||||
elif [ "$1" = "stop" ]; then
|
||||
stop_service
|
||||
elif [ "$1" = "restart" ]; then
|
||||
restart_service
|
||||
else
|
||||
echo "Syntax: Monitoring service [DroidNet]"
|
||||
echo "Available commands:"
|
||||
echo " start Start the service"
|
||||
echo " stop Stop the service"
|
||||
echo " restart Restart the service"
|
||||
fi
|
||||
|
||||
reload_service() {
|
||||
restart
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"admin/services/droidnet": {
|
||||
"title": "DroidNet",
|
||||
"order": 50,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-droidnet" ]
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/device": {
|
||||
"title": "Device",
|
||||
"order": 1,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/device"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/network": {
|
||||
"title": "Network",
|
||||
"order": 2,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/network"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/service": {
|
||||
"title": "Service",
|
||||
"order": 3,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/service"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/inbox": {
|
||||
"title": "Inbox",
|
||||
"order": 4,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/inbox"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/log": {
|
||||
"title": "Logs",
|
||||
"order": 5,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/log"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/setting": {
|
||||
"title": "Setting",
|
||||
"order": 6,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/setting"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"luci-app-droidnet": {
|
||||
"description": "Grant access to luci-app-droidnet",
|
||||
"read": {
|
||||
"file": {
|
||||
"/var/log/droidnet.log": [ "read" ],
|
||||
"/usr/bin/adb": [ "exec" ],
|
||||
"/usr/bin/pgrep": [ "exec" ]
|
||||
},
|
||||
"uci": [ "droidnet" ]
|
||||
},
|
||||
"write": {
|
||||
"file": {
|
||||
"/var/log/droidnet.log": [ "write" ],
|
||||
"/tmp/upload.apk": [ "write" ]
|
||||
},
|
||||
"uci": [ "droidnet" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in new issue
Block a user