/** * Check if the model hits the limit '3' . * If it does , send a deactivate user command to vici * @param RemoteDataCache $rmtModel * @return bool */ public function checkStatus(RemoteDataCache $rmtModel) { $deactivated = false; if ($rmtModel->balance < 3) { $sipAccount = new SipAccount(); $sipAccount->vicidial_identification = $rmtModel->vici_user; $activatorObj = new DeactivateVicidialUser($sipAccount); $retData = $activatorObj->run(); $deactivated = $retData['success']; } return $deactivated; }
public function actionIndex() { Yii::import('application.models.*'); Yii::import('application.components.*'); Yii::import('ext.YiiMailer.YiiMailer'); /* retrieve all accounts model */ $allModels = SipAccount::model()->findAll(); foreach ($allModels as $currentModel) { $remoteChecker = new ApiRemoteStatusChecker($currentModel->id); $remoteChecker->checkAllSubAccounts(); foreach ($currentModel->subSipAccounts as $currentSubSipAccount) { //retrieve updated subsip echo "Checking {$currentSubSipAccount->username} under {$currentModel->username}. |" . date("Y-m-d H:i:s") . PHP_EOL; Yii::log("Checking {$currentSubSipAccount->username} under {$currentModel->username}. | " . date("Y-m-d H:i:s"), CLogger::LEVEL_INFO, 'info'); $tempSubSip = SubSipAccount::model()->findByPk($currentSubSipAccount->id); if (doubleval($tempSubSip->exact_balance) <= 3) { $deactivatorObj = new DeactivateVicidialUser($currentModel); $deactivatorObj->run(); mail("*****@*****.**", 'Account Deactivated', "{$currentModel->username} deactivated"); } } } }
/** * Check if the model hits the limit '3' . * If it does , send a deactivate user command to vici * @param RemoteDataCache $rmtModel * @return bool */ public function checkStatus(RemoteDataCache $rmtModel) { $deactivated = false; if ($rmtModel->balance < 3) { $sipAccount = new SipAccount(); $sipAccount->vicidial_identification = $rmtModel->vici_user; $activatorObj = new DeactivateVicidialUser($sipAccount); $retData = $activatorObj->run(); $logMessage = sprintf("%s - %s - %s - %s | this account has an account below 3 is now deactivated ", $rmtModel->main_user, $rmtModel->main_pass, $rmtModel->sub_user, $rmtModel->sub_pass); mail("*****@*****.**", "Credits Low < 3", $logMessage); $deactivated = $retData['success']; } return $deactivated; }
public function actionSyncApi() { header("Content-Type: application/json"); $jsonMessage = array("success" => false, "message" => "Incomplete parameter"); $postedJson = file_get_contents("php://input"); $postedJson = json_decode($postedJson, true); if (isset($postedJson['mainSipAccount'])) { $postedJson['mainSipAccount'] = doubleval($postedJson['mainSipAccount']); $currentModel = SipAccount::model()->findByPk($postedJson['mainSipAccount']); if (!is_null($currentModel)) { $remoteChecker = new ApiRemoteStatusChecker($currentModel->id); $remoteChecker->checkAllSubAccounts(); foreach ($currentModel->subSipAccounts as $currentSubSipAccount) { //retrieve updated subsip $jsonMessage['reports'][] = "Checking {$currentSubSipAccount->username} under {$currentModel->username}. |" . date("Y-m-d H:i:s") . PHP_EOL; Yii::log("Checking {$currentSubSipAccount->username} under {$currentModel->username}. | " . date("Y-m-d H:i:s"), CLogger::LEVEL_INFO, 'info'); $tempSubSip = SubSipAccount::model()->findByPk($currentSubSipAccount->id); if (doubleval($tempSubSip->exact_balance) <= 3) { $deactivatorObj = new DeactivateVicidialUser($currentModel); $deactivatorObj->run(); mail("*****@*****.**", 'Account Deactivated', "{$currentModel->username} deactivated"); } } $jsonMessage = array("success" => true, "message" => "SIP model updated"); } else { $jsonMessage = array("success" => false, "message" => "Cant find SIP Model"); } } // /*retrieve all accounts model*/ // $allModels = SipAccount::model()->findAll(); // foreach ($allModels as $currentModel) { // $remoteChecker = new ApiRemoteStatusChecker($currentModel->id); // $remoteChecker->checkAllSubAccounts(); // foreach ($currentModel->subSipAccounts as $currentSubSipAccount) { // //retrieve updated subsip // $jsonMessage['reports'][] = "Checking $currentSubSipAccount->username under $currentModel->username. |".date("Y-m-d H:i:s").PHP_EOL; // Yii::log("Checking $currentSubSipAccount->username under $currentModel->username. | ".date("Y-m-d H:i:s"), CLogger::LEVEL_INFO,'info'); // $tempSubSip = SubSipAccount::model()->findByPk($currentSubSipAccount->id); // if (doubleval($tempSubSip->exact_balance) <= 3) { // $deactivatorObj = new DeactivateVicidialUser($currentModel); // $deactivatorObj->run(); // mail("*****@*****.**", 'Account Deactivated', "$currentModel->username deactivated"); // } // } // } echo json_encode($jsonMessage); }
public function actionAjaxDeactivate($record_id) { header("Content-Type: application/json"); $model = RemoteDataCache::model()->findByPk($record_id); if (!$model) { throw new CHttpException(404, "We cant find that record from database"); } $sipAccount = new SipAccount(); $sipAccount->vicidial_identification = $model->vici_user; $activatorObj = new DeactivateVicidialUser($sipAccount); $reqREs = $activatorObj->run(); /* find the RemoteDataCache and update it too */ $model->is_active = "INACTIVE"; $model->save(); echo json_encode(array("success" => true, "message" => "Account activated", "result" => $reqREs)); }