diff --git a/webclient/config.php b/webclient/config.php index 5e7980b5a861f872f24d5dd44e06471e748bf364..51116abd60ce33908aa847daf26b32c720fbe2b9 100644 --- a/webclient/config.php +++ b/webclient/config.php @@ -1,7 +1,6 @@ diff --git a/webclient/index.php b/webclient/index.php index cb0aab8ac7fa180db852a7c03bb0f9e8ab9e1e7c..44869e265f1ea58153ccdb5ec488889faf986b2d 100644 --- a/webclient/index.php +++ b/webclient/index.php @@ -23,7 +23,7 @@ if (!isset($mwsess)) { if ($_REQUEST['sucssite_loggedin']=="true" && $action!="logout") { require("startup.php"); } else { - echo 'Post requests only to this url'; + echo 'nope'; exit; } } diff --git a/webclient/poll.php b/webclient/poll.php index a9d7783c6df53ee8a51a2e0d5e20c4ad3cffec34..144623f2f5de8166c53403830e8cff485e51e466 100644 --- a/webclient/poll.php +++ b/webclient/poll.php @@ -1,12 +1,11 @@ - require_once("config.php"); $data = unserialize(@$_REQUEST['mwsess']); $sess = (int)$data['pid']; $auth = trim($data['auth']); -$path = $poller_path.$sess; +$path = $poller_path . $sess; header("Content-type: application/json; charset=utf-8"); @@ -27,7 +26,10 @@ if (@socket_recv($sock, $response, 4096, 0)===FALSE) { exit; } $res = json_decode($response, TRUE); -if ($res === NULL) { echo "{\"status\":\"Bad server response\"}\n"; exit; } +if ($res === NULL) { + echo "{\"status\":\"Bad server response\"}\n"; + exit; +} if ($res['status'] != "OK") { echo $response; @@ -46,8 +48,12 @@ if (@socket_recv($sock, $response, 262144, 0)===FALSE) { exit; } -if ($response!="") echo $response."\n"; -else echo "[]\n"; +if ($response != "") { + echo $response . "\n"; +} else { + echo "[]\n"; +} socket_close($sock); +exit; ?> diff --git a/webclient/startup.php b/webclient/startup.php index 0e9781a74274256b980cb6aa0a640cba9fb077df..32db816f3f13109bff79e7317a8ec286f9893b5d 100644 --- a/webclient/startup.php +++ b/webclient/startup.php @@ -7,140 +7,120 @@ $password = trim($_REQUEST['password']); // Preliminary checks -// Have we been passed SUCSsite cookies? -// If not, test that the login details make sense. -if (@$_REQUEST['sucssite_loggedin']!="true") { - if (empty($username) || empty($password)) { - echo json_encode((object) ['error' => 'username and password must both be not empty']); - exit; - } +// Test that the login details make sense. +if (empty($username) || empty($password)) { + echo json_encode((object) ['error' => 'username and password must both be not empty']); +} - if (ctype_alnum($username) === FALSE) { - echo json_encode((object) ['error' => 'alphanumeric usernames only']); - exit; - } +if (!preg_match("/^[a-z][a-z0-9_]*$/", $username)) { + echo json_encode((object) ['error' => 'invalid characters in username']); + exit; } -// Have we been asked to create a new Milliways account? -// If so, make sure that the password supplied is suitable. -if ($action=="create") { - $pass1 = @$_REQUEST['password1']; - $pass2 = @$_REQUEST['password2']; - - if ($pass1 != $pass2) { - echo json_encode((object) ['error' => 'Passwords don\'t match - please try again']); - exit; - } +login($mwpoll, $username, $password, true); - if (empty($pass1)) { - echo json_encode((object) ['error' => 'Password cannot be blank']); - exit; - } - - if (ctype_alnum($pass1) === FALSE) { - echo json_encode((object) ['error' => 'Milliways passwords can only contain alphanumeric characters']); - exit; - } +function login($mwpoll, $username, $password, $continue) { + $desc = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + ); + $pipes = array(); - if (strlen($pass1) < 6) { - echo json_encode((object) ['error' => 'Milliways passwords must be 6 characters or more']); - exit; - } -} - -$desc = array( - 0 => array("pipe", "r"), - 1 => array("pipe", "w"), -); -$pipes = array(); - -// Have we got SUCSsite cookies? -// And no login attempt? -// If so, fetch the user details and try to log in without a password. -if (@$_REQUEST['sucssite_loggedin']=="true" && empty($username)) { - - // Do we appear to be in the SUCSsite environment? - // There's only any point trying if we do. - if (file_exists("../settings.php")) { - // Do the bare minimum of SUCSsite init to retrieve the username for the session we've been passed - include("../settings.php"); - // Initialise the database - require("/usr/share/php/adodb/adodb.inc.php"); - $DB = NewADOConnection('postgres9'); - $DB->Connect('dbname='.$dbname.' user=apache'); - $DB->SetFetchMode(ADODB_FETCH_ASSOC); - - // Include the session library - require($base."lib/session.php"); - $session = new Session; - // $smarty->assign("session", $session); // This line might be useful? - $realuser = $session->username; - - if ($action == "create") { - $p = proc_open($mwpoll." -q -a -u ".$realuser." -s", $desc, $pipes); - } else { - $p = proc_open($mwpoll." -q -u ".$realuser." -s", $desc, $pipes); - } - $mode = "sucssite"; - } -} else { - // If not, try logging in with a password. $p = proc_open($mwpoll." -q -u $username", $desc, $pipes); - $mode = "password"; -} -if (empty($p)) { - echo "