Webseite mit Login integrieren - WebUntis Stundenplan

Ich hab den Wunsch für den Nachwuchs den Webbasierten Stundenplan von Webuntis auf unserem zentralen IPS Tablet anzeigen zu lassen…

Ganz bequem, dachte ich mir, ich bemühe da mal ne KI - die gar nicht so schlecht war bis dato…

Hier das Skript das in eine HTMLBOX Variable schreibt.
Es kommt:

Anmeldung erfolgreich - Inhalt der Webseite nach Anmeldung : Webuntis You need to enable Javascript to run this app.

wie geht es hier weiter?..

Hier das KI Skript:

<?php
// IP-Symcon Skript für WebUntis Login, Inhaltsanzeige und Speicherung in Variable

// Definiere die Anmeldedaten und URL
$username = 'abc';
$password = 'efg';
$url = 'https://kephiso.webuntis.com/WebUntis/?school=SCHULE';

// ID der IP-Symcon Variable
$variableId = 33406;

// Initialisiere cURL-Sitzung
$ch = curl_init();

// Setze cURL-Optionen
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'j_username' => $username,
    'j_password' => $password,
    'school' => 'Max Weishaupt RS'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');

// Führe die Anfrage aus
$response = curl_exec($ch);

// Überprüfe auf Fehler
if(curl_errno($ch)) {
    $result = 'cURL-Fehler: ' . curl_error($ch);
} else {
    $result = "Anmeldung erfolgreich\n\n";
    
    // Hole den Inhalt der Hauptseite nach der Anmeldung
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, false);
    $content = curl_exec($ch);
    
    // Entferne HTML-Tags und füge den bereinigten Inhalt zum Ergebnis hinzu
    $cleanContent = strip_tags($content);
    $result .= "Inhalt der Webseite nach Anmeldung:\n\n" . $cleanContent;
}

// Schließe cURL-Sitzung
curl_close($ch);

// Speichere das Ergebnis in der IP-Symcon Variable
SetValue($variableId, $result);

echo "Ergebnis wurde in Variable $variableId gespeichert.";
?>



Dieses Projekt kennst du? GitHub - SchoolUtils/WebUntis: JavaScript WebUntis API Client Da werden einige Verfahren gegen die API beschrieben bzw. im Code verwendet.

Nö - aber das schau ich mir an… bei ioBroker hab ich dazu einige erfolgreiche Beispiele gesehen.
Also gehen tuts schon mal.

Danke für den LINK

Ich hab ein Ticket geöffnet.

Ich bin nun auf die bei Github verlinkte Seite gekommen.
https://webuntis.noim.me/

<?php
// WebUntis API Aufruf für IP-Symcon

// Konfiguration
$school = 'SChule';
$username = '1';
$password = '';
$server = 'kephiso.webuntis.com';

// API-Endpunkt
$url = "https://{$server}/WebUntis/jsonrpc.do?school=" . urlencode($school);

// Funktion zum Senden von API-Anfragen
function sendRequest($url, $method, $params, $sessionId = null) {
    $data = array(
        'id' => 'ID',
        'method' => $method,
        'params' => $params,
        'jsonrpc' => '2.0'
    );

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    if ($sessionId) {
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Cookie: JSESSIONID=' . $sessionId
        ));
    }
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    return array(
        'response' => json_decode($response, true),
        'httpCode' => $httpCode
    );
}

// Login
$loginResult = sendRequest($url, 'authenticate', array(
    'user' => $username,
    'password' => $password,
    'client' => 'IP-Symcon'
));

if (isset($loginResult['response']['error'])) {
    die('Login-Fehler: ' . $loginResult['response']['error']['message'] . ' (HTTP Code: ' . $loginResult['httpCode'] . ')');
}

$sessionId = $loginResult['response']['result']['sessionId'];
$personType = $loginResult['response']['result']['personType'];
$personId = $loginResult['response']['result']['personId'];

echo "Login erfolgreich. Person ID: $personId, Typ: $personType\n";

// Hole Stundenplan für heute
$today = date('Ymd');

$timetableResult = sendRequest($url, 'getTimegrid', array(
    'options' => array(
        'element' => array(
            'id' => $personId,
            'type' => $personType
        ),
        'startDate' => $today,
        'endDate' => $today,
        'showInfo' => true,
        'showSubstText' => true,
        'showLsText' => true,
        'showLsNumber' => true,
        'showStudentgroup' => true
    )
), $sessionId);

if (isset($timetableResult['response']['error'])) {
    die('Fehler beim Abrufen des Stundenplans: ' . $timetableResult['response']['error']['message'] . ' (HTTP Code: ' . $timetableResult['httpCode'] . ')');
}

// Verarbeite den Stundenplan
$timetable = array();
foreach ($timetableResult['response']['result'] as $lesson) {
    $startTime = substr($lesson['startTime'], 0, 2) . ':' . substr($lesson['startTime'], 2);
    $endTime = substr($lesson['endTime'], 0, 2) . ':' . substr($lesson['endTime'], 2);
    $subject = isset($lesson['su'][0]['name']) ? $lesson['su'][0]['name'] : 'N/A';
    $teacher = isset($lesson['te'][0]['name']) ? $lesson['te'][0]['name'] : 'N/A';
    $room = isset($lesson['ro'][0]['name']) ? $lesson['ro'][0]['name'] : 'N/A';

    $timetable[] = array(
        'Zeit' => "{$startTime} - {$endTime}",
        'Fach' => $subject,
        'Lehrer' => $teacher,
        'Raum' => $room
    );
}

// Erstelle HTML-Tabelle für den Stundenplan
$html = '<table border="1" style="border-collapse: collapse; width: 100%;">
         <tr style="background-color: #f2f2f2;">
         <th style="padding: 10px; text-align: left;">Zeit</th>
         <th style="padding: 10px; text-align: left;">Fach</th>
         <th style="padding: 10px; text-align: left;">Lehrer</th>
         <th style="padding: 10px; text-align: left;">Raum</th>
         </tr>';

foreach ($timetable as $lesson) {
    $html .= "<tr>
              <td style='padding: 8px; border: 1px solid #ddd;'>{$lesson['Zeit']}</td>
              <td style='padding: 8px; border: 1px solid #ddd;'>{$lesson['Fach']}</td>
              <td style='padding: 8px; border: 1px solid #ddd;'>{$lesson['Lehrer']}</td>
              <td style='padding: 8px; border: 1px solid #ddd;'>{$lesson['Raum']}</td>
              </tr>";
}

$html .= '</table>';

// Schreibe den HTML-Stundenplan in die IP-Symcon-Variable mit ID 33406
SetValue(33406, $html);

echo "Stundenplan für heute wurde als HTML in Variable 33406 gespeichert.";

// Logout
sendRequest($url, 'logout', array(), $sessionId);
?>

Es kommt sowohl bei gettimetable,gettimetablefortoday,gettimegrid diese Meldung:

Login erfolgreich. Person ID: 4639, Typ: 5
Fehler beim Abrufen des Stundenplans: no right for timetable (HTTP Code: 200)

Mal schauen…