misc scripts & programs
1<?php
2
3// quick script to work as an endpoint for caddy on demand TLS
4//
5// all it does is connect with your application's DB and checks if the domain query matches a username
6//
7// if it matches, script returns 200. otherwise, 404
8
9$query = $_GET['domain'];
10
11$host = getenv('MYSQL_HOST');
12$db = getenv('MYSQL_DATABASE');
13$user = getenv('MYSQL_USER');
14$pass = getenv('MYSQL_PASSWORD');
15
16$conn = mysqli_connect($host, $user, $pass, $db);
17
18$sql = $conn->prepare("SELECT user FROM user WHERE user = ?");
19$sql->bind_param('s', $query);
20$sql->execute();
21
22$result = $sql->get_result();
23
24if ($final = mysqli_fetch_assoc($result)) {
25 $name = $final["user"];
26}
27else {
28 header('HTTP/1.0 404 Not Found');
29 die();
30}
31?>