Advertisement
-kw

HS Merseburg Gesamtdurchschnitt berechnen

-kw
Mar 29th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.52 KB | None | 0 0
  1. <?php
  2.  
  3. //about
  4. /*
  5. by -kw
  6. v1.0
  7.  
  8. Grabbt alle Noten und errechnet den Durchschnitt.
  9.  
  10.  */
  11.  
  12. if (isset($_POST['username']) && trim($_POST['username']) != '' && isset($_POST['passwd']) && trim($_POST['passwd']) != '' && isset($_POST['matrikelnr']) && trim($_POST['matrikelnr']) != '') {
  13.     $username = trim($_POST['username']); //Rechenzentrum Nutzername
  14.     $passwd = trim($_POST['passwd']); //Rechenzentrum Passwort
  15.     $matrikelnr = trim($_POST['matrikelnr']); //Matrikelnummer
  16.  
  17. //do not change from here
  18.     date_default_timezone_set("Europe/Berlin");
  19.     $cookies = "cookies.txt";
  20.     if (!file_exists($cookies)) {
  21.         file_put_contents($cookies, "");
  22.     }
  23.  
  24.     $noten = array();
  25.     $credits = array();
  26.  
  27.     function execute($ho, $state, $array, $newsess) {
  28.         global $cookies;
  29.         $log_hoster = $array;
  30.         $ch = curl_init();
  31.  
  32.         $url = $log_hoster[$ho][0];
  33.         $postdata = $log_hoster[$ho][1];
  34.         $ref = $log_hoster[$ho][2];
  35.  
  36.         curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  37.         curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  38.         curl_setopt($ch, CURLOPT_COOKIE, $cookies);
  39.         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
  40.         curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
  41.         curl_setopt($ch, CURLOPT_COOKIESESSION, $newsess);
  42.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  43.         curl_setopt($ch, CURLOPT_HEADER, false);
  44.         curl_setopt($ch, CURLOPT_POST, true);
  45.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  46.         curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
  47.         curl_setopt($ch, CURLOPT_REFERER, $ref);
  48.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  49.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  50.         curl_setopt($ch, CURLOPT_URL, $url);
  51.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  52.         $retu = curl_exec($ch);
  53.         sleep(1);
  54.         return $retu;
  55.     }
  56.  
  57.     function getsite($zielurl, $postdata = "", $ref = "", $newsess = true) {
  58.         $log_hoster = array(
  59.             array($zielurl, $postdata, $ref),
  60.         );
  61.         $temp = execute(0, true, $log_hoster, $newsess);
  62.         return $temp;
  63.     }
  64.  
  65. //einlogen
  66.     $URL = "https://hisqis.hs-merseburg.de/qisserver/rds?state=user&type=1&category=auth.login&startpage=portal.vm";
  67.     $seite = getsite($URL, "username=" . urlencode($username) . "&password=" . urlencode($passwd) . "&mtknr=" . urlencode($matrikelnr) . "&submit=%C2%A0Anmelden%C2%A0");
  68.     if (str_replace("anmelden", "", strtolower($seite)) != strtolower($seite)) {
  69.         echo "Login nicht erfolgreich...";
  70.         die();
  71.     }
  72.  
  73. //asi (SessionID) finden
  74.     $URL = "https://hisqis.hs-merseburg.de/qisserver/rds?state=change&type=1&moduleParameter=studyPOSMenu&nextdir=change&next=menu.vm&subdir=applications&xml=menu&purge=y&navigationPosition=functions%2CstudyPOSMenu&breadcrumb=studyPOSMenu&topitem=functions&subitem=studyPOSMenu";
  75.     $seite = explode("\n", getsite($URL, "", "https://hisqis.hs-merseburg.de/qisserver/", false));
  76.     foreach ($seite as $key => $value) {
  77.         if (str_replace("<a href=\"https://hisqis.hs-merseburg.de/qisserver/rds?state=notenspiegel", "", $value) != $value) {
  78.             $start = strpos($value, "asi=");
  79.             $cut = substr($value, $start + 4);
  80.             $ende = strpos($cut, '"');
  81.             $asi = substr($cut, 0, $ende);
  82.         }
  83.     }
  84.  
  85.     if (!isset($asi)) {
  86.         exit();
  87.     }
  88.  
  89. //Noten abrufen
  90.     $URL = "https://hisqis.hs-merseburg.de/qisserver/rds?state=notenspiegelStudent&next=list.vm&nextdir=qispos/notenspiegel/student&createInfos=Y&struct=auswahlBaum&nodeID=auswahlBaum%7Cabschluss%3Aabschl%3D84%2Cstgnr%3D1&expand=0&asi=" . $asi;
  91.     $seite = explode("\n", getsite($URL, "", "https://hisqis.hs-merseburg.de/qisserver/", false));
  92.  
  93. //Noten zählen
  94.     $counter = 0;
  95.     for ($i = 0; $i < count($seite); $i++) {
  96.         if (str_replace("bestanden", "", $seite[$i]) != $seite[$i] && str_replace("/QIS/images//his_info3.gif", "", $seite[$i - 3]) != $seite[$i - 3]) {
  97.             $counter++;
  98.             $index = trim($seite[$i - 11]);
  99.             while (isset($noten[$index])) {
  100.                 $index .= "_";
  101.             }
  102.             $noten[$index] = trim($seite[$i - 5]);
  103.             $credits[$index] = floatval(trim($seite[$i + 3]));
  104.         }
  105.     }
  106.  
  107.     $creditssumme = 0;
  108.     $gesamtsumme = 0;
  109.     $tabelle = "<table border='1'><tr><th>Fach</th><th>Note</th><th>Credits</th></tr>\n";
  110.     foreach ($noten as $key => $value) {
  111.         if ($credits[$key] != 0) {
  112.             $creditssumme += $credits[$key];
  113.             $gesamtsumme += $value * $credits[$key];
  114.             $tabelle .= "<tr><td>{$key}</td><td>{$value}</td><td>{$credits[$key]}</td></tr>\n";
  115.         }
  116.     }
  117.     $tabelle .= "</table><br><br>\n\n";
  118.  
  119.     $tabelle .= "<table border='1'><tr><th>Credits gesamt</th><th>Gesamtdurchschnitt</th></tr>\n";
  120.     $tabelle .= "<tr><td>{$creditssumme}</td><td>" . $gesamtsumme / $creditssumme . "</td></tr>\n";
  121.  
  122.     echo $tabelle;
  123. } else {
  124.     // login formular ?>
  125.     <!DOCTYPE html>
  126.     <html>
  127.     <head>
  128.         <meta charset="utf-8">
  129.         <meta http-equiv="X-UA-Compatible" content="IE=edge">
  130.         <title>Dirchnschnittsrechner (auto)</title>
  131.         <link rel="stylesheet" href="">
  132.     </head>
  133.     <body>
  134.         <form action="./durchschnitt_all.php" method="post" accept-charset="utf-8">
  135.             Nutzername: <input type="text" name="username" value="" placeholder="3kwagner" required><br />
  136.             Password: <input type="password" name="passwd" value="" placeholder="asdfghjk" required><br />
  137.             Matrikelnummer: <input type="text" name="matrikelnr" value="" placeholder="12345" required><br />
  138.             <input type="submit" name="submit" value="Durschnitt berechnen!"><br><br>
  139.             Hinweis: Mit den hier eingegebenen Daten wird sich das Script im HIS einloggen, deine Noten auslesen und dir anschließend deinen Durchschnitt anzeigen.<br>Die LogIn-Daten werden ausdrücklich <b>nicht</b> gespeichert!<br>
  140.             Benutzung auf eigene Gefahr!
  141.         </form>
  142.     </body>
  143.     </html>
  144.     <?php
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement