Snap DynDNS Server enables you to set up your own easy and simple Dynamic DNS service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

109 lines
3.4 KiB

  1. <?php
  2. /***********************************************************************
  3. * Copyright (C) 2016 Max Mehl <mail [at] mehl [dot] mx>
  4. ************************************************************************
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public
  17. * License along with this program. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. ************************************************************************
  21. *
  22. * This file receives the requests, sanitises them, forwards the input
  23. * to update.sh and prints the results. It is also responsible for
  24. * debug logs.
  25. *
  26. ***********************************************************************/
  27. ?>
  28. <?php
  29. // check whether debuggging is activated (very unprofessional here, improvements welcome)
  30. $config = file_get_contents('config.cfg');
  31. $debug = preg_match("/DEBUG=true/", $config);
  32. if($debug === 1) {
  33. $debug = true;
  34. }
  35. else {
  36. $debug = false;
  37. }
  38. // if GET request is empty, use POST automatically
  39. if(empty($_GET)) {
  40. $method = "post";
  41. }
  42. // if a parameter is empty, set variable to false
  43. if($method === "post") {
  44. $domain = isset($_POST['domain']) ? $_POST['domain'] : false;
  45. $ip = isset($_POST['ip']) ? $_POST['ip'] : false;
  46. $user = isset($_POST['user']) ? $_POST['user'] : false;
  47. $pass = isset($_POST['pass']) ? $_POST['pass'] : false;
  48. }
  49. else {
  50. $domain = isset($_GET['domain']) ? $_GET['domain'] : false;
  51. $ip = isset($_GET['ip']) ? $_GET['ip'] : false;
  52. $user = isset($_GET['user']) ? $_GET['user'] : false;
  53. $pass = isset($_GET['pass']) ? $_GET['pass'] : false;
  54. }
  55. // if any variable is empty, throw an error, else proceed
  56. if(empty($domain) || empty($ip) || empty($user) || empty($pass)) {
  57. echo 'At least one variable is empty. You have to define domain, IP address, username and password';
  58. }
  59. else {
  60. // sanitise variables so we can protect our shell script
  61. $domain = escapeshellarg($domain);
  62. $ip = escapeshellarg($ip);
  63. $user = escapeshellarg($user);
  64. $pass = escapeshellarg($pass);
  65. // pass variables to update.sh and show output
  66. $command = '/bin/bash update.sh ' . $domain . ' ' . $ip . ' ' . $user . ' ' . $pass;
  67. $output = shell_exec($command);
  68. echo "<pre>$output</pre>";
  69. }
  70. // DEBUGGING
  71. if($debug === true) {
  72. $date = date("Y-m-d H:i:s");
  73. $browser = $_SERVER['HTTP_USER_AGENT'];
  74. $postdata = print_r($_POST, TRUE);
  75. $getdata = print_r($_GET, TRUE);
  76. $debug =
  77. // basic info
  78. '$date: ' . $date . '<br />' .
  79. '$browser: ' . $browser . '<br />' .
  80. '$debug: ' . $debug . '<br />' .
  81. '$method: ' . $method . '<br />' .
  82. // Specific set variables
  83. '$domain: ' . $domain . '<br />' .
  84. '$ip: ' . $ip . '<br />' .
  85. '$user: ' . $user . '<br />' .
  86. '$pass: ' . $pass . '<br />' .
  87. // all POST and GET
  88. '$postdata: ' . $postdata . '<br />' .
  89. '$getdata: ' . $getdata . '<br />'
  90. ;
  91. echo "<h2>Debug information:</h2>";
  92. print_r($debug); // Show debug in browser
  93. $debug_log = str_replace('<br />', "\r\n", $debug); //
  94. file_put_contents('debug.log', $debug_log, FILE_APPEND | LOCK_EX);
  95. }
  96. ?>