feat(legacy): read stream config from file

- We don't delete the stream preferences from the database to prevent data loss. This will be handled in a future release.
This commit is contained in:
jo 2022-09-06 12:00:50 +02:00 committed by Kyle Robbertze
parent ba73866e47
commit 5bf62dd9cb
14 changed files with 498 additions and 1237 deletions

View file

@ -4,9 +4,6 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
{
public function init()
{
$CC_CONFIG = Config::getConfig();
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
$this->setDecorators([
@ -46,13 +43,9 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
$this->addElement($master_username);
// Master password
if ($isDemo) {
$master_password = new Zend_Form_Element_Text('master_password');
} else {
$master_password = new Zend_Form_Element_Password('master_password');
$master_password->setAttrib('renderPassword', 'true');
}
$master_password->setAttrib('autocomplete', 'off')
$master_password = new Zend_Form_Element_Password('master_password');
$master_password
->setAttrib('autocomplete', 'off')
->setAttrib('renderPassword', 'true')
->setAllowEmpty(true)
->setValue(Application_Model_Preference::GetLiveStreamMasterPassword())
@ -60,74 +53,53 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
->setFilters(['StringTrim']);
$this->addElement($master_password);
$masterSourceParams = parse_url(Application_Model_Preference::GetMasterDJSourceConnectionURL());
// Master source connection url parameters
$masterSourceHost = new Zend_Form_Element_Text('master_source_host');
$masterSourceHost->setLabel(_('Master Source Host:'))
$masterSourceHost
->setLabel(_('Master Source Host:'))
->setAttrib('readonly', true)
->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL());
$this->addElement($masterSourceHost);
// liquidsoap harbor.input port
$betweenValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(1024, 49151);
$m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
$masterSourcePort->setLabel(_('Master Source Port:'))
->setValue($m_port)
->setValidators([$betweenValidator])
->addValidator('regex', false, ['pattern' => '/^[0-9]+$/', 'messages' => ['regexNotMatch' => _('Only numbers are allowed.')]]);
$masterSourcePort
->setLabel(_('Master Source Port:'))
->setAttrib('readonly', true)
->setValue(Application_Model_StreamSetting::getMasterLiveStreamPort());
$this->addElement($masterSourcePort);
$m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
$masterSourceMount = new Zend_Form_Element_Text('master_source_mount');
$masterSourceMount->setLabel(_('Master Source Mount:'))
->setValue($m_mount)
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
]);
$masterSourceMount
->setLabel(_('Master Source Mount:'))
->setAttrib('readonly', true)
->setValue(Application_Model_StreamSetting::getMasterLiveStreamMountPoint());
$this->addElement($masterSourceMount);
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
// Show source connection url parameters
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
$showSourceHost->setLabel(_('Show Source Host:'))
$showSourceHost
->setLabel(_('Show Source Host:'))
->setAttrib('readonly', true)
->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL());
$this->addElement($showSourceHost);
// liquidsoap harbor.input port
$l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
$showSourcePort->setLabel(_('Show Source Port:'))
->setValue($l_port)
->setValidators([$betweenValidator])
->addValidator('regex', false, ['pattern' => '/^[0-9]+$/', 'messages' => ['regexNotMatch' => _('Only numbers are allowed.')]]);
$showSourcePort
->setLabel(_('Show Source Port:'))
->setAttrib('readonly', true)
->setValue(Application_Model_StreamSetting::getDjLiveStreamPort());
$this->addElement($showSourcePort);
$l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
$showSourceMount->setLabel(_('Show Source Mount:'))
->setValue($l_mount)
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
]);
$showSourceMount
->setLabel(_('Show Source Mount:'))
->setAttrib('readonly', true)
->setValue(Application_Model_StreamSetting::getDjLiveStreamMountPoint());
$this->addElement($showSourceMount);
}
public function updateVariables()
{
$CC_CONFIG = Config::getConfig();
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
$masterSourceParams = parse_url(Application_Model_Preference::GetMasterDJSourceConnectionURL());
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
$this->setDecorators(
[
[
@ -140,7 +112,6 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
'show_source_host' => isset($showSourceHost) ? Application_Model_Preference::GetLiveDJSourceConnectionURL() : '',
'show_source_port' => isset($showSourcePort) ? Application_Model_StreamSetting::getDjLiveStreamPort() : '',
'show_source_mount' => isset($showSourceMount) ? Application_Model_StreamSetting::getDjLiveStreamMountPoint() : '',
'isDemo' => $isDemo,
],
],
]

View file

@ -21,88 +21,55 @@ class Application_Form_StreamSetting extends Zend_Form
$setting = $this->setting;
$stream_format = new Zend_Form_Element_Radio('streamFormat');
$stream_format
->setLabel(_('Stream Label:'))
->setMultiOptions([
_('Artist - Title'),
_('Show - Artist - Title'),
_('Station name - Show name'),
])
->setValue(Application_Model_Preference::GetStreamLabelFormat())
->setDecorators(['ViewHelper']);
$this->addElement($stream_format);
$offAirMeta = new Zend_Form_Element_Text('offAirMeta');
$offAirMeta
->setLabel(_('Off Air Metadata'))
->setValue(Application_Model_Preference::getOffAirMeta())
->setDecorators(['ViewHelper']);
$this->addElement($offAirMeta);
$enable_replay_gain = new Zend_Form_Element_Checkbox('enableReplayGain');
$enable_replay_gain
->setLabel(_('Enable Replay Gain'))
->setValue(Application_Model_Preference::GetEnableReplayGain())
->setDecorators(['ViewHelper']);
$this->addElement($enable_replay_gain);
$replay_gain = new Zend_Form_Element_Hidden('replayGainModifier');
$replay_gain
->setLabel(_('Replay Gain Modifier'))
->setValue(Application_Model_Preference::getReplayGainModifier())
->setAttribs(['style' => 'border: 0; color: #f6931f; font-weight: bold;'])
->setDecorators(['ViewHelper']);
$this->addElement($replay_gain);
$output_sound_device = new Zend_Form_Element_Checkbox('output_sound_device');
$output_sound_device->setLabel(_('Hardware Audio Output:'))
$output_sound_device
->setLabel(_('Hardware Audio Output:'))
->setAttrib('readonly', true)
->setRequired(false)
->setValue(($setting['output_sound_device'] == 'true') ? 1 : 0)
->setDecorators(['ViewHelper']);
$this->addElement($output_sound_device);
$output_sound_device_type = new Zend_Form_Element_Select('output_sound_device_type');
$output_sound_device_type->setLabel(_('Output Type'))
->setMultiOptions([
'ALSA' => _('ALSA'),
'AO' => _('AO'),
'OSS' => _('OSS'),
'Portaudio' => _('Portaudio'),
'Pulseaudio' => _('Pulseaudio'),
'Jack' => _('Jack'),
])
$output_sound_device_type
->setLabel(_('Output Type'))
->setAttrib('readonly', true)
->setValue(isset($setting['output_sound_device_type']) ? $setting['output_sound_device_type'] : 0)
->setDecorators(['ViewHelper']);
$this->addElement($output_sound_device_type);
$icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata');
$icecast_vorbis_metadata->setLabel(_('Icecast Vorbis Metadata'))
->setRequired(false)
->setValue(($setting['icecast_vorbis_metadata'] == 'true') ? 1 : 0)
->setDecorators(['ViewHelper']);
if (Application_Model_Preference::GetEnableStreamConf() == 'false') {
$icecast_vorbis_metadata->setAttrib('readonly', true);
}
$this->addElement($icecast_vorbis_metadata);
$stream_format = new Zend_Form_Element_Radio('streamFormat');
$stream_format->setLabel(_('Stream Label:'));
$stream_format->setMultiOptions([
_('Artist - Title'),
_('Show - Artist - Title'),
_('Station name - Show name'),
]);
$stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat());
$stream_format->setDecorators(['ViewHelper']);
$this->addElement($stream_format);
$offAirMeta = new Zend_Form_Element_Text('offAirMeta');
$offAirMeta->setLabel(_('Off Air Metadata'))
->setValue(Application_Model_Preference::getOffAirMeta())
->setDecorators(['ViewHelper']);
$this->addElement($offAirMeta);
$enable_replay_gain = new Zend_Form_Element_Checkbox('enableReplayGain');
$enable_replay_gain->setLabel(_('Enable Replay Gain'))
->setValue(Application_Model_Preference::GetEnableReplayGain())
->setDecorators(['ViewHelper']);
$this->addElement($enable_replay_gain);
$replay_gain = new Zend_Form_Element_Hidden('replayGainModifier');
$replay_gain->setLabel(_('Replay Gain Modifier'))
->setValue(Application_Model_Preference::getReplayGainModifier())
->setAttribs(['style' => 'border: 0; color: #f6931f; font-weight: bold;'])
->setDecorators(['ViewHelper']);
$this->addElement($replay_gain);
$custom = Application_Model_Preference::getUsingCustomStreamSettings();
$customSettings = new Zend_Form_Element_Radio('customStreamSettings');
$customSettings->setLabel(_('Streaming Server:'));
$customSettings->setMultiOptions([_('Default Streaming'), _('Custom / 3rd Party Streaming')]);
$customSettings->setValue(!empty($custom) ? $custom : 0);
$this->addElement($customSettings);
}
public function isValid($data)
{
if (isset($data['output_sound_device'])) {
$d = [];
$d['output_sound_device'] = $data['output_sound_device'];
$d['icecast_vorbis_metadata'] = $data['icecast_vorbis_metadata'];
if (isset($data['output_sound_device_type'])) {
$d['output_sound_device_type'] = $data['output_sound_device_type'];
}
$d['streamFormat'] = $data['streamFormat'];
$this->populate($d);
}
return parent::isValid($data);
}
}

