From b1211d3aa113999329ba72d8e68b001a04e0296d Mon Sep 17 00:00:00 2001 From: James Date: Wed, 21 Dec 2011 12:05:45 -0500 Subject: [PATCH 1/6] IN-66: Stat server modification - fixed url for airtime_latest_version file --- utils/phone_home_stat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/phone_home_stat.php b/utils/phone_home_stat.php index a230f31ad..c7738a6b4 100644 --- a/utils/phone_home_stat.php +++ b/utils/phone_home_stat.php @@ -79,7 +79,7 @@ if(Application_Model_Preference::GetSupportFeedback() == '1'){ // Get latest version from stat server and store to db if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ - $url = 'http://stat.sourcefabric.org/airtime_latest_version'; + $url = 'http://stat.sourcefabric.org/airtime-stats/airtime_latest_version'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); From 30b192a80920532651e41d2511512da902bb807e Mon Sep 17 00:00:00 2001 From: James Date: Wed, 21 Dec 2011 17:30:42 -0500 Subject: [PATCH 2/6] CC-3218: tream-settings: Spaces and other illegal characters should not be allowed in the fields: server, username, password, URL, and mount point - masking was added on the front end and validators were added for the server side. - extra fix: fixed php undefined index notice problem. --- .../controllers/PreferenceController.php | 1 + airtime_mvc/application/forms/StreamSetting.php | 4 +++- .../application/forms/StreamSettingSubForm.php | 15 +++++++++++++++ .../js/airtime/preferences/streamsetting.js | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 88ceca045..8d227c7e7 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -133,6 +133,7 @@ class PreferenceController extends Zend_Controller_Action $baseUrl = $request->getBaseUrl(); $this->view->headScript()->appendFile($baseUrl.'/js/airtime/preferences/streamsetting.js','text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/meioMask/jquery.meio.mask.js','text/javascript'); // get current settings $temp = Application_Model_StreamSetting::getStreamSetting(); diff --git a/airtime_mvc/application/forms/StreamSetting.php b/airtime_mvc/application/forms/StreamSetting.php index 9d5289ebf..6c4e59871 100644 --- a/airtime_mvc/application/forms/StreamSetting.php +++ b/airtime_mvc/application/forms/StreamSetting.php @@ -68,8 +68,10 @@ class Application_Form_StreamSetting extends Zend_Form } public function isValid($data){ - $this->populate(array("output_sound_device"=>$data['output_sound_device'], "icecast_vorbis_metadata"=>$data['icecast_vorbis_metadata'], + if($data['output_sound_device']){ + $this->populate(array("output_sound_device"=>$data['output_sound_device'], "icecast_vorbis_metadata"=>$data['icecast_vorbis_metadata'], "output_sound_device_type"=>$data['output_sound_device_type'], "streamFormat"=>$data['streamFormat'])); + } return true; } } diff --git a/airtime_mvc/application/forms/StreamSettingSubForm.php b/airtime_mvc/application/forms/StreamSettingSubForm.php index f63825eb8..2d69d9c29 100644 --- a/airtime_mvc/application/forms/StreamSettingSubForm.php +++ b/airtime_mvc/application/forms/StreamSettingSubForm.php @@ -83,10 +83,13 @@ 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']:"") + ->setValidators(array( + array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $host->setAttrib("disabled", "disabled"); } + $host->setAttrib('alt', 'regular_text'); $this->addElement($host); $port = new Zend_Form_Element_Text('port'); @@ -103,10 +106,13 @@ 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']:"") + ->setValidators(array( + array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $pass->setAttrib("disabled", "disabled"); } + $pass->setAttrib('alt', 'regular_text'); $this->addElement($pass); $genre = new Zend_Form_Element_Text('genre'); @@ -121,10 +127,13 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{ $url = new Zend_Form_Element_Text('url'); $url->setLabel("URL") ->setValue(isset($setting[$prefix.'_url'])?$setting[$prefix.'_url']:"") + ->setValidators(array( + array('regex', false, array('/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $url->setAttrib("disabled", "disabled"); } + $url->setAttrib('alt', 'url'); $this->addElement($url); $description = new Zend_Form_Element_Text('description'); @@ -139,19 +148,25 @@ 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']:"") + ->setValidators(array( + array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $mount->setAttrib("disabled", "disabled"); } + $mount->setAttrib('alt', 'regular_text'); $this->addElement($mount); $user = new Zend_Form_Element_Text('user'); $user->setLabel("Username") ->setValue(isset($setting[$prefix.'_user'])?$setting[$prefix.'_user']:"") + ->setValidators(array( + array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $user->setAttrib("disabled", "disabled"); } + $user->setAttrib('alt', 'regular_text'); $this->addElement($user); $liquidsopa_error_msg = '

Getting information from the server...

'; diff --git a/airtime_mvc/public/js/airtime/preferences/streamsetting.js b/airtime_mvc/public/js/airtime/preferences/streamsetting.js index 681bf43c0..ff5883efe 100644 --- a/airtime_mvc/public/js/airtime/preferences/streamsetting.js +++ b/airtime_mvc/public/js/airtime/preferences/streamsetting.js @@ -174,5 +174,16 @@ $(document).ready(function() { showErrorSections() setInterval('checkLiquidsoapStatus()', 1000) + $.mask.rules = { + '@': /[^ &<>]/, + 'u': /[0-9a-zA-Z-_.:/]/ + } + // add masking on the fields that don't allow special chars + + $.mask.masks = $.extend($.mask.masks,{ + regular_text:{ mask: '@', type:'repeat', 'maxLength': 256, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),:/]'}, + url:{ mask: 'u', type:'repeat', 'maxLength': 261, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),]'} + }) + $('input:text').setMask() }); From 9665c970afd9fcf51324dfa0a40adddbe1572de1 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 22 Dec 2011 15:35:46 -0500 Subject: [PATCH 3/6] CC-3218: Stream-settings: Spaces and other illegal characters should not be allowed in the fields: server, username, password, URL, and mount point - adding an another mask for domain name. Front and backend --- airtime_mvc/application/forms/StreamSettingSubForm.php | 4 ++-- airtime_mvc/public/js/airtime/preferences/streamsetting.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/forms/StreamSettingSubForm.php b/airtime_mvc/application/forms/StreamSettingSubForm.php index 2d69d9c29..bbda6576c 100644 --- a/airtime_mvc/application/forms/StreamSettingSubForm.php +++ b/airtime_mvc/application/forms/StreamSettingSubForm.php @@ -84,12 +84,12 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{ $host->setLabel("Server") ->setValue(isset($setting[$prefix.'_host'])?$setting[$prefix.'_host']:"") ->setValidators(array( - array('regex', false, array('/^[^ &<>]+$/', 'messages' => 'Invalid character entered')))) + array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => 'Invalid character entered')))) ->setDecorators(array('ViewHelper')); if($disable_all){ $host->setAttrib("disabled", "disabled"); } - $host->setAttrib('alt', 'regular_text'); + $host->setAttrib('alt', 'domain'); $this->addElement($host); $port = new Zend_Form_Element_Text('port'); diff --git a/airtime_mvc/public/js/airtime/preferences/streamsetting.js b/airtime_mvc/public/js/airtime/preferences/streamsetting.js index ff5883efe..a8195bb2d 100644 --- a/airtime_mvc/public/js/airtime/preferences/streamsetting.js +++ b/airtime_mvc/public/js/airtime/preferences/streamsetting.js @@ -176,13 +176,15 @@ $(document).ready(function() { setInterval('checkLiquidsoapStatus()', 1000) $.mask.rules = { '@': /[^ &<>]/, - 'u': /[0-9a-zA-Z-_.:/]/ + 'u': /[0-9a-zA-Z-_.:/]/, + 'd': /[0-9a-zA-Z-_.]/ } // add masking on the fields that don't allow special chars $.mask.masks = $.extend($.mask.masks,{ regular_text:{ mask: '@', type:'repeat', 'maxLength': 256, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),:/]'}, - url:{ mask: 'u', type:'repeat', 'maxLength': 261, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),]'} + url:{ mask: 'u', type:'repeat', 'maxLength': 261, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),]'}, + domain:{ mask: 'd', type:'repeat', 'maxLength': 261, selectCharsOnFocus: false, autoTab: false, fixedChars : '[(),:/]'} }) $('input:text').setMask() From a55b47efff659bc0981a2e4514b4f8a14ada9343 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 22 Dec 2011 17:21:18 -0500 Subject: [PATCH 4/6] -Allow etc and stor directories to be configurable --- .../configs/airtime-conf-production.php | 4 +++- airtime_mvc/application/configs/conf.php | 4 +++- .../controllers/plugins/RabbitMqPlugin.php | 4 +++- airtime_mvc/application/models/StoredFile.php | 15 +++++++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/configs/airtime-conf-production.php b/airtime_mvc/application/configs/airtime-conf-production.php index 31fb031e1..2d2dddb7d 100644 --- a/airtime_mvc/application/configs/airtime-conf-production.php +++ b/airtime_mvc/application/configs/airtime-conf-production.php @@ -8,7 +8,9 @@ * that the user can customize these. */ -$ini = parse_ini_file('/etc/airtime/airtime.conf', true); + +$configFile = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; +$ini = parse_ini_file($configFile, true); $dbhost = $ini['database']['host']; $dbname = $ini['database']['dbname']; diff --git a/airtime_mvc/application/configs/conf.php b/airtime_mvc/application/configs/conf.php index 27850985a..909ca4fa2 100644 --- a/airtime_mvc/application/configs/conf.php +++ b/airtime_mvc/application/configs/conf.php @@ -23,7 +23,9 @@ $CC_CONFIG = array( 'phingPath' => dirname(__FILE__).'/../../library/phing' ); -Config::loadConfig("/etc/airtime/airtime.conf"); + +$configFile = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; +Config::loadConfig($configFile); // Add database table names $CC_CONFIG['playListTable'] = $CC_CONFIG['tblNamePrefix'].'playlist'; diff --git a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php index 1c885528c..900f5a237 100644 --- a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php +++ b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php @@ -7,7 +7,9 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract if (Application_Model_RabbitMq::$doPush) { $md = array('schedule' => Application_Model_Schedule::GetScheduledPlaylists()); Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md); - Application_Model_RabbitMq::SendMessageToShowRecorder("update_schedule"); + if (!isset($_SERVER['AIRTIME_SRV'])){ + Application_Model_RabbitMq::SendMessageToShowRecorder("update_schedule"); + } } } } diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index a728e8846..d48c3c420 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -409,11 +409,13 @@ class Application_Model_StoredFile { * @return string */ public function getFilePath() - { + { $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); + $directory = $music_dir->getDirectory(); + $filepath = $this->_file->getDbFilepath(); - return $music_dir->getDirectory().$filepath; + return $directory.$filepath; } /** @@ -877,8 +879,13 @@ class Application_Model_StoredFile { $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; - $r = @copy($audio_file, $audio_stor); - $r = @unlink($audio_file); + Logging::log("copyFileToStor: moving file $audio_file to $audio_stor"); + + //Martin K.: changed to rename: Much less load + quicker since this is an atomic operation + $r = @rename($audio_file, $audio_stor); + + //$r = @copy($audio_file, $audio_stor); + //$r = @unlink($audio_file); } public static function getFileCount() From 00a05e146ba03a1875418bacf766ecb743a58b32 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 23 Dec 2011 15:32:48 -0500 Subject: [PATCH 5/6] CC-3222: Add option to disable auto starting Airtime services (after install and after system restart) -Done --- install_minimal/airtime-install | 26 ++++++++++------- install_minimal/include/airtime-initialize.sh | 20 +++++++------ .../install/media-monitor-copy-files.py | 3 +- .../install/media-monitor-initialize.py | 20 +++++++------ python_apps/monit/monit-airtime-generic.cfg | 5 ---- .../monit/monit-airtime-rabbitmq-server.cfg | 6 +--- python_apps/pypo/install/pypo-copy-files.py | 6 ++-- python_apps/pypo/install/pypo-initialize.py | 29 ++++++++++--------- .../install/recorder-copy-files.py | 7 +++-- .../install/recorder-initialize.py | 21 +++++++------- 10 files changed, 74 insertions(+), 69 deletions(-) diff --git a/install_minimal/airtime-install b/install_minimal/airtime-install index 4f2fb73b3..23ec01e2c 100755 --- a/install_minimal/airtime-install +++ b/install_minimal/airtime-install @@ -17,16 +17,17 @@ fi showhelp () { echo "Usage: airtime-install [options] ---help|-h Displays usage information. ---overwrite|-o Overwrite any existing config files. ---preserve|-p Keep any existing config files. ---no-db|-n Turn off database install. ---reinstall|-r Force a fresh install of this Airtime Version ---media-monitor|-m Install only media-monitor ---pypo|-p Install only pypo and liquidsoap ---show-recorder|-s Install only show-recorder ---web|-w Install only files for web-server ---liquidsoap-keep-alive|-l Keep Liquidsoap alive when upgrading" +--help|-h Displays usage information. +--overwrite|-o Overwrite any existing config files. +--preserve|-p Keep any existing config files. +--no-db|-n Turn off database install. +--reinstall|-r Force a fresh install of this Airtime Version +--media-monitor|-m Install only media-monitor +--pypo|-p Install only pypo and liquidsoap +--show-recorder|-s Install only show-recorder +--web|-w Install only files for web-server +--liquidsoap-keep-alive|-l Keep Liquidsoap alive when upgrading +--disable-auto-start-services|-d Disable auto-starting Airtime services" } overwrite="f" @@ -38,8 +39,9 @@ pypo="f" showrecorder="f" web="f" liquidsoap_keep_alive="f" +disable_auto_start_services="f" -set -- $(getopt -l help,overwrite,preserve,no-db,reinstall,media-monitor,pypo,show-recorder,web,liquidsoap-keep-alive "hopnrmyswl" "$@") +set -- $(getopt -l help,overwrite,preserve,no-db,reinstall,media-monitor,pypo,show-recorder,web,liquidsoap-keep-alive,disable-auto-start-services "hopnrmyswld" "$@") while [ $# -gt 0 ] do case "$1" in @@ -53,6 +55,7 @@ do (-s|--show-recorder) showrecorder="t";; (-w|--web) web="t";; (-l|--liquidsoap-keep-alive) liquidsoap_keep_alive="t";; + (-d|--disable-auto-start-services) disable_auto_start_services="t";; (--) shift; break;; (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; @@ -107,6 +110,7 @@ export nodb export overwrite export preserve export liquidsoap_keep_alive +export disable_auto_start_services set +e test "$mediamonitor" = "t" -o "$pypo" = "t" -o "$showrecorder" = "t" diff --git a/install_minimal/include/airtime-initialize.sh b/install_minimal/include/airtime-initialize.sh index 084419142..dc69073bd 100755 --- a/install_minimal/include/airtime-initialize.sh +++ b/install_minimal/include/airtime-initialize.sh @@ -53,15 +53,17 @@ sleep 1 set +e -if [ "$mediamonitor" = "t" ]; then - monit monitor airtime-media-monitor -fi -if [ "$pypo" = "t" ]; then - monit monitor airtime-playout - monit monitor airtime-liquidsoap -fi -if [ "$showrecorder" = "t" ]; then - monit monitor airtime-show-recorder +if [ "$disable_auto_start_services" = "f" ]; then + if [ "$mediamonitor" = "t" ]; then + monit monitor airtime-media-monitor + fi + if [ "$pypo" = "t" ]; then + monit monitor airtime-playout + monit monitor airtime-liquidsoap + fi + if [ "$showrecorder" = "t" ]; then + monit monitor airtime-show-recorder + fi fi monit monitor rabbitmq-server diff --git a/python_apps/media-monitor/install/media-monitor-copy-files.py b/python_apps/media-monitor/install/media-monitor-copy-files.py index 8c083aa63..ecacf6ab1 100644 --- a/python_apps/media-monitor/install/media-monitor-copy-files.py +++ b/python_apps/media-monitor/install/media-monitor-copy-files.py @@ -42,8 +42,9 @@ try: sys.exit(1) #copy monit files - shutil.copy('%s/../monit-airtime-media-monitor.cfg'%current_script_dir, '/etc/monit/conf.d/') shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-media-monitor.cfg'%current_script_dir, '/etc/monit/conf.d/') #create log dir create_dir(config['log_dir']) diff --git a/python_apps/media-monitor/install/media-monitor-initialize.py b/python_apps/media-monitor/install/media-monitor-initialize.py index 638ab06e1..992487b49 100644 --- a/python_apps/media-monitor/install/media-monitor-initialize.py +++ b/python_apps/media-monitor/install/media-monitor-initialize.py @@ -6,15 +6,17 @@ if os.geteuid() != 0: sys.exit(1) try: - #update-rc.d init script - p = Popen("update-rc.d airtime-media-monitor defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] + + if os.environ["disable_auto_start_services"] == "f": + #update-rc.d init script + p = Popen("update-rc.d airtime-media-monitor defaults >/dev/null 2>&1", shell=True) + sts = os.waitpid(p.pid, 0)[1] - #Start media-monitor daemon - print "* Waiting for media-monitor processes to start..." - p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True) - sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-media-monitor start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] + #Start media-monitor daemon + print "* Waiting for media-monitor processes to start..." + p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-media-monitor start-no-monit", shell=True) + sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e diff --git a/python_apps/monit/monit-airtime-generic.cfg b/python_apps/monit/monit-airtime-generic.cfg index 791a401e3..e4b531587 100644 --- a/python_apps/monit/monit-airtime-generic.cfg +++ b/python_apps/monit/monit-airtime-generic.cfg @@ -3,8 +3,3 @@ set httpd port 2812 allow admin:monit - - check process rabbitmq-server - with pidfile "/var/run/rabbitmq.pid" - start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; /usr/lib/airtime/utils/rabbitmq-update-pid.sh'" - stop program = "/etc/init.d/rabbitmq-server stop" diff --git a/python_apps/monit/monit-airtime-rabbitmq-server.cfg b/python_apps/monit/monit-airtime-rabbitmq-server.cfg index 74742dc58..dac2463c8 100644 --- a/python_apps/monit/monit-airtime-rabbitmq-server.cfg +++ b/python_apps/monit/monit-airtime-rabbitmq-server.cfg @@ -1,11 +1,7 @@ set daemon 10 # Poll at 5 second intervals - #set logfile syslog facility log_daemon set logfile /var/log/monit.log - set httpd port 2812 - allow admin:monit - check process rabbitmq-server with pidfile "/var/run/rabbitmq.pid" - start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; sed "s/.*,\(.*\)\}.*/\1/" /var/lib/rabbitmq/pids > /var/run/rabbitmq.pid'" + start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; /usr/lib/airtime/utils/rabbitmq-update-pid.sh'" stop program = "/etc/init.d/rabbitmq-server stop" diff --git a/python_apps/pypo/install/pypo-copy-files.py b/python_apps/pypo/install/pypo-copy-files.py index d0baac86a..90d4705fb 100644 --- a/python_apps/pypo/install/pypo-copy-files.py +++ b/python_apps/pypo/install/pypo-copy-files.py @@ -42,9 +42,11 @@ try: sys.exit(1) #copy monit files - shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/') - shutil.copy('%s/../monit-airtime-liquidsoap.cfg'%current_script_dir, '/etc/monit/conf.d/') shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../../monit/monit-airtime-rabbitmq-server.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-liquidsoap.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/') #create pypo log dir create_dir(config['pypo_log_dir']) diff --git a/python_apps/pypo/install/pypo-initialize.py b/python_apps/pypo/install/pypo-initialize.py index 57b2a6ae8..9df8245aa 100644 --- a/python_apps/pypo/install/pypo-initialize.py +++ b/python_apps/pypo/install/pypo-initialize.py @@ -87,10 +87,6 @@ try: print "Unsupported system architecture." sys.exit(1) - #initialize init.d scripts - p = Popen("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] - #generate liquidsoap config file #access the DB and generate liquidsoap.cfg under /etc/airtime/ ac = api_client.api_client_factory(config) @@ -101,18 +97,23 @@ try: else: print "Unable to connect to the Airtime server." - #restart airtime-playout - print "* Waiting for pypo processes to start..." - if os.environ["liquidsoap_keep_alive"] == "f": - print " * Restarting any previous Liquidsoap instances" - p = Popen("/etc/init.d/airtime-playout stop", shell=True) + if os.environ["disable_auto_start_services"] == "f": + #initialize init.d scripts + p = Popen("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True) sts = os.waitpid(p.pid, 0)[1] - else: - print " * Keeping any previous Liquidsoap instances running" - p = Popen("/etc/init.d/airtime-playout pypo-stop", shell=True) + + #restart airtime-playout + print "* Waiting for pypo processes to start..." + if os.environ["liquidsoap_keep_alive"] == "f": + print " * Restarting any previous Liquidsoap instances" + p = Popen("/etc/init.d/airtime-playout stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + else: + print " * Keeping any previous Liquidsoap instances running" + p = Popen("/etc/init.d/airtime-playout pypo-stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-playout start-no-monit", shell=True) sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-playout start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e diff --git a/python_apps/show-recorder/install/recorder-copy-files.py b/python_apps/show-recorder/install/recorder-copy-files.py index d78a22f6f..44ae93cc9 100644 --- a/python_apps/show-recorder/install/recorder-copy-files.py +++ b/python_apps/show-recorder/install/recorder-copy-files.py @@ -41,10 +41,11 @@ try: print 'Error loading config file: ', e sys.exit(1) - + #copy monit files - shutil.copy('%s/../monit-airtime-show-recorder.cfg'%current_script_dir, '/etc/monit/conf.d/') - shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-show-recorder.cfg'%current_script_dir, '/etc/monit/conf.d/') #create temporary media-storage directory #print "Creating temporary media storage directory" diff --git a/python_apps/show-recorder/install/recorder-initialize.py b/python_apps/show-recorder/install/recorder-initialize.py index caefa436a..9bcf38453 100644 --- a/python_apps/show-recorder/install/recorder-initialize.py +++ b/python_apps/show-recorder/install/recorder-initialize.py @@ -7,15 +7,16 @@ if os.geteuid() != 0: sys.exit(1) try: - #register init.d script - p = Popen("update-rc.d airtime-show-recorder defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] - - #start daemon - print "* Waiting for show-recorder processes to start..." - p = Popen("/etc/init.d/airtime-show-recorder stop", shell=True) - sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-show-recorder start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] + if os.environ["disable_auto_start_services"] == "f": + #register init.d script + p = Popen("update-rc.d airtime-show-recorder defaults >/dev/null 2>&1", shell=True) + sts = os.waitpid(p.pid, 0)[1] + + #start daemon + print "* Waiting for show-recorder processes to start..." + p = Popen("/etc/init.d/airtime-show-recorder stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-show-recorder start-no-monit", shell=True) + sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e From c9c6a08a1c9e56985e8e03e07a4ff47bb358ca61 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 24 Dec 2011 10:59:09 -0500 Subject: [PATCH 6/6] CC-3220: Stream Setting: Status box is stuck on waiting if nothing is changed and click save - done - liquidsoap_update_error and liquidsoap_update_connection functions are combined into one function, liquidsoap_update_status, in various place - created various telnet commands in liquidsoap( connection check for each stream, connection status for all streams) - In liquidsoap, shoutcast stream doesn't use default id. It is more informative by using id with "shoutcast_stream_#{stream_number} --- .../application/controllers/ApiController.php | 17 ++------- .../upgrades/airtime-2.0.0/api_client.cfg.200 | 7 +--- python_apps/api_clients/api_client.cfg | 7 +--- python_apps/api_clients/api_client.py | 24 +++--------- .../pypo/liquidsoap_scripts/ls_lib.liq | 15 +++++--- .../pypo/liquidsoap_scripts/ls_script.liq | 38 +++++++++++++++---- python_apps/pypo/pypo-notify.py | 22 +++-------- python_apps/pypo/pypofetch.py | 35 +++++++++++++++++ 8 files changed, 94 insertions(+), 71 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 2abdc31cc..332a42ce0 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -23,8 +23,7 @@ class ApiController extends Zend_Controller_Action ->addActionContext('get-stream-setting', 'json') ->addActionContext('status', 'json') ->addActionContext('register-component', 'json') - ->addActionContext('update-liquidsoap-error', 'json') - ->addActionContext('update-liquidsoap-connection', 'json') + ->addActionContext('update-liquidsoap-status', 'json') ->addActionContext('library-init', 'json') ->addActionContext('live-chat', 'json') ->initContext(); @@ -780,22 +779,14 @@ class ApiController extends Zend_Controller_Action Application_Model_ServiceRegister::Register($component, $remoteAddr); } - public function updateLiquidsoapErrorAction(){ + public function updateLiquidsoapStatusAction(){ $request = $this->getRequest(); - $error_msg = $request->getParam('error_msg'); + $msg = $request->getParam('msg'); $stream_id = $request->getParam('stream_id'); $boot_time = $request->getParam('boot_time'); - Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg, $boot_time); - } - - public function updateLiquidsoapConnectionAction(){ - $request = $this->getRequest(); - $stream_id = $request->getParam('stream_id'); - $boot_time = $request->getParam('boot_time'); - // setting error_msg as "" when there is no error_msg - Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK", $boot_time); + Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time); } /** diff --git a/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 b/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 index f9da7739a..2d51bb2d2 100644 --- a/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 +++ b/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 @@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php' # URL to tell Airtime we want to get stream setting get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/' -#URL to update liquidsoap error msg -update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' - -#URL to update liquidsoap connection -update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' +#URL to update liquidsoap status +update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' ############## # OBP config # diff --git a/python_apps/api_clients/api_client.cfg b/python_apps/api_clients/api_client.cfg index f9da7739a..2d51bb2d2 100644 --- a/python_apps/api_clients/api_client.cfg +++ b/python_apps/api_clients/api_client.cfg @@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php' # URL to tell Airtime we want to get stream setting get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/' -#URL to update liquidsoap error msg -update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' - -#URL to update liquidsoap connection -update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' +#URL to update liquidsoap status +update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' ############## # OBP config # diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 22b13fdcb..7459d63e8 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -571,29 +571,15 @@ class AirTimeApiClient(ApiClientInterface): except Exception, e: logger.error("Exception: %s", e) - def notify_liquidsoap_error(self, error_msg, stream_id, time): + def notify_liquidsoap_status(self, msg, stream_id, time): logger = logging.getLogger() try: - url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_error"]) - - url = url.replace("%%api_key%%", self.config["api_key"]) - error_msg = error_msg.replace('/', ' ') - encoded_msg = urllib.quote(error_msg, '') - url = url.replace("%%error_msg%%", encoded_msg) - url = url.replace("%%stream_id%%", stream_id) - url = url.replace("%%boot_time%%", time) - logger.debug(url) - req = urllib2.Request(url) - response = urllib2.urlopen(req).read() - except Exception, e: - logger.error("Exception: %s", e) - - def notify_liquidsoap_connection(self, stream_id, time): - logger = logging.getLogger() - try: - url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_connection"]) + url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_status"]) url = url.replace("%%api_key%%", self.config["api_key"]) + msg = msg.replace('/', ' ') + encoded_msg = urllib.quote(msg, '') + url = url.replace("%%msg%%", encoded_msg) url = url.replace("%%stream_id%%", stream_id) url = url.replace("%%boot_time%%", time) logger.debug(url) diff --git a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq index f6e966989..b1a98f3c6 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq @@ -37,15 +37,17 @@ def to_live(old,new) = end -def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream) = +def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream, connected) = def on_error(msg) - system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}") - log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}") + connected := "false" + system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{!time}") + log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{!time}") 5. end def on_connect() - system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}") - log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}") + connected := "true" + system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{!time}") + log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{!time}") end if output_type == "icecast" then user_ref = ref user @@ -136,7 +138,8 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de if url == "" then url_ref := "N/A" end - output.shoutcast = output.shoutcast(host = host, + output.shoutcast = output.shoutcast(id = "shoutcast_stream_#{stream}", + host = host, port = port, password = pass, fallible = true, diff --git a/python_apps/pypo/liquidsoap_scripts/ls_script.liq b/python_apps/pypo/liquidsoap_scripts/ls_script.liq index 4e72261bb..42bc1e479 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_script.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_script.liq @@ -6,7 +6,7 @@ set("log.stdout", true) set("server.telnet", true) set("server.telnet.port", 1234) -time = gettimeofday() +time = ref string_of(gettimeofday()) queue = audio_to_stereo(request.queue(id="queue", length=0.5)) queue = cue_cut(queue) @@ -17,6 +17,13 @@ stream_metadata_type = ref 0 station_name = ref '' show_name = ref '' +s1_connected = ref '' +s2_connected = ref '' +s3_connected = ref '' +s1_namespace = ref '' +s2_namespace = ref '' +s3_namespace = ref '' + %include "ls_lib.liq" server.register(namespace="vars", "pypo_data", fun (s) -> begin pypo_data := s "Done" end) @@ -24,6 +31,8 @@ server.register(namespace="vars", "web_stream_enabled", fun (s) -> begin web_str server.register(namespace="vars", "stream_metadata_type", fun (s) -> begin stream_metadata_type := int_of_string(s) s end) server.register(namespace="vars", "show_name", fun (s) -> begin show_name := s s end) server.register(namespace="vars", "station_name", fun (s) -> begin station_name := s s end) +server.register(namespace="vars", "bootup_time", fun (s) -> begin time := s s end) +server.register(namespace="streams", "connection_status", fun (s) -> begin "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}" end) default = amplify(0.00001, noise()) @@ -100,19 +109,34 @@ if output_sound_device then end if s1_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1") + if s1_output == 'shoutcast' then + s1_namespace := "shoutcast_stream_1" + else + s1_namespace := s1_mount + end + server.register(namespace=!s1_namespace, "connected", fun (s) -> begin !s1_connected end) + output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1", s1_connected) end if s2_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2") + if s2_output == 'shoutcast' then + s2_namespace := "shoutcast_stream_2" + else + s2_namespace := s2_mount + end + server.register(namespace=!s2_namespace, "connected", fun (s) -> begin !s2_connected end) + output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2", s2_connected) end if s3_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s, "3") + if s3_output == 'shoutcast' then + s3_namespace := "shoutcast_stream_3" + else + s3_namespace := s3_mount + end + server.register(namespace=!s3_namespace, "connected", fun (s) -> begin !s3_connected end) + output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s, "3", s3_connected) end ignore(output.dummy(blank())) diff --git a/python_apps/pypo/pypo-notify.py b/python_apps/pypo/pypo-notify.py index a6cf103dc..42fb523fc 100644 --- a/python_apps/pypo/pypo-notify.py +++ b/python_apps/pypo/pypo-notify.py @@ -82,24 +82,14 @@ class Notify: logger.debug("Response: "+json.dumps(response)) # @pram time: time that LS started - def notify_liquidsoap_error(self, error_msg, stream_id, time): + def notify_liquidsoap_status(self, msg, stream_id, time): logger = logging.getLogger() logger.debug('#################################################') - logger.debug('# Calling server to update liquidsoap error #') + logger.debug('# Calling server to update liquidsoap status #') logger.debug('#################################################') - logger.debug('error msg = '+ str(error_msg)) - response = self.api_client.notify_liquidsoap_error(error_msg, stream_id, time) - logger.debug("Response: "+json.dumps(response)) - - # @pram time: time that LS started - def notify_liquidsoap_connection(self, stream_id, time): - logger = logging.getLogger() - - logger.debug('#################################################') - logger.debug('# Calling server to update liquidsoap connection#') - logger.debug('#################################################') - response = self.api_client.notify_liquidsoap_connection(stream_id, time) + logger.debug('msg = '+ str(msg)) + response = self.api_client.notify_liquidsoap_status(msg, stream_id, time) logger.debug("Response: "+json.dumps(response)) if __name__ == '__main__': @@ -115,13 +105,13 @@ if __name__ == '__main__': if options.error and options.stream_id: try: n = Notify() - n.notify_liquidsoap_error(options.error, options.stream_id, options.time) + n.notify_liquidsoap_status(options.error, options.stream_id, options.time) except Exception, e: print e elif options.connect and options.stream_id: try: n = Notify() - n.notify_liquidsoap_connection(options.stream_id, options.time) + n.notify_liquidsoap_status("OK", options.stream_id, options.time) except Exception, e: print e else: diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 06d2271bc..7c020586e 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -216,6 +216,41 @@ class PypoFetch(Thread): self.process_schedule(self.schedule_data, "scheduler", False) else: logger.info("No change detected in setting...") + self.update_liquidsoap_connection_status() + """ + updates the status of liquidsoap connection to the streaming server + This fucntion updates the bootup time variable in liquidsoap script + """ + def update_liquidsoap_connection_status(self): + logger = logging.getLogger('fetch') + tn = telnetlib.Telnet(LS_HOST, LS_PORT) + # update the boot up time of liquidsoap. Since liquidsoap is not restarting, + # we are manually adjusting the bootup time variable so the status msg will get + # updated. + current_time = time.time() + boot_up_time_command = "vars.bootup_time "+str(current_time)+"\n" + tn.write(boot_up_time_command) + tn.write("streams.connection_status\n") + tn.write('exit\n') + + output = tn.read_all() + output_list = output.split("\r\n") + stream_info = output_list[2] + + # streamin info is in the form of: + # eg. s1:true,2:true,3:false + streams = stream_info.split(",") + logger.info(streams) + + fake_time = current_time + 1 + for s in streams: + info = s.split(':') + stream_id = info[0] + status = info[1] + if(status == "true"): + self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time)) + + def set_export_source(self, export_source): logger = logging.getLogger('fetch')