34 Commits

Author SHA1 Message Date
Janis Steiner
00209479bb Update README.md 2024-10-21 15:16:38 +00:00
Janis Steiner
1cb5eceeb9 adding success message 2024-10-21 16:13:37 +01:00
Janis Steiner
117f3d2eb3 fix naming 2024-10-14 15:34:22 +01:00
Janis Steiner
583d6f51eb . 2024-10-14 15:23:01 +01:00
Janis Steiner
cd0c685420 . 2024-10-14 15:21:18 +01:00
Janis Steiner
d40d86d796 . 2024-10-14 15:20:31 +01:00
Janis Steiner
a5a35ff777 changing from m to kg 2024-10-14 15:17:18 +01:00
Janis Steiner
399a007803 fixing bug where filamanet usage was set for wrong user 2024-10-14 15:07:02 +01:00
Janis Steiner
e2182e93d7 fixing bug where filamanet usage was set for wrong user 2024-10-14 15:02:04 +01:00
Janis Steiner
d059a48379 fixing bug where filamanet usage was set for wrong user 2024-10-14 15:00:02 +01:00
Janis Steiner
0d6ef57b1a creating filament tracking 2024-10-14 14:58:15 +01:00
Janis Steiner
0f9db35b48 creating filament tracking 2024-10-14 14:57:08 +01:00
Janis Steiner
af29d88f3d creating filament tracking 2024-10-14 14:54:45 +01:00
Janis Steiner
90c19b42d0 creating infra for filament tracking by user 2024-10-14 14:29:42 +01:00
Janis Steiner
a69fd1488b creating infra for filament tracking by user__ 2024-10-14 14:27:01 +01:00
Janis Steiner
dfb5d35a25 creating infra for filament tracking by user_ 2024-10-14 14:21:25 +01:00
Janis Steiner
47a141acc6 creating infra for filament tracking by user 2024-10-14 14:16:15 +01:00
Janis Steiner
fe92406a66 creating infra for filament tracking by user 2024-10-14 14:14:47 +01:00
Janis Steiner
1e72a1624b . 2024-10-14 14:09:07 +01:00
Janis Steiner
26dd986dbb srv stats 2024-10-14 13:50:00 +01:00
Janis Steiner
e6fc6b3b7c fixing disk usage 2024-10-14 13:17:42 +01:00
Janis Steiner
d48ac8418a fixing disk usage 2024-10-14 13:16:23 +01:00
Janis Steiner
31d11f1f4d fixing disk usage 2024-10-14 13:15:29 +01:00
Janis Steiner
017c34e2d5 changed server load stats 2024-10-14 13:12:21 +01:00
Janis Steiner
c7a644a8e4 making log viewer better 2024-10-14 12:59:16 +01:00
Janis Steiner
4611b118bf adding new page 2024-10-14 12:44:27 +01:00
Janis Steiner
3192cf02dd adding new page 2024-10-14 12:42:10 +01:00
Janis Steiner
3e1380ca47 fixing webcam issues 2024-10-14 12:38:32 +01:00
Janis Steiner
5e853f4000 fixing bug where no notification was sent 2024-10-14 11:59:29 +01:00
Janis Steiner
0e755eefe8 fixing reservations for teachers 2024-10-05 12:43:35 +01:00
Janis Steiner
ae3146c804 fixing design of settings page 2024-10-05 10:47:19 +01:00
Janis Steiner
e91de28ef5 fixing bug where printers where shown twice in print menu 2024-09-22 12:45:09 +01:00
Janis Steiner
a114232c47 fixing some bugs 2024-09-22 12:41:42 +01:00
Janis Steiner
9e77ad56f9 . 2024-09-21 15:45:18 +01:00
16 changed files with 375 additions and 134 deletions

View File

@@ -1,5 +1,5 @@
# system0-test # system0-2.0
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. The new version of system0. It runs on Docker and is much smarter with many new features compared to the original system0.
# system0 # system0
Frontend system for octoprint<br> Frontend system for octoprint<br>

