install.php aktualisiert

This commit is contained in:
M_Viper 2024-02-25 15:25:57 +00:00
parent 5c29ff6041
commit d731f0e430
1 changed files with 136 additions and 104 deletions

View File

@ -1,104 +1,136 @@
<!DOCTYPE html> <?php
<html lang="de"> // Datenbankverbindung herstellen
<head> include_once 'config/config.php';
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> // Verbindung zur MySQL-Datenbank herstellen
<link rel="stylesheet" type="text/css" href="css/install.css"> $conn = new mysqli($host, $username, $password);
<title>Materialverwaltung Installer</title> if ($conn->connect_error) {
</head> die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
<body> }
<div class="container">
<h1>Materialverwaltung Installer</h1> if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Formulardaten abrufen
<?php $host = $_POST["host"];
if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST["username"];
// Formulardaten abrufen $password = $_POST["password"];
$host = $_POST["host"]; $database = $_POST["database"];
$username = $_POST["username"]; $email = $_POST["email"];
$password = $_POST["password"]; $notification_days = $_POST["notification_days"]; // Hinzugefügtes Feld für die Benachrichtigungstage
$database = $_POST["database"];
$email = $_POST["email"]; // Datenbank erstellen
$sql_create_db = "CREATE DATABASE IF NOT EXISTS $database";
// Verbindung zur MySQL-Datenbank herstellen if ($conn->query($sql_create_db) === TRUE) {
$conn = new mysqli($host, $username, $password); echo "<p>Datenbank erfolgreich erstellt.</p>";
if ($conn->connect_error) {
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error); // Datenbank auswählen
} $conn->select_db($database);
// Datenbank erstellen // Tabelle erstellen
$sql_create_db = "CREATE DATABASE IF NOT EXISTS $database"; $sql_create_table = "CREATE TABLE IF NOT EXISTS materials (
if ($conn->query($sql_create_db) === TRUE) { id INT AUTO_INCREMENT PRIMARY KEY,
echo "<p>Datenbank erfolgreich erstellt.</p>"; item_name VARCHAR(255) NOT NULL,
manufacturer VARCHAR(255) NOT NULL,
// Datenbank auswählen location VARCHAR(255) NOT NULL,
$conn->select_db($database); amount_should INT NOT NULL,
amount_is INT NOT NULL,
// Tabelle erstellen expiration_date DATE NOT NULL,
$sql_create_table = "CREATE TABLE IF NOT EXISTS materials ( barcode VARCHAR(255) NOT NULL,
id INT AUTO_INCREMENT PRIMARY KEY, image VARCHAR(255),
item_name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
manufacturer VARCHAR(255) NOT NULL, notification_days INT NOT NULL DEFAULT 0
location VARCHAR(255) NOT NULL, )";
amount_should INT NOT NULL, if ($conn->query($sql_create_table) === TRUE) {
amount_is INT NOT NULL, echo "<p>Tabelle 'materials' erfolgreich erstellt.</p>";
expiration_date DATE NOT NULL,
barcode VARCHAR(255) NOT NULL, // Speichern der Daten in der config.php-Datei
image VARCHAR(255), $config_content = "<?php\n";
email VARCHAR(255) NOT NULL $config_content .= "\$host = '$host';\n";
)"; $config_content .= "\$username = '$username';\n";
if ($conn->query($sql_create_table) === TRUE) { $config_content .= "\$password = '$password';\n";
echo "<p>Tabelle 'materials' erfolgreich erstellt.</p>"; $config_content .= "\$database = '$database';\n";
$config_content .= "\$email = '$email';\n";
// Speichern der Daten in der config.php-Datei $config_content .= "\$notification_days = $notification_days;\n"; // Hinzugefügtes Feld für die Benachrichtigungstage
$config_content = "<?php\n"; $config_content .= "?>";
$config_content .= "\$host = '$host';\n";
$config_content .= "\$username = '$username';\n"; file_put_contents('config/config.php', $config_content);
$config_content .= "\$password = '$password';\n";
$config_content .= "\$database = '$database';\n"; // Weiterleitung zur Indexseite nach erfolgreicher Installation
$config_content .= "\$email = '$email';\n"; header("Location: index.php");
$config_content .= "?>"; exit();
} else {
file_put_contents('config/config.php', $config_content); echo "<p>Fehler beim Erstellen der Tabelle: " . $conn->error . "</p>";
}
// Weiterleitung zur Indexseite nach erfolgreicher Installation } else {
header("Location: index.php"); echo "<p>Fehler beim Erstellen der Datenbank: " . $conn->error . "</p>";
exit(); }
} else {
echo "<p>Fehler beim Erstellen der Tabelle: " . $conn->error . "</p>"; // Datenbankverbindung schließen
} $conn->close();
} else {
echo "<p>Fehler beim Erstellen der Datenbank: " . $conn->error . "</p>"; // Aktuellen Pfad ermitteln
} $current_path = getcwd();
// Datenbankverbindung schließen // Pfad zur PHP-Datei, die den Cron-Job ausführt
$conn->close(); $cron_script_path = $current_path . '/notification_cron.php';
}
?> // Crontab-Zeile erstellen (hier: Täglich um 13 Uhr)
$cron_job = '0 13 * * * /usr/bin/php ' . $cron_script_path;
<h2>Datenbankverbindung eingeben</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> // Crontab einrichten
<div class="form-group"> exec('crontab -l', $existing_cron_jobs); // Aktuelle Crontab abrufen
<label for="host">Host:</label> if (!in_array($cron_job, $existing_cron_jobs)) {
<input type="text" id="host" name="host" required> $existing_cron_jobs[] = $cron_job; // Neuen Cron-Job hinzufügen
</div> $new_cron_tab = implode("\n", $existing_cron_jobs); // Crontab zusammenführen
<div class="form-group"> file_put_contents('/tmp/crontab.txt', $new_cron_tab); // Temporäre Crontab-Datei erstellen
<label for="username">Benutzername:</label> exec('crontab /tmp/crontab.txt'); // Neue Crontab-Datei einrichten
<input type="text" id="username" name="username" required> unlink('/tmp/crontab.txt'); // Temporäre Crontab-Datei löschen
</div> }
<div class="form-group"> }
<label for="password">Passwort:</label> ?>
<input type="password" id="password" name="password" required>
</div> <!DOCTYPE html>
<div class="form-group"> <html lang="de">
<label for="database">Datenbankname:</label> <head>
<input type="text" id="database" name="database" required> <meta charset="UTF-8">
</div> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="form-group"> <link rel="stylesheet" type="text/css" href="css/install.css">
<label for="email">E-Mail-Adresse für Materialbenachrichtigungen:</label> <link rel="icon" href="img/favicon.png" type="image/x-icon">
<input type="email" id="email" name="email" required> <title>Viper Installer</title>
</div> </head>
<input type="submit" value="Installieren"> <body>
</form> <div class="container">
</div> <center><img src="img/logo.png" alt="Logo"></center>
</body> <center><h1>Installer</h1></center>
</html>
<h2>Datenbankverbindung eingeben</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="form-group">
<label for="host">Host:</label>
<input type="text" id="host" name="host" required>
</div>
<div class="form-group">
<label for="username">Benutzername:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Passwort:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="database">Datenbankname:</label>
<input type="text" id="database" name="database" required>
</div>
<div class="form-group">
<label for="email">E-Mail-Adresse für Benachrichtigungen:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="notification_days">Benachrichtigungstage vor Ablauf:</label> <!-- Neues Feld für Benachrichtigungstage -->
<input type="number" id="notification_days" name="notification_days" required>
</div>
<input type="submit" value="Installieren">
</form>
</div>
</body>
<span class="watermark">© copyright 2024 by M_Viper</span>
</html>