CC-3224: "On-the-fly" stream rebroadcasting

- frond-end implementation for master dj and live dj
- db implementation
- liquidsoap is broken on this commit
This commit is contained in:
James 2012-03-02 16:55:11 -05:00
parent 96c4462adc
commit 128a497059
16 changed files with 304 additions and 99 deletions

View file

@ -807,8 +807,6 @@ class ApiController extends Zend_Controller_Action
}
$info = Application_Model_StreamSetting::getStreamSetting();
$info[] = (array("keyname" =>"harbor_input_port", "value"=>Application_Model_Preference::GetLiveSteamPort(), "type"=>"integer"));
$info[] = (array("keyname" =>"harbor_input_mount_point", "value"=>Application_Model_Preference::GetLiveSteamMountPoint(), "type"=>"string"));
$this->view->msg = $info;
}
@ -988,6 +986,7 @@ class ApiController extends Zend_Controller_Action
$username = $request->getParam('username');
$password = $request->getParam('password');
$djtype = $request->getParam('djtype');
if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{
@ -995,11 +994,57 @@ class ApiController extends Zend_Controller_Action
print 'You are not allowed to access this resource.';
exit;
}
//check against master
if($username == Application_Model_Preference::GetLiveSteamMasterUsername() && $password == Application_Model_Preference::GetLiveSteamMasterPassword()){
$this->view->msg = true;
}else{
$this->view->msg = false;
Logging::log("user:".$username." pass:".$password." type:".$djtype);
if($djtype == 'master'){
//check against master
if($username == Application_Model_Preference::GetLiveSteamMasterUsername() && $password == Application_Model_Preference::GetLiveSteamMasterPassword()){
Logging::log("master true");
$this->view->msg = true;
}else{
Logging::log("master false");
$this->view->msg = false;
}
}elseif($djtype == "dj"){
Logging::log("djtype...");
//check against show dj auth
$showInfo = Application_Model_Show::GetCurrentShow();
if(isset($showInfo[0]['id'])){
$current_show_id = $showInfo[0]['id'];
$CcShow = CcShowQuery::create()->findPK($current_show_id);
// get custom pass info from the show
$custom_user = $CcShow->getDbLiveStreamUser();
$custom_pass = $CcShow->getDbLiveStreamPass();
Logging::log("user:".$username." pass:".$password);
Logging::log("c_user:".$custom_user." c_pass:".$custom_pass);
// get hosts ids
$show = new Application_Model_Show($current_show_id);
$hosts_ids = $show->getHostsIds();
// check against hosts auth
foreach( $hosts_ids as $host){
$h = new Application_Model_User($host['subjs_id']);
if($username == $h->getLogin() && md5($password) == $h->getPassword()){
$this->view->msg = true;
return;
}
}
// check against custom auth
if($username == $custom_user && $password == $custom_pass){
Logging::log("custom true");
$this->view->msg = true;
}else{
Logging::log("custom false");
$this->view->msg = false;
}
}else{
$this->view->msg = false;
}
}
}
}

View file

@ -205,23 +205,29 @@ class PreferenceController extends Zend_Controller_Action
$values['streamFormat'] = $form->getValue('streamFormat');
Application_Model_StreamSetting::setStreamSetting($values);
$data = array();
$info = Application_Model_StreamSetting::getStreamSetting();
$info[] = (array("keyname" =>"harbor_input_port", "value"=>$values["harbor_input_port"], "type"=>"integer"));
$info[] = (array("keyname" =>"harbor_input_mount_point", "value"=>$values["harbor_input_mount_point"], "type"=>"string"));
$data['setting'] = $info;
for($i=1;$i<=$num_of_stream;$i++){
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
}
// this goes into cc_pref table
Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
Application_Model_Preference::SetLiveSteamAutoEnable($values["auto_enable_live_stream"]);
Application_Model_Preference::SetLiveSteamMasterUsername($values["master_username"]);
Application_Model_Preference::SetLiveSteamMasterPassword($values["master_password"]);
Application_Model_Preference::SetLiveSteamPort($values["harbor_input_port"]);
Application_Model_Preference::SetLiveSteamMountPoint($values["harbor_input_mount_point"]);
// extra info that goes into cc_stream_setting
Application_Model_StreamSetting::SetMasterLiveSteamPort($values["master_harbor_input_port"]);
Application_Model_StreamSetting::SetMasterLiveSteamMountPoint($values["master_harbor_input_mount_point"]);
Application_Model_StreamSetting::SetDJLiveSteamPort($values["dj_harbor_input_port"]);
Application_Model_StreamSetting::SetDJLiveSteamMountPoint($values["dj_harbor_input_mount_point"]);
// store stream update timestamp
Application_Model_Preference::SetStreamUpdateTimestamp();
$data = array();
$info = Application_Model_StreamSetting::getStreamSetting();
$data['setting'] = $info;
for($i=1;$i<=$num_of_stream;$i++){
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
}
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
}

View file

