Alternc  latest
Alternc logiel libre pour l'hébergement
adm_deactivate.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  LICENSE
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License (GPL)
8  as published by the Free Software Foundation; either version 2
9  of the 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 General Public License for more details.
15 
16  To read the license please visit http://www.gnu.org/copyleft/gpl.html
17  ----------------------------------------------------------------------
18 */
19 
20 /**
21  * Page used by administrators to deactivate an account
22  * and redirect its domains
23  *
24  * @copyright AlternC-Team 2000-2017 https://alternc.com/
25  */
26 
27 require_once("../class/config.php");
28 
29 include_once("head.php");
30 
31 if (!$admin->enabled) {
32  $msg->raise("ERROR", "admin", _("This page is restricted to authorized staff"));
33  echo $msg->msg_html_all();
34  exit;
35 }
36 $fields = array (
37  "uid" => array ("request", "integer", ""),
38  "submit" => array ("post", "string", ""),
39  "redirect" => array ("post", "string", ""),
40 );
42 
43 if (!$uid) {
44  $msg->raise("ERROR", "admin", _("Account not found"));
45  echo $msg->msg_html_all();
46  include_once("foot.php");
47  exit();
48 }
49 
50 if (!$admin->checkcreator($uid)) {
51  $msg->raise("ERROR", "admin", _("This page is restricted to authorized staff"));
52  echo $msg->msg_html_all();
53  include_once("foot.php");
54  exit();
55 }
56 
57 if (!$r=$admin->get($uid)) {
58  $msg->raise("ERROR", "admin", _("User does not exist"));
59  echo $msg->msg_html_all();
60  include_once("foot.php");
61  exit();
62 }
63 
64 $confirmed = ($submit == _("Confirm"))?true:false;
65 
66 
67 if (! ($confirmed ) ) {
68  print '<h2>' . _('WARNING: experimental feature, use at your own risk') . '</h2>';
69  __("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.");
70 
71  ?>
72  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
73  <?php csrf_get(); ?>
74  <input type="hidden" name="uid" value="<?php ehe($uid); ?>" />
75  <?php __("Redirection URL:") ?> <input type="text" name="redirect" class="int" value="http://example.com/" />
76  <input type="submit" name="submit" class="inb" value="<?php __("Confirm")?>" />
77  <input type="button" class="inb" name="cancel" value="<?php __("Cancel"); ?>" onclick="document.location='adm_list.php'"/>
78  </form><?php
79 
80  print "<h3>" . _("Domains of user: ") . $r["login"] . "</h3>";
81 } else {
82  if (empty($redirect)) {
83  $msg->raise("ERROR", "admin", _("Missing redirect url."));
84  echo $msg->msg_html_all();
85  include_once("foot.php");
86  exit();
87  }
88 }
89 
90 // 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
91 $backup = "";
92 
93 # 1. list the domains of the user
94 # 1.1 list the domains
95 global $cuid;
97 $cuid = $uid;
98 $domains = $dom->enum_domains();
99 
100 if ($confirmed) {
101  print "<pre>";
102  printf(_("-- Redirecting all domains and subdomains of the user %s to %s\n"), $r['login'], $redirect);
103 }
104 
105 reset($domains);
106 # 1.2 foreach domain, list the subdomains
107 foreach ($domains as $key => $domain) {
108  if (!$confirmed) print '<h4>' . $domain . '</h4><ul>';
109  $dom->lock();
110  $r=$dom->get_domain_all($domain);
111  $dom->unlock();
112  # 2. for each subdomain
113  if (is_array($r['sub'])) {
114  foreach ($r['sub'] as $k => $sub) {
115 # shortcuts
116  $type = $sub['type'];
117  $dest = $sub['dest'];
118  $sub = $sub['name'];
119 # if it's a real website
120  if ($type == $dom->type_local) {
121  if (!$confirmed) {
122  print "<li>";
123  if ($sub) {
124  print $sub . '.';
125  }
126  print "$domain -> $dest</li>";
127  } else {
128 
129 # 2.1 keep a copy of where it was, in an SQL request
130  $backup .= "UPDATE `sub_domaines` SET `type`='$type', valeur='$dest',web_action='UPDATE' WHERE `domaine`='$domain' AND sub='$sub';\n";
131 
132 # 2.2 change the subdomain to redirect to http://spam.koumbit.org/
133  $dom->lock();
134  if (!$dom->set_sub_domain($domain, $sub, $dom->type_url, "edit", $redirect)) {
135  print "-- error in $sub.$domain: ";
136  echo $msg->msg_html("ERROR");
137  }
138  $dom->unlock();
139  }
140  }
141  }
142  }
143  if (!$confirmed) print '</ul>';
144 }
145 
146 # 3. wrap up (?)
147 if ($confirmed) {
148  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";
149  print $backup;
150  print "</pre>";
151 }
152 $cuid = $old_cuid;
153 
154 include_once("foot.php");
155 
156 ?>
157 
if(! $uid) if(! $admin->checkcreator($uid)) if(! $r=$admin->get($uid)) $confirmed
$domains
if(! $admin->enabled) $fields
Page used by administrators to deactivate an account and redirect its domains.
global $cuid
$old_cuid
exit
Definition: adm_doadd.php:70
$msg
Definition: bootstrap.php:75
$r
Definition: aws_add.php:75
$domain
Definition: dom_import.php:36
$sub
__($str)
Definition: functions.php:404
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
Definition: functions.php:688
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
Definition: functions.php:1159
print
Definition: mail_add.php:92
$uid
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
$dom
Definition: whois_test.php:10