Page MenuHomePhabricator

No OneTemporary

diff --git a/phplib/logger.php b/phplib/logger.php
index 015ee79..b7adf83 100644
--- a/phplib/logger.php
+++ b/phplib/logger.php
@@ -1,91 +1,101 @@
<?php
require 'Monolog/autoload.php';
use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Handler\BrowserConsoleHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Processor\WebProcessor;
global $logger;
$logger = new Logger('WEB');
$syslog = new SyslogHandler('cdrtool', 'local0');
$formatter = new LineFormatter("%channel%: %message% %extra%");
$syslog->setFormatter($formatter);
$logger->pushHandler($syslog);
$logger->pushProcessor(new WebProcessor(null, ['ip']));
global $browserLogger;
$browserLogger = new Logger('CDRTool');
$console= new BrowserConsoleHandler();
$browserLogger->pushHandler($console);
+function changeLoggerChannel($name)
+{
+ global $logger;
+ $logger = $logger->withName($name);
+ $handler = $logger->popHandler();
+ $formatter = new LineFormatter("%channel%: %message% %extra%", null, false, true);
+ $handler->setFormatter($formatter);
+ $logger->pushHandler($handler);
+}
+
function logger($message, $level = 'notice')
{
if ($level == 'notice') {
notice($message);
} elseif ($level == 'error') {
error($message);
} elseif ($level == 'critical') {
critical($message);
}
}
function loggerAndPrint($message, $level = 'notice')
{
if ($level == 'notice') {
noticeAndPrint($message);
}
}
function notice($message)
{
global $logger;
$logger->notice($message);
}
function warning($message)
{
global $logger;
$logger->warning($message);
}
function error($message)
{
global $logger;
$logger->error($message);
}
function critical($message)
{
global $logger;
$logger->critical($message);
}
function noticeAndPrint($message)
{
print "$message";
notice($message);
}
function warningAndPrint($message)
{
global $logger;
print "$message";
$logger->warning($message);
}
function errorAndPrint($message)
{
global $logger;
print "$message";
$logger->error($message);
}
function criticalAndPrint($message)
{
print "$message";
critical($message);
}
diff --git a/scripts/OpenSIPS/quotaCheck.php b/scripts/OpenSIPS/quotaCheck.php
index 72c8711..58a9c5c 100755
--- a/scripts/OpenSIPS/quotaCheck.php
+++ b/scripts/OpenSIPS/quotaCheck.php
@@ -1,80 +1,73 @@
#!/usr/bin/env php
<?php
/**
* This script blocks accounts in OpenSIPS
* based on platform wide or user specified quota
* - quota can be specified in opensips.subscriber.quota
* - account is blocked by adding SIP account in group quota
* and configuring opensips.cfg to reject calls from such users
* - Blocked Users must be deblocked manualy and their quota
* must be changed to a higher value otherwise
* subscriber gets blocked again at the next script run
* - Add this script to cron to run every 5 minutes
* - Notifications are sent once to subscribers
*/
//$verbose=1;
set_time_limit(0);
require '/etc/cdrtool/global.inc';
require 'cdr_generic.php';
require 'rating.php';
// override logger
-use Monolog\Formatter\LineFormatter;
-
-global $logger;
-$logger = $logger->withName('quotaCheck');
-$handler = $logger->popHandler();
-$formatter = new LineFormatter("%channel%: %message% %extra%", null, false, true);
-$handler->setFormatter($formatter);
-$logger->pushHandler($handler);
+changeLoggerChannel('quotaCheck');
$b = time();
$lockFile = sprintf("/var/lock/CDRTool_QuotaCheck.lock");
$abort_text = "Another check is in progress. Try again later.\n";
$f = fopen($lockFile, "w");
if (flock($f, LOCK_EX + LOCK_NB, $w)) {
if ($w) {
print $abort_text;
critical($abort_text);
exit(2);
}
} else {
print $abort_text;
critical($abort_text);
exit(1);
}
foreach ($DATASOURCES as $k => $v) {
if (strlen($v["UserQuotaClass"])) {
unset($CDRS);
$class_name = $v["class"];
$CDRS = new $class_name($k);
$Quota_class = $v["UserQuotaClass"];
$log=sprintf("Checking user quotas for data source %s\n", $v['name']);
logger($log);
//print $log;
$Quota = new $Quota_class($CDRS);
$Quota->checkQuota($v['UserQuotaNotify']);
$d = time() - $b;
if ($d > 5) {
$log = sprintf("Runtime: %d s", $d);
logger($log);
}
}
}
function deleteQuotaCheckLockfile($lockFile)
{
if (!unlink($lockFile)) {
errorAndPrint("Error: cannot delete lock file $lockFile");
}
}
diff --git a/scripts/OpenSIPS/quotaDeblock.php b/scripts/OpenSIPS/quotaDeblock.php
index 3223b39..4194227 100755
--- a/scripts/OpenSIPS/quotaDeblock.php
+++ b/scripts/OpenSIPS/quotaDeblock.php
@@ -1,68 +1,71 @@
#!/usr/bin/env php
<?php
/**
* This script blocks accounts in OpenSIPS
* based on platform wide or user specified quota
* - quota can be specified in opensips.subscriber.quota
* - account is blocked by adding SIP account in group quota
* and configuring opensips.cfg to reject calls from such users
* - Blocked Users must be deblocked manualy and their quota
* must be changed to a higher value otherwise
* subscriber gets blocked again at the next script run
* - Add this script to cron to run every 5 minutes
* - Notifications are sent once to subscribers
*/
// $verbose=1;
set_time_limit(0);
require '/etc/cdrtool/global.inc';
require 'cdr_generic.php';
require 'rating.php';
+// override logger
+changeLoggerChannel('quotaDeblock');
+
$b = time();
$lockFile = sprintf("/var/lock/CDRTool_QuotaDeblock.lock");
$abort_text = "Another deblock process is in progress. Try again later.\n";
$f = fopen($lockFile, "w");
if (flock($f, LOCK_EX + LOCK_NB, $w)) {
if ($w) {
print $abort_text;
syslog(LOG_NOTICE, $abort_text);
exit(2);
}
} else {
print $abort_text;
syslog(LOG_NOTICE, $abort_text);
exit(1);
}
foreach ($DATASOURCES as $k => $v) {
if (strlen($v["UserQuotaClass"])) {
unset($CDRS);
$class_name = $v["class"];
$CDRS = new $class_name($k);
$Quota_class = $v["UserQuotaClass"];
$log = sprintf("Checking user quotas for data source %s\n", $v['name']);
syslog(LOG_NOTICE, $log);
//print $log;
$Quota = new $Quota_class($CDRS);
$Quota->deblockAccounts();
$d = time()-$b;
$log = sprintf("Runtime: %d s", $d);
syslog(LOG_NOTICE, $log);
}
}
function deleteQuotaDeblock($lockFile)
{
if (!unlink($lockFile)) {
print "Error: cannot delete lock file $lockFile. Aborting.\n";
syslog(LOG_NOTICE, "Error: cannot delete lock file $lockFile");
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Nov 26, 4:03 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3414104
Default Alt Text
(6 KB)

Event Timeline