function track() { global $DBH, $wa, $tracking_numbers, $whatsspyNMAKey, $crawl_time, $whatsappAuth; $pollCount = 0; $lastseenCount = 0; $statusMsgCount = 0; $picCount = 0; $crawl_time = time(); setupWhatsappHandler(); retrieveTrackingUsers(); echo '[init] Started tracking with phonenumber ' . $whatsappAuth['number'] . "\n"; startTrackerHistory(); sendNMAMessage($whatsspyNMAKey, 'WhatsSpy', 'Tracker started.', 'Whatsspy tracker has started tracking ' . count($tracking_numbers) . ' users.', '1'); while (true) { $crawl_time = time(); // Socket read $tick_start = microtime(true); $wa->pollMessage(); $tick_end = microtime(true); echo '[poll #' . $pollCount . '] Tracking ' . count($tracking_numbers) . ' users.' . "\n"; // 1) LAST SEEN PRIVACY // // Check lastseen (every 2 hours) if ($pollCount % calculateTick(60 * 60 * 2) == 0) { echo '[lastseen #' . $lastseenCount . '] Checking ' . count($tracking_numbers) . ' users.' . "\n"; foreach ($tracking_numbers as $number) { $wa->sendGetRequestLastSeen($number); } $lastseenCount++; } // 2) STATUS MESSAGE (and privacy) // // Check status message (every 2 hours) if ($pollCount % calculateTick(60 * 60 * 2) == 0) { echo '[status-msg #' . $statusMsgCount . '] Checking ' . count($tracking_numbers) . ' users.' . "\n"; if (count($tracking_numbers) > 0) { $wa->sendGetStatuses($tracking_numbers); } $statusMsgCount++; } // 3) PROFILE PICTURE (and privacy) // // Check profile picture (every 6 hours) if ($pollCount % calculateTick(60 * 60 * 6) == 0) { echo '[profile-pic #' . $picCount . '] Checking ' . count($tracking_numbers) . ' users.' . "\n"; foreach ($tracking_numbers as $number) { $wa->sendGetProfilePicture($number, true); } $picCount++; } // 4) DATABASE ACCOUNT REFRESH // // Check user database and refresh user set every hour. // Check this at the end if ($pollCount % calculateTick(60 * 60 * 1) == calculateTick(60 * 60 * 1 - 1)) { retrieveTrackingUsers(true); } // 5) DATABASE ACCOUNT VERIFY CHECK // // Verify any freshly inserted accounts and check if there really whatsapp users. // Check everey 5 minutes. // When the user is verified the number is automaticly added to the tracker running DB. if ($pollCount % calculateTick(60 * 5) == 0) { verifyTrackingUsers(); } // 6) WHATSAPP PING // // Keep connection alive (<300s) if ($pollCount % calculateTick(60 * 2) == 0) { echo '[keep-alive] Ping sent' . "\n"; $wa->sendPing(); } // usage of 39512f5ea29c597f25483697471ac0b00cbb8088359c219e98fa8bdaf7e079fa $pollCount++; // Draw the socket read a draw if ($tick_end - $tick_start < 2.0) { sleep(2); } } }
function sendNotification($DBH, $wa, $whatsspyNotificatons, $type, $data) { global $application_name; if ($whatsspyNotificatons == null) { return; } foreach ($whatsspyNotificatons as $name => $notificationAgent) { if ($notificationAgent['enabled'] == true) { if ($type == 'tracker' && @$notificationAgent['notify-tracker'] == true) { // Tracker notification can be sent. switch ($name) { case 'nma': sendNMAMessage($notificationAgent['key'], $application_name, $data['title'], $data['description'], '2'); break; case 'ln': sendLNMessage($notificationAgent['key'], $data['title'], $data['description'], @$data['image']); break; case 'script': sendCustomScriptMessage($notificationAgent['cmd'], $type, $data); break; default: break; } } else { if ($type == 'user' && $notificationAgent['notify-user'] == true) { // User notification can be sent. // Check if user is enabled as notifyable $user = isUserNotifyable($DBH, $data['number'], $data['notify_type']); if ($user['notifyable'] == true) { $filteredTitle = str_replace(':name', $user['name'], $data['title']); $filteredDesc = str_replace(':name', $user['name'], $data['description']); switch ($name) { case 'nma': sendNMAMessage($notificationAgent['key'], $application_name, $filteredTitle, $filteredDesc, '1'); break; case 'ln': sendLNMessage($notificationAgent['key'], $filteredTitle, $filteredDesc, @$data['image']); break; case 'wa': sendWhatsAppMessage($wa, $notificationAgent['key'], $filteredDesc, @$data['image']); break; case 'script': sendCustomScriptMessage($notificationAgent['cmd'], $type, $data, $user); break; default: break; } } } } } } }