Auto file-creation, trimming and lowercase-compare on inputs, better instructions and labels

The config and cache files are now recreated if missing/deleted.
Inputs are now trimmed in the API and compared in lowercase to avoid missmatches.
Added better labels and descriptions on some inputs, as well as placeholders.
Fixed some details in README.md
This commit is contained in:
aunefyren 2021-09-21 12:40:54 +02:00
parent 2942cd15a7
commit 2f2e1ca0aa
7 changed files with 45 additions and 24 deletions

View file

@ -25,7 +25,7 @@ A website-based platform and API for collecting Plex user stats within a set tim
## Instructions
This is a web-based platform. Place it in a webserver like Apache or Nginx and make sure it processes PHP content.
There are multiple settings you must configure! They will be stored in config/config.json, but can be configured easily at <b>you-domain-or-ip/admin.html</b>.
There are multiple settings you must configure! They will be stored in config/config.json, but can be configured easily at <b>your-domain-or-ip/admin.html</b>.
PHP will have issues with this API based on the results you want. If you have a large time frame for your wrapped period and there is a huge amount of Tautulli entries you can have multiple issues.
In your php.ini file you may have to change:
@ -37,11 +37,11 @@ You need to give PHP permission to edit files in the directory called <b>config<
The cache is stored at config/cache.json, but can be cleared using the admin menu.
Your password is stored hashed in the config.json.
Your password is hashed and stored in the config.json.
If you visit <b>you-domain-or-ip/caching.html</b> you can do a pre-caching of a set of users. This is very useful if you want to prepare for a lot of traffic.
If you visit <b>your-domain-or-ip/caching.html</b> you can do a pre-caching of a set of users. This is very useful if you want to prepare for a lot of traffic.
## Need help?
If you have any issues feel free to contact me. I am always trying to improve the project. If I can't, many people on several forums (including /r/plex) might be able to assist you.
If you have any issues feel free to contact me. I am always trying to improve the project. If I can't, many people on several forums (including [/r/plex](https://www.reddit.com/r/plex)) might be able to assist you.
<b>Goodybye.</b>

View file

