Exemple #1
0
	public function getAllInfo($reload = FALSE){
		global $dockerManPaths;
		$DockerClient = new DockerClient();
		$DockerUpdate = new DockerUpdate();
		$new_info     = array();

		$dockerIni = $dockerManPaths['webui-info'];
		if (! is_dir( dirname( $dockerIni ))) @mkdir( dirname( $dockerIni ), 0770, true);
		$info = (is_file($dockerIni)) ? json_decode(file_get_contents($dockerIni), TRUE) : array();
		if (! count($info) ) $info = array();

		$containers   = $DockerClient->getDockerContainers();
		if (! count($containers) ) $containers = array();

		$autostart_file = $dockerManPaths['autostart-file'];
		$allAutoStart = @file($autostart_file, FILE_IGNORE_NEW_LINES);
		if ($allAutoStart===FALSE) $allAutoStart = array();

		$update_file = $dockerManPaths['update-status'];
		$updateStatus = (is_file($update_file)) ? json_decode(file_get_contents($update_file), TRUE) : array();

		foreach ($containers as $ct) {
			$name           = $ct['Name'];
			$image          = $ct['Image'];
			$tmp            = ( count($info[$name]) ) ?  $info[$name] : array() ;

			$tmp['running'] = $ct['Running'];
			$tmp['autostart'] = in_array($name, $allAutoStart);

			$img = $this->getBannerIcon( $image );
			$tmp['banner'] = ( $img['banner'] ) ? $img['banner'] : "#";
			$tmp['icon']   = ( $img['icon'] )   ? $img['icon'] : "#";

			$WebUI      = $this->getControlURL($name);
			$tmp['url'] = ($WebUI) ? $WebUI : "#";

			$Registry = $this->getTemplateValue($image, "Registry");
			$tmp['registry'] = ( $Registry ) ? $Registry : "#";

			if ($reload) {
				$nv = $DockerUpdate->getUpdateStatus($name, $image);
				if ($nv != 'undef'){
					$updateStatus[$name] = $nv;
				}
			}
			$tmp['updated'] = (array_key_exists($name, $updateStatus)) ? $updateStatus[$name] : 'undef';

			$tmp['template'] = $this->getUserTemplate($name);

  		$this->debug("\n$name");foreach ($tmp as $c => $d) $this->debug(sprintf("   %-10s: %s", $c, $d));
			$new_info[$name] = $tmp;
		}
		file_put_contents($dockerIni, json_encode($new_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
		if($reload) {
			foreach ($updateStatus as $ct => $update)	if (!isset($new_info[$ct])) unset($updateStatus[$ct]);
			file_put_contents($update_file, json_encode($updateStatus, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
		}
		return $new_info;
	}
foreach ($argv as $arg) {
  switch ($arg) {
  case '-v'   : $docker->verbose = true; break;
  case 'check': $check = true; break;}
}

if (!isset($check)) {
  echo " Updating templates... ";
  $docker->downloadTemplates();
  echo " Updating info... ";
  $docker->getAllInfo(true);
  echo " Done.";
} else {
  require_once("/usr/local/emhttp/webGui/include/Wrappers.php");
  $client = new DockerClient();
  $update = new DockerUpdate();
  $notify = "/usr/local/emhttp/webGui/scripts/notify";
  $unraid = parse_plugin_cfg("dynamix",true);
  $server = strtoupper($var['NAME']);
  $output = $unraid['notify']['docker_notify'];

  $list = $client->getDockerContainers();
  $info = $docker->getAllInfo();
  foreach ($list as $ct) {
    $name = $ct['Name'];
    $image = $ct['Image'];
    if ($info[$name]['updated'] == "false") {
      $new = $update->getRemoteVersion($docker->getTemplateValue($image, "Registry"), $image);
      exec("$notify -e 'Docker - $name [$new]' -s 'Notice [$server] - Docker update $new' -d 'A new version of $name is available' -i 'normal $output' -x");
    }
Exemple #3
0
/* Copyright 2015, Lime Technology
 * Copyright 2015, Guilherme Jardim, Eric Schultz, Jon Panozzo.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<?
ignore_user_abort(true);
require_once("/usr/local/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php");
$DockerClient = new DockerClient();
$DockerUpdate = new DockerUpdate();
$DockerTemplates = new DockerTemplates();

function prepareDir($dir){
  if (strlen($dir)){
    if ( ! is_dir($dir) && ! is_file($dir)){
      mkdir($dir, 0777, true);
      chown($dir, 'nobody');
      chgrp($dir, 'users');
      sleep(1);
    }
  }
}

function ContainerExist($container){