Fix Airtime bandwidth limit suspension code
This commit is contained in:
parent
24f488cac2
commit
0fc4f6c26f
|
@ -12,7 +12,7 @@ define('COMPANY_SITE' , 'Sourcefabric.org');
|
||||||
define('COMPANY_SITE_URL' , 'http://sourcefabric.org/');
|
define('COMPANY_SITE_URL' , 'http://sourcefabric.org/');
|
||||||
define('SUPPORT_EMAIL_ADDRESS', "help@sourcefabric.org");
|
define('SUPPORT_EMAIL_ADDRESS', "help@sourcefabric.org");
|
||||||
|
|
||||||
define("AIRTIMEPRO_API_URL", "https://account.sourcefabric.com/api/");
|
define("AIRTIMEPRO_API_URL", "https://account.sourcefabric.com:5001/api/");
|
||||||
|
|
||||||
define('HELP_URL' , 'http://help.sourcefabric.org/');
|
define('HELP_URL' , 'http://help.sourcefabric.org/');
|
||||||
define('FAQ_URL' , 'https://sourcefabricberlin.zendesk.com/hc/en-us/sections/200994309-Airtime-FAQ');
|
define('FAQ_URL' , 'https://sourcefabricberlin.zendesk.com/hc/en-us/sections/200994309-Airtime-FAQ');
|
||||||
|
|
|
@ -147,11 +147,13 @@ class ApiController extends Zend_Controller_Action
|
||||||
public function bandwidthUsageAction() {
|
public function bandwidthUsageAction() {
|
||||||
$bandwidthUsage = json_decode($this->getRequest()->getParam("bandwidth_data"));
|
$bandwidthUsage = json_decode($this->getRequest()->getParam("bandwidth_data"));
|
||||||
$usageBytes = 0;
|
$usageBytes = 0;
|
||||||
foreach ($bandwidthUsage as $entry) {
|
if (!empty($bandwidthUsage)) {
|
||||||
// TODO: store the IP address for future use
|
foreach ($bandwidthUsage as $entry) {
|
||||||
$ts = strtotime($entry->timestamp);
|
// TODO: store the IP address for future use
|
||||||
if ($ts > Application_Model_Preference::getBandwidthLimitUpdateTimer()) {
|
$ts = strtotime($entry->timestamp);
|
||||||
$usageBytes += $entry->bytes;
|
if ($ts > Application_Model_Preference::getBandwidthLimitUpdateTimer()) {
|
||||||
|
$usageBytes += $entry->bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Application_Model_Preference::incrementBandwidthLimitCounter($usageBytes);
|
Application_Model_Preference::incrementBandwidthLimitCounter($usageBytes);
|
||||||
|
@ -160,10 +162,11 @@ class ApiController extends Zend_Controller_Action
|
||||||
$usage = Application_Model_Preference::getBandwidthLimitCounter();
|
$usage = Application_Model_Preference::getBandwidthLimitCounter();
|
||||||
if ($usage > Application_Model_Preference::getBandwidthLimit()) {
|
if ($usage > Application_Model_Preference::getBandwidthLimit()) {
|
||||||
$CC_CONFIG = Config::getConfig();
|
$CC_CONFIG = Config::getConfig();
|
||||||
|
$url = AIRTIMEPRO_API_URL . "/station/" . $CC_CONFIG['stationId'] . "/suspend";
|
||||||
$user = array('', $CC_CONFIG['apiKey'][0]);
|
$user = array('', $CC_CONFIG['apiKey'][0]);
|
||||||
$data = array('reason' => "Bandwidth limit exceeded");
|
$data = array('reason' => "Bandwidth limit exceeded");
|
||||||
try {
|
try {
|
||||||
$result = Application_Common_HTTPHelper::doPost(AIRTIMEPRO_API_URL, $user, $data);
|
$result = Application_Common_HTTPHelper::doPost($url, $user, $data);
|
||||||
Logging::info($result);
|
Logging::info($result);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
Loading…
Reference in New Issue