Merging 2.5.x into saas

This commit is contained in:
Duncan Sommerville 2014-10-27 16:27:45 -04:00
commit 1a90184a69
8 changed files with 87 additions and 46 deletions

View File

@ -61,6 +61,7 @@ class LoginController extends Zend_Controller_Action
$result = $auth->authenticate($authAdapter); $result = $auth->authenticate($authAdapter);
if ($result->isValid()) { if ($result->isValid()) {
Zend_Session::regenerateId();
//all info about this user from the login table omit only the password //all info about this user from the login table omit only the password
$userInfo = $authAdapter->getResultRowObject(null, 'password'); $userInfo = $authAdapter->getResultRowObject(null, 'password');
@ -81,6 +82,7 @@ class LoginController extends Zend_Controller_Action
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter); $result = $auth->authenticate($authAdapter);
if ($result->isValid()) { if ($result->isValid()) {
Zend_Session::regenerateId();
//set the user locale in case user changed it in when logging in //set the user locale in case user changed it in when logging in
Application_Model_Preference::SetUserLocale($locale); Application_Model_Preference::SetUserLocale($locale);

View File

@ -129,6 +129,15 @@ class Rest_MediaController extends Zend_Rest_Controller
public function postAction() public function postAction()
{ {
/* If the user presents a valid API key, we don't check CSRF tokens.
CSRF tokens are only used for session based authentication.
*/
if(!$this->verifyAPIKey()){
if(!$this->verifyCSRFToken($this->_getParam('csrf_token'))){
return;
}
}
if (!$this->verifyAuth(true, true)) if (!$this->verifyAuth(true, true))
{ {
return; return;
@ -295,6 +304,21 @@ class Rest_MediaController extends Zend_Rest_Controller
return $id; return $id;
} }
private function verifyCSRFToken($token){
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
$observed_csrf_token = $token;
$expected_csrf_token = $current_namespace->authtoken;
if($observed_csrf_token == $expected_csrf_token){
return true;
}else{
$resp = $this->getResponse();
$resp->setHttpResponseCode(401);
$resp->appendBody("ERROR: Token Missmatch.");
return false;
}
}
private function verifyAuth($checkApiKey, $checkSession) private function verifyAuth($checkApiKey, $checkSession)
{ {
//Session takes precedence over API key for now: //Session takes precedence over API key for now:

View File

@ -166,10 +166,7 @@
</ul> </ul>
<?php endif; ?> <?php endif; ?>
</dd> </dd>
<?php echo $this->element->getElement('csrf') ?> <?php echo $this->element->getElement('csrf') ?>
<button type="submit" id="cu_save_user" class="btn btn-small right-floated"><?php echo _("Save")?></button>
</dl> </dl>
<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>
</form> </form>

View File

@ -42,14 +42,16 @@ class FileMoverAnalyzer(Analyzer):
# TODO: Also, handle the case where the move fails and write some code # TODO: Also, handle the case where the move fails and write some code
# to possibly move the file to problem_files. # to possibly move the file to problem_files.
max_dir_len = 32 max_dir_len = 48
max_file_len = 32 max_file_len = 48
final_file_path = import_directory final_file_path = import_directory
orig_file_basename, orig_file_extension = os.path.splitext(original_filename)
if metadata.has_key("artist_name"): if metadata.has_key("artist_name"):
final_file_path += "/" + metadata["artist_name"][0:max_dir_len] # truncating with array slicing final_file_path += "/" + metadata["artist_name"][0:max_dir_len] # truncating with array slicing
if metadata.has_key("album_title"): if metadata.has_key("album_title"):
final_file_path += "/" + metadata["album_title"][0:max_dir_len] final_file_path += "/" + metadata["album_title"][0:max_dir_len]
final_file_path += "/" + original_filename[0:max_file_len] # Note that orig_file_extension includes the "." already
final_file_path += "/" + orig_file_basename[0:max_file_len] + orig_file_extension
#Ensure any redundant slashes are stripped #Ensure any redundant slashes are stripped
final_file_path = os.path.normpath(final_file_path) final_file_path = os.path.normpath(final_file_path)

View File

@ -120,7 +120,12 @@ class MessageListener:
def disconnect_from_messaging_server(self): def disconnect_from_messaging_server(self):
'''Stop consuming RabbitMQ messages and disconnect''' '''Stop consuming RabbitMQ messages and disconnect'''
# If you try to close a connection that's already closed, you're going to have a bad time.
# We're breaking EAFP because this can be called multiple times depending on exception
# handling flow here.
if not self._channel.is_closed and not self._channel.is_closing:
self._channel.stop_consuming() self._channel.stop_consuming()
if not self._connection.is_closed and not self._connection.is_closing:
self._connection.close() self._connection.close()
def graceful_shutdown(self, signum, frame): def graceful_shutdown(self, signum, frame):

View File

@ -57,7 +57,8 @@ def process_http_requests(ipc_queue, http_retry_queue_path):
logging.error("Failed to unpickle %s. Continuing..." % http_retry_queue_path) logging.error("Failed to unpickle %s. Continuing..." % http_retry_queue_path)
pass pass
while True:
try:
while not shutdown: while not shutdown:
try: try:
request = ipc_queue.get(block=True, timeout=5) request = ipc_queue.get(block=True, timeout=5)
@ -84,6 +85,14 @@ def process_http_requests(ipc_queue, http_retry_queue_path):
# while the web server is down or unreachable. # while the web server is down or unreachable.
with open(http_retry_queue_path, 'wb') as pickle_file: with open(http_retry_queue_path, 'wb') as pickle_file:
pickle.dump(retry_queue, pickle_file) pickle.dump(retry_queue, pickle_file)
except Exception as e: # Terrible top-level exception handler to prevent the thread from dying, just in case.
if shutdown:
return
logging.exception("Unhandled exception in StatusReporter")
logging.exception(e)
logging.info("Restarting StatusReporter thread")
time.sleep(2) # Throttle it
def send_http_request(picklable_request, retry_queue): def send_http_request(picklable_request, retry_queue):
if not isinstance(picklable_request, PicklableHttpRequest): if not isinstance(picklable_request, PicklableHttpRequest):
@ -134,11 +143,11 @@ def is_web_server_broken(url):
test_req = requests.get(url) test_req = requests.get(url)
test_req.raise_for_status() test_req.raise_for_status()
except Exception as e: except Exception as e:
return true return True
else: else:
# The request worked fine, so the web server and Airtime are still up. # The request worked fine, so the web server and Airtime are still up.
return false return False
return false return False
def alert_hung_request(): def alert_hung_request():

View File

@ -9,14 +9,16 @@ respawn
setuid www-data setuid www-data
setgid www-data setgid www-data
expect fork #expect fork
env LANG='en_US.UTF-8' env LANG='en_US.UTF-8'
env LC_ALL='en_US.UTF-8' env LC_ALL='en_US.UTF-8'
script #script
airtime_analyzer # airtime_analyzer
end script #end script
exec airtime_analyzer