/** * @param $freeVoipAccountUsername * @param $topupValue * @param RemoteDataCache $subAccount * @throws CHttpException */ public function topUp($freeVoipAccountUsername, $topupValue, RemoteDataCache $subAccount) { $criteria = new CDbCriteria(); $criteria->compare("username", $freeVoipAccountUsername); $freeVoipAccount = FreeVoipAccounts::model()->find($criteria); if ($freeVoipAccount) { //transfer fund from FreeVoipAccount to SipAccount /** * @TODO - transfer this to a component */ $rmt = new RemoteTransferFund(); $remoteResult = $rmt->commitTransaction($freeVoipAccount->username, $freeVoipAccount->password, $subAccount->main_user, doubleval($topupValue), $freeVoipAccount->pincode); ViciActionLogger::logAction("MAIN_TOPUP", "Credit increased account {$subAccount->main_user}", $topupValue, uniqid(), time()); } else { throw new CHttpException(404, "{$freeVoipAccountUsername} doesnt exists"); } }
/** * @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 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 testTopUpToday() { $accountName = "test"; $testTopupValue = 300; ViciActionLogger::logAction("SUB_ACCOUNT_TOPUP", "Top upping {$accountName} with {$testTopupValue}", $testTopupValue, uniqid()); }