From 79f2e8ee799c7237cb94d37f1a38783477050048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Beli=C3=ABn?= Date: Sat, 27 Jan 2018 18:30:10 +0100 Subject: [PATCH] Apply fixes from StyleCI (#12) --- index.php | 1 + public/alert-xhr.php | 65 ++++---- public/cloud-xhr.php | 236 +++++++++++++-------------- public/cloud.php | 114 +++++++------ public/index.php | 3 +- public/vps-xhr.php | 374 +++++++++++++++++++++---------------------- public/vps.php | 93 ++++++----- 7 files changed, 462 insertions(+), 424 deletions(-) diff --git a/index.php b/index.php index 1bf19d0..19ef8bd 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ get('/status/task'); -$result = array(); +$result = []; foreach ($status as $s) { - if (isset($_GET['cloud']) && $s['project'] !== 'PublicCloud') { - continue; - } - if (isset($_GET['vps']) && $s['project'] !== 'VPS') { - continue; - } - - if ($s['project'] === 'PublicCloud') { - if (!isset($result[$s['impactedService']])) { - $result[$s['impactedService']] = array(); + if (isset($_GET['cloud']) && $s['project'] !== 'PublicCloud') { + continue; } - if (!isset($result[$s['impactedService']][$s['uuid']])) { - $result[$s['impactedService']][$s['uuid']] = array( - 'status' => NULL, - 'alerts' => array() - ); + if (isset($_GET['vps']) && $s['project'] !== 'VPS') { + continue; } - $result[$s['impactedService']][$s['uuid']]['alerts'][] = $s; + if ($s['project'] === 'PublicCloud') { + if (!isset($result[$s['impactedService']])) { + $result[$s['impactedService']] = []; + } + if (!isset($result[$s['impactedService']][$s['uuid']])) { + $result[$s['impactedService']][$s['uuid']] = [ + 'status' => null, + 'alerts' => [], + ]; + } + + $result[$s['impactedService']][$s['uuid']]['alerts'][] = $s; - switch ($s['status']) { + switch ($s['status']) { case 'planned': if ($result[$s['impactedService']][$s['uuid']]['status'] !== 'inProgress') { - $result[$s['impactedService']][$s['uuid']]['status'] = 'planned'; + $result[$s['impactedService']][$s['uuid']]['status'] = 'planned'; } break; case 'inProgress': @@ -42,24 +43,24 @@ break; case 'finished': if ($result[$s['impactedService']][$s['uuid']]['status'] !== 'inProgress' && $result[$s['impactedService']][$s['uuid']]['status'] !== 'planned') { - $result[$s['impactedService']][$s['uuid']]['status'] = 'finished'; + $result[$s['impactedService']][$s['uuid']]['status'] = 'finished'; } break; } - } else { - if (!isset($result[$s['impactedService']])) { - $result[$s['impactedService']] = array( - 'status' => NULL, - 'alerts' => array() - ); - } + } else { + if (!isset($result[$s['impactedService']])) { + $result[$s['impactedService']] = [ + 'status' => null, + 'alerts' => [], + ]; + } - $result[$s['impactedService']]['alerts'][] = $s; + $result[$s['impactedService']]['alerts'][] = $s; - switch ($s['status']) { + switch ($s['status']) { case 'planned': if ($result[$s['impactedService']]['status'] !== 'inProgress') { - $result[$s['impactedService']]['status'] = 'planned'; + $result[$s['impactedService']]['status'] = 'planned'; } break; case 'inProgress': @@ -67,11 +68,11 @@ break; case 'finished': if ($result[$s['impactedService']]['status'] !== 'inProgress' && $result[$s['impactedService']]['status'] !== 'planned') { - $result[$s['impactedService']]['status'] = 'finished'; + $result[$s['impactedService']]['status'] = 'finished'; } break; } - } + } } echo json_encode($result); diff --git a/public/cloud-xhr.php b/public/cloud-xhr.php index 6725cca..00ea522 100644 --- a/public/cloud-xhr.php +++ b/public/cloud-xhr.php @@ -12,157 +12,157 @@ * */ if (isset($_GET['cpu'])) { - $result = array(); - - $project = json_decode(file_get_contents($cache)); - foreach ($project as $p) { - $result[$p->project_id] = array(); - foreach ($p->instances as $i) { - try { - $max = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', array('period' => 'today', 'type' => 'cpu:max')); - $used = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', array('period' => 'today', 'type' => 'cpu:used')); - - $lastMax = array_pop($max['values']); - $lastUsed = array_pop($used['values']); - - $prevUsed = array_pop($used['values']); - $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); - - if ($lastMax['value'] > 0) { - $result[$p->project_id][$i->id] = array($lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status); - } else { - $result[$p->project_id][$i->id] = 'Max value = 0'; + $result = []; + + $project = json_decode(file_get_contents($cache)); + foreach ($project as $p) { + $result[$p->project_id] = []; + foreach ($p->instances as $i) { + try { + $max = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', ['period' => 'today', 'type' => 'cpu:max']); + $used = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', ['period' => 'today', 'type' => 'cpu:used']); + + $lastMax = array_pop($max['values']); + $lastUsed = array_pop($used['values']); + + $prevUsed = array_pop($used['values']); + $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); + + if ($lastMax['value'] > 0) { + $result[$p->project_id][$i->id] = [$lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status]; + } else { + $result[$p->project_id][$i->id] = 'Max value = 0'; + } + } catch (Exception $e) { + $result[$p->project_id][$i->id] = $e->getMessage(); + } } - } catch (Exception $e) { - $result[$p->project_id][$i->id] = $e->getMessage(); - } } - } - echo json_encode($result); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['cpu-chart'], $_GET['project'], $_GET['instance'])) { - $result = array(); +elseif (isset($_GET['cpu-chart'], $_GET['project'], $_GET['instance'])) { + $result = []; - try { - $max = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', array('period' => 'lastweek', 'type' => 'cpu:max')); - $used = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', array('period' => 'lastweek', 'type' => 'cpu:used')); + try { + $max = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', ['period' => 'lastweek', 'type' => 'cpu:max']); + $used = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', ['period' => 'lastweek', 'type' => 'cpu:used']); - $values = array(); - foreach ($max['values'] as $v) { - $values[] = array( + $values = []; + foreach ($max['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $max['values'] = $values; + 'y' => $v['value'], + ]; + } + $max['values'] = $values; - $values = array(); - foreach ($used['values'] as $v) { - $values[] = array( + $values = []; + foreach ($used['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $used['values'] = $values; + 'y' => $v['value'], + ]; + } + $used['values'] = $values; - $result[] = array('max' => $max, 'used' => $used); - } catch (Exception $e) { - $result[] = $e->getMessage(); - } + $result[] = ['max' => $max, 'used' => $used]; + } catch (Exception $e) { + $result[] = $e->getMessage(); + } - echo json_encode($result); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['ram'])) { - $result = array(); - - $project = json_decode(file_get_contents($cache)); - foreach ($project as $p) { - $result[$p->project_id] = array(); - foreach ($p->instances as $i) { - try { - $max = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', array('period' => 'today', 'type' => 'mem:max')); - $used = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', array('period' => 'today', 'type' => 'mem:used')); - - $lastMax = array_pop($max['values']); - $lastUsed = array_pop($used['values']); - - $prevUsed = array_pop($used['values']); - $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); - - if ($lastMax['value'] > 0) { - $result[$p->project_id][$i->id] = array($lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status); - } else { - $result[$p->project_id][$i->id] = 'Max value = 0'; +elseif (isset($_GET['ram'])) { + $result = []; + + $project = json_decode(file_get_contents($cache)); + foreach ($project as $p) { + $result[$p->project_id] = []; + foreach ($p->instances as $i) { + try { + $max = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', ['period' => 'today', 'type' => 'mem:max']); + $used = $ovh->get('/cloud/project/'.$p->project_id.'/instance/'.$i->id.'/monitoring', ['period' => 'today', 'type' => 'mem:used']); + + $lastMax = array_pop($max['values']); + $lastUsed = array_pop($used['values']); + + $prevUsed = array_pop($used['values']); + $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); + + if ($lastMax['value'] > 0) { + $result[$p->project_id][$i->id] = [$lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status]; + } else { + $result[$p->project_id][$i->id] = 'Max value = 0'; + } + } catch (Exception $e) { + $result[$p->project_id][$i->id] = $e->getMessage(); + } } - } catch (Exception $e) { - $result[$p->project_id][$i->id] = $e->getMessage(); - } } - } - echo json_encode($result); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['ram-chart'], $_GET['project'], $_GET['instance'])) { - $result = array(); +elseif (isset($_GET['ram-chart'], $_GET['project'], $_GET['instance'])) { + $result = []; - try { - $max = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', array('period' => 'lastweek', 'type' => 'mem:max')); - $used = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', array('period' => 'lastweek', 'type' => 'mem:used')); + try { + $max = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', ['period' => 'lastweek', 'type' => 'mem:max']); + $used = $ovh->get('/cloud/project/'.$_GET['project'].'/instance/'.$_GET['instance'].'/monitoring', ['period' => 'lastweek', 'type' => 'mem:used']); - $values = array(); - foreach ($max['values'] as $v) { - $values[] = array( + $values = []; + foreach ($max['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $max['values'] = $values; + 'y' => $v['value'], + ]; + } + $max['values'] = $values; - $values = array(); - foreach ($used['values'] as $v) { - $values[] = array( + $values = []; + foreach ($used['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $used['values'] = $values; + 'y' => $v['value'], + ]; + } + $used['values'] = $values; - $result[] = array('max' => $max, 'used' => $used); - } catch (Exception $e) { - $result[] = $e->getMessage(); - } + $result[] = ['max' => $max, 'used' => $used]; + } catch (Exception $e) { + $result[] = $e->getMessage(); + } - echo json_encode($result); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_REQUEST['info'], $_REQUEST['project'], $_REQUEST['instance'])) { - $json = json_decode(file_get_contents($cache)); - $instance = NULL; - foreach ($json as $j) { - if ($j->project_id === $_REQUEST['project']) { - foreach ($j->instances as $i) { - if ($i->id === $_REQUEST['instance']) { - $instance = $i; - break; +elseif (isset($_REQUEST['info'], $_REQUEST['project'], $_REQUEST['instance'])) { + $json = json_decode(file_get_contents($cache)); + $instance = null; + foreach ($json as $j) { + if ($j->project_id === $_REQUEST['project']) { + foreach ($j->instances as $i) { + if ($i->id === $_REQUEST['instance']) { + $instance = $i; + break; + } + } } - } } - } - if (!is_null($instance)) { -?> + if (!is_null($instance)) { + ?> @@ -171,16 +171,20 @@ -monthlyBilling)) { ?> +monthlyBilling)) { + ?> - + - +
monthlyBilling->since))) ?>
get('/cloud/project'); - foreach ($project as $p) { - $current = $ovh->get('/cloud/project/'.$p); + $project = $ovh->get('/cloud/project'); + foreach ($project as $p) { + $current = $ovh->get('/cloud/project/'.$p); - $instances = array(); - $instance = $ovh->get('/cloud/project/'.$p.'/instance'); - foreach ($instance as $i) { - try { - $i['flavor'] = $ovh->get('/cloud/project/'.$p.'/flavor/'.$i['flavorId']); - $i['image'] = $ovh->get('/cloud/project/'.$p.'/image/'.$i['imageId']); - } catch (Exception $e) { - $errors[] = $e->getMessage(); - } + $instances = []; + $instance = $ovh->get('/cloud/project/'.$p.'/instance'); + foreach ($instance as $i) { + try { + $i['flavor'] = $ovh->get('/cloud/project/'.$p.'/flavor/'.$i['flavorId']); + $i['image'] = $ovh->get('/cloud/project/'.$p.'/image/'.$i['imageId']); + } catch (Exception $e) { + $errors[] = $e->getMessage(); + } - $instances[] = $i; - } + $instances[] = $i; + } - $current['instances'] = $instances; + $current['instances'] = $instances; - $volumes = array(); - $volume = $ovh->get('/cloud/project/'.$p.'/volume'); - foreach ($volume as $v) { - $volumes[] = $v; - } + $volumes = []; + $volume = $ovh->get('/cloud/project/'.$p.'/volume'); + foreach ($volume as $v) { + $volumes[] = $v; + } - $current['volumes'] = $volumes; + $current['volumes'] = $volumes; - $json[] = $current; - } + $json[] = $current; + } - if (!file_exists('../cache') || !is_dir('../cache')) { mkdir('../cache'); } - file_put_contents($cache, json_encode($json, JSON_PRETTY_PRINT)); + if (!file_exists('../cache') || !is_dir('../cache')) { + mkdir('../cache'); + } + file_put_contents($cache, json_encode($json, JSON_PRETTY_PRINT)); } ?> @@ -68,7 +70,7 @@ + ?>

