submit.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. error_reporting(E_ALL);
  3. class FormException extends Exception {
  4. public function errorMessage() {
  5. $errorMsg = 'Wrong argument in form: ' . $this->getMessage();
  6. return $errorMsg;
  7. }
  8. }
  9. use PHPMailer\PHPMailer\PHPMailer;
  10. use PHPMailer\PHPMailer\Exception;
  11. require "../vendor/autoload.php";
  12. function check_arguments($arr) {
  13. foreach ($arr as $key) {
  14. if (! array_key_exists($key, $_POST)) {
  15. throw new FormException("Missing argument: " . $key);
  16. }
  17. }
  18. }
  19. sleep(10);
  20. ?><!DOCTYPE html>
  21. <html lang="en">
  22. <head>
  23. <meta charset="UTF-8">
  24. <title>Setup session</title>
  25. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  26. <meta name="robots" content="noindex, nofollow">
  27. <link rel="stylesheet" href="/assets/css/simple.min.css" integrity="sha384-RU21UwWLAoiCR1pUjxpW4YprCd2Pdvbi1kFN8QPxkI3gXdF5GrL+OH5GVg/Mvwa5">
  28. </head>
  29. <body>
  30. <header>
  31. <h1>Setup session</h1>
  32. </header>
  33. <main>
  34. <?php
  35. try {
  36. $passwd = rtrim(file_get_contents("../passwd.txt"), "\n");
  37. $required_arguments = [
  38. "request",
  39. "entity",
  40. "tunnel_type",
  41. "ipv6-ll",
  42. "email",
  43. "website",
  44. "location",
  45. "comments",
  46. "captcha"
  47. ];
  48. check_arguments($required_arguments);
  49. if ($_POST["request"] != "true") {
  50. throw new FormException("The form was sent incorrectly.");
  51. }
  52. if ($_POST["captcha"] != "42") {
  53. throw new FormException("Captcha incorrect!");
  54. }
  55. $entity = $_POST["entity"];
  56. $email = $_POST["email"];
  57. $tunneltype = $_POST["tunnel_type"];
  58. $message = "Hello,\n\nI would like to peer with you. The following are my details.\n\n";
  59. $message .= "Entity: entitydb/" . $entity . ".json\n";
  60. $message .= "E-Mail: " . $email . "\n";
  61. $message .= "Website: " . $_POST["website"] . "\n";
  62. $message .= "\n";
  63. $message .= "Tunnel type: ";
  64. switch ($tunneltype) {
  65. case "wireguard":
  66. $message .= "WireGuard";
  67. break;
  68. case "fastd":
  69. $message .= "fastd";
  70. break;
  71. case "openvpn":
  72. $message .= "OpenVPN";
  73. break;
  74. case "gre":
  75. $message .= "GRE";
  76. break;
  77. case "vxlan":
  78. $message .= "VXLAN";
  79. break;
  80. default:
  81. throw new FormException("Wrong tunnel type");
  82. break;
  83. }
  84. $message .= "\n";
  85. $message .= "Location: " . $_POST["location"] . "\n";
  86. $message .= "IPv6 link-local: " . $_POST["ipv6-ll"] . "\n";
  87. $message .= "\n";
  88. switch ($tunneltype) {
  89. case "wireguard":
  90. $required_arguments = [
  91. "wg-pubkey",
  92. "wg-psk",
  93. "wg-endpoint",
  94. "wg-keepalive"
  95. ];
  96. check_arguments($required_arguments);
  97. // $message .= "WireGuard\n=========\n";
  98. $message .= "WireGuard public key: " . $_POST["wg-pubkey"] . "\n";
  99. $message .= "WireGuard PSK: " . $_POST["wg-psk"] . "\n";
  100. $message .= "Keepalive: " . $_POST["wg-keepalive"] . "\n";
  101. $message .= "Endpoint: " . $_POST["wg-endpoint"] . "\n";
  102. break;
  103. case "fastd":
  104. $required_arguments = [
  105. "fastd-mode",
  106. "fastd-method",
  107. "fastd-pubkey",
  108. "fastd-endpoint"
  109. ];
  110. check_arguments($required_arguments);
  111. // $message .= "fastd\n=====\n";
  112. $message .= "Mode: ";
  113. switch ($_POST["fastd-mode"]) {
  114. case "tun":
  115. $message .= "TUN";
  116. break;
  117. case "tap":
  118. $message .= "TAP";
  119. break;
  120. default:
  121. throw new FormException("Wrong fastd mode");
  122. break;
  123. }
  124. $message .= "\n";
  125. $message .= "Method: " . $_POST["fastd-method"] . "\n";
  126. $message .= "Connection over: IPv6\n";
  127. $message .= "Public key: " . $_POST["fastd-pubkey"] . "\n";
  128. $message .= "Endpoint: " . $_POST["fastd-endpoint"] . "\n";
  129. break;
  130. case "openvpn":
  131. $required_arguments = [
  132. "openvpn-mode",
  133. "openvpn-proto",
  134. "openvpn-cipher",
  135. "openvpn-endpoint",
  136. "openvpn-port",
  137. "openvpn-keepalive",
  138. "openvpn-keepalive-to"
  139. ];
  140. check_arguments($required_arguments);
  141. // $message .= "OpenVPN\n=======\n";
  142. $message .= "Mode: P2P\n";
  143. $message .= "Protocol: UDP6\n";
  144. $message .= "Cipher: AES-256-CBC\n";
  145. $message .= "Endpoint: " . $_POST["openvpn-endpoint"] . "\n";
  146. $message .= "Port: " . $_POST["openvpn-port"] . "\n";
  147. $message .= "Keepalive: " . $_POST["openvpn-keepalive"] . "\n";
  148. $message .= "Keepalive timeout: " . $_POST["openvpn-keepalive-to"] . "\n";
  149. break;
  150. case "gre":
  151. $required_arguments = [
  152. "gre-endpoint",
  153. "gre-fou",
  154. "gre-fou-port"
  155. ];
  156. check_arguments($required_arguments);
  157. // $message .= "GRE\n===\n";
  158. $message .= "Endpoint: " . $_POST["gre-endpoint"] . "\n";
  159. $message .= "TTL: 255\n";
  160. $message .= "FOU: " . $_POST["gre-fou"] . "\n";
  161. $message .= "FOU port: " . $_POST["gre-fou-port"] . "\n";
  162. break;
  163. case "vxlan":
  164. $required_arguments = [
  165. "vxlan-endpoint",
  166. "vxlan-port",
  167. "vxlan-vni"
  168. ];
  169. check_arguments($required_arguments);
  170. // $message .= "VXLAN\n=====\n";
  171. $message .= "Endpoint: " . $_POST["vxlan-endpoint"] . "\n";
  172. $message .= "Port: " . $_POST["vxlan-port"] . "\n";
  173. $message .= "VNI: " . $_POST["vxlan-vni"] . "\n";
  174. break;
  175. }
  176. $message .= "\n";
  177. $message .= "Additional comments:\n";
  178. $message .= $_POST["comments"];
  179. $message .= "\n\n";
  180. $message .= "Greetings\n" . ucwords($entity);
  181. $mail = new PHPMailer;
  182. $mail->SMTPDebug = 0;
  183. $mail->isSMTP();
  184. $mail->Host = 'mxe87b.netcup.net';
  185. $mail->Username = 'crxn-peering-request-form@byeob.de';
  186. $mail->Password = $passwd;
  187. $mail->Port = 587;
  188. $mail->SMTPAuth = true;
  189. $mail->SMTPSecure = 'tls';
  190. $mail->From = 'crxn-peering-request-form@byeob.de';
  191. $mail->FromName = 'CRXN peering request form';
  192. $mail->addAddress('crxn@mk16.de');
  193. $mail->addReplyTo($replay, $entity);
  194. $mail->WordWrap = 50;
  195. $mail->isHTML(false);
  196. $mail->Subject = 'CRXN peering request';
  197. $mail->Body = $message;
  198. if(!$mail->send()) {
  199. echo 'The message could not be sent. Try again or send your request to crxn@mk16.de.<br>';
  200. echo 'Error: ' . $mail->ErrorInfo;
  201. } else {
  202. echo "Thank you for your inquiry! Your message has been sent.";
  203. }
  204. } catch (phpmailerException $e) {
  205. echo "The message could not be sent. Try again or send your request to crxn@mk16.de.<br>";
  206. echo "Error: " . $e->errorMessage();
  207. } catch (FormException $e) {
  208. echo "The message could not be sent. Try again or send your request to crxn@mk16.de.<br>";
  209. echo "Error: " . $e->errorMessage();
  210. } catch (Exception $e) {
  211. echo "The message could not be sent. Try again or send your request to crxn@mk16.de.<br>";
  212. echo "Error: " . $e->getMessage();}
  213. ?>
  214. </main>
  215. </body>
  216. </html>