4
scripts/README.md Normal file
View 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
View 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"

View 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");
?>

View 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>
";
?>

View File

@@ -78,6 +78,11 @@ function load_user()
</select><br><br> </select><br><br>
<input type="submit" class="btn btn-dark mb-5" value="Farbe aktualisieren" id="button"> <input type="submit" class="btn btn-dark mb-5" value="Farbe aktualisieren" id="button">
</form> </form>
<?php
if(isset($_POST["printer"])){
echo("<center><div class='alert alert-success' role='alert'>Farbe geändert</div></center>");
}
?>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -14,7 +14,6 @@ $username=htmlspecialchars($_SESSION["username"]);
$id=$_SESSION["id"]; $id=$_SESSION["id"];
?> ?>
<script src="/assets/js/load_page.js"></script> <script src="/assets/js/load_page.js"></script>
<script> <script>
function load_user() 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=document.getElementById(input);
var selector_value=selector.value; var selector_value=selector.value;
fetch("/api/printer_settings.php?action="+action+"&value="+selector.value+"&id="+id); await fetch("/api/printer_settings.php?action="+action+"&value="+selector.value+"&id="+id);
document.getElementById("table1").deleteRow(row); //document.getElementById("table1").deleteRow(row);
location.reload();
} }
</script> </script>
<?php <?php
@@ -48,6 +48,7 @@ function delete_input(input,action,id,row){
<?php <?php
$color=$_SESSION["color"]; $color=$_SESSION["color"];
include "../assets/components.php"; include "../assets/components.php";
$tab=$_GET["show"];
?> ?>
<div id="content"></div> <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="container mt-5" style="min-height: 95vh;">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div style="width: 100hh"> <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> <h1>Druckerfreigabe erzwingen (falls beim freigeben Fehlermeldungen angezeigt werden)</h1>
<?php <?php
if(isset($_POST['free'])) if(isset($_POST['free']))
@@ -128,16 +151,17 @@ function delete_input(input,action,id,row){
mysqli_stmt_fetch($stmt); mysqli_stmt_fetch($stmt);
if($system_status==0) 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 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--; $cnt--;
} }
echo("</tbody></table></div></div></div></div>"); echo("</tbody></table></div></div></div></div>");
?> ?>
<br><br> <br><br>
</div>
<div id="camera_settings" style="display:none">
<!-- Rotation der Druckerkameras: --> <!-- Rotation der Druckerkameras: -->
<h1>Rotation der Druckerkameras</h1> <h1>Rotation der Druckerkameras</h1>
<?php <?php
@@ -177,7 +201,8 @@ function delete_input(input,action,id,row){
} }
echo("</tbody></table></div></div></div>"); echo("</tbody></table></div></div></div>");
?> ?>
<br><br> </div></div>
<div id="class_settings" style="display:none">
<h1>Klassen</h1> <h1>Klassen</h1>
<?php <?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>"); 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 //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><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("<td><button type='submit' value='add' class='btn btn-primary'>Hinzufügen</button></td>");
echo("</form>"); echo("</form>");
@@ -226,7 +251,8 @@ function delete_input(input,action,id,row){
echo("</div>"); echo("</div>");
?> ?>
</div>
<div id="filament_settings" style="display:none">
<h1>Filamente</h1> <h1>Filamente</h1>
<?php <?php
//list printers => form => color //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>"); 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 //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='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><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>"); 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("</tbody></table></div></div></div>");
echo("</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 <?php
test_queue($link); test_queue($link);
?> ?>
@@ -284,6 +393,18 @@ function delete_input(input,action,id,row){
</div> </div>
</div> </div>
<div id="footer"></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> </body>
</html> </html>

View File

@@ -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>

View File

@@ -121,6 +121,7 @@ function load_user()
<?php <?php
if(isset($_GET['free'])&&$_GET["rid"]==($_SESSION["rid"]-1)) if(isset($_GET['free'])&&$_GET["rid"]==($_SESSION["rid"]-1))
{ {
$cnt="";
$printer_id=htmlspecialchars($_GET['free']); $printer_id=htmlspecialchars($_GET['free']);
$sql="select used_by_userid from printer where id=$printer_id"; $sql="select used_by_userid from printer where id=$printer_id";
$stmt = mysqli_prepare($link, $sql); $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"; $sql="update printer set free=1,printing=0,cancel=0 ,used_by_userid=0 where id=$printer_id";
$stmt = mysqli_prepare($link, $sql); $stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt); 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)) if(isset($_GET['remove_queue'])&&$_GET["rid"]==($_SESSION["rid"]-1))
{ {

View File

@@ -373,7 +373,7 @@ function is_time_between($startTime, $endTime, $checkTime) {
<?php <?php
//get number of printers //get number of printers
$num_of_printers=0; $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); $stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt); mysqli_stmt_store_result($stmt);
@@ -437,7 +437,7 @@ function is_time_between($startTime, $endTime, $checkTime) {
//get number of printers //get number of printers
$num_of_printers=0; $num_of_printers=0;
$sql="select count(*) from printer"; $sql="select count(*) from printer where system_status=0";
$stmt = mysqli_prepare($link, $sql); $stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt); mysqli_stmt_store_result($stmt);

View File

@@ -111,6 +111,16 @@ if(isset($_GET["del"])){
while($row = $result->fetch_assoc()) { 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>"); 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>"); echo("</table>");
?> ?>

View File

@@ -38,7 +38,7 @@ $(document).ready(function () {
<div class="col-md-auto"> <div class="col-md-auto">
<h1>Log Entries</h1> <h1>Log Entries</h1>
<!-- Filter Form --> <!-- Search Form -->
<div class="overflow-auto"> <div class="overflow-auto">
<form method="GET" action=""> <form method="GET" action="">
<table class="table"> <table class="table">
@@ -51,50 +51,38 @@ $(document).ready(function () {
<th>Info</th> <th>Info</th>
</tr> </tr>
<tr> <tr>
<td>---</td>
<td>---</td> <td>---</td>
<td> <td>
<select class="form-select" name="type_"> <!-- Search by IP Address -->
<option value="All_types">All Types</option> <input type="text" class="form-control" name="search_ip" value="<?= isset($_GET['search_ip']) ? htmlspecialchars($_GET['search_ip']) : '' ?>" placeholder="Search IP...">
<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>
</td> </td>
<td> <td>
<select class="form-select" id="username" name="username"> <!-- Search by Type -->
<option value="All_usernames">All Users</option> <input type="text" class="form-control" name="search_type" value="<?= isset($_GET['search_type']) ? htmlspecialchars($_GET['search_type']) : '' ?>" placeholder="Search Type...">
<?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>
</td> </td>
<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> </td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
// Define default filters // Retrieve search terms from GET parameters
$type_filter = isset($_GET["type_"]) ? $_GET["type_"] : "All_types"; $search_ip = isset($_GET['search_ip']) ? $_GET['search_ip'] : '';
$user_filter = isset($_GET["username"]) ? $_GET["username"] : "All_usernames"; $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 // Pagination variables
$items_per_page = 25; $items_per_page = 25;
@@ -126,11 +114,13 @@ $(document).ready(function () {
// Reverse the log entries to display the latest first // Reverse the log entries to display the latest first
$log_entries = array_reverse($log_entries); $log_entries = array_reverse($log_entries);
// Filter log entries by type and username // Filter log entries by search terms (partial matches)
$filtered_entries = array_filter($log_entries, function ($entry) use ($type_filter, $user_filter) { $filtered_entries = array_filter($log_entries, function ($entry) use ($search_ip, $search_type, $search_username, $search_info) {
$type_match = ($type_filter === "All_types" || $entry['type'] === $type_filter); $ip_match = empty($search_ip) || stripos($entry['ip'], $search_ip) !== false;
$user_match = ($user_filter === "All_usernames" || $entry['username'] === $user_filter); $type_match = empty($search_type) || stripos($entry['type'], $search_type) !== false;
return $type_match && $user_match; $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 // 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"> <ul class="pagination justify-content-center">
<?php if ($current_page > 1): ?> <?php if ($current_page > 1): ?>
<li class="page-item"> <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> </li>
<?php endif; ?> <?php endif; ?>
<?php for ($page = 1; $page <= $total_pages; $page++): ?> <?php for ($page = 1; $page <= $total_pages; $page++): ?>
<li class="page-item <?= ($page === $current_page) ? 'active' : '' ?>"> <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> </li>
<?php endfor; ?> <?php endfor; ?>
<?php if ($current_page < $total_pages): ?> <?php if ($current_page < $total_pages): ?>
<li class="page-item"> <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> </li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>

View File

@@ -1,26 +1,42 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<?php <?php
$username=htmlspecialchars($_GET["username"]); $username = htmlspecialchars($_GET["username"]);
$printer_url=$_GET["url"]; $printer_url = $_GET["url"];
$rotation=$_GET["rotation"]; $rotation = $_GET["rotation"];
?> ?>
<head> <head>
<title>Webcam</title> <title>Webcam</title>
</head> </head>
<body> <body>
<?php <!-- Display the first image -->
$path = "/var/www/html/user_files/$username/$printer_url.jpeg"; <a id="image-link" href='<?php echo("webcam.php?username=$username&url=$printer_url&rotation=$rotation"); ?>' target="_blank">
unlink($path); <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">
exec("wget --quiet \"http://$printer_url/webcam/?action=snapshot\" -O $path"); </a>
echo("<img style='transform: rotate(".$rotation."deg);' loading='lazy' width='100%' src='/user_files/$username/$printer_url.jpeg'>");
?>
<script> <script>
setInterval(function() { // Function to call PHP script to download the latest image and then swap it
location.reload(); function loadAndSwapImage() {
}, 5000); // 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> </script>
</body> </body>
</html> </html>

View File

@@ -20,6 +20,8 @@
var tel_id=a.checked; var tel_id=a.checked;
fetch("/api/update_settings.php?"+div_id+"="+tel_id); fetch("/api/update_settings.php?"+div_id+"="+tel_id);
} }
//check if sendmail must be executed
fetch("/api/sendmail.php");
</script> </script>
<style> <style>
@@ -205,7 +207,7 @@
<i class="fa-solid fa-file fa-6x justify-content-center"></i> <i class="fa-solid fa-file fa-6x justify-content-center"></i>
</div> </div>
<div class="card-body"> <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> <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> <a href="/app/view_log.php" class="stretched-link"></a>
</div> </div>
@@ -220,7 +222,7 @@
<i class="fa-solid fa-key fa-6x justify-content-center"></i> <i class="fa-solid fa-key fa-6x justify-content-center"></i>
</div> </div>
<div class="card-body"> <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> <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> <a href="/app/view_apikey.php" class="stretched-link"></a>
</div> </div>
@@ -235,9 +237,9 @@
<i class="fa-solid fa-print fa-6x justify-content-center"></i> <i class="fa-solid fa-print fa-6x justify-content-center"></i>
</div> </div>
<div class="card-body"> <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> <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>
</div> </div>

View File

@@ -28,7 +28,8 @@ $sql = "CREATE TABLE IF NOT EXISTS users (
notification_way INT, notification_way INT,
notification_mail INT, notification_mail INT,
notification_telegram INT, notification_telegram INT,
class_id INT class_id INT,
filament_usage INT
)"; )";
$link->query($sql); $link->query($sql);
//printer table //printer table

View File

@@ -17,11 +17,9 @@ require_once "../waf/salt.php";
require_once "keepmeloggedin.php"; require_once "keepmeloggedin.php";
include "../assets/components.php"; include "../assets/components.php";
$error=logmein($link); $error=logmein($link);
if($error==="success") if($error==="success")
{ {
header("LOCATION: /app/overview.php"); header("LOCATION: /app/overview.php");
} }
// Define variables and initialize with empty values // Define variables and initialize with empty values
@@ -60,40 +58,39 @@ EOF;
} }
// Processing form data when form is submitted // Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
// Check if username is empty // Check if username is empty
if(empty(trim($_POST["username"]))){ if(empty(trim($_POST["username"]))){
$username_err = "Please enter username."; $username_err = "Please enter username.";
} else{ } else{
$username = trim($_POST["username"]); $username = trim($_POST["username"]);
} }
// Check if password is empty // Check if password is empty
if(empty(trim($_POST["password"]))){ if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password."; $password_err = "Please enter your password.";
} else{ } else{
$password = trim($_POST["password"]); $password = trim($_POST["password"]);
} }
// Validate credentials // Validate credentials
if(empty($username_err) && empty($password_err)){ if(empty($username_err) && empty($password_err)){
// Prepare a select statement // 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 = ?"; $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)){ if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters // Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username); mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters // Set parameters
$param_username = htmlspecialchars($username); $param_username = htmlspecialchars($username);
// Attempt to execute the prepared statement // Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){ if(mysqli_stmt_execute($stmt)){
// Store result // Store result
mysqli_stmt_store_result($stmt); mysqli_stmt_store_result($stmt);
// Check if username exists, if yes then verify password // 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 // 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); 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)){ if(mysqli_stmt_fetch($stmt)){
@@ -137,8 +134,8 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
$_SESSION["telegram_id"]=$telegram_id; $_SESSION["telegram_id"]=$telegram_id;
$_SESSION["notification_telegram"]=$notification_telegram; $_SESSION["notification_telegram"]=$notification_telegram;
$_SESSION["notification_mail"]=$notification_mail; $_SESSION["notification_mail"]=$notification_mail;
$_SESSION["class_id"]=$class_id; $_SESSION["class_id"]=$class_id;
// Redirect user to welcome page // Redirect user to welcome page
log_("$username logged in","LOGIN:SUCCESS"); log_("$username logged in","LOGIN:SUCCESS");
header("location:/app/overview.php"); header("location:/app/overview.php");
@@ -168,13 +165,12 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="login"){
mysqli_stmt_close($stmt); mysqli_stmt_close($stmt);
} }
} }
// Close connection // Close connection
mysqli_close($link); mysqli_close($link);
} }
// Processing form data when form is submitted and user wants to create new user // Processing form data when form is submitted and user wants to create new user
if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
// Validate username // Validate username
if(empty(trim($_POST["username"]))){ if(empty(trim($_POST["username"]))){
$err = "Please enter a username."; $err = "Please enter a username.";
@@ -183,19 +179,17 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
} else{ } else{
// Prepare a select statement // Prepare a select statement
$sql = "SELECT id FROM users WHERE username = ?"; $sql = "SELECT id FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){ if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters // Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username); mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters // Set parameters
$param_username = trim($_POST["username"]); $param_username = trim($_POST["username"]);
// Attempt to execute the prepared statement // Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){ if(mysqli_stmt_execute($stmt)){
/* store result */ /* store result */
mysqli_stmt_store_result($stmt); mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){ if(mysqli_stmt_num_rows($stmt) == 1){
$err = "This username is already taken."; $err = "This username is already taken.";
} else{ } else{
@@ -209,7 +203,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST" and $_GET["action"]=="create_user"){
mysqli_stmt_close($stmt); mysqli_stmt_close($stmt);
} }
} }
// Validate password // Validate password
if(empty(trim($_POST["password"]))){ if(empty(trim($_POST["password"]))){
$err = "Please enter a password."; $err = "Please enter a password.";