Merge branch 'saas-dev' into saas-landing-page

Conflicts:
	airtime_mvc/application/controllers/ApiController.php
	airtime_mvc/application/controllers/IndexController.php
This commit is contained in:
drigato 2015-06-08 14:55:24 -04:00
commit 060280d5a5
7 changed files with 86 additions and 29 deletions

View file

@ -42,3 +42,33 @@ class Application_Common_HTTPHelper
return $stationUrl; return $stationUrl;
} }
} }
class ZendActionHttpException extends Exception {
private $_action;
/**
* @param Zend_Controller_Action $action
* @param int $statusCode
* @param string $message
* @param int $code
* @param Exception $previous
*
* @throws Zend_Controller_Response_Exception
*/
public function __construct(Zend_Controller_Action $action, $statusCode, $message,
$code = 0, Exception $previous = null) {
$this->_action = $action;
Logging::info("Error in action " . $action->getRequest()->getActionName()
. " with status code $statusCode: $message");
$action->getResponse()
->setHttpResponseCode($statusCode)
->appendBody($message);
parent::__construct($message, $code, $previous);
}
public function getAction() {
return $this->_action;
}
}

View file

@ -74,6 +74,7 @@ class ApiController extends Zend_Controller_Action
print _('You are not allowed to access this resource.'); print _('You are not allowed to access this resource.');
exit; exit;
} }
return true;
} }
public function versionAction() public function versionAction()
@ -158,7 +159,7 @@ class ApiController extends Zend_Controller_Action
*/ */
public function liveInfoAction() public function liveInfoAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout // disable the view and the layout
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
@ -253,7 +254,7 @@ class ApiController extends Zend_Controller_Action
*/ */
public function liveInfoV2Action() public function liveInfoV2Action()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout // disable the view and the layout
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
@ -361,7 +362,7 @@ class ApiController extends Zend_Controller_Action
public function weekInfoAction() public function weekInfoAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout // disable the view and the layout
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
@ -392,26 +393,38 @@ class ApiController extends Zend_Controller_Action
*/ */
public function showLogoAction() public function showLogoAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { // Disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
$request = $this->getRequest(); $request = $this->getRequest();
$showId = $request->getParam('id'); $showId = $request->getParam('id');
if (empty($showId)) {
// if no id is passed, just die - redirects to a 404 throw new ZendActionHttpException($this, 400, "ERROR: No ID was given.");
if (!$showId || $showId === '') {
return;
} }
$show = CcShowQuery::create()->findPk($showId); $show = CcShowQuery::create()->findPk($showId);
if (empty($show)) {
// disable the view and the layout throw new ZendActionHttpException($this, 400, "ERROR: No show with ID $showId exists.");
$this->view->layout()->disableLayout(); }
$this->_helper->viewRenderer->setNoRender(true);
$path = $show->getDbImagePath(); $path = $show->getDbImagePath();
$mime_type = mime_content_type($path); $mime_type = mime_content_type($path);
if (empty($path)) {
throw new ZendActionHttpException($this, 400, "ERROR: Show does not have an associated image.");
}
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type); try {
} else { // Sometimes end users may be looking at stale data - if an image is removed
// but has been cached in a client's browser this will throw an exception
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type);
} catch(FileNotFoundException $e) {
throw new ZendActionHttpException($this, 404, "ERROR: No image found at $path");
} catch(Exception $e) {
throw new ZendActionHttpException($this, 500, "ERROR: " . $e->getMessage());
}
} else {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print _('You are not allowed to access this resource. '); print _('You are not allowed to access this resource. ');
exit; exit;
@ -423,7 +436,7 @@ class ApiController extends Zend_Controller_Action
*/ */
public function stationMetadataAction() public function stationMetadataAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout // disable the view and the layout
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
@ -462,7 +475,7 @@ class ApiController extends Zend_Controller_Action
*/ */
public function stationLogoAction() public function stationLogoAction()
{ {
if (Application_Model_Preference::GetAllow3rdPartyApi()) { if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
// disable the view and the layout // disable the view and the layout
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);

View file

@ -239,7 +239,7 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface {
} }
else else
{ {
if ($product["status"] === "Active") { if (($product["status"] === "Active") || ($product["status"] === "Suspended")) {
$airtimeProduct = $product; $airtimeProduct = $product;
$subdomain = ''; $subdomain = '';

View file

@ -56,12 +56,13 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
$this->getResponse() $this->getResponse()
->setHttpResponseCode(500) ->setHttpResponseCode(500)
->appendBody("Error processing image: " . $e->getMessage()); ->appendBody("Error processing image: " . $e->getMessage());
return;
} }
$show = CcShowQuery::create()->findPk($showId); $show = CcShowQuery::create()->findPk($showId);
$con = Propel::getConnection();
try { try {
$con = Propel::getConnection();
$con->beginTransaction(); $con->beginTransaction();
$show->setDbImagePath($path); $show->setDbImagePath($path);
@ -103,8 +104,8 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
$show = CcShowQuery::create()->findPk($showId); $show = CcShowQuery::create()->findPk($showId);
$con = Propel::getConnection();
try { try {
$con = Propel::getConnection();
$con->beginTransaction(); $con->beginTransaction();
$show->setDbImagePath(null); $show->setDbImagePath(null);
@ -268,7 +269,7 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
private static function delTree($dir) { private static function delTree($dir) {
$files = array_diff(scandir($dir), array('.', '..')); $files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) { foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); (is_dir("$dir/$file")) ? self::delTree("$dir/$file") : unlink("$dir/$file");
} }
return rmdir($dir); return rmdir($dir);
} }
@ -279,7 +280,7 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
* provided, otherwise returns the id * provided, otherwise returns the id
*/ */
private function getShowId() { private function getShowId() {
if (!$id = $this->_getParam('id', false)) { if (!($id = $this->_getParam('id', false))) {
$resp = $this->getResponse(); $resp = $this->getResponse();
$resp->setHttpResponseCode(400); $resp->setHttpResponseCode(400);
$resp->appendBody("ERROR: No show ID specified."); $resp->appendBody("ERROR: No show ID specified.");

View file

@ -14,6 +14,8 @@ def generate_liquidsoap_config(ss):
for key, value in data.iteritems(): for key, value in data.iteritems():
try: try:
if not "port" in key and not "bitrate" in key: # Stupid hack
raise ValueError()
str_buffer = "%s = %s\n" % (key, int(value)) str_buffer = "%s = %s\n" % (key, int(value))
except ValueError: except ValueError:
try: # Is it a boolean? try: # Is it a boolean?

View file

@ -477,6 +477,7 @@ class PypoFetch(Thread):
loops = 1 loops = 1
while True: while True:
self.logger.info("Loop #%s", loops) self.logger.info("Loop #%s", loops)
manual_fetch_needed = False
try: try:
""" """
our simple_queue.get() requires a timeout, in which case we our simple_queue.get() requires a timeout, in which case we
@ -492,17 +493,26 @@ class PypoFetch(Thread):
Currently we are checking every POLL_INTERVAL seconds Currently we are checking every POLL_INTERVAL seconds
""" """
message = self.fetch_queue.get(block=True, timeout=self.listener_timeout) message = self.fetch_queue.get(block=True, timeout=self.listener_timeout)
manual_fetch_needed = False
self.handle_message(message) self.handle_message(message)
except Empty, e: except Empty as e:
self.logger.info("Queue timeout. Fetching schedule manually") self.logger.info("Queue timeout. Fetching schedule manually")
self.persistent_manual_schedule_fetch(max_attempts=5) manual_fetch_needed = True
except Exception, e: except Exception as e:
top = traceback.format_exc() top = traceback.format_exc()
self.logger.error('Exception: %s', e) self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top) self.logger.error("traceback: %s", top)
try:
if manual_fetch_needed:
self.persistent_manual_schedule_fetch(max_attempts=5)
except Exception as e:
top = traceback.format_exc()
self.logger.error('Failed to manually fetch the schedule.')
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)
loops += 1 loops += 1
def run(self): def run(self):
@ -510,3 +520,4 @@ class PypoFetch(Thread):
Entry point of the thread Entry point of the thread
""" """
self.main() self.main()
self.logger.info('PypoFetch thread exiting')

View file

@ -35,6 +35,7 @@ class PypoFile(Thread):
self.media_queue = schedule_queue self.media_queue = schedule_queue
self.media = None self.media = None
self.cache_dir = os.path.join(config["cache_dir"], "scheduler") self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
self._config = self.read_config_file(CONFIG_PATH)
def copy_file(self, media_item): def copy_file(self, media_item):
""" """
@ -65,11 +66,9 @@ class PypoFile(Thread):
if do_copy: if do_copy:
self.logger.debug("copying from %s to local cache %s" % (src, dst)) self.logger.debug("copying from %s to local cache %s" % (src, dst))
try: try:
config = self.read_config_file(CONFIG_PATH)
CONFIG_SECTION = "general" CONFIG_SECTION = "general"
username = config.get(CONFIG_SECTION, 'api_key') username = self._config.get(CONFIG_SECTION, 'api_key')
host = self._config.get(CONFIG_SECTION, 'base_url')
host = config.get(CONFIG_SECTION, 'base_url')
url = "http://%s/rest/media/%s/download" % (host, media_item["id"]) url = "http://%s/rest/media/%s/download" % (host, media_item["id"])
with open(dst, "wb") as handle: with open(dst, "wb") as handle:
response = requests.get(url, auth=requests.auth.HTTPBasicAuth(username, ''), stream=True, verify=False) response = requests.get(url, auth=requests.auth.HTTPBasicAuth(username, ''), stream=True, verify=False)
@ -210,3 +209,4 @@ class PypoFile(Thread):
Entry point of the thread Entry point of the thread
""" """
self.main() self.main()