$value = 0; for ($i = count($array) - 1; $i >= 0; $i--) { $curr = $array[$i]->value; if ($curr) { $coef = 1 / ($i + 1); $value += $curr * $coef; $totalCoef += $coef; } } return $totalCoef ? $value / $totalCoef : 0; } set_time_limit(180); $start = microtime(); require 'API.php'; include_once '_cgGlobal.php'; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); try { include '../cti/database.conf'; $db = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password); } catch (Exception $ex) { echo 'Impossible de se connecter à la base de données'; exit; } $request = $db->query('SELECT * FROM xdslConfig'); $config = $request->fetch(); if (!$config) { echo 'Impossible de se récupérer la config'; exit; } if ($config['ignoredBoxes']) { $config['ignoredBoxes'] = json_decode($config['ignoredBoxes']);
// Si le fichier de cache existe $time = filemtime($file); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $time) { header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304); exit; } if ($time > strtotime('-12 hours')) { header("Last-Modified: " . gmdate('r', $time)); echo file_get_contents($file); exit; } } $f = fopen($file, 'w+'); require 'API.php'; include_once '_cgGlobal.php'; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); $services = $api->get('/xdsl'); $return = array(); foreach ($services as $service) { $infos = $api->get('/xdsl/' . $service); $return[] = array('id' => $service, 'description' => isset($infos->description) ? $infos->description : $service); } fwrite($f, json_encode($return)); fclose($f); header("Last-Modified: " . gmdate('r', filemtime($file))); echo file_get_contents($file); exit; } else { // Récupération de la configuration echo json_encode($db->query('SELECT ignoredBoxes, email, startNotify, stopNotify, pingWarn, pingDanger, syncDiff FROM xdslConfig')->fetch(PDO::FETCH_ASSOC)); exit;
<?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'] . '.')); } } }
session_start(); include "OvhApi.php"; //Your app secret keys ;) $AK = "***********************"; $AS = "***********************"; $myOut = ""; //User doesn't ask something, so menu or connect if (!isset($_SESSION["ck"])) { $myAccess = '{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}]}'; OvhApi::getCredential($AK, OvhApi::$roots["ovh-eu"], $myAccess, false); } else { if (isset($_GET["ask"])) { switch ($_GET["ask"]) { case "get-domains": $myOvh = new OvhApi(OvhApi::$roots["ovh-eu"], $AK, $AS, false); $myOut = $myOvh->get("/domain"); break; } } } ?> <html> <head> <title>OvhApi</title> </head> <body> <h1>OvhApi by <a href="https://github.com/Servuc">@Servuc</a></h1> <?php if (is_array($myOut)) {
<?php if (!isset($_POST) || empty($_POST)) { echo 'Aucune donnée envoyée !'; exit; } 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); } } }
while ($bytes / 1000 >= 1) { $bytes = $bytes / 1000; $unitCount++; } return round($bytes, 2) . $units[$unitCount]; } try { include '../cti/database.conf'; $db = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password); } catch (Exception $ex) { echo 'Impossible de se connecter à la base de données'; exit; } require 'API.php'; include_once '_cgGlobal.php'; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); $all = $db->query('SELECT * FROM xdslErrors')->fetchAll(PDO::FETCH_ASSOC); foreach ($all as $datas) { $infos = $api->get('/xdsl/' . $datas['service']); if (isset($infos->description)) { $description = $infos->description; } else { $description = $datas['service']; } echo '<div class="col-sm-4"><div class="panel panel-primary"><div class="panel-heading">' . $description . ' (' . date('j/n G:i', strtotime($datas['detectedTime'])) . ')<button type="button" class="close" data-dismiss="panel" data-service="' . $datas['service'] . '" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="panel-body" style="min-height: 130px;">'; foreach (json_decode($datas['errors']) as $error) { echo $error . '<br/>'; } echo '</div></div></div>'; } /*
} $_POST['ips'] = str_replace("\r\n", "\n", $_POST['ips']); foreach (explode("\n", $_POST['ips']) as $ip) { if (preg_match("#^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\$#", $ip)) { $ips[] = $ip; } else { echo $ip . " n'est pas une IP valide !\n"; } } if (!isset($ips)) { echo "Aucune IP valide n'a été entrée\n"; exit; } $domain = "transacom.fr"; $subDomains = array(); $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); 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;
<?php session_start(); include "OvhApi.php"; //Your app secret keys ;) $AK = "***********************"; $AS = "***********************"; //Enough parameters if ($argc >= 2) { //First is used to choose what we will done switch ($argv[1]) { case "-g": //You MUST do this the first time $myAccess = '{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}]}'; OvhApi::getCredential($AK, OvhApi::$roots["ovh-eu"], $myAccess); break; case "-d": $myOvh = new OvhApi(OvhApi::$roots["ovh-eu"], $AK, $AS); print_r($myOvh->get("/domain")); break; } echo "\n"; } else { echo "Usage : " . $argv[0] . " option\n"; }
<?php if (!isset($_POST) || empty($_POST)) { echo 'Aucune donnée envoyée !'; exit; } require 'API.php'; include_once '_cgGlobal.php'; $targets = $_POST['datas']; $api = new OvhApi(OVH_API_EU, A_KEY, A_SECRET, C_KEY); 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); } }
<?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)); } }