Project « description ?> »
project_id ?>

@@ -94,15 +96,15 @@ -instances as $index => $i) { ?> +instances as $index => $i) { + ?> volumes as $v) { - if (in_array($i->id, $v->attachedTo)) { - $instanceVolumes[] = $v; - } - } -?> + $instanceVolumes = []; + foreach ($p->volumes as $v) { + if (in_array($i->id, $v->attachedTo)) { + $instanceVolumes[] = $v; + } + } ?> @@ -127,20 +131,24 @@ - + - + - + 1) { - for ($k = 1; $k < count($instanceVolumes); $k++) { -?> + for ($k = 1; $k < count($instanceVolumes); $k++) { + ?> @@ -149,10 +157,10 @@ - + } + } ?> + @@ -167,13 +175,17 @@ } ?>
- + - +
    diff --git a/public/index.php b/public/index.php index cac68d4..08e0043 100644 --- a/public/index.php +++ b/public/index.php @@ -1,3 +1,4 @@ infos->status, array('expired', 'unPaid'))) { - continue; - } + $vps = json_decode(file_get_contents($cache)); + foreach ($vps as $v) { + if (in_array($v->infos->status, ['expired', 'unPaid'])) { + continue; + } - $status = $ovh->get('/vps/'.$v->name.'/status'); + $status = $ovh->get('/vps/'.$v->name.'/status'); - $result[$v->name] = $status; - } + $result[$v->name] = $status; + } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['disk'])) { - $result = array(); - - $vps = json_decode(file_get_contents($cache)); - foreach ($vps as $v) { - if (in_array($v->infos->status, array('expired', 'unPaid'))) { - continue; - } +elseif (isset($_GET['disk'])) { + $result = []; - $result[$v->name] = array(); + $vps = json_decode(file_get_contents($cache)); + foreach ($vps as $v) { + if (in_array($v->infos->status, ['expired', 'unPaid'])) { + continue; + } - $disks = $ovh->get('/vps/'.$v->name.'/disks'); - foreach ($disks as $i => $d) { - try { - $max = $ovh->get('/vps/'.$v->name.'/disks/'.$d.'/use', array('type' => 'max')); - $used = $ovh->get('/vps/'.$v->name.'/disks/'.$d.'/use', array('type' => 'used')); - - if ($max['value'] > 0) { - $result[$v->name][] = array($used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)); - } else { - $result[$v->name][] = 'Max value = 0'; + $result[$v->name] = []; + + $disks = $ovh->get('/vps/'.$v->name.'/disks'); + foreach ($disks as $i => $d) { + try { + $max = $ovh->get('/vps/'.$v->name.'/disks/'.$d.'/use', ['type' => 'max']); + $used = $ovh->get('/vps/'.$v->name.'/disks/'.$d.'/use', ['type' => 'used']); + + if ($max['value'] > 0) { + $result[$v->name][] = [$used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)]; + } else { + $result[$v->name][] = 'Max value = 0'; + } + } catch (Exception $e) { + $result[$v->name][] = $e->getMessage(); + } } - } catch (Exception $e) { - $result[$v->name][] = $e->getMessage(); - } } - } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['disk-chart'], $_GET['vps'])) { - $result = array(); +elseif (isset($_GET['disk-chart'], $_GET['vps'])) { + $result = []; - $disks = $ovh->get('/vps/'.$_GET['vps'].'/disks'); - foreach ($disks as $i => $d) { - try { - $max = $ovh->get('/vps/'.$_GET['vps'].'/disks/'.$d.'/monitoring', array('period' => 'lastweek', 'type' => 'max')); - $used = $ovh->get('/vps/'.$_GET['vps'].'/disks/'.$d.'/monitoring', array('period' => 'lastweek', 'type' => 'used')); + $disks = $ovh->get('/vps/'.$_GET['vps'].'/disks'); + foreach ($disks as $i => $d) { + try { + $max = $ovh->get('/vps/'.$_GET['vps'].'/disks/'.$d.'/monitoring', ['period' => 'lastweek', 'type' => 'max']); + $used = $ovh->get('/vps/'.$_GET['vps'].'/disks/'.$d.'/monitoring', ['period' => 'lastweek', 'type' => 'used']); - $values = array(); - foreach ($max['values'] as $v) { - $values[] = array( + $values = []; + foreach ($max['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $max['values'] = $values; - - $values = array(); - foreach ($used['values'] as $v) { - $values[] = array( + 'y' => $v['value'], + ]; + } + $max['values'] = $values; + + $values = []; + foreach ($used['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $used['values'] = $values; - - $result[] = array('max' => $max, 'used' => $used); - } catch (Exception $e) { - $result[] = $e->getMessage(); + 'y' => $v['value'], + ]; + } + $used['values'] = $values; + + $result[] = ['max' => $max, 'used' => $used]; + } catch (Exception $e) { + $result[] = $e->getMessage(); + } } - } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['cpu'])) { - $result = array(); +elseif (isset($_GET['cpu'])) { + $result = []; - $vps = json_decode(file_get_contents($cache)); - foreach ($vps as $v) { - if (in_array($v->infos->status, array('expired', 'unPaid'))) { - continue; - } + $vps = json_decode(file_get_contents($cache)); + foreach ($vps as $v) { + if (in_array($v->infos->status, ['expired', 'unPaid'])) { + continue; + } - try { - if (substr($v->model->version, 0, 4) === '2014') { - $max = $ovh->get('/vps/'.$v->name.'/use', array('type' => 'cpu:max')); - $used = $ovh->get('/vps/'.$v->name.'/use', array('type' => 'cpu:used')); + try { + if (substr($v->model->version, 0, 4) === '2014') { + $max = $ovh->get('/vps/'.$v->name.'/use', ['type' => 'cpu:max']); + $used = $ovh->get('/vps/'.$v->name.'/use', ['type' => 'cpu:used']); - $result[$v->name] = array($used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)); - } else { - $max = $ovh->get('/vps/'.$v->name.'/monitoring', array('period' => 'today', 'type' => 'cpu:max')); - $used = $ovh->get('/vps/'.$v->name.'/monitoring', array('period' => 'today', 'type' => 'cpu:used')); + $result[$v->name] = [$used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)]; + } else { + $max = $ovh->get('/vps/'.$v->name.'/monitoring', ['period' => 'today', 'type' => 'cpu:max']); + $used = $ovh->get('/vps/'.$v->name.'/monitoring', ['period' => 'today', 'type' => 'cpu:used']); - $lastMax = array_pop($max['values']); - $lastUsed = array_pop($used['values']); + $lastMax = array_pop($max['values']); + $lastUsed = array_pop($used['values']); - $prevUsed = array_pop($used['values']); - $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); + $prevUsed = array_pop($used['values']); + $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); - $result[$v->name] = array($lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status); - } - } catch (Exception $e) { - $result[$v->name] = $e->getMessage(); + $result[$v->name] = [$lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status]; + } + } catch (Exception $e) { + $result[$v->name] = $e->getMessage(); + } } - } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['cpu-chart'], $_GET['vps'])) { - $result = array(); +elseif (isset($_GET['cpu-chart'], $_GET['vps'])) { + $result = []; - try { - $max = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', array('period' => 'lastweek', 'type' => 'cpu:max')); - $used = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', array('period' => 'lastweek', 'type' => 'cpu:used')); + try { + $max = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', ['period' => 'lastweek', 'type' => 'cpu:max']); + $used = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', ['period' => 'lastweek', 'type' => 'cpu:used']); - $values = array(); - foreach ($max['values'] as $v) { - $values[] = array( + $values = []; + foreach ($max['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $max['values'] = $values; + 'y' => $v['value'], + ]; + } + $max['values'] = $values; - $values = array(); - foreach ($used['values'] as $v) { - $values[] = array( + $values = []; + foreach ($used['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $used['values'] = $values; + 'y' => $v['value'], + ]; + } + $used['values'] = $values; - $result[] = array('max' => $max, 'used' => $used); - } catch (Exception $e) { - $result[] = $e->getMessage(); - } + $result[] = ['max' => $max, 'used' => $used]; + } catch (Exception $e) { + $result[] = $e->getMessage(); + } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['ram'])) { - $result = array(); +elseif (isset($_GET['ram'])) { + $result = []; - $vps = json_decode(file_get_contents($cache)); - foreach ($vps as $v) { - if (in_array($v->infos->status, array('expired', 'unPaid'))) { - continue; - } + $vps = json_decode(file_get_contents($cache)); + foreach ($vps as $v) { + if (in_array($v->infos->status, ['expired', 'unPaid'])) { + continue; + } - try { - if (substr($v->model->version, 0, 4) === '2014') { - $max = $ovh->get('/vps/'.$v->name.'/use', array('type' => 'mem:max')); - $used = $ovh->get('/vps/'.$v->name.'/use', array('type' => 'mem:used')); + try { + if (substr($v->model->version, 0, 4) === '2014') { + $max = $ovh->get('/vps/'.$v->name.'/use', ['type' => 'mem:max']); + $used = $ovh->get('/vps/'.$v->name.'/use', ['type' => 'mem:used']); - $result[$v->name] = array($used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)); - } else { - $max = $ovh->get('/vps/'.$v->name.'/monitoring', array('period' => 'today', 'type' => 'mem:max')); - $used = $ovh->get('/vps/'.$v->name.'/monitoring', array('period' => 'today', 'type' => 'mem:used')); + $result[$v->name] = [$used['value'], $used['unit'], round($used['value'] / $max['value'] * 100)]; + } else { + $max = $ovh->get('/vps/'.$v->name.'/monitoring', ['period' => 'today', 'type' => 'mem:max']); + $used = $ovh->get('/vps/'.$v->name.'/monitoring', ['period' => 'today', 'type' => 'mem:used']); - $lastMax = array_pop($max['values']); - $lastUsed = array_pop($used['values']); + $lastMax = array_pop($max['values']); + $lastUsed = array_pop($used['values']); - $prevUsed = array_pop($used['values']); - $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); + $prevUsed = array_pop($used['values']); + $status = (round($lastUsed['value']) > round($prevUsed['value']) ? 1 : (round($lastUsed['value']) < round($prevUsed['value']) ? -1 : 0)); - $result[$v->name] = array($lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status); - } - } catch (Exception $e) { - $result[$v->name] = $e->getMessage(); + $result[$v->name] = [$lastUsed['value'], $used['unit'], round($lastUsed['value'] / $lastMax['value'] * 100), $status]; + } + } catch (Exception $e) { + $result[$v->name] = $e->getMessage(); + } } - } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_GET['ram-chart'], $_GET['vps'])) { - $result = array(); +elseif (isset($_GET['ram-chart'], $_GET['vps'])) { + $result = []; - try { - $max = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', array('period' => 'lastweek', 'type' => 'mem:max')); - $used = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', array('period' => 'lastweek', 'type' => 'mem:used')); + try { + $max = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', ['period' => 'lastweek', 'type' => 'mem:max']); + $used = $ovh->get('/vps/'.$_GET['vps'].'/monitoring', ['period' => 'lastweek', 'type' => 'mem:used']); - $values = array(); - foreach ($max['values'] as $v) { - $values[] = array( + $values = []; + foreach ($max['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $max['values'] = $values; + 'y' => $v['value'], + ]; + } + $max['values'] = $values; - $values = array(); - foreach ($used['values'] as $v) { - $values[] = array( + $values = []; + foreach ($used['values'] as $v) { + $values[] = [ 'x' => date('c', $v['timestamp']), - 'y' => $v['value'] - ); - } - $used['values'] = $values; + 'y' => $v['value'], + ]; + } + $used['values'] = $values; - $result[] = array('max' => $max, 'used' => $used); - } catch (Exception $e) { - $result[] = $e->getMessage(); - } + $result[] = ['max' => $max, 'used' => $used]; + } catch (Exception $e) { + $result[] = $e->getMessage(); + } - header('Content-Type: application/json'); - echo json_encode($result); + header('Content-Type: application/json'); + echo json_encode($result); } /* ************************************************************************ * */ -else if (isset($_REQUEST['info'], $_REQUEST['vps'])) { - $json = json_decode(file_get_contents($cache)); - $vps = NULL; - foreach ($json as $j) { - if ($j->name === $_REQUEST['vps']) { - $vps = $j; - break; +elseif (isset($_REQUEST['info'], $_REQUEST['vps'])) { + $json = json_decode(file_get_contents($cache)); + $vps = null; + foreach ($json as $j) { + if ($j->name === $_REQUEST['vps']) { + $vps = $j; + break; + } } - } - if (!is_null($vps)) { - $d1 = new DateTime(); - $d2 = new DateTime($vps->infos->expiration); - $diff = $d1->diff($d2); -?> + if (!is_null($vps)) { + $d1 = new DateTime(); + $d2 = new DateTime($vps->infos->expiration); + $diff = $d1->diff($d2); ?>
    1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?>> name ?>
    @@ -112,9 +114,11 @@
    1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?> class="text-center alert-live"> 1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?>>
      -ipAddresses as $ip) { ?> +ipAddresses as $ip) { + ?>
    • ip ?>
    • - +
    1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?>>region ?> 1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?> class="text-nowrap text-right">flavor->ram / 1000) ?> Go 1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?> class="text-nowrap text-right ram-live"> 1 ? 'rowspan="'.count($instanceVolumes).'"' : '') ?> class="text-nowrap text-center"> name ?>
    id ?>
    region ?> type ?> size ?> Go status ?>
    name ?>
    id ?>
    region ?>status ?>
    - infos->status, array('expired', 'unPaid')) ? ' class="text-danger"' : '') ?>> + infos->status, ['expired', 'unPaid']) ? ' class="text-danger"' : '') ?>> @@ -283,12 +282,11 @@ @@ -306,7 +304,7 @@
    infos->status ?>
    infos->renewalType === 'manual' || $vps->infos->renew->manualPayment === TRUE) { - echo _('Manual'); - } else if ($vps->infos->renew->automatic === TRUE) { - echo sprintf(ngettext('Automatic: %d month', 'Automatic: %d months', $vps->infos->renew->period), $vps->infos->renew->period); - } -?> + if ($vps->infos->renewalType === 'manual' || $vps->infos->renew->manualPayment === true) { + echo _('Manual'); + } elseif ($vps->infos->renew->automatic === true) { + echo sprintf(ngettext('Automatic: %d month', 'Automatic: %d months', $vps->infos->renew->period), $vps->infos->renew->period); + } ?>
    get('/vps'); - foreach ($vps as $v) { - $_v = $ovh->get('/vps/'.$v); + $vps = $ovh->get('/vps'); + foreach ($vps as $v) { + $_v = $ovh->get('/vps/'.$v); - $_v['infos'] = $ovh->get('/vps/'.$v.'/serviceInfos'); + $_v['infos'] = $ovh->get('/vps/'.$v.'/serviceInfos'); - if ($_v['infos']['status'] === 'ok') { - $_v['distribution'] = $ovh->get('/vps/'.$v.'/distribution'); - $_v['ipAddresses'] = $ovh->get('/vps/'.$v.'/ips'); - } + if ($_v['infos']['status'] === 'ok') { + $_v['distribution'] = $ovh->get('/vps/'.$v.'/distribution'); + $_v['ipAddresses'] = $ovh->get('/vps/'.$v.'/ips'); + } - $json[] = $_v; - } + $json[] = $_v; + } - if (!file_exists('../cache') || !is_dir('../cache')) { mkdir('../cache'); } - file_put_contents($cache, json_encode($json, JSON_PRETTY_PRINT)); + if (!file_exists('../cache') || !is_dir('../cache')) { + mkdir('../cache'); + } + file_put_contents($cache, json_encode($json, JSON_PRETTY_PRINT)); } ?> @@ -67,53 +69,69 @@ infos->expiration); - $diff = $d1->diff($d2); - $expiration = ($diff->days <= 30); -?> - infos->status, array('expired', 'unPaid')) ? ' class="table-danger"' : '') ?>> + $d1 = new DateTime(); + $d2 = new DateTime($v->infos->expiration); + $diff = $d1->diff($d2); + $expiration = ($diff->days <= 30); ?> + infos->status, ['expired', 'unPaid']) ? ' class="table-danger"' : '') ?>> -infos->renewalType === 'manual') { ?> +infos->renewalType === 'manual') { + ?> - + name ?>
    displayName ?> -infos->renewalType === 'manual') { ?> +infos->renewalType === 'manual') { + ?>
    - + -ipAddresses)) { ?> +ipAddresses)) { + ?> - + zone ?> model->offer ?>
    model->version ?> - model->name ?> distribution) ? $v->distribution->name : '') ?> distribution) ? $v->distribution->bitFormat.' bits' : '') ?> model->disk ?> Go -infos->status, array('expired', 'unPaid'))) { ?> +infos->status, ['expired', 'unPaid'])) { + ?> - + - + vcore ?> -infos->status, array('expired', 'unPaid'))) { ?> +infos->status, ['expired', 'unPaid'])) { + ?> - + - + memoryLimit / 1024) ?> Go -infos->status, array('expired', 'unPaid'))) { ?> +infos->status, ['expired', 'unPaid'])) { + ?> @@ -125,10 +143,13 @@ smtp tools - + - +