Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
0.1.13
- Tile colored red completely when connection with PiHole has been lost
Tile colored orange when PiHole is disabled
(not in dim state a colored status message is shown)

0.1.8/9
- redesigned tile to show more user friendly data
- added last refresh time to the details screen
- fixed broken auto update function
- data reset when connection lost

0.1.7
- fixed show/hide system tray icon based on the usersetting

0.1.6
- added working code for buttons

Expand Down
82 changes: 54 additions & 28 deletions PiholestatsApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,50 @@ App {
property url piholeTileUrl : "PiholestatsTile.qml"
property PiholestatsSettings piholeSettings
property PiholestatsScreen piholeScreen
property PiholestatsTile piholeTile
property bool dialogShown : false //shown when changes have been. Shown only once.

property SystrayIcon piholeTray
property bool showAppIcon : true
property bool firstTimeShown : true
property variant piholeConfigJSON
property variant emptyPiholeConfigJSON : {
"domains_being_blocked":0,
"dns_queries_today":0,
"ads_blocked_today":0,
"ads_percentage_today":0,
"unique_domains":0,
"queries_forwarded":0,
"queries_cached":0,
"clients_ever_seen":0,
"unique_clients":0,
"dns_queries_all_types":0,
"reply_NODATA":0,
"reply_NXDOMAIN":0,
"reply_CNAME":0,
"reply_IP":0,
"privacy_level":0,
"status":"geen connectie",
"gravity_last_updated":{"file_exists":true,"absolute":0,"relative":{"days":0,"hours":0,"minutes":0}}
}
property bool piholeDataRead: false

// app settings
property string connectionPath
property string ipadres
property string poortnummer : "80"
property int refreshrate : 60 // interval to retrieve data
property int refreshrate : 60 // interval to retrieve data
property string authtoken

//data vars
property string tmp_ads_blocked_today
property string tmp_ads_percentage_today
property string lastupdated
property string status

property string tileColor
property string textBgColor
property string textColor

// user settings from config file
property variant userSettingsJSON : {
Expand Down Expand Up @@ -70,11 +96,11 @@ App {
} catch(e) {
}
refreshScreen();
datetimeTimer.start()
}

// refresh screen
function refreshScreen() {
piholeDataRead = false;
readPiHolePHPData();
}

Expand All @@ -96,49 +122,49 @@ App {

// read json file
function readPiHolePHPData() {
// console.log("*****PiHole connectionPath:" + connectionPath);

if ( connectionPath.length > 4 ) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://"+connectionPath+"/admin/api.php", true);
xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == XMLHttpRequest.DONE) {

if (xmlhttp.status === 200) {
// console.log("*****PiHole response:" + xmlhttp.responseText);
// saveJSON(xmlhttp.responseText);
piholeConfigJSON = JSON.parse(xmlhttp.responseText);

tmp_ads_blocked_today = piholeConfigJSON['ads_blocked_today'];
// console.log("*****PiHole tmp_ads_blocked_today: " + tmp_ads_blocked_today);
// last tmp_ads_percentage_today = piholeConfigJSON['ads_percentage_today'];
tmp_ads_percentage_today = Math.round(piholeConfigJSON['ads_percentage_today']) + " %";
// console.log("*****PiHole tmp_ads_percentage_today: " + tmp_ads_percentage_today);
piholeConfigJSON = JSON.parse(xmlhttp.responseText);
tmp_ads_blocked_today = piholeConfigJSON['ads_blocked_today'];
tmp_ads_percentage_today = Math.round(piholeConfigJSON['ads_percentage_today']) + "%";
status = piholeConfigJSON['status'];
var tmp = new Date();
lastupdated = tmp.getFullYear() + "-" + ("0" + (tmp.getMonth() + 1)).slice(-2) + "-" + ("0" + tmp.getDate()).slice(-2) + " " + ("0" + tmp.getHours() ).slice(-2) + ":" + ("0" + tmp.getMinutes()).slice(-2);
}
if (xmlhttp.status === 0) {
piholeConfigJSON = emptyPiholeConfigJSON;
}
if (piholeConfigJSON['status'] == "geen connectie") {
tileColor = "#FF0000";
textBgColor = "#FF0000";
textColor = "#FFFFFF";
} else {
tmp_ads_blocked_today = "server incorrect";
// console.log("*****PiHole tmp_ads_blocked_today: "+ tmp_ads_blocked_today);
tmp_ads_percentage_today = "server incorrect";
// console.log("*****PiHole tmp_ads_percentage_today: "+ tmp_ads_percentage_today);

if (piholeConfigJSON['status'] == "disabled") {
tileColor = "#FFA500";
textBgColor = "#FFA500";
textColor = "#000000";
} else {
tileColor = "#FFFFFF";
textBgColor = dimmableColors.tileBackground;
textColor = dimmableColors.clockTileColor;
}
}
}
}
xmlhttp.send();
} else {
tmp_ads_blocked_today = "empty settings";
// console.log("*****PiHole tmp_ads_blocked_today: "+ tmp_ads_blocked_today);
tmp_ads_percentage_today = "empty settings";
// console.log("*****PiHole tmp_ads_percentage_today: "+ tmp_ads_percentage_today);
}
xmlhttp.send();
}

