add php and perl scripts

Changed files
+66
+31
ask.php
··· 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 + 24 + if ($final = mysqli_fetch_assoc($result)) { 25 + $name = $final["user"]; 26 + } 27 + else { 28 + header('HTTP/1.0 404 Not Found'); 29 + die(); 30 + } 31 + ?>
+35
list.pl
··· 1 + #!/usr/bin/perl 2 + # 3 + # newline-separated list of values from a mySQL database. used this with dreamwidth code 4 + 5 + use DBI; 6 + 7 + my $Client = HTTP::Tiny->new(); 8 + 9 + my $db = "x"; 10 + my $host = "x"; 11 + my $port = "3306"; 12 + 13 + my $dsn = "DBI:mysql:database=$db;host=$host;port=$port"; 14 + 15 + my $username = "x"; 16 + my $password = "x"; 17 + 18 + my %attr = ( PrintError=>0, # turn off error reporting via warn() 19 + RaiseError=>1 # report error via die() 20 + ); 21 + $dbh = DBI->connect($dsn, $username, $password, \%attr) 22 + || die "ERROR: $DBI::errstr"; 23 + 24 + $query = "SELECT user FROM user;"; 25 + $sth = $dbh->prepare($query); 26 + $sth->execute(); 27 + $data = $sth->fetchall_arrayref(); 28 + $sth->finish; 29 + 30 + foreach $data ( @$data) { 31 + ($name) = @$data; 32 + print "$name\n"; 33 + } 34 + 35 + $dbh->disconnect();