Initial commit

This commit is contained in:
2026-04-12 02:20:01 +02:00
commit 6c3e922080
8 changed files with 505 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
config.php

11
README.md Normal file
View File

@@ -0,0 +1,11 @@
# RFDB
The Radio Frequency Data Base.
## Quick start
Create a database named `rfdb`, then load the database template `rfdb.sql`
file into your database.
Rename the `config.php.example` file to `config.php`, then edit it according
to your database configuration.

13
config.php.example Normal file
View File

@@ -0,0 +1,13 @@
<?php
define("CONFIG_DB_DSN", "mysql:host=localhost;dbname=rfdb");
define("CONFIG_DB_USER", "username");
define("CONFIG_DB_PASSWORD", "password");
define("CONFIG_DB_OPTS", [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
]);
?>

34
db.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
require "config.php";
function db_connect(): PDO
{
static $pdo = null;
if ($pdo !== null) {
return $pdo;
}
try {
$pdo = new PDO(CONFIG_DB_DSN, CONFIG_DB_USER, CONFIG_DB_PASSWORD);
} catch (PDOException $e) {
exit("Errore connessione database: " . $e->getMessage());
}
return $pdo;
}
function db_query(string $query, array $params = []): array
{
$pdo = db_connect();
try {
$stmt = $pdo->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
} catch (PDOException $e) {
exit("Errore connessione database: " . $e->getMessage());
}
}
?>

120
frequenze.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
require "db.php";
session_start();
// Verify session
if (!isset($_SESSION["auth"])) {
header("Location: index.php");
exit;
}
// Logout request
if (isset($_GET["logout"])) {
session_destroy();
header("Location: index.php");
exit;
}
// Add frequency request
if (isset($_POST["add_freq"])) {
db_query("INSERT INTO frequenze"
. " (frequenza, nome, descrizione, modulazione, organizzazione)"
. " VALUES (?, ?, ?, ?, ?)",
[
$_POST["frequenza"], $_POST["nome"], $_POST["descrizione"],
$_POST["modulazione"] ?: null,
$_POST["organizzazione"] ?: null
]);
}
// Delete frequency request
if (isset($_POST["del_freq"])) {
db_query("DELETE FROM frequenze WHERE id = ?", [$_POST["id"]]);
}
// Get data
$frequenze = db_query(
"SELECT f.*, o.nome as org_nome, m.nome as mod_nome FROM frequenze f"
. " LEFT JOIN organizzazioni o ON f.organizzazione = o.id"
. " LEFT JOIN modulazioni m ON f.modulazione = m.id"
. " ORDER BY f.frequenza");
$organizzazioni = db_query("SELECT * FROM organizzazioni");
$modulazioni = db_query("SELECT * FROM modulazioni");
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>RFDB - Gestione</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<strong>RFDB MANAGER</strong> |
<a href="frequenze.php">Frequenze</a> |
<a href="?logout">Logout</a>
</nav>
<div class="form-box">
<h3>Aggiungi Nuova Frequenza</h3>
<form method="post">
Frequenza (MHz): <input type="number" step="any" name="frequenza" required>
Modulazione:
<select name="modulazione">
<option value="">Nessuna</option>
<?php foreach($modulazioni as $m): ?>
<option value="<?= $m["id"] ?>"><?= htmlspecialchars($m["nome"]) ?></option>
<?php endforeach; ?>
</select><br><br>
Nome: <input type="text" name="nome"><br><br>
Descrizione:<br>
<textarea name="descrizione" cols="40" rows="3"></textarea><br><br>
Organizzazione:
<select name="organizzazione">
<option value="">Nessuna</option>
<?php foreach($organizzazioni as $o): ?>
<option value="<?= $o["id"] ?>"><?= htmlspecialchars($o["nome"]) ?></option>
<?php endforeach; ?>
</select><br><br>
<button type="submit" name="add_freq">Salva Frequenza</button>
</form>
</div>
<h3>Elenco Frequenze Registrate</h3>
<table>
<thead>
<tr>
<th>MHz</th>
<th>Modulazione</th>
<th>Nome</th>
<th>Descrizione</th>
<th>Organizzazione</th>
<th>#</th>
</tr>
</thead>
<tbody>
<?php foreach ($frequenze as $f): ?>
<tr>
<td><strong><?= $f["frequenza"] ?></strong></td>
<td><?= htmlspecialchars($f["mod_nome"]) ?></td>
<td><?= htmlspecialchars($f["nome"]) ?></td>
<td><?= htmlspecialchars($f["descrizione"]) ?></td>
<td><?= htmlspecialchars($f["org_nome"] ?? "-") ?></td>
<td>
<form method="POST">
<input value="<?= $f["id"] ?>" name="id" hidden>
<button type="submit" name="del_freq">Elimina</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>

