<?php if (!isset($_POST) || empty($_POST)) { echo 'Aucune donnée envoyée !'; exit; } require 'API.php'; include_once '_cgGlobal.php'; $domains = explode(PHP_EOL, $_POST['domains']); $mail_servers = $_POST['servers']; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); foreach ($domains as $domain) { /* Suppression des anciens MX */ $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'MX')); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); } } /* Ajout des nouveaux MX */ if ($mail_servers[0]) { $mail_servers[0]['server'] = 'mail.' . $domain; } foreach ($mail_servers as $mx) { if ($mx) { $api->post('/domain/zone/' . $domain . '/record', array('fieldType' => 'MX', 'ttl' => 0, 'target' => $mx['priority'] . ' ' . $mx['server'] . '.')); } } }
} require 'API.php'; include_once 'c_cgGlobal.php'; $targets = $_POST['datas']; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); foreach ($targets as $target) { $FQDN = $target['fqdn']; $ips = $target['ips']; preg_match_all("#^((([a-zA-Z0-9-_]+\\.)*[a-zA-Z0-9-_]+)\\.)?([a-zA-Z0-9-_]+\\.[a-zA-Z]{2,})\$#", $FQDN, $matches); $domain = $matches[4][0]; $subDomain = $matches[2][0]; /* Suppression de l'enregistrement du domaine */ if (strlen($subDomain)) { $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'CNAME', 'subDomain' => $subDomain)); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); } } $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'A', 'subDomain' => $subDomain)); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); } } } /* Ajout des nouveau sous-domaine */ foreach (explode(PHP_EOL, $ips) as $ip) { $api->post('/domain/zone/' . $domain . '/record', array('fieldType' => 'A', 'ttl' => 0, 'subDomain' => $subDomain, 'target' => $ip)); } }
foreach ($targets as $target) { $FQDN = $target['domain']; $target = $target['target']; preg_match_all("#^((([a-zA-Z0-9-_]\\-+\\.)*[a-zA-Z0-9-\\-_]+)\\.)?([a-zA-Z0-9\\-_]+\\.[a-zA-Z]{2,})\$#", $FQDN, $matches); $domain = $matches[4][0]; $subDomain = $matches[2][0]; if (strlen($subDomain)) { /* Suppression d'une possible redirection existante */ $current = $api->get('/domain/zone/' . $domain . '/redirection', array('subDomain' => $subDomain)); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/redirection/' . $id); } } /* Suppressions des champs existant sur le domaine */ $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'CNAME', 'subDomain' => $subDomain)); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); } } $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'A', 'subDomain' => $subDomain)); if (count($current)) { foreach ($current as $id) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); } } } /* Ajout de la nouvelle redirection */ $api->post('/domain/zone/' . $domain . '/redirection', array('subDomain' => $subDomain, 'target' => $target, 'type' => 'visiblePermanent')); }
foreach ($ips as $key => $ip) { $subDomains[$key] = preg_replace('#^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#', '$4-$3-$2-$1.dsl', $ip); if (strlen($subDomains[$key])) { $current = $api->get('/domain/zone/' . $domain . '/record', array('fieldType' => 'A', 'subDomain' => $subDomains[$key])); $deleted = false; if (count($current)) { foreach ($current as $id) { $details = $api->get('/domain/zone/' . $domain . '/record/' . $id); if (!(isset($details->target) && $details->target == $ip)) { $api->delete('/domain/zone/' . $domain . '/record/' . $id); $deleted = true; } } } else { $deleted = true; } if ($deleted) { $api->post('/domain/zone/' . $domain . '/record', array('fieldType' => 'A', 'subDomain' => $subDomains[$key], 'target' => $ip, 'ttl' => 0)); } } } $api->post('/domain/zone/' . $domain . '/refresh'); sleep(10); foreach ($ips as $key => $ip) { if (strlen($subDomains[$key])) { $response = $api->post('/ip/' . $ip . '/reverse', array('ipReverse' => $ip, 'reverse' => $subDomains[$key] . '.' . $domain)); if (isset($response->message)) { echo $response->message . '<br />'; } } }
<?php if (!isset($_POST) || empty($_POST)) { echo 'Aucune donnée envoyée !'; exit; } require 'API.php'; include_once '_cgGlobal.php'; $status = isset($_POST['on']); $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); $services = $api->get('/xdsl'); if (is_array($services)) { foreach ($services as $service) { $api->post('/xdsl/' . $service . '/ipv6', array('enabled' => !$status)); $api->post('/xdsl/' . $service . '/ipv6', array('enabled' => $status)); } }