🔥 remove remaining legacy saas code
This commit is contained in:
parent
e232469551
commit
0f5cb8b1f8
123 changed files with 10 additions and 10171 deletions
|
@ -57,7 +57,6 @@ class ApiController extends Zend_Controller_Action
|
|||
->addActionContext('status' , 'json')
|
||||
->addActionContext('register-component' , 'json')
|
||||
->addActionContext('update-liquidsoap-status' , 'json')
|
||||
->addActionContext('live-chat' , 'json')
|
||||
->addActionContext('update-file-system-mount' , 'json')
|
||||
->addActionContext('handle-watched-dir-missing' , 'json')
|
||||
->addActionContext('rabbitmq-do-push' , 'json')
|
||||
|
|
|
@ -1,301 +0,0 @@
|
|||
<?php
|
||||
|
||||
define('VAT_RATE', 19.00);
|
||||
|
||||
class BillingController extends Zend_Controller_Action {
|
||||
|
||||
public function init()
|
||||
{
|
||||
//Two of the actions in this controller return JSON because they're used for AJAX:
|
||||
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
||||
$ajaxContext->addActionContext('vat-validator', 'json')
|
||||
->addActionContext('is-country-in-eu', 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$this->_redirect('billing/upgrade');
|
||||
}
|
||||
|
||||
public function upgradeAction()
|
||||
{
|
||||
//If you're not on a trial and you're suspended, we don't let you access the plans page and redirect you to the invoices
|
||||
//page to force you to pay your bills first.
|
||||
$isTrial = (Application_Model_Preference::GetPlanLevel() == 'trial');
|
||||
if (!$isTrial && (Application_Model_Preference::getProvisioningStatus() == PROVISIONING_STATUS_SUSPENDED)) {
|
||||
$this->_redirect('billing/invoices');
|
||||
}
|
||||
|
||||
Zend_Layout::getMvcInstance()->assign('parent_page', 'Billing');
|
||||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']);
|
||||
Billing::ensureClientIdIsValid();
|
||||
|
||||
//Zend's CSRF token element requires the session to be open for writing
|
||||
SessionHelper::reopenSessionForWriting();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$form = new Application_Form_BillingUpgradeDowngrade();
|
||||
|
||||
if ($request->isPost()) {
|
||||
|
||||
$formData = $request->getPost();
|
||||
|
||||
if ($form->isValid($formData)) {
|
||||
|
||||
$credentials = Billing::getAPICredentials();
|
||||
|
||||
//Check if VAT should be applied or not to this invoice.
|
||||
if (in_array("7", $formData["customfields"])) {
|
||||
$apply_vat = Billing::checkIfVatShouldBeApplied($formData["customfields"]["7"], $formData["country"]);
|
||||
} else {
|
||||
$apply_vat = false;
|
||||
}
|
||||
|
||||
$placeAnUpgradeOrder = true;
|
||||
|
||||
$currentPlanProduct = Billing::getClientCurrentAirtimeProduct();
|
||||
$currentPlanProductId = $currentPlanProduct["pid"];
|
||||
$currentPlanProductBillingCycle = strtolower($currentPlanProduct["billingcycle"]);
|
||||
//If there's been no change in the plan or the billing cycle, we should not
|
||||
//place an upgrade order. WHMCS doesn't allow this in its web interface,
|
||||
//and it freaks out and does the wrong thing if we do it via the API
|
||||
//so we have to do avoid that.
|
||||
if (($currentPlanProductId == $formData["newproductid"]) &&
|
||||
($currentPlanProductBillingCycle == $formData["newproductbillingcycle"])
|
||||
) {
|
||||
$placeAnUpgradeOrder = false;
|
||||
}
|
||||
|
||||
$postfields = array();
|
||||
$postfields["username"] = $credentials["username"];
|
||||
$postfields["password"] = md5($credentials["password"]);
|
||||
$postfields["action"] = "upgradeproduct";
|
||||
$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
|
||||
$postfields["serviceid"] = Billing::getClientInstanceId();
|
||||
$postfields["type"] = "product";
|
||||
$postfields["newproductid"] = $formData["newproductid"];
|
||||
$postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"];
|
||||
$postfields["paymentmethod"] = $formData["paymentmethod"];
|
||||
$postfields["responsetype"] = "json";
|
||||
|
||||
$upgrade_query_string = "";
|
||||
foreach ($postfields AS $k => $v) $upgrade_query_string .= "$k=" . urlencode($v) . "&";
|
||||
|
||||
//update client info
|
||||
|
||||
$clientfields = array();
|
||||
$clientfields["username"] = $credentials["username"];
|
||||
$clientfields["password"] = md5($credentials["password"]);
|
||||
$clientfields["action"] = "updateclient";
|
||||
$clientfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$clientfields["customfields"] = base64_encode(serialize($formData["customfields"]));
|
||||
unset($formData["customfields"]);
|
||||
$clientfields["responsetype"] = "json";
|
||||
unset($formData["newproductid"]);
|
||||
unset($formData["newproductbillingcycle"]);
|
||||
unset($formData["paymentmethod"]);
|
||||
unset($formData["action"]);
|
||||
$clientfields = array_merge($clientfields, $formData);
|
||||
unset($clientfields["password2verify"]);
|
||||
unset($clientfields["submit"]);
|
||||
$client_query_string = "";
|
||||
foreach ($clientfields AS $k => $v) $client_query_string .= "$k=" . urlencode($v) . "&";
|
||||
|
||||
//Update the client details in WHMCS first
|
||||
$result = Billing::makeRequest($credentials["url"], $client_query_string);
|
||||
Logging::info($result);
|
||||
if ($result["result"] == "error") {
|
||||
$this->setErrorMessage();
|
||||
$this->view->form = $form;
|
||||
return;
|
||||
}
|
||||
|
||||
//If there were no changes to the plan or billing cycle, we just redirect you to the
|
||||
//invoices screen and show a message.
|
||||
if (!$placeAnUpgradeOrder) {
|
||||
$this->_redirect('billing/invoices?planupdated');
|
||||
return;
|
||||
}
|
||||
|
||||
//Then place an upgrade order in WHMCS
|
||||
$result = Billing::makeRequest($credentials["url"], $upgrade_query_string);
|
||||
if ($result["result"] == "error") {
|
||||
Logging::info($_SERVER['HTTP_HOST'] . " - Account upgrade failed. - " . $result["message"]);
|
||||
$this->setErrorMessage();
|
||||
$this->view->form = $form;
|
||||
} else {
|
||||
Logging::info($_SERVER['HTTP_HOST'] . "Account plan upgrade request:");
|
||||
Logging::info($result);
|
||||
|
||||
// Disable the view and the layout here, squashes an error.
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
if ($apply_vat) {
|
||||
Billing::addVatToInvoice($result["invoiceid"]);
|
||||
}
|
||||
|
||||
// there may not be an invoice created if the client is downgrading
|
||||
if (!empty($result["invoiceid"])) {
|
||||
self::viewInvoice($result["invoiceid"]);
|
||||
} else {
|
||||
$this->_redirect('billing/invoices?planupdated');
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->view->form = $form;
|
||||
}
|
||||
} else {
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function isCountryInEuAction()
|
||||
{
|
||||
// Disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$request = $this->getRequest();
|
||||
if (!$request->isPost()) {
|
||||
throw new Exception("Must POST data to isCountryInEuAction.");
|
||||
}
|
||||
$formData = $request->getPost();
|
||||
|
||||
//Set the return JSON value
|
||||
$this->_helper->json(array("result"=>Billing::isCountryInEU($formData["country"])));
|
||||
}
|
||||
|
||||
public function vatValidatorAction()
|
||||
{
|
||||
// Disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$request = $this->getRequest();
|
||||
if (!$request->isPost()) {
|
||||
throw new Exception("Must POST data to vatValidatorAction.");
|
||||
}
|
||||
$formData = $request->getPost();
|
||||
|
||||
$vatNumber = trim($formData["vatnumber"]);
|
||||
if (empty($vatNumber)) {
|
||||
$this->_helper->json(array("result"=>false));
|
||||
}
|
||||
|
||||
//Set the return JSON value
|
||||
$this->_helper->json(array("result"=>Billing::checkIfVatShouldBeApplied($vatNumber, $formData["country"])));
|
||||
}
|
||||
|
||||
|
||||
private function setErrorMessage($msg=null)
|
||||
{
|
||||
if (!is_null($msg)) {
|
||||
$this->view->errorMessage = $msg;
|
||||
} else {
|
||||
$this->view->errorMessage = "An error occurred and we could not update your account. Please contact support for help.";
|
||||
}
|
||||
}
|
||||
|
||||
private function setSuccessMessage($msg=null)
|
||||
{
|
||||
if (!is_null($msg)) {
|
||||
$this->view->successMessage = $msg;
|
||||
} else {
|
||||
$this->view->successMessage = "Your account has been updated.";
|
||||
}
|
||||
}
|
||||
|
||||
private static function viewInvoice($invoice_id)
|
||||
{
|
||||
$whmcsurl = "https://account.sourcefabric.com/dologin.php";
|
||||
$autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"];
|
||||
$timestamp = time(); //whmcs timezone?
|
||||
$client = Billing::getClientDetails();
|
||||
$email = $client["email"];
|
||||
$hash = sha1($email.$timestamp.$autoauthkey);
|
||||
$goto = "viewinvoice.php?id=".$invoice_id;
|
||||
header("Location: ".$whmcsurl."?email=$email×tamp=$timestamp&hash=$hash&goto=$goto");
|
||||
}
|
||||
|
||||
public function clientAction()
|
||||
{
|
||||
Zend_Layout::getMvcInstance()->assign('parent_page', 'Billing');
|
||||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']);
|
||||
|
||||
//Zend's CSRF token element requires the session to be open for writing
|
||||
SessionHelper::reopenSessionForWriting();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$form = new Application_Form_BillingClient();
|
||||
Billing::ensureClientIdIsValid();
|
||||
if ($request->isPost()) {
|
||||
$formData = $request->getPost();
|
||||
if ($form->isValid($formData)) {
|
||||
|
||||
$credentials = Billing::getAPICredentials();
|
||||
|
||||
$postfields = array();
|
||||
$postfields["username"] = $credentials["username"];
|
||||
$postfields["password"] = md5($credentials["password"]);
|
||||
$postfields["action"] = "updateclient";
|
||||
|
||||
$postfields["customfields"] = base64_encode(serialize($formData["customfields"]));
|
||||
unset($formData["customfields"]);
|
||||
|
||||
$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$postfields["responsetype"] = "json";
|
||||
$postfields = array_merge($postfields, $formData);
|
||||
unset($postfields["password2verify"]);
|
||||
unset($postfields["submit"]);
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = Billing::makeRequest($credentials["url"], $query_string);
|
||||
|
||||
if ($result["result"] == "error") {
|
||||
$this->setErrorMessage();
|
||||
} else {
|
||||
$form = new Application_Form_BillingClient();
|
||||
$this->setSuccessMessage();
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
} else {
|
||||
$this->view->form = $form;
|
||||
}
|
||||
} else {
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
public function invoicesAction()
|
||||
{
|
||||
Zend_Layout::getMvcInstance()->assign('parent_page', 'Billing');
|
||||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']);
|
||||
|
||||
$this->view->invoices = Billing::getInvoices();
|
||||
}
|
||||
|
||||
public function invoiceAction()
|
||||
{
|
||||
Billing::ensureClientIdIsValid();
|
||||
$request = $this->getRequest();
|
||||
$invoice_id = $request->getParam('invoiceid');
|
||||
self::viewInvoice($invoice_id);
|
||||
}
|
||||
}
|
|
@ -485,13 +485,6 @@ class LibraryController extends Zend_Controller_Action
|
|||
|
||||
public function publishDialogAction() {
|
||||
$this->_helper->layout->disableLayout();
|
||||
|
||||
|
||||
if (LIBRETIME_ENABLE_BILLING === true && !Billing::isStationPodcastAllowed()) {
|
||||
$this->renderScript("podcast/featureupgrade-pane.phtml");
|
||||
}
|
||||
|
||||
|
||||
//This just spits out publish-dialog.phtml!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,21 +88,6 @@ class LoginController extends Zend_Controller_Action
|
|||
Application_Model_Preference::SetUserLocale($locale);
|
||||
|
||||
$this->_redirect('showbuilder');
|
||||
} elseif (LIBRETIME_ENABLE_WHMCS) {
|
||||
$email = $form->getValue('username');
|
||||
$authAdapter = new WHMCS_Auth_Adapter("admin", $email, $password);
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
if ($result->isValid()) {
|
||||
Zend_Session::regenerateId();
|
||||
//set the user locale in case user changed it in when logging in
|
||||
Application_Model_Preference::SetUserLocale($locale);
|
||||
|
||||
$this->_redirect('showbuilder');
|
||||
}
|
||||
else {
|
||||
$form = $this->loginError($username);
|
||||
}
|
||||
} else {
|
||||
$form = $this->loginError($username);
|
||||
}
|
||||
|
@ -175,18 +160,7 @@ class LoginController extends Zend_Controller_Action
|
|||
$form->email->addError($this->view->translate(_("Email could not be sent. Check your mail server settings and ensure it has been configured properly.")));
|
||||
}
|
||||
} else {
|
||||
if (!LIBRETIME_ENABLE_WHMCS) {
|
||||
$form->email->addError($this->view->translate(_("That username or email address could not be found.")));
|
||||
} else {
|
||||
$form->email->addError(
|
||||
$this->view->translate(
|
||||
sprintf(
|
||||
_pro("That username or email address could not be found. If you are the station owner, you should <a href=\"%s\">reset your here</a>."),
|
||||
WHMCS_PASSWORD_RESET_URL
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
$form->email->addError($this->view->translate(_("That username or email address could not be found.")));
|
||||
}
|
||||
} else { //Form is not valid
|
||||
$form->email->addError($this->view->translate(_("There was a problem with the username or email address you entered.")));
|
||||
|
|
|
@ -27,15 +27,10 @@ class PodcastController extends Zend_Controller_Action {
|
|||
*/
|
||||
public function stationAction() {
|
||||
|
||||
if (LIBRETIME_ENABLE_BILLING === true && !Billing::isStationPodcastAllowed()) {
|
||||
$this->render("featureupgrade-page");
|
||||
return;
|
||||
}
|
||||
|
||||
$stationPodcastId = Application_Model_Preference::getStationPodcastId();
|
||||
$podcast = Application_Service_PodcastService::getPodcastById($stationPodcastId);
|
||||
$this->view->podcast = json_encode($podcast);
|
||||
$this->view->form = new Application_Form_StationPodcast();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class PreferenceController extends Zend_Controller_Action
|
|||
Application_Model_Preference::setTuneinPartnerId($values["tunein_partner_id"]);
|
||||
|
||||
// SoundCloud Preferences
|
||||
if (Billing::isStationPodcastAllowed() && array_key_exists('SoundCloudLicense', $values)) {
|
||||
if (array_key_exists('SoundCloudLicense', $values)) {
|
||||
Application_Model_Preference::setDefaultSoundCloudLicenseType($values["SoundCloudLicense"]);
|
||||
Application_Model_Preference::setDefaultSoundCloudSharingType($values["SoundCloudSharing"]);
|
||||
}
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Aws\S3\S3Client;
|
||||
|
||||
class ProvisioningController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* The "create action" is in ProvisioningHelper because it needs to have no dependency on Zend,
|
||||
* since when we bootstrap Zend, we already need the database set up and working (Bootstrap.php is a mess).
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Endpoint to change Airtime preferences remotely.
|
||||
* Mainly for use with the dashboard right now.
|
||||
*/
|
||||
public function changeAction() {
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
if (!RestAuth::verifyAuth(true, false, $this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// This is hacky and should be genericized
|
||||
if (isset($_POST['station_name'])) {
|
||||
Application_Model_Preference::SetStationName($_POST['station_name']);
|
||||
}
|
||||
if (isset($_POST['description'])) {
|
||||
Application_Model_Preference::SetStationDescription($_POST['description']);
|
||||
}
|
||||
if (isset($_POST['provisioning_status'])) {
|
||||
Application_Model_Preference::setProvisioningStatus($_POST['provisioning_status']);
|
||||
}
|
||||
if (isset($_POST['icecast_pass'])) {
|
||||
Application_Model_Preference::setDefaultIcecastPassword($_POST['icecast_pass']);
|
||||
}
|
||||
if (isset($_POST['bandwidth_limit'])) {
|
||||
Application_Model_Preference::setBandwidthLimit($_POST['bandwidth_limit']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(400)
|
||||
->appendBody("ERROR: " . $e->getMessage());
|
||||
Logging::error($e->getMessage());
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody("OK");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Airtime Pro station's files from Amazon S3
|
||||
*
|
||||
* FIXME: When we deploy this next time, we should ensure that
|
||||
* this function can only be accessed with POST requests!
|
||||
*/
|
||||
public function terminateAction()
|
||||
{
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
if (!RestAuth::verifyAuth(true, false, $this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) {
|
||||
$proxyStorageBackend = new ProxyStorageBackend($storageBackend);
|
||||
$proxyStorageBackend->deleteAllCloudFileObjects();
|
||||
}
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody("OK");
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,6 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
//$this->_helper->layout->setLayout("showbuilder");
|
||||
|
||||
$this->view->headScript()->appendScript("localStorage.setItem( 'user-type', '$userType' );");
|
||||
$this->view->headScript()->appendScript(Application_Common_GoogleAnalytics::generateGoogleTagManagerDataLayerJavaScript());
|
||||
|
||||
$this->view->headLink()->appendStylesheet($baseUrl . 'css/redmond/jquery-ui-1.8.8.custom.css?' . $CC_CONFIG['airtime_version']);
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ThankYouController extends Zend_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
//Variable for the template (thank-you/index.phtml)
|
||||
$this->view->stationUrl = Application_Common_HTTPHelper::getStationUrl();
|
||||
$this->view->conversionUrl = Application_Common_HTTPHelper::getStationUrl() . 'thank-you/confirm-conversion';
|
||||
$this->view->gaEventTrackingJsCode = ""; //Google Analytics event tracking code that logs an event.
|
||||
|
||||
// Embed the Google Analytics conversion tracking code if the
|
||||
// user is a super admin and old plan level is set to trial.
|
||||
if (Application_Common_GoogleAnalytics::didPaidConversionOccur($this->getRequest())) {
|
||||
$this->view->gaEventTrackingJsCode = Application_Common_GoogleAnalytics::generateConversionTrackingJavaScript();
|
||||
}
|
||||
|
||||
$csrf_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$csrf_element = new Zend_Form_Element_Hidden('csrf');
|
||||
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
|
||||
$csrf_form = new Zend_Form();
|
||||
$csrf_form->addElement($csrf_element);
|
||||
$this->view->form = $csrf_form;
|
||||
}
|
||||
|
||||
/** Confirm that a conversion was tracked. */
|
||||
public function confirmConversionAction()
|
||||
{
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$observed_csrf_token = $this->_getParam('csrf_token');
|
||||
$expected_csrf_token = $current_namespace->authtoken;
|
||||
|
||||
if($observed_csrf_token != $expected_csrf_token) {
|
||||
Logging::info("Invalid CSRF token");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getRequest()->isPost()) {
|
||||
Logging::info("Goal conversion from trial to paid.");
|
||||
// Clear old plan level so we prevent duplicate events.
|
||||
// This should only be called from AJAX. See thank-you/index.phtml
|
||||
Application_Model_Preference::ClearOldPlanLevel();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
<?php
|
||||
|
||||
class WhmcsLoginController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$username = "admin"; //This is just for appearance in your session. It shows up in the corner of the Airtime UI.
|
||||
$email = $_POST["email"];
|
||||
$password = $_POST["password"];
|
||||
|
||||
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
|
||||
if (Zend_Auth::getInstance()->hasIdentity())
|
||||
{
|
||||
$this->_redirect('showbuilder');
|
||||
}
|
||||
|
||||
$authAdapter = new WHMCS_Auth_Adapter($username, $email, $password);
|
||||
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$result = $auth->authenticate($authAdapter);
|
||||
if ($result->isValid()) {
|
||||
//all info about this user from the login table omit only the password
|
||||
//$userInfo = $authAdapter->getResultRowObject(null, 'password');
|
||||
|
||||
//the default storage is a session with namespace Zend_Auth
|
||||
/*
|
||||
[id] => 1
|
||||
[login] => admin
|
||||
[pass] => hashed password
|
||||
[type] => A
|
||||
[first_name] =>
|
||||
[last_name] =>
|
||||
[lastlogin] =>
|
||||
[lastfail] =>
|
||||
[skype_contact] =>
|
||||
[jabber_contact] =>
|
||||
[email] => asdfasdf@asdasdf.com
|
||||
[cell_phone] =>
|
||||
[login_attempts] => 0
|
||||
*/
|
||||
|
||||
//Zend_Auth already does this for us, it's not needed:
|
||||
//$authStorage = $auth->getStorage();
|
||||
//$authStorage->write($result->getIdentity()); //$userInfo);
|
||||
|
||||
//set the user locale in case user changed it in when logging in
|
||||
//$locale = $form->getValue('locale');
|
||||
//Application_Model_Preference::SetUserLocale($locale);
|
||||
|
||||
$this->_redirect('showbuilder');
|
||||
}
|
||||
else {
|
||||
echo("Sorry, that username or password was incorrect.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface {
|
||||
private $username;
|
||||
private $password;
|
||||
private $email;
|
||||
|
||||
function __construct($username, $email, $password) {
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->email = $email;
|
||||
$this->identity = null;
|
||||
}
|
||||
|
||||
function authenticate() {
|
||||
list($credentialsValid, $clientId) = $this->validateCredentialsWithWHMCS($this->email, $this->password);
|
||||
if (!$credentialsValid)
|
||||
{
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null);
|
||||
}
|
||||
if (!$this->verifyClientSubdomainOwnership($clientId))
|
||||
{
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null);
|
||||
}
|
||||
|
||||
$identity = array();
|
||||
|
||||
//TODO: Get identity of the first admin user!
|
||||
|
||||
/*
|
||||
$identity["id"] = 1;
|
||||
$identity["type"] = "S";
|
||||
$identity["login"] = $this->username; //admin";
|
||||
$identity["email"] = $this->email;*/
|
||||
$identity = $this->getSuperAdminIdentity();
|
||||
if (is_null($identity)) {
|
||||
Logging::error("No super admin user found");
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
|
||||
}
|
||||
$identity = (object)$identity; //Convert the array into an stdClass object
|
||||
|
||||
try {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} catch (Exception $e) {
|
||||
// exception occured
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
|
||||
}
|
||||
}
|
||||
|
||||
private function getSuperAdminIdentity()
|
||||
{
|
||||
$firstSuperAdminUser = CcSubjsQuery::create()
|
||||
->filterByDbType('S')
|
||||
->orderByDbId()
|
||||
->findOne();
|
||||
if (!$firstSuperAdminUser) {
|
||||
//If there's no super admin users, get the first regular admin user!
|
||||
$firstSuperAdminUser = CcSubjsQuery::create()
|
||||
->filterByDbType('A')
|
||||
->orderByDbId()
|
||||
->findOne();
|
||||
if (!$firstSuperAdminUser) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$identity["id"] = $firstSuperAdminUser->getDbId();
|
||||
$identity["type"] = "S"; //Super Admin
|
||||
$identity["login"] = $firstSuperAdminUser->getDbLogin();
|
||||
$identity["email"] = $this->email;
|
||||
return $identity;
|
||||
}
|
||||
|
||||
//Returns an array! Read the code carefully:
|
||||
private function validateCredentialsWithWHMCS($email, $password)
|
||||
{
|
||||
$client_postfields = array();
|
||||
$client_postfields["username"] = $_SERVER['WHMCS_USERNAME']; //WHMCS API username
|
||||
$client_postfields["password"] = md5($_SERVER['WHMCS_PASSWORD']); //WHMCS API password
|
||||
$client_postfields["action"] ="validatelogin";
|
||||
$client_postfields["responsetype"] = "json";
|
||||
|
||||
$client_postfields["email"] = $email;
|
||||
$client_postfields["password2"] = $password;
|
||||
|
||||
$query_string = "";
|
||||
foreach ($client_postfields as $k => $v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, WHMCS_API_URL);
|
||||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$jsondata = curl_exec($ch);
|
||||
if (curl_error($ch)) {
|
||||
Logging::error("Failed to reach WHMCS server in " . __FUNCTION__ . ": "
|
||||
. curl_errno($ch) . ' - ' . curl_error($ch) . ' - ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||
//die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$arr = json_decode($jsondata, true); # Decode JSON String
|
||||
|
||||
if ($arr["result"] != "success") {
|
||||
return array(false, -1);
|
||||
}
|
||||
$clientId = $arr["userid"];
|
||||
|
||||
return array(true, $clientId);
|
||||
}
|
||||
|
||||
function verifyClientSubdomainOwnership($clientId)
|
||||
{
|
||||
//Do a quick safety check to ensure the client ID we're authenticating
|
||||
//matches up to the owner of this instance.
|
||||
if ($clientId != Application_Model_Preference::GetClientId())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$client_postfields = array();
|
||||
$client_postfields["username"] = $_SERVER['WHMCS_USERNAME'];
|
||||
$client_postfields["password"] = md5($_SERVER['WHMCS_PASSWORD']);
|
||||
$client_postfields["action"] ="getclientsproducts";
|
||||
$client_postfields["responsetype"] = "json";
|
||||
|
||||
$client_postfields["clientid"] = $clientId;
|
||||
//$client_postfields["stats"] = "true";
|
||||
|
||||
$query_string = "";
|
||||
foreach ($client_postfields as $k => $v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, WHMCS_API_URL);
|
||||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$jsondata = curl_exec($ch);
|
||||
if (curl_error($ch)) {
|
||||
Logging::error("Failed to reach WHMCS server in " . __FUNCTION__ . ": "
|
||||
. curl_errno($ch) . ' - ' . curl_error($ch) . ' - ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||
//die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$arr = json_decode($jsondata, true); # Decode JSON String
|
||||
//$client_id = $arr["clientid"];
|
||||
//print_r($arr);
|
||||
if ($arr["result"] != "success") {
|
||||
die("Sorry, that email address or password was incorrect.");
|
||||
}
|
||||
|
||||
$doesAirtimeProductExist = false;
|
||||
$isAirtimeAccountSuspended = true;
|
||||
$airtimeProduct = null;
|
||||
|
||||
foreach ($arr["products"]["product"] as $product)
|
||||
{
|
||||
if (strpos($product["groupname"], "Airtime") === FALSE)
|
||||
{
|
||||
//Ignore non-Airtime products
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (($product["status"] === "Active") || ($product["status"] === "Suspended")) {
|
||||
$airtimeProduct = $product;
|
||||
$subdomain = '';
|
||||
|
||||
foreach ($airtimeProduct['customfields']['customfield'] as $customField)
|
||||
{
|
||||
if ($customField['name'] === SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME)
|
||||
{
|
||||
$subdomain = $customField['value'];
|
||||
if (($subdomain . ".airtime.pro") === $_SERVER['SERVER_NAME'])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -118,8 +118,6 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
"error",
|
||||
"locale",
|
||||
"upgrade",
|
||||
'whmcs-login',
|
||||
"provisioning",
|
||||
"embed",
|
||||
"feeds"
|
||||
)))
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Zend_Controller_Plugin_ConversionTracking extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
if (!Zend_Session::isStarted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//If user is a super admin and old plan level is set to trial....
|
||||
if (Application_Common_GoogleAnalytics::didPaidConversionOccur($request))
|
||||
{
|
||||
//Redirect to Thank you page, unless the request was already going there...
|
||||
if ($request->getControllerName() != 'thank-you')
|
||||
{
|
||||
$request->setModuleName('default')
|
||||
->setControllerName('thank-you')
|
||||
->setActionName('index')
|
||||
->setDispatched(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -33,8 +33,6 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
|
|||
"auth",
|
||||
"error",
|
||||
"upgrade",
|
||||
'whmcs-login',
|
||||
"provisioning",
|
||||
"embed",
|
||||
"feeds"
|
||||
))
|
||||
|
@ -223,29 +221,12 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
|
|||
}
|
||||
|
||||
$view->headScript()->appendScript("var userType = '$userType';");
|
||||
if (LIBRETIME_ENABLE_LIVECHAT === true
|
||||
&& array_key_exists('REQUEST_URI', $_SERVER) //Doesn't exist for unit tests
|
||||
&& strpos($_SERVER['REQUEST_URI'], 'Dashboard/stream-player') === false
|
||||
&& strpos($_SERVER['REQUEST_URI'], 'audiopreview') === false
|
||||
&& $_SERVER['REQUEST_URI'] != "/") {
|
||||
$plan_level = strval(Application_Model_Preference::GetPlanLevel());
|
||||
// Since the Hobbyist plan doesn't come with Live Chat support, don't enable it
|
||||
if (Application_Model_Preference::GetLiveChatEnabled() && $plan_level !== 'hobbyist') {
|
||||
$client_id = strval(Application_Model_Preference::GetClientId());
|
||||
$station_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
||||
$view->headScript()->appendScript("var livechat_client_id = '$client_id';\n" .
|
||||
"var livechat_plan_type = '$plan_level';\n" .
|
||||
"var livechat_station_url = 'http://$station_url';");
|
||||
$view->headScript()->appendFile($baseUrl . 'js/airtime/common/livechat.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function _initViewHelpers()
|
||||
{
|
||||
$view = $this->_bootstrap->getResource('view');
|
||||
$view->addHelperPath(APPLICATION_PATH . 'views/helpers', 'Airtime_View_Helper');
|
||||
$view->assign('suspended', (Application_Model_Preference::getProvisioningStatus() == PROVISIONING_STATUS_SUSPENDED));
|
||||
}
|
||||
|
||||
protected function _initTitle()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue