summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/config.php13
-rw-r--r--web/index.php41
2 files changed, 54 insertions, 0 deletions
diff --git a/web/config.php b/web/config.php
new file mode 100644
index 0000000..eff0d0f
--- /dev/null
+++ b/web/config.php
@@ -0,0 +1,13 @@
+<?php
+
+$c = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . '/irclogs.ini', true);
+
+if (!isset($c['database'], $c['database']['driver'], $c['database']['name'], $c['database']['hostweb'], $c['database']['user'], $c['database']['pass'])) {
+ throw new RuntimeException("Database credentials must be set in irclogs.ini!");
+}
+
+define('DB_URL', "{$c['database']['driver']}:dbname={$c['database']['name']};host={$c['database']['hostweb']}");
+define('DB_USER', $c['database']['user']);
+define('DB_PASS', $c['database']['pass']);
+
+define('INSTANCE_NAME', $c['instance']['name'] ?: $_SERVER['HTTP_HOST']); \ No newline at end of file
diff --git a/web/index.php b/web/index.php
new file mode 100644
index 0000000..fd5246a
--- /dev/null
+++ b/web/index.php
@@ -0,0 +1,41 @@
+<?php
+include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php';
+
+$db = new PDO(DB_URL, DB_USER, DB_PASS);
+
+$stmt = $db->query('SELECT name FROM rooms ORDER BY joined_at, departed_at DESC');
+$stmt->execute();
+$rooms = $stmt->fetchAll(PDO::FETCH_ASSOC);
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title>Index - <?= INSTANCE_NAME ?></title>
+ <link rel="stylesheet" href="/static/style.css">
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
+</head>
+
+<body>
+ <?php if (isset($rooms)): ?>
+ <h1>Index of <?= INSTANCE_NAME ?></h1>
+ <?php if (empty($rooms)): ?>
+ <p>There are no rooms. <a href="/mod/">Add one!</a></p>
+ <?php else: ?>
+ <table>
+ <tr>
+ <th>Room</th>
+ <th>Last message</th>
+ </tr>
+ <?php foreach ($rooms as $r): ?>
+ <tr>
+ <td><a href="/?c=<?= $r['name'] ?>"><?= $r['name'] ?></a></td>
+ <td><?= '1 minute ago' ?></td>
+ </tr>
+ <?php endforeach; ?>
+ </table>
+ <?php endif; ?>
+ <?php endif; ?>
+</body>
+
+</html> \ No newline at end of file