Merge branch '2.3.x' into 2.3.x-saas

Conflicts:
	airtime_mvc/application/models/User.php
This commit is contained in:
Martin Konecny 2013-01-30 18:31:45 -05:00
commit 0a198ae424
20 changed files with 184 additions and 51 deletions

View File

@ -385,6 +385,15 @@ class LibraryController extends Zend_Controller_Action
//TODO move this to the datatables row callback. //TODO move this to the datatables row callback.
foreach ($r["aaData"] as &$data) { foreach ($r["aaData"] as &$data) {
foreach ($data as $k => &$v) {
if ($k != "image" && $k != "checkbox") {
$v = htmlspecialchars($v);
}
}
//TODO: Replace the above foreach loop with the line below when ticket
//CC-4896 is completed.
//$data = array_map('htmlspecialchars', $data);
if ($data['ftype'] == 'audioclip') { if ($data['ftype'] == 'audioclip') {
$file = Application_Model_StoredFile::Recall($data['id']); $file = Application_Model_StoredFile::Recall($data['id']);
$scid = $file->getSoundCloudId(); $scid = $file->getSoundCloudId();
@ -429,7 +438,7 @@ class LibraryController extends Zend_Controller_Action
$formValues = $this->_getParam('data', null); $formValues = $this->_getParam('data', null);
$formdata = array(); $formdata = array();
foreach ($formValues as $val) { foreach ($formValues as $val) {
$formdata[$val["name"]] = $val["value"]; $formdata[$val["name"]] = htmlspecialchars($val["value"]);
} }
$file->setDbColMetadata($formdata); $file->setDbColMetadata($formdata);

View File

@ -238,7 +238,8 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetEnableReplayGain($values["enableReplayGain"]); Application_Model_Preference::SetEnableReplayGain($values["enableReplayGain"]);
Application_Model_Preference::setReplayGainModifier($values["replayGainModifier"]); Application_Model_Preference::setReplayGainModifier($values["replayGainModifier"]);
$md = array('schedule' => Application_Model_Schedule::getSchedule()); $md = array('schedule' => Application_Model_Schedule::getSchedule());
Application_Model_RabbitMq::PushSchedule(); Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md);
//Application_Model_RabbitMq::PushSchedule();
} }
Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']); Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']);

View File

@ -115,7 +115,7 @@ class UserController extends Zend_Controller_Action
$post = $this->getRequest()->getPost(); $post = $this->getRequest()->getPost();
$users = Application_Model_User::getUsersDataTablesInfo($post); $users = Application_Model_User::getUsersDataTablesInfo($post);
die(json_encode($users)); $this->_helper->json->sendJson($users);
} }
public function getUserDataAction() public function getUserDataAction()

View File

@ -24,7 +24,7 @@
<div class="personal-block solo"> <div class="personal-block solo">
<ul> <ul>
<li> <li>
<a id="current-user" href=<?php echo $baseUrl . "User/edit-user"?>><span class="name"><?php echo $this->loggedInAs()?></span></a> | <a href=<?php echo $baseUrl . "Login/logout"?>><?php echo _("Logout")?></a> <a id="current-user" href=<?php echo $baseUrl . "User/edit-user"?>><span class="name"><?php echo $this->escape($this->loggedInAs()); ?></span></a> | <a href=<?php echo $baseUrl . "Login/logout"?>><?php echo _("Logout")?></a>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -32,6 +32,8 @@ class Logging {
{ {
if (is_array($p_msg) || is_object($p_msg)) { if (is_array($p_msg) || is_object($p_msg)) {
return print_r($p_msg, true); return print_r($p_msg, true);
} else if (is_bool($p_msg)) {
return $p_msg ? "true" : "false";
} else { } else {
return $p_msg; return $p_msg;
} }

View File

@ -696,6 +696,10 @@ SQL;
'replay_gain' => $replay_gain, 'replay_gain' => $replay_gain,
'independent_event' => $independent_event, 'independent_event' => $independent_event,
); );
if ($schedule_item['cue_in'] > $schedule_item['cue_out']) {
$schedule_item['cue_in'] = $schedule_item['cue_out'];
}
self::appendScheduleItem($data, $start, $schedule_item); self::appendScheduleItem($data, $start, $schedule_item);
} }
@ -906,7 +910,6 @@ SQL;
self::createScheduledEvents($data, $range_start, $range_end); self::createScheduledEvents($data, $range_start, $range_end);
self::foldData($data["media"]); self::foldData($data["media"]);
return $data; return $data;
} }

