This commit has been accessed 1,116 times via Git panel.
commit 2965f53d4254371253ca59e00cf8f050ba90541c
tree 41992aef4cb51b7d70661e1353390cac0f3af269
parent 88890ee92210ecb5def20c69aab510bbe035fb78
author Engels Antonio <engels@kartero.org> 1445976043 +0800
committer Engels Antonio <engels@kartero.org> 1445976043 +0800
Add change email address support
diff --git a/index.php b/index.php
index d8d8038..a8ec403 100644
--- a/index.php
+++ b/index.php
@@ -167,6 +167,7 @@ if (isset($_GET['do']) and ($_GET['do'] == "logout")) {
$_SESSION = array();
session_destroy();
header("Location: .");
+ echo '<meta http-equiv="refresh" content="0; url=/">';
exit;
}
@@ -647,6 +648,73 @@ if (isset($_SESSION['logged_uid'])) {
}
}
}
+
+ if (isset($_POST['pm_email'])) {
+ $pm_email = trim($_POST['pm_email']);
+ $pm_email = strtolower($pm_email);
+
+ if (preg_match("/@/",$pm_email)) {
+ $pm_email = substr($pm_email,0,strpos($pm_email,"@"));
+ }
+
+ $pm_email = $pm_email . "@" . $_SESSION['logged_uid'];
+
+ if ($pm_email != $_POST['pm_mod']) {
+ $pm_query = mysql_query("select id from users where id='$pm_email'");
+
+ if (mysql_num_rows($pm_query) == 0) {
+ $pm_query = mysql_query("select id from aliases where id='$pm_email'");
+
+ if (mysql_num_rows($pm_query) == 0) {
+ $pm_maildir_new = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@"));
+
+ if (!file_exists($pm_maildir_new)) {
+ $pm_maildir_old = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1) .'/' . substr($pm_mod,0,strpos($pm_mod,"@"));
+
+ if (!file_exists("$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1))) {
+ mkdir("$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1), 0700, true);
+ }
+ rename($pm_maildir_old, $pm_maildir_new);
+
+ if (file_exists("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1))) {
+ $pm_home_old = "$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1) .'/' . substr($pm_mod,0,strpos($pm_mod,"@"));
+ $pm_home_new = "$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@"));
+
+ if (!file_exists("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1))) {
+ mkdir("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1), 0700, true);
+ }
+ rename($pm_home_old, $pm_home_new);
+ }
+
+ if (file_exists('images/contacts/' . sha1($pm_mod))) {
+ rename('images/contacts/' . sha1($pm_mod), 'images/contacts/' . sha1($pm_email));
+ }
+
+ $pm_maildir_set = "{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@")) . '/';
+ $pm_query = mysql_query("update users set id='$pm_email', maildir='$pm_maildir_set' where id='$pm_mod'");
+ ack("{$_POST['pm_mod']} account migrated to $pm_email");
+
+ $pm_query = mysql_query("update aliases set alias='$pm_email' where alias='$pm_mod'");
+
+ if (mysql_affected_rows() > 0) {
+ if (mysql_affected_rows() > 1) {
+ ack("{$_POST['pm_mod']} aliases migrated to $pm_email");
+ }
+ else {
+ ack("{$_POST['pm_mod']} alias migrated to $pm_email");
+ }
+ }
+ }
+ }
+ else {
+ nak("$pm_email alias exists");
+ }
+ }
+ else {
+ nak("$pm_email account exists");
+ }
+ }
+ }
}
if (isset($_POST['pm_set']) and !empty($_POST['pm_set']) and isset($_POST['pm_do']) and !empty($_POST['pm_do'])) {
@@ -1821,7 +1889,7 @@ echo "</tr>";
$pm_aka = mysql_query("select * from aliases where alias='{$pm_row[0]}'");
$pm_aka = mysql_num_rows($pm_aka);
- echo "<tr bgcolor=\"$pm_bg\"><td align=\"right\">$msg_new</td><td align=\"right\">$msg_cur</td><td align=\"right\">$pm_aka</td><form method=\"post\"><input type=\"hidden\" name=\"pm_set\" value=\"{$pm_row[0]}\"><input type=\"hidden\" name=\"pm_do\" value=\"$pm_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$pm_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_mod\" value=\"{$pm_row[0]}\"><td>{$pm_row[0]}</td><td><input class=\"input\" type=\"text\" name=\"pm_name\" maxlength=\"128\" autocomplete=\"off\" value=\"{$pm_row[3]}\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"input\" type=\"text\" name=\"pm_quota\" maxlength=\"16\" autocomplete=\"off\" value=\"{$pm_row[6]}\" style=\"text-align: right;\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_del\" value=\"{$pm_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$pm_row[0]} plus all messages and aliases associated with this account?')) {return true;} else {return false;}\"></td></form></tr>";
+ echo "<tr bgcolor=\"$pm_bg\"><td align=\"right\">$msg_new</td><td align=\"right\">$msg_cur</td><td align=\"right\">$pm_aka</td><form method=\"post\"><input type=\"hidden\" name=\"pm_set\" value=\"{$pm_row[0]}\"><input type=\"hidden\" name=\"pm_do\" value=\"$pm_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$pm_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_mod\" value=\"{$pm_row[0]}\"><td><input class=\"input\" type=\"text\" name=\"pm_email\" value=\"{$pm_row[0]}\" maxlength=\"255\" autocomplete=\"off\" required></td><td><input class=\"input\" type=\"text\" name=\"pm_name\" maxlength=\"128\" autocomplete=\"off\" value=\"{$pm_row[3]}\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"input\" type=\"text\" name=\"pm_quota\" maxlength=\"16\" autocomplete=\"off\" value=\"{$pm_row[6]}\" style=\"text-align: right;\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_del\" value=\"{$pm_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$pm_row[0]} plus all messages and aliases associated with this account?')) {return true;} else {return false;}\"></td></form></tr>";
}
echo "</table>";
tree 41992aef4cb51b7d70661e1353390cac0f3af269
parent 88890ee92210ecb5def20c69aab510bbe035fb78
author Engels Antonio <engels@kartero.org> 1445976043 +0800
committer Engels Antonio <engels@kartero.org> 1445976043 +0800
Add change email address support
diff --git a/index.php b/index.php
index d8d8038..a8ec403 100644
--- a/index.php
+++ b/index.php
@@ -167,6 +167,7 @@ if (isset($_GET['do']) and ($_GET['do'] == "logout")) {
$_SESSION = array();
session_destroy();
header("Location: .");
+ echo '<meta http-equiv="refresh" content="0; url=/">';
exit;
}
@@ -647,6 +648,73 @@ if (isset($_SESSION['logged_uid'])) {
}
}
}
+
+ if (isset($_POST['pm_email'])) {
+ $pm_email = trim($_POST['pm_email']);
+ $pm_email = strtolower($pm_email);
+
+ if (preg_match("/@/",$pm_email)) {
+ $pm_email = substr($pm_email,0,strpos($pm_email,"@"));
+ }
+
+ $pm_email = $pm_email . "@" . $_SESSION['logged_uid'];
+
+ if ($pm_email != $_POST['pm_mod']) {
+ $pm_query = mysql_query("select id from users where id='$pm_email'");
+
+ if (mysql_num_rows($pm_query) == 0) {
+ $pm_query = mysql_query("select id from aliases where id='$pm_email'");
+
+ if (mysql_num_rows($pm_query) == 0) {
+ $pm_maildir_new = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@"));
+
+ if (!file_exists($pm_maildir_new)) {
+ $pm_maildir_old = "$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1) .'/' . substr($pm_mod,0,strpos($pm_mod,"@"));
+
+ if (!file_exists("$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1))) {
+ mkdir("$mail_root/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1), 0700, true);
+ }
+ rename($pm_maildir_old, $pm_maildir_new);
+
+ if (file_exists("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1))) {
+ $pm_home_old = "$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_mod, 0, 1) .'/' . substr($pm_mod,0,strpos($pm_mod,"@"));
+ $pm_home_new = "$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@"));
+
+ if (!file_exists("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1))) {
+ mkdir("$mail_home/{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1), 0700, true);
+ }
+ rename($pm_home_old, $pm_home_new);
+ }
+
+ if (file_exists('images/contacts/' . sha1($pm_mod))) {
+ rename('images/contacts/' . sha1($pm_mod), 'images/contacts/' . sha1($pm_email));
+ }
+
+ $pm_maildir_set = "{$_SESSION['logged_uid']}/" . substr($pm_email, 0, 1) .'/' . substr($pm_email,0,strpos($pm_email,"@")) . '/';
+ $pm_query = mysql_query("update users set id='$pm_email', maildir='$pm_maildir_set' where id='$pm_mod'");
+ ack("{$_POST['pm_mod']} account migrated to $pm_email");
+
+ $pm_query = mysql_query("update aliases set alias='$pm_email' where alias='$pm_mod'");
+
+ if (mysql_affected_rows() > 0) {
+ if (mysql_affected_rows() > 1) {
+ ack("{$_POST['pm_mod']} aliases migrated to $pm_email");
+ }
+ else {
+ ack("{$_POST['pm_mod']} alias migrated to $pm_email");
+ }
+ }
+ }
+ }
+ else {
+ nak("$pm_email alias exists");
+ }
+ }
+ else {
+ nak("$pm_email account exists");
+ }
+ }
+ }
}
if (isset($_POST['pm_set']) and !empty($_POST['pm_set']) and isset($_POST['pm_do']) and !empty($_POST['pm_do'])) {
@@ -1821,7 +1889,7 @@ echo "</tr>";
$pm_aka = mysql_query("select * from aliases where alias='{$pm_row[0]}'");
$pm_aka = mysql_num_rows($pm_aka);
- echo "<tr bgcolor=\"$pm_bg\"><td align=\"right\">$msg_new</td><td align=\"right\">$msg_cur</td><td align=\"right\">$pm_aka</td><form method=\"post\"><input type=\"hidden\" name=\"pm_set\" value=\"{$pm_row[0]}\"><input type=\"hidden\" name=\"pm_do\" value=\"$pm_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$pm_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_mod\" value=\"{$pm_row[0]}\"><td>{$pm_row[0]}</td><td><input class=\"input\" type=\"text\" name=\"pm_name\" maxlength=\"128\" autocomplete=\"off\" value=\"{$pm_row[3]}\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"input\" type=\"text\" name=\"pm_quota\" maxlength=\"16\" autocomplete=\"off\" value=\"{$pm_row[6]}\" style=\"text-align: right;\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_del\" value=\"{$pm_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$pm_row[0]} plus all messages and aliases associated with this account?')) {return true;} else {return false;}\"></td></form></tr>";
+ echo "<tr bgcolor=\"$pm_bg\"><td align=\"right\">$msg_new</td><td align=\"right\">$msg_cur</td><td align=\"right\">$pm_aka</td><form method=\"post\"><input type=\"hidden\" name=\"pm_set\" value=\"{$pm_row[0]}\"><input type=\"hidden\" name=\"pm_do\" value=\"$pm_do\"><td align=\"center\" valign=\"middle\" width=\"10\"><input type=\"image\" src=\"images/{$pm_do}.png\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_mod\" value=\"{$pm_row[0]}\"><td><input class=\"input\" type=\"text\" name=\"pm_email\" value=\"{$pm_row[0]}\" maxlength=\"255\" autocomplete=\"off\" required></td><td><input class=\"input\" type=\"text\" name=\"pm_name\" maxlength=\"128\" autocomplete=\"off\" value=\"{$pm_row[3]}\"></td><td><input class=\"input\" type=\"text\" name=\"pm_pass\" maxlength=\"64\" autocomplete=\"off\"></td><td><input class=\"input\" type=\"text\" name=\"pm_quota\" maxlength=\"16\" autocomplete=\"off\" value=\"{$pm_row[6]}\" style=\"text-align: right;\"></td><td><input class=\"button\" type=\"submit\" value=\"mod\"></td></form><form method=\"post\"><input type=\"hidden\" name=\"pm_del\" value=\"{$pm_row[0]}\"><td><input class=\"button\" type=\"submit\" value=\"del\" onclick=\"if (confirm('Do you really want to delete {$pm_row[0]} plus all messages and aliases associated with this account?')) {return true;} else {return false;}\"></td></form></tr>";
}
echo "</table>";