View file

@ -4,8 +4,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
{
private $prefix;
private $setting;
private $stream_types;
private $stream_bitrates;
public static $customizable;
@ -23,171 +21,127 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$this->setting = $setting;
}
public function setStreamTypes($stream_types)
{
$this->stream_types = $stream_types;
}
public function setStreamBitrates($stream_bitrates)
{
$this->stream_bitrates = $stream_bitrates;
}
public function startForm()
{
$prefix = 's' . $this->prefix;
$stream_number = $this->prefix;
$setting = $this->setting;
$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');
$enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel(_('Enabled:'))
$enable
->setLabel(_('Enabled:'))
->setAttrib('disabled', true)
->setValue($setting[$prefix . '_enable'] == 'true' ? 1 : 0)
->setDecorators(['ViewHelper']);
$this->addElement($enable);
static::$customizable[] = $enable->getName();
$mobile = new Zend_Form_Element_Checkbox('mobile');
$mobile->setLabel(_('Mobile:'));
$mobile->setValue($setting[$prefix . '_mobile']);
$mobile->setDecorators(['ViewHelper']);
$mobile
->setLabel(_('Mobile:'))
->setAttrib('disabled', true)
->setValue($setting[$prefix . '_mobile'])
->setDecorators(['ViewHelper']);
$this->addElement($mobile);
static::$customizable[] = $mobile->getName();
$type = new Zend_Form_Element_Select('type');
$type->setLabel(_('Stream Type:'))
->setMultiOptions($stream_types)
$type = new Zend_Form_Element_Text('type');
$type
->setLabel(_('Stream Type:'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_type']) ? $setting[$prefix . '_type'] : 0)
->setDecorators(['ViewHelper']);
$this->addElement($type);
static::$customizable[] = $type->getName();
$bitrate = new Zend_Form_Element_Select('bitrate');
$bitrate->setLabel(_('Bit Rate:'))
->setMultiOptions($stream_bitrates)
$bitrate = new Zend_Form_Element_Text('bitrate');
$bitrate
->setLabel(_('Bit Rate:'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_bitrate']) ? $setting[$prefix . '_bitrate'] : 0)
->setDecorators(['ViewHelper']);
$this->addElement($bitrate);
static::$customizable[] = $bitrate->getName();
$output = new Zend_Form_Element_Select('output');
$output->setLabel(_('Service Type:'))
->setMultiOptions(['icecast' => 'Icecast', 'shoutcast' => 'SHOUTcast'])
->setValue($useDefaults ? $streamDefaults['output'] : (isset($setting[$prefix . '_output']) ? $setting[$prefix . '_output'] : 'icecast'))
$output = new Zend_Form_Element_Text('output');
$output
->setLabel(_('Service Type:'))
->setAttrib('readonly', true)
->setValue((isset($setting[$prefix . '_output']) ? $setting[$prefix . '_output'] : 'icecast'))
->setDecorators(['ViewHelper']);
$this->addElement($output);
$channels = new Zend_Form_Element_Select('channels');
$channels->setLabel(_('Channels:'))
->setMultiOptions(['mono' => _('1 - Mono'), 'stereo' => _('2 - Stereo')])
$channels = new Zend_Form_Element_Text('channels');
$channels
->setLabel(_('Channels:'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_channels']) ? $setting[$prefix . '_channels'] : 'stereo')
->setDecorators(['ViewHelper']);
$this->addElement($channels);
static::$customizable[] = $channels->getName();
$host = new Zend_Form_Element_Text('host');
$host->setLabel(_('Server'))
->setValue($useDefaults ? $streamDefaults['host'] : (isset($setting[$prefix . '_host']) ? $setting[$prefix . '_host'] : ''))
->setValidators([
['regex', false, ['/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered')]],
])
$host
->setLabel(_('Server'))
->setAttrib('readonly', true)
->setValue((isset($setting[$prefix . '_host']) ? $setting[$prefix . '_host'] : ''))
->setDecorators(['ViewHelper']);
$host->setAttrib('alt', 'domain');
$this->addElement($host);
$port = new Zend_Form_Element_Text('port');
$port->setLabel(_('Port'))
->setValue($useDefaults ? $streamDefaults['port'] : (isset($setting[$prefix . '_port']) ? $setting[$prefix . '_port'] : ''))
->setValidators([new Zend_Validate_Between(['min' => 0, 'max' => 99999])])
->addValidator('regex', false, ['pattern' => '/^[0-9]+$/', 'messages' => ['regexNotMatch' => _('Only numbers are allowed.')]])
$port
->setLabel(_('Port'))
->setAttrib('readonly', true)
->setValue((isset($setting[$prefix . '_port']) ? $setting[$prefix . '_port'] : ''))
->setDecorators(['ViewHelper']);
$this->addElement($port);
$pass = new Zend_Form_Element_Text('pass');
$pass->setLabel(_('Password'))
->setValue($useDefaults ? $streamDefaults['pass'] : (isset($setting[$prefix . '_pass']) ? $setting[$prefix . '_pass'] : ''))
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
])
$mount = new Zend_Form_Element_Text('mount');
$mount
->setLabel(_('Mount Point'))
->setAttrib('readonly', true)
->setValue((isset($setting[$prefix . '_mount']) ? $setting[$prefix . '_mount'] : ''))
->setDecorators(['ViewHelper']);
$pass->setAttrib('alt', 'regular_text');
$this->addElement($pass);
$mount->setAttrib('alt', 'regular_text');
$this->addElement($mount);
$name = new Zend_Form_Element_Text('name');
$name
->setLabel(_('Name'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_name']) ? $setting[$prefix . '_name'] : '')
->setDecorators(['ViewHelper']);
$this->addElement($name);
$genre = new Zend_Form_Element_Text('genre');
$genre->setLabel(_('Genre'))
$genre
->setAttrib('readonly', true)
->setLabel(_('Genre'))
->setValue(isset($setting[$prefix . '_genre']) ? $setting[$prefix . '_genre'] : '')
->setDecorators(['ViewHelper']);
$this->addElement($genre);
$url = new Zend_Form_Element_Text('url');
$url->setLabel(_('URL'))
$url
->setLabel(_('URL'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_url']) ? $setting[$prefix . '_url'] : '')
->setValidators([
['regex', false, ['/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => _('Invalid character entered')]],
])
->setDecorators(['ViewHelper']);
$url->setAttrib('alt', 'url');
$this->addElement($url);
$name = new Zend_Form_Element_Text('name');
$name->setLabel(_('Name'))
->setValue(isset($setting[$prefix . '_name']) ? $setting[$prefix . '_name'] : '')
->setDecorators(['ViewHelper']);
$this->addElement($name);
$description = new Zend_Form_Element_Text('description');
$description->setLabel(_('Description'))
$description
->setLabel(_('Description'))
->setAttrib('readonly', true)
->setValue(isset($setting[$prefix . '_description']) ? $setting[$prefix . '_description'] : '')
->setDecorators(['ViewHelper']);
$this->addElement($description);
$mount = new Zend_Form_Element_Text('mount');
$mount->setLabel(_('Mount Point'))
->setValue($useDefaults ? $streamDefaults['mount'] : (isset($setting[$prefix . '_mount']) ? $setting[$prefix . '_mount'] : ''))
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
])
->setDecorators(['ViewHelper']);
$mount->setAttrib('alt', 'regular_text');
$this->addElement($mount);
$user = new Zend_Form_Element_Text('user');
$user->setLabel(_('Username'))
->setValue($useDefaults ? $streamDefaults['user'] : (isset($setting[$prefix . '_user']) ? $setting[$prefix . '_user'] : ''))
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
])
->setDecorators(['ViewHelper']);
$user->setAttrib('alt', 'regular_text');
$this->addElement($user);
$adminUser = new Zend_Form_Element_Text('admin_user');
$adminUser->setLabel(_('Admin User'))
->setValue(Application_Model_StreamSetting::getAdminUser($prefix))
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
])
->setDecorators(['ViewHelper']);
$adminUser->setAttrib('alt', 'regular_text');
$this->addElement($adminUser);
$adminPass = new Zend_Form_Element_Password('admin_pass');
$adminPass->setLabel(_('Admin Password'))
->setValue(Application_Model_StreamSetting::getAdminPass($prefix))
->setValidators([
['regex', false, ['/^[^ &<>]+$/', 'messages' => _('Invalid character entered')]],
])
->setDecorators(['ViewHelper']);
$adminPass->setAttrib('alt', 'regular_text');
$this->addElement($adminPass);
$public_url = new Zend_Form_Element_Text('public_url');
$public_url
->setLabel(_('Stream URL'))
->setValue($setting[$prefix . '_public_url'] ?? '');
$this->addElement($public_url);
$liquidsoap_error_msg = '<div class="stream-status status-info"><p>' . _('Getting information from the server...') . '</p></div>';
@ -200,48 +154,4 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
]],
]);
}
public function isValid($data)
{
$f_data = $data['s' . $this->prefix . '_data'];
$isValid = parent::isValid($f_data);
// XXX: A couple of ugly workarounds here, but I guess that's what you get when you
// combine an already-complex POST and GET into a single action...
if (Application_Model_Preference::getUsingCustomStreamSettings() && $f_data) {
if ($f_data['enable'] == 1 && isset($f_data['host'])) {
if ($f_data['host'] == '') {
$element = $this->getElement('host');
$element->addError(_('Server cannot be empty.'));
$isValid = false;
}
if ($f_data['port'] == '') {
$element = $this->getElement('port');
$element->addError(_('Port cannot be empty.'));
$isValid = false;
}
if ($f_data['output'] == 'icecast') {
if ($f_data['mount'] == '') {
$element = $this->getElement('mount');
$element->addError(_('Mount cannot be empty with Icecast server.'));
$isValid = false;
}
}
}
}
return $isValid;
}
public function toggleState()
{
$elements = $this->getElements();
foreach ($elements as $element) {
if (Application_Model_Preference::getUsingCustomStreamSettings()) {
$element->setAttrib('disabled', null);
} elseif (!(in_array($element->getName(), static::$customizable)
|| $element->getType() == 'Zend_Form_Element_Hidden')) {
$element->setAttrib('disabled', 'disabled');
}
}
}
}