View File

@ -136,13 +136,17 @@ class Application_Model_Scheduler
if ($type === "audioclip") { if ($type === "audioclip") {
$file = CcFilesQuery::create()->findPK($id, $this->con); $file = CcFilesQuery::create()->findPK($id, $this->con);
$storedFile = new Application_Model_StoredFile($file->getDbId());
if (is_null($file) || !$file->visible()) { if (is_null($file) || !$file->visible()) {
throw new Exception(_("A selected File does not exist!")); throw new Exception(_("A selected File does not exist!"));
} else { } else {
$data = $this->fileInfo; $data = $this->fileInfo;
$data["id"] = $id; $data["id"] = $id;
$data["cliplength"] = $file->getDbLength(); $data["cliplength"] = $storedFile->getRealClipLength(
$file->getDbCuein(),
$file->getDbCueout());
$data["cuein"] = $file->getDbCuein(); $data["cuein"] = $file->getDbCuein();
$data["cueout"] = $file->getDbCueout(); $data["cueout"] = $file->getDbCueout();
@ -438,7 +442,6 @@ class Application_Model_Scheduler
} }
foreach ($schedFiles as $file) { foreach ($schedFiles as $file) {
$endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']); $endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']);
//item existed previously and is being moved. //item existed previously and is being moved.

View File

@ -227,7 +227,7 @@ class Application_Model_ShowBuilder
$row["endDate"] = $showEndDT->format("Y-m-d"); $row["endDate"] = $showEndDT->format("Y-m-d");
$row["endTime"] = $showEndDT->format("H:i"); $row["endTime"] = $showEndDT->format("H:i");
$row["duration"] = floatval($showEndDT->format("U.u")) - floatval($showStartDT->format("U.u")); $row["duration"] = floatval($showEndDT->format("U.u")) - floatval($showStartDT->format("U.u"));
$row["title"] = $p_item["show_name"]; $row["title"] = htmlspecialchars($p_item["show_name"]);
$row["instance"] = intval($p_item["si_id"]); $row["instance"] = intval($p_item["si_id"]);
$row["image"] = ''; $row["image"] = '';

View File

@ -1285,6 +1285,14 @@ SQL;
} }
} }
} }
public function getRealClipLength($p_cuein, $p_cueout) {
$sql = "SELECT :cueout::INTERVAL - :cuein::INTERVAL";
return Application_Common_Database::prepareAndExecute($sql, array(
':cueout' => $p_cueout,
':cuein' => $p_cuein), 'column');
}
} }
class DeleteScheduledFileException extends Exception {} class DeleteScheduledFileException extends Exception {}

View File

@ -343,6 +343,8 @@ class Application_Model_User
$res['iTotalDisplayRecords']--; $res['iTotalDisplayRecords']--;
$res['iTotalRecords']--; $res['iTotalRecords']--;
} }
$record = array_map('htmlspecialchars', $record);
} }
$res['aaData'] = array_values($res['aaData']); $res['aaData'] = array_values($res['aaData']);

View File

