Skip to content

Commit

Permalink
A Whole Plethora of Fixes
Browse files Browse the repository at this point in the history
Fix Broadcasting, add default device and quiet times.
Fix URL Protection, revamp filtering.
Fix http issue when fetching weather via https.
Fix several other general settings that were not setting/loading correctly.
Fix type detection when asking to play some media.
Fix issues preventing WPA installation.
Fix groups not being displayed as cast devices.
Fix copying of URL's via UI.
  • Loading branch information
VaMaster committed Sep 7, 2018
1 parent ba18d18 commit 0b8c0e3
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 173 deletions.
326 changes: 235 additions & 91 deletions api.php

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ a:hover:not(#executeButton), .barBtn:hover, .barBtn:hover, .barBtn:hover > .clie
background-color: var(--theme-accent) !important;
}

.form-control-sm {
display: inline-block !important;
max-width: 35%;
}

.center-group {
text-align: center;
}

.nav-item > .nav-link, .appContainer, .userGroup *, .form-control, .text-muted {
color: var(--theme-primary-shade2) !important;
Expand Down
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
scriptDefaults();
$defaults = checkDefaults();
$forceSSL = $defaults['forceSSL'] ?? false;

if ($forceSSL === "false") $forceSSL = false;
write_log("ForceSSL is set to $forceSSL");
if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") && $forceSSL) {
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
write_log("Force is on, redirecting to: $redirect","ERROR");
if (isDomainAvailable($redirect)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
}

if (!session_started()) {
session_start();
}

writeSessionArray($defaults);
$GLOBALS['time'] = microtime(true);
if (substr_count($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") && hasGzip()) ob_start("ob_gzhandler"); else ob_start();
Expand Down
89 changes: 73 additions & 16 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var apiToken, appName, bgs, bgWrap, cv, dvr, token, newToken, deviceID, resultDu
var cleanLogs=true, couchEnabled=false, lidarrEnabled=false, ombiEnabled=false, sickEnabled=false, sonarrEnabled=false, radarrEnabled=false,
headphonesEnabled=false, watcherEnabled=false, dvrEnabled=false, hook=false, hookPlay=false, polling=false, pollcount=false,
hookPause=false, hookStop=false, hookCustom=false, hookFetch=false, hookSplit = false, autoUpdate = false, masterUser = false,
noNewUsers=false, notifyUpdate=false, waiting=false;
noNewUsers=false, notifyUpdate=false, waiting=false, broadcastDevice="all";

var forceUpdate = true;

Expand Down Expand Up @@ -191,21 +191,41 @@ function buildUiDeferred() {
function deviceHtml(type, deviceData) {
var output = "";
$.each(deviceData, function (key, device) {
var skip = false;
if (device.hasOwnProperty('Id') && device.hasOwnProperty('Name') && device.hasOwnProperty('Selected')) {
var string = "";
var id = device["Id"];
var name = device["Name"];
var friendlyName = device["FriendlyName"];
if (type === 'Broadcast') {
if (id === broadcastDevice) device["Selected"] = true;
}
var selected = ((device["Selected"]) ? ((type === 'Client') ? " dd-selected" : " selected") : "");

if (type === 'Client') {
string = "<a class='dropdown-item client-item" + selected + "' data-type='Client' data-id='" + id + "'>" + name + "</a>";
string = "<a class='dropdown-item client-item" + selected + "' data-type='Client' data-id='" + id + "'>" + friendlyName + "</a>";
} else {
string = "<option data-type='" + type + "' value='" + id + "'" + selected + ">" + name + "</option>";
}
output += string;
if (device.hasOwnProperty('Product')) {
console.log("Device type present.");
if (device["Product"] !== 'Cast' && type==="Broadcast") {
console.log("Skip this baby.");
skip = true;
}
}
if (!skip) output += string;
}
});
if (type === 'Client') output += '<a class="dropdown-item client-item" data-id="rescan"><b>rescan devices</b></a>';
if (type === 'Broadcast') {
console.log("Generating broadcast device list here...");
var tmp = output;
var selected = (broadcastDevice === 'all') ? " selected" : "";
output = "<option data-type='Broadcast' value='all'" + selected + ">ALL DEVICES</option>";
output += tmp;
} else {
if (type === 'Client') output += '<a class="dropdown-item client-item" data-id="rescan"><b>rescan devices</b></a>';
}
return output;
}

Expand All @@ -214,7 +234,10 @@ function updateDevices(newDevices) {
var newString = JSON.stringify(newDevices);
if (newString !== devices) {
console.log("Device array changed, updating: ", newDevices);
if (newDevices.hasOwnProperty("Client")) $('#clientWrapper').html(deviceHtml('Client', newDevices["Client"]));
if (newDevices.hasOwnProperty("Client")) {
$('#clientWrapper').html(deviceHtml('Client', newDevices["Client"]));
$('#broadcastList').html(deviceHtml('Broadcast', newDevices["Client"]));
}
if (newDevices.hasOwnProperty("Server")) $('#serverList').html(deviceHtml('Server', newDevices["Server"]));
if (newDevices.hasOwnProperty("Dvr")) {
if (newDevices["Dvr"].length === 0) $('.dvrGroup').hide(); else ($('.dvrGroup').show());
Expand Down Expand Up @@ -372,6 +395,7 @@ function parseServerData(data) {
}

function setUiVariables(data) {
console.log("Setting UI Variables: ",data);
for (var propertyName in data) {
if (data.hasOwnProperty(propertyName)) switch (propertyName) {
case 'sonarrEnabled':
Expand All @@ -395,6 +419,7 @@ function setUiVariables(data) {
case 'cleanLogs':
case 'autoUpdate':
case 'notifyUpdate':
case 'broadcastDevice':
var value = data[propertyName];
try {
value = JSON.parse(value);
Expand All @@ -413,7 +438,11 @@ function setUiVariables(data) {
window[propertyName] = value;
}
break;

case 'quietStart':
case 'quietStop':
value = data[propertyName];
$('#'+ propertyName).val(value);
break;
case 'couchList':
case 'sonarrList':
case 'radarrList':
Expand Down Expand Up @@ -811,9 +840,9 @@ function notify() {

function fetchWeather() {
var condition = "";
$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function (data) {
city = data["geoplugin_city"];
state = data["geoplugin_regionName"];
$.getJSON('https://geoip.tools/v1/json', function (data) {
city = data["city"];
state = data["region_name"];
console.log("City and state are " + city + " and " + state);
$.simpleWeather({
location: city + ',' + state,
Expand Down Expand Up @@ -1035,14 +1064,21 @@ function setListeners() {
var value, regUrl;
if ($(this).hasClass("copyInput")) {
value = $(this).val();
clipboard.copy(value);
$.snackbar({content: "Successfully copied URL."});

copyString(value);
}

if ($(this).hasClass("testInput")) {
value = encodeURIComponent($(this).val());
var url = "";
if ($(this).val() === 'broadcast') {
var msg = encodeURIComponent("Flex TV is the bee's, knees, Mcgee.");
url = 'api.php?notify=true&message=' + msg + '&apiToken=' + apiToken;
} else {
value = encodeURIComponent($(this).val());
url = 'api.php?test=' + value + '&apiToken=' + apiToken
}

$.get('api.php?test=' + value + '&apiToken=' + apiToken, function (data) {
$.get(url, function (data) {
if (data.hasOwnProperty('status')) {
console.log("We have a msg.",data['status']);
var msg = data['status'].replace(/"/g,"");
Expand All @@ -1069,8 +1105,8 @@ function setListeners() {

if ($(this).hasClass("hookLnk")) {
appName = $(this).data('value');
var string = serverAddress + "/api.php?apiToken=" + apiToken + "&notify=true";
clipboard.copy(string);
var string = serverAddress + "api.php?apiToken=" + apiToken + "&notify=true&message=";
copyString(string);
}

if ($(this).hasClass("logBtn")) {
Expand Down Expand Up @@ -1159,6 +1195,16 @@ function setListeners() {
});
});

$(document).on("click change", "#broadcastList",function () {
var ID = $(this).val();
apiToken = $('#apiTokenData').data('token');

$.get('api.php?apiToken=' + apiToken, {
device: 'Broadcast',
id: ID
});
});

$(document).on("click change", "#dvrList", function () {
var serverID = $(this).val();
apiToken = $('#apiTokenData').data('token');
Expand Down Expand Up @@ -1370,4 +1416,15 @@ $(window).on("load",function () {
setTimeout(updateStatus, 1);
}

});
});

function copyString(data) {
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute("id", "dummy_id");
document.getElementById("dummy_id").value=JSON.stringify(data);
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
$.snackbar({content: "Successfully copied data."});
}
1 change: 1 addition & 0 deletions manifest_template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Flex TV",
"short_name": "Flex TV",
"icons": [
{
"src": "img\/android-icon-192x192.png",
Expand Down
18 changes: 16 additions & 2 deletions php/body.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function makeSettingsBody($defaults) {
</div>
<div class='togglebutton".$hidden."'>
<label for='cleanLogs' class='appLabel checkLabel'>" . $lang["uiSettingObscureLogs"] . "
<input id='cleanLogs' type='checkbox' class='appInput appToggle' " . ($_SESSION['cleanLogs'] ? 'checked' : '') . "/>
<input id='cleanLogs' type='checkbox' class='appInput' " . ($_SESSION['cleanLogs'] ? 'checked' : '') . "/>
</label>
</div>
<div class='togglebutton'>
Expand Down Expand Up @@ -246,10 +246,24 @@ function makeSettingsBody($defaults) {
<div class='appContainer card'>
<div class='card-body'>
<h4 class='cardHeader'>Notifications</h4>
<div class='form-group'>
<label class='appLabel' for='broadcastList'>" . $lang["uiSettingBroadcastDevice"] . "</label>
<select class='form-control custom-select deviceList' id='broadcastList' title='".$lang['uiSettingBroadcastDeviceHint']."'>
</select>
</div>
<div class='form-group center-group'>
<label for='appt-time'>Start:</label>
<input type='time' id='quietStart' class='form-control form-control-sm appInput' min='0:00' max='23:59'/>
<label for='appt-time'>Stop:</label>
<input type='time' id='quietStop' class='form-control form-control-sm appInput' min='0:00' max='23:59'/>
</div>
<div class='fetchNotify'>
<button id='copyCouch' value='urlCouchPotato' class='hookLnk btn btn-raised btn-warn btn-100' title='Copy WebHook Notification URL'>
<button id='copyBroadcast' class='hookLnk btn btn-raised btn-warn btn-100' title='Copy WebHook Notification URL'>
<i class='material-icons'>assignment</i>
</button>
<button id='testBroadcast' value='broadcast' class='testInput btn btn-info btn-raised btn-100' title='Test WebHook Notification'>
<i class='material-icons'>send</i>
</button>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions php/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@
"uiSettingApiKey": "API Key:",
"uiSettingAutoUpdate": "Automatically Install Updates",
"uiSettingNotifyUpdate": "Notify when updates are available",
"uiSettingBroadcastDevice": "Broadcast Device",
"uiSettingBroadcastDeviceHint": "The device to broadcast notifications to.",
"uiSettingBtnReset": "RESET",
"uiSettingBtnTest": "TEST",
"uiSettingCastLogs": "Download Cast Logs",
Expand Down
Loading

0 comments on commit 0b8c0e3

Please sign in to comment.