Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-cloud-storage
Conflicts: airtime_mvc/build/sql/schema.sql
This commit is contained in:
commit
134ade877c
49 changed files with 739 additions and 548 deletions
|
@ -5,8 +5,17 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
public function init()
|
||||
{
|
||||
$ignoreAuth = array("live-info", "live-info-v2", "week-info",
|
||||
"station-metadata", "station-logo");
|
||||
$ignoreAuth = array("live-info",
|
||||
"live-info-v2",
|
||||
"week-info",
|
||||
"station-metadata",
|
||||
"station-logo",
|
||||
"show-history-feed",
|
||||
"item-history-feed",
|
||||
"shows",
|
||||
"show-tracks",
|
||||
"show-schedules"
|
||||
);
|
||||
|
||||
$params = $this->getRequest()->getParams();
|
||||
if (!in_array($params['action'], $ignoreAuth)) {
|
||||
|
@ -266,10 +275,10 @@ class ApiController extends Zend_Controller_Action
|
|||
$utcTimeEnd = $end->format("Y-m-d H:i:s");
|
||||
|
||||
$result = array(
|
||||
"env" => APPLICATION_ENV,
|
||||
"schedulerTime" => $utcTimeNow,
|
||||
"currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow),
|
||||
"nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd)
|
||||
"env" => APPLICATION_ENV,
|
||||
"schedulerTime" => $utcTimeNow,
|
||||
"currentShow" => Application_Model_Show::getCurrentShow($utcTimeNow),
|
||||
"nextShow" => Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd)
|
||||
);
|
||||
} else {
|
||||
$result = Application_Model_Schedule::GetPlayOrderRangeOld($limit);
|
||||
|
@ -476,9 +485,9 @@ class ApiController extends Zend_Controller_Action
|
|||
$shows,
|
||||
array("starts", "ends", "start_timestamp","end_timestamp"),
|
||||
$timezone
|
||||
);
|
||||
);
|
||||
|
||||
$result[$dow[$i]] = $shows;
|
||||
$result[$dow[$i]] = $shows;
|
||||
}
|
||||
|
||||
// XSS exploit prevention
|
||||
|
@ -1314,4 +1323,175 @@ class ApiController extends Zend_Controller_Action
|
|||
Application_Model_StreamSetting::SetListenerStatError($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display played items for a given time range and show instance_id
|
||||
*
|
||||
* @return json array
|
||||
*/
|
||||
public function itemHistoryFeedAction()
|
||||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$results = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
|
||||
|
||||
$this->_helper->json->sendJson($results['history']);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display show schedules for a given time range and show instance_id
|
||||
*
|
||||
* @return json array
|
||||
*/
|
||||
public function showHistoryFeedAction()
|
||||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$userId = $request->getParam("user_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$shows = $historyService->getShowList($startsDT, $endsDT, $userId);
|
||||
|
||||
$this->_helper->json->sendJson($shows);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display show info (without schedule) for given show_id
|
||||
*
|
||||
* @return json array
|
||||
*/
|
||||
public function showsAction()
|
||||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$showId = $request->getParam("show_id", null);
|
||||
$results = array();
|
||||
|
||||
if (empty($showId)) {
|
||||
$shows = CcShowQuery::create()->find();
|
||||
foreach($shows as $show) {
|
||||
$results[] = $show->getShowInfo();
|
||||
}
|
||||
} else {
|
||||
$show = CcShowQuery::create()->findPK($showId);
|
||||
$results[] = $show->getShowInfo();
|
||||
}
|
||||
|
||||
$this->_helper->json->sendJson($results);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display show schedule for given show_id
|
||||
*
|
||||
* @return json array
|
||||
*/
|
||||
public function showSchedulesAction()
|
||||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$showId = $request->getParam("show_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
if ((!isset($showId)) || (!is_numeric($showId))) {
|
||||
//if (!isset($showId)) {
|
||||
$this->_helper->json->sendJson(
|
||||
array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required show_id parameter. use type int.".$showId))
|
||||
);
|
||||
}
|
||||
|
||||
$shows = Application_Model_Show::getShows($startsDT, $endsDT, FALSE, $showId);
|
||||
|
||||
// is this a valid show?
|
||||
if (empty($shows)) {
|
||||
$this->_helper->json->sendJson(
|
||||
array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested show_id"))
|
||||
);
|
||||
}
|
||||
|
||||
$this->_helper->json->sendJson($shows);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* displays track listing for given instance_id
|
||||
*
|
||||
* @return json array
|
||||
*/
|
||||
public function showTracksAction()
|
||||
{
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
$prefTimezone = Application_Model_Preference::GetTimezone();
|
||||
|
||||
$instanceId = $this->_getParam('instance_id');
|
||||
|
||||
if ((!isset($instanceId)) || (!is_numeric($instanceId))) {
|
||||
$this->_helper->json->sendJson(
|
||||
array("jsonrpc" => "2.0", "error" => array("code" => 400, "message" => "missing invalid type for required instance_id parameter. use type int"))
|
||||
);
|
||||
}
|
||||
|
||||
$showInstance = new Application_Model_ShowInstance($instanceId);
|
||||
$showInstanceContent = $showInstance->getShowListContent($prefTimezone);
|
||||
|
||||
// is this a valid show instance with content?
|
||||
if (empty($showInstanceContent)) {
|
||||
$this->_helper->json->sendJson(
|
||||
array("jsonrpc" => "2.0", "error" => array("code" => 204, "message" => "no content for requested instance_id"))
|
||||
);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$position = 0;
|
||||
foreach ($showInstanceContent as $track) {
|
||||
|
||||
$elementMap = array(
|
||||
'title' => isset($track['track_title']) ? $track['track_title'] : "",
|
||||
'artist' => isset($track['creator']) ? $track['creator'] : "",
|
||||
'position' => $position,
|
||||
'id' => ++$position,
|
||||
'mime' => isset($track['mime'])?$track['mime']:"",
|
||||
'starts' => isset($track['starts']) ? $track['starts'] : "",
|
||||
'length' => isset($track['length']) ? $track['length'] : "",
|
||||
'file_id' => ($track['type'] == 0) ? $track['item_id'] : $track['filepath']
|
||||
);
|
||||
|
||||
$result[] = $elementMap;
|
||||
}
|
||||
|
||||
$this->_helper->json($result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,49 +10,6 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
->initContext();
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
@ -69,7 +26,7 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$startsDT->setTimezone($userTimezone);
|
||||
$endsDT->setTimezone($userTimezone);
|
||||
|
@ -98,7 +55,7 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
public function getDataAction(){
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest());
|
||||
|
||||
$data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"));
|
||||
$this->_helper->json->sendJson($data);
|
||||
|
|
|
@ -19,56 +19,13 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
->initContext();
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($this->getRequest());
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$startsDT->setTimezone($userTimezone);
|
||||
$endsDT->setTimezone($userTimezone);
|
||||
|
@ -123,7 +80,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
|
||||
|
@ -146,7 +103,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
|
||||
|
@ -169,7 +126,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$shows = $historyService->getShowList($startsDT, $endsDT);
|
||||
|
|
|
@ -236,49 +236,6 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function checkBuilderFeedAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
@ -287,7 +244,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$timestamp = intval($request->getParam("timestamp", -1));
|
||||
$instances = $request->getParam("instances", array());
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
|
||||
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||
|
@ -307,7 +264,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$show_instance_filter = intval($request->getParam("showInstanceFilter", 0));
|
||||
$my_shows = intval($request->getParam("myShows", 0));
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
list($startsDT, $endsDT) = Application_Common_HTTPHelper::getStartEndFromRequest($request);
|
||||
|
||||
$opts = array("myShows" => $my_shows,
|
||||
"showFilter" => $show_filter,
|
||||
|
|
|
@ -146,7 +146,14 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
// If we have an identity and we're making a RESTful request,
|
||||
// we need to check the CSRF token
|
||||
if ($request->_action != "get" && $request->getModuleName() == "rest") {
|
||||
$this->verifyCSRFToken($request->getParam("csrf_token"));
|
||||
$tokenValid = $this->verifyCSRFToken($request->getParam("csrf_token"));
|
||||
|
||||
if (!$tokenValid) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(401)
|
||||
->appendBody("ERROR: CSRF token mismatch.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
|
@ -189,10 +196,8 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$observed_csrf_token = $token;
|
||||
$expected_csrf_token = $current_namespace->authtoken;
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(401)
|
||||
->appendBody("ERROR: CSRF token mismatch.");
|
||||
Logging::error("Observed: " . $observed_csrf_token);
|
||||
Logging::error("Expected: " . $expected_csrf_token);
|
||||
|
||||
return ($observed_csrf_token == $expected_csrf_token);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue