Commit bdf91f07 authored by Steve Johnson's avatar Steve Johnson

fixed qrc polling issues

parent 9804b0b6
......@@ -74,25 +74,29 @@ var App = (function () {
var request = new XMLHttpRequest();
var url = Url.remoteLoginAgent(connectCode);
request.timeout = 120000;
request.ontimeout = function() {
// restart the agent
console.log("Remote Agent Timeout. Restarting..");
startRemoteLoginAgent();
}
request.issue(url, function(response){
if (response.httpStatus === 200) {
// TODO: Ensure cookie is set.
alert("received 200 from "+url+" - redirecting to smc.");
console.log("received 200 from "+url+" - redirecting to smc.");
location.replace(Url.secureMessageCenter());
}
else {
else if (response.httpStatus != 0){
// Failed to be authenticated. Restart after delay to prevent spinning.
clearTimeout(longPollTimer);
setTimeout(function(){startRemoteLoginAgent();}, 5000);
console.log("received "+response.httpStatus+" from "+url);
setTimeout(function(){startRemoteLoginAgent();}, 2500);
}
});
longPollTimer = setTimeout(function(){
request.abort();
startRemoteLoginAgent();
}, 120000);
}
function generateQRCode() {
......
......@@ -13,7 +13,8 @@
}
function purge_agents() {
purge_files(agent_dir(), 60);
// Five minutes. Long poll interval is 2 minutes.
purge_files(agent_dir(), 60*5);
}
// TODO: How to manage access token lifespan (in terms of how long they map to valid login cookies)
......@@ -35,6 +36,7 @@
foreach ($files as $file) {
if (is_file($file)) {
if ($time - filemtime($file) >= $age) {
dbg_log("purging file: ".$file);
unlink($file);
}
}
......
......@@ -15,6 +15,8 @@
require 'utils.php';
require 'qrc_utils.php';
// Client will time out every 2 minutes. Ensure we terminate after 5.
// Don't need a session. Might be hanging session_start by others.
session_write_close();
......@@ -27,7 +29,7 @@
$ccode = $_GET['connectCode'];
// Purge aged agent files
//purge_agents();
purge_agents();
// Ensure agent file exists - if not, create one.
// Agent file is initially empty - filename is connect code. Used to identify active agents.
......@@ -39,10 +41,22 @@
$file_time = filemtime($agent_file);
// Poll interval is 1/2 second. Exit after 3 minutes (client should timeout after 2 minutes)
$poll_limit = 3 * 60 * 2;
while(true) {
if ($poll_limit <= 0) {
dbg_log("remote_login_agent: poll limit expired for connection: ".$ccode);
exit(0);
}
$poll_limit = $poll_limit - 1;
clearstatcache();
if (!file_exists($agent_file)) {
dbg_log("remote_login_agent: agent file not found: ".$agent_file);
exit(0);
}
......@@ -73,6 +87,9 @@
header('HTTP/1.0 200 OK');
// Done with this connection agent
unlink($agent_file);
echo "got your cookie!";
exit(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment