Merge branch 'saas' into saas-speedy
This commit is contained in:
commit
3e255bfd37
50 changed files with 829 additions and 270 deletions
|
@ -1073,7 +1073,9 @@ class ApiController extends Zend_Controller_Action
|
|||
$dir->getId(),$all=false);
|
||||
foreach ($files as $f) {
|
||||
// if the file is from this mount
|
||||
if (substr($f->getFilePath(), 0, strlen($rd)) === $rd) {
|
||||
$filePaths = $f->getFilePaths();
|
||||
$filePath = $filePaths[0];
|
||||
if (substr($filePath, 0, strlen($rd)) === $rd) {
|
||||
$f->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,40 @@
|
|||
<?php
|
||||
class ErrorController extends Zend_Controller_Action {
|
||||
|
||||
class ErrorController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
public function errorAction()
|
||||
public function init()
|
||||
{
|
||||
//The default layout includes the Dashboard header, which may contain private information.
|
||||
//We cannot show that.
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->setupCSS();
|
||||
|
||||
}
|
||||
|
||||
public function errorAction() {
|
||||
$errors = $this->_getParam('error_handler');
|
||||
|
||||
switch ($errors->type) {
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
|
||||
if ($errors) {
|
||||
// log error message and stack trace
|
||||
Logging::error($errors->exception->getMessage());
|
||||
Logging::error($errors->exception->getTraceAsString());
|
||||
|
||||
// 404 error -- controller or action not found
|
||||
$this->getResponse()->setHttpResponseCode(404);
|
||||
$this->view->message = _('Page not found');
|
||||
break;
|
||||
default:
|
||||
// application error
|
||||
$this->getResponse()->setHttpResponseCode(500);
|
||||
$this->view->message = _('Application error');
|
||||
break;
|
||||
switch ($errors->type) {
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE :
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER :
|
||||
$this->error404Action();
|
||||
break;
|
||||
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION :
|
||||
$this->error400Action();
|
||||
break;
|
||||
default :
|
||||
$this->error500Action();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$exceptions = $this->_getAllParams();
|
||||
Logging::error($exceptions);
|
||||
$this->error500Action();
|
||||
return;
|
||||
}
|
||||
|
||||
// Log exception, if logger available
|
||||
|
@ -33,11 +47,17 @@ class ErrorController extends Zend_Controller_Action
|
|||
$this->view->exception = $errors->exception;
|
||||
}
|
||||
|
||||
$this->view->request = $errors->request;
|
||||
$this->view->request = $errors->request;
|
||||
}
|
||||
|
||||
public function getLog()
|
||||
private function setupCSS()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$staticBaseDir = Application_Common_OsPath::formatDirectoryWithDirectorySeparators($CC_CONFIG['staticBaseDir']);
|
||||
$this->view->headLink()->appendStylesheet($staticBaseDir . 'css/styles.css?' . $CC_CONFIG['airtime_version']);
|
||||
}
|
||||
|
||||
public function getLog() {
|
||||
$bootstrap = $this->getInvokeArg('bootstrap');
|
||||
if (!$bootstrap->hasPluginResource('Log')) {
|
||||
return false;
|
||||
|
@ -47,9 +67,43 @@ class ErrorController extends Zend_Controller_Action
|
|||
return $log;
|
||||
}
|
||||
|
||||
public function deniedAction()
|
||||
{
|
||||
// action body
|
||||
/**
|
||||
* 404 error - route or controller
|
||||
*/
|
||||
public function error404Action() {
|
||||
$this->_helper->viewRenderer('error-404');
|
||||
$this->getResponse()->setHttpResponseCode(404);
|
||||
$this->view->message = _('Page not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 400 error - no such action
|
||||
*/
|
||||
public function error400Action() {
|
||||
$this->_helper->viewRenderer('error-400');
|
||||
$this->getResponse()->setHttpResponseCode(400);
|
||||
$this->view->message = _('The requested action is not supported.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 403 error - permission denied
|
||||
*/
|
||||
public function error403Action() {
|
||||
|
||||
$this->_helper->viewRenderer('error-403');
|
||||
$this->getResponse()->setHttpResponseCode(403);
|
||||
$this->view->message = _('You do not have permission to access this resource.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 500 error - internal server error
|
||||
*/
|
||||
public function error500Action() {
|
||||
|
||||
$this->_helper->viewRenderer('error-500');
|
||||
|
||||
$this->getResponse()->setHttpResponseCode(500);
|
||||
$this->view->message = _('An internal application error has occurred.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,6 +356,8 @@ class LibraryController extends Zend_Controller_Action
|
|||
$res = $file->delete();
|
||||
} catch (FileNoPermissionException $e) {
|
||||
$message = $noPermissionMsg;
|
||||
} catch (DeleteScheduledFileException $e) {
|
||||
$message = _("Could not delete file because it is scheduled in the future.");
|
||||
} catch (Exception $e) {
|
||||
//could throw a scheduled in future exception.
|
||||
$message = _("Could not delete file(s).");
|
||||
|
|
|
@ -18,6 +18,40 @@ class ProvisioningController extends Zend_Controller_Action
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 ($_POST['station_name']) {
|
||||
Application_Model_Preference::SetStationName($_POST['station_name']);
|
||||
}
|
||||
if ($_POST['description']) {
|
||||
Application_Model_Preference::SetStationDescription($_POST['description']);
|
||||
}
|
||||
} 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
|
||||
*/
|
||||
|
@ -31,12 +65,12 @@ class ProvisioningController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
|
||||
foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) {
|
||||
$proxyStorageBackend = new ProxyStorageBackend($storageBackend);
|
||||
$proxyStorageBackend->deleteAllCloudFileObjects();
|
||||
}
|
||||
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody("OK");
|
||||
|
|
|
@ -35,7 +35,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$user = Application_Model_User::GetCurrentUser();
|
||||
$userType = $user->getType();
|
||||
$this->view->headScript()->appendScript("localStorage.setItem( 'user-type', '$userType' );");
|
||||
$this->view->headScript()->appendScript($this->generateGoogleTagManagerDataLayerJavaScript());
|
||||
$this->view->headScript()->appendScript(Application_Common_GoogleAnalytics::generateGoogleTagManagerDataLayerJavaScript());
|
||||
|
||||
$this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||
$this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||
|
@ -369,104 +369,5 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
throw new Exception("this controller is/was a no-op please fix your
|
||||
code");
|
||||
}
|
||||
|
||||
/** Returns a string containing the JavaScript code to pass some billing account info
|
||||
* into Google Tag Manager / Google Analytics, so we can track things like the plan type.
|
||||
*/
|
||||
private static function generateGoogleTagManagerDataLayerJavaScript()
|
||||
{
|
||||
$code = "";
|
||||
|
||||
try
|
||||
{
|
||||
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
|
||||
$username = $_SERVER["WHMCS_USERNAME"];
|
||||
$password = $_SERVER["WHMCS_PASSWORD"];
|
||||
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey; # URL to WHMCS API file goes here
|
||||
|
||||
$postfields = array();
|
||||
$postfields["username"] = $username;
|
||||
$postfields["password"] = md5($password);
|
||||
$postfields["action"] = "getclientsdetails";
|
||||
$postfields["stats"] = true;
|
||||
$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$postfields["responsetype"] = "json";
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); // WHMCS IP whitelist doesn't support IPv6
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Aggressive 5 second timeout
|
||||
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)) {
|
||||
//die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
|
||||
throw new Exception("WHMCS server down or invalid request.");
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$arr = json_decode($jsondata); # Decode JSON String
|
||||
|
||||
if ($arr->result !== "success") {
|
||||
Logging::warn("WHMCS API call failed in " . __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
$client = $arr->client;
|
||||
$stats = $arr->stats;
|
||||
$currencyCode = $client->currency_code;
|
||||
//$incomeCents = NumberFormatter::parseCurrency($stats->income, $currencyCode);
|
||||
|
||||
$isTrial = true;
|
||||
if (strpos($stats->income, "0.00") === FALSE) {
|
||||
$isTrial = false;
|
||||
}
|
||||
/*
|
||||
if ($incomeCents > 0) {
|
||||
$isTrial = false;
|
||||
}*/
|
||||
$plan = Application_Model_Preference::GetPlanLevel();
|
||||
$country = $client->country;
|
||||
$postcode = $client->postcode;
|
||||
|
||||
//Figure out how long the customer has been around using a mega hack.
|
||||
//(I'm avoiding another round trip to WHMCS for now...)
|
||||
//We calculate it based on the trial end date...
|
||||
$trialEndDateStr = Application_Model_Preference::GetTrialEndingDate();
|
||||
if ($trialEndDateStr == '') {
|
||||
$accountDuration = 0;
|
||||
} else {
|
||||
$today = new DateTime();
|
||||
$trialEndDate = new DateTime($trialEndDateStr);
|
||||
$trialDuration = new DateInterval("P30D"); //30 day trial duration
|
||||
$accountCreationDate = $trialEndDate->sub($trialDuration);
|
||||
$interval = $today->diff($accountCreationDate);
|
||||
$accountDuration = $interval->days;
|
||||
}
|
||||
|
||||
$code = "$( document ).ready(function() {
|
||||
dataLayer.push({
|
||||
'ZipCode': '" . $postcode . "',
|
||||
'UserID': '" . $client->id . "',
|
||||
'Customer': 'Customer',
|
||||
'PlanType': '" . $plan . "',
|
||||
'Trial': '" . $isTrial . "',
|
||||
'Country': '" . $country . "',
|
||||
'AccountDuration': '" . strval($accountDuration) . "'
|
||||
});
|
||||
});";
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
48
airtime_mvc/application/controllers/ThankYouController.php
Normal file
48
airtime_mvc/application/controllers/ThankYouController.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,8 @@ class UpgradeController extends Zend_Controller_Action
|
|||
array_push($upgraders, new AirtimeUpgrader259());
|
||||
array_push($upgraders, new AirtimeUpgrader2510());
|
||||
array_push($upgraders, new AirtimeUpgrader2511());
|
||||
|
||||
array_push($upgraders, new AirtimeUpgrader2512());
|
||||
|
||||
$didWePerformAnUpgrade = false;
|
||||
try
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
{
|
||||
$this->_errorPage = array('module' => 'default',
|
||||
'controller' => 'error',
|
||||
'action' => 'denied');
|
||||
'action' => 'error');
|
||||
|
||||
$this->_roleName = $roleName;
|
||||
|
||||
|
@ -111,7 +111,16 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
$controller = strtolower($request->getControllerName());
|
||||
Application_Model_Auth::pinSessionToClient(Zend_Auth::getInstance());
|
||||
|
||||
if (in_array($controller, array("api", "auth", "locale", "upgrade", 'whmcs-login', "provisioning"))) {
|
||||
if (in_array($controller, array(
|
||||
"api",
|
||||
"auth",
|
||||
"error",
|
||||
"locale",
|
||||
"upgrade",
|
||||
'whmcs-login',
|
||||
"provisioning"
|
||||
)))
|
||||
{
|
||||
$this->setRoleName("G");
|
||||
} elseif (!Zend_Auth::getInstance()->hasIdentity()) {
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class Zend_Controller_Plugin_ConversionTracking extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE cc_show ALTER COLUMN description TYPE varchar(8192);
|
||||
ALTER TABLE cc_show_instances ALTER COLUMN description TYPE varchar(8192);
|
Loading…
Add table
Add a link
Reference in a new issue