@ -37,7 +37,6 @@ class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
->setFilters(array('StringTrim'))
->setValidators(array(
new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))))
->setValue(Application_Model_Preference::GetLiveSteamMasterUsername())
->setDecorators(array('ViewHelper'));
$this->addElement($custom_username);
@ -51,7 +50,6 @@ class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
->setFilters(array('StringTrim'))
->setValidators(array(
new ConditionalNotEmpty(array("cb_custom_auth"=>"1"))))
//fix//->setValue(Application_Model_Preference::GetLiveSteamMasterUsername())
->setDecorators(array('ViewHelper'));
$this->addElement($custom_password);

View file

@ -39,17 +39,34 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
$this->addElement($master_password);
//liquidsoap harbor.input port
$port = new Zend_Form_Element_Text('harbor_input_port');
$port->setLabel("Port to Connect")
->setValue(Application_Model_Preference::GetLiveSteamPort())
$port = new Zend_Form_Element_Text('master_harbor_input_port');
$port->setLabel("Master DJ Port")
->setValue(Application_Model_StreamSetting::GetMasterLiveSteamPort())
->setValidators(array(new Zend_Validate_Between(array('min'=>0, 'max'=>99999))))
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>'Only numbers are allowed.')))
->setDecorators(array('ViewHelper'));
$this->addElement($port);
$mount = new Zend_Form_Element_Text('harbor_input_mount_point');
$mount->setLabel("Mount Point to Connect")
->setValue(Application_Model_Preference::GetLiveSteamMountPoint())
$mount = new Zend_Form_Element_Text('master_harbor_input_mount_point');
$mount->setLabel("Master DJ Mount Point")
->setValue(Application_Model_StreamSetting::GetMasterLiveSteamMountPoint())
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered'))))
->setDecorators(array('ViewHelper'));
$this->addElement($mount);
//liquidsoap harbor.input port
$port = new Zend_Form_Element_Text('dj_harbor_input_port');
$port->setLabel("DJ Port")
->setValue(Application_Model_StreamSetting::GetDJLiveSteamPort())
->setValidators(array(new Zend_Validate_Between(array('min'=>0, 'max'=>99999))))
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>'Only numbers are allowed.')))
->setDecorators(array('ViewHelper'));
$this->addElement($port);
$mount = new Zend_Form_Element_Text('dj_harbor_input_mount_point');
$mount->setLabel("DJ Mount Point")
->setValue(Application_Model_StreamSetting::GetDJLiveSteamMountPoint())
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered'))))
->setDecorators(array('ViewHelper'));

View file

@ -728,22 +728,6 @@ class Application_Model_Preference
public static function GetLiveSteamMasterPassword(){
return self::GetValue("live_stream_master_password");
}
public static function SetLiveSteamPort($value){
self::SetValue("live_stream_port", $value, false);
}
public static function GetLiveSteamPort(){
return self::GetValue("live_stream_port");
}
public static function SetLiveSteamMountPoint($value){
self::SetValue("live_stream_mp", $value, false);
}
public static function GetLiveSteamMountPoint(){
return self::GetValue("live_stream_mp");
}
/* User specific preferences end */
}

View file