// save json data in json file. Optional, see readPiHolePHPData
function saveJSON(text) {

var doc3 = new XMLHttpRequest();
doc3.open("PUT", "file:///var/volatile/tmp/pihole_retrieved_data.json");
doc3.send(text);
}

// Timer in s * 1000
Timer {
id: datetimeTimer
Expand Down
12 changes: 6 additions & 6 deletions PiholestatsScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Screen {
function changeState(request) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", request, true);
if (xmlhttp.readyState == XMLHttpRequest.DONE) app.refreshScreen();
xmlhttp.send();
app.refreshScreen();
}

// header
Expand All @@ -40,7 +40,7 @@ Screen {

Text {
id: headerText
text: "Pi-Hole live gegevens:"
text: "Pi-Hole live gegevens (per " + app.lastupdated + ")"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 25 : 20
anchors {
Expand Down Expand Up @@ -95,7 +95,7 @@ Screen {
// line 1 value
Text {
id: line1value
text: app.piholeConfigJSON['status'];
text: app.piholeConfigJSON['status']
color: colors.clockTileColor
font.family: qfont.italic.name
font.pixelSize: isNxt ? 23 : 18
Expand Down Expand Up @@ -161,7 +161,7 @@ Screen {
// line 4 text
Text {
id: line4text
text: "Reclame vandaag geblokkeerd: "
text: "Reclame geblokkeerd laatste 24h: "
font.family: qfont.italic.name
font.pixelSize: isNxt ? 23 : 18
anchors {
Expand Down Expand Up @@ -373,8 +373,8 @@ Screen {
bottomMargin: isNxt ? 20 : 16
}
onClicked: {
changeState("http://"+app.connectionPath+"/admin/api.php?disable=30&auth="+app.authtoken);
}
changeState("http://"+app.connectionPath+"/admin/api.php?disable=30&auth="+app.authtoken);
}
}

// button 60s
Expand Down
108 changes: 82 additions & 26 deletions PiholestatsTile.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,50 @@ Tile {
id: piholeTile
property bool dimState: screenStateController.dimmedColors

onDimStateChanged: {
resetBackgroundColor();
}

function resetBackgroundColor() {
if (app.piholeConfigJSON['status'] == "enabled") {
fullRectangle.color = dimState ? "#000000" : "#FFFFFF"
console.log("PiHole enabled, dim:" + dimState);
} else {
if (app.piholeConfigJSON['status'] == "disabled") {
fullRectangle.color = dimState ? "#000000" : "#FFA500"
console.log("PiHole disabled, dim:" + dimState);
} else {
fullRectangle.color = dimState ? "#000000" : "#FF0000"
console.log("PiHole other, dim:" + dimState);
}
}
}

onClicked: {
stage.openFullscreen(app.piholeScreenUrl);
}

Item { //listener to respond realtime to property changes
property string tileColor: app.tileColor
property string textColor: app.textColor
property string textBgColor: app.textBgColor

onTileColorChanged: resetBackgroundColor();
onTextColorChanged: tileline5.color = textColor;
onTextBgColorChanged: text5Rect.color = textBgColor;
}

Rectangle {
id:fullRectangle
width: piholeTile.width
height: piholeTile.height
radius: 5
}

// Title
Text {
id: tiletitle
text: "PiHole Stats"
text: "PiHole Status"
anchors {
baseline: parent.top
baselineOffset: isNxt ? 30 : 24
Expand All @@ -24,57 +60,77 @@ Tile {
pixelSize: isNxt ? 25 : 20
}
color: (typeof dimmableColors !== 'undefined') ? dimmableColors.waTileTextColor : colors.waTileTextColor
visible: !dimState || (app.piholeConfigJSON['status'] == "geen connectie")
}
// line 1 text
Text {
id: tileline1
text: "Ads blocked today: "
text: "In de laatste 24 uur is"
color: (typeof dimmableColors !== 'undefined') ? dimmableColors.clockTileColor : colors.clockTileColor
anchors {
top: tiletitle.bottom
left: parent.left
leftMargin: isNxt ? 10 : 8
topMargin: isNxt ? 25 : 20
horizontalCenter: parent.horizontalCenter
}
font {
family: qfont.regular.name
pixelSize: isNxt ? 22 : 18
}
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.italic.name
visible: (app.piholeConfigJSON['status'] !== "geen connectie")
}

// line 2 text
Text {
id: tileline2
text: app.tmp_ads_blocked_today
text: app.tmp_ads_percentage_today + " van het DNS"
color: (typeof dimmableColors !== 'undefined') ? dimmableColors.clockTileColor : colors.clockTileColor
anchors {
left: tileline1.left
top: tileline1.bottom
horizontalCenter: parent.horizontalCenter
}
font {
family: qfont.regular.name
pixelSize: isNxt ? 22 : 18
}
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.italic.name
visible: (app.piholeConfigJSON['status'] !== "geen connectie")
}

// line 3 text
// line 4 text
Text {
id: tileline3
text: "Percentage blocked: "
id: tileline4
text: "verkeer geblokkeerd."
color: (typeof dimmableColors !== 'undefined') ? dimmableColors.clockTileColor : colors.clockTileColor
anchors {
left: tileline2.left
top: tileline2.bottom
horizontalCenter: parent.horizontalCenter
}
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.italic.name
font {
family: qfont.regular.name
pixelSize: isNxt ? 22 : 18
}
visible: (app.piholeConfigJSON['status'] !== "geen connectie")
}

// line 4 text
Text {
id: tileline4
text: app.tmp_ads_percentage_today
color: (typeof dimmableColors !== 'undefined') ? dimmableColors.clockTileColor : colors.clockTileColor
// line 5 text
Rectangle {
id: text5Rect
color: app.stringBackcolor
anchors {
left: tileline3.left
top: tileline3.bottom
top: tileline4.bottom
topMargin: isNxt ? 15 : 10
horizontalCenter: parent.horizontalCenter
}
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.italic.name
}
Text {
id: tileline5
text: "status: " + app.piholeConfigJSON['status']
color: app.stringColor
font {
family: qfont.regular.name
pixelSize: isNxt ? 22 : 18
}
}
width: childrenRect.width
height: childrenRect.height
visible: (app.piholeConfigJSON['status'] !== "enabled")
}
}
2 changes: 1 addition & 1 deletion PiholestatsTray.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import qb.base 1.0

SystrayIcon {
id: piholeSystrayIcon
visible: true
visible: app.showAppIcon
posIndex: 8000

property string objectName: "piholeSystrayIcon"
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.6
0.1.13