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:
commit
060280d5a5
7 changed files with 86 additions and 29 deletions
|
@ -42,3 +42,33 @@ class Application_Common_HTTPHelper
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -74,6 +74,7 @@ class ApiController extends Zend_Controller_Action
|
|||
print _('You are not allowed to access this resource.');
|
||||
exit;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function versionAction()
|
||||
|
@ -158,7 +159,7 @@ class ApiController extends Zend_Controller_Action
|
|||
*/
|
||||
public function liveInfoAction()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
@ -253,7 +254,7 @@ class ApiController extends Zend_Controller_Action
|
|||
*/
|
||||
public function liveInfoV2Action()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
@ -361,7 +362,7 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
public function weekInfoAction()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
@ -392,25 +393,37 @@ class ApiController extends Zend_Controller_Action
|
|||
*/
|
||||
public function showLogoAction()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
$request = $this->getRequest();
|
||||
$showId = $request->getParam('id');
|
||||
|
||||
// if no id is passed, just die - redirects to a 404
|
||||
if (!$showId || $showId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$show = CcShowQuery::create()->findPk($showId);
|
||||
|
||||
// disable the view and the layout
|
||||
// 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();
|
||||
$showId = $request->getParam('id');
|
||||
if (empty($showId)) {
|
||||
throw new ZendActionHttpException($this, 400, "ERROR: No ID was given.");
|
||||
}
|
||||
|
||||
$show = CcShowQuery::create()->findPk($showId);
|
||||
if (empty($show)) {
|
||||
throw new ZendActionHttpException($this, 400, "ERROR: No show with ID $showId exists.");
|
||||
}
|
||||
|
||||
$path = $show->getDbImagePath();
|
||||
$mime_type = mime_content_type($path);
|
||||
if (empty($path)) {
|
||||
throw new ZendActionHttpException($this, 400, "ERROR: Show does not have an associated image.");
|
||||
}
|
||||
|
||||
try {
|
||||
// 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');
|
||||
print _('You are not allowed to access this resource. ');
|
||||
|
@ -423,7 +436,7 @@ class ApiController extends Zend_Controller_Action
|
|||
*/
|
||||
public function stationMetadataAction()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
@ -462,7 +475,7 @@ class ApiController extends Zend_Controller_Action
|
|||
*/
|
||||
public function stationLogoAction()
|
||||
{
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi()) {
|
||||
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) {
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
|
|
@ -239,7 +239,7 @@ class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface {
|
|||
}
|
||||
else
|
||||
{
|
||||
if ($product["status"] === "Active") {
|
||||
if (($product["status"] === "Active") || ($product["status"] === "Suspended")) {
|
||||
$airtimeProduct = $product;
|
||||
$subdomain = '';
|
||||
|
||||
|
|
|
@ -56,12 +56,13 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
|
|||
$this->getResponse()
|
||||
->setHttpResponseCode(500)
|
||||
->appendBody("Error processing image: " . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
$show = CcShowQuery::create()->findPk($showId);
|
||||
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$con->beginTransaction();
|
||||
|
||||
$show->setDbImagePath($path);
|
||||
|
@ -103,8 +104,8 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
|
|||
|
||||
$show = CcShowQuery::create()->findPk($showId);
|
||||
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$con->beginTransaction();
|
||||
|
||||
$show->setDbImagePath(null);
|
||||
|
@ -268,7 +269,7 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
|
|||
private static function delTree($dir) {
|
||||
$files = array_diff(scandir($dir), array('.', '..'));
|
||||
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);
|
||||
}
|
||||
|
@ -279,7 +280,7 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
|
|||
* provided, otherwise returns the id
|
||||
*/
|
||||
private function getShowId() {
|
||||
if (!$id = $this->_getParam('id', false)) {
|
||||
if (!($id = $this->_getParam('id', false))) {
|
||||
$resp = $this->getResponse();
|
||||
$resp->setHttpResponseCode(400);
|
||||
$resp->appendBody("ERROR: No show ID specified.");
|
||||
|
|
|
@ -14,6 +14,8 @@ def generate_liquidsoap_config(ss):
|
|||
|
||||
for key, value in data.iteritems():
|
||||
try:
|
||||
if not "port" in key and not "bitrate" in key: # Stupid hack
|
||||
raise ValueError()
|
||||
str_buffer = "%s = %s\n" % (key, int(value))
|
||||
except ValueError:
|
||||
try: # Is it a boolean?
|
||||
|
|
|
@ -477,6 +477,7 @@ class PypoFetch(Thread):
|
|||
loops = 1
|
||||
while True:
|
||||
self.logger.info("Loop #%s", loops)
|
||||
manual_fetch_needed = False
|
||||
try:
|
||||
"""
|
||||
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
|
||||
"""
|
||||
|
||||
|
||||
message = self.fetch_queue.get(block=True, timeout=self.listener_timeout)
|
||||
manual_fetch_needed = False
|
||||
self.handle_message(message)
|
||||
except Empty, e:
|
||||
except Empty as e:
|
||||
self.logger.info("Queue timeout. Fetching schedule manually")
|
||||
self.persistent_manual_schedule_fetch(max_attempts=5)
|
||||
except Exception, e:
|
||||
manual_fetch_needed = True
|
||||
except Exception as e:
|
||||
top = traceback.format_exc()
|
||||
self.logger.error('Exception: %s', e)
|
||||
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
|
||||
|
||||
def run(self):
|
||||
|
@ -510,3 +520,4 @@ class PypoFetch(Thread):
|
|||
Entry point of the thread
|
||||
"""
|
||||
self.main()
|
||||
self.logger.info('PypoFetch thread exiting')
|
||||
|
|
|
@ -35,6 +35,7 @@ class PypoFile(Thread):
|
|||
self.media_queue = schedule_queue
|
||||
self.media = None
|
||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||
self._config = self.read_config_file(CONFIG_PATH)
|
||||
|
||||
def copy_file(self, media_item):
|
||||
"""
|
||||
|
@ -65,11 +66,9 @@ class PypoFile(Thread):
|
|||
if do_copy:
|
||||
self.logger.debug("copying from %s to local cache %s" % (src, dst))
|
||||
try:
|
||||
config = self.read_config_file(CONFIG_PATH)
|
||||
CONFIG_SECTION = "general"
|
||||
username = config.get(CONFIG_SECTION, 'api_key')
|
||||
|
||||
host = config.get(CONFIG_SECTION, 'base_url')
|
||||
username = self._config.get(CONFIG_SECTION, 'api_key')
|
||||
host = self._config.get(CONFIG_SECTION, 'base_url')
|
||||
url = "http://%s/rest/media/%s/download" % (host, media_item["id"])
|
||||
with open(dst, "wb") as handle:
|
||||
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
|
||||
"""
|
||||
self.main()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue