Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00209479bb | ||
|
|
1cb5eceeb9 | ||
|
|
117f3d2eb3 | ||
|
|
583d6f51eb | ||
|
|
cd0c685420 | ||
|
|
d40d86d796 | ||
|
|
a5a35ff777 | ||
|
|
399a007803 | ||
|
|
e2182e93d7 | ||
|
|
d059a48379 | ||
|
|
0d6ef57b1a | ||
|
|
0f9db35b48 | ||
|
|
af29d88f3d | ||
|
|
90c19b42d0 | ||
|
|
a69fd1488b | ||
|
|
dfb5d35a25 | ||
|
|
47a141acc6 | ||
|
|
fe92406a66 | ||
|
|
1e72a1624b | ||
|
|
26dd986dbb | ||
|
|
e6fc6b3b7c | ||
|
|
d48ac8418a | ||
|
|
31d11f1f4d | ||
|
|
017c34e2d5 | ||
|
|
c7a644a8e4 | ||
|
|
4611b118bf | ||
|
|
3192cf02dd | ||
|
|
3e1380ca47 | ||
|
|
5e853f4000 | ||
|
|
0e755eefe8 | ||
|
|
ae3146c804 | ||
|
|
e91de28ef5 | ||
|
|
a114232c47 | ||
|
|
9e77ad56f9 |
@@ -1,5 +1,5 @@
|
||||
# system0-test
|
||||
This is the test repo for experimental system0 features. Currently it houses the new docker system that we are developing instead of the normal sys0-image.
|
||||
# system0-2.0
|
||||
The new version of system0. It runs on Docker and is much smarter with many new features compared to the original system0.
|
||||
|
||||
# system0
|
||||
Frontend system for octoprint<br>
|
||||
|
||||
4
scripts/README.md
Normal file
4
scripts/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# sys0_client.sh
|
||||
This script can be installed into rc.local to start after every boot.<br>
|
||||
WARNING! before installing change the MACHINE_ID and the SYSTEM=_WEBSERVER_URL<br>
|
||||
Be sure to give every octoprint machine a seperate id.<br>
|
||||
5
scripts/sys0_client.sh
Normal file
5
scripts/sys0_client.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
ngrok http 80 &
|
||||
sleep 5
|
||||
url=$(curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"https:..([^"]*).*/\1/p' )
|
||||
curl --silent "https://SYSTEM0_WEBSERVER_URL/api/update_url.php?url=$url&id=ENTER_THE_ID_FOR_THIS_MACHINE_HERE&apikey=YOUR_SYSTEM0_APIKEY&octoapikey=OCTOPRINT_ADMIN_APIKEY"
|
||||
12
sys0-code/api/download_image.php
Normal file
12
sys0-code/api/download_image.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// Get parameters
|
||||
$username = htmlspecialchars($_GET["username"]);
|
||||
$printer_url = $_GET["url"];
|
||||
|
||||
// Path to save the downloaded image
|
||||
$path = "/var/www/html/user_files/$username/$printer_url.jpeg";
|
||||
|
||||
// Download the latest snapshot from the printer URL
|
||||
exec("wget --quiet \"http://$printer_url/webcam/?action=snapshot\" -O $path");
|
||||
|
||||
?>
|
||||
92
sys0-code/api/server_stats.php
Normal file
92
sys0-code/api/server_stats.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// Initialize the session and check if the user is authenticated
|
||||
session_start();
|
||||
include "../config/config.php";
|
||||
|
||||
// Perform authentication and role checks
|
||||
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true || $_SESSION["role"][9] !== "1") {
|
||||
echo "Unauthorized access!";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Sanitize session variables
|
||||
$username = htmlspecialchars($_SESSION["username"]);
|
||||
$id = intval($_SESSION["id"]);
|
||||
$color = htmlspecialchars($_SESSION["color"]);
|
||||
|
||||
// Server statistics retrieval
|
||||
|
||||
// Get server load
|
||||
$load = sys_getloadavg();
|
||||
$load_percentage = round(($load[0] / 4) * 100); // Assuming a 4-core processor
|
||||
|
||||
// Get CPU usage
|
||||
$cpu_usage = shell_exec("top -bn1 | grep 'Cpu(s)' | sed 's/.*, *\\([0-9.]*\\)%* id.*/\\1/' | awk '{print 100 - $1}'");
|
||||
$cpu_usage = round($cpu_usage, 2);
|
||||
|
||||
// Get RAM usage
|
||||
$ram_usage = shell_exec("free | grep Mem | awk '{print $3/$2 * 100.0}'");
|
||||
$ram_usage = round($ram_usage, 2);
|
||||
|
||||
// Get Disk usage
|
||||
$disk_usage = shell_exec("df -h /var/www/html/user_files | grep / | awk '{print $5}'");
|
||||
|
||||
// Get server uptime
|
||||
$uptime = shell_exec("uptime -p");
|
||||
|
||||
// Output stats with Bootstrap styling
|
||||
|
||||
echo "
|
||||
<div class='col-md-6 mb-4'>
|
||||
<div class='card'>
|
||||
<div class='card-body'>
|
||||
<p class='stat-label'>CPU Usage: {$cpu_usage}%</p>
|
||||
<div class='progress'>
|
||||
<div class='progress-bar bg-danger' role='progressbar' style='width: {$cpu_usage}%' aria-valuenow='{$cpu_usage}' aria-valuemin='0' aria-valuemax='100'>{$cpu_usage}%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='col-md-6 mb-4'>
|
||||
<div class='card'>
|
||||
<div class='card-body'>
|
||||
<p class='stat-label'>RAM Usage: {$ram_usage}%</p>
|
||||
<div class='progress'>
|
||||
<div class='progress-bar bg-warning' role='progressbar' style='width: {$ram_usage}%' aria-valuenow='{$ram_usage}' aria-valuemin='0' aria-valuemax='100'>{$ram_usage}%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='col-md-6 mb-4'>
|
||||
<div class='card'>
|
||||
<div class='card-body'>
|
||||
<p class='stat-label'>Server Load (1 min avg): {$load[0]}</p>
|
||||
<div class='progress'>
|
||||
<div class='progress-bar bg-info' role='progressbar' style='width: {$load_percentage}%' aria-valuenow='{$load_percentage}' aria-valuemin='0' aria-valuemax='100'>{$load_percentage}%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='col-md-6 mb-4'>
|
||||
<div class='card'>
|
||||
<div class='card-body'>
|
||||
<p class='stat-label'>Disk Usage: {$disk_usage}</p>
|
||||
<div class='progress'>
|
||||
<div class='progress-bar bg-success' role='progressbar' style='width: {$disk_usage}' aria-valuenow='{$disk_usage}' aria-valuemin='0' aria-valuemax='100'>{$disk_usage}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='col-md-12 mb-4'>
|
||||
<div class='card'>
|
||||
<div class='card-body'>
|
||||
<p class='stat-label'>Server Uptime: {$uptime}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
";
|
||||
?>
|
||||
@@ -78,6 +78,11 @@ function load_user()
|
||||
</select><br><br>
|
||||
<input type="submit" class="btn btn-dark mb-5" value="Farbe aktualisieren" id="button">
|
||||
</form>
|
||||
<?php
|
||||
if(isset($_POST["printer"])){
|
||||
echo("<center><div class='alert alert-success' role='alert'>Farbe geändert</div></center>");
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,6 @@ $username=htmlspecialchars($_SESSION["username"]);
|
||||
$id=$_SESSION["id"];
|
||||
?>
|
||||
|
||||
|
||||
<script src="/assets/js/load_page.js"></script>
|
||||
<script>
|
||||
function load_user()
|
||||
@@ -31,11 +30,12 @@ function update_input(input,action,id){
|
||||
|
||||
}
|
||||
|
||||
function delete_input(input,action,id,row){
|
||||
async function delete_input(input,action,id,row){
|
||||
var selector=document.getElementById(input);
|
||||
var selector_value=selector.value;
|
||||
fetch("/api/printer_settings.php?action="+action+"&value="+selector.value+"&id="+id);
|
||||
document.getElementById("table1").deleteRow(row);
|
||||
await fetch("/api/printer_settings.php?action="+action+"&value="+selector.value+"&id="+id);
|
||||
//document.getElementById("table1").deleteRow(row);
|
||||
location.reload();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
@@ -48,6 +48,7 @@ function delete_input(input,action,id,row){
|
||||
<?php
|
||||
$color=$_SESSION["color"];
|
||||
include "../assets/components.php";
|
||||
$tab=$_GET["show"];
|
||||
?>
|
||||
<div id="content"></div>
|
||||
|
||||
@@ -59,6 +60,28 @@ function delete_input(input,action,id,row){
|
||||
<div class="container mt-5" style="min-height: 95vh;">
|
||||
<div class="row justify-content-center">
|
||||
<div style="width: 100hh">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=printer_settings" id="printer_settings_tab">Druckereinstellungen</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=camera_settings" id="camera_settings_tab">Kameraeinstellungen</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=class_settings" id="class_settings_tab">Klasseneinstellungen</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=filament_settings" id="filament_settings_tab">Filamenteinstellungen</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=srv_stats" id="srv_stats_tab">Serverstatistiken</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="debug.php?show=usr_fil_stats" id="usr_fil_stats_tab">Benutzer-Filament Statistik</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="printer_settings" style="display:none">
|
||||
<h1>Druckerfreigabe erzwingen (falls beim freigeben Fehlermeldungen angezeigt werden)</h1>
|
||||
<?php
|
||||
if(isset($_POST['free']))
|
||||
@@ -128,16 +151,17 @@ function delete_input(input,action,id,row){
|
||||
mysqli_stmt_fetch($stmt);
|
||||
|
||||
if($system_status==0)
|
||||
echo("<tr><td>$printer_id</td><td><form method='POST' action='?free=$printer_id'><button type='submit' value='free' name='free' class='btn btn-dark'>Free</button></form></td><td><a href='debug.php?update_status=$printer_id&status=1' class='btn btn-danger'>Status auf kaputt setzen</a></td></tr>");
|
||||
echo("<tr><td>$printer_id</td><td><form method='POST' action='?free=$printer_id&show=$tab'><button type='submit' value='free' name='free' class='btn btn-dark'>Free</button></form></td><td><a href='debug.php?update_status=$printer_id&status=1&show=$tab' class='btn btn-danger'>Status auf kaputt setzen</a></td></tr>");
|
||||
else
|
||||
echo("<tr><td>$printer_id</td><td><form method='POST' action='?free=$printer_id'><button type='submit' value='free' name='free' class='btn btn-dark'>Free</button></form></td><td><a href='debug.php?update_status=$printer_id&status=0' class='btn btn-success'>Status auf bereit setzen</a></td></tr>");
|
||||
echo("<tr><td>$printer_id</td><td><form method='POST' action='?free=$printer_id&show=$tab'><button type='submit' value='free' name='free' class='btn btn-dark'>Free</button></form></td><td><a href='debug.php?update_status=$printer_id&status=0&show=$tab' class='btn btn-success'>Status auf bereit setzen</a></td></tr>");
|
||||
$cnt--;
|
||||
}
|
||||
echo("</tbody></table></div></div></div></div>");
|
||||
?>
|
||||
<br><br>
|
||||
|
||||
|
||||
</div>
|
||||
<div id="camera_settings" style="display:none">
|
||||
<!-- Rotation der Druckerkameras: -->
|
||||
<h1>Rotation der Druckerkameras</h1>
|
||||
<?php
|
||||
@@ -177,7 +201,8 @@ function delete_input(input,action,id,row){
|
||||
}
|
||||
echo("</tbody></table></div></div></div>");
|
||||
?>
|
||||
<br><br>
|
||||
</div></div>
|
||||
<div id="class_settings" style="display:none">
|
||||
<h1>Klassen</h1>
|
||||
<?php
|
||||
|
||||
@@ -194,7 +219,7 @@ function delete_input(input,action,id,row){
|
||||
echo("<div class='container'><div class='row'><div class='col'><div class='overflow-auto'><table class='table' id='table2'><thead><tr><th>Klasse</th><th>Hinzufügen/Löschen</th></tr></thead><tbody>");
|
||||
|
||||
//form to add a color
|
||||
echo("<form action='debug.php?action=add_class' method='post'>");
|
||||
echo("<form action='debug.php?action=add_class&show=$tab' method='post'>");
|
||||
echo("<td><input type='text' placeholder='Klasse' name='class_name' required></input></td>");
|
||||
echo("<td><button type='submit' value='add' class='btn btn-primary'>Hinzufügen</button></td>");
|
||||
echo("</form>");
|
||||
@@ -226,7 +251,8 @@ function delete_input(input,action,id,row){
|
||||
echo("</div>");
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div id="filament_settings" style="display:none">
|
||||
<h1>Filamente</h1>
|
||||
<?php
|
||||
//list printers => form => color
|
||||
@@ -243,7 +269,7 @@ function delete_input(input,action,id,row){
|
||||
echo("<div class='container'><div class='row'><div class='col'><div class='overflow-auto'><table class='table' id='table1'><thead><tr><th>Filamente</th><th>Farbe</th><th>Hinzufügen/Löschen</th></tr></thead><tbody>");
|
||||
|
||||
//form to add a color
|
||||
echo("<form action='debug.php?action=add_filament' method='post'>");
|
||||
echo("<form action='debug.php?action=add_filament&show=$tab' method='post'>");
|
||||
echo("<td><input type='number' placeholder='Filament id' name='filament_id' required></input></td>");
|
||||
echo("<td><input type='text' placeholder='filament Farbe' name='filament_name' required></input></td>");
|
||||
echo("<td><button type='submit' value='add' class='btn btn-primary'>Hinzufügen</button></td>");
|
||||
@@ -274,8 +300,91 @@ function delete_input(input,action,id,row){
|
||||
}
|
||||
echo("</tbody></table></div></div></div>");
|
||||
echo("</div>");
|
||||
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="srv_stats" style="display:none">
|
||||
<div class="container my-5">
|
||||
<h1 class="text-center mb-4">Server Stats</h1>
|
||||
<div id="stats" class="row text-center">
|
||||
<!-- Stats will be dynamically loaded here via AJAX -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function refreshStats() {
|
||||
$.ajax({
|
||||
url: "/api/server_stats.php", // Load from server_stats.php, which includes auth and stats
|
||||
method: "GET",
|
||||
success: function (data) {
|
||||
$("#stats").html(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
refreshStats();
|
||||
|
||||
setInterval(refreshStats, 1000);
|
||||
</script>
|
||||
</div>
|
||||
<div id="usr_fil_stats" style="display:none">
|
||||
<h1 class="text-center mb-4">Genutztes Filament nach Nutzer</h1>
|
||||
<form action="debug.php?show=usr_fil_stats" method="POST">
|
||||
<input type="text" class="form-control flex-grow-1 mr-2" name="username" placeholder="Benutzername eingeben" >
|
||||
<button type="submit" class="btn btn-primary">Suchen</button>
|
||||
</form>
|
||||
<br>
|
||||
<a class="btn btn-primary" href="debug.php?show=usr_fil_stats&high_usage">Nutzer mit mehr als 1 Kg nutzung anzeigen</a>
|
||||
<!-- list users -->
|
||||
<?php
|
||||
if(isset($_GET["reset"])){
|
||||
$usr_id=intval(htmlspecialchars($_GET["reset"]));
|
||||
$sql="update users set filament_usage = 0 where id = $usr_id";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$stmt->close();
|
||||
}
|
||||
if(isset($_GET["high_usage"]))
|
||||
$sql="select username, id, filament_usage from users where filament_usage > 800 ORDER BY filament_usage DESC";
|
||||
if(isset($_POST["username"])){
|
||||
$username_search=htmlspecialchars($_POST["username"]);
|
||||
$sql="select username, id, filament_usage from users where username LIKE '%$username_search%' ORDER BY filament_usage DESC";
|
||||
}
|
||||
if(isset($_GET["high_usage"]) or isset($_POST["username"])){
|
||||
//list users
|
||||
$usr_username="";
|
||||
$usr_id="";
|
||||
$usr_filament_usage="";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
mysqli_stmt_bind_result($stmt, $usr_username, $usr_id,$usr_filament_usage);
|
||||
|
||||
echo "<h2>Suchergebnisse</h2>";
|
||||
echo "<table class='table' style='overflow-x: auto'>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Filament nutzung</th>
|
||||
<th>Nutzung zurücksetzen</th>
|
||||
</tr>";
|
||||
|
||||
if (mysqli_stmt_num_rows($stmt) > 0) {
|
||||
while (mysqli_stmt_fetch($stmt)) {
|
||||
$real_usage=(($usr_filament_usage*1.24)/1000);
|
||||
echo "<tr>
|
||||
<td>{$usr_username}</td>
|
||||
<td>{$real_usage} Kg</td>
|
||||
<td><a href='debug.php?show=usr_fil_stats&reset={$usr_id}'>Zurücksetzen</a></td>
|
||||
</tr>";
|
||||
}
|
||||
} else {
|
||||
echo "<tr><td colspan='2'>No users found.</td></tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
test_queue($link);
|
||||
?>
|
||||
@@ -284,6 +393,18 @@ function delete_input(input,action,id,row){
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer"></div>
|
||||
<script>
|
||||
//decide which div should be shown:
|
||||
// Get the URL parameters
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
|
||||
// Get the value of the "show" parameter
|
||||
const show_div = document.getElementById(urlParams.get('show'));
|
||||
const nav_tab = document.getElementById(urlParams.get('show')+"_tab");
|
||||
show_div.style.display="block";
|
||||
nav_tab.setAttribute('class', 'nav-link active');
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Server Stats</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="stats"></div>
|
||||
<script>
|
||||
function refreshStats() {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
// Refresh stats every 1 second
|
||||
setInterval(refreshStats, 1000);
|
||||
|
||||
</script>
|
||||
<?php
|
||||
|
||||
// Get server load
|
||||
$load = sys_getloadavg();
|
||||
|
||||
// Get CPU usage
|
||||
$cpu_usage = shell_exec("top -bn1 | grep 'Cpu(s)' | sed 's/.*, *\\([0-9.]*\\)%* id.*/\\1/' | awk '{print 100 - $1\"%\"}'");
|
||||
|
||||
// Get RAM usage
|
||||
$ram_usage = shell_exec("free | grep Mem | awk '{print $3/$2 * 100.0\"%\"}'");
|
||||
|
||||
// Display results
|
||||
echo "Server Load: " . implode(", ", $load) . "<br>";
|
||||
echo "CPU Usage: " . $cpu_usage . "<br>";
|
||||
echo "RAM Usage: " . $ram_usage . "<br>";
|
||||
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -121,6 +121,7 @@ function load_user()
|
||||
<?php
|
||||
if(isset($_GET['free'])&&$_GET["rid"]==($_SESSION["rid"]-1))
|
||||
{
|
||||
$cnt="";
|
||||
$printer_id=htmlspecialchars($_GET['free']);
|
||||
$sql="select used_by_userid from printer where id=$printer_id";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
@@ -131,6 +132,32 @@ function load_user()
|
||||
$sql="update printer set free=1,printing=0,cancel=0 ,used_by_userid=0 where id=$printer_id";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
//try to find out how much filament was used
|
||||
$stmt->close();
|
||||
//load apikey etc
|
||||
$url="";
|
||||
$apikey="";
|
||||
$sql="select printer_url,apikey from printer where id=$printer_id";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
mysqli_stmt_bind_result($stmt, $url,$apikey);
|
||||
mysqli_stmt_fetch($stmt);
|
||||
$stmt->close();
|
||||
//connect to the printer
|
||||
exec("curl --max-time 10 $url/api/job?apikey=$apikey > /var/www/html/user_files/$username/finish.json");
|
||||
$fg=file_get_contents("/var/www/html/user_files/$username/finish.json");
|
||||
$json=json_decode($fg,true);
|
||||
$userid=$_SESSION["id"];
|
||||
if(isset($json['job']['filament']['tool0']['volume'])){
|
||||
$filament_usage=intval($json['job']['filament']['tool0']['volume']);
|
||||
$sql="UPDATE users SET filament_usage = COALESCE(filament_usage,0) + $filament_usage WHERE id = $cnt";
|
||||
//echo($sql);
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
}
|
||||
|
||||
//echo("used $filament_usage mm of filament");
|
||||
}
|
||||
if(isset($_GET['remove_queue'])&&$_GET["rid"]==($_SESSION["rid"]-1))
|
||||
{
|
||||
|
||||
@@ -373,7 +373,7 @@ function is_time_between($startTime, $endTime, $checkTime) {
|
||||
<?php
|
||||
//get number of printers
|
||||
$num_of_printers=0;
|
||||
$sql="select count(*) from printer where free=1";
|
||||
$sql="select count(*) from printer where free=1 and system_status=0";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
@@ -437,7 +437,7 @@ function is_time_between($startTime, $endTime, $checkTime) {
|
||||
|
||||
//get number of printers
|
||||
$num_of_printers=0;
|
||||
$sql="select count(*) from printer";
|
||||
$sql="select count(*) from printer where system_status=0";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
@@ -111,6 +111,16 @@ if(isset($_GET["del"])){
|
||||
while($row = $result->fetch_assoc()) {
|
||||
echo("<tr><td>".$row["time_from"]."</td><td>".$row["time_to"]."</td><td>".$row["day"]."</td><td>".$row["name"]."</td><td><a href='reservations.php?del=".$row["res_id"]."'>Löschen</a></td><tr>");
|
||||
}
|
||||
$stmt->close();
|
||||
//check if is set for teachers, which do not have a class but always id 0
|
||||
$sql="select reservations.id as res_id,time_to,time_from,day from reservations WHERE for_class=0 ORDER BY reservations.id desc;";
|
||||
$stmt = $link->prepare($sql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
while($row = $result->fetch_assoc()) {
|
||||
echo("<tr><td>".$row["time_from"]."</td><td>".$row["time_to"]."</td><td>".$row["day"]."</td><td>Lehrer</td><td><a href='reservations.php?del=".$row["res_id"]."'>Löschen</a></td><tr>");
|
||||
}
|
||||
|
||||
echo("</table>");
|
||||
|
||||
?>
|
||||
|
||||
@@ -38,7 +38,7 @@ $(document).ready(function () {
|
||||
<div class="col-md-auto">
|
||||
<h1>Log Entries</h1>
|
||||
|
||||
<!-- Filter Form -->
|
||||
<!-- Search Form -->
|
||||
<div class="overflow-auto">
|
||||
<form method="GET" action="">
|
||||
<table class="table">
|
||||
@@ -51,50 +51,38 @@ $(document).ready(function () {
|
||||
<th>Info</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>---</td>
|
||||
<td>---</td>
|
||||
<td>
|
||||
<select class="form-select" name="type_">
|
||||
<option value="All_types">All Types</option>
|
||||
<option value="PRINT::UPLOAD::PRINTER">PRINT::UPLOAD::PRINTER</option>
|
||||
<option value="PRINT:JOB:START:FAILED">PRINT:JOB:START:FAILED</option>
|
||||
<option value="PRINT::UPLOAD::QUEUE">PRINT::UPLOAD::QUEUE</option>
|
||||
<option value="PRINT::UPLOAD::FILE::FAILED">PRINT::UPLOAD::FILE::FAILED</option>
|
||||
<option value="JOB::PRINTERCTRL::FREE">JOB::PRINTERCTRL::FREE</option>
|
||||
<option value="JOB::QUEUECTRL::REMOVE">JOB::QUEUECTRL::REMOVE</option>
|
||||
<option value="JOB::PRINTERCTRL::CANCEL::FAILED">JOB::PRINTERCTRL::CANCEL::FAILED</option>
|
||||
<option value="JOB::PRINTERCTRL::CANCEL">JOB::PRINTERCTRL::CANCEL</option>
|
||||
</select>
|
||||
<!-- Search by IP Address -->
|
||||
<input type="text" class="form-control" name="search_ip" value="<?= isset($_GET['search_ip']) ? htmlspecialchars($_GET['search_ip']) : '' ?>" placeholder="Search IP...">
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-select" id="username" name="username">
|
||||
<option value="All_usernames">All Users</option>
|
||||
<?php
|
||||
// Fetch all usernames in one query
|
||||
$sql = "SELECT username FROM users ORDER BY username ASC";
|
||||
$stmt = mysqli_prepare($link, $sql);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_bind_result($stmt, $uname);
|
||||
|
||||
// Populate the dropdown with usernames
|
||||
while (mysqli_stmt_fetch($stmt)) {
|
||||
echo '<option value="' . htmlspecialchars($uname) . '">' . htmlspecialchars($uname) . '</option>';
|
||||
}
|
||||
mysqli_stmt_close($stmt);
|
||||
?>
|
||||
</select>
|
||||
<!-- Search by Type -->
|
||||
<input type="text" class="form-control" name="search_type" value="<?= isset($_GET['search_type']) ? htmlspecialchars($_GET['search_type']) : '' ?>" placeholder="Search Type...">
|
||||
</td>
|
||||
<td>
|
||||
<button type="submit" class="btn btn-primary">Apply Filter</button>
|
||||
<!-- Search by Username -->
|
||||
<input type="text" class="form-control" name="search_username" value="<?= isset($_GET['search_username']) ? htmlspecialchars($_GET['search_username']) : '' ?>" placeholder="Search Username...">
|
||||
</td>
|
||||
<td>
|
||||
<!-- Search by Info -->
|
||||
<input type="text" class="form-control" name="search_info" value="<?= isset($_GET['search_info']) ? htmlspecialchars($_GET['search_info']) : '' ?>" placeholder="Search Info...">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<button type="submit" class="btn btn-primary">Search</button>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
// Define default filters
|
||||
$type_filter = isset($_GET["type_"]) ? $_GET["type_"] : "All_types";
|
||||
$user_filter = isset($_GET["username"]) ? $_GET["username"] : "All_usernames";
|
||||
// Retrieve search terms from GET parameters
|
||||
$search_ip = isset($_GET['search_ip']) ? $_GET['search_ip'] : '';
|
||||
$search_type = isset($_GET['search_type']) ? $_GET['search_type'] : '';
|
||||
$search_username = isset($_GET['search_username']) ? $_GET['search_username'] : '';
|
||||
$search_info = isset($_GET['search_info']) ? $_GET['search_info'] : '';
|
||||
|
||||
// Pagination variables
|
||||
$items_per_page = 25;
|
||||
@@ -126,11 +114,13 @@ $(document).ready(function () {
|
||||
// Reverse the log entries to display the latest first
|
||||
$log_entries = array_reverse($log_entries);
|
||||
|
||||
// Filter log entries by type and username
|
||||
$filtered_entries = array_filter($log_entries, function ($entry) use ($type_filter, $user_filter) {
|
||||
$type_match = ($type_filter === "All_types" || $entry['type'] === $type_filter);
|
||||
$user_match = ($user_filter === "All_usernames" || $entry['username'] === $user_filter);
|
||||
return $type_match && $user_match;
|
||||
// Filter log entries by search terms (partial matches)
|
||||
$filtered_entries = array_filter($log_entries, function ($entry) use ($search_ip, $search_type, $search_username, $search_info) {
|
||||
$ip_match = empty($search_ip) || stripos($entry['ip'], $search_ip) !== false;
|
||||
$type_match = empty($search_type) || stripos($entry['type'], $search_type) !== false;
|
||||
$username_match = empty($search_username) || stripos($entry['username'], $search_username) !== false;
|
||||
$info_match = empty($search_info) || stripos($entry['info'], $search_info) !== false;
|
||||
return $ip_match && $type_match && $username_match && $info_match;
|
||||
});
|
||||
|
||||
// Calculate total pages and slice the log entries for the current page
|
||||
@@ -163,19 +153,19 @@ $(document).ready(function () {
|
||||
<ul class="pagination justify-content-center">
|
||||
<?php if ($current_page > 1): ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page=<?= $current_page - 1 ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>">Previous</a>
|
||||
<a class="page-link" href="?page=<?= $current_page - 1 ?>&search_ip=<?= urlencode($search_ip) ?>&search_type=<?= urlencode($search_type) ?>&search_username=<?= urlencode($search_username) ?>&search_info=<?= urlencode($search_info) ?>">Previous</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php for ($page = 1; $page <= $total_pages; $page++): ?>
|
||||
<li class="page-item <?= ($page === $current_page) ? 'active' : '' ?>">
|
||||
<a class="page-link" href="?page=<?= $page ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>"><?= $page ?></a>
|
||||
<a class="page-link" href="?page=<?= $page ?>&search_ip=<?= urlencode($search_ip) ?>&search_type=<?= urlencode($search_type) ?>&search_username=<?= urlencode($search_username) ?>&search_info=<?= urlencode($search_info) ?>"><?= $page ?></a>
|
||||
</li>
|
||||
<?php endfor; ?>
|
||||
|
||||
<?php if ($current_page < $total_pages): ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page=<?= $current_page + 1 ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>">Next</a>
|
||||
<a class="page-link" href="?page=<?= $current_page + 1 ?>&search_ip=<?= urlencode($search_ip) ?>&search_type=<?= urlencode($search_type) ?>&search_username=<?= urlencode($search_username) ?>&search_info=<?= urlencode($search_info) ?>">Next</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
@@ -1,26 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<?php
|
||||
$username=htmlspecialchars($_GET["username"]);
|
||||
$printer_url=$_GET["url"];
|
||||
$rotation=$_GET["rotation"];
|
||||
$username = htmlspecialchars($_GET["username"]);
|
||||
$printer_url = $_GET["url"];
|
||||
$rotation = $_GET["rotation"];
|
||||
?>
|
||||
<head>
|
||||
<title>Webcam</title>
|
||||
|
||||
<title>Webcam</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
$path = "/var/www/html/user_files/$username/$printer_url.jpeg";
|
||||
unlink($path);
|
||||
exec("wget --quiet \"http://$printer_url/webcam/?action=snapshot\" -O $path");
|
||||
echo("<img style='transform: rotate(".$rotation."deg);' loading='lazy' width='100%' src='/user_files/$username/$printer_url.jpeg'>");
|
||||
?>
|
||||
<!-- Display the first image -->
|
||||
<a id="image-link" href='<?php echo("webcam.php?username=$username&url=$printer_url&rotation=$rotation"); ?>' target="_blank">
|
||||
<img id="webcam-image" style="transform: rotate(<?php echo $rotation; ?>deg);" width="100%" src="/user_files/<?php echo $username; ?>/<?php echo $printer_url; ?>.jpeg" alt="Webcam Feed">
|
||||
</a>
|
||||
<script>
|
||||
setInterval(function() {
|
||||
location.reload();
|
||||
}, 5000);
|
||||
// Function to call PHP script to download the latest image and then swap it
|
||||
function loadAndSwapImage() {
|
||||
// Make an AJAX call to PHP to trigger the image download
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/api/download_image.php?username=<?php echo $username; ?>&url=<?php echo $printer_url; ?>', true);
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
// Preload the new image once the PHP script has completed downloading
|
||||
let img = new Image();
|
||||
img.src = '/user_files/<?php echo $username; ?>/<?php echo $printer_url; ?>.jpeg?rand=' + Math.random(); // Add cache buster to avoid caching issues
|
||||
|
||||
// Swap the image when it is loaded
|
||||
img.onload = function() {
|
||||
let webcamImage = document.getElementById('webcam-image');
|
||||
webcamImage.src = img.src;
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(); // Execute the request
|
||||
}
|
||||
|
||||
// Reload the image every 5 seconds
|
||||
setInterval(loadAndSwapImage, 5000);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
var tel_id=a.checked;
|
||||
fetch("/api/update_settings.php?"+div_id+"="+tel_id);
|
||||
}
|
||||
//check if sendmail must be executed
|
||||
fetch("/api/sendmail.php");
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -205,7 +207,7 @@
|
||||
<i class="fa-solid fa-file fa-6x justify-content-center"></i>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">View system0 Log</h5>
|
||||
<h5 class="card-title">System0 Protokoll ansehen</h5>
|
||||
<p class="card-text">Zeigen Sie das Protokoll der Systemaktivitäten und -ereignisse an.</p>
|
||||
<a href="/app/view_log.php" class="stretched-link"></a>
|
||||
</div>
|
||||
@@ -220,7 +222,7 @@
|
||||
<i class="fa-solid fa-key fa-6x justify-content-center"></i>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">View the system0 API Key</h5>
|
||||
<h5 class="card-title">System0 APIkey ansehen</h5>
|
||||
<p class="card-text">Zeigen Sie den API-Schlüssel an, der für den Zugriff auf die Systemfunktionalitäten verwendet wird.</p>
|
||||
<a href="/app/view_apikey.php" class="stretched-link"></a>
|
||||
</div>
|
||||
@@ -235,9 +237,9 @@
|
||||
<i class="fa-solid fa-print fa-6x justify-content-center"></i>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Drucker Einstellungen</h5>
|
||||
<h5 class="card-title">Einstellungen & Statistiken</h5>
|
||||
<p class="card-text">Hier findest du das Debug-Tool und die Einstellungen.</p>
|
||||
<a href="/app/debug.php" class="stretched-link"></a>
|
||||
<a href="/app/debug.php?show=printer_settings" class="stretched-link"></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -28,7 +28,8 @@ $sql = "CREATE TABLE IF NOT EXISTS users (
|
||||
notification_way INT,
|
||||
notification_mail INT,
|
||||
notification_telegram INT,
|
||||
class_id INT
|
||||
class_id INT,
|
||||
filament_usage INT
|
||||
)";
|
||||
$link->query($sql);
|
||||
//printer table
|
||||
|
||||
@@ -17,11 +17,9 @@ require_once "../waf/salt.php";
|
||||
require_once "keepmeloggedin.php";
|
||||
include "../assets/components.php";
|
||||
$error=logmein($link);
|
||||
|
||||
if($error==="success")
|
||||
{
|
||||
header("LOCATION: /app/overview.php");
|
||||
|
||||
}
|
||||
|
||||
// Define variables and initialize with empty values
|
||||
@@ -60,40 +58,39 @@ EOF;
|
||||
}
|
||||
// Processing form data when form is submitted
|
||||
if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
|
||||
|
||||
|
||||
// Check if username is empty
|
||||
if(empty(trim($_POST["username"]))){
|
||||
$username_err = "Please enter username.";
|
||||
} else{
|
||||
$username = trim($_POST["username"]);
|
||||
}
|
||||
|
||||
|
||||
// Check if password is empty
|
||||
if(empty(trim($_POST["password"]))){
|
||||
$password_err = "Please enter your password.";
|
||||
} else{
|
||||
$password = trim($_POST["password"]);
|
||||
}
|
||||
|
||||
|
||||
// Validate credentials
|
||||
if(empty($username_err) && empty($password_err)){
|
||||
// Prepare a select statement
|
||||
$sql = "SELECT id, username, password, role, color,banned,banned_reason ,telegram_id,notification_telegram,notification_mail, class_id FROM users WHERE username = ?";
|
||||
|
||||
|
||||
if($stmt = mysqli_prepare($link, $sql)){
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "s", $param_username);
|
||||
|
||||
// Set parameters
|
||||
$param_username = htmlspecialchars($username);
|
||||
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if(mysqli_stmt_execute($stmt)){
|
||||
// Store result
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
|
||||
// Check if username exists, if yes then verify password
|
||||
if(mysqli_stmt_num_rows($stmt) == 1){
|
||||
if(mysqli_stmt_num_rows($stmt) == 1){
|
||||
// Bind result variables
|
||||
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password, $role,$color,$banned,$banned_reason,$telegram_id,$notification_telegram,$notification_mail,$class_id);
|
||||
if(mysqli_stmt_fetch($stmt)){
|
||||
@@ -137,8 +134,8 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
|
||||
$_SESSION["telegram_id"]=$telegram_id;
|
||||
$_SESSION["notification_telegram"]=$notification_telegram;
|
||||
$_SESSION["notification_mail"]=$notification_mail;
|
||||
$_SESSION["class_id"]=$class_id;
|
||||
|
||||
$_SESSION["class_id"]=$class_id;
|
||||
|
||||
// Redirect user to welcome page
|
||||
log_("$username logged in","LOGIN:SUCCESS");
|
||||
header("location:/app/overview.php");
|
||||
@@ -168,13 +165,12 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Close connection
|
||||
mysqli_close($link);
|
||||
}
|
||||
// Processing form data when form is submitted and user wants to create new user
|
||||
if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
|
||||
|
||||
// Validate username
|
||||
if(empty(trim($_POST["username"]))){
|
||||
$err = "Please enter a username.";
|
||||
@@ -183,19 +179,17 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
|
||||
} else{
|
||||
// Prepare a select statement
|
||||
$sql = "SELECT id FROM users WHERE username = ?";
|
||||
|
||||
|
||||
if($stmt = mysqli_prepare($link, $sql)){
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "s", $param_username);
|
||||
|
||||
|
||||
// Set parameters
|
||||
$param_username = trim($_POST["username"]);
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if(mysqli_stmt_execute($stmt)){
|
||||
/* store result */
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
if(mysqli_stmt_num_rows($stmt) == 1){
|
||||
$err = "This username is already taken.";
|
||||
} else{
|
||||
@@ -209,7 +203,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Validate password
|
||||
if(empty(trim($_POST["password"]))){
|
||||
$err = "Please enter a password.";
|
||||
|
||||
Reference in New Issue
Block a user