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;
}
}
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
* by passing them through htmlspecialchars
*
* @param unknown $arr the array to sanitize
* @param unknown $keys indexes of values to be sanitized
* @param array $arr the array to sanitize
* @param array $keys indexes of values to be sanitized
*/
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,
* 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)
{
@ -480,26 +480,38 @@ class ApiController extends Zend_Controller_Action
*/
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()) {
$request = $this->getRequest();
$showId = $request->getParam('id');
// if no id is passed, just die - redirects to a 404
if (!$showId || $showId === '') {
return;
if (empty($showId)) {
throw new ZendActionHttpException($this, 400, "ERROR: No ID was given.");
}
$show = CcShowQuery::create()->findPk($showId);
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
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.");
}
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type);
} else {
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. ');
exit;

View File

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

View File

@ -102,7 +102,6 @@ class UserController extends Zend_Controller_Action
public function getHostsAction()
{
$search = $this->_getParam('term');
$res = 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.
// The reason is because we use that as a password placeholder
// on the client side.
if (($formData['cu_password'] != "xxxxxx") &&
if (array_key_exists('cu_password', $formData) && ($formData['cu_password'] != "xxxxxx") &&
(!empty($formData['cu_password']))) {
$user->setPassword($formData['cu_password']);
}
$user->setEmail($formData['cu_email']);
$user->setCellPhone($formData['cu_cell_phone']);
$user->setSkype($formData['cu_skype']);
$user->setJabber($formData['cu_jabber']);
if (array_key_exists('cu_email', $formData)) {
$user->setEmail($formData['cu_email']);
}
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();
Application_Model_Preference::SetUserLocale($formData['cu_locale']);

View File

@ -268,6 +268,7 @@ SQL;
$nextMedia = CcScheduleQuery::create()
->filterByDbStarts($currentMedia["starts"], Criteria::GREATER_THAN)
->filterByDbId($currentMedia["id"], Criteria::NOT_EQUAL)
->filterByDbPlayoutStatus(0, Criteria::GREATER_THAN)
->orderByDbStarts(Criteria::ASC)
->findOne();
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 < :timeEnd::timestamp
AND modified_instance != TRUE
ORDER BY
CASE
ORDER BY
CASE
WHEN si.ends > :timeNow::timestamp
AND si.starts < :timeNow::timestamp THEN 1
WHEN si.starts > :timeNow::timestamp THEN 2
ELSE 3
END
END, si.starts
LIMIT :lim
SQL;

View File

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

View File

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

View File

@ -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);
$con = Propel::getConnection();
try {
$con = Propel::getConnection();
$con->beginTransaction();
$show->setDbImagePath($path);
@ -103,8 +104,8 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
$show = CcShowQuery::create()->findPk($showId);
$con = Propel::getConnection();
try {
$con = Propel::getConnection();
$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.");

View File

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