Commit 7e4b11ce authored by Maikel Zweerink's avatar Maikel Zweerink

Fixed PHP error logging on JSON REST API (issue @303). Updated WhatsApi version…

Fixed PHP error logging on JSON REST API (issue @303). Updated WhatsApi version and implemented variable top x users in Statistics page.
parent bf02dc29
......@@ -743,9 +743,16 @@ switch($_GET['whatsspy']) {
echo json_encode($result_global);
break;
case 'top10_users':
case 'top_usage_users':
// Top 10 setup
$result_top10 = array();
$result_topusers = array();
// Add metadata: the amount of users (in this group)
$select_meta = $DBH->prepare('SELECT COUNT(1) FROM accounts a '.$group_query_acc_join);
$select_meta -> execute();
$result_topusers['meta'] = $select_meta -> fetch(PDO::FETCH_ASSOC);
$top_limit = (is_numeric($_GET['users']) ? round($_GET['users']) : 10);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -757,9 +764,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['today'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['today'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -772,9 +779,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['yesterday'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['yesterday'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -787,9 +794,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['2days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['2days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -802,9 +809,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['3days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['3days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -817,9 +824,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['4days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['4days_ago'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -831,9 +838,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['24hours'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['24hours'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -845,9 +852,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['7days'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['7days'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -859,9 +866,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['14days'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['14days'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -873,9 +880,9 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['31days'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['31days'] = $select->fetchAll(PDO::FETCH_ASSOC);
$select = $DBH->prepare('SELECT '.$select_top.' a.name, ROUND(EXTRACT(\'epoch\' FROM SUM(sh."end" - sh."start"))) "online", COUNT(sh.status) "count"
FROM accounts a
......@@ -886,11 +893,11 @@ switch($_GET['whatsspy']) {
AND "end" IS NOT NULL
GROUP BY a.id, a.name
ORDER BY online DESC, count DESC
LIMIT 10');
$select -> execute();
$result_top10['alltime'] = $select->fetchAll(PDO::FETCH_ASSOC);
LIMIT :limit');
$select -> execute(array(':limit' => $top_limit));
$result_topusers['alltime'] = $select->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result_top10);
echo json_encode($result_topusers);
break;
case 'user_status_analytics_user':
// user data for pie charts
......
......@@ -653,7 +653,7 @@ function track() {
//
// Keep connection alive (<300s)
if($pollCount % calculateTick($tracking_ticks['keep-alive']) == 0) {
tracker_log('[keep-alive] Ping sent to WhatsApp server.');
tracker_log('[keep-alive] Ping sent.'."\r", true, false);
$wa->sendPing();
}
// usage of 39512f5ea29c597f25483697471ac0b00cbb8088359c219e98fa8bdaf7e079fa
......
......@@ -19,8 +19,8 @@ class Constants
const WHATSAPP_REQUEST_HOST = 'v.whatsapp.net/v2/code'; // The request code host.
const WHATSAPP_SERVER = 's.whatsapp.net'; // The hostname used to login/send messages.
const WHATSAPP_DEVICE = 'S40'; // The device name.
const WHATSAPP_VER = '2.12.68'; // The WhatsApp version.
const WHATSAPP_USER_AGENT = 'WhatsApp/2.12.68 S40Version/14.26 Device/Nokia302'; // User agent used in request/registration code.
const WHATSAPP_VER_CHECKER = 'https://coderus.openrepos.net/whitesoft/whatsapp_version'; // Check WhatsApp version
const WHATSAPP_VER = '2.12.81'; // The WhatsApp version.
const WHATSAPP_USER_AGENT = 'WhatsApp/2.12.81 S40Version/14.26 Device/Nokia302'; // User agent used in request/registration code.
const WHATSAPP_VER_CHECKER = 'https://coderus.openrepos.net/whitesoft/whatsapp_scratch'; // Check WhatsApp version
}
......@@ -37,6 +37,7 @@ abstract class AllEvents
}
//Adding to this list? Please put them in alphabetical order!
public function onCallReceived($mynumber, $from, $id, $notify, $time, $callId) {}
public function onClose($mynumber, $error) {}
public function onCodeRegister($mynumber, $login, $password, $type, $expiration, $kind, $price, $cost, $currency, $price_expiration) {}
public function onCodeRegisterFailed($mynumber, $status, $reason, $retry_after) {}
......@@ -94,6 +95,9 @@ abstract class AllEvents
public function onMessagePaused($mynumber, $from, $id, $type, $time) {}
public function onMessageReceivedClient($mynumber, $from, $id, $type, $time, $participant) {}
public function onMessageReceivedServer($mynumber, $from, $id, $type, $time) {}
public function onNumberWasAdded($mynumber, $jid) {}
public function onNumberWasRemoved($mynumber, $jid) {}
public function onNumberWasUpdated($mynumber, $jid) {}
public function onPaidAccount($mynumber, $author, $kind, $status, $creation, $expiration) {}
public function onPaymentRecieved($mynumber, $kind, $status, $creation, $expiration) {}
public function onPing($mynumber, $id) {}
......@@ -107,4 +111,5 @@ abstract class AllEvents
public function onSendPresence($mynumber, $type, $name ) {}
public function onSendStatusUpdate($mynumber, $txt ) {}
public function onStreamError($data) {}
public function onWebSync($mynumber, $from, $id, $syncData, $code, $name) {}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -20,7 +20,7 @@ function generateRequestToken($country, $phone)
// return base64_encode($output);
$const = 'PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk';
$releaseTime = '1425519315543';
$releaseTime = '1430860548912';
$token = md5($const . $releaseTime . $phone);
return $token;
......
......@@ -489,7 +489,7 @@ class TokenMap
if (!$subdict && $token >= 236 && $token < (236 + count(self::$secondaryStrings))) {
$subdict = true;
}
$tokenMap = array();
if ($subdict) {
$tokenMap = self::$secondaryStrings;
} else {
......@@ -499,6 +499,7 @@ class TokenMap
if ($token < 0 || $token > count($tokenMap)) {
return;//fail
}
$string = $tokenMap[$token];
if (!$string) {
throw new Exception("Invalid token/length in GetToken");
......
This diff is collapsed.
......@@ -491,7 +491,7 @@ angular.module('whatsspy', ['ngRoute', 'ngVis', 'whatsspyFilters', 'whatsspyCont
promises[2] = $rootScope.loadGlobalStats('global_stats');
promises[3] = $rootScope.loadGlobalStats('user_status_analytics_user');
promises[4] = $rootScope.loadGlobalStats('user_status_analytics_time');
promises[5] = $rootScope.loadGlobalStats('top10_users');
promises[5] = $rootScope.loadGlobalStats('top_usage_users');
}
// Load any new status
if(Object.keys($rootScope.accountData).length > 0 && slack == false) {
......
......@@ -1146,6 +1146,8 @@ angular.module('whatsspyControllers', [])
$scope.filterGroup = null;
$rootScope.tokenAuth = null;
$scope.showTopUsers = 10;
if($routeParams.token != null) {
if($rootScope.authenticated == true) {
// logout
......@@ -1161,6 +1163,14 @@ angular.module('whatsspyControllers', [])
});
$scope.$watch('filterGroup', function() {
if($scope.showTopUsers != 10) {
$scope.showTopUsers = 10;
} else {
$scope.refreshContent();
}
});
$scope.$watch('showTopUsers', function() {
$scope.refreshContent();
});
......@@ -1200,6 +1210,9 @@ angular.module('whatsspyControllers', [])
if($rootScope.tokenAuth != null) {
query = '&token='+$rootScope.tokenAuth;
}
if(component == 'top_usage_users') {
query = query + '&users='+$scope.showTopUsers;
}
var deferred = $q.defer();
$http({method: 'GET', url: 'api/?whatsspy=getGlobalStats&component='+component+'&group='+$scope.filterGroup + query}).
success(function(data, status, headers, config) {
......@@ -1215,7 +1228,7 @@ angular.module('whatsspyControllers', [])
}
$scope.stats[component] = data;
if(component == 'top10_users') {
if(component == 'top_usage_users') {
if($scope.stats.generated == null) {
$scope.stats.generated = {};
}
......@@ -1268,7 +1281,7 @@ angular.module('whatsspyControllers', [])
promises[0] = $rootScope.loadGlobalStats('global_stats');
promises[1] = $rootScope.loadGlobalStats('user_status_analytics_user');
promises[2] = $rootScope.loadGlobalStats('user_status_analytics_time');
promises[3] = $rootScope.loadGlobalStats('top10_users');
promises[3] = $rootScope.loadGlobalStats('top_usage_users');
$q.all(promises).then(function(greeting) {
$rootScope.showLoader = false;
......
File mode changed from 100644 to 100755
......@@ -432,17 +432,27 @@
</div>
</div>
</span>
<span data-ng-show="stats.top10_users != null">
<span data-ng-show="stats.top_usage_users != null">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> Top 10 tracked users</h3>
<h3 class="panel-title"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> Top {{showTopUsers}} tracked users</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<button data-ng-show="stats.top_usage_users.meta.count <= 20" data-ng-disabled="showTopUsers == 5" data-ng-click="showTopUsers = 5;" type="button" class="btn btn-primary">Top 5</button>
<button data-ng-disabled="showTopUsers == 10" data-ng-click="showTopUsers = 10;" type="button" class="btn btn-primary">Top 10</button>
<button data-ng-show="stats.top_usage_users.meta.count >= 20" data-ng-disabled="showTopUsers == 20" data-ng-click="showTopUsers = 20;" type="button" class="btn btn-primary">Top 20</button>
<button data-ng-show="stats.top_usage_users.meta.count >= 30" data-ng-disabled="showTopUsers == 30" data-ng-click="showTopUsers = 30;" type="button" class="btn btn-primary">Top 30</button>
<button data-ng-show="stats.top_usage_users.meta.count >= 50" data-ng-disabled="showTopUsers == 50" data-ng-click="showTopUsers = 50;" type="button" class="btn btn-primary">Top 50</button>
<button data-ng-show="stats.top_usage_users.meta.count >= 100" data-ng-disabled="showTopUsers == 100" data-ng-click="showTopUsers = 100;" type="button" class="btn btn-primary">Top 100</button>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h4>Top 10 most active users per day - {{stats.generated.top10DayChoice}}</h4>
<h4>Top {{showTopUsers}} most active users per day - {{stats.generated.top10DayChoice}}</h4>
<button data-ng-disabled="stats.generated.top10DayChoice == 'today'" data-ng-click="stats.generated.top10DayChoice = 'today';" type="button" class="btn btn-info">Today</button>
<button data-ng-disabled="stats.generated.top10DayChoice == 'yesterday'" data-ng-click="stats.generated.top10DayChoice = 'yesterday';" type="button" class="btn btn-info">Yesterday</button>
<button data-ng-disabled="stats.generated.top10DayChoice == '2days_ago'" data-ng-click="stats.generated.top10DayChoice = '2days_ago';" type="button" class="btn btn-info">2 days ago</button>
......@@ -457,7 +467,7 @@
<th>Time online</th>
<th>Opened WA</th>
</tr>
<tr data-ng-repeat="user in stats.top10_users[stats.generated.top10DayChoice]">
<tr data-ng-repeat="user in stats.top_usage_users[stats.generated.top10DayChoice]">
<td>
<a data-ng-show="tokenAuth == null" data-ng-href="#/overview#{{user.id}}" class="whatsspy-clean-link"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{user.name | emptyName}}</a>
......@@ -471,7 +481,7 @@
</table>
</div>
<div class="col-md-6">
<h4>Top 10 most active users in total - {{stats.generated.top10TimeChoice}}</h4>
<h4>Top {{showTopUsers}} most active users in total - {{stats.generated.top10TimeChoice}}</h4>
<button data-ng-disabled="stats.generated.top10TimeChoice == 'alltime'" data-ng-click="stats.generated.top10TimeChoice = 'alltime';" type="button" class="btn btn-info">All</button>
<button data-ng-disabled="stats.generated.top10TimeChoice == '31days'" data-ng-click="stats.generated.top10TimeChoice = '31days';" type="button" class="btn btn-info">31 days</button>
<button data-ng-disabled="stats.generated.top10TimeChoice == '14days'" data-ng-click="stats.generated.top10TimeChoice = '14days';" type="button" class="btn btn-info">14 days</button>
......@@ -486,7 +496,7 @@
<th>Time online</th>
<th>Opened WA</th>
</tr>
<tr data-ng-repeat="user in stats.top10_users[stats.generated.top10TimeChoice]">
<tr data-ng-repeat="user in stats.top_usage_users[stats.generated.top10TimeChoice]">
<td>
<a data-ng-show="tokenAuth == null" data-ng-href="#/overview#{{user.id}}" class="whatsspy-clean-link"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{user.name | emptyName}}</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment