padlister: init
This commit is contained in:
parent
72bac64809
commit
6887bae0a3
|
@ -35,6 +35,7 @@
|
|||
./modules/nginx.nix
|
||||
./modules/userdir.nix
|
||||
./modules/hedgedoc.nix
|
||||
./modules/padlist.nix
|
||||
./modules/postgres.nix
|
||||
./modules/wiki.nix
|
||||
./modules/ftp.nix
|
||||
|
|
49
modules/padlist.nix
Normal file
49
modules/padlist.nix
Normal file
|
@ -0,0 +1,49 @@
|
|||
# php pad lister tool written by jonas
|
||||
{ pkgs, config, lib, ... }:
|
||||
let
|
||||
domain = "list.pad.${config.fsr.domain}";
|
||||
in
|
||||
{
|
||||
services.phpfpm.pools.padlist = {
|
||||
user = "hedgedoc";
|
||||
group = "hedgedoc";
|
||||
settings = {
|
||||
"listen.owner" = config.services.nginx.user;
|
||||
"pm" = "dynamic";
|
||||
"pm.max_children" = 32;
|
||||
"pm.max_requests" = 500;
|
||||
"pm.start_servers" = 2;
|
||||
"pm.min_spare_servers" = 2;
|
||||
"pm.max_spare_servers" = 5;
|
||||
"php_admin_value[error_log]" = "stderr";
|
||||
"php_admin_flag[log_errors]" = true;
|
||||
"catch_workers_output" = true;
|
||||
};
|
||||
phpEnv."PATH" = lib.makeBinPath [ pkgs.php ];
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
virtualHosts.${domain} = {
|
||||
root = pkgs.callPackage ../pkgs/padlist { };
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations = {
|
||||
"= /" = {
|
||||
extraConfig = ''
|
||||
rewrite ^ /index.php;
|
||||
'';
|
||||
};
|
||||
"~ \.php$" = {
|
||||
extraConfig = ''
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:${config.services.phpfpm.pools.padlist.socket};
|
||||
fastcgi_index index.php;
|
||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||
include ${pkgs.nginx}/conf/fastcgi.conf;
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}
|
10
pkgs/padlist/default.nix
Normal file
10
pkgs/padlist/default.nix
Normal file
|
@ -0,0 +1,10 @@
|
|||
{ stdenvNoCC, ... }:
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "padlister";
|
||||
src = ./.;
|
||||
phases = [ "unpackPhase" "installPhase" ];
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp -r $src/index.php $out
|
||||
'';
|
||||
}
|
79
pkgs/padlist/index.php
Normal file
79
pkgs/padlist/index.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
|
||||
$host = '/run/postgresql';
|
||||
$dbname = 'hedgedoc';
|
||||
$user = 'hedgedoc';
|
||||
|
||||
try {
|
||||
$dbh = new PDO("pgsql:host=$host;dbname=$dbname", $user);
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
die();
|
||||
}
|
||||
|
||||
$query = 'SELECT "Notes".title, "Notes"."updatedAt", "Notes"."shortid", "Users".profile FROM "Notes" JOIN "Users" ON "Notes"."ownerId" = "Users".id WHERE permission = \'freely\' OR permission = \'editable\' OR permission = \'limited\' ORDER BY "Notes"."updatedAt" DESC';
|
||||
try {
|
||||
$stmt = $dbh->query($query);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
die();
|
||||
}
|
||||
|
||||
function formatDateString($stringDate)
|
||||
{
|
||||
$datetime = DateTime::createFromFormat('Y-m-d H:i:s.uP', $stringDate);
|
||||
$formattedDate = $datetime->format('d.m.Y H:i');
|
||||
return $formattedDate;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Pad lister</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<br><br>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Titel</th>
|
||||
<th>Owner</th>
|
||||
<th>Last edit</th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
foreach ($rows as $row) {
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://pad.staging.ifsr.de/<?= $row['shortid'] ?>"><?= $row['title'] ?></a>
|
||||
</td>
|
||||
<td>
|
||||
<?= json_decode($row['profile'])->username ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= formatDateString($row['updatedAt']) ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<br><br>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue