add php and perl scripts

Changed files
+66
+31
ask.php
···
+
<?php
+
+
// quick script to work as an endpoint for caddy on demand TLS
+
//
+
// all it does is connect with your application's DB and checks if the domain query matches a username
+
//
+
// if it matches, script returns 200. otherwise, 404
+
+
$query = $_GET['domain'];
+
+
$host = getenv('MYSQL_HOST');
+
$db = getenv('MYSQL_DATABASE');
+
$user = getenv('MYSQL_USER');
+
$pass = getenv('MYSQL_PASSWORD');
+
+
$conn = mysqli_connect($host, $user, $pass, $db);
+
+
$sql = $conn->prepare("SELECT user FROM user WHERE user = ?");
+
$sql->bind_param('s', $query);
+
$sql->execute();
+
+
$result = $sql->get_result();
+
+
if ($final = mysqli_fetch_assoc($result)) {
+
$name = $final["user"];
+
}
+
else {
+
header('HTTP/1.0 404 Not Found');
+
die();
+
}
+
?>
+35
list.pl
···
+
#!/usr/bin/perl
+
#
+
# newline-separated list of values from a mySQL database. used this with dreamwidth code
+
+
use DBI;
+
+
my $Client = HTTP::Tiny->new();
+
+
my $db = "x";
+
my $host = "x";
+
my $port = "3306";
+
+
my $dsn = "DBI:mysql:database=$db;host=$host;port=$port";
+
+
my $username = "x";
+
my $password = "x";
+
+
my %attr = ( PrintError=>0, # turn off error reporting via warn()
+
RaiseError=>1 # report error via die()
+
);
+
$dbh = DBI->connect($dsn, $username, $password, \%attr)
+
|| die "ERROR: $DBI::errstr";
+
+
$query = "SELECT user FROM user;";
+
$sth = $dbh->prepare($query);
+
$sth->execute();
+
$data = $sth->fetchall_arrayref();
+
$sth->finish;
+
+
foreach $data ( @$data) {
+
($name) = @$data;
+
print "$name\n";
+
}
+
+
$dbh->disconnect();