@ -1,4 +1,4 @@
<h2><? echo sprintf(_("%s's Settings"), $this->currentUser) ?></h2> <h2><? echo sprintf(_("%s's Settings"), $this->escape($this->currentUser)) ?></h2>
<div id="current-user-container"> <div id="current-user-container">
<form id="current-user-form" class="edit-user-global" method="post" enctype="application/x-www-form-urlencoded"> <form id="current-user-form" class="edit-user-global" method="post" enctype="application/x-www-form-urlencoded">
<dl class="zend_form"> <dl class="zend_form">
@ -160,4 +160,4 @@
<button type="submit" id="cu_save_user" class="btn btn-small right-floated"><?php echo _("Save")?></button> <button type="submit" id="cu_save_user" class="btn btn-small right-floated"><?php echo _("Save")?></button>
</dl> </dl>
</form> </form>
</div> </div>

View File

@ -11,7 +11,7 @@
<?php if($this->element->getElement('storageFolder')->hasErrors()) : ?> <?php if($this->element->getElement('storageFolder')->hasErrors()) : ?>
<ul class='errors'> <ul class='errors'>
<?php foreach($this->element->getElement('storageFolder')->getMessages() as $error): ?> <?php foreach($this->element->getElement('storageFolder')->getMessages() as $error): ?>
<li><?php echo $error; ?></li> <li><?php echo $this->escape($error); ?></li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<?php endif; ?> <?php endif; ?>
@ -29,7 +29,7 @@
<?php if($this->element->getElement('watchedFolder')->hasErrors()) : ?> <?php if($this->element->getElement('watchedFolder')->hasErrors()) : ?>
<ul class='errors'> <ul class='errors'>
<?php foreach($this->element->getElement('watchedFolder')->getMessages() as $error): ?> <?php foreach($this->element->getElement('watchedFolder')->getMessages() as $error): ?>
<li><?php echo $error; ?></li> <li><?php echo $this->escape($error); ?></li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<?php endif; ?> <?php endif; ?>

View File

