PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/ass8_portal/mojpoweradmin/inc/toolkit.inc.php

https://github.com/kitpz2/grupappz
PHP | 378 lines | 286 code | 46 blank | 46 comment | 35 complexity | 5062de2936d2c7eaceb23ab360e81342 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /* Poweradmin, a friendly web-based admin tool for PowerDNS.
  3. * See <https://rejo.zenger.nl/poweradmin> for more details.
  4. *
  5. * Copyright 2007, 2008 Rejo Zenger <rejo@zenger.nl>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. session_start();
  21. include_once("config-me.inc.php");
  22. if(!@include_once("config.inc.php"))
  23. {
  24. error( _('You have to create a config.inc.php!') );
  25. }
  26. /*************
  27. * Constants *
  28. *************/
  29. if (isset($_GET["start"])) {
  30. define('ROWSTART', (($_GET["start"] - 1) * $iface_rowamount));
  31. } else {
  32. define('ROWSTART', 0);
  33. }
  34. if (isset($_GET["letter"])) {
  35. define('LETTERSTART', $_GET["letter"]);
  36. $_SESSION["letter"] = $_GET["letter"];
  37. } elseif(isset($_SESSION["letter"])) {
  38. define('LETTERSTART', $_SESSION["letter"]);
  39. } else {
  40. define('LETTERSTART', "a");
  41. }
  42. $valid_tlds = array(
  43. "ac", "ad", "ae", "aero", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar",
  44. "arpa", "as", "asia", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be",
  45. "bf", "bg", "bh", "bi", "biz", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv",
  46. "bw", "by", "bz", "ca", "cat", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl",
  47. "cm", "cn", "co", "com", "coop", "cr", "cu", "cv", "cx", "cy", "cz", "de", "dj",
  48. "dk", "dm", "do", "dz", "ec", "edu", "ee", "eg", "er", "es", "et", "eu", "fi",
  49. "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gd", "ge", "gf", "gg", "gh", "gi",
  50. "gl", "gm", "gn", "gov", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", "hk",
  51. "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "im", "in", "info", "int", "io",
  52. "iq", "ir", "is", "it", "je", "jm", "jo", "jobs", "jp", "ke", "kg", "kh", "ki",
  53. "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr",
  54. "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mil", "mk",
  55. "ml", "mm", "mn", "mo", "mobi", "mp", "mq", "mr", "ms", "mt", "mu", "museum",
  56. "mv", "mw", "mx", "my", "mz", "na", "name", "nc", "ne", "net", "nf", "ng", "ni",
  57. "nl", "no", "np", "nr", "nu", "nz", "om", "org", "pa", "pe", "pf", "pg", "ph",
  58. "pk", "pl", "pm", "pn", "pr", "pro", "ps", "pt", "pw", "py", "qa", "re", "ro",
  59. "rs", "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk",
  60. "sl", "sm", "sn", "so", "sr", "st", "su", "sv", "sy", "sz", "tc", "td", "tel",
  61. "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tp", "tr", "travel",
  62. "tt", "tv", "tw", "tz", "ua", "ug", "uk", "um", "us", "uy", "uz", "va", "vc",
  63. "ve", "vg", "vi", "vn", "vu", "wf", "ws", "xn--0zwm56d", "xn--11b5bs3a9aj6g",
  64. "xn--80akhbyknj4f", "xn--9t4b11yi5a", "xn--deba0ad", "xn--g6w251d",
  65. "xn--hgbk6aj7f53bba", "xn--hlcj6aya9esc7a", "xn--jxalpdlp", "xn--kgbechtv",
  66. "xn--zckzah", "ye", "yt", "yu", "za", "zm", "zw");
  67. /* Database connection */
  68. require_once("database.inc.php");
  69. // Generates $db variable to access database.
  70. // Array of the available zone types
  71. $server_types = array("MASTER", "SLAVE", "NATIVE");
  72. // $rtypes - array of possible record types
  73. $rtypes = array('A', 'AAAA', 'CNAME', 'HINFO', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT');
  74. // If fancy records is enabled, extend this field.
  75. if($dns_fancy) {
  76. $rtypes[14] = 'URL';
  77. $rtypes[15] = 'MBOXFW';
  78. }
  79. // $template - array of records that will be applied when adding a new zone file
  80. $template = array(
  81. array(
  82. "name" => "##DOMAIN##",
  83. "type" => "SOA",
  84. "content" => "$dns_ns1 $dns_hostmaster 0",
  85. "ttl" => "$dns_ttl",
  86. "prio" => ""
  87. ),
  88. array(
  89. "name" => "##DOMAIN##",
  90. "type" => "NS",
  91. "content" => "$dns_ns1",
  92. "ttl" => "$dns_ttl",
  93. "prio" => ""
  94. ),
  95. array(
  96. "name" => "##DOMAIN##",
  97. "type" => "NS",
  98. "content" => "$dns_ns2",
  99. "ttl" => "$dns_ttl",
  100. "prio" => ""
  101. ),
  102. array(
  103. "name" => "www.##DOMAIN##",
  104. "type" => "A",
  105. "content" => "##WEBIP##",
  106. "ttl" => "$dns_ttl",
  107. "prio" => ""
  108. ),
  109. array(
  110. "name" => "##DOMAIN##",
  111. "type" => "A",
  112. "content" => "##WEBIP##",
  113. "ttl" => "$dns_ttl",
  114. "prio" => ""
  115. ),
  116. array(
  117. "name" => "mail.##DOMAIN##",
  118. "type" => "A",
  119. "content" => "##MAILIP##",
  120. "ttl" => "$dns_ttl",
  121. "prio" => ""
  122. ),
  123. array(
  124. "name" => "localhost.##DOMAIN##",
  125. "type" => "A",
  126. "content" => "127.0.0.1",
  127. "ttl" => "$dns_ttl",
  128. "prio" => ""
  129. ),
  130. array(
  131. "name" => "##DOMAIN##",
  132. "type" => "MX",
  133. "content" => "mail.##DOMAIN##",
  134. "ttl" => "$dns_ttl",
  135. "prio" => "10"
  136. )
  137. );
  138. /*************
  139. * Includes *
  140. *************/
  141. require_once("error.inc.php");
  142. require_once("auth.inc.php");
  143. require_once("i18n.inc.php");
  144. require_once("users.inc.php");
  145. require_once("dns.inc.php");
  146. require_once("record.inc.php");
  147. $db = dbConnect();
  148. doAuthenticate();
  149. /*************
  150. * Functions *
  151. *************/
  152. /*
  153. * Display the page option: [1] [2] .. [n]
  154. */
  155. function show_pages($amount,$rowamount,$id='')
  156. {
  157. if ($amount > $rowamount) {
  158. if (!isset($_GET["start"])) $_GET["start"]=1;
  159. echo _('Show page') . ":<br>";
  160. for ($i=1;$i<=ceil($amount / $rowamount);$i++) {
  161. if ($_GET["start"] == $i) {
  162. echo "[ <b>".$i."</b> ] ";
  163. } else {
  164. echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i;
  165. if ($id!='') echo "&id=".$id;
  166. echo "\">".$i."</a> ] ";
  167. }
  168. }
  169. }
  170. }
  171. /*
  172. * Display the alphabetic option: [0-9] [a] [b] .. [z]
  173. */
  174. function show_letters($letterstart,$userid=true)
  175. {
  176. echo _('Show zones beginning with') . ":<br>";
  177. $letter = "[[:digit:]]";
  178. if ($letterstart == "1")
  179. {
  180. echo "[ <span class=\"lettertaken\">0-9</span> ] ";
  181. }
  182. elseif (zone_letter_start($letter,$userid))
  183. {
  184. echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=1\">0-9</a> ] ";
  185. }
  186. else
  187. {
  188. echo "[ <span class=\"letternotavailble\">0-9</span> ] ";
  189. }
  190. foreach (range('a','z') as $letter)
  191. {
  192. if ($letter == $letterstart)
  193. {
  194. echo "[ <span class=\"lettertaken\">".$letter."</span> ] ";
  195. }
  196. elseif (zone_letter_start($letter,$userid))
  197. {
  198. echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] ";
  199. }
  200. else
  201. {
  202. echo "[ <span class=\"letternotavailble\">".$letter."</span> ] ";
  203. }
  204. }
  205. }
  206. function zone_letter_start($letter,$userid=true)
  207. {
  208. global $db;
  209. global $sql_regexp;
  210. $query = "SELECT
  211. domains.id AS domain_id,
  212. zones.owner,
  213. domains.name AS domainname
  214. FROM domains
  215. LEFT JOIN zones ON domains.id=zones.domain_id
  216. WHERE substring(domains.name,1,1) ".$sql_regexp." ".$db->quote("^".$letter, 'text');
  217. $db->setLimit(1);
  218. $result = $db->query($query);
  219. $numrows = $result->numRows();
  220. if ( $numrows == "1" ) {
  221. return 1;
  222. } else {
  223. return 0;
  224. }
  225. }
  226. function error($msg) {
  227. if ($msg) {
  228. echo " <div class=\"error\">Error: " . $msg . "</div>\n";
  229. } else {
  230. echo " <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n";
  231. }
  232. }
  233. function success($msg) {
  234. if ($msg) {
  235. echo " <div class=\"success\">" . $msg . "</div>\n";
  236. } else {
  237. echo " <div class=\"success\">" . _('Something has been successfully performed. What exactly, however, will remain a mystery.') . "</div>\n";
  238. }
  239. }
  240. /*
  241. * Something has been done nicely, display a message and a back button.
  242. */
  243. function message($msg)
  244. {
  245. include_once("header.inc.php");
  246. ?>
  247. <P><TABLE CLASS="messagetable"><TR><TD CLASS="message"><H2><?php echo _('Success!'); ?></H2>
  248. <BR>
  249. <FONT STYLE="font-weight: Bold">
  250. <P>
  251. <?php
  252. if($msg)
  253. {
  254. echo nl2br($msg);
  255. }
  256. else
  257. {
  258. echo _('Successful!');
  259. }
  260. ?>
  261. </P>
  262. <BR>
  263. <P>
  264. <a href="javascript:history.go(-1)">&lt;&lt; <?php echo _('back'); ?></a></FONT>
  265. </P>
  266. </TD></TR></TABLE></P>
  267. <?php
  268. include_once("footer.inc.php");
  269. }
  270. /*
  271. * Reroute a user to a cleanpage of (if passed) arg
  272. */
  273. function clean_page($arg='')
  274. {
  275. if (!$arg)
  276. {
  277. header("Location: ".$_SERVER["PHP_SELF"]."?time=".time());
  278. exit;
  279. }
  280. else
  281. {
  282. if (preg_match('!\?!si', $arg))
  283. {
  284. $add = "&time=";
  285. }
  286. else
  287. {
  288. $add = "?time=";
  289. }
  290. header("Location: $arg$add".time());
  291. exit;
  292. }
  293. }
  294. function get_status($res)
  295. {
  296. if ($res == '0')
  297. {
  298. return "<FONT CLASS=\"inactive\">" . _('Inactive') . "</FONT>";
  299. }
  300. elseif ($res == '1')
  301. {
  302. return "<FONT CLASS=\"active\">" . _('Active') . "</FONT>";
  303. }
  304. }
  305. function parse_template_value($val, $domain, $webip, $mailip)
  306. {
  307. $val = str_replace('##DOMAIN##', $domain, $val);
  308. $val = str_replace('##WEBIP##', $webip, $val);
  309. $val = str_replace('##MAILIP##', $mailip, $val);
  310. return $val;
  311. }
  312. function is_valid_email($address) {
  313. $fields = split("@", $address, 2);
  314. if((!eregi("^[0-9a-z]([-_.]?[0-9a-z])*$", $fields[0])) || !is_valid_hostname_fqdn($fields[1], 0)) {
  315. return false;
  316. }
  317. return true;
  318. }
  319. function v_num($string) {
  320. if (!eregi("^[0-9]+$", $string)) {
  321. return false ;
  322. } else {
  323. return true ;
  324. }
  325. }
  326. // Debug print
  327. function debug_print($var) {
  328. echo "<pre style=\"border: 2px solid blue;\">\n";
  329. if (is_array($var)) { print_r($var) ; } else { echo $var ; }
  330. echo "</pre>\n";
  331. }
  332. ?>