Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //about
- /*
- by -kw, 12.10.2016
- v2.5
- Dieses Script sollte etwa einmal die Stunde per Cron aufgerufen werden.
- Es sucht im HIS nach neuen Noten und sendet euch dann ggf. eine E-Mail.
- Das Script muss im Verzeichnis eine Datei anlegen können.
- Das Script wird nur im HIS der HS Merseburg funktionieren.
- Keine Haftung, Garantie, Gewährleistung und sonstiges. Benutzung auf eigene Gefahr.
- Sensible Daten sollten nicht auf Servern gespeichert werden!
- Changelog
- ---------
- v2:
- + Changed: suche nichtmehr alle 0,0, sondern prüfe jede Note einzeln
- + E-Mail mit Fach und Note
- + erkennt nun auch nicht bestandene Prüfungen
- + schickt eine Mail mit der Notenübersicht raus.
- */
- //config
- $mailto = "mail@example.com"; // E-Mail Adresse des zu Benachrichtigenden
- $mailto_uebersicht = "mail@example.com"; // E-Mail Adresse des zu Benachrichtigenden (Übersicht)
- $absender_mail = "mail@example.com"; // E-Mail des Absenders
- $absender = "Beispiel Name"; // Absendername
- $reply = "mail@example.com"; // Antwort an
- $username = ""; //Rechenzentrum Nutzername
- $passwd = ""; //Rechenzentrum Passwort
- $matrikelnr = ""; //Matrikelnummer
- //do not change from here
- date_default_timezone_set("Europe/Berlin");
- $savefile = "counter.txt";
- $cookies = "cookies.txt";
- if (!file_exists($cookies)) {
- file_put_contents($cookies, "");
- }
- $noten = array();
- $noten_old = array();
- $changed_marks = array();
- $old_counter = array();
- $new_marks = array();
- $mailtext = "Aktualisierte Notenübersicht:\n-----------------------------\n\n";
- $tabelle = "";
- function execute($ho, $state, $array, $newsess) {
- global $cookies;
- $log_hoster = $array;
- $ch = curl_init();
- $url = $log_hoster[$ho][0];
- $postdata = $log_hoster[$ho][1];
- $ref = $log_hoster[$ho][2];
- curl_setopt($ch, CURLINFO_HEADER_OUT, true);
- curl_setopt($ch, CURLOPT_AUTOREFERER, true);
- curl_setopt($ch, CURLOPT_COOKIE, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
- curl_setopt($ch, CURLOPT_COOKIESESSION, $newsess);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
- curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
- curl_setopt($ch, CURLOPT_REFERER, $ref);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
- $retu = curl_exec($ch);
- sleep(1);
- return $retu;
- }
- function getsite($zielurl, $postdata = "", $ref = "", $newsess = true) {
- $log_hoster = array(
- array($zielurl, $postdata, $ref),
- );
- $temp = execute(0, true, $log_hoster, $newsess);
- return $temp;
- }
- //einlogen
- $URL = "https://hisqis.hs-merseburg.de/qisserver/rds?state=user&type=1&category=auth.login&startpage=portal.vm";
- $seite = getsite($URL, "username=" . urlencode($username) . "&password=" . urlencode($passwd) . "&mtknr=" . urlencode($matrikelnr) . "&submit=%C2%A0Anmelden%C2%A0");
- //asi (SessionID) finden
- $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";
- $seite = explode("\n", getsite($URL, "", "https://hisqis.hs-merseburg.de/qisserver/", false));
- foreach ($seite as $key => $value) {
- if (str_replace("<a href=\"https://hisqis.hs-merseburg.de/qisserver/rds?state=notenspiegel", "", $value) != $value) {
- $start = strpos($value, "asi=");
- $cut = substr($value, $start + 4);
- $ende = strpos($cut, '"');
- $asi = substr($cut, 0, $ende);
- }
- }
- if (!isset($asi)) {
- exit();
- }
- //Noten abrufen
- $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;
- $seite = explode("\n", getsite($URL, "", "https://hisqis.hs-merseburg.de/qisserver/", false));
- //Noten zählen
- $counter = 0;
- for ($i = 0; $i < count($seite); $i++) {
- if (str_replace("bestanden", "", $seite[$i]) != $seite[$i] && str_replace("/QIS/images//his_info3.gif", "", $seite[$i - 3]) != $seite[$i - 3]) {
- $counter++;
- $index = trim($seite[$i - 11]);
- while (isset($noten[$index])) {
- $index .= "_";
- }
- $noten[$index] = trim($seite[$i - 5]);
- }
- }
- //alten Wert lesen/erzeugen
- if (file_exists($savefile)) {
- $old_counter = file_get_contents($savefile);
- $old_counter = explode("\n", $old_counter);
- if (count($old_counter) > 0) {
- foreach ($old_counter as $key => $value) {
- $tmparr = explode(" - ", $value);
- if (count($tmparr) > 1) {
- $noten_old[$tmparr[0]] = $tmparr[1];
- }
- }
- }
- } else {
- file_put_contents($savefile, "");
- }
- function comparearrays() {
- global $noten, $noten_old, $savefile, $tabelle, $changed_marks, $new_marks;
- $retu = false;
- if (count($noten) > 0) {
- foreach ($noten as $key => $value) {
- if (isset($noten_old[$key])) {
- if ($noten_old[$key] != $value) {
- //Note geändert
- $changed_marks[$key] = $value;
- $retu = true;
- }
- } else {
- //neue Note
- $new_marks[$key] = $value;
- $retu = true;
- }
- }
- }
- if ($retu) {
- if (count($changed_marks) > 0) {
- foreach ($changed_marks as $key => $value) {
- $tabelle .= "Geändert: " . $key . " - " . $value . "\n";
- }
- }
- if (count($new_marks) > 0) {
- foreach ($new_marks as $key => $value) {
- $tabelle .= "Neu: " . $key . " - " . $value . "\n";
- }
- }
- if (count($noten) > 0) {
- file_put_contents($savefile, "");
- foreach ($noten as $key => $value) {
- file_put_contents($savefile, $key . " - " . $value . "\n", FILE_APPEND);
- }
- }
- }
- return $retu;
- }
- //Vergleich, ggf. Mail
- if (comparearrays()) {
- mail($mailto, "Neue Note(n) online!", str_replace("\n", "<br />", htmlentities($mailtext)) . $tabelle, "Content-Type: text/html charset=\"iso-8859-1\"\r\n");
- if (isset($mailto_uebersicht) && trim($mailto_uebersicht) != "") {
- $message = "Hallo,\n\n im Anhang die aktualisierte Notenübersicht:\n\n";
- $message .= $tabelle . "\n\n\n";
- $message .= "Viele Grüße\n\nPS: Diese Mail wurde automatisch verschickt.";
- $message = htmlentities($message);
- $message = str_replace("\n", "<br />", $message);
- // Download der Übersicht
- $datei = "/tmp/Notenuebersicht_Studium_" . date("Y_m_d_H_i", time()) . ".pdf";
- $ch = curl_init("https://hisqis.hs-merseburg.de/qisserver/rds?state=hisreports&status=receive&publishid=0&vmfile=no&moduleCall=abschluss&lastState=notenspiegelStudent&finishedObj=Y&xslobject=de&asi=" . $asi);
- $zieldatei = fopen($datei, "w");
- curl_setopt($ch, CURLOPT_FILE, $zieldatei);
- curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
- curl_setopt($ch, CURLOPT_COOKIE, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
- curl_setopt($ch, CURLOPT_COOKIESESSION, false);
- curl_exec($ch);
- fclose($zieldatei);
- //mail versenden
- $name = basename($datei);
- $size = filesize($datei);
- $data = file_get_contents($datei);
- $type = mime_content_type($datei);
- $attachments[] = array("name" => $name, "size" => $size, "type" => $type, "data" => $data);
- $mime_boundary = "-----=" . md5(uniqid(mt_rand(), 1));
- $header = "From:" . $absender . "<" . $absender_mail . ">\n";
- $header .= "Reply-To: " . $reply . "\n";
- $header .= "MIME-Version: 1.0\r\n";
- $header .= "Content-Type: multipart/mixed;\r\n";
- $header .= " boundary=\"" . $mime_boundary . "\"\r\n";
- $content = "This is a multi-part message in MIME format.\r\n\r\n";
- $content .= "--" . $mime_boundary . "\r\n";
- $content .= "Content-Type: text/html charset=\"iso-8859-1\"\r\n";
- $content .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
- $content .= $message . "\r\n";
- //$anhang ist ein Mehrdimensionals Array
- //$anhang enthält mehrere Dateien
- if (is_array($attachments) && is_array(current($attachments))) {
- foreach ($attachments as $dat) {
- $data = chunk_split(base64_encode($dat['data']));
- $content .= "--" . $mime_boundary . "\r\n";
- $content .= "Content-Disposition: attachment;\r\n";
- $content .= "\tfilename=\"" . $dat['name'] . "\";\r\n";
- $content .= "Content-Length: ." . $dat['size'] . ";\r\n";
- $content .= "Content-Type: " . $dat['type'] . "; name=\"" . $dat['name'] . "\"\r\n";
- $content .= "Content-Transfer-Encoding: base64\r\n\r\n";
- $content .= $data . "\r\n";
- }
- $content .= "--" . $mime_boundary . "--";
- }
- mail($mailto_uebersicht, "Aktualisierter Notenspiegel", $content, $header);
- }
- }
Add Comment
Please, Sign In to add comment