@ -104,6 +104,19 @@ class Application_Model_Show {
return $res;
}
public function getHostsIds()
{
global $CC_DBC;
$sql = "SELECT subjs_id
FROM cc_show_hosts
WHERE show_id = {$this->_showId}";
$hosts = $CC_DBC->GetAll($sql);
return $hosts;
}
//remove everything about this show.
public function delete()
@ -785,6 +798,8 @@ class Application_Model_Show {
$info['allow_live_stream_override'] = $ccShow->getDbAllowLiveStream();
$info['cb_airtime_auth'] = $ccShow->getDbLiveStreamUsingAirtimeAuth();
$info['cb_custom_auth'] = $ccShow->getDbLiveStreamUsingCustomAuth();
$info['custom_username'] = $ccShow->getDbLiveStreamUser();
$info['custom_password'] = $ccShow->getDbLiveStreamPass();
return $info;
}
}
@ -1698,9 +1713,13 @@ class Application_Model_Show {
* @param String $timeNow - current time (in UTC)
* @return array - show being played right now
*/
public static function GetCurrentShow($timeNow)
public static function GetCurrentShow($timeNow=null)
{
global $CC_CONFIG, $CC_DBC;
if($timeNow == null){
$date = new Application_Model_DateHelper;
$timeNow = $date->getUtcTimestamp();
}
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends"
." FROM $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"

View file

@ -1,5 +1,48 @@
<?php
class Application_Model_StreamSetting {
public static function SetValue($key, $value, $type){
global $CC_CONFIG, $CC_DBC;
$key = pg_escape_string($key);
$value = pg_escape_string($value);
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql);
if($result == 1) {
$sql = "UPDATE cc_stream_setting"
." SET value = '$value', type='$type'"
." WHERE keyname = '$key'";
} else {
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
." VALUES ('$key', '$value', '$type')";
}
return $CC_DBC->query($sql);
}
public static function GetValue($key){
global $CC_CONFIG, $CC_DBC;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql);
if ($result == 0)
return "";
else {
$sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = '$key'";
$result = $CC_DBC->GetOne($sql);
return $result;
}
}
/* Returns the id's of all streams that are enabled in an array. An
* example of the array returned in JSON notation is ["s1", "s2", "s3"] */
@ -63,6 +106,18 @@ class Application_Model_StreamSetting {
." WHERE keyname not like '%_error'";
$rows = $CC_DBC->getAll($sql);
if(isset($rows["master_harbor_input_port"])){
$rows[] = (array("keyname" =>"master_harbor_input_port", "value"=>self::GetMasterLiveSteamPort(), "type"=>"integer"));
}
if(isset($rows["master_harbor_input_mount_point"])){
$rows[] = (array("keyname" =>"master_harbor_input_mount_point", "value"=>self::GetMasterLiveSteamMountPoint(), "type"=>"string"));
}
if(isset($rows["dj_harbor_input_port"])){
$rows[] = (array("keyname" =>"dj_harbor_input_port", "value"=>self::GetDJLiveSteamPort(), "type"=>"integer"));
}
if(isset($rows["dj_harbor_input_mount_point"])){
$rows[] = (array("keyname" =>"dj_harbor_input_mount_point", "value"=>self::GetDJLiveSteamMountPoint(), "type"=>"string"));
}
return $rows;
}
@ -197,4 +252,36 @@ class Application_Model_StreamSetting {
}
return $out;
}
public static function SetMasterLiveSteamPort($value){
self::SetValue("master_live_stream_port", $value, "integer");
}
public static function GetMasterLiveSteamPort(){
return self::GetValue("master_live_stream_port");
}
public static function SetMasterLiveSteamMountPoint($value){
self::SetValue("master_live_stream_mp", $value, "string");
}
public static function GetMasterLiveSteamMountPoint(){
return self::GetValue("master_live_stream_mp");
}
public static function SetDJLiveSteamPort($value){
self::SetValue("dj_live_stream_port", $value, "integer");
}
public static function GetDJLiveSteamPort(){
return self::GetValue("dj_live_stream_port");
}
public static function SetDJLiveSteamMountPoint($value){
self::SetValue("dj_live_stream_mp", $value, "string");
}
public static function GetDJLiveSteamMountPoint(){
return self::GetValue("dj_live_stream_mp");
}
}

View file

@ -43,29 +43,57 @@
</ul>
<?php endif; ?>
</dd>
<dt id="harbor_input_port-label">
<label class="optional" for="harbor_input_port"><?php echo $this->element->getElement('harbor_input_port')->getLabel() ?> :
<dt id="master_harbor_input_port-label">
<label class="optional" for="master_harbor_input_port"><?php echo $this->element->getElement('master_harbor_input_port')->getLabel() ?> :
</label>
</dt>
<dd id="harbor_input_port-element">
<?php echo $this->element->getElement('harbor_input_port') ?>
<?php if($this->element->getElement('harbor_input_port')->hasErrors()) : ?>
<dd id="master_harbor_input_port-element">
<?php echo $this->element->getElement('master_harbor_input_port') ?>
<?php if($this->element->getElement('master_harbor_input_port')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('harbor_input_port')->getMessages() as $error): ?>
<?php foreach($this->element->getElement('master_harbor_input_port')->getMessages() as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</dd>
<dt id="harbor_input_mount_point-label">
<label class="optional" for="harbor_input_mount_point"><?php echo $this->element->getElement('harbor_input_mount_point')->getLabel() ?> :
<dt id="master_harbor_input_mount_point-label">
<label class="optional" for="master_harbor_input_mount_point"><?php echo $this->element->getElement('master_harbor_input_mount_point')->getLabel() ?> :
</label>
</dt>
<dd id="harbor_input_mount_point-element">
<?php echo $this->element->getElement('harbor_input_mount_point') ?>
<?php if($this->element->getElement('harbor_input_mount_point')->hasErrors()) : ?>
<dd id="master_harbor_input_mount_point-element">
<?php echo $this->element->getElement('master_harbor_input_mount_point') ?>
<?php if($this->element->getElement('master_harbor_input_mount_point')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('harbor_input_mount_point')->getMessages() as $error): ?>
<?php foreach($this->element->getElement('master_harbor_input_mount_point')->getMessages() as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</dd>
<dt id="dj_harbor_input_port-label">
<label class="optional" for="dj_harbor_input_port"><?php echo $this->element->getElement('dj_harbor_input_port')->getLabel() ?> :
</label>
</dt>
<dd id="dj_harbor_input_port-element">
<?php echo $this->element->getElement('dj_harbor_input_port') ?>
<?php if($this->element->getElement('dj_harbor_input_port')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('dj_harbor_input_port')->getMessages() as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</dd>
<dt id="dj_harbor_input_mount_point-label">
<label class="optional" for="dj_harbor_input_mount_point"><?php echo $this->element->getElement('dj_harbor_input_mount_point')->getLabel() ?> :
</label>
</dt>
<dd id="dj_harbor_input_mount_point-element">
<?php echo $this->element->getElement('dj_harbor_input_mount_point') ?>
<?php if($this->element->getElement('dj_harbor_input_mount_point')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('dj_harbor_input_mount_point')->getMessages() as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>