cacert-webdb/www/disputes.php

436 lines
18 KiB
PHP
Raw Normal View History

2005-03-12 19:40:24 +00:00
<? /*
2008-04-06 19:45:09 +00:00
LibreSSL - CAcert web application
Copyright (C) 2004-2008 CAcert Inc.
2005-03-12 19:40:24 +00:00
2008-04-06 19:45:09 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
2005-03-12 19:40:24 +00:00
2008-04-06 19:45:09 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2005-03-12 19:40:24 +00:00
2008-04-06 19:45:09 +00:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2005-03-12 19:40:24 +00:00
*/ ?>
<?
require_once("../includes/loggedin.php");
loadem("account");
2008-09-01 22:06:26 +00:00
$type=""; if(array_key_exists('type',$_REQUEST)) $type=$_REQUEST['type'];
2005-03-12 19:40:24 +00:00
if($type == "reallyemail")
{
$emailid = intval($_SESSION['_config']['emailid']);
$hash = mysql_escape_string(trim($_SESSION['_config']['hash']));
$res = mysql_query("select * from `disputeemail` where `id`='$emailid' and `hash`='$hash'");
if(mysql_num_rows($res) <= 0)
{
showheader(_("Email Dispute"));
echo _("This dispute no longer seems to be in the database, can't continue.");
showfooter();
exit;
}
$row = mysql_fetch_assoc($res);
$oldmemid = $row['oldmemid'];
if($action == "reject")
{
2008-09-03 18:36:33 +00:00
mysql_query("update `disputeemail` set hash='',action='reject' where `id`='".intval($emailid)."'");
2005-03-12 19:40:24 +00:00
showheader(_("Email Dispute"));
echo _("You have opted to reject this dispute and the request will be removed from the database");
showfooter();
exit;
}
if($action == "accept")
{
showheader(_("Email Dispute"));
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>";
echo "<p>"._("The following accounts have been removed:")."<br>\n";
2008-09-03 18:36:33 +00:00
$query = "select * from `email` where `id`='".intval($emailid)."' and deleted=0";
2005-03-12 19:40:24 +00:00
$res = mysql_query($query);
if(mysql_num_rows($res) > 0)
{
$row = mysql_fetch_assoc($res);
echo $row['email']."<br>\n";
$query = "select `emailcerts`.`id`
from `emaillink`,`emailcerts` where
`emailid`='$emailid' and `emaillink`.`emailcertsid`=`emailcerts`.`id` and
`revoked`=0 and UNIX_TIMESTAMP(`expire`)-UNIX_TIMESTAMP() > 0
group by `emailcerts`.`id`";
$dres = mysql_query($query);
while($drow = mysql_fetch_assoc($dres))
2008-09-03 18:36:33 +00:00
mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($drow['id'])."'");
2005-03-12 19:40:24 +00:00
$do = `../scripts/runclient`;
2008-09-03 18:36:33 +00:00
$query = "update `email` set `deleted`=NOW() where `id`='".intval($emailid)."'";
2005-03-12 19:40:24 +00:00
mysql_query($query);
}
mysql_query("update `disputeemail` set hash='',action='accept' where `id`='$emailid'");
2005-03-18 16:08:22 +00:00
$rc = mysql_num_rows(mysql_query("select * from `domains` where `memid`='$oldmemid' and `deleted`=0"));
$rc = mysql_num_rows(mysql_query("select * from `email` where `memid`='$oldmemid' and `deleted`=0 and `id`!='$emailid'"));
2005-03-12 19:40:24 +00:00
$res = mysql_query("select * from `users` where `id`='$oldmemid'");
$user = mysql_fetch_assoc($res);
if($rc == 0 && $rc2 == 0 && $_SESSION['_config']['email'] == $user['email'])
{
mysql_query("update `users` set `deleted`=NOW() where `id`='$oldmemid'");
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.");
}
showfooter();
exit;
}
}
if($type == "email")
{
$emailid = intval($emailid);
$hash = trim(mysql_escape_string(stripslashes($hash)));
if($emailid <= 0 || $hash == "")
{
showheader(_("Email Dispute"));
echo _("Invalid request. Can't continue.");
showfooter();
exit;
}
$res = mysql_query("select * from `disputeemail` where `id`='$emailid' and `hash`='$hash'");
if(mysql_num_rows($res) <= 0)
{
$res = mysql_query("select * from `disputeemail` where `id`='$emailid' and hash!=''");
if(mysql_num_rows($res) > 0)
{
$row = mysql_fetch_assoc($res);
mysql_query("update `disputeemail` set `attempts`='".intval($row['attempts'] + 1)."' where `id`='".$row['id']."'");
showheader(_("Email Dispute"));
if($row['attempts'] >= 3)
{
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.");
mysql_query("update `disputeemail` set hash='',action='failed' where `id`='$emailid'");
} else
echo _("Your attempt to accept or reject a disputed email is invalid due to the hash string not matching with the email ID.");
showfooter();
exit;
} else {
showheader(_("Email Dispute"));
echo _("Invalid request. Can't continue.");
showfooter();
exit;
}
}
$_SESSION['_config']['emailid'] = $emailid;
$_SESSION['_config']['hash'] = $hash;
$row = mysql_fetch_assoc(mysql_query("select * from `disputeemail` where `id`='$emailid'"));
$_SESSION['_config']['email'] = $row['email'];
showheader(_("Email Dispute"));
includeit("4", "disputes");
showfooter();
exit;
}
if($type == "reallydomain")
{
$domainid = intval($_SESSION['_config']['domainid']);
$hash = mysql_escape_string(trim($_SESSION['_config']['hash']));
$res = mysql_query("select * from `disputedomain` where `id`='$domainid' and `hash`='$hash'");
if(mysql_num_rows($res) <= 0)
{
showheader(_("Domain Dispute"));
echo _("This dispute no longer seems to be in the database, can't continue.");
showfooter();
exit;
}
if($action == "reject")
{
mysql_query("update `disputedomain` set hash='',action='reject' where `id`='$domainid'");
showheader(_("Domain Dispute"));
echo _("You have opted to reject this dispute and the request will be removed from the database");
showfooter();
exit;
}
if($action == "accept")
{
showheader(_("Domain Dispute"));
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>";
echo "<p>"._("The following accounts have been removed:")."<br>\n";
$query = "select * from `domains` where `id`='$domainid' and deleted=0";
$res = mysql_query($query);
if(mysql_num_rows($res) > 0)
{
echo $_SESSION['_config']['domain']."<br>\n";
mysql_query("update `domains` set `deleted`=NOW() where `id`='$domainid'");
$query = "select * from `domlink` where `domid`='$domainid'";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res))
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");
$do = `../scripts/runserver`;
}
mysql_query("update `disputedomain` set hash='',action='accept' where `id`='$domainid'");
showfooter();
exit;
}
}
if($type == "domain")
{
$domainid = intval($domainid);
$hash = trim(mysql_escape_string(stripslashes($hash)));
if($domainid <= 0 || $hash == "")
{
showheader(_("Domain Dispute"));
echo _("Invalid request. Can't continue.");
showfooter();
exit;
}
$res = mysql_query("select * from `disputedomain` where `id`='$domainid' and `hash`='$hash'");
if(mysql_num_rows($res) <= 0)
{
$res = mysql_query("select * from `disputedomain` where `id`='$domainid' and hash!=''");
if(mysql_num_rows($res) > 0)
{
$row = mysql_fetch_assoc($res);
mysql_query("update `disputedomain` set `attempts`='".intval($row['attempts'] + 1)."' where `id`='".$row['id']."'");
showheader(_("Domain Dispute"));
if($row['attempts'] >= 3)
{
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.");
mysql_query("update `disputedomain` set hash='',action='failed' where `id`='$domainid'");
} else
echo _("Your attempt to accept or reject a disputed domain is invalid due to the hash string not matching with the domain ID.");
showfooter();
exit;
} else {
showheader(_("Domain Dispute"));
echo _("Invalid request. Can't continue.");
showfooter();
exit;
}
}
$_SESSION['_config']['domainid'] = $domainid;
$_SESSION['_config']['hash'] = $hash;
$row = mysql_fetch_assoc(mysql_query("select * from `disputedomain` where `id`='$domainid'"));
$_SESSION['_config']['domain'] = $row['domain'];
showheader(_("Domain Dispute"));
includeit("6", "disputes");
showfooter();
exit;
}
if($oldid == "1")
{
2008-09-01 22:19:28 +00:00
$email = trim(mysql_escape_string(stripslashes($_REQUEST['dispute'])));
2005-03-12 19:40:24 +00:00
if($email == "")
{
showheader(_("Email Dispute"));
echo _("Not a valid email address. Can't continue.");
showfooter();
exit;
}
$res = mysql_query("select * from `disputeemail` where `email`='$email' and hash!=''");
if(mysql_num_rows($res) > 0)
{
showheader(_("Email Dispute"));
2008-11-24 20:49:09 +00:00
printf(_("The email address '%s' already exists in the dispute system. Can't continue."), sanitizeHTML($email));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
unset($oldid);
$query = "select * from `email` where `email`='$email' and `deleted`=0";
$res = mysql_query($query);
if(mysql_num_rows($res) <= 0)
{
showheader(_("Email Dispute"));
2008-11-24 20:49:09 +00:00
printf(_("The email address '%s' doesn't exist in the system. Can't continue."), sanitizeHTML($email));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
$row = mysql_fetch_assoc($res);
$oldmemid = $row['memid'];
$emailid = $row['id'];
if($_SESSION['profile']['id'] == $oldmemid)
{
showheader(_("Email Dispute"));
echo _("You aren't allowed to dispute your own email addresses. Can't continue.");
showfooter();
exit;
}
$res = mysql_query("select * from `users` where `id`='$oldmemid'");
$user = mysql_fetch_assoc($res);
2005-07-01 13:12:14 +00:00
$rc = mysql_num_rows(mysql_query("select * from `domains` where `memid`='$oldmemid' and `deleted`=0"));
$rc2 = mysql_num_rows(mysql_query("select * from `email` where `memid`='$oldmemid' and `deleted`=0 and `id`!='$emailid'"));
2005-03-12 19:40:24 +00:00
if($user['email'] == $email && ($rc > 0 || $rc2 > 0))
{
showheader(_("Email Dispute"));
echo _("You only dispute the primary email address of an account if there is no longer any email addresses or domains linked to it.");
showfooter();
exit;
}
2006-04-30 08:30:54 +00:00
$hash = make_hash();
2008-12-28 12:33:29 +00:00
$query = "insert into `disputeemail` set `email`='$email',`memid`='".intval($_SESSION['profile']['id'])."',
`oldmemid`='$oldmemid',`created`=NOW(),`hash`='$hash',`id`='".intval($emailid)."',
2005-03-12 19:40:24 +00:00
`IP`='".$_SERVER['REMOTE_ADDR']."'";
mysql_query($query);
2008-11-24 20:55:23 +00:00
$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";
2005-03-12 19:40:24 +00:00
$body .= "https://".$_SESSION['_config']['normalhostname']."/disputes.php?type=email&emailid=$emailid&hash=$hash\n\n";
$body .= _("Best regards")."\n"._("CAcert.org Support!");
2005-05-23 01:53:59 +00:00
sendmail($email, "[CAcert.org] "._("Dispute Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
2005-03-12 19:40:24 +00:00
showheader(_("Email Dispute"));
2008-11-24 20:49:09 +00:00
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));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
if($oldid == "2")
{
2008-09-01 22:19:28 +00:00
$domain = trim(mysql_escape_string(stripslashes($_REQUEST['dispute'])));
2005-03-12 19:40:24 +00:00
if($domain == "")
{
showheader(_("Domain Dispute"));
echo _("Not a valid Domain. Can't continue.");
showfooter();
exit;
}
$query = "select * from `disputedomain` where `domain`='$domain' and hash!=''";
$res = mysql_query($query);
if(mysql_num_rows($res) > 0)
{
showheader(_("Domain Dispute"));
2008-11-24 20:55:23 +00:00
printf(_("The domain '%s' already exists in the dispute system. Can't continue."), sanitizeHTML($domain));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
unset($oldid);
$query = "select * from `domains` where `domain`='$domain' and `deleted`=0";
2008-09-05 16:04:05 +00:00
$email = ""; if(array_key_exists('email',$_REQUEST)) $email=trim(mysql_real_escape_string($_REQUEST['email']));
2005-03-12 19:40:24 +00:00
$res = mysql_query($query);
if(mysql_num_rows($res) <= 0)
{
showheader(_("Domain Dispute"));
2008-11-24 20:55:23 +00:00
printf(_("The domain '%s' doesn't exist in the system. Can't continue."), sanitizeHTML($email));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
$row = mysql_fetch_assoc($res);
$oldmemid = $row['memid'];
if($_SESSION['profile']['id'] == $oldmemid)
{
showheader(_("Domain Dispute"));
2008-09-05 15:56:40 +00:00
echo _("You aren't allowed to dispute your own domains. Can't continue.");
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
$domainid = $row['id'];
$_SESSION['_config']['domainid'] = $domainid;
2008-11-14 23:39:35 +00:00
$_SESSION['_config']['memid'] = array_key_exists('memid',$_REQUEST)?intval($_REQUEST['memid']):0;
2005-03-12 19:40:24 +00:00
$_SESSION['_config']['domain'] = $domain;
$_SESSION['_config']['oldmemid'] = $oldmemid;
$addy = array();
$domtmp = escapeshellarg($domain);
2005-07-01 13:12:14 +00:00
if(strtolower(substr($domtmp, -4, 3)) != ".jp")
$adds = explode("\n", trim(`whois $domtmp|grep \@`));
2005-03-12 19:40:24 +00:00
if(substr($domain, -4) == ".org" || substr($domain, -5) == ".info")
{
if(is_array($adds))
foreach($adds as $line)
{
$bits = explode(":", $line, 2);
$line = trim($bits[1]);
if(!in_array($line, $addy) && $line != "")
$addy[] = trim(mysql_escape_string(stripslashes($line)));
}
} else {
if(is_array($adds))
foreach($adds as $line)
{
$line = trim(str_replace("\t", " ", $line));
$line = trim(str_replace("(", "", $line));
$line = trim(str_replace(")", " ", $line));
$bits = explode(" ", $line);
foreach($bits as $bit)
{
if(strstr($bit, "@"))
$line = $bit;
}
if(!in_array($line, $addy) && $line != "")
$addy[] = trim(mysql_escape_string(stripslashes($line)));
}
}
$rfc = array("root@$domain", "hostmaster@$domain", "postmaster@$domain", "admin@$domain", "webmaster@$domain");
foreach($rfc as $sub)
if(!in_array($sub, $addy))
$addy[] = $sub;
$_SESSION['_config']['addy'] = $addy;
showheader(_("Domain Dispute"));
includeit("5", "disputes");
showfooter();
exit;
}
if($oldid == "5")
{
2006-08-16 03:45:18 +00:00
$authaddy = trim(mysql_escape_string(stripslashes($_REQUEST['authaddy'])));
2005-03-12 19:40:24 +00:00
if(!in_array($authaddy, $_SESSION['_config']['addy']) || $authaddy == "")
{
showheader(_("My CAcert.org Account!"));
echo _("The address you submitted isn't a valid authority address for the domain.");
showfooter();
exit;
}
$query = "select * from `domains` where `domain`='".$_SESSION['_config']['domain']."' and `deleted`=0";
$res = mysql_query($query);
if(mysql_num_rows($res) <= 0)
{
showheader(_("Domain Dispute!"));
2008-11-24 20:55:23 +00:00
printf(_("The domain '%s' isn't in the system. Can't continue."), sanitizeHTML($_SESSION['_config']['domain']));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
$domainid = intval($_SESSION['_config']['domainid']);
$memid = intval($_SESSION['_config']['memid']);
$oldmemid = intval($_SESSION['_config']['oldmemid']);
$domain = mysql_escape_string($_SESSION['_config']['domain']);
2006-04-30 08:30:54 +00:00
$hash = make_hash();
2005-03-12 19:40:24 +00:00
$query = "insert into `disputedomain` set `domain`='$domain',`memid`='".$_SESSION['profile']['id']."',
`oldmemid`='$oldmemid',`created`=NOW(),`hash`='$hash',`id`='$domainid'";
mysql_query($query);
$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";
$body .= "https://".$_SESSION['_config']['normalhostname']."/disputes.php?type=domain&domainid=$domainid&hash=$hash\n\n";
$body .= _("Best regards")."\n"._("CAcert.org Support!");
2005-05-23 01:53:59 +00:00
sendmail($authaddy, "[CAcert.org] "._("Dispute Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
2005-03-12 19:40:24 +00:00
showheader(_("Domain Dispute"));
2008-11-24 20:55:23 +00:00
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));
2005-03-12 19:40:24 +00:00
showfooter();
exit;
}
showheader(_("Domain and Email Disputes"));
includeit($id, "disputes");
showfooter();
?>