SAAS-876 - reset to default settings when using Airtime Pro streaming

This commit is contained in:
Duncan Sommerville 2015-07-13 12:28:58 -04:00
parent 44dd969c0c
commit 9fdc08f88a
6 changed files with 78 additions and 15 deletions

View file

@ -11,6 +11,7 @@ class ProvisioningHelper
private $dbuser, $dbpass, $dbname, $dbhost, $dbowner, $apikey;
private $instanceId;
private $stationName, $description;
private $defaultIcecastPassword;
public function __construct($apikey)
{
@ -118,6 +119,9 @@ class ProvisioningHelper
if (isset($_POST['description'])) {
$this->description = $_POST['description'];
}
if (isset($_POST['icecast_pass'])) {
$this->defaultIcecastPassword = $_POST['icecast_pass'];
}
}
/**
@ -208,6 +212,9 @@ class ProvisioningHelper
if ($this->description) {
Application_Model_Preference::SetStationDescription($this->description);
}
if (isset($this->defaultIcecastPassword)) {
Application_Model_Preference::setDefaultIcecastPassword($this->defaultIcecastPassword);
}
}
}

View file

@ -32,6 +32,7 @@ define('DEFAULT_LOGO_PLACEHOLDER', 1);
define('DEFAULT_LOGO_FILE', 'images/airtime_logo.png');
define('DEFAULT_TIMESTAMP_FORMAT', 'Y-m-d H:i:s');
define('DEFAULT_MICROTIME_FORMAT', 'Y-m-d H:i:s.u');
define('DEFAULT_ICECAST_PASS', 'hackme');
// Metadata Keys for files
define('MDATA_KEY_FILEPATH' , 'filepath');

View file

@ -218,13 +218,7 @@ class PreferenceController extends Zend_Controller_Action
$s4_set_admin_pass = !empty($values["s4_data"]["admin_pass"]);
// this goes into cc_pref table
Application_Model_Preference::setUsingCustomStreamSettings($values['customStreamSettings']);
Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]);
Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]);
Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
$this->setStreamPreferences($values);
// compare new values with current value
$changeRGenabled = Application_Model_Preference::GetEnableReplayGain() != $values["enableReplayGain"];
@ -317,6 +311,21 @@ class PreferenceController extends Zend_Controller_Action
}
}
/**
* Set stream settings preferences
*
* @param array $values stream setting preference values
*/
private function setStreamPreferences($values) {
Application_Model_Preference::setUsingCustomStreamSettings($values['customStreamSettings']);
Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]);
Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]);
Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
}
public function serverBrowseAction()
{
$request = $this->getRequest();

View file

@ -41,6 +41,10 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$stream_types = $this->stream_types;
$stream_bitrates = $this->stream_bitrates;
$streamDefaults = Application_Model_StreamSetting::getDefaults($prefix);
// If we're not using custom stream settings, use the defaults
$useDefaults = !Application_Model_Preference::getUsingCustomStreamSettings();
$this->setIsArray(true);
$this->setElementsBelongTo($prefix."_data");
@ -77,7 +81,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$output = new Zend_Form_Element_Select('output');
$output->setLabel(_("Service Type:"))
->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"SHOUTcast"))
->setValue(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast")
->setValue($useDefaults ? $streamDefaults['output'] :
(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast"))
->setDecorators(array('ViewHelper'));
$this->addElement($output);
@ -91,7 +96,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$host = new Zend_Form_Element_Text('host');
$host->setLabel(_("Server"))
->setValue(isset($setting[$prefix.'_host'])?$setting[$prefix.'_host']:"")
->setValue($useDefaults ? $streamDefaults['host'] :
(isset($setting[$prefix.'_host'])?$setting[$prefix.'_host']:""))
->setValidators(array(
array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper'));
@ -100,7 +106,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$port = new Zend_Form_Element_Text('port');
$port->setLabel(_("Port"))
->setValue(isset($setting[$prefix.'_port'])?$setting[$prefix.'_port']:"")
->setValue($useDefaults ? $streamDefaults['port'] :
(isset($setting[$prefix.'_port'])?$setting[$prefix.'_port']:""))
->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'));
@ -108,7 +115,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$pass = new Zend_Form_Element_Text('pass');
$pass->setLabel(_("Password"))
->setValue(isset($setting[$prefix.'_pass'])?$setting[$prefix.'_pass']:"")
->setValue($useDefaults ? $streamDefaults['pass'] :
(isset($setting[$prefix.'_pass'])?$setting[$prefix.'_pass']:""))
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper'));
@ -144,7 +152,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$mount = new Zend_Form_Element_Text('mount');
$mount->setLabel(_("Mount Point"))
->setValue(isset($setting[$prefix.'_mount'])?$setting[$prefix.'_mount']:"")
->setValue($useDefaults ? $streamDefaults['mount'] :
(isset($setting[$prefix.'_mount'])?$setting[$prefix.'_mount']:""))
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper'));
@ -153,7 +162,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$user = new Zend_Form_Element_Text('user');
$user->setLabel(_("Username"))
->setValue(isset($setting[$prefix.'_user'])?$setting[$prefix.'_user']:"")
->setValue($useDefaults ? $streamDefaults['user'] :
(isset($setting[$prefix.'_user'])?$setting[$prefix.'_user']:""))
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper'));

View file

@ -1522,6 +1522,18 @@ class Application_Model_Preference
self::setValue("using_custom_stream_settings", $value);
}
// SAAS-876 - Store the default Icecast password to restore when switching
// back to Airtime Pro streaming settings
public static function getDefaultIcecastPassword() {
$val = self::getValue("default_icecast_password");
return empty($val) ? DEFAULT_ICECAST_PASS : $val;
}
public static function setDefaultIcecastPassword($value) {
self::setValue("default_icecast_password", $value);
}
public static function getRadioPageDisplayLoginButton()
{
return self::getValue("radio_page_display_login_button");

View file

@ -246,6 +246,10 @@ class Application_Model_StreamSetting
} elseif (is_array($d)) {
$temp = explode('_', $key);
$prefix = $temp[0];
// SAAS-876 - If we're using Airtime Pro streaming, set the stream to use the default settings
if (!Application_Model_Preference::getUsingCustomStreamSettings()) {
$d = array_merge($d, static::getDefaults($prefix));
}
foreach ($d as $k => $v) {
$keyname = $prefix . "_" . $k;
if ($k == 'enable') {
@ -265,8 +269,28 @@ class Application_Model_StreamSetting
}
}
/**
* SAAS-876 - Get the default stream settings values for Airtime Pro streaming
*
* @param int $prefix
*
* @return array array of default stream setting values
*/
public static function getDefaults($prefix) {
$config = Config::getConfig();
return array(
'host' => $config['stationId'] . '.out.airtime.pro',
'port' => 8000,
'output' => 'icecast',
'user' => $config['stationId'],
'pass' => Application_Model_Preference::getDefaultIcecastPassword(),
// Kind of ugly... convert prefix int to ascii char
'mount' => $config['stationId'] . '_' . chr($prefix[1] + 96),
);
}
/*
* Sets indivisual stream setting.
* Sets individual stream setting.
*
* $data - data array. $data is [].
* TODO: Make this SQL a prepared statement!