diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index cefff769e..7d1ea2a6d 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -61,7 +61,13 @@ class Application_Model_Preference ." VALUES ($id, '$key', $value)"; } } - return $con->exec($sql); + try { + $con->exec($sql); + } catch (Exception $e){ + Logging::log("Could not connect to database."); + header('HTTP/1.0 503 Service Unavailable'); + exit; + } } public static function GetValue($key, $isUserValue = false){ diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 886f9a8ba..a6044c868 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -235,7 +235,9 @@ class Application_Model_StoredFile { foreach ($c['user'] as $constant => $value) { if (preg_match('/^MDATA_KEY/', $constant)) { if (isset($dbmd_copy[$value])) { - $md[$constant] = $this->getDbColMetadataValue($value); + $propelColumn = $dbmd_copy[$value]; + $method = "get$propelColumn"; + $md[$constant] = $this->_file->$method(); } } } diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py index cab57381c..1cef988b1 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py @@ -88,17 +88,16 @@ class AirtimeMetadata: try: airtime_file = mutagen.File(m['MDATA_KEY_FILEPATH'], easy=True) - for key in m.keys() : + for key in m: if key in self.airtime2mutagen: value = m[key] - if (value is not None): - self.logger.debug("Saving %s to file", key) - self.logger.debug(value) - if isinstance(value, basestring) and (len(value) > 0): - airtime_file[self.airtime2mutagen[key]] = api_client.encode_to(value, 'utf-8') - elif isinstance(value, int): - airtime_file[self.airtime2mutagen[key]] = str(value) - + + if value is not None: + value = unicode(value) + + if len(value) > 0: + self.logger.debug("Saving key '%s' with value '%s' to file", key, value) + airtime_file[self.airtime2mutagen[key]] = value airtime_file.save() except Exception, e: diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index 42f22b0ba..e527d56cb 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -62,7 +62,7 @@ class AirtimeNotifier(Notifier): message.ack() self.logger.info("Received md from RabbitMQ: " + body) - m = json.loads(message.body) + m = json.loads(message.body) if m['event_type'] == "md_update": self.logger.info("AIRTIME NOTIFIER md update event") @@ -103,9 +103,9 @@ class AirtimeNotifier(Notifier): self.mmc.ensure_is_dir(self.config.imported_directory) self.mmc.ensure_is_dir(self.config.organize_directory) - self.mmc.set_needed_file_permissions(self.config.storage_directory, True) - self.mmc.set_needed_file_permissions(self.config.imported_directory, True) - self.mmc.set_needed_file_permissions(self.config.organize_directory, True) + self.mmc.is_readable(self.config.storage_directory, True) + self.mmc.is_readable(self.config.imported_directory, True) + self.mmc.is_readable(self.config.organize_directory, True) self.watch_directory(new_storage_directory) elif m['event_type'] == "file_delete": @@ -150,7 +150,6 @@ class AirtimeNotifier(Notifier): file_md = None data = None - if (os.path.exists(filepath) and (mode == self.config.MODE_CREATE)): if file_md is None: mutagen = self.md_manager.get_md_from_file(filepath) @@ -192,17 +191,13 @@ class AirtimeNotifier(Notifier): mm = self.proc_fun() - self.mmc.set_needed_file_permissions(directory, True) + self.mmc.is_readable(directory, True) for (path, dirs, files) in os.walk(directory): - - for d in dirs: - self.mmc.set_needed_file_permissions(os.path.join(path, d), True) - for filename in files: full_filepath = os.path.join(path, filename) if self.mmc.is_audio_file(full_filepath): - if self.mmc.set_needed_file_permissions(full_filepath, False): + if self.mmc.is_readable(full_filepath, False): self.logger.info("importing %s", full_filepath) event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False} mm.multi_queue.put(event) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 0d6a6e602..419bbd685 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -134,7 +134,7 @@ class AirtimeProcessEvent(ProcessEvent): #file is being overwritten/replaced in GUI. elif "goutputstream" in pathname: self.temp_files[pathname] = None - elif self.mmc.is_audio_file(pathname): + elif self.mmc.is_audio_file(pathname) and self.mmc.is_readable(pathname, False): if self.mmc.is_parent_directory(pathname, self.config.organize_directory): #file was created in /srv/airtime/stor/organize. Need to process and move #to /srv/airtime/stor/imported @@ -151,14 +151,14 @@ class AirtimeProcessEvent(ProcessEvent): self.logger.error('Exception: %s', e) self.logger.error("traceback: %s", traceback.format_exc()) - self.mmc.set_needed_file_permissions(pathname, dir) + self.mmc.is_readable(pathname, dir) is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory) self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded}) else: #event is because of a created directory if self.mmc.is_parent_directory(pathname, self.config.storage_directory): - self.mmc.set_needed_file_permissions(pathname, dir) + self.mmc.is_readable(pathname, dir) def process_IN_MODIFY(self, event): # if IN_MODIFY is followed by IN_CREATE, it's not true modify event @@ -237,9 +237,9 @@ class AirtimeProcessEvent(ProcessEvent): if event.pathname in filename: self.handle_mount_change() #if stuff dropped in stor via a UI move must change file permissions. - self.mmc.set_needed_file_permissions(event.pathname, event.dir) + self.mmc.is_readable(event.pathname, event.dir) if not event.dir: - if self.mmc.is_audio_file(event.name): + if self.mmc.is_audio_file(event.name) and self.mmc.is_readable(full_filepath, False): if event.cookie in self.temp_files: self.file_events.append({'filepath': event.pathname, 'mode': self.config.MODE_MODIFY}) del self.temp_files[event.cookie] diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index b28b1dfcd..fdd83de6b 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -49,7 +49,7 @@ class MediaMonitorCommon: return False #check if file is readable by "nobody" - def has_correct_permissions(self, filepath, euid='nobody', egid='nogroup'): + def is_user_readable(self, filepath, euid='nobody', egid='nogroup'): try: uid = pwd.getpwnam(euid)[2] @@ -76,35 +76,13 @@ class MediaMonitorCommon: return readable # the function only changes the permission if its not readable by www-data - def set_needed_file_permissions(self, item, is_dir): + def is_readable(self, item, is_dir): try: - omask = os.umask(0) - if not self.has_correct_permissions(item, 'www-data', 'www-data') or not self.has_correct_permissions(item, 'pypo', 'pypo'): - # stats.st_mode is the original permission - # stat.S_IROTH - readable by all permission - # stat.S_IXOTH - excutable by all permission - # try to set permission - if self.is_parent_directory(item, self.config.storage_directory) or self.is_parent_directory(item, self.config.imported_directory) or self.is_parent_directory(item, self.config.organize_directory): - if is_dir is True: - os.chmod(item, 02777) - else: - os.chmod(item, 0666) - else : - # add world readable permission - stats = os.stat(item) - if is_dir is True: - bitor = stats.st_mode | stat.S_IROTH | stat.S_IXOTH - else: - bitor = stats.st_mode | stat.S_IROTH - os.chmod(item, bitor) + return self.is_user_readable(item, 'www-data', 'www-data') \ + and self.is_user_readable(item, 'pypo', 'pypo') except Exception, e: - self.logger.error("Failed to change file's owner/group/permissions. %s", e) - self.logger.error("traceback: %s", traceback.format_exc()) + self.logger.warn("Failed to check owner/group/permissions for %s", item) return False - finally: - os.umask(omask) - return True - #checks if path is a directory, and if it doesnt exist, then creates it. #Otherwise prints error to log file. diff --git a/python_apps/media-monitor/media_monitor.py b/python_apps/media-monitor/media_monitor.py index d9dcf518c..7c39bba0a 100644 --- a/python_apps/media-monitor/media_monitor.py +++ b/python_apps/media-monitor/media_monitor.py @@ -51,6 +51,7 @@ def configure_locale(): if current_locale_encoding not in ['utf-8', 'utf8']: logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding) + sys.exit(1) # configure logging try: