/** * @return SubSipAccount $mdl * @throws CHttpException */ public function getSubSipAccountModel() { $mdl = SubSipAccount::model()->findByPk($this->subSipOwner); if (!$mdl) { throw new CHttpException(404, "Cant find Sub SIP Account model"); } return $mdl; }
protected function check($command, $username, $password, $customer, $customerpassword, SubSipAccount $currentSubSipAccount) { $curlURL = "https://77.72.173.130/API/Request.ashx?"; $httparams = compact('command', 'username', 'password', 'customer', 'customerpassword'); $curlURL .= http_build_query($httparams); $curlres = curl_init($curlURL); curl_setopt($curlres, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlres, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curlres, CURLOPT_SSL_VERIFYPEER, false); $curlResRaw = curl_exec($curlres); /*check result and update the model*/ $xmlObject = simplexml_load_string($curlResRaw); if (isset($xmlObject->Result) && $xmlObject->Result === "Failed") { $currentSubSipAccount->customer_name = $xmlObject->Customer; $currentSubSipAccount->balance = 0; $currentSubSipAccount->exact_balance = 0; if (!$currentSubSipAccount->save()) { $logMessage = " {$curlResRaw} \t " . CVarDumper::dumpAsString($currentSubSipAccount); Yii::log("CHtml::errorSummary({$currentSubSipAccount})", CLogger::LEVEL_ERROR, 'info'); } } else { // if ($xmlObject->Blocked == "False") { // $currentSubSipAccount->account_status = 'active'; // }else{ // $currentSubSipAccount->account_status = 'blocked'; // } $currentSubSipAccount->customer_name = $xmlObject->Customer; $currentSubSipAccount->last_checked_bal = $currentSubSipAccount->exact_balance; $currentSubSipAccount->balance = doubleval($xmlObject->Balance); $currentSubSipAccount->exact_balance = doubleval($xmlObject->SpecificBalance); /*end of check blocked*/ if (!$currentSubSipAccount->save()) { Yii::log(CHtml::errorSummary($currentSubSipAccount), CLogger::LEVEL_ERROR, 'info'); } } }
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"); } } } }
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 actionDeactivate($subAccount) { $childCur = SubSipAccount::model()->findByPk($subAccount); $activatorObj = new DeactivateVicidialUser($childCur->parentSip); $activatorObj->run(); Yii::app()->user->setFlash("info", "Account <strong>{$childCur->username}</strong> deactivated"); $this->redirect(Yii::app()->request->urlReferrer); }