<?php
// Konfiguration
$base_url = 'https://192.168.0.14:8080/remote/json.php';
$username = 'ispconfigremoteuser';
$password = 'secretpassword';
$client_id = 0;
$server_id = 1;
$domain_name = "mydomain.lan";
$adminmail = 'superadmin@intranet.lan';
$admin = 'admin';
$forwarders = array("abuse", "webmaster", "postmaster");
// SSL-Zertifikatsüberprüfung deaktivieren
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'ignore_errors' => true,
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
);
$context = stream_context_create($options);
// Login zur ISPConfig API
$login_payload = json_encode(array(
'username' => $username,
'password' => $password,
));
$login_response = file_get_contents("$base_url?login", false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => $login_payload,
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
)));
$login_result = json_decode($login_response, true);
$session_id = $login_result['response'];
if ($session_id) {
echo "Login erfolgreich: Session-ID: $session_id\n";
// Definieren der Weiterleitungen
$forwardings = array(
"$admin@$domain_name" => $adminmail,
);
// Weiterleitungen für abuse, webmaster, postmaster hinzufügen
foreach ($forwarders as $forwarder) {
$forwardings["$forwarder@$domain_name"] = "$admin@$domain_name";
}
foreach ($forwardings as $source => $destination) {
// Parameter für die Weiterleitung
$forward_payload = json_encode(array(
'session_id' => $session_id,
'client_id' => $client_id,
'params' => array(
'server_id' => $server_id,
'source' => $source,
'destination' => $destination,
'type' => 'forward',
'active' => 'y',
),
));
// Weiterleitung hinzufügen
$add_forward_response = file_get_contents("$base_url?mail_forward_add", false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => $forward_payload,
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
)));
$add_forward_result = json_decode($add_forward_response, true);
if ($add_forward_result['response']) {
echo "Weiterleitung $source -> $destination wurde erfolgreich angelegt.\n";
} else {
echo "Fehler beim Anlegen der Weiterleitung $source -> $destination.\n";
}
}
// Logout
$logout_payload = json_encode(array('session_id' => $session_id));
$logout_response = file_get_contents("$base_url?logout", false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => $logout_payload,
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
)));
$logout_result = json_decode($logout_response, true);
if ($logout_result['response']) {
echo "Logout erfolgreich.\n";
} else {
echo "Fehler beim Logout.\n";
}
} else {
echo "Login fehlgeschlagen.\n";
}