@ -39,7 +39,7 @@ if (isset($this->obj)) {
<input id='obj_type' type='hidden' value='playlist'></input> <input id='obj_type' type='hidden' value='playlist'></input>
<div class="playlist_title"> <div class="playlist_title">
<h3 id="obj_name"> <h3 id="obj_name">
<a id="playlist_name_display" contenteditable="true"><?php echo $this->obj->getName(); ?></a> <a id="playlist_name_display" contenteditable="true"><?php echo $this->escape($this->obj->getName()); ?></a>
</h3> </h3>
<h4 id="obj_length"><?php echo $this->length; ?></h4> <h4 id="obj_length"><?php echo $this->length; ?></h4>
</div> </div>

View File

@ -28,7 +28,7 @@ function rebuildStreamURL(ele){
}else{ }else{
streamurl = "http://"+host+":"+port+"/" streamurl = "http://"+host+":"+port+"/"
} }
div.find("#stream_url").html(streamurl) div.find("#stream_url").text(streamurl)
} }
function restrictOggBitrate(ele, on){ function restrictOggBitrate(ele, on){
var div = ele.closest("div") var div = ele.closest("div")

View File

@ -15,6 +15,8 @@ INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_admin_pas
UPDATE cc_music_dirs SET directory = directory || '/' where id in (select id from cc_music_dirs where substr(directory, length(directory)) != '/'); UPDATE cc_music_dirs SET directory = directory || '/' where id in (select id from cc_music_dirs where substr(directory, length(directory)) != '/');
UPDATE cc_files SET filepath = substring(filepath from 2) where id in (select id from cc_files where substring(filepath from 1 for 1) = '/'); UPDATE cc_files SET filepath = substring(filepath from 2) where id in (select id from cc_files where substring(filepath from 1 for 1) = '/');
UPDATE cc_files SET cueout = length where cueout = '00:00:00';
INSERT INTO cc_pref("keystr", "valstr") VALUES('locale', 'en_CA'); INSERT INTO cc_pref("keystr", "valstr") VALUES('locale', 'en_CA');
INSERT INTO cc_pref("subjid", "keystr", "valstr") VALUES(1, 'user_locale', 'en_CA'); INSERT INTO cc_pref("subjid", "keystr", "valstr") VALUES(1, 'user_locale', 'en_CA');

View File

@ -73,17 +73,26 @@ class ApcUrl(object):
else: return self.base_url else: return self.base_url
class ApiRequest(object): class ApiRequest(object):
def __init__(self, name, url): def __init__(self, name, url, logger=None):
self.name = name self.name = name
self.url = url self.url = url
self.__req = None self.__req = None
if logger is None: self.logger = logging
else: self.logger = logger
def __call__(self,_post_data=None, **kwargs): def __call__(self,_post_data=None, **kwargs):
# TODO : get rid of god damn urllib and replace everything with # TODO : get rid of god damn urllib and replace everything with
# grequests or requests at least # grequests or requests at least
final_url = self.url.params(**kwargs).url() final_url = self.url.params(**kwargs).url()
if _post_data is not None: _post_data = urllib.urlencode(_post_data) if _post_data is not None: _post_data = urllib.urlencode(_post_data)
req = urllib2.Request(final_url, _post_data) try:
response = urllib2.urlopen(req).read() req = urllib2.Request(final_url, _post_data)
response = urllib2.urlopen(req).read()
except Exception, e:
self.logger.error('Exception: %s', e)
import traceback
top = traceback.format_exc()
self.logger.error("traceback: %s", top)
response = ""
# Ghetto hack for now because we don't the content type we are getting # Ghetto hack for now because we don't the content type we are getting
# (Pointless to look at mime since it's not being set correctly always) # (Pointless to look at mime since it's not being set correctly always)
try: return json.loads(response) try: return json.loads(response)

View File

@ -28,10 +28,10 @@ start () {
stop () { stop () {
monit unmonitor airtime-liquidsoap >/dev/null 2>&1 monit unmonitor airtime-liquidsoap >/dev/null 2>&1
/usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py #send term signal after 10 seconds
timeout 10 /usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
# Send TERM after 5 seconds, wait at most 30 seconds. # Send TERM after 5 seconds, wait at most 30 seconds.
start-stop-daemon --stop --oknodo --retry 5 --quiet --pidfile $PIDFILE start-stop-daemon --stop --oknodo --retry=TERM/10/KILL/5 --quiet --pidfile $PIDFILE
rm -f $PIDFILE rm -f $PIDFILE
} }

View File

@ -6,14 +6,14 @@ try:
config = ConfigObj('/etc/airtime/pypo.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
LS_HOST = config['ls_host'] LS_HOST = config['ls_host']
LS_PORT = config['ls_port'] LS_PORT = config['ls_port']
tn = telnetlib.Telnet(LS_HOST, LS_PORT) tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write("master_harbor.stop\n") tn.write("master_harbor.stop\n")
tn.write("live_dj_harbor.stop\n") tn.write("live_dj_harbor.stop\n")
tn.write('exit\n') tn.write('exit\n')
tn.read_all() tn.read_all()
except Exception, e: except Exception, e:
print('Error loading config file: %s', e) print('Error loading config file: %s', e)
sys.exit() sys.exit()

View File

@ -195,28 +195,81 @@ def check_dj_client(user,password) =
hd == "True" hd == "True"
end end
def append_dj_inputs(master_harbor_input_port, master_harbor_input_mount_point, dj_harbor_input_port, dj_harbor_input_mount_point, s) = def append_dj_inputs(master_harbor_input_port,
if master_harbor_input_port != 0 and master_harbor_input_mount_point != "" and dj_harbor_input_port != 0 and dj_harbor_input_mount_point != "" then master_harbor_input_mount_point,
master_dj = mksafe(audio_to_stereo(input.harbor(id="master_harbor", master_harbor_input_mount_point, port=master_harbor_input_port, auth=check_master_dj_client, dj_harbor_input_port,
max=40., on_connect=master_dj_connect, on_disconnect=master_dj_disconnect))) dj_harbor_input_mount_point,
dj_live = mksafe(audio_to_stereo(input.harbor(id="live_dj_harbor", dj_harbor_input_mount_point, port=dj_harbor_input_port, auth=check_dj_client, s) =
max=40., on_connect=live_dj_connect, on_disconnect=live_dj_disconnect))) if master_harbor_input_port != 0
and master_harbor_input_mount_point != ""
and dj_harbor_input_port != 0
and dj_harbor_input_mount_point != "" then
master_dj = mksafe(
audio_to_stereo(
input.harbor(id="master_harbor",
master_harbor_input_mount_point,
port=master_harbor_input_port,
auth=check_master_dj_client,
max=40.,
on_connect=master_dj_connect,
on_disconnect=master_dj_disconnect)))
dj_live = mksafe(
audio_to_stereo(
input.harbor(id="live_dj_harbor",
dj_harbor_input_mount_point,
port=dj_harbor_input_port,
auth=check_dj_client,
max=40.,
on_connect=live_dj_connect,
on_disconnect=live_dj_disconnect)))
ignore(output.dummy(master_dj, fallible=true)) ignore(output.dummy(master_dj, fallible=true))
ignore(output.dummy(dj_live, fallible=true)) ignore(output.dummy(dj_live, fallible=true))
switch(id="master_dj_switch", track_sensitive=false, transitions=[transition, transition, transition], [({!master_dj_enabled},master_dj), ({!live_dj_enabled},dj_live), ({true}, s)])
switch(id="master_dj_switch",
track_sensitive=false,
transitions=[transition, transition, transition],
[({!master_dj_enabled},master_dj),
({!live_dj_enabled},dj_live),
({true}, s)])
elsif master_harbor_input_port != 0 and master_harbor_input_mount_point != "" then elsif master_harbor_input_port != 0 and master_harbor_input_mount_point != "" then
master_dj = mksafe(audio_to_stereo(input.harbor(id="master_harbor", master_harbor_input_mount_point, port=master_harbor_input_port, auth=check_master_dj_client, master_dj = mksafe(
max=40., on_connect=master_dj_connect, on_disconnect=master_dj_disconnect))) audio_to_stereo(
input.harbor(id="master_harbor",
master_harbor_input_mount_point,
port=master_harbor_input_port,
auth=check_master_dj_client,
max=40.,
on_connect=master_dj_connect,
on_disconnect=master_dj_disconnect)))
ignore(output.dummy(master_dj, fallible=true)) ignore(output.dummy(master_dj, fallible=true))
switch(id="master_dj_switch", track_sensitive=false, transitions=[transition, transition], [({!master_dj_enabled},master_dj), ({true}, s)]) switch(id="master_dj_switch",
track_sensitive=false,
transitions=[transition, transition],
[({!master_dj_enabled},master_dj), ({true}, s)])
elsif dj_harbor_input_port != 0 and dj_harbor_input_mount_point != "" then elsif dj_harbor_input_port != 0 and dj_harbor_input_mount_point != "" then
dj_live = mksafe(audio_to_stereo(input.harbor(id="live_dj_harbor", dj_harbor_input_mount_point, port=dj_harbor_input_port, auth=check_dj_client, dj_live = mksafe(
max=40., on_connect=live_dj_connect, on_disconnect=live_dj_disconnect))) audio_to_stereo(
input.harbor(id="live_dj_harbor",
dj_harbor_input_mount_point,
port=dj_harbor_input_port,
auth=check_dj_client,
max=40.,
on_connect=live_dj_connect,
on_disconnect=live_dj_disconnect)))
ignore(output.dummy(dj_live, fallible=true)) ignore(output.dummy(dj_live, fallible=true))
switch(id="live_dj_switch", track_sensitive=false, transitions=[transition, transition], [({!live_dj_enabled},dj_live), ({true}, s)])
switch(id="live_dj_switch",
track_sensitive=false,
transitions=[transition, transition],
[({!live_dj_enabled},dj_live), ({true}, s)])
else else
s s
end end

View File

@ -135,6 +135,7 @@ class PypoFetch(Thread):
try: try:
lock.acquire() lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT) tn = telnetlib.Telnet(LS_HOST, LS_PORT)
self.logger.info(command)
tn.write(command) tn.write(command)
tn.write('exit\n') tn.write('exit\n')
tn.read_all() tn.read_all()
@ -143,6 +144,24 @@ class PypoFetch(Thread):
finally: finally:
lock.release() lock.release()
@staticmethod
def telnet_send(logger, lock, commands):
try:
lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
for i in commands:
logger.info(i)
tn.write(i)
tn.write('exit\n')
tn.read_all()
except Exception, e:
logger.error(str(e))
finally:
lock.release()
@staticmethod @staticmethod
def switch_source(logger, lock, sourcename, status): def switch_source(logger, lock, sourcename, status):
logger.debug('Switching source: %s to "%s" status', sourcename, status) logger.debug('Switching source: %s to "%s" status', sourcename, status)
@ -159,17 +178,26 @@ class PypoFetch(Thread):
else: else:
command += "stop\n" command += "stop\n"
try: PypoFetch.telnet_send(logger, lock, [command])
lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write(command) #TODO: Merge this with switch_source
tn.write('exit\n') def switch_source_temp(self, sourcename, status):
tn.read_all() self.logger.debug('Switching source: %s to "%s" status', sourcename, status)
except Exception, e: command = "streams."
logger.error(str(e)) if sourcename == "master_dj":
finally: command += "master_dj_"
lock.release() elif sourcename == "live_dj":
command += "live_dj_"
elif sourcename == "scheduled_play":
command += "scheduled_play_"
if status == "on":
command += "start\n"
else:
command += "stop\n"
return command
""" """
grabs some information that are needed to be set on bootstrap time grabs some information that are needed to be set on bootstrap time
@ -182,11 +210,18 @@ class PypoFetch(Thread):
self.logger.error('Unable to get bootstrap info.. Exiting pypo...') self.logger.error('Unable to get bootstrap info.. Exiting pypo...')
else: else:
self.logger.debug('info:%s', info) self.logger.debug('info:%s', info)
commands = []
for k, v in info['switch_status'].iteritems(): for k, v in info['switch_status'].iteritems():
self.switch_source(self.logger, self.telnet_lock, k, v) commands.append(self.switch_source_temp(k, v))
self.update_liquidsoap_stream_format(info['stream_label'])
self.update_liquidsoap_station_name(info['station_name']) stream_format = info['stream_label']
self.update_liquidsoap_transition_fade(info['transition_fade']) station_name = info['station_name']
fade = info['transition_fade']
commands.append(('vars.stream_metadata_type %s\n' % stream_format).encode('utf-8'))
commands.append(('vars.station_name %s\n' % station_name).encode('utf-8'))
commands.append(('vars.default_dj_fade %s\n' % fade).encode('utf-8'))
PypoFetch.telnet_send(self.logger, self.telnet_lock, commands)
def restart_liquidsoap(self): def restart_liquidsoap(self):
@ -330,8 +365,13 @@ class PypoFetch(Thread):
# updated. # updated.
current_time = time.time() current_time = time.time()
boot_up_time_command = "vars.bootup_time " + str(current_time) + "\n" boot_up_time_command = "vars.bootup_time " + str(current_time) + "\n"
self.logger.info(boot_up_time_command)
tn.write(boot_up_time_command) tn.write(boot_up_time_command)
tn.write("streams.connection_status\n")
connection_status = "streams.connection_status\n"
self.logger.info(connection_status)
tn.write(connection_status)
tn.write('exit\n') tn.write('exit\n')
output = tn.read_all() output = tn.read_all()
@ -356,6 +396,7 @@ class PypoFetch(Thread):
if(status == "true"): if(status == "true"):
self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time)) self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time))
def update_liquidsoap_stream_format(self, stream_format): def update_liquidsoap_stream_format(self, stream_format):
# Push stream metadata to liquidsoap # Push stream metadata to liquidsoap
# TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!! # TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!!