Merge branch 'cc-5709-airtime-analyzer-cloud-storage' into cc-5709-airtime-analyzer-cloud-storage-saas
Conflicts: airtime_mvc/application/Bootstrap.php airtime_mvc/application/configs/ACL.php airtime_mvc/application/controllers/ApiController.php airtime_mvc/application/controllers/plugins/Acl_plugin.php airtime_mvc/application/forms/GeneralPreferences.php airtime_mvc/application/modules/rest/controllers/MediaController.php airtime_mvc/application/views/scripts/form/preferences_general.phtml airtime_mvc/application/views/scripts/form/support-setting.phtml airtime_mvc/build/sql/schema.sql
This commit is contained in:
commit
ca9750f415
46 changed files with 771 additions and 595 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", "show-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);
|
||||
|
@ -479,9 +488,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
|
||||
|
@ -1412,4 +1421,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);
|
||||
|
|
|
@ -244,49 +244,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();
|
||||
|
@ -295,7 +252,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);
|
||||
|
@ -315,7 +272,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,
|
||||
|
|
|
@ -111,16 +111,16 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
$controller = strtolower($request->getControllerName());
|
||||
Application_Model_Auth::pinSessionToClient(Zend_Auth::getInstance());
|
||||
|
||||
//Ignore authentication for all access to the rest API. We do auth via API keys for this
|
||||
//and/or by OAuth.
|
||||
if (strtolower($request->getModuleName()) == "rest")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($controller, array("api", "auth", "locale", "upgrade", 'whmcs-login', "provisioning"))) {
|
||||
$this->setRoleName("G");
|
||||
} elseif (!Zend_Auth::getInstance()->hasIdentity()) {
|
||||
|
||||
// If we don't have an identity and we're making a RESTful request,
|
||||
// we need to do API key verification
|
||||
if ($request->getModuleName() == "rest") {
|
||||
$this->verifyAuth();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($controller !== 'login') {
|
||||
|
||||
|
@ -143,7 +143,19 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// 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") {
|
||||
$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();
|
||||
$this->setRoleName($userInfo->type);
|
||||
|
||||
|
@ -169,6 +181,40 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
}
|
||||
}
|
||||
|
||||
private function verifyAuth() {
|
||||
if ($this->verifyAPIKey()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(401)
|
||||
->appendBody("ERROR: Incorrect API key.");
|
||||
return false;
|
||||
}
|
||||
|
||||
private function verifyCSRFToken($token) {
|
||||
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$observed_csrf_token = $token;
|
||||
$expected_csrf_token = $current_namespace->authtoken;
|
||||
Logging::error("Observed: " . $observed_csrf_token);
|
||||
Logging::error("Expected: " . $expected_csrf_token);
|
||||
|
||||
return ($observed_csrf_token == $expected_csrf_token);
|
||||
}
|
||||
|
||||
private function verifyAPIKey() {
|
||||
// The API key is passed in via HTTP "basic authentication":
|
||||
// http://en.wikipedia.org/wiki/Basic_access_authentication
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
// Decode the API key that was passed to us in the HTTP request.
|
||||
$authHeader = $this->getRequest()->getHeader("Authorization");
|
||||
$encodedRequestApiKey = substr($authHeader, strlen("Basic "));
|
||||
$encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":");
|
||||
|
||||
return ($encodedRequestApiKey === $encodedStoredApiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deny Access Function
|
||||
* Redirects to errorPage, this can be called from an action using the action helper
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue