Remove hack to track abuse usage with the one of v20
This commit is contained in:
parent
c740b8aa7d
commit
75d7d2d66b
1 changed files with 46 additions and 8 deletions
|
|
@ -305,14 +305,6 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
|
|||
$moduleobject = $reg[1];
|
||||
if ($moduleobject == 'explorer') { // If we call page to explore details of a service
|
||||
$moduleobject = $regbis[2];
|
||||
} else {
|
||||
// TODO
|
||||
// Increase counter of API access
|
||||
if (getDolGlobalString('API_COUNTER_ENABLED')) {
|
||||
include DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
dolibarr_set_const($db, 'API_COUNTER_COUNT', getDolGlobalInt('API_COUNTER_COUNT') + 1, 'chaine', 1);
|
||||
//var_dump('eeee');exit;
|
||||
}
|
||||
}
|
||||
|
||||
$moduleobject = strtolower($moduleobject);
|
||||
|
|
@ -442,4 +434,50 @@ if (Luracast\Restler\Defaults::$returnResponse) {
|
|||
echo $result;
|
||||
}
|
||||
|
||||
if (getDolGlobalInt("API_ENABLE_COUNT_CALLS") && $api->r->responseCode == 200) {
|
||||
$error = 0;
|
||||
$db->begin();
|
||||
$userid = DolibarrApiAccess::$user->id;
|
||||
|
||||
$sql = "SELECT up.value";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user_param as up";
|
||||
$sql .= " WHERE up.param = 'API_COUNT_CALL'";
|
||||
$sql .= " AND up.fk_user = ".((int) $userid);
|
||||
$sql .= " AND up.entity = ".((int) $conf->entity);
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
$updateapi = false;
|
||||
$nbrows = $db->num_rows($result);
|
||||
if ($nbrows == 0) {
|
||||
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."user_param";
|
||||
$sql2 .= " (fk_user, entity, param, value)";
|
||||
$sql2 .= " VALUES (".((int) $userid).", ".((int) $conf->entity).", 'API_COUNT_CALL', 1)";
|
||||
} else {
|
||||
$updateapi = true;
|
||||
$sql2 = "UPDATE ".MAIN_DB_PREFIX."user_param as up";
|
||||
$sql2 .= " SET up.value = up.value + 1";
|
||||
$sql2 .= " WHERE up.param = 'API_COUNT_CALL'";
|
||||
$sql2 .= " AND up.fk_user = ".((int) $userid);
|
||||
$sql2 .= " AND up.entity = ".((int) $conf->entity);
|
||||
}
|
||||
|
||||
$result2 = $db->query($sql2);
|
||||
if (!$result2) {
|
||||
$modeapicall = $updateapi ? 'updating' : 'inserting';
|
||||
dol_syslog('Error while '.$modeapicall. ' API_COUNT_CALL for user '.$userid, LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
} else {
|
||||
dol_syslog('Error on select API_COUNT_CALL for user '.$userid, LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
$db->rollback();
|
||||
} else {
|
||||
$db->commit();
|
||||
}
|
||||
}
|
||||
|
||||
//session_destroy();
|
||||
|
|
|
|||
Loading…
Reference in a new issue