Merge branch 'saas-dev' into saas-installer-albert

This commit is contained in:
Albert Santoni 2015-06-10 12:02:08 -04:00
commit 3996e757b7
10 changed files with 93 additions and 36 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

@ -435,8 +435,8 @@ class ApiController extends Zend_Controller_Action
* Go through a given array and sanitize any potentially exploitable fields * Go through a given array and sanitize any potentially exploitable fields
* by passing them through htmlspecialchars * by passing them through htmlspecialchars
* *
* @param unknown $arr the array to sanitize * @param array $arr the array to sanitize
* @param unknown $keys indexes of values to be sanitized * @param array $keys indexes of values to be sanitized
*/ */
private function convertSpecialChars(&$arr, $keys) private function convertSpecialChars(&$arr, $keys)
{ {
@ -456,7 +456,7 @@ class ApiController extends Zend_Controller_Action
* Recursively find image_path keys in the various $result subarrays, * Recursively find image_path keys in the various $result subarrays,
* and convert them to point to the show-logo endpoint * and convert them to point to the show-logo endpoint
* *
* @param unknown $arr the array to search * @param array $arr the array to search
*/ */
private function findAndConvertPaths(&$arr) private function findAndConvertPaths(&$arr)
{ {
@ -480,26 +480,38 @@ class ApiController extends Zend_Controller_Action
*/ */
public function showLogoAction() public function showLogoAction()
{ {
// Disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if (Application_Model_Preference::GetAllow3rdPartyApi() || $this->checkAuth()) { 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;

View File

@ -10,7 +10,7 @@ class IndexController extends Zend_Controller_Action
public function indexAction() public function indexAction()
{ {
$this->_forward('index', 'showbuilder'); $this->_redirect('Showbuilder');
} }
public function mainAction() public function mainAction()

View File

@ -102,7 +102,6 @@ class UserController extends Zend_Controller_Action
public function getHostsAction() public function getHostsAction()
{ {
$search = $this->_getParam('term'); $search = $this->_getParam('term');
$res = Application_Model_User::getHosts($search);
$this->view->hosts = Application_Model_User::getHosts($search); $this->view->hosts = Application_Model_User::getHosts($search);
} }
@ -144,14 +143,27 @@ class UserController extends Zend_Controller_Action
// We don't allow 6 x's as a password. // We don't allow 6 x's as a password.
// The reason is because we use that as a password placeholder // The reason is because we use that as a password placeholder
// on the client side. // on the client side.
if (($formData['cu_password'] != "xxxxxx") && if (array_key_exists('cu_password', $formData) && ($formData['cu_password'] != "xxxxxx") &&
(!empty($formData['cu_password']))) { (!empty($formData['cu_password']))) {
$user->setPassword($formData['cu_password']); $user->setPassword($formData['cu_password']);
} }
$user->setEmail($formData['cu_email']);
$user->setCellPhone($formData['cu_cell_phone']); if (array_key_exists('cu_email', $formData)) {
$user->setSkype($formData['cu_skype']); $user->setEmail($formData['cu_email']);
$user->setJabber($formData['cu_jabber']); }
if (array_key_exists('cu_cell_phone', $formData)) {
$user->setCellPhone($formData['cu_cell_phone']);
}
if (array_key_exists('cu_skype', $formData)) {
$user->setSkype($formData['cu_skype']);
}
if (array_key_exists('cu_jabber', $formData)) {
$user->setJabber($formData['cu_jabber']);
}
$user->save(); $user->save();
Application_Model_Preference::SetUserLocale($formData['cu_locale']); Application_Model_Preference::SetUserLocale($formData['cu_locale']);

View File

@ -268,6 +268,7 @@ SQL;
$nextMedia = CcScheduleQuery::create() $nextMedia = CcScheduleQuery::create()
->filterByDbStarts($currentMedia["starts"], Criteria::GREATER_THAN) ->filterByDbStarts($currentMedia["starts"], Criteria::GREATER_THAN)
->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL) ->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL)
->filterByDbPlayoutStatus(0, Criteria::GREATER_THAN)
->orderByDbStarts(Criteria::ASC) ->orderByDbStarts(Criteria::ASC)
->findOne(); ->findOne();
if (isset($nextMedia)) { if (isset($nextMedia)) {

View File

@ -1157,13 +1157,13 @@ WHERE si.show_id = s.id
AND si.starts >= :timeNow::timestamp - INTERVAL '2 days' AND si.starts >= :timeNow::timestamp - INTERVAL '2 days'
AND si.starts < :timeEnd::timestamp AND si.starts < :timeEnd::timestamp
AND modified_instance != TRUE AND modified_instance != TRUE
ORDER BY ORDER BY
CASE CASE
WHEN si.ends > :timeNow::timestamp WHEN si.ends > :timeNow::timestamp
AND si.starts < :timeNow::timestamp THEN 1 AND si.starts < :timeNow::timestamp THEN 1
WHEN si.starts > :timeNow::timestamp THEN 2 WHEN si.starts > :timeNow::timestamp THEN 2
ELSE 3 ELSE 3
END END, si.starts
LIMIT :lim LIMIT :lim
SQL; SQL;

View File

@ -75,8 +75,13 @@ class Application_Model_StreamSetting
$host = $streamData[$prefix."host"]; $host = $streamData[$prefix."host"];
$port = $streamData[$prefix."port"]; $port = $streamData[$prefix."port"];
$mount = $streamData[$prefix."mount"]; $mount = $streamData[$prefix."mount"];
if ($streamData[$prefix."output"] == "shoutcast") {
$url = "http://$host:$port/";
} else { //Icecast
$url = "http://$host:$port/$mount";
}
$streams[$id] = Array( $streams[$id] = Array(
"url" => "http://$host:$port/$mount", "url" => $url,
"codec" => $streamData[$prefix."type"], "codec" => $streamData[$prefix."type"],
"bitrate" => $streamData[$prefix."bitrate"], "bitrate" => $streamData[$prefix."bitrate"],
"mobile" => $streamData[$prefix."mobile"] "mobile" => $streamData[$prefix."mobile"]

View File

@ -282,7 +282,6 @@ class Application_Model_User
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs "; $sql_gen = "SELECT login AS value, login AS label, id as index FROM cc_subjs ";
$sql = $sql_gen;
$types = array(); $types = array();
$params = array(); $params = array();
@ -296,13 +295,8 @@ class Application_Model_User
$sql = $sql_gen ." WHERE (". $sql_type.") "; $sql = $sql_gen ." WHERE (". $sql_type.") ";
if (!is_null($search)) { $sql .= " AND login ILIKE :search";
//need to use addslashes for 'LIKE' values $params[":search"] = "%$search%";
$search = addslashes($search);
$like = "login ILIKE '%{$search}%'";
$sql = $sql . " AND ".$like;
}
$sql = $sql ." ORDER BY login"; $sql = $sql ." ORDER BY login";

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

@ -15,6 +15,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?