]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/tools/yourls.nix
Add chatons infos
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / tools / yourls.nix
1 { env, yourls, yourls-plugins, config }:
2 rec {
3 activationScript = {
4 deps = [ "httpd" ];
5 text = ''
6 install -m 0755 -o ${apache.user} -g ${apache.group} -d /var/lib/php/sessions/yourls
7 '';
8 };
9 keys."webapps/tools-yourls" = {
10 user = apache.user;
11 group = apache.group;
12 permissions = "0400";
13 text = ''
14 <?php
15 define( 'YOURLS_DB_USER', '${env.mysql.user}' );
16 define( 'YOURLS_DB_PASS', '${env.mysql.password}' );
17 define( 'YOURLS_DB_NAME', '${env.mysql.database}' );
18 define( 'YOURLS_DB_HOST', '${env.mysql.host}' );
19 define( 'YOURLS_DB_PREFIX', 'yourls_' );
20 define( 'YOURLS_SITE', 'https://tools.immae.eu/url' );
21 define( 'YOURLS_HOURS_OFFSET', 0 );
22 define( 'YOURLS_LANG', ''' );
23 define( 'YOURLS_UNIQUE_URLS', true );
24 define( 'YOURLS_PRIVATE', true );
25 define( 'YOURLS_COOKIEKEY', '${env.cookieKey}' );
26 $yourls_user_passwords = array();
27 define( 'YOURLS_DEBUG', false );
28 define( 'YOURLS_URL_CONVERT', 36 );
29 $yourls_reserved_URL = array();
30 define( 'LDAPAUTH_HOST', 'ldaps://${env.ldap.host}' );
31 define( 'LDAPAUTH_PORT', '636' );
32 define( 'LDAPAUTH_BASE', '${env.ldap.base}' );
33 define( 'LDAPAUTH_SEARCH_USER', '${env.ldap.dn}' );
34 define( 'LDAPAUTH_SEARCH_PASS', '${env.ldap.password}' );
35
36 define( 'LDAPAUTH_GROUP_ATTR', 'memberof' );
37 define( 'LDAPAUTH_GROUP_REQ', 'cn=admin,cn=yourls,ou=services,dc=immae,dc=eu');
38
39 define( 'LDAPAUTH_USERCACHE_TYPE', 0);
40 '';
41 };
42 chatonsProperties = {
43 file.datetime = "2022-08-27T18:00:00";
44 service = {
45 name = "Yourls";
46 description = "Your own URL shortener";
47 website = "https://tools.immae.eu/url/admin/";
48 logo = "https://tools.immae.eu/url/images/favicon.gif";
49 status.level = "OK";
50 status.description = "OK";
51 registration."" = ["MEMBER" "CLIENT"];
52 registration.load = "FULL";
53 install.type = "PACKAGE";
54 };
55 software = {
56 name = "YOURLS";
57 website = "http://yourls.org/";
58 license.url = "https://github.com/YOURLS/YOURLS/blob/master/LICENSE";
59 license.name = "MIT License";
60 version = webRoot.version;
61 source.url = "https://github.com/YOURLS/YOURLS";
62 modules = map (a: a.pluginName) webRoot.plugins;
63 };
64 };
65 webRoot = (yourls.override { yourls_config = config.secrets.fullPaths."webapps/tools-yourls"; }).withPlugins (p: [p.ldap]);
66 apache = rec {
67 user = "wwwrun";
68 group = "wwwrun";
69 modules = [ "proxy_fcgi" ];
70 root = webRoot;
71 vhostConf = socket: ''
72 Alias /url "${root}"
73 <Directory "${root}">
74 <FilesMatch "\.php$">
75 SetHandler "proxy:unix:${socket}|fcgi://localhost"
76 </FilesMatch>
77
78 AllowOverride None
79 Require all granted
80 <IfModule mod_rewrite.c>
81 RewriteEngine On
82 RewriteBase /url/
83 RewriteCond %{REQUEST_FILENAME} !-f
84 RewriteCond %{REQUEST_FILENAME} !-d
85 RewriteRule ^.*$ /url/yourls-loader.php [L]
86 </IfModule>
87 DirectoryIndex index.php
88 </Directory>
89 '';
90 };
91 phpFpm = rec {
92 serviceDeps = [ "mysql.service" "openldap.service" ];
93 basedir = builtins.concatStringsSep ":" (
94 [ webRoot config.secrets.fullPaths."webapps/tools-yourls" ]
95 ++ webRoot.plugins);
96 pool = {
97 "listen.owner" = apache.user;
98 "listen.group" = apache.group;
99 "pm" = "ondemand";
100 "pm.max_children" = "60";
101 "pm.process_idle_timeout" = "60";
102
103 # Needed to avoid clashes in browser cookies (same domain)
104 "php_value[session.name]" = "YourlsPHPSESSID";
105 "php_admin_value[open_basedir]" = "${basedir}:/tmp:/var/lib/php/sessions/yourls";
106 "php_admin_value[session.save_path]" = "/var/lib/php/sessions/yourls";
107 };
108 };
109 }