Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

email_history2.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?
  2. /************************************************************************
  3. ||------------|| User email history page ||---------------------------||
  4. This page lists previous email addresses a user has used on the site. It
  5. gets called if $_GET['action'] == 'email'.
  6. It also requires $_GET['userid'] in order to get the data for the correct
  7. user.
  8. ************************************************************************/
  9. $UserID = $_GET['userid'];
  10. if (!is_number($UserID)) {
  11. error(404);
  12. }
  13. $DB->query("
  14. SELECT
  15. ui.JoinDate,
  16. p.Level AS Class
  17. FROM users_main AS um
  18. JOIN users_info AS ui ON um.ID = ui.UserID
  19. JOIN permissions AS p ON p.ID = um.PermissionID
  20. WHERE um.ID = $UserID");
  21. list($Joined, $Class) = $DB->next_record();
  22. if (!check_perms('users_view_email', $Class)) {
  23. error(403);
  24. }
  25. // TODO: Is this even used?
  26. $UsersOnly = $_GET['usersonly'] ?? false;
  27. $DB->query("
  28. SELECT Username
  29. FROM users_main
  30. WHERE ID = $UserID");
  31. list($Username) = $DB->next_record();
  32. View::show_header("Email history for $Username");
  33. // Get current email (and matches)
  34. $DB->query("
  35. SELECT
  36. m.Email,
  37. '".sqltime()."' AS Time,
  38. m.IP,
  39. GROUP_CONCAT(h.UserID SEPARATOR '|') AS UserIDs,
  40. GROUP_CONCAT(h.Time SEPARATOR '|') AS UserSetTimes,
  41. GROUP_CONCAT(h.IP SEPARATOR '|') AS UserIPs,
  42. GROUP_CONCAT(m2.Username SEPARATOR '|') AS Usernames,
  43. GROUP_CONCAT(m2.Enabled SEPARATOR '|') AS UsersEnabled,
  44. GROUP_CONCAT(i.Donor SEPARATOR '|') AS UsersDonor,
  45. GROUP_CONCAT(i.Warned SEPARATOR '|') AS UsersWarned
  46. FROM users_main AS m
  47. LEFT JOIN users_history_emails AS h ON h.Email = m.Email
  48. AND h.UserID != m.ID
  49. LEFT JOIN users_main AS m2 ON m2.ID = h.UserID
  50. LEFT JOIN users_info AS i ON i.UserID = h.UserID
  51. WHERE m.ID = '$UserID'"
  52. );
  53. //$CurrentEmail = array_shift($DB->to_array());
  54. $CurrentEmail = ($DB->to_array())[0]; // Only variables should be passed by reference
  55. // Get historic emails (and matches)
  56. $DB->query("
  57. SELECT
  58. h2.Email,
  59. h2.Time,
  60. h2.IP,
  61. h3.UserID AS UserIDs,
  62. h3.Time AS UserSetTimes,
  63. h3.IP AS UserIPs,
  64. m3.Username AS Usernames,
  65. m3.Enabled AS UsersEnabled,
  66. i2.Donor AS UsersDonor,
  67. i2.Warned AS UsersWarned
  68. FROM users_history_emails AS h2
  69. LEFT JOIN users_history_emails AS h3 ON h3.Email = h2.Email
  70. AND h3.UserID != h2.UserID
  71. LEFT JOIN users_main AS m3 ON m3.ID = h3.UserID
  72. LEFT JOIN users_info AS i2 ON i2.UserID = h3.UserID
  73. WHERE h2.UserID = '$UserID'
  74. ORDER BY Time DESC"
  75. );
  76. $History = $DB->to_array();
  77. // Current email
  78. $Current['Email'] = $CurrentEmail['Email'];
  79. $Current['StartTime'] = $History[0]['Time'];
  80. $Current['CurrentIP'] = $CurrentEmail['IP'];
  81. $Current['IP'] = $History[(count($History) - 1)]['IP'];
  82. // Matches for current email
  83. if ($CurrentEmail['Usernames'] != '') {
  84. $UserIDs = explode('|', $CurrentEmail['UserIDs']);
  85. $Usernames = explode('|', $CurrentEmail['Usernames']);
  86. $UsersEnabled = explode('|', $CurrentEmail['UsersEnabled']);
  87. $UsersDonor = explode('|', $CurrentEmail['UsersDonor']);
  88. $UsersWarned = explode('|', $CurrentEmail['UsersWarned']);
  89. $UserSetTimes = explode('|', $CurrentEmail['UserSetTimes']);
  90. $UserIPs = explode('|', $CurrentEmail['UserIPs']);
  91. foreach ($UserIDs as $Key => $Val) {
  92. $CurrentMatches[$Key]['Username'] = '&nbsp;&nbsp;&#187;&nbsp;'.Users::format_username($Val, true, true, true);
  93. $CurrentMatches[$Key]['IP'] = $UserIPs[$Key];
  94. $CurrentMatches[$Key]['EndTime'] = $UserSetTimes[$Key];
  95. }
  96. }
  97. // Email history records
  98. if (count($History) === 1) {
  99. $Invite['Email'] = $History[0]['Email'];
  100. $Invite['EndTime'] = $Joined;
  101. $Invite['AccountAge'] = date(time() + time() - strtotime($Joined)); // Same as EndTime but without ' ago'
  102. $Invite['IP'] = $History[0]['IP'];
  103. if ($Current['StartTime'] == '0000-00-00 00:00:00') {
  104. $Current['StartTime'] = $Joined;
  105. }
  106. } else {
  107. foreach ($History as $Key => $Val) {
  108. if (isset($History[$Key + 1]) && $History[$Key + 1]['Time'] == '0000-00-00 00:00:00' && $Val['Time'] != '0000-00-00 00:00:00') {
  109. // Invited email
  110. $Invite['Email'] = $Val['Email'];
  111. $Invite['EndTime'] = $Joined;
  112. $Invite['AccountAge'] = date(time() + time() - strtotime($Joined)); // Same as EndTime but without ' ago'
  113. $Invite['IP'] = $Val['IP'];
  114. } elseif (isset($History[$Key - 1]) && $History[$Key - 1]['Email'] != $Val['Email'] && $Val['Time'] != '0000-00-00 00:00:00') {
  115. // Old email
  116. $i = 1;
  117. while ($Val['Email'] == $History[$Key + $i]['Email']) {
  118. $i++;
  119. }
  120. $Old[$Key]['StartTime'] = (isset($History[$Key + $i]) && $History[$Key + $i]['Time'] != '0000-00-00 00:00:00') ? $History[$Key + $i]['Time'] : $Joined;
  121. $Old[$Key]['EndTime'] = $Val['Time'];
  122. $Old[$Key]['IP'] = $Val['IP'];
  123. $Old[$Key]['ElapsedTime'] = date(time() + strtotime($Old[$Key]['EndTime']) - strtotime($Old[$Key]['StartTime']));
  124. $Old[$Key]['Email'] = $Val['Email'];
  125. }
  126. if ($Val['Usernames'] != '') {
  127. // Match with old email
  128. $OldMatches[$Key]['Email'] = $Val['Email'];
  129. $OldMatches[$Key]['Username'] = '&nbsp;&nbsp;&#187;&nbsp;'.Users::format_username($Val['UserIDs'], true, true, true);
  130. $OldMatches[$Key]['EndTime'] = $Val['UserSetTimes'];
  131. $OldMatches[$Key]['IP'] = $Val['UserIPs'];
  132. }
  133. }
  134. }
  135. // Clean up arrays
  136. if ($Old ?? false) {
  137. $Old = array_reverse(array_reverse($Old));
  138. $LastOld = count($Old) - 1;
  139. if ($Old[$LastOld]['StartTime'] != $Invite['EndTime']) {
  140. // Make sure the timeline is intact (invite email was used as email for the account in the beginning)
  141. $Old[$LastOld + 1]['Email'] = $Invite['Email'];
  142. $Old[$LastOld + 1]['StartTime'] = $Invite['EndTime'];
  143. $Old[$LastOld + 1]['EndTime'] = $Old[$LastOld]['StartTime'];
  144. $Old[$LastOld + 1]['ElapsedTime'] = date(time() + strtotime($Old[$LastOld + 1]['EndTime'] ) - strtotime($Old[$LastOld + 1]['StartTime']));
  145. $Old[$LastOld + 1]['IP'] = $Invite['IP'];
  146. }
  147. }
  148. // Start page with current email
  149. ?>
  150. <div class="thin">
  151. <div class="header">
  152. <h2>Email history for <a href="user.php?id=<?=$UserID ?>"><?=$Username ?></a></h2>
  153. <div class="linkbox center">
  154. <a href="userhistory.php?action=email&amp;userid=<?=$UserID?>" class="brackets">Old email history</a>
  155. </div>
  156. </div>
  157. <br />
  158. <table width="100%">
  159. <tr class="colhead">
  160. <td>Current email</td>
  161. <td>Start</td>
  162. <td>End</td>
  163. <td>Current IP <a href="userhistory.php?action=ips&amp;userid=<?=$UserID ?>" class="brackets">H</a></td>
  164. <td>Set from IP</td>
  165. </tr>
  166. <?
  167. $Current['Email'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Current['Email']) : '[Encrypted]';
  168. $Current['CurrentIP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Current['CurrentIP']) : '[Encrypted]';
  169. $Current['IP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Current['IP']) : '[Encrypted]';
  170. ?>
  171. <tr class="row">
  172. <td><?=display_str($Current['Email'])?></td>
  173. <td><?=time_diff($Current['StartTime'])?></td>
  174. <td></td>
  175. <td>
  176. <?=display_str($Current['CurrentIP'])?>
  177. (<?=Tools::get_country_code_by_ajax($Current['CurrentIP'])?>)
  178. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Current['CurrentIP'])?>" class="brackets tooltip" title="Search">S</a>
  179. <a href="http://whatismyipaddress.com/ip/<?=display_str($Current['CurrentIP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  180. <br />
  181. <?=Tools::get_host_by_ajax($Current['CurrentIP'])?>
  182. </td>
  183. <td>
  184. <?=display_str($Current['IP'])?>
  185. (<?=Tools::get_country_code_by_ajax($Current['IP'])?>)
  186. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Current['IP'])?>" class="brackets tooltip" title="Search">S</a>
  187. <a href="http://whatismyipaddress.com/ip/<?=display_str($Current['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  188. <br />
  189. <?=Tools::get_host_by_ajax($Current['IP'])?>
  190. </td>
  191. </tr>
  192. <?
  193. if ($CurrentMatches ?? false) {
  194. // Match on the current email
  195. foreach ($CurrentMatches as $Match) {
  196. $Match['IP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Match['IP']) : '[Encrypted]';
  197. ?>
  198. <tr class="row">
  199. <td><?=$Match['Username']?></td>
  200. <td></td>
  201. <td><?=time_diff($Match['EndTime'])?></td>
  202. <td></td>
  203. <td>
  204. <?=display_str($Match['IP'])?>
  205. (<?=Tools::get_country_code_by_ajax($Match['IP'])?>)
  206. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search">S</a>
  207. <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  208. <br />
  209. <?=Tools::get_host_by_ajax($Match['IP'])?>
  210. </td>
  211. </tr>
  212. <?
  213. }
  214. }
  215. // Old emails
  216. if ($Old ?? false) {
  217. ?>
  218. <tr class="colhead">
  219. <td>Old emails</td>
  220. <td>Start</td>
  221. <td>End</td>
  222. <td>Elapsed</td>
  223. <td>Set from IP</td>
  224. </tr>
  225. <?
  226. $j = 0;
  227. // Old email
  228. foreach ($Old as $Record) {
  229. ++$j;
  230. // Matches on old email
  231. ob_start();
  232. $i = 0;
  233. if ($OldMatches ?? false) {
  234. foreach ($OldMatches as $Match) {
  235. if ($Match['Email'] == $Record['Email']) {
  236. ++$i;
  237. // Email matches
  238. ?>
  239. <tr class="row hidden" id="matches_<?=$j?>">
  240. <td><?=$Match['Username']?></td>
  241. <td></td>
  242. <td><?=time_diff($Match['EndTime'])?></td>
  243. <td></td>
  244. <td>
  245. <?=display_str($Match['IP'])?>
  246. (<?=Tools::get_country_code_by_ajax($Match['IP'])?>)
  247. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search">S</a>
  248. <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  249. <br />
  250. <?=Tools::get_host_by_ajax($Match['IP'])?>
  251. </td>
  252. </tr>
  253. <?
  254. }
  255. }
  256. }
  257. // Save matches to variable
  258. $MatchCount = $i;
  259. $Matches = ob_get_contents();
  260. ob_end_clean();
  261. $Record['Email'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Record['Email']) : '[Encrypted]';
  262. $Record['IP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Record['IP']) : '[Encrypted]';
  263. ?>
  264. <tr class="row">
  265. <td><?=display_str($Record['Email'])?><?=(($MatchCount > 0) ? ' <a href="#" onclick="$(\'#matches_'.$j.'\').gtoggle(); return false;">('.$MatchCount.')</a>' : '')?></td>
  266. <td><?=time_diff($Record['StartTime'])?></td>
  267. <td><?=time_diff($Record['EndTime'])?></td>
  268. <td><?=time_diff($Record['ElapsedTime'])?></td>
  269. <td>
  270. <?=display_str($Record['IP'])?>
  271. (<?=Tools::get_country_code_by_ajax($Record['IP'])?>)
  272. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Record['IP'])?>" class="brackets tooltip" title="Search">S</a>
  273. <a href="http://whatismyipaddress.com/ip/<?=display_str($Record['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  274. <br />
  275. <?=Tools::get_host_by_ajax($Record['IP'])?>
  276. </td>
  277. </tr>
  278. <?
  279. if ($MatchCount > 0) {
  280. if (isset($Matches)) {
  281. echo $Matches;
  282. unset($Matches);
  283. unset($MatchCount);
  284. }
  285. }
  286. }
  287. }
  288. // Invite email (always there)
  289. ?>
  290. <tr class="colhead">
  291. <td>Invite email</td>
  292. <td>Start</td>
  293. <td>End</td>
  294. <td>Age of account</td>
  295. <td>Registration IP address</td>
  296. </tr>
  297. <?
  298. // Matches on invite email
  299. $i = 0;
  300. ob_start();
  301. if ($OldMatches ?? false) {
  302. foreach ($OldMatches as $Match) {
  303. if ($Match['Email'] == $Invite['Email']) {
  304. ++$i;
  305. // Match email is the same as the invite email
  306. $Match['IP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Match['IP']) : '[Encrypted]';
  307. ?>
  308. <tr class="row hidden" id="matches_invite">
  309. <td><?=$Match['Username']?></td>
  310. <td></td>
  311. <td><?=time_diff($Match['EndTime'])?></td>
  312. <td></td>
  313. <td>
  314. <?=display_str($Match['IP'])?>
  315. (<?=Tools::get_country_code_by_ajax($Match['IP'])?>)
  316. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search">S</a>
  317. <a href="http://whatismyipaddress.com/ip/<?=display_str($Match['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  318. <br />
  319. <?=Tools::get_host_by_ajax($Match['IP'])?>
  320. </td>
  321. </tr>
  322. <?
  323. }
  324. }
  325. }
  326. $MatchCount = $i;
  327. $Matches = ob_get_contents();
  328. ob_end_clean();
  329. $Invite['Email'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Invite['Email']) : '[Encrypted]';
  330. $Invite['IP'] = apc_exists('DBKEY') ? DBCrypt::decrypt($Invite['IP']) : '[Encrypted]';
  331. ?>
  332. <tr class="row">
  333. <td><?=display_str($Invite['Email'])?><?=(($MatchCount > 0) ? ' <a href="#" onclick="$(\'#matches_invite\').gtoggle(); return false;">('.$MatchCount.')</a>' : '')?></td>
  334. <td>Never</td>
  335. <td><?=time_diff($Invite['EndTime'])?></td>
  336. <td><?=time_diff($Invite['AccountAge'])?></td>
  337. <td>
  338. <?=display_str($Invite['IP'])?>
  339. (<?=Tools::get_country_code_by_ajax($Invite['IP'])?>)
  340. <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Invite['IP'])?>" class="brackets tooltip" title="Search">S</a>
  341. <a href="http://whatismyipaddress.com/ip/<?=display_str($Invite['IP'])?>" class="brackets tooltip" title="Search WIMIA.com">WI</a>
  342. <br />
  343. <?=Tools::get_host_by_ajax($Invite['IP'])?>
  344. </td>
  345. </tr>
  346. <?
  347. if ($Matches) {
  348. echo $Matches;
  349. }
  350. ?>
  351. </table>
  352. </div>
  353. <? View::show_footer(); ?>