diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b89838 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +# +# Copyright (C) 2020 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector) +# +# This is free software, licensed under the MIT License. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-internet-detector +LUCI_TITLE:=Internet detector for the LuCI status page +LUCI_DEPENDS:=+luci-mod-admin-full +LUCI_PKGARCH:=all +PKG_LICENSE:=MIT + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/htdocs/luci-static/resources/view/status/include/00_internet.js b/htdocs/luci-static/resources/view/status/include/00_internet.js new file mode 100644 index 0000000..57c03a8 --- /dev/null +++ b/htdocs/luci-static/resources/view/status/include/00_internet.js @@ -0,0 +1,53 @@ +'use strict'; +'require fs'; + +return L.Class.extend({ + title: _('Internet'), + + hosts: [ + '8.8.8.8', + '1.1.1.1', + '8.8.4.4', + ], + + checkInterval: 11, // 5 x 11 = 55 sec. + + load: async function() { + window.internetDetectorCounter = ('internetDetectorCounter' in window) ? + ++window.internetDetectorCounter : 0; + if(!('internetDetectorState' in window)) { + window.internetDetectorState = 1; + }; + + if(window.internetDetectorState === 0 && + window.internetDetectorCounter % this.checkInterval) { + return; + }; + + for(let host of this.hosts) { + await fs.exec('/bin/ping', [ '-c', '1', '-W', '1', host ]).then(res => { + window.internetDetectorState = res.code; + }).catch(e => {}); + + if(window.internetDetectorState === 0) { + break; + }; + }; + }, + + render: function() { + let internetStatus = E('span', { 'class': 'label' }); + + if(window.internetDetectorState === 0) { + internetStatus.style.background = '#46a546'; + internetStatus.textContent = _('Internet connected'); + } else { + internetStatus.textContent = _('Internet disconnected'); + }; + + return E('div', { + 'class': 'cbi-section', + 'style': 'margin-bottom:1em', + }, internetStatus); + }, +}); diff --git a/po/ru/internet-detector.po b/po/ru/internet-detector.po new file mode 100644 index 0000000..d8f98d5 --- /dev/null +++ b/po/ru/internet-detector.po @@ -0,0 +1,21 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: ru\n" +"X-Generator: Poedit 2.0.6\n" + +msgid "Internet" +msgstr "Интернет" + +msgid "Internet connected" +msgstr "Интернет подключен" + +msgid "Internet disconnected" +msgstr "Интернет отключен" diff --git a/po/templates/internet-detector.pot b/po/templates/internet-detector.pot new file mode 100644 index 0000000..e8f45f0 --- /dev/null +++ b/po/templates/internet-detector.pot @@ -0,0 +1,11 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "Internet" +msgstr "" + +msgid "Internet connected" +msgstr "" + +msgid "Internet disconnected" +msgstr "" diff --git a/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json b/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json new file mode 100644 index 0000000..c5f7a76 --- /dev/null +++ b/root/usr/share/rpcd/acl.d/luci-app-internet-detector.json @@ -0,0 +1,10 @@ +{ + "luci-app-internet-detector": { + "description": "Grant access to internet-detector procedures", + "read": { + "file": { + "/bin/ping -c 1 -W 1 [0-9.]*": [ "exec" ] + } + } + } +} diff --git a/screenshots/01.jpg b/screenshots/01.jpg new file mode 100644 index 0000000..a6768e2 Binary files /dev/null and b/screenshots/01.jpg differ diff --git a/translations/internet-detector.ru.lmo b/translations/internet-detector.ru.lmo new file mode 100644 index 0000000..3238988 Binary files /dev/null and b/translations/internet-detector.ru.lmo differ