]> WPIA git - gigi.git/blob - doc/jenkinsJob/dyn-txt.php
UPD: rename dns-txt testdomain to "<string>._cacert._auth.domain.tld"
[gigi.git] / doc / jenkinsJob / dyn-txt.php
1 <?php
2 header("Content-type: text/plain");
3
4 define("ZONENAME", "cacert.dyn.dogcraft.de");
5 define("KEYNAME", "keys/Kcacert.dyn.dogcraft.de.+165+54687.key");
6
7 if(!isset($_GET['token']) || !isset($_GET['t1']) || !isset($_GET['t2']) || !isset($_GET['action'])){
8   die("Error");
9 }
10 if($_GET['token'] != "rD1m3A9ew6Hs4DIv7lnTxNbR6dr"){
11   die ();
12 }
13 $t1 = $_GET['t1'];
14 $t2 = $_GET['t2'];
15 if(!preg_match("/^[a-zA-Z0-9]+$/", $t1) || !preg_match("/^[a-zA-Z0-9]+$/", $t2)){
16   die("Error");
17 }
18 $todelete = array();
19
20 if(file_exists("data.php")){
21   include ("data.php");
22 }
23
24 $time = time()/60;
25 if(!isset($todelete[$time])){
26   $todelete[$time] = array();
27 }
28
29 $dnscalls = "";
30
31 if($_GET['action'] == "http"){
32   $todelete[$time][] = array("http", $t1);
33   file_put_contents("cacert-$t1.txt", $t2);
34 } else if($_GET['action'] == "dns") {
35   $todelete[$time][] = array("dns", $t1);
36   $dnscalls .= "update delete {$t1}._cacert._auth." . ZONENAME . " TXT\n"
37     ."update add {$t1}._cacert._auth." . ZONENAME . " 60 TXT {$t2}\n";
38 }
39 $copy = $todelete;
40 foreach($copy as $nt => $ar){
41   if($nt < $time - 2){
42     unset($todelete[$nt]);
43     foreach($ar as $act){
44       if($act[0] == "http"){
45         unlink("cacert-{$act[1]}.txt");
46       } else if($act[0] == "dns") {
47         $dnscalls .= "update delete {$act[1]}._cacert._auth." . ZONENAME . " TXT\n";
48       }
49     }
50   }
51 }
52 file_put_contents("data.php", "<?php \$todelete = ".var_export($todelete,true).";\n?>");
53
54 if($dnscalls != ""){
55   dnsAction($dnscalls);
56 }
57
58 function dnsAction($command) {
59   $call = "server localhost\n$command\nsend\nquit\n";
60
61   $nsupdate = popen("/usr/bin/nsupdate -k " . KEYNAME, 'w');
62   fwrite($nsupdate, $call);
63   $retval = pclose($nsupdate); // nsupdate doesn't return anything useful when called this way
64 }
65