eduroamLogin(); } if ($admin_type > -1) { $this->ZePrijavljen = true; $this->LoggingIn = false; $sql = sisplet_query ("SELECT name, surname, lang FROM users WHERE email='" .base64_decode ($_COOKIE['uid']) ."'"); if ($r = mysqli_fetch_row ($sql)) { $this->ime = $r[0]; $this->priimek = $r[1]; if (is_numeric ($r[2]) && $r[2] != "0" && $r[2]!=$lang['id']) { unset ($lang); include ($site_path .'lang/' .$r[2] .'.php'); } $this->ime = CleanXSS ($this->ime); $this->priimek = CleanXSS ($this->priimek); } } else { if (isset ($_POST['mail'])) $this->email = strtolower ($_POST['mail']); if (isset ($_GET['mail'])) $this->email = strtolower ($_GET['mail']); if (isset ($_POST['pass'])) $this->pass = $_POST['pass']; $this->email = CleanXSS ($this->email); $this->pass = CleanXSS ($this->pass); $this->LoggingIn = true; } } function eduroamAnotherServerLogin() { global $pass_salt; global $cookie_domain; global $originating_domain; global $keep_domain; // Popravimo string iz geta, ker ima nekje + namesto space $repaired_string = str_replace(' ', '+', $_GET['s']); // malo manj varno, ampak bo OK. $klobasa = base64_decode($repaired_string); // Dobimo array parametrov iz get-a $data = explode ("|", $klobasa); // Pridobimo maile - mozno da jih je vec, potem vzamemo prvega $mails = explode(";", $data[0]); sort($mails); $mail = $mails[0]; $ime = $data[1]; $priimek = $data[2]; $njegova = $data[3]; $moja = $data[4]; // Preverimo ce ima veljaven token (najprej pobrisemo stare) sisplet_query ("DELETE FROM aai_prenosi WHERE timestamp < (UNIX_TIMESTAMP() - 600);"); $res = sisplet_query ("SELECT * FROM aai_prenosi WHERE moja='" .$moja ."' AND njegova='" .$njegova ."'"); if (mysqli_num_rows ($res) > 0) { $pass = base64_encode((hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&" .$pass_salt))); // Preverimo ce obstaja user v bazi $result = sisplet_query ("SELECT pass, id FROM users WHERE email='" .$mail ."'"); if (mysqli_num_rows ($result) == 0) { // dodaj ga v bazo $pass = base64_encode(hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&" .$pass_salt)); sisplet_query ("INSERT INTO users (email, name, surname, type, pass, eduroam, when_reg) VALUES ('$mail', '$ime', '$priimek', '3', '" .$pass ."', '1', NOW())"); // Pridobimo id dodanega userja $user_id = mysqli_insert_id($GLOBALS['connect_db']); } else { // potegni geslo in mu daj kuki $r = mysqli_fetch_row ($result); $pass = $r[0]; $user_id = $r[1]; } $result = sisplet_query ("SELECT value FROM misc WHERE what='CookieLife'"); $row = mysqli_fetch_row ($result); $LifeTime = $row[0]; // Zlogiramo login sisplet_query ("UPDATE users SET last_login=NOW() WHERE id='".$user_id."'"); // določi še, od kje se je prijavil $hostname=""; $headers = apache_request_headers(); if (array_key_exists('X-Forwarded-For', $headers)){ $hostname=$headers['X-Forwarded-For']; } else { $hostname=$_SERVER["REMOTE_ADDR"]; } sisplet_query ("INSERT INTO user_login_tracker (uid, IP, kdaj) VALUES ('".$user_id."', '" .$hostname ."', NOW())"); setcookie ("uid", base64_encode($mail), time()+$LifeTime, '/', $cookie_domain); setcookie ("secret", $pass, time()+$LifeTime, '/', $cookie_domain); // moram vedeti, da je AAI! setcookie ("aai", '1', '/', $cookie_domain); $this->ZePrijavljen = true; // Moramo po registraciji vrec na kak URL $rxx = str_replace ($originating_domain, $keep_domain, '/admin/survey/'); header ('location: '.$rxx.'?&l=1'); } else header ('location: /index.php'); } function eduroamLogin() { global $pass_salt; global $cookie_domain; global $originating_domain; global $keep_domain; $mail = $_SERVER['mail']; $ime = $_SERVER['givenName']; $priimek = $_SERVER['sn']; $pass = base64_encode((hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&" .$pass_salt))); $result = sisplet_query ("SELECT pass, id FROM users WHERE email='" .$mail ."'"); if (mysqli_num_rows ($result) == 0) { // dodaj ga v bazo $pass = base64_encode((hash('SHA256', "e5zhbWRTEGW&u375ejsznrtztjhdtz%WZ&" .$pass_salt))); sisplet_query ("INSERT INTO users (email, name, surname, type, pass, eduroam) VALUES ('$mail', '$ime', '$priimek', '3', '" .$pass ."', '1')"); // Pridobimo id dodanega userja $user_id = mysqli_insert_id($GLOBALS['connect_db']); } else { // potegni geslo in mu daj kuki $r = mysqli_fetch_row ($result); $pass = $r[0]; $user_id = $r[1]; } $result = sisplet_query ("SELECT value FROM misc WHERE what='CookieLife'"); $row = mysqli_fetch_row ($result); $LifeTime = $row[0]; sisplet_query ("UPDATE users SET last_login=NOW() WHERE id='" .$user_id ."'"); // določi še, od kje se je prijavil $hostname=""; $headers = apache_request_headers(); if (array_key_exists('X-Forwarded-For', $headers)){ $hostname=$headers['X-Forwarded-For']; } else { $hostname=$_SERVER["REMOTE_ADDR"]; } sisplet_query ("INSERT INTO user_login_tracker (uid, IP, kdaj) VALUES ('" .$user_id ."', '" .$hostname ."', NOW())"); setcookie ("uid", base64_encode($mail), time()+$LifeTime, '/', $cookie_domain); setcookie ("secret", $pass, time()+$LifeTime, '/', $cookie_domain); setcookie("unam", base64_encode($ime.' '.$priimek),time() + $LifeTime, '/', $cookie_domain); // moram vedeti, da je AAI! setcookie("aai", '1', time() + $LifeTime, '/', $cookie_domain); // Piškotek za cca. 10 let, da mu naslednjić ponudimo prijavno setcookie('external-login', '1', time()+280000000, '/', $cookie_domain); $this->ZePrijavljen = true; // Moramo po registraciji vrec na kak URL $rxx = str_replace ($originating_domain, $keep_domain, '/admin/survey/'); header ('location: '.$rxx.'?&l=1'); } function GoogleLogin () { require_once ('../function/JWT.php'); global $site_url; global $lang; global $proxy; $oauth2_code = $_GET['code']; $discovery = json_decode(file_get_contents('https://accounts.google.com/.well-known/openid-configuration')); if ($proxy != "") { $ctx = stream_context_create(array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query(array( 'client_id' => AppSettings::getInstance()->getSetting('google-login_client_id'), 'client_secret' => AppSettings::getInstance()->getSetting('google-login_client_secret'), 'code' => $oauth2_code, 'grant_type' => 'authorization_code', 'redirect_uri' => $site_url .'utils/google-oauth2.php', 'openid.realm' => $site_url, )), 'proxy' => 'tcp://' .$proxy, ), )); } else { $ctx = stream_context_create(array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query(array( 'client_id' => AppSettings::getInstance()->getSetting('google-login_client_id'), 'client_secret' => AppSettings::getInstance()->getSetting('google-login_client_secret'), 'code' => $oauth2_code, 'grant_type' => 'authorization_code', 'redirect_uri' => $site_url .'utils/google-oauth2.php', 'openid.realm' => $site_url, )), ), )); } $resp = file_get_contents($discovery->token_endpoint, false, $ctx); if (!$resp) { // $http_response_header here got magically populated by file_get_contents(), surprise echo '
' .$lang['google_auth_rejected'] .'
'; echo '' .$lang['google_auth_rejected'] .'
'; echo '