| 1 | *** /usr/local/tarballs/maia-1.0.1/php/xadminusers.php Sun Feb 12 14:49:19 2006 |
|---|
| 2 | --- ./xadminusers.php Mon Apr 17 12:12:20 2006 |
|---|
| 3 | *************** |
|---|
| 4 | *** 98,205 **** |
|---|
| 5 | |
|---|
| 6 | $super = is_superadmin($uid); |
|---|
| 7 | |
|---|
| 8 | ! $button = ''; |
|---|
| 9 | |
|---|
| 10 | // Find out which button we pushed to get here |
|---|
| 11 | if (isset($_POST["button_add"])) { |
|---|
| 12 | |
|---|
| 13 | $button = "add"; |
|---|
| 14 | ! $succeeded = false; |
|---|
| 15 | ! |
|---|
| 16 | if (isset($_POST["new_email"])) { |
|---|
| 17 | |
|---|
| 18 | $smarty->assign('new_email', 1); |
|---|
| 19 | |
|---|
| 20 | ! $new_email = trim($_POST["new_email"]); |
|---|
| 21 | |
|---|
| 22 | ! // Rewrite the e-mail address as necessary for POP3/IMAP, to make |
|---|
| 23 | ! // it match the routing address provided by the MTA-RX. |
|---|
| 24 | ! if ($auth_method == "pop3" && !empty($routing_domain)) { |
|---|
| 25 | ! $username = get_user_from_email($new_email); |
|---|
| 26 | ! $new_email = $username . "@" . $routing_domain; |
|---|
| 27 | ! } elseif ($auth_method == "imap") { |
|---|
| 28 | ! $new_email = get_rewritten_email_address($new_email, $address_rewriting_type); |
|---|
| 29 | ! $username = get_user_from_email($new_email); |
|---|
| 30 | ! } elseif ($auth_method == "internal") { |
|---|
| 31 | ! $new_email = get_rewritten_email_address($new_email, $address_rewriting_type); |
|---|
| 32 | ! $username = $new_email; |
|---|
| 33 | ! } else { |
|---|
| 34 | ! $username = get_user_from_email($new_email); |
|---|
| 35 | ! } |
|---|
| 36 | ! $bad_user = empty($username); |
|---|
| 37 | ! $smarty->assign("bad_user", $bad_user); |
|---|
| 38 | |
|---|
| 39 | ! if (!$super && !$bad_user) { |
|---|
| 40 | |
|---|
| 41 | ! // Make sure the new address is in a domain that |
|---|
| 42 | ! // this administrator controls. |
|---|
| 43 | ! $domain = "@" . get_domain_from_email($new_email); |
|---|
| 44 | ! $select = "SELECT id " . |
|---|
| 45 | ! "FROM maia_domains, maia_domain_admins " . |
|---|
| 46 | ! "WHERE maia_domains.id = maia_domain_admins.domain_id " . |
|---|
| 47 | ! "AND maia_domain_admins.admin_id = ? " . |
|---|
| 48 | ! "AND maia_domains.domain = ?"; |
|---|
| 49 | ! $sth = $dbh->query($select, array($uid, $domain)); |
|---|
| 50 | ! $bad_domain = !$sth->fetchrow(); |
|---|
| 51 | ! $smarty->assign("bad_domain", $bad_domain); |
|---|
| 52 | ! $sth->free(); |
|---|
| 53 | ! } |
|---|
| 54 | |
|---|
| 55 | ! if (($super || !$bad_domain) && !$bad_user) { |
|---|
| 56 | ! // Only add the new address if it doesn't already exist. |
|---|
| 57 | ! $select = "SELECT maia_user_id FROM users WHERE email = ?"; |
|---|
| 58 | ! $sth = $dbh->query($select, array($new_email)); |
|---|
| 59 | ! if (!$sth->fetchrow()) { |
|---|
| 60 | ! $new_user_id = add_user($username, $new_email); |
|---|
| 61 | ! $succeeded = true; // FIXME need to check return value, but add_user |
|---|
| 62 | ! // doesn't really return anything defined on error |
|---|
| 63 | ! if ($auth_method == "internal") { |
|---|
| 64 | ! // Generate a random password and assign it to the new user |
|---|
| 65 | ! list($password, $digest) = generate_random_password(); |
|---|
| 66 | ! $update = "UPDATE maia_users SET password = ? WHERE id = ?"; |
|---|
| 67 | ! $dbh->query($update, array($digest, $new_user_id)); |
|---|
| 68 | |
|---|
| 69 | ! // Expand the newuser.tpl template to e-mail the new user his |
|---|
| 70 | ! // temporary login credentials. |
|---|
| 71 | ! $select = "SELECT admin_email, newuser_template_file, reminder_login_url, internal_auth FROM maia_config WHERE id = 0"; |
|---|
| 72 | ! $sth2 = $dbh->query($select); |
|---|
| 73 | ! if ($row = $sth2->fetchrow()) { |
|---|
| 74 | ! $admin_email = $row["admin_email"]; |
|---|
| 75 | ! $template_file = $row["newuser_template_file"]; |
|---|
| 76 | ! $login_url = $row["reminder_login_url"]; |
|---|
| 77 | ! $issue_password = ($row["internal_auth"] == "Y"); |
|---|
| 78 | ! } |
|---|
| 79 | ! $sth2->free(); |
|---|
| 80 | ! if ($issue_password) { |
|---|
| 81 | ! $fh = fopen($template_file, "r"); |
|---|
| 82 | ! $body = fread($fh, filesize($template_file)); |
|---|
| 83 | ! fclose($fh); |
|---|
| 84 | ! $body = preg_replace("/%%ADMINEMAIL%%/", $admin_email, $body); |
|---|
| 85 | ! $body = preg_replace("/%%LOGIN%%/", $username, $body); |
|---|
| 86 | ! $body = preg_replace("/%%PASSWORD%%/", $password, $body); |
|---|
| 87 | ! $body = preg_replace("/%%LOGINURL%%/", $login_url, $body); |
|---|
| 88 | ! $result = smtp_send($admin_email, $new_email, $body); |
|---|
| 89 | ! $succeeded = (strncmp($result, "2", 1) == 0) ; |
|---|
| 90 | ! $smarty->assign('smtp_result', $result); |
|---|
| 91 | ! } |
|---|
| 92 | ! } |
|---|
| 93 | ! } else { |
|---|
| 94 | ! $succeeded = false; |
|---|
| 95 | ! } |
|---|
| 96 | ! $sth->free(); |
|---|
| 97 | ! if ($succeeded) { |
|---|
| 98 | ! $lang['text_address_added'] = sprintf($lang['text_address_added'], $new_email); |
|---|
| 99 | ! } else { |
|---|
| 100 | ! $lang['text_address_not_added'] = sprintf($lang['text_address_not_added'], $new_email); |
|---|
| 101 | ! } |
|---|
| 102 | ! } else { |
|---|
| 103 | ! $lang['text_address_not_added'] = sprintf($lang['text_address_not_added'], $new_email); |
|---|
| 104 | ! } |
|---|
| 105 | } else { |
|---|
| 106 | ! $lang['text_address_not_added'] = sprintf($lang['text_address_not_added'], $new_email); |
|---|
| 107 | } |
|---|
| 108 | - $smarty->assign("succeeded", $succeeded); |
|---|
| 109 | |
|---|
| 110 | } elseif (isset($_POST["button_delete_email"])) { |
|---|
| 111 | |
|---|
| 112 | $button = "delete_email"; |
|---|
| 113 | --- 98,211 ---- |
|---|
| 114 | |
|---|
| 115 | $super = is_superadmin($uid); |
|---|
| 116 | |
|---|
| 117 | ! $button = 'none'; |
|---|
| 118 | |
|---|
| 119 | // Find out which button we pushed to get here |
|---|
| 120 | if (isset($_POST["button_add"])) { |
|---|
| 121 | |
|---|
| 122 | $button = "add"; |
|---|
| 123 | ! |
|---|
| 124 | if (isset($_POST["new_email"])) { |
|---|
| 125 | |
|---|
| 126 | $smarty->assign('new_email', 1); |
|---|
| 127 | |
|---|
| 128 | ! $new_email_list = trim($_POST["new_email"]); |
|---|
| 129 | |
|---|
| 130 | ! // Split on commas to allow for lists |
|---|
| 131 | ! $email_list = split(",", $new_email_list); |
|---|
| 132 | ! foreach ($email_list as $new_email) { |
|---|
| 133 | ! $succeeded = false; |
|---|
| 134 | ! $new_email = trim($new_email); |
|---|
| 135 | ! // Rewrite the e-mail address as necessary for POP3/IMAP, to make |
|---|
| 136 | ! // it match the routing address provided by the MTA-RX. |
|---|
| 137 | ! if ($auth_method == "pop3" && !empty($routing_domain)) { |
|---|
| 138 | ! $username = get_user_from_email($new_email); |
|---|
| 139 | ! $new_email = $username . "@" . $routing_domain; |
|---|
| 140 | ! } elseif ($auth_method == "imap") { |
|---|
| 141 | ! $new_email = get_rewritten_email_address($new_email, $address_rewriting_type); |
|---|
| 142 | ! $username = get_user_from_email($new_email); |
|---|
| 143 | ! } elseif ($auth_method == "internal") { |
|---|
| 144 | ! $new_email = get_rewritten_email_address($new_email, $address_rewriting_type); |
|---|
| 145 | ! $username = $new_email; |
|---|
| 146 | ! } else { |
|---|
| 147 | ! $username = get_user_from_email($new_email); |
|---|
| 148 | ! } |
|---|
| 149 | ! $bad_user = empty($username); |
|---|
| 150 | ! $smarty->assign("bad_user", $bad_user); |
|---|
| 151 | |
|---|
| 152 | ! if (!$super && !$bad_user) { |
|---|
| 153 | |
|---|
| 154 | ! // Make sure the new address is in a domain that |
|---|
| 155 | ! // this administrator controls. |
|---|
| 156 | ! $domain = "@" . get_domain_from_email($new_email); |
|---|
| 157 | ! $select = "SELECT id " . |
|---|
| 158 | ! "FROM maia_domains, maia_domain_admins " . |
|---|
| 159 | ! "WHERE maia_domains.id = maia_domain_admins.domain_id " . |
|---|
| 160 | ! "AND maia_domain_admins.admin_id = ? " . |
|---|
| 161 | ! "AND maia_domains.domain = ?"; |
|---|
| 162 | ! $sth = $dbh->query($select, array($uid, $domain)); |
|---|
| 163 | ! $bad_domain = !$sth->fetchrow(); |
|---|
| 164 | ! $smarty->assign("bad_domain", $bad_domain); |
|---|
| 165 | ! $sth->free(); |
|---|
| 166 | ! } |
|---|
| 167 | |
|---|
| 168 | ! if (($super || !$bad_domain) && !$bad_user) { |
|---|
| 169 | ! // Only add the new address if it doesn't already exist. |
|---|
| 170 | ! $select = "SELECT maia_user_id FROM users WHERE email = ?"; |
|---|
| 171 | ! $sth = $dbh->query($select, array($new_email)); |
|---|
| 172 | ! if (!$sth->fetchrow()) { |
|---|
| 173 | ! $new_user_id = add_user($username, $new_email); |
|---|
| 174 | ! $succeeded = true; // FIXME need to check return value, but add_user |
|---|
| 175 | ! // doesn't really return anything defined on error |
|---|
| 176 | ! if ($auth_method == "internal") { |
|---|
| 177 | ! // Generate a random password and assign it to the new user |
|---|
| 178 | ! list($password, $digest) = generate_random_password(); |
|---|
| 179 | ! $update = "UPDATE maia_users SET password = ? WHERE id = ?"; |
|---|
| 180 | ! $dbh->query($update, array($digest, $new_user_id)); |
|---|
| 181 | |
|---|
| 182 | ! // Expand the newuser.tpl template to e-mail the new user his |
|---|
| 183 | ! // temporary login credentials. |
|---|
| 184 | ! $select = "SELECT admin_email, newuser_template_file, reminder_login_url, internal_auth FROM maia_config WHERE id = 0"; |
|---|
| 185 | ! $sth2 = $dbh->query($select); |
|---|
| 186 | ! if ($row = $sth2->fetchrow()) { |
|---|
| 187 | ! $admin_email = $row["admin_email"]; |
|---|
| 188 | ! $template_file = $row["newuser_template_file"]; |
|---|
| 189 | ! $login_url = $row["reminder_login_url"]; |
|---|
| 190 | ! $issue_password = ($row["internal_auth"] == "Y"); |
|---|
| 191 | ! } |
|---|
| 192 | ! $sth2->free(); |
|---|
| 193 | ! if ($issue_password) { |
|---|
| 194 | ! $fh = fopen($template_file, "r"); |
|---|
| 195 | ! $body = fread($fh, filesize($template_file)); |
|---|
| 196 | ! fclose($fh); |
|---|
| 197 | ! $body = preg_replace("/%%ADMINEMAIL%%/", $admin_email, $body); |
|---|
| 198 | ! $body = preg_replace("/%%LOGIN%%/", $username, $body); |
|---|
| 199 | ! $body = preg_replace("/%%PASSWORD%%/", $password, $body); |
|---|
| 200 | ! $body = preg_replace("/%%LOGINURL%%/", $login_url, $body); |
|---|
| 201 | ! $result = smtp_send($admin_email, $new_email, $body); |
|---|
| 202 | ! $succeeded = (strncmp($result, "2", 1) == 0) ; |
|---|
| 203 | ! $smarty->assign('smtp_result', $result); |
|---|
| 204 | ! } |
|---|
| 205 | ! } |
|---|
| 206 | ! } else { |
|---|
| 207 | ! $succeeded = false; |
|---|
| 208 | ! } |
|---|
| 209 | ! $sth->free(); |
|---|
| 210 | ! if ($succeeded) { |
|---|
| 211 | ! $lang['text_address_added_array'][] = sprintf($lang['text_address_added'], $new_email); |
|---|
| 212 | ! } else { |
|---|
| 213 | ! $lang['text_address_not_added_array'][] = sprintf($lang['text_address_not_added'], $new_email); |
|---|
| 214 | ! } |
|---|
| 215 | ! } else { |
|---|
| 216 | ! $lang['text_address_not_added_array'][] = sprintf($lang['text_address_not_added'], $new_email); |
|---|
| 217 | ! } |
|---|
| 218 | ! } |
|---|
| 219 | } else { |
|---|
| 220 | ! $lang['text_address_not_added'] = sprintf($lang['text_address_not_added'], $new_email_list); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | + // $smarty->assign("succeeded", $succeeded); |
|---|
| 224 | + |
|---|
| 225 | } elseif (isset($_POST["button_delete_email"])) { |
|---|
| 226 | |
|---|
| 227 | $button = "delete_email"; |
|---|
| 228 | *************** |
|---|
| 229 | *** 397,403 **** |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | $smarty->assign('button', $button); |
|---|
| 233 | ! $smarty->assign('lang', $lang); |
|---|
| 234 | |
|---|
| 235 | $smarty->display('xadminusers.tpl'); |
|---|
| 236 | ! ?> |
|---|
| 237 | \ No newline at end of file |
|---|
| 238 | --- 403,411 ---- |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | $smarty->assign('button', $button); |
|---|
| 242 | ! $smarty->assign('lang', $lang); |
|---|
| 243 | |
|---|
| 244 | $smarty->display('xadminusers.tpl'); |
|---|
| 245 | ! |
|---|
| 246 | ! |
|---|
| 247 | ! ?> |
|---|