@ -125,27 +125,27 @@ function set_tautulli(back) {
html += '<div class="form-group">';
html += '<label for="tautulli_apikey" title="The API key needed to interact with Tautulli. Commonly found at Tautulli->Settings->Web Interface->API Key.">Tautulli API key</label>';
html += '<input type="text" class="form-control" id="tautulli_apikey" value="' + tautulli_apikey + '" autocomplete="off" required /><br>';
html += '<input type="text" class="form-control" id="tautulli_apikey" value="' + tautulli_apikey + '" autocomplete="off" required placeholder="l0NgWe1rDAp1K3y..." /><br>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="tautulli_ip" title="The IP address or domain that connects to Tautulli. No subfolders as this is another setting, but subdomains can be defined.">IP or domain for Tautulli connection</label>';
html += '<input type="text" class="form-control" id="tautulli_ip" value="' + tautulli_ip + '" required /><br>';
html += '<input type="text" class="form-control" id="tautulli_ip" value="' + tautulli_ip + '" required placeholder="mycooldomain.plex" /><br>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="tautulli_port" title="The port Tautulli uses for connections. Typically empty if a domain is used.">Port for Tautulli (optional)</label>';
html += '<input type="text" class="form-control" id="tautulli_port" value="' + tautulli_port + '" /><br>';
html += '<input type="text" class="form-control" id="tautulli_port" value="' + tautulli_port + '" placeholder="8181" /><br>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="tautulli_length" title="The max amount of items Tautulli responds with. Typically doesn\'t need to be changed, but with server-wide stats it could limit results if the amount of items needed are extreme.">Tautlli item length</label>';
html += '<input type="number" class="form-control" id="tautulli_length" value="' + tautulli_length + '" autocomplete="off" required /><br>';
html += '<label for="tautulli_length" title="The max amount of entries Tautulli responds with during API calls. Typically doesn\'t need to be changed, but with server-wide stats it could limit results if the amount of entries in your Tautulli is extreme.">Tautlli item length</label>';
html += '<input type="number" min="0" class="form-control" id="tautulli_length" value="' + tautulli_length + '" autocomplete="off" placeholder="5000" required /><br>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="tautulli_root" title="Subfolder for Tautulli, no slashes needed at the beginning or end. It is the folder accessed after the main IP/domain. For example: tautulli.com/subfolder.">Root for Tautulli (optional)</label>';
html += '<input type="text" class="form-control" id="tautulli_root" value="' + tautulli_root + '" autocomplete="off" /><br>';
html += '<input type="text" class="form-control" id="tautulli_root" value="' + tautulli_root + '" autocomplete="off" placeholder="tautulli"/><br>';
html += '</div>';
html += '<div class="form-group">';
@ -158,13 +158,13 @@ function set_tautulli(back) {
html += '</div>';
html += '<div class="form-group">';
html += '<label for="library_id_movies" title="The ID for your chosen movie library in Tautulli. Can be found by going to Tautulli->Libraries->Your library. The ID is the url as section_id.">ID for movie-library in Tautulli</label>';
html += '<input type="number" class="form-control" id="library_id_movies" value="' + library_id_movies + '" autocomplete="off" required /><br>';
html += '<label for="library_id_movies" title="The ID for your chosen movie library in Tautulli. Can be found by going to Tautulli->Libraries->Your library. The ID is the URL as section_id.">ID for movie-library in Tautulli</label>';
html += '<input type="number" min="0" class="form-control" id="library_id_movies" value="' + library_id_movies + '" autocomplete="off" required placeholder="1" /><br>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="library_id_shows" title="The ID for your chosen show library in Tautulli. Can be found by going to Tautulli->Libraries->Your library. The ID is the url as section_id.">ID for show-library in Tautulli</label>';
html += '<input type="number" class="form-control" id="library_id_shows" value="' + library_id_shows + '" autocomplete="off" required /><br>';
html += '<label for="library_id_shows" title="The ID for your chosen show library in Tautulli. Can be found by going to Tautulli->Libraries->Your library. The ID is the URL as section_id.">ID for show-library in Tautulli</label>';
html += '<input type="number" min="0" class="form-control" id="library_id_shows" value="' + library_id_shows + '" autocomplete="off" required placeholder="2" /><br> ';
html += '</div>';
html += '<div class="form-group">';
@ -279,11 +279,11 @@ function set_tautulli_details(back) {
html += '<div class="form-group">';
html += '<label for="cache_age_limit" title="How old the cache can be in days before it expires.">Amount of days cache is valid (optional)<br>';
html += '<input type="number" class="form-control" id="cache_age_limit" value="' + cache_age_limit + '" /></label>';
html += '<input type="number" min="0" class="form-control" id="cache_age_limit" value="' + cache_age_limit + '" placeholder="7" /></label>';
html += '</div>';
html += '<div class="form-group" title="Clear the cache to include the newest settings.">';
html += '<label for="clear_cache">Clear cache (optional)<br>';
html += '<div class="form-group" title="Clear the cache now to include the newest settings.">';
html += '<label for="clear_cache">Clear cache now (optional)<br>';
html += '<input type="checkbox" class="form-control" id="clear_cache" checked /></label>';
html += '</div>';

View file

@ -1,6 +1,12 @@
<?php
$data = json_decode(file_get_contents("php://input"));
$config = json_decode(file_get_contents("../config/config.json"));
$path = "../config/config.json";
if(!file_exists($path)) {
fopen($path, "w");
}
$config = json_decode(file_get_contents($path));
if(empty($data)) {
echo json_encode(array("error" => true, "message" => "No input provided."));

View file

@ -1,5 +1,10 @@
<?php
$data = json_decode(file_get_contents("php://input"));
$path = "../config/config.json";
if(!file_exists($path)) {
fopen($path, "w");
}
$config = json_decode(file_get_contents("../config/config.json"));
if (empty($config)) {

View file

@ -23,9 +23,9 @@ $connection = create_url();
//Declare given email
if(!empty($data)){
$p_identity = htmlspecialchars($data->p_identity);
$p_identity = htmlspecialchars(trim($data->p_identity));
} else if(isset($_GET["p_identity"])) {
$p_identity = htmlspecialchars($_GET["p_identity"]);
$p_identity = htmlspecialchars(trim($_GET["p_identity"]));
} else {
echo json_encode(array("message" => "No input provided.", "error" => true));
exit(0);
@ -157,7 +157,7 @@ function tautulli_get_user($input) {
}
for ($i = 0; $i < count($response->response->data); $i++) {
if ($response->response->data[$i]->email == $input || $response->response->data[$i]->username == $input) {
if (strtolower($response->response->data[$i]->email) == strtolower($input) || strtolower($response->response->data[$i]->username) == strtolower($input)) {
return $response->response->data[$i]->user_id;
}
}
@ -191,7 +191,12 @@ function tautulli_get_name($id) {
function check_cache() {
global $config;
global $id;
$cache = json_decode(file_get_contents("../config/cache.json"));
$path = "../config/cache.json";
if(!file_exists($path)) {
fopen($path, "w");
}
$cache = json_decode(file_get_contents($path));
if(!empty($cache)) {
for($i = 0; $i < count($cache); $i++) {

View file

@ -1,7 +1,12 @@
<?php
$path = "../config/config.json";
$path2 = "../config/cache.json";
$data = json_decode(file_get_contents("php://input"));
if(!file_exists($path)) {
fopen($path, "w");
}
$config = json_decode(file_get_contents($path));
if(!empty($data)) {

View file

@ -14,7 +14,7 @@ function search_box() {
<div class='form-group'>
<label for="timeout" title="">Timeout between each call</label>
<label for="timeout" title="">Timeout between each call in seconds</label>
<input type="number" class='form-control' name="timeout" id="timeout" value='10' autocomplete="off" required />
</div>
@ -49,7 +49,7 @@ function cache() {
<img id="loading_icon" src="assets/loading.gif" style="padding: 1em;width: 4em; height: 4em; display:inline-block;">
</div>
<h3>Caching results</h3>
<h3>Caching results:</h3>
<div id="cache_results">
</div>