From 03de93807f0a249360321ef449140e860880e7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Fri, 8 Nov 2019 18:39:29 +0100 Subject: 0.7.1 added and fixed resetgeslo --- main.php | 75 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'main.php') diff --git a/main.php b/main.php index dec102a..52d4616 100644 --- a/main.php +++ b/main.php @@ -49,11 +49,12 @@ Errors: -3 bad username or password -4 not written yet -5 unable to create cookie dir + -6 non existing user */ class gimsisextClient { private $username; private $password; - public $version = array(0, 6, 0); + public $version = array(0, 7, 1); private $programname = "gimsisextclient"; private $programdomain = 'gimsisextclient.gimb.tk'; private $cookiedir; // set at runtime, ker je get_curerent_user, v login() @@ -71,6 +72,7 @@ Errors: private $gimsisextsetgeslo = "https://zgimsis.gimb.org/gse/WS_Gim/wsGimSisUtils.asmx/ShraniUporabnikGeslo"; private $gimsisextizbrisisporocilo = "https://zgimsis.gimb.org/gse/Page_Gim/Uporabnik/Sporocila.aspx/DeleteMessage"; private $gimsisextizostanki = "https://zgimsis.gimb.org/gse/Page_Gim/Ucenec/IzostankiUcenec.aspx"; + private $gimsisextresetgeslo = "https://zgimsis.gimb.org/gse/ResetPassword.aspx"; public function setusername($value) { $this->username = $value; } @@ -683,48 +685,43 @@ Errors: } return $izostanki; } - public function fetchocene() { - $ch = $this->login(); - if(!curl_getinfo($ch)) { - if(!empty($ch)){return $ch;}else{return -2;} - } - curl_setopt($ch, CURLOPT_URL, $this->gimsisextocene); + public function resetgeslo($user) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0); + curl_setopt($ch, CURLOPT_COOKIESESSION, true ); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_VERBOSE, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return transfer? + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow 3xx redirects? + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // max 3xx redirectas? + curl_setopt($ch, CURLOPT_USERAGENT, $this->programdomain."/".implode(".", $this->version)); + curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // auto send refereres? + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // timeout for tcp connection + curl_setopt($ch, CURLOPT_TIMEOUT, 10); // timeout for http response + curl_setopt($ch, CURLOPT_URL, $this->gimsisextresetgeslo); curl_setopt($ch, CURLOPT_POST, 0); - $ocene_output = curl_exec($ch); + $resetgeslo_init_output = curl_exec($ch); $xmlDoc = new DOMDocument(); - $xmlDoc->loadHTML( $ocene_output ); - $spanNode = $xmlDoc->getElementsByTagName( "span" ); - $ocene = array(); - foreach ($spanNode as $sn) { - if($sn->getAttribute('class') == "txtVOcObd") { - $is = $sn->getElementsByTagName("span")[0]; // innerspan je is, innerspantitle je pa ist, hehe - $ist = explode("\n", $is->getAttribute("title")); - $datum = explode(": ", $ist[0])[1]; - $ucitelj = explode(": ", $ist[1])[1]; - $predmet = explode(": ", $ist[2])[1]; - $ocenjevanje = explode(": ", $ist[3])[1]; - $vrsta = explode(": ", $ist[4])[1]; - $rok = explode(": ", $ist[5])[1]; - $ocena = DOMinnerHTML($is); - if(explode(" ", $is->getAttribute("class"))[1] == "ocVmesna") { - $zacasna = 1; - } else { - $zacasna = 0; - } - $ocene[] = array( - "datum" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $datum))), - "profesor" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $ucitelj))), - "predmet" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $predmet))), - "naslov" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $ocenjevanje))), - "vrsta" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $vrsta))), - "rok" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $rok))), - "rok" => str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $rok))), - "ocena" => intval(str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $ocena)))), - "zacasna" => boolval(str_replace("\n", null, str_replace("\r", null, str_replace(" ", null, $zacasna)))) - ); + $xmlDoc->loadHTML( $resetgeslo_init_output ); + $searchNode = $xmlDoc->getElementsByTagName( "input" ); + foreach( $searchNode as $sn ) { + if($sn->getAttribute('name') != 'edtGSEUserId') { + $postvars .= urlencode($sn->getAttribute('name'))."=".urlencode($sn->getAttribute('value'))."&"; } } - return $ocene; + curl_setopt($ch, CURLOPT_URL, $this->gimsisextresetgeslo); + curl_setopt($ch, CURLOPT_POST, 1); + $postbody = $postvars . urlencode('edtGSEUserId') . '=' . $user; + curl_setopt($ch, CURLOPT_POSTFIELDS, $postbody); + $resetgeslo_output = curl_exec($ch); + if(get_string_between($resetgeslo_output, "Uporabnik z vne", "enim uporabni") == "s") { + return -6; + } else { + $odg = get_string_between($resetgeslo_output, "na e-poštni naslov ", "."); + $odg2 = get_string_between($resetgeslo_output, "na e-poštni naslov ", "."); + if(strlen($odg) < strlen($odg2)) return $odg2; + } } } ?> -- cgit v1.2.3