| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: adm_tld.php,v 1.4 2004/11/29 17:27:04 anonymous Exp $ |
|---|
| 4 | ---------------------------------------------------------------------- |
|---|
| 5 | AlternC - Web Hosting System |
|---|
| 6 | Copyright (C) 2002 by the AlternC Development Team. |
|---|
| 7 | http://alternc.org/ |
|---|
| 8 | ---------------------------------------------------------------------- |
|---|
| 9 | Based on: |
|---|
| 10 | Valentin Lacambre's web hosting softwares: http://altern.org/ |
|---|
| 11 | ---------------------------------------------------------------------- |
|---|
| 12 | LICENSE |
|---|
| 13 | |
|---|
| 14 | This program is free software; you can redistribute it and/or |
|---|
| 15 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 16 | as published by the Free Software Foundation; either version 2 |
|---|
| 17 | of the License, or (at your option) any later version. |
|---|
| 18 | |
|---|
| 19 | This program is distributed in the hope that it will be useful, |
|---|
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | GNU General Public License for more details. |
|---|
| 23 | |
|---|
| 24 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 25 | ---------------------------------------------------------------------- |
|---|
| 26 | Original Author of file: Benjamin Sonntag |
|---|
| 27 | Purpose of file: Manage allowed TLD on the server |
|---|
| 28 | ---------------------------------------------------------------------- |
|---|
| 29 | */ |
|---|
| 30 | require_once("../class/config.php"); |
|---|
| 31 | |
|---|
| 32 | include_once("head.php"); |
|---|
| 33 | |
|---|
| 34 | $uid = $_GET['uid']; |
|---|
| 35 | if (!$uid) { |
|---|
| 36 | __("Missing uid"); |
|---|
| 37 | include_once("foot.php"); |
|---|
| 38 | exit(); |
|---|
| 39 | } |
|---|
| 40 | if (!$admin->enabled || !$admin->checkcreator($uid)) { |
|---|
| 41 | __("This page is restricted to authorized staff"); |
|---|
| 42 | include_once("foot.php"); |
|---|
| 43 | exit(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if (!$r=$admin->get($uid)) { |
|---|
| 47 | __("User does not exist"); |
|---|
| 48 | include_once("foot.php"); |
|---|
| 49 | exit(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (! ($confirmed = ($_GET['submit'] == _("Confirm")) ) ) { |
|---|
| 53 | print '<h2>' . _('WARNING: experimental feature, use at your own risk') . '</h2>'; |
|---|
| 54 | __("The following domains will be deactivated and redirected to the URL entered in the following box. A backup of the domain configuration will be displayed as a serie of SQL request that you can run to restore the current configuration if you want. Click confirm if you are sure you want to deactivate all this user's domains."); |
|---|
| 55 | |
|---|
| 56 | ?> |
|---|
| 57 | <form action="<?=$PHP_SELF?>" method="GET"> |
|---|
| 58 | <input type="hidden" name="uid" value="<?=$uid?>" /> |
|---|
| 59 | <? __("Redirection URL:") ?> <input type="text" name="redirect" value="http://example.com/" /> |
|---|
| 60 | <input type="submit" name="submit" value="<?=_("Confirm")?>" /> |
|---|
| 61 | </form><?php |
|---|
| 62 | |
|---|
| 63 | print "<h3>" . _("Domains of user: ") . $r["login"] . "</h3>"; |
|---|
| 64 | } else { |
|---|
| 65 | if (!$_GET['redirect']) { |
|---|
| 66 | __("Missing redirect url."); |
|---|
| 67 | include_once("foot.php"); |
|---|
| 68 | exit(); |
|---|
| 69 | } else { |
|---|
| 70 | $redirect = $_GET['redirect']; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | # this string will contain an SQL request that will be printed at the end of the process and that can be used to reload the old domain configuration |
|---|
| 75 | $backup = ""; |
|---|
| 76 | |
|---|
| 77 | # 1. list the domains of the user |
|---|
| 78 | # 1.1 list the domains |
|---|
| 79 | global $cuid; |
|---|
| 80 | $old_cuid = $cuid; |
|---|
| 81 | $cuid = $uid; |
|---|
| 82 | $domains = $dom->enum_domains(); |
|---|
| 83 | |
|---|
| 84 | if ($confirmed) { |
|---|
| 85 | print "<pre>"; |
|---|
| 86 | printf(_("-- Redirecting all domains and subdomains of the user %s to %s\n"), $r['login'], $redirect); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | reset($domains); |
|---|
| 90 | # 1.2 foreach domain, list the subdomains |
|---|
| 91 | foreach ($domains as $key => $domain) { |
|---|
| 92 | if (!$confirmed) print '<h4>' . $domain . '</h4><ul>'; |
|---|
| 93 | $dom->lock(); |
|---|
| 94 | if (!$r=$dom->get_domain_all($domain)) { |
|---|
| 95 | $error=$err->errstr(); |
|---|
| 96 | } |
|---|
| 97 | $dom->unlock(); |
|---|
| 98 | # 2. for each subdomain |
|---|
| 99 | foreach ($r['sub'] as $k => $sub) { |
|---|
| 100 | # shortcuts |
|---|
| 101 | $type = $sub['type']; |
|---|
| 102 | $dest = $sub['dest']; |
|---|
| 103 | $sub = $sub['name']; |
|---|
| 104 | # if it's a real website |
|---|
| 105 | if ($type == $dom->type_local) { |
|---|
| 106 | if (!$confirmed) { |
|---|
| 107 | print "<li>"; |
|---|
| 108 | if ($sub) { |
|---|
| 109 | print $sub . '.'; |
|---|
| 110 | } |
|---|
| 111 | print "$domain -> $dest</li>"; |
|---|
| 112 | } else { |
|---|
| 113 | |
|---|
| 114 | # 2.1 keep a copy of where it was, in an SQL request |
|---|
| 115 | $backup .= "UPDATE `sub_domaines` SET `type`='$type', valeur='$dest' WHERE `domaine`='$domain' AND sub='$sub';\n"; |
|---|
| 116 | $backup .= "DELETE FROM `sub_domaines_standby` WHERE domaine='$domain' and sub='$sub';\n"; |
|---|
| 117 | $backup .= "INSERT INTO sub_domaines_standby (compte,domaine,sub,valeur,type,action) values ('$cuid','$domain','$sub','$dest','$type',1);\n"; // UPDATE |
|---|
| 118 | |
|---|
| 119 | # 2.2 change the subdomain to redirect to http://spam.koumbit.org/ |
|---|
| 120 | $dom->lock(); |
|---|
| 121 | if (!$dom->set_sub_domain($domain, $sub, $dom->type_url, "edit", $redirect)) { |
|---|
| 122 | print "-- error in $sub.$domain: " . $err->errstr() . "\n"; |
|---|
| 123 | } |
|---|
| 124 | $dom->unlock(); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | if (!$confirmed) print '</ul>'; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | # 3. wrap up (?) |
|---|
| 132 | if ($confirmed) { |
|---|
| 133 | print "-- The following is a serie of SQL request you can run, as root, to revert the user's domains to their previous state.\n"; |
|---|
| 134 | print $backup; |
|---|
| 135 | print "</pre>"; |
|---|
| 136 | } |
|---|
| 137 | $cuid = $old_cuid; |
|---|
| 138 | |
|---|
| 139 | include_once("foot.php"); |
|---|
| 140 | |
|---|
| 141 | ?> |
|---|
| 142 | |
|---|