51
index.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
require "db.php";
session_start();
// If already logged in redirect
if (isset($_SESSION["auth"])) {
header("Location: frequenze.php");
exit();
}
// Login request
if (isset($_POST["login"]) && isset($_POST["username"]) && isset($_POST["password"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$users = db_query("SELECT id, password FROM utenti WHERE username = ?", [$username]);
if (!empty($users) && password_verify($password, $users[0]["password"])) {
$_SESSION["auth"] = $users[0]["id"];
header("Location: frequenze.php");
exit;
}
$error = "Credenziali errate!";
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>RFDB - Login</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<pre>
,--..Y
\ /`. R.F.D.B. Radio Frequency Data Base
A. \ Bassano del Grappa (VI)
_/ """--'
</pre>
<?php if (isset($error)) echo "<p style=\"color:red\">$error</p>"; ?>
<form method="POST">
Username: <input type="text" name="username" required><br>
Password: <input type="password" name="password" required><br><br>
<button type="submit" name="login">Login</button>
</form>
</body>
</html>

241
rfdb.sql Normal file
View File

@@ -0,0 +1,241 @@
/*M!999999\- enable the sandbox mode */
-- MariaDB dump 10.19-12.2.2-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: rfdb
-- ------------------------------------------------------
-- Server version 12.2.2-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*M!100616 SET @OLD_NOTE_VERBOSITY=@@NOTE_VERBOSITY, NOTE_VERBOSITY=0 */;
--
-- Table structure for table `frequenze`
--
DROP TABLE IF EXISTS `frequenze`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `frequenze` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`frequenza` double DEFAULT NULL,
`modulazione` int(10) unsigned DEFAULT NULL,
`nome` varchar(100) DEFAULT NULL,
`descrizione` text DEFAULT NULL,
`organizzazione` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `frequenze_organizzazioni_FK` (`organizzazione`),
KEY `frequenze_modulazioni_FK` (`modulazione`),
CONSTRAINT `frequenze_organizzazioni_FK` FOREIGN KEY (`organizzazione`) REFERENCES `organizzazioni` (`id`)
CONSTRAINT `frequenze_modulazioni_FK` FOREIGN KEY (`modulazione`) REFERENCES `modulazioni` (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `frequenze`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `frequenze` WRITE;
/*!40000 ALTER TABLE `frequenze` DISABLE KEYS */;
INSERT INTO `frequenze` VALUES
(1,446.00625,2,'PMR CH1','',NULL),
(2,446.01875,2,'PMR CH2','',NULL),
(3,446.03125,2,'PMR CH3','',NULL);
/*!40000 ALTER TABLE `frequenze` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `frequenze_utilizzatori`
--
DROP TABLE IF EXISTS `frequenze_utilizzatori`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `frequenze_utilizzatori` (
`frequenza` int(10) unsigned NOT NULL,
`utilizzatore` int(10) unsigned NOT NULL,
PRIMARY KEY (`frequenza`,`utilizzatore`),
KEY `frequenze_utilizzatori_utilizzatori_FK` (`utilizzatore`),
CONSTRAINT `frequenze_utilizzatori_frequenze_FK` FOREIGN KEY (`frequenza`) REFERENCES `frequenze` (`id`),
CONSTRAINT `frequenze_utilizzatori_utilizzatori_FK` FOREIGN KEY (`utilizzatore`) REFERENCES `utilizzatori` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `frequenze_utilizzatori`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `frequenze_utilizzatori` WRITE;
/*!40000 ALTER TABLE `frequenze_utilizzatori` DISABLE KEYS */;
/*!40000 ALTER TABLE `frequenze_utilizzatori` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `modulazioni`
--
DROP TABLE IF EXISTS `modulazioni`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `modulazioni` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`nome` char(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `modulazioni`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `modulazioni` WRITE;
/*!40000 ALTER TABLE `modulazioni` DISABLE KEYS */;
INSERT INTO `modulazioni` VALUES
(1,'WFM'),
(2,'NFM'),
(3,'DMR');
/*!40000 ALTER TABLE `modulazioni` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `organizzazioni`
--
DROP TABLE IF EXISTS `organizzazioni`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `organizzazioni` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`nome` varchar(100) DEFAULT NULL,
`descrizione` text DEFAULT NULL,
`area` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `organizzazioni`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `organizzazioni` WRITE;
/*!40000 ALTER TABLE `organizzazioni` DISABLE KEYS */;
/*!40000 ALTER TABLE `organizzazioni` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `organizzazioni_utilizzatori`
--
DROP TABLE IF EXISTS `organizzazioni_utilizzatori`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `organizzazioni_utilizzatori` (
`organizzazione` int(10) unsigned NOT NULL,
`utilizzatore` int(10) unsigned NOT NULL,
PRIMARY KEY (`organizzazione`,`utilizzatore`),
KEY `organizzazionei_utilizzatori_utilizzatori_FK` (`utilizzatore`),
CONSTRAINT `organizzazionei_utilizzatori_utilizzatori_FK` FOREIGN KEY (`utilizzatore`) REFERENCES `utilizzatori` (`id`),
CONSTRAINT `organizzazioni_utilizzatori_organizzazioni_FK` FOREIGN KEY (`organizzazione`) REFERENCES `organizzazioni` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `organizzazioni_utilizzatori`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `organizzazioni_utilizzatori` WRITE;
/*!40000 ALTER TABLE `organizzazioni_utilizzatori` DISABLE KEYS */;
/*!40000 ALTER TABLE `organizzazioni_utilizzatori` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `utenti`
--
DROP TABLE IF EXISTS `utenti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `utenti` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(100) DEFAULT NULL,
`password` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `utenti`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `utenti` WRITE;
/*!40000 ALTER TABLE `utenti` DISABLE KEYS */;
INSERT INTO `utenti` VALUES
(1,'admin','$2y$12$mWhaxVtCTMb2ozvglfDKLu8N3pqUcr57p3sFhG0PjpucsSB2EMmza');
/*!40000 ALTER TABLE `utenti` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
--
-- Table structure for table `utilizzatori`
--
DROP TABLE IF EXISTS `utilizzatori`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `utilizzatori` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`nome` varchar(100) DEFAULT NULL,
`identificativo` varchar(100) DEFAULT NULL,
`nickname` varchar(100) DEFAULT NULL,
`note` text DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `utilizzatori`
--
SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0;
LOCK TABLES `utilizzatori` WRITE;
/*!40000 ALTER TABLE `utilizzatori` DISABLE KEYS */;
/*!40000 ALTER TABLE `utilizzatori` ENABLE KEYS */;
UNLOCK TABLES;
COMMIT;
SET AUTOCOMMIT=@OLD_AUTOCOMMIT;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;
-- Dump completed on 2026-04-12 2:09:24

34
style.css Normal file
View File

@@ -0,0 +1,34 @@
body {
font-family: monospace;
background: #f0f0f0;
padding: 20px;
}
table {
border-collapse: collapse;
width: 100%;
background: white;
}
th, td {
border: 1px solid black;
padding: 5px;
text-align: left;
}
th {
background: #ccc;
}
.form-box {
border: 2px solid black;
padding: 10px;
margin-bottom: 20px;
background: #e0e0e0;
}
nav {
margin-bottom: 20px;
border-bottom: 2px solid black;
padding-bottom: 10px;
}