loadComponent('Tools'); } private function query_to_var($string) { $arr = array(); $pairs = explode('&', $string); //debug($pairs); foreach ($pairs as $pair) { $parts = explode('=', $pair); $arr[urldecode($parts[0])] = urldecode($parts[1]); } return $arr; } private function get_string_between($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; $sub = substr($string, $ini, $len); $elem = explode(' ', $sub)[0]; return str_replace('"', '', $elem); } private function login_school($ch) { //$login_data = $this->request->session()->read('data'); $login_data = [ 'portal_username' => 'asd.trinkl', 'portal_password' => 'HiegTzs!182', ]; curl_setopt($ch, CURLOPT_URL, SCHULPORTAL_BASE_URL); $text = curl_exec($ch); $post = [ 'user_name' => $login_data['portal_username'], 'password' => $login_data['portal_password'], 'repository' => 'schulen.bayern.de', 'site_name' => 'schulportal', 'secure' => '1', 'resource_id' => '2', 'login_type' => '2', ]; curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); // Anmeldeformular fuer das Schulportal abschicken - Step 2 curl_setopt($ch, CURLOPT_URL, SCHULPORTAL_BASE_URL . '/InternalSite/Validate.asp'); $text = curl_exec($ch); } public function screen() { $this->set('path', $this->Tools->screen()); } public function trans() { if ($this->request->is('post')) { //debug($this->request); $string = $this->request['data']['string']; $arr = $this->query_to_var($string); $this->set('arr', $arr); } } public function showxml() { if ($this->request->is('post')) { //debug($this->request); $string = $this->request['data']['string']; echo($string); //$arr = $p = xml_parser_create(); //xml_parse_into_struct($p, $string, $vals, $index); //xml_parser_free($p); $vals = Xml::toArray(Xml::build($string)); //debug($vals); //debug($index); $this->set('arr', $vals); } } public function login() { if ($this->request->is('post')) { $post = $this->request['data']; $this->request->session()->write('data', $this->request['data']); debug($post); return $this->redirect(['action' => 'examine']); } } public function viva() { $schools = $this->Monitorings->find('all', array('conditions' => array('action' => 'lehrkap'))); $schools->select(['school']) ->distinct(['school']); foreach ($schools as $school) { $snr = $school->school; $vdata = $this->Monitorings->find('all', array('conditions' => array('action' => 'lehrkap', 'school' => $snr, 'comment' => 'vor Viva'))); $vdata->select(['data']); //debug($vdata->first()->data); $ndata = $this->Monitorings->find('all', array('conditions' => array('action' => 'lehrkap', 'school' => $snr, 'comment' => 'nach Viva'))); //debug($ndata->first()->data); $ndata->select(['data']); $data[$snr]['vor'] = $vdata->first()->data; $data[$snr]['nach'] = $ndata->first()->data; //debug($data); } $this->set('data', $data); } public function examine() { //$login_data = $this->request->session()->read('data'); if ($this->request->is('post')) { //debug($this->request->data['school_nr']);die; $login_data = [ 'asd_username' => 'A005_TrinklW', 'asd_password' => 'HiegTzs!12', ]; $school_nr = $this->request->data['school_nr']; //$school_nr = '0181'; $ch = $this->Tools->init_curl_params(); $this->login_school($ch); $text = $this->Tools->asd_curl($ch, '', array(), '/asddv/dv_xy_00.jsf'); $viewstate = $this->get_string_between($text, 'id="javax.faces.ViewState" value="', '" autocomplete'); $post = [ 'login:username' => $login_data['asd_username'], 'login:password' => $login_data['asd_password'], 'login' => 'login', 'javax.faces.ViewState' => $viewstate, 'login:loginButton' => 'login:loginButton', ]; $text = $this->Tools->asd_curl($ch, $post, array('Content-Type: application/x-www-form-urlencoded'), '/login/login.jsf'); $text = $this->Tools->asd_curl($ch, '', array(), '/asdus/us_01_01.jsf'); $viewstate = $this->get_string_between($text, 'id="javax.faces.ViewState" value="', '" autocomplete'); $conversationId = $this->get_string_between($text, 'name="conversationId" value="', '" />'); $post_basic = [ 'mainForm' => 'mainForm', 'referenzBaumAnzeigen' => 'false', 'mainForm:hasChanged' => 'false', 'mainForm:hasNotReleased' => 'false', 'mainForm:hasPopUpChanged' => 'false', 'mainForm:hasAdresseChanged' => 'false', 'mainForm:confirmedOverride' => 'false', 'mainForm:zuordnungNotification' => 'false', 'skipvalidation' => 'false', 'mainForm:istAnzeigeMaske' => 'false', ]; $post = [ 'changeNotification' => 'false', 'conversationId' => $conversationId, 'mainForm:dienststelle_schluessel' => $school_nr, 'mainForm:dienststelle_nameoffiziell' => '', 'mainForm:dienststelle_dst_wl_dsttyp_id_uebe' => 'EMPTY:0', 'mainForm:dienststelle_plzstrasse' => '', 'mainForm:dienststelle_ort' => '', 'mainForm:dienststelle_sat_kurz_bezeichnung' => 'EMPTY:0', 'mainForm:dienststelle_bdg_kurz_bezeichnung' => 'EMPTY:0', 'mainForm:dienststelle_wl_kurz_bezeichnung' => 'EMPTY:0', 'mainForm:dienststelle_dst_wl_regierung_id_u' => 'EMPTY:0', 'mainForm:dienststelle_dst_wl_schulamt_id' => 'EMPTY:0', 'mainForm:dienststelle_referent' => '', 'mainForm:dienststelle_dst_wl_mb_bezirk_id_u' => 'EMPTY:0', 'mainForm:dienststelle_status' => 'EMPTY:0', 'mainForm:dienststelle_sortierung' => 'com.hp.asd.domain.tech.PersProperty:7', 'mainForm:action_suchen' => 'Suchen', 'javax.faces.ViewState' => $viewstate, ]; $text = $this->Tools->asd_curl($ch, array_merge($post_basic, $post), array('Content-Type: application/x-www-form-urlencoded'), '/asdus/us_01_01.jsf?cid=' . $conversationId); $viewstate = $this->get_string_between($text, 'id="javax.faces.ViewState" value="', '" autocomplete'); $conversationId = $this->get_string_between($text, 'name="conversationId" value="', '" />'); $post = [ 'changeNotification' => 'false', 'conversationId' => $conversationId, 'mainForm:resultTable:0:email' => '0001@schulen.bayern.de', 'mainForm:resultTable:0:j_idt112' => 'on', 'javax.faces.ViewState' => $viewstate, 'mainForm:resultTable:0:dienststelle_nameoffiziell' => 'mainForm:resultTable:0:dienststelle_nameoffiziell', ]; $text = $this->Tools->asd_curl($ch, array_merge($post_basic, $post), array('Content-Type: application/x-www-form-urlencoded'), '/asdus/us_01_02.jsf?cid=' . $conversationId); //debug($text);die; //$output = $this->Tools->asd_basic($text); //$this->set('output', $output); $viewstate = $this->get_string_between($text, 'id="javax.faces.ViewState" value="', '" autocomplete'); $conversationId = $this->get_string_between($text, 'name="conversationId" value="', '" />'); $mask = $this->get_string_between($text, '/uniquesig0/asd/asdus/', '.jsf?cid='); //debug($mask); //debug($text);die; $post = [ 'conversationId' => $conversationId, 'changeNotification' => 'true', 'mainForm:schulnummer' => $school_nr, 'mainForm:schule' => 'Leibniz-Gymnasium+Altdorf', 'mainForm:schulstellePlzStrasse' => 'Gymnasium', 'mainForm:lehrkapazitaet' => 'Lehrkapazit%C3%A4t', 'mainForm:erhebungsinformationskommentar' => '', 'mainForm:statusaenderungen_kommentar' => '', 'javax.faces.ViewState' => $viewstate, ]; if ($mask == 'us_01_10') { $schooltype = 'gms'; $schuleSelect = $this->get_string_between($text, 'name="mainForm:schuleSelect" class="w100p" size="1" onchange="submit()">