public function actionIndex() { $initialSeriesData = array(); $sipAccountNames = array(); $chartInitialData = array(); $criteria = new CDbCriteria(); $criteria->order = "vici_user ASC"; $allRemoteModels = RemoteDataCache::model()->findAll($criteria); foreach ($allRemoteModels as $key => $currentRemoteData) { $tempColorContainer = "red"; //collect sip accounts $sipAccountNames[$key] = $currentRemoteData->sub_user; //register chart data array $chartInitialData = array("name" => $currentRemoteData->sub_user, "data" => $currentRemoteData->exact_balance); if (doubleval($currentRemoteData->exact_balance) >= 5) { $tempColorContainer = "#7CB5EC"; } else { if ($currentRemoteData->exact_balance > 3) { $tempColorContainer = "orange"; } } //register series data $initialSeriesData[$key] = array("y" => doubleval($currentRemoteData->exact_balance), "color" => $tempColorContainer); } $this->render('index', array('chartData' => $chartInitialData, 'seriesDataStr' => json_encode($initialSeriesData), 'sipAccountsStr' => json_encode($sipAccountNames))); }
/** * * @return RemoteDataCache $remoteDataCacheObj */ public function getRemoteDataCacheObject() { /** * @var RemoteDataCache $remoteDataCacheObj */ $remoteDataCacheObj = RemoteDataCache::model()->findByPk($this->remoteDataCacheId); return $remoteDataCacheObj; }
public function sync(RemoteDataCache $model) { if (!$model) { throw new Exception("RemoteDataCache cannot be null"); } /* get information from remote api server */ $voipInfoRetriever = new BestVOIPInformationRetriever(); $last_balance = $model->balance; $remoteVoipResult = $voipInfoRetriever->getInfo($model->main_user, $model->main_pass, $model->sub_user, $model->sub_pass); $model->balance = doubleval($remoteVoipResult->getBalance()); $model->exact_balance = doubleval($remoteVoipResult->getSpecificBalance()); $model->last_balance = $last_balance; $model->save(); /* check notification */ // $this->checkNotification($model); /* check status */ // $this->checkStatus($model); }
/** * @param RemoteDataCache $remoteDataCacheMdl * @return bool */ public function activateAccount(RemoteDataCache $remoteDataCacheMdl) { $sipAccount = new SipAccount(); $sipAccount->vicidial_identification = $remoteDataCacheMdl->vici_user; /** * @var VicidialDbDeactivator $deactivator */ $activator = Yii::app()->vicidialActivator; $activator->setVicidialUser($sipAccount->vicidial_identification); if ($activator->run()) { $groupId = uniqid(); ViciActionLogger::logAction(ViciLogAction::VICILOG_ACTION_SUBSIP_ACTIVIVATE, "{$remoteDataCacheMdl->sub_user} under {$remoteDataCacheMdl->main_user} is now activated", 0, $groupId, time()); Yii::log(json_encode("{$remoteDataCacheMdl->sub_user} under {$remoteDataCacheMdl->main_user} is now activated"), CLogger::LEVEL_INFO, "activation"); } else { Yii::log(json_encode("deactivation failed {$sipAccount->vicidial_identification}"), CLogger::LEVEL_INFO, "activation"); } /* find the RemoteDataCache and update it too */ $remoteDataCacheMdl->is_active = "ACTIVE"; return $remoteDataCacheMdl->save(); }
public function actionMonitor() { //check if cookie is present , if (isset(Yii::app()->request->cookies['monitoredAccounts'])) { $accountsToMonitorStr = Yii::app()->request->cookies['monitoredAccounts']->value; $accountsToMonitorArr = explode(",", $accountsToMonitorStr); $criteria = new CDbCriteria(); $criteria->addInCondition('sub_user', $accountsToMonitorArr); $accountsToMonitor = RemoteDataCache::model()->findAll($criteria); $this->render('monitor', compact('accountsToMonitor')); } else { $this->redirect(array('/activeMonitor/index')); } }
public function actionAutoTopUp() { if (isset($_POST['AutoTopUpUpdateForm'])) { $formModel = new AutoTopUpUpdateForm(); $formModel->scenario = "updateVal"; $formModel->setAttributes($_POST['AutoTopUpUpdateForm']); if ($formModel->validate() && $formModel->updateRecord()) { $remoteDataCache = $formModel->getRemoteDataCacheObject(); Yii::app()->user->setFlash("success", "Success! Auto top-up configuration for {$remoteDataCache->sub_user} under {$remoteDataCache->main_user} was updated. "); } else { Yii::app()->user->setFlash("error", CHtml::errorSummary($formModel)); } } $criteria = new CDbCriteria(); $criteria->addCondition("main_user <> 'Prion1967'"); $criteria->order = "vici_user ASC"; $allRemoteDataCache = RemoteDataCache::model()->findAll($criteria); $this->render('//control/config/autoTopUp', compact('allRemoteDataCache')); }
public function actionAccount($mainusername) { $criteria = new CDbCriteria(); $criteria->compare("main_user", $mainusername); $remoteDataArr = RemoteDataCache::model()->findAll($criteria); foreach ($remoteDataArr as $key => $currentRemoteObj) { /* * @var RemoteDataCache $currentRemoteObj * */ $currentRemoteObj->is_active = "INACTIVE"; $currentRemoteObj->save(); // $sipAccount = new SipAccount(); // $sipAccount->username = $mainusername; // $sipAccount->vicidial_identification = $currentRemoteObj->vici_user; /** * @var VicidialDbDeactivator $deactivator */ $deactivator = Yii::app()->vicidialDeactivator; $deactivator->setVicidialUser($currentRemoteObj->vici_user); $logsReq = ""; if ($deactivator->run()) { $logsReq = "{$currentRemoteObj->vici_user} is now deactivated"; Yii::log(json_encode("{$currentRemoteObj->sub_user} under {$currentRemoteObj->main_user} is now deactivated"), CLogger::LEVEL_INFO, "deactivation"); } else { $logsReq = "Deactivation failed {$currentRemoteObj->vici_user}"; } $logMessage = sprintf("%s - %s - %s - %s | this account is now deactivated | remote log : %s ", $currentRemoteObj->main_user, $currentRemoteObj->main_pass, $currentRemoteObj->sub_user, $currentRemoteObj->sub_pass, $logsReq); ViciActionLogger::logAction(ViciLogAction::VICILOG_ACTION_SUBSIP_DEACTIVIVATE, "{$currentRemoteObj->sub_user} under {$currentRemoteObj->main_user} is now deactivated", 0, uniqid(), time()); mail("*****@*****.**", "Credits Low < 3", $logMessage); Yii::log($logMessage, CLogger::LEVEL_INFO, 'info'); if ($currentRemoteObj->main_user === "lj2016888") { mail("*****@*****.**", "Credits Low < 3", $logMessage); } /** * Auto top up */ $this->autoTopUpCheck($currentRemoteObj); } header("Content-Type: application/json"); echo json_encode(array("success" => true, "message" => "account disabled")); }
public function actionIndex() { Yii::import('application.models.*'); echo "Cleaning all AutoTopupConfiguration \n"; AutoTopupConfiguration::model()->deleteAll(); $allAccounts = RemoteDataCache::model()->findAll(); foreach ($allAccounts as $currentAccount) { $freeVoipObject = FreeVoipAccounts::model()->findByAttributes(array('username' => 'jawdroppingcalls')); $autoTopUpConf = new AutoTopupConfiguration(); $autoTopUpConf->activated = false; $autoTopUpConf->budget = 0; $autoTopUpConf->freeVoipAccount = $freeVoipObject->id; $autoTopUpConf->remote_data_cache = $currentAccount->id; $autoTopUpConf->topUpValue = 0; if ($autoTopUpConf->save(false)) { echo "AutoTopupConfiguration created for {$currentAccount->main_user} \n"; } else { echo "Cant create configuration for {$currentAccount->main_user} \n"; } } }
public function actionIndex() { /*get all ids*/ $remoteDataCacheIds = array(); // retrieve all records from database $remoteDataCacheModels = RemoteDataCache::model()->findAll(); //retrieve all records from remote $allAsteriskModels = AsteriskCarriers::getData(); //collect the id foreach ($remoteDataCacheModels as $key => $value) { $remoteDataCacheIds[] = $value->id; } $remoteDataCacheModels = null; foreach ($remoteDataCacheIds as $currentRemoteDataCacheId) { $curRemoteDataCacheModel = RemoteDataCache::model()->findByPk($currentRemoteDataCacheId); $currentRemoteDataCacheExists = false; Yii::log("Checking : {$curRemoteDataCacheModel->sub_user} | {$curRemoteDataCacheModel->sub_pass}", CLogger::LEVEL_INFO, 'sync_remove'); /** * @var RemoteDataCache $currentRemoteDataCache */ foreach ($allAsteriskModels as $currentAsteriskModel) { //check if matched if ($currentAsteriskModel['main_user'] === $curRemoteDataCacheModel->main_user && $currentAsteriskModel['main_pass'] === $curRemoteDataCacheModel->main_pass && $currentAsteriskModel['sub_user'] === $curRemoteDataCacheModel->sub_user && $currentAsteriskModel['sub_pass'] === $curRemoteDataCacheModel->sub_pass) { Yii::log("RemoteDataCache exists! {$curRemoteDataCacheModel->sub_user} | {$curRemoteDataCacheModel->sub_pass}", CLogger::LEVEL_INFO, 'sync_remove'); $currentRemoteDataCacheExists = true; continue; } } //end of loop allasteriskmodels if (!$currentRemoteDataCacheExists) { $logMessage = sprintf("Deleting record : %s | %s | %s | %s", $curRemoteDataCacheModel->main_user, $curRemoteDataCacheModel->main_pass, $curRemoteDataCacheModel->sub_user, $curRemoteDataCacheModel->sub_pass); Yii::log($logMessage, CLogger::LEVEL_INFO, "sync_remove"); $curRemoteDataCacheModel->delete(); } } //end of remotedatacache loop }
public function actionUpdateAccountBalance($mainUsername, $mainPassword, $subUsername, $subPassword) { header("Content-Type: application/json"); $model = new RemoteDataCache(); $jsonReply = array("success" => false, "message" => "Can't find model", "model" => $model); $criteria = new CDbCriteria(); $criteria->compare("main_user", $mainUsername); $criteria->compare("main_pass", $mainPassword); $criteria->compare("sub_user", $subUsername); $criteria->compare("sub_pass", $subPassword); $model = RemoteDataCache::model()->find($criteria); if ($model) { $sync = new SyncSingleSubSip(); $sync->sync($model); $jsonReply = array("success" => true, "message" => "Record updated", "model" => $model); } /** * @todo * Retrieve the updated model */ $jsonReply['model'] = RemoteDataCache::model()->findByPk($model->id); echo CJSON::encode($jsonReply); Yii::app()->end(); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return RemoteDataCache the loaded model * @throws CHttpException */ public function loadModel($id) { $model = RemoteDataCache::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function synData() { /** * @var RemoteDataCache $foundModel */ $fetchData = new ChartInfoDataArr(); Yii::log("Fetching data from remote source.", CLogger::LEVEL_INFO, 'sync_log'); $fetchedData = $fetchData->getData(); Yii::log("Data Fetched from remote source", CLogger::LEVEL_INFO, 'sync_log'); foreach ($fetchedData as $currentFetchedData) { Yii::log(sprintf("Processing data - %s - %s - %s - %s", $currentFetchedData['main_user'], $currentFetchedData['main_pass'], $currentFetchedData['sub_user'], $currentFetchedData['sub_pass']), CLogger::LEVEL_INFO, 'sync_log'); $criteria = new CDbCriteria(); $criteria->compare("main_user", $currentFetchedData['main_user']); $criteria->compare("main_pass", $currentFetchedData['main_pass']); $criteria->compare("sub_user", $currentFetchedData['sub_user']); $criteria->compare("sub_pass", $currentFetchedData['sub_pass']); $foundModel = RemoteDataCache::model()->find($criteria); if ($foundModel) { $last_balance = $foundModel->balance; Yii::log("Current Data . " . json_encode($currentFetchedData), CLogger::LEVEL_INFO, 'sync_log'); Yii::log("Model found . ", CLogger::LEVEL_INFO, 'sync_log'); /* check current data before saving */ /* notification check */ Yii::log("Checking data for notification . ", CLogger::LEVEL_INFO, 'sync_log'); $this->checkNotification($foundModel); /* deactivation check */ Yii::log("Checking status code . ", CLogger::LEVEL_INFO, 'sync_log'); // //$this->checkStatus($foundModel); // /* proceed with update */ Yii::log("Updating balance . ", CLogger::LEVEL_INFO, 'sync_log'); $foundModel->balance = doubleval($currentFetchedData['balance']); Yii::log("Balance updated . ", CLogger::LEVEL_INFO, 'sync_log'); $foundModel->exact_balance = doubleval($currentFetchedData['exact_balance']); $foundModel->last_balance = $last_balance; $foundModel->vici_user = doubleval($currentFetchedData['vici_user']); $foundModel->num_lines = doubleval(@$currentFetchedData['number_of_lines']); $foundModel->ip_address = $currentFetchedData['server_ip']; $foundModel->campaign = $currentFetchedData["campaign"]; //Removing this for now to prevent fresh data from updating deactivated record // $foundModel->is_active = $currentFetchedData["status"]; if ($foundModel->save()) { Yii::log("Found Model Updated . ", CLogger::LEVEL_INFO, 'sync_log'); } else { Yii::log("Cant update model because : " . CHtml::errorSummary($foundModel), CLogger::LEVEL_INFO, 'sync_log'); } } else { Yii::log(sprintf("Model not found , saving as new model instead - %s - %s - %s - %s", $currentFetchedData['main_user'], $currentFetchedData['main_pass'], $currentFetchedData['sub_user'], $currentFetchedData['sub_pass']), CLogger::LEVEL_INFO, 'sync_log'); $newModel = new RemoteDataCache(); $newModel->main_user = $currentFetchedData['main_user']; $newModel->main_pass = $currentFetchedData['main_pass']; $newModel->sub_user = $currentFetchedData['sub_user']; $newModel->sub_pass = $currentFetchedData['sub_pass']; $newModel->balance = doubleval($currentFetchedData['balance']); $newModel->exact_balance = doubleval($currentFetchedData['exact_balance']); $newModel->vici_user = doubleval($currentFetchedData['vici_user']); $newModel->num_lines = doubleval(@$currentFetchedData['number_of_lines']); $newModel->ip_address = $currentFetchedData['server_ip']; $newModel->campaign = $currentFetchedData["campaign"]; $newModel->is_active = $currentFetchedData["status"]; if ($newModel->save()) { Yii::log("New Model Saved . ", CLogger::LEVEL_INFO, 'sync_log'); } else { Yii::log("Cant save new model because : " . CHtml::errorSummary($newModel), CLogger::LEVEL_INFO, 'sync_log'); } } } }
/** * Retrieves bar chart report data as json data */ public function actionGetBarChartReportData() { header("Content-Type: application/json"); $criteria = new CDbCriteria(); $criteria->order = "vici_user ASC"; $allremoteData = RemoteDataCache::model()->findAll($criteria); $seriesData = array(); foreach ($allremoteData as $currentRemoteData) { /** * @var $currentRemoteData RemoteDataCache */ $curDataContainer = array(); if ($currentRemoteData->balance >= 10) { $curDataContainer = array("y" => doubleval($currentRemoteData->balance), "color" => "#7CB5EC"); } else { if ($currentRemoteData->balance >= 3) { $curDataContainer = array("y" => doubleval($currentRemoteData->balance), "color" => "orange"); } else { $curDataContainer = array("y" => doubleval($currentRemoteData->balance), "color" => "red"); } } $seriesData[] = $curDataContainer; } echo CJSON::encode($seriesData); }
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)); }
/** * * @throws Exception * @return integer Returns number of updated accounts */ public function topupAccounts() { $accountsAffectedInt = 0; $accountsArr = explode(",", $this->accounts); $groupId = uniqid(); foreach ($accountsArr as $key => $currentAccountName) { /** * @var $model RemoteDataCache */ $model = RemoteDataCache::model()->findByAttributes(array('sub_user' => $currentAccountName)); if ($model) { //topup the main account /** * @var $topUpMainAccount TopUpMainAccount */ $topUpMainAccount = Yii::app()->topUpMainAccount; $topUpMainAccount->topUp($this->freeVoipAccountUsername, $this->topupvalue, $model); //$this->topUpMainAccount($model); // topup the main account , old implementation //TOPUP the sub accounts /** * @TODO - use Yii component , put this to yii component */ $remoteAcctUpdated = new ApiRemoteUpdateBalance($model->sub_pass, $model->sub_user, $model->main_pass, $model->main_user, $this->topupvalue); /** * Logger */ ViciActionLogger::logAction("SUB_ACCOUNT_TOPUP", "Top upping {$model->sub_user} with {$this->topupvalue}", $this->topupvalue, $groupId, time()); /** * @TODO - use Yii component */ if ($remoteAcctUpdated->update()) { if ($this->andActivate) { /** * @TODO - use Yii component */ $activator = new ActivationFormModel(); $activator->activateAccount($model); } } /** * Force the RemoteDataCache instance to update its current campaign */ $campaignForcer = Yii::app()->campaignForcer; $campaignForcer->update($this->forceAgent, $model->sub_user); /** * Get the latest data from remote api */ $lastBalance = $model->balance; $voipInfoRetriever = new BestVOIPInformationRetriever(); $remoteVoipResult = $voipInfoRetriever->getInfo($model->main_user, $model->main_pass, $model->sub_user, $model->sub_pass); /** * Checking */ if ($model->last_balance_since_topup !== 0 && !is_null($model->last_balance_since_topup)) { /** * Create a charge log for certain remote data cache */ $newChargeLog = new AccountChargeLog(); $newChargeLog->account_id = $model->id; $newChargeLog->charge = doubleval($model->last_balance_since_topup) - doubleval($model->exact_balance); if (!$newChargeLog->save()) { throw new Exception(CHtml::errorSummary($newChargeLog)); } } $model->balance = doubleval($remoteVoipResult->getBalance()); $model->exact_balance = doubleval($remoteVoipResult->getSpecificBalance()); $model->last_balance = $lastBalance; $model->last_balance_since_topup = $remoteVoipResult->getSpecificBalance(); $model->save(); /** * Update the counter */ $accountsAffectedInt++; } } return $accountsAffectedInt; }
public function getRemoteDataCacheModel() { return RemoteDataCache::model()->findByPk($this->remote_data_cache); }
public function actionGenerate() { $allModels = RemoteDataCache::model()->findAll(); foreach ($allModels as $key => $currentModel) { $urlStr = sprintf("https://apivoip.ml/disable/account?mainusername=%s&mainpassword=%s", $currentModel->main_user, $currentModel->main_pass); echo $urlStr . "<br>"; } die; }