2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 require_once("../includes/loggedin.php");
23 $type=""; if(array_key_exists('type',$_REQUEST)) $type=$_REQUEST['type'];
24 $action=""; if(array_key_exists('action',$_REQUEST)) $action=sanitizeHTML($_REQUEST['action']);
26 if($type == "reallyemail")
28 $emailid = intval($_SESSION['_config']['emailid']);
29 $hash = mysql_escape_string(trim($_SESSION['_config']['hash']));
31 $res = mysql_query("select * from `disputeemail` where `id`='$emailid' and `hash`='$hash'");
32 if(mysql_num_rows($res) <= 0)
34 showheader(_("Email Dispute"));
35 echo _("This dispute no longer seems to be in the database, can't continue.");
39 $row = mysql_fetch_assoc($res);
40 $oldmemid = $row['oldmemid'];
42 if($action == "reject")
44 mysql_query("update `disputeemail` set hash='',action='reject' where `id`='".intval($emailid)."'");
45 showheader(_("Email Dispute"));
46 echo _("You have opted to reject this dispute and the request will be removed from the database");
50 if($action == "accept")
52 showheader(_("Email Dispute"));
53 echo "<p>"._("You have opted to accept this dispute and the request will now remove this email address from the existing account, and revoke any current certificates.")."</p>";
54 echo "<p>"._("The following accounts have been removed:")."<br>\n";
55 $query = "select * from `email` where `id`='".intval($emailid)."' and deleted=0";
56 $res = mysql_query($query);
57 if(mysql_num_rows($res) > 0)
59 $row = mysql_fetch_assoc($res);
60 echo $row['email']."<br>\n";
61 $query = "select `emailcerts`.`id`
62 from `emaillink`,`emailcerts` where
63 `emailid`='$emailid' and `emaillink`.`emailcertsid`=`emailcerts`.`id` and
64 `revoked`=0 and UNIX_TIMESTAMP(`expire`)-UNIX_TIMESTAMP() > 0
65 group by `emailcerts`.`id`";
66 $dres = mysql_query($query);
67 while($drow = mysql_fetch_assoc($dres))
68 mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($drow['id'])."'");
70 $do = `
../scripts
/runclient`
;
71 $query = "update `email` set `deleted`=NOW() where `id`='".intval($emailid)."'";
74 mysql_query("update `disputeemail` set hash='',action='accept' where `id`='$emailid'");
75 $rc = mysql_num_rows(mysql_query("select * from `domains` where `memid`='$oldmemid' and `deleted`=0"));
76 $rc = mysql_num_rows(mysql_query("select * from `email` where `memid`='$oldmemid' and `deleted`=0 and `id`!='$emailid'"));
77 $res = mysql_query("select * from `users` where `id`='$oldmemid'");
78 $user = mysql_fetch_assoc($res);
79 if($rc == 0 && $rc2 == 0 && $_SESSION['_config']['email'] == $user['email'])
81 mysql_query("update `users` set `deleted`=NOW() where `id`='$oldmemid'");
82 echo _("This was the primary email on the account, and no emails or domains were left linked so the account has also been removed from the system.");
92 $emailid = intval($_REQUEST['emailid']);
93 $hash = trim(mysql_escape_string(stripslashes($_REQUEST['hash'])));
94 if($emailid <= 0 ||
$hash == "")
96 showheader(_("Email Dispute"));
97 echo _("Invalid request. Can't continue.");
102 $res = mysql_query("select * from `disputeemail` where `id`='$emailid' and `hash`='$hash'");
103 if(mysql_num_rows($res) <= 0)
105 $res = mysql_query("select * from `disputeemail` where `id`='$emailid' and hash!=''");
106 if(mysql_num_rows($res) > 0)
108 $row = mysql_fetch_assoc($res);
109 mysql_query("update `disputeemail` set `attempts`='".intval($row['attempts'] +
1)."' where `id`='".$row['id']."'");
110 showheader(_("Email Dispute"));
111 if($row['attempts'] >= 3)
113 echo _("Your attempt to accept or reject a disputed email is invalid due to the hash string not matching with the email ID. Your attempt has been logged and the request will be removed from the system as a result.");
114 mysql_query("update `disputeemail` set hash='',action='failed' where `id`='$emailid'");
116 echo _("Your attempt to accept or reject a disputed email is invalid due to the hash string not matching with the email ID.");
120 showheader(_("Email Dispute"));
121 echo _("Invalid request. Can't continue.");
126 $_SESSION['_config']['emailid'] = $emailid;
127 $_SESSION['_config']['hash'] = $hash;
128 $row = mysql_fetch_assoc(mysql_query("select * from `disputeemail` where `id`='$emailid'"));
129 $_SESSION['_config']['email'] = $row['email'];
130 showheader(_("Email Dispute"));
131 includeit("4", "disputes");
136 if($type == "reallydomain")
138 $domainid = intval($_SESSION['_config']['domainid']);
139 $hash = mysql_escape_string(trim($_SESSION['_config']['hash']));
141 $res = mysql_query("select * from `disputedomain` where `id`='$domainid' and `hash`='$hash'");
142 if(mysql_num_rows($res) <= 0)
144 showheader(_("Domain Dispute"));
145 echo _("This dispute no longer seems to be in the database, can't continue.");
150 if($action == "reject")
152 mysql_query("update `disputedomain` set hash='',action='reject' where `id`='$domainid'");
153 showheader(_("Domain Dispute"));
154 echo _("You have opted to reject this dispute and the request will be removed from the database");
158 if($action == "accept")
160 showheader(_("Domain Dispute"));
161 echo "<p>"._("You have opted to accept this dispute and the request will now remove this domain from the existing account, and revoke any current certificates.")."</p>";
162 echo "<p>"._("The following accounts have been removed:")."<br>\n";
163 $query = "select * from `domains` where `id`='$domainid' and deleted=0";
164 $res = mysql_query($query);
165 if(mysql_num_rows($res) > 0)
167 echo $_SESSION['_config']['domain']."<br>\n";
168 mysql_query("update `domains` set `deleted`=NOW() where `id`='$domainid'");
169 $query = "select * from `domlink` where `domid`='$domainid'";
170 $res = mysql_query($query);
171 while($row = mysql_fetch_assoc($res))
172 mysql_query("update `domaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".$row['certid']."' and `revoked`=0 and UNIX_TIMESTAMP(`expire`)-UNIX_TIMESTAMP() > 0");
173 $do = `
../scripts
/runserver`
;
175 mysql_query("update `disputedomain` set hash='',action='accept' where `id`='$domainid'");
181 if($type == "domain")
183 $domainid = intval($_REQUEST['domainid']);
184 $hash = trim(mysql_escape_string(stripslashes($_REQUEST['hash'])));
185 if($domainid <= 0 ||
$hash == "")
187 showheader(_("Domain Dispute"));
188 echo _("Invalid request. Can't continue.");
193 $res = mysql_query("select * from `disputedomain` where `id`='$domainid' and `hash`='$hash'");
194 if(mysql_num_rows($res) <= 0)
196 $res = mysql_query("select * from `disputedomain` where `id`='$domainid' and hash!=''");
197 if(mysql_num_rows($res) > 0)
199 $row = mysql_fetch_assoc($res);
200 mysql_query("update `disputedomain` set `attempts`='".intval($row['attempts'] +
1)."' where `id`='".$row['id']."'");
201 showheader(_("Domain Dispute"));
202 if($row['attempts'] >= 3)
204 echo _("Your attempt to accept or reject a disputed domain is invalid due to the hash string not matching with the domain ID. Your attempt has been logged and the request will be removed from the system as a result.");
205 mysql_query("update `disputedomain` set hash='',action='failed' where `id`='$domainid'");
207 echo _("Your attempt to accept or reject a disputed domain is invalid due to the hash string not matching with the domain ID.");
211 showheader(_("Domain Dispute"));
212 echo _("Invalid request. Can't continue.");
217 $_SESSION['_config']['domainid'] = $domainid;
218 $_SESSION['_config']['hash'] = $hash;
219 $row = mysql_fetch_assoc(mysql_query("select * from `disputedomain` where `id`='$domainid'"));
220 $_SESSION['_config']['domain'] = $row['domain'];
221 showheader(_("Domain Dispute"));
222 includeit("6", "disputes");
229 csrf_check('emaildispute');
230 $email = trim(mysql_escape_string(stripslashes($_REQUEST['dispute'])));
233 showheader(_("Email Dispute"));
234 echo _("Not a valid email address. Can't continue.");
239 //check if email belongs to locked account
240 $res = mysql_query("select 1 from `email`, `users` where `email`.`email`='$email' and `email`.`memid`=`users`.`id` and (`users`.`assurer_blocked`=1 or `users`.`locked`=1)");
241 if(mysql_num_rows($res) > 0)
243 showheader(_("Email Dispute"));
244 printf(_("Sorry, the email address '%s' cannot be disputed for administrative reasons. To solve this problem please get in contact with %s."), sanitizeHTML($email),"<a href='mailto:support@cacert.org'>support@cacert.org</a>");
245 $duser=$_SESSION['profile']['fname']." ".$_SESSION['profile']['lname'];
246 $body = sprintf("Someone has just attempted to dispute this email '%s', which belongs to a locked account:\n".
247 "Username(ID): %s (%s)\n".
249 "IP/Hostname: %s\n", $email, $duser, $_SESSION['profile']['id'], $_SESSION['profile']['email'], $_SERVER['REMOTE_ADDR'].(array_key_exists('REMOTE_HOST',$_SERVER)?
"/".$_SERVER['REMOTE_HOST']:""));
250 sendmail("support@cacert.org", "[CAcert.org] failed dispute on locked account", $body, $_SESSION['profile']['email'], "", "", $duser);
256 $res = mysql_query("select * from `disputeemail` where `email`='$email' and hash!=''");
257 if(mysql_num_rows($res) > 0)
259 showheader(_("Email Dispute"));
260 printf(_("The email address '%s' already exists in the dispute system. Can't continue."), sanitizeHTML($email));
266 $query = "select * from `email` where `email`='$email' and `deleted`=0";
267 $res = mysql_query($query);
268 if(mysql_num_rows($res) <= 0)
270 showheader(_("Email Dispute"));
271 printf(_("The email address '%s' doesn't exist in the system. Can't continue."), sanitizeHTML($email));
275 $row = mysql_fetch_assoc($res);
276 $oldmemid = $row['memid'];
277 $emailid = $row['id'];
278 if($_SESSION['profile']['id'] == $oldmemid)
280 showheader(_("Email Dispute"));
281 echo _("You aren't allowed to dispute your own email addresses. Can't continue.");
286 $res = mysql_query("select * from `users` where `id`='$oldmemid'");
287 $user = mysql_fetch_assoc($res);
288 $rc = mysql_num_rows(mysql_query("select * from `domains` where `memid`='$oldmemid' and `deleted`=0"));
289 $rc2 = mysql_num_rows(mysql_query("select * from `email` where `memid`='$oldmemid' and `deleted`=0 and `id`!='$emailid'"));
290 if($user['email'] == $email && ($rc > 0 ||
$rc2 > 0))
292 showheader(_("Email Dispute"));
293 echo _("You only dispute the primary email address of an account if there is no longer any email addresses or domains linked to it.");
299 $query = "insert into `disputeemail` set `email`='$email',`memid`='".intval($_SESSION['profile']['id'])."',
300 `oldmemid`='$oldmemid',`created`=NOW(),`hash`='$hash',`id`='".intval($emailid)."',
301 `IP`='".$_SERVER['REMOTE_ADDR']."'";
304 $body = sprintf(_("You have been sent this email as the email address '%s' is being disputed. You have the option to accept or reject this request, after 2 days the request will automatically be discarded. Click the following link to accept or reject the dispute:"), $email)."\n\n";
305 $body .= "https://".$_SESSION['_config']['normalhostname']."/disputes.php?type=email&emailid=$emailid&hash=$hash\n\n";
306 $body .= _("Best regards")."\n"._("CAcert.org Support!");
308 sendmail($email, "[CAcert.org] "._("Dispute Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
310 showheader(_("Email Dispute"));
311 printf(_("The email address '%s' has been entered into the dispute system, the email address will now be sent an email which will give the recipent the option of accepting or rejecting the request, if after 2 days we haven't received a valid response for or against we will discard the request."), sanitizeHTML($email));
318 csrf_check('domaindispute');
319 $domain = trim(mysql_escape_string(stripslashes($_REQUEST['dispute'])));
322 showheader(_("Domain Dispute"));
323 echo _("Not a valid Domain. Can't continue.");
328 //check if domain belongs to locked account
329 $res = mysql_query("select 1 from `domains`, `users` where `domains`.`domain`='$domain' and `domains`.`memid`=`users`.`id` and (`users`.`assurer_blocked`=1 or `users`.`locked`=1)");
330 if(mysql_num_rows($res) > 0)
332 showheader(_("Domain Dispute"));
333 printf(_("Sorry, the domain '%s' cannot be disputed for administrative reasons. To solve this problem please get in contact with %s."), sanitizeHTML($domain),"<a href='mailto:support@cacert.org'>support@cacert.org</a>");
334 $duser=$_SESSION['profile']['fname']." ".$_SESSION['profile']['lname'];
335 $body = sprintf("Someone has just attempted to dispute this domain '%s', which belongs to a locked account:\n".
336 "Username(ID): %s (%s)\n".
338 "IP/Hostname: %s\n", $domain, $duser, $_SESSION['profile']['id'], $_SESSION['profile']['email'], $_SERVER['REMOTE_ADDR'].(array_key_exists('REMOTE_HOST',$_SERVER)?
"/".$_SERVER['REMOTE_HOST']:""));
339 sendmail("support@cacert.org", "[CAcert.org] failed dispute on locked account", $body, $_SESSION['profile']['email'], "", "", $duser);
345 $query = "select * from `disputedomain` where `domain`='$domain' and hash!=''";
346 $res = mysql_query($query);
347 if(mysql_num_rows($res) > 0)
349 showheader(_("Domain Dispute"));
350 printf(_("The domain '%s' already exists in the dispute system. Can't continue."), sanitizeHTML($domain));
355 $query = "select * from `domains` where `domain`='$domain' and `deleted`=0";
356 $res = mysql_query($query);
357 if(mysql_num_rows($res) <= 0)
359 $query = "select 1 from `orgdomains` where `domain`='$domain'";
360 $res = mysql_query($query);
361 if(mysql_num_rows($res) > 0)
363 showheader(_("Domain Dispute"));
364 printf(_("The domain '%s' is included in an organisation account. Please send a mail to %s to dispute this domain."), sanitizeHTML($domain),'<a href="mailto:support@cacert.org">support@cacert.org</a>');
368 showheader(_("Domain Dispute"));
369 printf(_("The domain '%s' doesn't exist in the system. Can't continue."), sanitizeHTML($domain));
373 $row = mysql_fetch_assoc($res);
374 $oldmemid = $row['memid'];
375 if($_SESSION['profile']['id'] == $oldmemid)
377 showheader(_("Domain Dispute"));
378 echo _("You aren't allowed to dispute your own domains. Can't continue.");
383 $domainid = $row['id'];
384 $_SESSION['_config']['domainid'] = $domainid;
385 $_SESSION['_config']['memid'] = array_key_exists('memid',$_REQUEST)?
intval($_REQUEST['memid']):0;
386 $_SESSION['_config']['domain'] = $domain;
387 $_SESSION['_config']['oldmemid'] = $oldmemid;
390 $domtmp = escapeshellarg($domain);
391 if(strtolower(substr($domtmp, -4, 3)) != ".jp")
392 $adds = explode("\n", trim(`whois
$domtmp|grep \
@`
));
393 if(substr($domain, -4) == ".org" ||
substr($domain, -5) == ".info")
396 foreach($adds as $line)
398 $bits = explode(":", $line, 2);
399 $line = trim($bits[1]);
400 if(!in_array($line, $addy) && $line != "")
401 $addy[] = trim(mysql_escape_string(stripslashes($line)));
405 foreach($adds as $line)
407 $line = trim(str_replace("\t", " ", $line));
408 $line = trim(str_replace("(", "", $line));
409 $line = trim(str_replace(")", " ", $line));
411 $bits = explode(" ", $line);
412 foreach($bits as $bit)
414 if(strstr($bit, "@"))
417 if(!in_array($line, $addy) && $line != "")
418 $addy[] = trim(mysql_escape_string(stripslashes($line)));
422 $rfc = array("root@$domain", "hostmaster@$domain", "postmaster@$domain", "admin@$domain", "webmaster@$domain");
423 foreach($rfc as $sub)
424 if(!in_array($sub, $addy))
426 $_SESSION['_config']['addy'] = $addy;
427 showheader(_("Domain Dispute"));
428 includeit("5", "disputes");
435 $authaddy = trim(mysql_escape_string(stripslashes($_REQUEST['authaddy'])));
437 if(!in_array($authaddy, $_SESSION['_config']['addy']) ||
$authaddy == "")
439 showheader(_("My CAcert.org Account!"));
440 echo _("The address you submitted isn't a valid authority address for the domain.");
445 $query = "select * from `domains` where `domain`='".$_SESSION['_config']['domain']."' and `deleted`=0";
446 $res = mysql_query($query);
447 if(mysql_num_rows($res) <= 0)
449 showheader(_("Domain Dispute!"));
450 printf(_("The domain '%s' isn't in the system. Can't continue."), sanitizeHTML($_SESSION['_config']['domain']));
455 $domainid = intval($_SESSION['_config']['domainid']);
456 $memid = intval($_SESSION['_config']['memid']);
457 $oldmemid = intval($_SESSION['_config']['oldmemid']);
458 $domain = mysql_escape_string($_SESSION['_config']['domain']);
461 $query = "insert into `disputedomain` set `domain`='$domain',`memid`='".$_SESSION['profile']['id']."',
462 `oldmemid`='$oldmemid',`created`=NOW(),`hash`='$hash',`id`='$domainid'";
465 $body = sprintf(_("You have been sent this email as the domain '%s' is being disputed. You have the option to accept or reject this request, after 2 days the request will automatically be discarded. Click the following link to accept or reject the dispute:"), $domain)."\n\n";
466 $body .= "https://".$_SESSION['_config']['normalhostname']."/disputes.php?type=domain&domainid=$domainid&hash=$hash\n\n";
467 $body .= _("Best regards")."\n"._("CAcert.org Support!");
469 sendmail($authaddy, "[CAcert.org] "._("Dispute Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
471 showheader(_("Domain Dispute"));
472 printf(_("The domain '%s' has been entered into the dispute system, the email address you choose will now be sent an email which will give the recipent the option of accepting or rejecting the request, if after 2 days we haven't received a valid response for or against we will discard the request."), sanitizeHTML($domain));
477 showheader(_("Domain and Email Disputes"));
478 includeit($id, "disputes");