"Fossies" - the Fresh Open Source Software Archive

Member "fogproject-1.5.9/packages/web/lib/pages/hostmanagementpage.class.php" (13 Sep 2020, 127620 Bytes) of package /linux/misc/fogproject-1.5.9.tar.gz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "hostmanagementpage.class.php": 1.5.8_vs_1.5.9.

    1 <?php
    2 /**
    3  * Host management page
    4  *
    5  * PHP version 5
    6  *
    7  * The host represented to the GUI
    8  *
    9  * @category HostManagementPage
   10  * @package  FOGProject
   11  * @author   Tom Elliott <tommygunsster@gmail.com>
   12  * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
   13  * @link     https://fogproject.org
   14  */
   15 /**
   16  * Host management page
   17  *
   18  * The host represented to the GUI
   19  *
   20  * @category HostManagementPage
   21  * @package  FOGProject
   22  * @author   Tom Elliott <tommygunsster@gmail.com>
   23  * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
   24  * @link     https://fogproject.org
   25  */
   26 class HostManagementPage extends FOGPage
   27 {
   28     /**
   29      * The node that uses this class.
   30      *
   31      * @var string
   32      */
   33     public $node = 'host';
   34     /**
   35      * Initializes the host page
   36      *
   37      * @param string $name the name to construct with
   38      *
   39      * @return void
   40      */
   41     public function __construct($name = '')
   42     {
   43         $this->name = 'Host Management';
   44         parent::__construct($this->name);
   45         if (self::$pendingHosts > 0) {
   46             $this->menu['pending'] = self::$foglang['PendingHosts'];
   47         }
   48         global $id;
   49         if ($id) {
   50             $linkstr = "$this->linkformat#host-%s";
   51             $this->subMenu = array(
   52                 sprintf(
   53                     $linkstr,
   54                     'general'
   55                 ) => self::$foglang['General'],
   56             );
   57             if (!$this->obj->get('pending')) {
   58                 $this->subMenu = self::fastmerge(
   59                     $this->subMenu,
   60                     array(
   61                         sprintf(
   62                             $linkstr,
   63                             'tasks'
   64                         ) => self::$foglang['BasicTasks'],
   65                     )
   66                 );
   67             }
   68             $this->subMenu = self::fastmerge(
   69                 $this->subMenu,
   70                 array(
   71                     sprintf(
   72                         $linkstr,
   73                         'active-directory'
   74                     ) => self::$foglang['AD'],
   75                     sprintf(
   76                         $linkstr,
   77                         'printers'
   78                     ) => self::$foglang['Printers'],
   79                     sprintf(
   80                         $linkstr,
   81                         'snapins'
   82                     ) => self::$foglang['Snapins'],
   83                     sprintf(
   84                         $linkstr,
   85                         'service'
   86                     ) => sprintf(
   87                         '%s %s',
   88                         self::$foglang['Service'],
   89                         self::$foglang['Settings']
   90                     ),
   91                     sprintf(
   92                         $linkstr,
   93                         'powermanagement'
   94                     ) => self::$foglang['PowerManagement'],
   95                     sprintf(
   96                         $linkstr,
   97                         'hardware-inventory'
   98                     ) => self::$foglang['Inventory'],
   99                     sprintf(
  100                         $linkstr,
  101                         'virus-history'
  102                     ) => self::$foglang['VirusHistory'],
  103                     sprintf(
  104                         $linkstr,
  105                         'login-history'
  106                     ) => self::$foglang['LoginHistory'],
  107                     sprintf(
  108                         $linkstr,
  109                         'image-history'
  110                     ) => self::$foglang['ImageHistory'],
  111                     sprintf(
  112                         $linkstr,
  113                         'snapin-history'
  114                     ) => self::$foglang['SnapinHistory'],
  115                     $this->membership => self::$foglang['Membership'],
  116                     $this->delformat => self::$foglang['Delete'],
  117                 )
  118             );
  119             $this->notes = array(
  120                 self::$foglang['Host'] => $this->obj->get('name'),
  121                 self::$foglang['MAC'] => $this->obj->get('mac'),
  122                 self::$foglang['Image'] => $this->obj->getImageName(),
  123                 self::$foglang['LastDeployed'] => $this->obj->get('deployed'),
  124             );
  125             $primaryGroup = @min($this->obj->get('groups'));
  126             $Group = new Group($primaryGroup);
  127             if ($Group->isValid()) {
  128                 $this->notes[self::$foglang['PrimaryGroup']] = $Group->get('name');
  129                 unset($Group);
  130             }
  131         }
  132         if (!($this->obj instanceof Host && $this->obj->isValid())) {
  133             $this->exitNorm = filter_input(INPUT_POST, 'bootTypeExit');
  134             $this->exitEfi = filter_input(INPUT_POST, 'efiBootTypeExit');
  135         } else {
  136             $this->exitNorm = $this->obj->get('biosexit');
  137             $this->exitEfi = $this->obj->get('efiexit');
  138         }
  139         $this->exitNorm = Service::buildExitSelector(
  140             'bootTypeExit',
  141             $this->exitNorm,
  142             true,
  143             'bootTypeExit'
  144         );
  145         $this->exitEfi = Service::buildExitSelector(
  146             'efiBootTypeExit',
  147             $this->exitEfi,
  148             true,
  149             'efiBootTypeExit'
  150         );
  151         self::$HookManager->processEvent(
  152             'SUB_MENULINK_DATA',
  153             array(
  154                 'menu' => &$this->menu,
  155                 'submenu' => &$this->subMenu,
  156                 'notes' => &$this->notes,
  157                 'biosexit' => &$this->exitNorm,
  158                 'efiexit' => &$this->exitEfi,
  159                 'object' => &$this->obj,
  160                 'linkformat' => &$this->linkformat,
  161                 'delformat' => &$this->delformat,
  162                 'membership' => &$this->membership
  163             )
  164         );
  165         $this->headerData = array(
  166             '',
  167             '<label for="toggler">'
  168             . '<input type="checkbox" name="toggle-checkbox" '
  169             . 'class="toggle-checkboxAction" id="toggler"/>'
  170             . '</label>',
  171         );
  172         self::$fogpingactive ? array_push($this->headerData, '') : null;
  173         array_push(
  174             $this->headerData,
  175             _('Host'),
  176             _('Imaged'),
  177             _('Task'),
  178             _('Assigned Image')
  179         );
  180         $this->templates = array(
  181             '<i class="icon fa fa-question hand"></i>',
  182             '<label for="host-${id}">'
  183             . '<input type="checkbox" name="host[]" '
  184             . 'value="${id}" class="toggle-action" id="host-${id}"/>'
  185             . '</label>',
  186         );
  187         if (self::$fogpingactive) {
  188             array_push(
  189                 $this->templates,
  190                 '${pingstatus}'
  191             );
  192         }
  193         $up = new TaskType(2);
  194         $down = new TaskType(1);
  195         $mc = new TaskType(8);
  196         array_push(
  197             $this->templates,
  198             '<a href="?node=host&sub=edit&id=${id}" '
  199             . 'title="'
  200             . _('Edit')
  201             . ': ${host_name}" id="host-${host_name}" '
  202             . 'data-toggle="tooltip" data-placement="right">'
  203             . '${host_name}'
  204             . '</a>'
  205             . '<br/>'
  206             . '<small>${host_mac}</small>',
  207             '<small>${deployed}</small>',
  208             sprintf(
  209                 '<a href="?node=host&sub=deploy&type=1&id=${id}">'
  210                 . '<i class="icon fa fa-%s" title="%s"></i></a> '
  211                 . '<a href="?node=host&sub=deploy&type=2&id=${id}">'
  212                 . '<i class="icon fa fa-%s" title="%s"></i></a> '
  213                 . '<a href="?node=host&sub=deploy&type=8&id=${id}">'
  214                 . '<i class="icon fa fa-%s" title="%s"></i></a> '
  215                 . '<a href="?node=host&sub=edit&id=${id}#host-tasks">'
  216                 . '<i class="icon fa fa-arrows-alt" title="%s"></i></a>',
  217                 $down->get('icon'),
  218                 $down->get('name'),
  219                 $up->get('icon'),
  220                 $up->get('name'),
  221                 $mc->get('icon'),
  222                 $mc->get('name'),
  223                 _('Goto task list')
  224             ),
  225             '<small><a href="?node=image&sub=edit&id=${image_id}">'
  226             . '${image_name}</a></small>'
  227         );
  228         unset($up, $down, $mc);
  229         $this->attributes = array(
  230             array(
  231                 'width' => 16,
  232                 'id' => 'host-${host_name}',
  233                 'class' => 'filter-false',
  234                 'title' => '${host_desc}',
  235                 'data-toggle' => 'tooltip',
  236                 'data-placement' => 'right'
  237             ),
  238             array(
  239                 'class' => 'l filter-false form-group',
  240                 'width' => 16
  241             ),
  242         );
  243         if (self::$fogpingactive) {
  244             array_push(
  245                 $this->attributes,
  246                 array(
  247                     'width' => 16,
  248                     'class' => 'filter-false'
  249                 )
  250             );
  251         }
  252         array_push(
  253             $this->attributes,
  254             array('width' => 50),
  255             array('width' => 145),
  256             array(
  257                 'width' => 60,
  258                 'class' => 'filter-false'
  259             ),
  260             array(
  261                 'width' => 20
  262             )
  263         );
  264         /**
  265          * Lambda function to return data either by list or search.
  266          *
  267          * @param object $Host the object to use.
  268          *
  269          * @return void
  270          */
  271         self::$returnData = function (&$Host) {
  272             $this->data[] = array(
  273                 'id' => $Host->id,
  274                 'deployed' => self::formatTime(
  275                     $Host->deployed,
  276                     'Y-m-d H:i:s'
  277                 ),
  278                 'host_name' => $Host->name,
  279                 'host_mac' => $Host->primac,
  280                 'host_desc' => $Host->description,
  281                 'image_id' => $Host->imageID,
  282                 'image_name' => $Host->imagename,
  283                 'pingstatus' => $Host->pingstatus,
  284             );
  285             unset($Host);
  286         };
  287     }
  288     /**
  289      * Lists the pending hosts
  290      *
  291      * @return false
  292      */
  293     public function pending()
  294     {
  295         $this->title = _('Pending Host List');
  296         $this->data = array();
  297         Route::listem(
  298             'host',
  299             'name',
  300             false,
  301             array('pending' => 1)
  302         );
  303         $Hosts = json_decode(
  304             Route::getData()
  305         );
  306         $Hosts = $Hosts->hosts;
  307         array_map(self::$returnData, $Hosts);
  308         self::$HookManager->processEvent(
  309             'HOST_DATA',
  310             array(
  311                 'data' => &$this->data,
  312                 'templates' => &$this->templates,
  313                 'attributes' => &$this->attributes
  314             )
  315         );
  316         self::$HookManager->processEvent(
  317             'HOST_HEADER_DATA',
  318             array(
  319                 'headerData' => &$this->headerData
  320             )
  321         );
  322         if (count($this->data) > 0) {
  323             printf(
  324                 '<form class="form-horizontal" method="post" action="%s">',
  325                 $this->formAction
  326             );
  327         }
  328         $this->render();
  329         if (count($this->data) > 0) {
  330             echo '<button name="approvependhost" type="submit" id='
  331                 . '"approvependhost" class='
  332                 . '"btn btn-info">'
  333                 . _('Approve selected hosts')
  334                 . '</button>'
  335                 . '<button name="delpendhost" type="submit" id='
  336                 . '"delpendhost" class='
  337                 . '"btn btn-danger">'
  338                 . _('Delete selected hosts')
  339                 . '</button>';
  340             echo '</form>';
  341         }
  342     }
  343     /**
  344      * Pending host form submitting
  345      *
  346      * @return void
  347      */
  348     public function pendingPost()
  349     {
  350         $host = filter_input_array(
  351             INPUT_POST,
  352             array(
  353                 'host' => array(
  354                     'flags' => FILTER_REQUIRE_ARRAY
  355                 )
  356             )
  357         );
  358         $host = $host['host'];
  359         if (isset($_POST['approvependhost'])) {
  360             self::getClass('HostManager')->update(
  361                 array(
  362                     'id' => $host
  363                 ),
  364                 '',
  365                 array('pending' => 0)
  366             );
  367             $title = _('Approve Success');
  368             $msg = _('Selected hosts approved successfully');
  369         }
  370         if (isset($_POST['delpendhost'])) {
  371             self::getClass('HostManager')->destroy(
  372                 array(
  373                     'id' => $host
  374                 )
  375             );
  376             $title = _('Deleted Success');
  377             $msg = _('Selected hosts deleted successfully');
  378         }
  379         $msg = json_encode(
  380             array(
  381                 'msg' => $msg,
  382                 'title' => $title
  383             )
  384         );
  385         echo $msg;
  386         exit;
  387     }
  388     /**
  389      * Creates a new host entry manually.
  390      *
  391      * @return void
  392      */
  393     public function add()
  394     {
  395         $this->title = _('New Host');
  396         unset(
  397             $this->data,
  398             $this->form,
  399             $this->headerData,
  400             $this->templates,
  401             $this->attributes
  402         );
  403         $this->templates = array(
  404             '${field}',
  405             '${input}',
  406         );
  407         $this->attributes = array(
  408             array('class' => 'col-xs-4'),
  409             array('class' => 'col-xs-8 form-group'),
  410         );
  411         $fields = array(
  412             '<label for="host">'
  413             . _('Host Name')
  414             . '</label>' => '<div class="input-group">'
  415             . '<input type="text" name="host" '
  416             . 'value="'
  417             . filter_input(INPUT_POST, 'host')
  418             . '" maxlength="15" '
  419             . 'class="hostname-input form-control" '
  420             . 'id="host" required/>'
  421             . '</div>',
  422             '<label for="mac">'
  423             . _('Primary MAC')
  424             . '</label>' => '<div class="input-group">'
  425             . '<span class="mac-manufactor input-group-addon">'
  426             . '</span>'
  427             . '<input type="text" name="mac" class="macaddr form-control" '
  428             . 'id="mac" value="'
  429             . filter_input(INPUT_POST, 'mac')
  430             . '" maxlength="17" required/>'
  431             . '</div>',
  432             '<label for="description">'
  433             . _('Host Description')
  434             . '</label>' => '<div class="input-group">'
  435             . '<textarea class="form-control" '
  436             . 'id="description" name="description">'
  437             . filter_input(INPUT_POST, 'description')
  438             . '</textarea>'
  439             . '</div>',
  440             '<label for="productKey">'
  441             . _('Host Product Key')
  442             . '</label>' => '<div class="input-group">'
  443             . '<input id="productKey" type="text" '
  444             . 'name="key" value="'
  445             . filter_input(INPUT_POST, 'key')
  446             . '" class="form-control"/>'
  447             . '</div>',
  448             '<label for="image">'
  449             . _('Host Image')
  450             . '</label>' => '<div class="input-group">'
  451             . self::getClass('ImageManager')->buildSelectBox(
  452                 filter_input(INPUT_POST, 'image'),
  453                 '',
  454                 'id'
  455             )
  456             . '</div>',
  457             '<label for="kern">'
  458             . _('Host Kernel')
  459             . '</label>' => '<div class="input-group">'
  460             . '<input type="text" name="kern" '
  461             . 'value="'
  462             . filter_input(INPUT_POST, 'kern')
  463             . '" class="form-control" id="kern"/>'
  464             . '</div>',
  465             '<label for="args">'
  466             . _('Host Kernel Arguments')
  467             . '</label>' => '<div class="input-group">'
  468             . '<input type="text" name="args" id="args" value="'
  469             . filter_input(INPUT_POST, 'args')
  470             . '" class="form-control"/>'
  471             . '</div>',
  472             '<label for="init">'
  473             . _('Host Init')
  474             . '</label>' => '<div class="input-group">'
  475             . '<input type="text" name="init" value="'
  476             . filter_input(INPUT_POST, 'init')
  477             . '" id="init" class="form-control"/>',
  478             '<label for="dev">'
  479             . _('Host Primary Disk')
  480             . '</label>' => '<div class="input-group">'
  481             . '<input type="text" name="dev" value="'
  482             . filter_input(INPUT_POST, 'dev')
  483             . '" id="dev" class="form-control"/>'
  484             . '</div>',
  485             '<label for="bootTypeExit">'
  486             . _('Host Bios Exit Type')
  487             . '</label>' => '<div class="input-group">'
  488             . $this->exitNorm
  489             . '</div>',
  490             '<label for="efiBootTypeExit">'
  491             . _('Host EFI Exit Type')
  492             . '</label>' => '<div class="input-group">'
  493             . $this->exitEfi
  494             . '</div>',
  495         );
  496         self::$HookManager
  497             ->processEvent(
  498                 'HOST_FIELDS',
  499                 array(
  500                     'fields' => &$fields,
  501                     'Host' => self::getClass('Host')
  502                 )
  503             );
  504         array_walk($fields, $this->fieldsToData);
  505         self::$HookManager
  506             ->processEvent(
  507                 'HOST_ADD_GEN',
  508                 array(
  509                     'data' => &$this->data,
  510                     'templates' => &$this->templates,
  511                     'attributes' => &$this->attributes,
  512                     'headerData' => &$this->headerData
  513                 )
  514             );
  515         echo '<div class="col-xs-9">';
  516         echo '<form class="form-horizontal" method="post" action="'
  517             . $this->formAction
  518             . '">';
  519         echo '<div class="panel panel-info">';
  520         echo '<div class="panel-heading text-center">';
  521         echo '<h4 class="title">';
  522         echo $this->title;
  523         echo '</h4>';
  524         echo '</div>';
  525         echo '<div class="panel-body">';
  526         if (!isset($_POST['enforcesel'])) {
  527             $_POST['enforcesel'] = self::getSetting('FOG_ENFORCE_HOST_CHANGES');
  528         }
  529         echo '<!-- Host General -->';
  530         $this->render(12);
  531         echo '</div>';
  532         echo '</div>';
  533         $this->adFieldsToDisplay(
  534             filter_input(INPUT_POST, 'domain'),
  535             filter_input(INPUT_POST, 'domainname'),
  536             filter_input(INPUT_POST, 'ou'),
  537             filter_input(INPUT_POST, 'domainuser'),
  538             filter_input(INPUT_POST, 'domainpassword'),
  539             filter_input(INPUT_POST, 'domainpasswordlegacy'),
  540             isset($_POST['enforcesel']),
  541             false
  542         );
  543         echo '</form>';
  544         echo '</div>';
  545     }
  546     /**
  547      * Handles the forum submission process.
  548      *
  549      * @return void
  550      */
  551     public function addPost()
  552     {
  553         self::$HookManager->processEvent('HOST_ADD_POST');
  554         $name = trim(
  555             filter_input(INPUT_POST, 'host')
  556         );
  557         $mac = trim(
  558             filter_input(INPUT_POST, 'mac')
  559         );
  560         $desc = trim(
  561             filter_input(INPUT_POST, 'description')
  562         );
  563         $password = trim(
  564             filter_input(INPUT_POST, 'domainpassword')
  565         );
  566         $useAD = (int)isset($_POST['domain']);
  567         $domain = trim(
  568             filter_input(INPUT_POST, 'domainname')
  569         );
  570         $ou = trim(
  571             filter_input(INPUT_POST, 'ou')
  572         );
  573         $user = trim(
  574             filter_input(INPUT_POST, 'domainuser')
  575         );
  576         $pass = $password;
  577         $passlegacy = trim(
  578             filter_input(INPUT_POST, 'domainpasswordlegacy')
  579         );
  580         $key = trim(
  581             filter_input(INPUT_POST, 'key')
  582         );
  583         $productKey = preg_replace(
  584             '/([\w+]{5})/',
  585             '$1-',
  586             str_replace(
  587                 '-',
  588                 '',
  589                 strtoupper($key)
  590             )
  591         );
  592         $productKey = substr($productKey, 0, 29);
  593         $enforce = (int)isset($_POST['enforcesel']);
  594         $image = (int)filter_input(INPUT_POST, 'image');
  595         $kernel = trim(
  596             filter_input(INPUT_POST, 'kern')
  597         );
  598         $kernelArgs = trim(
  599             filter_input(INPUT_POST, 'args')
  600         );
  601         $kernelDevice = trim(
  602             filter_input(INPUT_POST, 'dev')
  603         );
  604         $init = trim(
  605             filter_input(INPUT_POST, 'init')
  606         );
  607         $bootTypeExit = trim(
  608             filter_input(INPUT_POST, 'bootTypeExit')
  609         );
  610         $efiBootTypeExit = trim(
  611             filter_input(INPUT_POST, 'efiBootTypeExit')
  612         );
  613         try {
  614             if (!$name) {
  615                 throw new Exception(
  616                     _('A host name is required!')
  617                 );
  618             }
  619             if (!$mac) {
  620                 throw new Exception(
  621                     _('A mac address is required!')
  622                 );
  623             }
  624             if (self::getClass('HostManager')->exists($name)) {
  625                 throw new Exception(
  626                     _('A host already exists with this name!')
  627                 );
  628             }
  629             $MAC = new MACAddress($mac);
  630             if (!$MAC->isValid()) {
  631                 throw new Exception(_('MAC Format is invalid'));
  632             }
  633             self::getClass('HostManager')->getHostByMacAddresses($MAC);
  634             if (self::$Host->isValid()) {
  635                 throw new Exception(
  636                     sprintf(
  637                         '%s: %s',
  638                         _('A host with this mac already exists with name'),
  639                         self::$Host->get('name')
  640                     )
  641                 );
  642             }
  643             $ModuleIDs = self::getSubObjectIDs(
  644                 'Module',
  645                 array('isDefault' => 1)
  646             );
  647             self::$Host
  648                 ->set('name', $name)
  649                 ->set('description', $desc)
  650                 ->set('imageID', $image)
  651                 ->set('kernel', $kernel)
  652                 ->set('kernelArgs', $kernelArgs)
  653                 ->set('kernelDevice', $kernelDevice)
  654                 ->set('init', $init)
  655                 ->set('biosexit', $bootTypeExit)
  656                 ->set('efiexit', $efiBootTypeExit)
  657                 ->set('productKey', $productKey)
  658                 ->set('modules', $ModuleIDs)
  659                 ->addPriMAC($MAC)
  660                 ->setAD(
  661                     $useAD,
  662                     $domain,
  663                     $ou,
  664                     $user,
  665                     $pass,
  666                     true,
  667                     true,
  668                     $passlegacy,
  669                     $productKey,
  670                     $enforce
  671                 );
  672             if (!self::$Host->save()) {
  673                 throw new Exception(_('Add host failed!'));
  674             }
  675             $hook = 'HOST_ADD_SUCCESS';
  676             $msg = json_encode(
  677                 array(
  678                     'msg' => _('Host added!'),
  679                     'title' => _('Host Create Success')
  680                 )
  681             );
  682         } catch (Exception $e) {
  683             $hook = 'HOST_ADD_FAIL';
  684             $msg = json_encode(
  685                 array(
  686                     'error' => $e->getMessage(),
  687                     'title' => _('Host Create Fail')
  688                 )
  689             );
  690         }
  691         self::$HookManager
  692             ->processEvent(
  693                 $hook,
  694                 array('Host' => &$Host)
  695             );
  696         echo $msg;
  697         exit;
  698     }
  699     /**
  700      * Generates the powermanagement display items.
  701      *
  702      * @return void
  703      */
  704     public function hostPMDisplay()
  705     {
  706         echo '<!-- Power Management Items -->';
  707         echo '<div class="tab-pane fade" id="host-powermanagement">';
  708         echo '<div class="panel panel-info">';
  709         echo '<div class="panel-heading text-center">';
  710         echo '<h4 class="title">';
  711         echo _('Power Management');
  712         echo '</h4>';
  713         echo '</div>';
  714         echo '<div class="panel-body">';
  715         $this->newPMDisplay();
  716         unset(
  717             $this->data,
  718             $this->form,
  719             $this->headerData,
  720             $this->templates,
  721             $this->attributes
  722         );
  723         // PowerManagement
  724         $this->headerData = array(
  725             '<div class="checkbox">'
  726             . '<label for="rempowerselectors">'
  727             . '<input type="checkbox" id="rempowerselectors"/>'
  728             . '</label>'
  729             . '</div>',
  730             _('Cron Schedule'),
  731             _('Action'),
  732         );
  733         $this->templates = array(
  734             '<input type="checkbox" name="rempowermanagements[]" '
  735             . 'class="rempoweritems" value="${id}" id="rmpm-${id}"/>'
  736             . '<label for="rmpm-${id}"></label>',
  737             '<div class="cronOptions input-group">'
  738             . FOGCron::buildSpecialCron()
  739             . '</div>'
  740             . '<div class="col-xs-12">'
  741             . '<div class="cronInputs">'
  742             . '<div class="col-xs-2">'
  743             . '<input type="hidden" name="pmid[]" value="${id}"/>'
  744             . '<div class="input-group">'
  745             . '<input type="text" name="scheduleCronMin[]" '
  746             . 'class="scheduleCronMin form-control cronInput" value="${min}" '
  747             . 'id="scheduleCronMin"/>'
  748             . '</div>'
  749             . '</div>'
  750             . '<div class="col-xs-2">'
  751             . '<div class="input-group">'
  752             . '<input type="text" name="scheduleCronHour[]" '
  753             . 'class="scheduleCronHour form-control cronInput" value="${hour}" '
  754             . 'id="scheduleCronHour"/>'
  755             . '</div>'
  756             . '</div>'
  757             . '<div class="col-xs-2">'
  758             . '<div class="input-group">'
  759             . '<input type="text" name="scheduleCronDOM[]" '
  760             . 'class="scheduleCronDOM form-control cronInput" value="${dom}" '
  761             . 'id="scheduleCronDOM"/>'
  762             . '</div>'
  763             . '</div>'
  764             . '<div class="col-xs-2">'
  765             . '<div class="input-group">'
  766             . '<input type="text" name="scheduleCronMonth[]" '
  767             . 'class="scheduleCronMonth form-control cronInput" value="${month}" '
  768             . 'id="scheduleCronMonth"/>'
  769             . '</div>'
  770             . '</div>'
  771             . '<div class="col-xs-2">'
  772             . '<div class="input-group">'
  773             . '<input type="text" name="scheduleCronDOW[]" '
  774             . 'class="scheduleCronDOW form-control cronInput" value="${dow}" '
  775             . 'id="scheduleCronDOW"/>'
  776             . '</div>'
  777             . '</div>'
  778             . '</div>'
  779             . '</div>',
  780             '${action}',
  781         );
  782         $this->attributes = array(
  783             array(
  784                 'width' => 16,
  785                 'class' => 'filter-false'
  786             ),
  787             array(
  788                 'class' => 'filter-false'
  789             ),
  790             array(
  791                 'class' => 'filter-false'
  792             )
  793         );
  794         Route::listem('powermanagement');
  795         $PowerManagements = json_decode(
  796             Route::getData()
  797         );
  798         $PowerManagements = $PowerManagements->powermanagements;
  799         foreach ((array)$PowerManagements as &$PowerManagement) {
  800             $mine = in_array(
  801                 $PowerManagement->id,
  802                 $this->obj->get('powermanagementtasks')
  803             );
  804             if (!$mine) {
  805                 continue;
  806             }
  807             if ($PowerManagement->onDemand) {
  808                 continue;
  809             }
  810             $this->data[] = array(
  811                 'id' => $PowerManagement->id,
  812                 'min' => $PowerManagement->min,
  813                 'hour' => $PowerManagement->hour,
  814                 'dom' => $PowerManagement->dom,
  815                 'month' => $PowerManagement->month,
  816                 'dow' => $PowerManagement->dow,
  817                 'action' => self::getClass('PowerManagementManager')
  818                     ->getActionSelect(
  819                         $PowerManagement->action,
  820                         true
  821                     )
  822             );
  823             unset($PowerManagement);
  824         }
  825         // Current data.
  826         if (is_array($this->data) && count($this->data) > 0) {
  827             echo '<div class="panel panel-info">';
  828             echo '<div class="panel-heading text-center">';
  829             echo '<h4 class="title">';
  830             echo _('Current Power Management settings');
  831             echo '</h4>';
  832             echo '</div>';
  833             echo '<div class="body">';
  834             echo '<form class="deploy-container form-horizontal" '
  835                 . 'method="post" action="'
  836                 . $this->formAction
  837                 . '&tab=host-powermanagement">';
  838             $this->render(12);
  839             echo '<div class="form-group">';
  840             echo '<label class="col-xs-4 control-label" for="pmupdate">';
  841             echo _('Update PM Values');
  842             echo '</label>';
  843             echo '<div class="col-xs-8">';
  844             echo '<button type="submit" name="pmupdate" class='
  845                 . '"btn btn-info btn-block" id="pmupdate">';
  846             echo _('Update');
  847             echo '</button>';
  848             echo '</div>';
  849             echo '</div>';
  850             echo '<div class="form-group">';
  851             echo '<label class="col-xs-4 control-label" for="pmdelete">';
  852             echo _('Delete selected');
  853             echo '</label>';
  854             echo '<div class="col-xs-8">';
  855             echo '<button type="submit" name="pmdelete" class='
  856                 . '"btn btn-danger btn-block" id="pmdelete">';
  857             echo _('Remove');
  858             echo '</button>';
  859             echo '</div>';
  860             echo '</div>';
  861             echo '</form>';
  862             echo '</div>';
  863             echo '</div>';
  864         }
  865         echo '</div>';
  866         echo '</div>';
  867         echo '</div>';
  868     }
  869     /**
  870      * Displays the host general tab.
  871      *
  872      * @return void
  873      */
  874     public function hostGeneral()
  875     {
  876         unset(
  877             $this->data,
  878             $this->form,
  879             $this->headerData,
  880             $this->attributes,
  881             $this->templates
  882         );
  883         $this->attributes = array(
  884             array('class' => 'col-xs-4'),
  885             array('class' => 'col-xs-8 form-group'),
  886         );
  887         $this->templates = array(
  888             '${field}',
  889             '${input}',
  890         );
  891         ob_start();
  892         foreach ((array)$this->obj->get('additionalMACs') as $ind => &$MAC) {
  893             echo '<div class="addrow">';
  894             echo '<div class="col-xs-10">';
  895             echo '<div class="input-group">';
  896             echo '<span class="mac-manufactor input-group-addon"></span>';
  897             echo '<input type="text" class="macaddr additionalMAC form-control" '
  898                 . 'name="additionalMACs[]" '
  899                 . 'value="'
  900                 . $MAC
  901                 . '" maxlength="17"/>';
  902             echo '<span class="icon remove-mac fa fa-minus-circle hand '
  903                 . 'input-group-addon" '
  904                 . 'data-toggle="tooltip" data-placement="top" '
  905                 . 'title="'
  906                 . _('Remove MAC')
  907                 . '"></span>';
  908             echo '</div>';
  909             echo '</div>';
  910             echo '<div class="col-xs-1">';
  911             echo '<div class="row">';
  912             echo '<span data-toggle="tooltip" data-placement="top" '
  913                 . 'title="'
  914                 . _('Ignore MAC on Client')
  915                 . '" class="hand">'
  916                 . _('I.M.C.')
  917                 . '</span>';
  918             echo '</div>';
  919             echo '<div class="checkbox">';
  920             echo '<label>';
  921             echo '<input type="checkbox" name="igclient[]" value="'
  922                 . $MAC
  923                 . '"'
  924                 . $this->obj->clientMacCheck($MAC)
  925                 . '/>';
  926             echo '</label>';
  927             echo '</div>';
  928             echo '</div>';
  929             echo '<div class="col-xs-1">';
  930             echo '<div class="row">';
  931             echo '<span data-toggle="tooltip" data-placement="top" '
  932                 . 'title="'
  933                 . _('Ignore MAC on Image')
  934                 . '" class="hand">'
  935                 . _('I.M.I.')
  936                 . '</span>';
  937             echo '</div>';
  938             echo '<div class="checkbox">';
  939             echo '<label>';
  940             echo '<input type="checkbox" name="igimage[]" value="'
  941                 . $MAC
  942                 . '"'
  943                 . $this->obj->imageMacCheck($MAC)
  944                 . '/>';
  945             echo '</label>';
  946             echo '</div>';
  947             echo '</div>';
  948             echo '</div>';
  949         }
  950         $addMACs = ob_get_clean();
  951         ob_start();
  952         foreach ((array)$this->obj->get('pendingMACs') as &$MAC) {
  953             echo '<div class="addrow">';
  954             echo '<div class="col-xs-10">';
  955             echo '<div class="input-group">';
  956             echo '<span class="mac-manufactor input-group-addon"></span>';
  957             echo '<input type="text" class="macaddr pending-mac form-control" '
  958                 . 'name="pendingMACs[]" '
  959                 . 'value="'
  960                 . $MAC
  961                 . '" maxlength="17"/>';
  962             echo '<a class="input-group-addon" href="'
  963                 . $this->formAction
  964                 . '&confirmMAC='
  965                 . $MAC
  966                 . '" data-toggle="tooltip" data-placement="top" '
  967                 . 'title="'
  968                 . _('Approve MAC')
  969                 . '">'
  970                 . '<i class="icon fa fa-check-circle"></i>'
  971                 . '</a>';
  972             echo '</div>';
  973             echo '</div>';
  974             echo '</div>';
  975             unset($MAC);
  976         }
  977         $pending = ob_get_clean();
  978         if ($pending) {
  979             $pending .= '<div class="addrow">'
  980                 . '<div class="col-xs-10">'
  981                 . _('Approve all pending? ')
  982                 . '<a href="'
  983                 . $this->formAction
  984                 . '&approveAll=1" '
  985                 . 'data-toggle="tooltip" data-placement="top" '
  986                 . 'title="'
  987                 . _('Approve all pending macs')
  988                 . '">'
  989                 . '<i class="icon fa fa-check-circle"></i>'
  990                 . '</a>'
  991                 . '</div>'
  992                 . '</div>';
  993         }
  994         $imageSelect = self::getClass('ImageManager')
  995             ->buildSelectBox(
  996                 filter_input(INPUT_POST, 'image') ?: $this->obj->get('imageID')
  997             );
  998 
  999         // Either use the passed in or get the objects info.
 1000         $name = (
 1001             filter_input(INPUT_POST, 'name') ?: $this->obj->get('name')
 1002         );
 1003         $mac = (
 1004             filter_input(INPUT_POST, 'mac') ?: $this->obj->get('mac')
 1005         );
 1006         $desc = (
 1007             filter_input(INPUT_POST, 'description') ?: $this->obj->get('description')
 1008         );
 1009         $productKey = (
 1010             filter_input(INPUT_POST, 'key') ?: $this->obj->get('productKey')
 1011         );
 1012         $productKeytest = self::aesdecrypt($productKey);
 1013         if ($test_base64 = base64_decode($productKeytest)) {
 1014             if (mb_detect_encoding($test_base64, 'utf-8', true)) {
 1015                 $productKey = $test_base64;
 1016             } elseif (mb_detect_encoding($productKeytest, 'utf-8', true)) {
 1017                 $productKey = $productKeytest;
 1018             }
 1019         }
 1020         $kern = (
 1021             filter_input(INPUT_POST, 'kern') ?: $this->obj->get('kernel')
 1022         );
 1023         $args = (
 1024             filter_input(INPUT_POST, 'args') ?: $this->obj->get('kernelArgs')
 1025         );
 1026         $init = (
 1027             filter_input(INPUT_POST, 'init') ?: $this->obj->get('init')
 1028         );
 1029         $dev = (
 1030             filter_input(INPUT_POST, 'dev') ?: $this->obj->get('kernelDevice')
 1031         );
 1032         $fields = array(
 1033             '<label for="name">'
 1034             . _('Host Name')
 1035             . '</label>' => '<div class="input-group">'
 1036             . '<input type="text" name="host" value="'
 1037             . $name
 1038             . '" maxlength="15" class="hostname-input form-control" '
 1039             . 'id="name" required/>'
 1040             . '</div>',
 1041             '<label for="mac">'
 1042             . _('Primary MAC')
 1043             . '</label>' => '<div class="col-xs-10">'
 1044             . '<div class="input-group">'
 1045             . '<span class="mac-manufactor input-group-addon"></span>'
 1046             . '<input type="text" class="macaddr form-control" '
 1047             . 'name="mac" '
 1048             . 'value="'
 1049             . $mac
 1050             . '" id="mac" '
 1051             . 'maxlength="17" required/>'
 1052             . '<span class="icon add-mac fa fa-plus-circle hand '
 1053             . 'input-group-addon" '
 1054             . 'data-toggle="tooltip" data-placement="top" title="'
 1055             . _('Add MAC')
 1056             . '"></span>'
 1057             . '</div>'
 1058             . '</div>'
 1059             . '<div class="col-xs-1">'
 1060             . '<div class="row">'
 1061             . '<span data-toggle="tooltip" data-placement="top" '
 1062             . 'title="'
 1063             . _('Ignore MAC on Client')
 1064             . '" class="hand">'
 1065             . _('I.M.C.')
 1066             . '</span>'
 1067             . '</div>'
 1068             . '<div class="checkbox">'
 1069             . '<label>'
 1070             . '<input type="checkbox" name="igclient[]" value="'
 1071             . $mac
 1072             . '"'
 1073             . $this->obj->clientMacCheck()
 1074             . '/>'
 1075             . '</label>'
 1076             . '</div>'
 1077             . '</div>'
 1078             . '<div class="col-xs-1">'
 1079             . '<div class="row">'
 1080             . '<span data-toggle="tooltip" data-placement="top" '
 1081             . 'title="'
 1082             . _('Ignore MAC on Image')
 1083             . '" class="hand">'
 1084             . _('I.M.I.')
 1085             . '</span>'
 1086             . '</div>'
 1087             . '<div class="checkbox">'
 1088             . '<label>'
 1089             . '<input type="checkbox" name="igimage[]" value="'
 1090             . $mac
 1091             . '"'
 1092             . $this->obj->imageMacCheck()
 1093             . '/>'
 1094             . '</label>'
 1095             . '</div>'
 1096             . '</div>'
 1097             . '</div>',
 1098             '<div class="additionalMACsRow">'
 1099             . '<label>'
 1100             . _('Additional MACs')
 1101             . '</label>'
 1102             . '</div>' => '<div class="additionalMACsCell">'
 1103             . $addMACs
 1104             . '</div>',
 1105             '<div class="pendingMACsRow">'
 1106             . '<label>'
 1107             . _('Pending MACs')
 1108             . '</label>'
 1109             . '</div>' => '<div class="pendingMACsCell">'
 1110             . $pending
 1111             . '</div>',
 1112             '<label for="description">'
 1113             . _('Host description')
 1114             . '</label>' => '<div class="input-group">'
 1115             . '<textarea class="form-control" id="description" '
 1116             . 'name="description">'
 1117             . $desc
 1118             . '</textarea>'
 1119             . '</div>',
 1120             '<label for="productKey">'
 1121             . _('Host Product Key')
 1122             . '</label>' => '<div class="input-group">'
 1123             . '<input type="text" name="key" value="'
 1124             . $productKey
 1125             . '" id="productKey" class="form-control"/>'
 1126             . '</div>',
 1127             '<label for="image">'
 1128             . _('Host Image')
 1129             . '</label>' => $imageSelect,
 1130             '<label for="kern">'
 1131             . _('Host Kernel')
 1132             . '</label>' => '<div class="input-group">'
 1133             . '<input type="text" name="kern" id="kern" '
 1134             . 'class="form-control" value="'
 1135             . $kern
 1136             . '"/>'
 1137             . '</div>',
 1138             '<label for="args">'
 1139             . _('Host Kernel Arguments')
 1140             . '</label>' => '<div class="input-group">'
 1141             . '<input type="text" name="args" id="args" '
 1142             . 'class="form-control" value="'
 1143             . $args
 1144             . '"/>'
 1145             . '</div>',
 1146             '<label for="init">'
 1147             . _('Host Init')
 1148             . '</label>' => '<div class="input-group">'
 1149             . '<input type="text" name="init" id="init" '
 1150             . 'class="form-control" value="'
 1151             . $init
 1152             . '"/>'
 1153             . '</div>',
 1154             '<label for="dev">'
 1155             . _('Host Primary Disk')
 1156             . '</label>' => '<div class="input-group">'
 1157             . '<input type="text" name="dev" id="dev" '
 1158             . 'class="form-control" value="'
 1159             . $dev
 1160             . '"/>'
 1161             . '</div>',
 1162             '<label for="bootTypeExit">'
 1163             . _('Host Bios Exit Type')
 1164             . '</label>' => $this->exitNorm,
 1165             '<label for="efiBootTypeExit">'
 1166             . _('Host EFI Exit Type')
 1167             . '</label>' => $this->exitEfi,
 1168             '<label for="updategen">'
 1169             . _('Make Changes?')
 1170            . '</label>' => '<button type="submit" class="btn btn-info btn-block" '
 1171            . 'id="updategen">'
 1172            . _('Update')
 1173            . '</button>'
 1174         );
 1175         self::$HookManager
 1176             ->processEvent(
 1177                 'HOST_FIELDS',
 1178                 array(
 1179                     'fields' => &$fields,
 1180                     'Host' => &$this->obj
 1181                 )
 1182             );
 1183         array_walk($fields, $this->fieldsToData);
 1184         self::$HookManager
 1185             ->processEvent(
 1186                 'HOST_EDIT_GEN',
 1187                 array(
 1188                     'headerData' => &$this->headerData,
 1189                     'data' => &$this->data,
 1190                     'templates' => &$this->templates,
 1191                     'attributes' => &$this->attributes,
 1192                     'Host'=>&$this->obj
 1193                 )
 1194             );
 1195         if ($this->obj->get('pub_key')
 1196             || $this->obj->get('sec_tok')
 1197         ) {
 1198             $this->form = '<div class="text-center" id="resetSecDataBox">'
 1199                 . '<button type="button" '
 1200                 . 'id="resetSecData" '
 1201                 . 'class="btn btn-warning btn-block">'
 1202                 . _('Reset Encryption Data')
 1203                 . '</button>'
 1204                 . '</div>';
 1205         }
 1206         echo '<!-- General -->';
 1207         echo '<div id="host-general" class="'
 1208             . 'tab-pane fade in active">';
 1209         echo '<div class="addrowempty hiddeninitially">';
 1210         echo '<div class="col-xs-10">';
 1211         echo '<div class="input-group">';
 1212         echo '<span class="mac-manufactor input-group-addon"></span>';
 1213         echo '<input type="text" class="macaddr additionalMAC form-control" '
 1214             . 'name="additionalMACs[]" '
 1215             . 'value="'
 1216             . '" maxlength="17"/>';
 1217         echo '<span class="icon remove-mac fa fa-minus-circle hand '
 1218             . 'input-group-addon" '
 1219             . 'data-toggle="tooltip" data-placement="top" '
 1220             . 'title="'
 1221             . _('Remove MAC')
 1222             . '"></span>';
 1223         echo '</div>';
 1224         echo '</div>';
 1225         echo '<div class="col-xs-1">';
 1226         echo '<div class="row">';
 1227         echo '<span data-toggle="tooltip" data-placement="top" '
 1228             . 'title="'
 1229             . _('Ignore MAC on Client')
 1230             . '" class="hand">'
 1231             . _('I.M.C.')
 1232             . '</span>';
 1233         echo '</div>';
 1234         echo '<div class="checkbox">';
 1235         echo '<label>';
 1236         echo '<input type="checkbox" name="igclient[]" value="'
 1237             . '"'
 1238             . '/>';
 1239         echo '</label>';
 1240         echo '</div>';
 1241         echo '</div>';
 1242         echo '<div class="col-xs-1">';
 1243         echo '<div class="row">';
 1244         echo '<span data-toggle="tooltip" data-placement="top" '
 1245             . 'title="'
 1246             . _('Ignore MAC on Image')
 1247             . '" class="hand">'
 1248             . _('I.M.I.')
 1249             . '</span>';
 1250         echo '</div>';
 1251         echo '<div class="checkbox">';
 1252         echo '<label>';
 1253         echo '<input type="checkbox" name="igimage[]" value="'
 1254             . '"'
 1255             . '/>';
 1256         echo '</label>';
 1257         echo '</div>';
 1258         echo '</div>';
 1259         echo '</div>';
 1260         echo '<div class="panel panel-info">';
 1261         echo '<div class="panel-heading text-center">';
 1262         echo '<h4 class="title">';
 1263         echo _('Host general');
 1264         echo '</h4>';
 1265         echo '</div>';
 1266         echo '<div class="panel-body">';
 1267         echo '<form class="form-horizontal" method="post" '
 1268             . 'action="'
 1269             . $this->formAction
 1270             . '&tab=host-general">';
 1271         $this->render(12);
 1272         echo '</form>';
 1273         echo '</div>';
 1274         echo '</div>';
 1275         echo '</div>';
 1276         unset(
 1277             $this->data,
 1278             $this->form,
 1279             $this->headerData,
 1280             $this->attributes,
 1281             $this->templates
 1282         );
 1283     }
 1284     /**
 1285      * Host general post update.
 1286      *
 1287      * @return void
 1288      */
 1289     public function hostGeneralPost()
 1290     {
 1291         $name = trim(
 1292             filter_input(INPUT_POST, 'host')
 1293         );
 1294         $mac = trim(
 1295             filter_input(INPUT_POST, 'mac')
 1296         );
 1297         $desc = trim(
 1298             filter_input(INPUT_POST, 'description')
 1299         );
 1300         $imageID = trim(
 1301             filter_input(INPUT_POST, 'image')
 1302         );
 1303         $key = strtoupper(
 1304             trim(
 1305                 filter_input(INPUT_POST, 'key')
 1306             )
 1307         );
 1308         $productKey = preg_replace(
 1309             '/([\w+]{5})/',
 1310             '$1-',
 1311             str_replace(
 1312                 '-',
 1313                 '',
 1314                 $key
 1315             )
 1316         );
 1317         $productKey = substr($productKey, 0, 29);
 1318         $kern = trim(
 1319             filter_input(INPUT_POST, 'kern')
 1320         );
 1321         $args = trim(
 1322             filter_input(INPUT_POST, 'args')
 1323         );
 1324         $dev = trim(
 1325             filter_input(INPUT_POST, 'dev')
 1326         );
 1327         $init = trim(
 1328             filter_input(INPUT_POST, 'init')
 1329         );
 1330         $bte = trim(
 1331             filter_input(INPUT_POST, 'bootTypeExit')
 1332         );
 1333         $ebte = trim(
 1334             filter_input(INPUT_POST, 'efiBootTypeExit')
 1335         );
 1336         if (empty($name)) {
 1337             throw new Exception(_('Please enter a hostname'));
 1338         }
 1339         if ($name != $this->obj->get('name')
 1340         ) {
 1341             if (!$this->obj->isHostnameSafe($name)) {
 1342                 throw new Exception(_('Please enter a valid hostname'));
 1343             }
 1344             if ($this->obj->getManager()->exists($name)) {
 1345                 throw new Exception(_('Please use another hostname'));
 1346             }
 1347         }
 1348         if (empty($mac)) {
 1349             throw new Exception(_('Please enter a mac address'));
 1350         }
 1351         $mac = self::parseMacList($mac);
 1352         if (count($mac) < 1) {
 1353             throw new Exception(_('Please enter a valid mac address'));
 1354         }
 1355         $mac = array_shift($mac);
 1356         if (!$mac->isValid()) {
 1357             throw new Exception(_('Please enter a valid mac address'));
 1358         }
 1359         $Task = $this->obj->get('task');
 1360         if ($Task->isValid()
 1361             && $imageID != $this->obj->get('imageID')
 1362         ) {
 1363             throw new Exception(_('Cannot change image when in tasking'));
 1364         }
 1365         $this
 1366             ->obj
 1367             ->set('name', $name)
 1368             ->set('description', $desc)
 1369             ->set('imageID', $imageID)
 1370             ->set('kernel', $kern)
 1371             ->set('kernelArgs', $args)
 1372             ->set('kernelDevice', $dev)
 1373             ->set('init', $init)
 1374             ->set('biosexit', $bte)
 1375             ->set('efiexit', $ebte)
 1376             ->set('productKey', $productKey);
 1377         $primac = $this->obj->get('mac')->__toString();
 1378         $setmac = $mac->__toString();
 1379         if ($primac != $setmac) {
 1380             $this->obj->addPriMAC($mac->__toString());
 1381         }
 1382         $addMACs = filter_input_array(
 1383             INPUT_POST,
 1384             array(
 1385                 'additionalMACs' => array(
 1386                     'flags' => FILTER_REQUIRE_ARRAY
 1387                 )
 1388             )
 1389         );
 1390         $addMACs = $addMACs['additionalMACs'];
 1391         $addmacs = self::parseMacList($addMACs);
 1392         unset($addMACs);
 1393         $macs = array();
 1394         foreach ((array)$addmacs as &$addmac) {
 1395             if (!$addmac->isValid()) {
 1396                 continue;
 1397             }
 1398             $macs[] = $addmac->__toString();
 1399             unset($addmac);
 1400         }
 1401         $removeMACs = array_diff(
 1402             (array)self::getSubObjectIDs(
 1403                 'MACAddressAssociation',
 1404                 array(
 1405                     'hostID' => $this->obj->get('id'),
 1406                     'primary' => 0,
 1407                     'pending' => 0
 1408                 ),
 1409                 'mac'
 1410             ),
 1411             $macs
 1412         );
 1413         $this
 1414             ->obj
 1415             ->addAddMAC($macs)
 1416             ->removeAddMAC($removeMACs);
 1417     }
 1418     /**
 1419      * Host printers display.
 1420      *
 1421      * @return void
 1422      */
 1423     public function hostPrinters()
 1424     {
 1425         unset(
 1426             $this->headerData,
 1427             $this->templates,
 1428             $this->attributes,
 1429             $this->form,
 1430             $this->data
 1431         );
 1432         $this->headerData = array(
 1433             '<label for="toggler1">'
 1434             . '<input type="checkbox" name="toggle-checkboxprint" class='
 1435             . '"toggle-checkboxprint" id="toggler1"/></label>',
 1436             _('Printer Alias'),
 1437             _('Printer Type')
 1438         );
 1439         $this->templates = array(
 1440             '<label for="printer-${printer_id}">'
 1441             . '<input type="checkbox" name="printer[]" class='
 1442             . '"toggle-print"${is_default} id="printer-${printer_id}" '
 1443             . 'value="${printer_id}"/></label>',
 1444             '<a href="?node=printer&sub=edit&id=${printer_id}">${printer_name}</a>',
 1445             '${printer_type}'
 1446         );
 1447         $this->attributes = array(
 1448             array(
 1449                 'width' => 16,
 1450                 'class' => 'filter-false'
 1451             ),
 1452             array(),
 1453             array()
 1454         );
 1455         Route::listem('printer');
 1456         $Printers = json_decode(
 1457             Route::getData()
 1458         );
 1459         $Printers = $Printers->printers;
 1460         foreach ((array)$Printers as &$Printer) {
 1461             if (!in_array($Printer->id, $this->obj->get('printersnotinme'))) {
 1462                 continue;
 1463             }
 1464             $this->data[] = array(
 1465                 'printer_id' => $Printer->id,
 1466                 'is_default' => (
 1467                     $this->obj->getDefault($Printer->id) ?
 1468                     ' checked' :
 1469                     ''
 1470                 ),
 1471                 'printer_name' => $Printer->name,
 1472                 'printer_type' => (
 1473                     stripos($Printer->config, 'local') !== false ?
 1474                     _('TCP/IP') :
 1475                     $Printer->config
 1476                 )
 1477             );
 1478             unset($Printer);
 1479         }
 1480         echo '<!-- Printers -->';
 1481         echo '<div class="tab-pane fade" id="host-printers">';
 1482         echo '<div class="panel panel-info">';
 1483         echo '<div class="panel-heading text-center">';
 1484         echo '<h4 class="title">';
 1485         echo _('Host Printers');
 1486         echo '</h4>';
 1487         echo '</div>';
 1488         echo '<div class="panel-body">';
 1489         echo '<form class="form-horizontal" method="post" action="'
 1490             . $this->formAction
 1491             . '&tab=host-printers">';
 1492         echo '<div class="panel panel-info">';
 1493         echo '<div class="panel-heading text-center">';
 1494         echo '<h4 class="title">';
 1495         echo _('Host printer configuration');
 1496         echo '</h4>';
 1497         echo '</div>';
 1498         echo '<div class="panel-body">';
 1499         echo '<h5 class="title text-center">';
 1500         echo _('Select management level for this host');
 1501         echo '</h5>';
 1502         echo '<div class="col-xs-offset-4">';
 1503         echo '<div class="radio">';
 1504         echo '<label for="nolevel" data-toggle="tooltip" data-placement="left" '
 1505             . 'title="'
 1506             . _('This setting turns off all FOG Printer Management')
 1507             . '. '
 1508             . _('Although there are multiple levels already')
 1509             . ' '
 1510             . _('between host and global settings')
 1511             . ', '
 1512             . _('this is just another to ensure safety')
 1513             . '.">';
 1514         echo '<input type="radio" name="level" value="0" '
 1515             . 'id="nolevel"'
 1516             . (
 1517                 $this->obj->get('printerLevel') == 0 ?
 1518                 ' checked' :
 1519                 ''
 1520             )
 1521             . '/>';
 1522         echo _('No Printer Management');
 1523         echo '</label>';
 1524         echo '</div>';
 1525         echo '<div class="radio">';
 1526         echo '<label for="addlevel" data-toggle="tooltip" data-placement="left" '
 1527             . 'title="'
 1528             . _(
 1529                 'This setting only adds and removes '
 1530                 . 'printers that are managed by FOG. '
 1531                 . 'If the printer exists in printer '
 1532                 . 'management but is not assigned to a '
 1533                 . 'host, it will remove the printer if '
 1534                 . 'it exists on the unassigned host. '
 1535                 . 'It will add printers to the host '
 1536                 . 'that are assigned.'
 1537             )
 1538             . '">';
 1539         echo '<input type="radio" name="level" value="1" '
 1540             . 'id="addlevel"'
 1541             . (
 1542                 $this->obj->get('printerLevel') == 1 ?
 1543                 ' checked' :
 1544                 ''
 1545             )
 1546             . '/>';
 1547         echo _('FOG Managed Printers');
 1548         echo '</label>';
 1549         echo '</div>';
 1550         echo '<div class="radio">';
 1551         echo '<label for="alllevel" data-toggle="tooltip" data-placement="left" '
 1552             . 'title="'
 1553             . _(
 1554                 'This setting will only allow FOG Assigned '
 1555                 . 'printers to be added to the host. Any '
 1556                 . 'printer that is not assigned will be '
 1557                 . 'removed including non-FOG managed printers.'
 1558             )
 1559             . '">';
 1560         echo '<input type="radio" name="level" value="2" '
 1561             . 'id="alllevel"'
 1562             . (
 1563                 $this->obj->get('printerLevel') == 2 ?
 1564                 ' checked' :
 1565                 ''
 1566             )
 1567             . '/>';
 1568         echo _('Only Assigned Printers');
 1569         echo '</label>';
 1570         echo '</div>';
 1571         echo '</div>';
 1572         echo '<br/>';
 1573         echo '<div class="form-group">';
 1574         echo '<label for="levelup" class="control-label col-xs-4">';
 1575         echo _('Update printer configuration');
 1576         echo '</label>';
 1577         echo '<div class="col-xs-8">';
 1578         echo '<button type="submit" name="levelup" class='
 1579             . '"btn btn-info btn-block" id="levelup">'
 1580             . _('Update')
 1581             . '</button>';
 1582         echo '</div>';
 1583         echo '</div>';
 1584         echo '</div>';
 1585         echo '</div>';
 1586         if (is_array($this->data) && count($this->data) > 0) {
 1587             self::$HookManager
 1588                 ->processEvent(
 1589                     'HOST_ADD_PRINTER',
 1590                     array(
 1591                         'headerData' => &$this->headerData,
 1592                         'data' => &$this->data,
 1593                         'templates' => &$this->templates,
 1594                         'attributes' => &$this->attributes
 1595                     )
 1596                 );
 1597             echo '<div class="text-center">';
 1598             echo '<div class="checkbox">';
 1599             echo '<label for="hostPrinterShow">';
 1600             echo '<input type="checkbox" name="hostPrinterShow" '
 1601                 . 'id="hostPrinterShow"/>';
 1602             echo _('Check here to see what printers can be added');
 1603             echo '</label>';
 1604             echo '</div>';
 1605             echo '</div>';
 1606             echo '<br/>';
 1607             echo '<div class="hiddeninitially printerNotInHost panel panel-info">';
 1608             echo '<div class="panel-heading text-center">';
 1609             echo '<h4 class="title">';
 1610             echo _('Add Printers');
 1611             echo '</h4>';
 1612             echo '</div>';
 1613             echo '<div class="panel-body">';
 1614             $this->render(12);
 1615             echo '<div class="form-group">';
 1616             echo '<label for="updateprinters" class="control-label col-xs-4">';
 1617             echo _('Add selected printers');
 1618             echo '</label>';
 1619             echo '<div class="col-xs-8">';
 1620             echo '<button type="submit" name="updateprinters" class='
 1621                 . '"btn btn-info btn-block" id="updateprinters" value="1">'
 1622                 . _('Add')
 1623                 . '</button>';
 1624             echo '</div>';
 1625             echo '</div>';
 1626             echo '</div>';
 1627             echo '</div>';
 1628         }
 1629         unset(
 1630             $this->data,
 1631             $this->headerData,
 1632             $this->templates,
 1633             $this->attributes
 1634         );
 1635         $this->headerData = array(
 1636             '<label for="toggler2">'
 1637             . '<input type="checkbox" name="toggle-checkbox" class='
 1638             . '"toggle-checkboxAction" id="toggler2"/></label>',
 1639             _('Default'),
 1640             _('Printer Alias'),
 1641             _('Printer Type')
 1642         );
 1643         $this->templates = array(
 1644             '<label for="printerrm-${printer_id}">'
 1645             . '<input type="checkbox" name="printerRemove[]" class='
 1646             . '"toggle-action" id="printerrm-${printer_id}" '
 1647             . 'value="${printer_id}"/></label>',
 1648             '<div class="radio">'
 1649             . '<input type="radio" class="default" '
 1650             . 'name="default" id="printer${printer_id}" '
 1651             . 'value="${printer_id}" ${is_default}/>'
 1652             . '<label for="printer${printer_id}">'
 1653             . '</label>'
 1654             . '</div>',
 1655             '<a href="?node=printer&sub=edit&id=${printer_id}">${printer_name}</a>',
 1656             '${printer_type}'
 1657         );
 1658         $this->attributes = array(
 1659             array(
 1660                 'class' => 'filter-false col-xs-1'
 1661             ),
 1662             array(
 1663                 'class' => 'filter-false col-xs-1'
 1664             ),
 1665             array(),
 1666             array()
 1667         );
 1668         foreach ((array)$Printers as $Printer) {
 1669             if (!in_array($Printer->id, $this->obj->get('printers'))) {
 1670                 continue;
 1671             }
 1672             $this->data[] = array(
 1673                 'printer_id' => $Printer->id,
 1674                 'is_default' => (
 1675                     $this->obj->getDefault($Printer->id) ?
 1676                     ' checked' :
 1677                     ''
 1678                 ),
 1679                 'printer_name' => $Printer->name,
 1680                 'printer_type' => (
 1681                     stripos($Printer->config, 'local') !== false ?
 1682                     _('TCP/IP') :
 1683                     $Printer->config
 1684                 )
 1685             );
 1686             unset($Printer);
 1687         }
 1688         if (is_array($this->data) && count($this->data) > 0) {
 1689             self::$HookManager
 1690                 ->processEvent(
 1691                     'HOST_EDIT_PRINTER',
 1692                     array(
 1693                         'headerData' => &$this->headerData,
 1694                         'data' => &$this->data,
 1695                         'templates' => &$this->templates,
 1696                         'attributes' => &$this->attributes
 1697                     )
 1698                 );
 1699             echo '<div class="panel panel-info">';
 1700             echo '<div class="panel-heading text-center">';
 1701             echo '<h4 class="title">';
 1702             echo _('Update/Remove printers');
 1703             echo '</h4>';
 1704             echo '</div>';
 1705             echo '<div class="panel-body">';
 1706             $this->render(12);
 1707             echo '<div class="form-group">';
 1708             echo '<label for="defaultsel" class="control-label col-xs-4">';
 1709             echo _('Update default printer');
 1710             echo '</label>';
 1711             echo '<div class="col-xs-8">';
 1712             echo '<button type="submit" name="defaultsel" class='
 1713                 . '"btn btn-info btn-block" id="defaultsel">'
 1714                 . _('Update')
 1715                 . '</button>';
 1716             echo '</div>';
 1717             echo '</div>';
 1718             echo '<div class="form-group">';
 1719             echo '<label for="printdel" class="control-label col-xs-4">';
 1720             echo _('Remove selected printers');
 1721             echo '</label>';
 1722             echo '<div class="col-xs-8">';
 1723             echo '<button type="submit" name="printdel" class='
 1724                 . '"btn btn-danger btn-block" id="printdel">'
 1725                 . _('Remove')
 1726                 . '</button>';
 1727             echo '</div>';
 1728             echo '</div>';
 1729             echo '</div>';
 1730             echo '</div>';
 1731         }
 1732         echo '</form>';
 1733         echo '</div>';
 1734         echo '</div>';
 1735         echo '</div>';
 1736         unset(
 1737             $this->headerData,
 1738             $this->templates,
 1739             $this->attributes,
 1740             $this->form,
 1741             $this->data
 1742         );
 1743     }
 1744     /**
 1745      * Host snapins.
 1746      *
 1747      * @return void
 1748      */
 1749     public function hostSnapins()
 1750     {
 1751         unset(
 1752             $this->headerData,
 1753             $this->templates,
 1754             $this->attributes,
 1755             $this->form,
 1756             $this->data
 1757         );
 1758         $this->headerData = array(
 1759             '<label for="toggler3">'
 1760             . '<input type="checkbox" name="toggle-checkboxsnapin" class='
 1761             . '"toggle-checkboxsnapin" id="toggler3"/></label>',
 1762             _('Snapin Name'),
 1763             _('Snapin Created')
 1764         );
 1765         $this->templates = array(
 1766             '<label for="snapin-${snapin_id}">'
 1767             . '<input type="checkbox" name="snapin[]" class='
 1768             . '"toggle-snapin" id="snapin-${snapin_id}" '
 1769             . 'value="${snapin_id}"/></label>',
 1770             '<a href="?node=snapin&sub=edit&id=${snapin_id}">${snapin_name}</a>',
 1771             '${snapin_created}'
 1772         );
 1773         $this->attributes = array(
 1774             array(
 1775                 'width' => 16,
 1776                 'class' => 'filter-false'
 1777             ),
 1778             array(),
 1779             array()
 1780         );
 1781         Route::listem('snapin');
 1782         $Snapins = json_decode(
 1783             Route::getData()
 1784         );
 1785         $Snapins = $Snapins->snapins;
 1786         foreach ((array)$Snapins as &$Snapin) {
 1787             if (!in_array($Snapin->id, $this->obj->get('snapinsnotinme'))) {
 1788                 continue;
 1789             }
 1790             $this->data[] = array(
 1791                 'snapin_id' => $Snapin->id,
 1792                 'snapin_name' => $Snapin->name,
 1793                 'snapin_created' => self::niceDate(
 1794                     $Snapin->createdTime
 1795                 )->format('Y-m-d H:i:s')
 1796             );
 1797             unset($Snapin);
 1798         }
 1799         echo '<!-- Snapins -->';
 1800         echo '<div id="host-snapins" class="tab-pane fade">';
 1801         echo '<div class="panel panel-info">';
 1802         echo '<div class="panel-heading text-center">';
 1803         echo '<h4 class="title">';
 1804         echo _('Host Snapins');
 1805         echo '</h4>';
 1806         echo '</div>';
 1807         echo '<div class="panel-body">';
 1808         echo '<form class="form-horizontal" method="post" action="'
 1809             . $this->formAction
 1810             . '&tab=host-snapins">';
 1811         if (is_array($this->data) && count($this->data) > 0) {
 1812             self::$HookManager
 1813                 ->processEvent(
 1814                     'HOST_ADD_SNAPIN',
 1815                     array(
 1816                         'headerData' => &$this->headerData,
 1817                         'data' => &$this->data,
 1818                         'templates' => &$this->templates,
 1819                         'attributes' => &$this->attributes
 1820                     )
 1821                 );
 1822             echo '<div class="text-center">';
 1823             echo '<div class="checkbox">';
 1824             echo '<label for="hostSnapinShow">';
 1825             echo '<input type="checkbox" name="hostSnapinShow" '
 1826                 . 'id="hostSnapinShow"/>';
 1827             echo _('Check here to see what snapins can be added');
 1828             echo '</label>';
 1829             echo '</div>';
 1830             echo '</div>';
 1831             echo '<br/>';
 1832             echo '<div class="hiddeninitially snapinNotInHost panel panel-info">';
 1833             echo '<div class="panel-heading text-center">';
 1834             echo '<h4 class="title">';
 1835             echo _('Add Snapins');
 1836             echo '</h4>';
 1837             echo '</div>';
 1838             echo '<div class="panel-body">';
 1839             $this->render(12);
 1840             echo '<div class="form-group">';
 1841             echo '<label for="updatesnapins" class="control-label col-xs-4">';
 1842             echo _('Add selected snapins');
 1843             echo '</label>';
 1844             echo '<div class="col-xs-8">';
 1845             echo '<button type="submit" name="updatesnapins" class='
 1846                 . '"btn btn-info btn-block" id="updatesnapins">'
 1847                 . _('Add')
 1848                 . '</button>';
 1849             echo '</div>';
 1850             echo '</div>';
 1851             echo '</div>';
 1852             echo '</div>';
 1853         }
 1854         unset(
 1855             $this->headerData,
 1856             $this->templates,
 1857             $this->attributes,
 1858             $this->form,
 1859             $this->data
 1860         );
 1861         $this->headerData = array(
 1862             '<label for="toggler4">'
 1863             . '<input type="checkbox" name="toggle-checkbox" class='
 1864             . '"toggle-checkboxAction" id="toggler4"/></label>',
 1865             _('Snapin Name'),
 1866             _('Snapin Created')
 1867         );
 1868         $this->templates = array(
 1869             '<label for="snapinrm-${snapin_id}">'
 1870             . '<input type="checkbox" name="snapinRemove[]" class='
 1871             . '"toggle-action" id="snapinrm-${snapin_id}" '
 1872             . 'value="${snapin_id}"/></label>',
 1873             '<a href="?node=snapin&sub=edit&id=${snapin_id}">${snapin_name}</a>',
 1874             '${snapin_created}'
 1875         );
 1876         $this->attributes = array(
 1877             array(
 1878                 'width' => 16,
 1879                 'class' => 'filter-false'
 1880             ),
 1881             array(),
 1882             array()
 1883         );
 1884         foreach ((array)$Snapins as $Snapin) {
 1885             if (!in_array($Snapin->id, $this->obj->get('snapins'))) {
 1886                 continue;
 1887             }
 1888             $this->data[] = array(
 1889                 'snapin_id' => $Snapin->id,
 1890                 'snapin_name' => $Snapin->name,
 1891                 'snapin_created' => self::niceDate(
 1892                     $Snapin->createdTime
 1893                 )->format('Y-m-d H:i:s')
 1894             );
 1895             unset($Snapin);
 1896         }
 1897         if (is_array($this->data) && count($this->data) > 0) {
 1898             self::$HookManager
 1899                 ->processEvent(
 1900                     'HOST_EDIT_SNAPIN',
 1901                     array(
 1902                         'headerData' => &$this->headerData,
 1903                         'data' => &$this->data,
 1904                         'templates' => &$this->templates,
 1905                         'attributes' => &$this->attributes
 1906                     )
 1907                 );
 1908             echo '<div class="panel panel-info">';
 1909             echo '<div class="panel-heading text-center">';
 1910             echo '<h4 class="title">';
 1911             echo _('Remove snapins');
 1912             echo '</h4>';
 1913             echo '</div>';
 1914             echo '<div class="panel-body">';
 1915             $this->render(12);
 1916             echo '<div class="form-group">';
 1917             echo '<label for="snapdel" class="control-label col-xs-4">';
 1918             echo _('Remove selected snapins');
 1919             echo '</label>';
 1920             echo '<div class="col-xs-8">';
 1921             echo '<button type="submit" name="snapdel" class='
 1922                 . '"btn btn-danger btn-block" id="snapdel">'
 1923                 . _('Remove')
 1924                 . '</button>';
 1925             echo '</div>';
 1926             echo '</div>';
 1927             echo '</div>';
 1928             echo '</div>';
 1929         }
 1930         echo '</form>';
 1931         echo '</div>';
 1932         echo '</div>';
 1933         echo '</div>';
 1934         unset(
 1935             $this->headerData,
 1936             $this->templates,
 1937             $this->attributes,
 1938             $this->form,
 1939             $this->data
 1940         );
 1941     }
 1942     /**
 1943      * Display's the host service stuff
 1944      *
 1945      * @return void
 1946      */
 1947     public function hostService()
 1948     {
 1949         // Client module stuff
 1950         unset(
 1951             $this->data,
 1952             $this->form,
 1953             $this->headerData,
 1954             $this->templates,
 1955             $this->attributes
 1956         );
 1957         $dcnote = sprintf(
 1958             '%s. %s. %s %s.',
 1959             _('This module is only used on the old client'),
 1960             _('The old client is what was distributed with FOG 1.2.0 and earlier'),
 1961             _('This module did not work past Windows XP due to'),
 1962             _('UAC introduced in Vista and up')
 1963         );
 1964         $gfnote = sprintf(
 1965             '%s. %s %s. %s %s %s. %s.',
 1966             _('This module is only used on the old client'),
 1967             _('The old client is what was distributed with'),
 1968             _('FOG 1.2.0 and earlier'),
 1969             _('This module has been replaced in the new client'),
 1970             _('and the equivalent module for what Green'),
 1971             _('FOG did is now called Power Management'),
 1972             _('This is only here to maintain old client operations')
 1973         );
 1974         $ucnote = sprintf(
 1975             '%s. %s %s. %s %s.',
 1976             _('This module is only used on the old client'),
 1977             _('The old client is what was distributed with'),
 1978             _('FOG 1.2.0 and earlier'),
 1979             _('This module did not work past Windows XP due'),
 1980             _('to UAC introduced in Vista and up')
 1981         );
 1982         $cunote = sprintf(
 1983             '%s (%s) %s.',
 1984             _('This module is only used'),
 1985             _('with modules and config'),
 1986             _('on the old client')
 1987         );
 1988         $this->attributes = array(
 1989             array('class' => 'col-xs-4'),
 1990             array('class' => 'col-xs-4 form-group'),
 1991             array('class' => 'col-xs-4'),
 1992         );
 1993         $this->templates = array(
 1994             '${mod_name}',
 1995             '${input}',
 1996             '${span}',
 1997         );
 1998         $this->data[] = array(
 1999             'mod_name' => '<label for="checkAll">'
 2000             . _('Select/Deselect All')
 2001             . '</label>',
 2002             'input' => '<div class="checkbox">'
 2003             . '<input type="checkbox" class="checkboxes" '
 2004             . 'id="checkAll" name="checkAll" value="checkAll"/>'
 2005             . '</div>',
 2006             'span' => ' '
 2007         );
 2008         $moduleName = self::getGlobalModuleStatus();
 2009         $ModuleOn = $this->obj->get('modules');
 2010         Route::listem('module');
 2011         $Modules = json_decode(
 2012             Route::getData()
 2013         );
 2014         $Modules = $Modules->modules;
 2015         foreach ((array)$Modules as &$Module) {
 2016             switch ($Module->shortName) {
 2017             case 'dircleanup':
 2018                 $note = sprintf(
 2019                     '<i class="icon fa fa-exclamation-triangle '
 2020                     . 'fa-1x hand" '
 2021                     . 'data-toggle="tooltip" data-placement="right" '
 2022                     . 'title="%s"></i>',
 2023                     $dcnote
 2024                 );
 2025                 break;
 2026             case 'greenfog':
 2027                 $note = sprintf(
 2028                     '<i class="icon fa fa-exclamation-triangle '
 2029                     . 'fa-1x hand" '
 2030                     . 'data-toggle="tooltip" data-placement="right" '
 2031                     . 'title="%s"></i>',
 2032                     $gfnote
 2033                 );
 2034                 break;
 2035             case 'usercleanup':
 2036                 $note = sprintf(
 2037                     '<i class="icon fa fa-exclamation-triangle '
 2038                     . 'fa-1x hand" '
 2039                     . 'data-toggle="tooltip" data-placement="right" '
 2040                     . 'title="%s"></i>',
 2041                     $ucnote
 2042                 );
 2043                 break;
 2044             case 'clientupdater':
 2045                 $note = sprintf(
 2046                     '<i class="icon fa fa-exclamation-triangle '
 2047                     . 'fa-1x hand" '
 2048                     . 'data-toggle="tooltip" data-placement="right" '
 2049                     . 'title="%s"></i>',
 2050                     $cunote
 2051                 );
 2052                 break;
 2053             default:
 2054                 $note = '';
 2055                 break;
 2056             }
 2057             if ($note) {
 2058                 $note = '<div class="col-xs-2">'
 2059                     . $note
 2060                     . '</div>';
 2061             }
 2062             $this->data[] = array(
 2063                 'input' => sprintf(
 2064                     '<div class="checkbox">'
 2065                     . '<input id="%s"%stype="checkbox" name="modules[]" value="%s"'
 2066                     . '%s%s/>'
 2067                     . '</div>',
 2068                     $Module->shortName,
 2069                     (
 2070                         ($moduleName[$Module->shortName]
 2071                         || $moduleName[$Module->shortName])
 2072                         && $Module->isDefault ?
 2073                         ' class="checkboxes" ':
 2074                         ''
 2075                     ),
 2076                     $Module->id,
 2077                     (
 2078                         in_array($Module->id, $ModuleOn) ?
 2079                         ' checked' :
 2080                         ''
 2081                     ),
 2082                     (
 2083                         !$moduleName[$Module->shortName] ?
 2084                         ' disabled' :
 2085                         ''
 2086                     ),
 2087                     $Module->shortName
 2088                 ),
 2089                 'span' => sprintf(
 2090                     '<div class="col-xs-2">'
 2091                     . '<span class="icon fa fa-question fa-1x hand" '
 2092                     . 'data-toggle="tooltip" data-placement="left" '
 2093                     . 'title="%s"></span>'
 2094                     . '</div>'
 2095                     . '%s',
 2096                     str_replace(
 2097                         '"',
 2098                         '\"',
 2099                         $Module->description
 2100                     ),
 2101                     $note
 2102                 ),
 2103                 'mod_name' => '<label for="'
 2104                 . $Module->shortName
 2105                 . '">'
 2106                 . $Module->name
 2107                 . '</label>',
 2108             );
 2109             unset($Module);
 2110         }
 2111         unset($moduleName, $ModuleOn);
 2112         self::$HookManager
 2113             ->processEvent(
 2114                 'HOST_EDIT_SERVICE',
 2115                 array(
 2116                     'headerData' => &$this->headerData,
 2117                     'data' => &$this->data,
 2118                     'templates' => &$this->templates,
 2119                     'attributes' => &$this->attributes
 2120                 )
 2121             );
 2122         echo '<!-- Service Configuration -->';
 2123         echo '<div class="tab-pane fade" id="host-service">';
 2124         echo '<div class="panel panel-info">';
 2125         echo '<div class="panel-heading text-center">';
 2126         echo '<h4 class="title">';
 2127         echo _('Host FOG Client Module configuration');
 2128         echo '</h4>';
 2129         echo '</div>';
 2130         echo '<div class="panel-body">';
 2131         echo '<form class="form-horizontal" method="post" action="'
 2132             . $this->formAction
 2133             . '&tab=host-service">';
 2134         echo '<div class="panel panel-info">';
 2135         echo '<div class="panel-heading text-center">';
 2136         echo '<h4 class="title">';
 2137         echo _('Host module settings');
 2138         echo '</h4>';
 2139         echo '</div>';
 2140         echo '<div class="panel-body">';
 2141         $this->render(12);
 2142         echo '<label class="control-label col-xs-4" for="updatestatus">';
 2143         echo _('Update module configurations');
 2144         echo '</label>';
 2145         echo '<div class="col-xs-8">';
 2146         echo '<button type="submit" name="updatestatus" id="updatestatus" '
 2147             . 'class="btn btn-info btn-block">';
 2148         echo _('Update');
 2149         echo '</button>';
 2150         echo '<input type="hidden" name="modulesend" value="1"/>';
 2151         echo '</div>';
 2152         echo '</div>';
 2153         echo '</div>';
 2154         echo '</form>';
 2155         unset(
 2156             $this->data,
 2157             $this->form,
 2158             $this->headerData,
 2159             $this->templates,
 2160             $this->attributes
 2161         );
 2162         $this->attributes = array(
 2163             array(
 2164                 'class' => 'col-xs-4'
 2165             ),
 2166             array(
 2167                 'class' => 'col-xs-4 form-group'
 2168             ),
 2169             array(
 2170                 'class' => 'col-xs-4'
 2171             )
 2172         );
 2173         $this->templates = array(
 2174             '${field}',
 2175             '${input}',
 2176             '${span}',
 2177         );
 2178         list(
 2179             $refresh,
 2180             $width,
 2181             $height,
 2182         ) = self::getSubObjectIDs(
 2183             'Service',
 2184             array(
 2185                 'name' => array(
 2186                     'FOG_CLIENT_DISPLAYMANAGER_R',
 2187                     'FOG_CLIENT_DISPLAYMANAGER_X',
 2188                     'FOG_CLIENT_DISPLAYMANAGER_Y',
 2189                 )
 2190             ),
 2191             'description',
 2192             false,
 2193             'AND',
 2194             'name',
 2195             false,
 2196             false
 2197         );
 2198         $names = array(
 2199             'x' => array(
 2200                 'width',
 2201                 $width,
 2202                 _('Screen Width (in pixels)'),
 2203             ),
 2204             'y' => array(
 2205                 'height',
 2206                 $height,
 2207                 _('Screen Height (in pixels)'),
 2208             ),
 2209             'r' => array(
 2210                 'refresh',
 2211                 $refresh,
 2212                 _('Screen Refresh Rate (in Hz)'),
 2213             )
 2214         );
 2215         foreach ($names as $name => &$get) {
 2216             $this->data[] = array(
 2217                 'input' => sprintf(
 2218                     '<div class="input-group">'
 2219                     . '<input type="number" id="%s" name="%s" value="%s" '
 2220                     . 'class="form-control"/>'
 2221                     . '</div>',
 2222                     $name,
 2223                     $name,
 2224                     $this->obj->getDispVals($get[0])
 2225                 ),
 2226                 'span' => sprintf(
 2227                     '<div class="col-xs-2">'
 2228                     . '<span class="icon fa fa-question fa-1x hand" '
 2229                     . 'data-toggle="tooltip" data-placement="right" '
 2230                     . 'title="%s"></span>'
 2231                     . '</div>',
 2232                     $get[1]
 2233                 ),
 2234                 'field' => '<label for="'
 2235                 . $name
 2236                 . '">'
 2237                 . $get[2]
 2238                 . '</label>',
 2239             );
 2240             unset($get);
 2241         }
 2242         self::$HookManager
 2243             ->processEvent(
 2244                 'HOST_EDIT_DISPSERV',
 2245                 array(
 2246                     'headerData' => &$this->headerData,
 2247                     'data' => &$this->data,
 2248                     'templates' => &$this->templates,
 2249                     'attributes' => &$this->attributes
 2250                 )
 2251             );
 2252         echo '<form class="form-horizontal" method="post" action="'
 2253             . $this->formAction
 2254             . '&tab=host-service">';
 2255         echo '<div class="panel panel-info">';
 2256         echo '<div class="panel-heading text-center">';
 2257         echo '<h4 class="title">';
 2258         echo _('Host Screen Resolution');
 2259         echo '</h4>';
 2260         echo '</div>';
 2261         echo '<div class="panel-body">';
 2262         $this->render(12);
 2263         echo '<label class="control-label col-xs-4" for="updatedisplay">';
 2264         echo _('Update display resolution');
 2265         echo '</label>';
 2266         echo '<div class="col-xs-8">';
 2267         echo '<button type="submit" name="updatedisplay" id="updatedisplay" '
 2268             . 'class="btn btn-info btn-block">';
 2269         echo _('Update');
 2270         echo '</button>';
 2271         echo '<input type="hidden" name="dispupdate" value="1"/>';
 2272         echo '</div>';
 2273         echo '</div>';
 2274         echo '</div>';
 2275         echo '</form>';
 2276         unset(
 2277             $this->data,
 2278             $this->form,
 2279             $this->headerData,
 2280             $this->templates,
 2281             $this->attributes
 2282         );
 2283         $this->attributes = array(
 2284             array('class' => 'col-xs-4'),
 2285             array('class' => 'col-xs-4 form-group'),
 2286             array('class' => 'col-xs-4')
 2287         );
 2288         $this->templates = array(
 2289             '${field}',
 2290             '${input}',
 2291             '${desc}',
 2292         );
 2293         $alodesc = self::getClass('Service')
 2294             ->set('name', 'FOG_CLIENT_AUTOLOGOFF_MIN')
 2295             ->load('name')
 2296             ->get('description');
 2297         $this->data[] = array(
 2298             'field' => '<label for="tme">'
 2299             . _('Auto Log Out Time (in minutes)')
 2300             . '</label>',
 2301             'input' => '<div class="input-group">'
 2302             . '<input type="number" name="tme" value="${value}" class='
 2303             . '"form-control" id="tme"/>'
 2304             . '</div>',
 2305             'desc' => '<div class="col-xs-2">'
 2306             . '<span class="icon fa fa-question fa-1x hand" '
 2307             . 'data-toggle="tooltip" data-placement="right" '
 2308             . 'title="${serv_desc}"></span>'
 2309             . '</div>',
 2310             'value' => $this->obj->getAlo(),
 2311             'serv_desc' => $alodesc,
 2312         );
 2313         self::$HookManager
 2314             ->processEvent(
 2315                 'HOST_EDIT_ALO',
 2316                 array(
 2317                     'headerData' => &$this->headerData,
 2318                     'data' => &$this->data,
 2319                     'templates' => &$this->templates,
 2320                     'attributes' => &$this->attributes
 2321                 )
 2322             );
 2323         echo '<form class="form-horizontal" method="post" action="'
 2324             . $this->formAction
 2325             . '&tab=host-service">';
 2326         echo '<div class="panel panel-info">';
 2327         echo '<div class="panel-heading text-center">';
 2328         echo '<h4 class="title">';
 2329         echo _('Host Auto Logout');
 2330         echo '</h4>';
 2331         echo '</div>';
 2332         echo '<div class="panel-body">';
 2333         $this->render(12);
 2334         echo '<label class="control-label col-xs-4" for="updatealo">';
 2335         echo _('Update auto-logout time');
 2336         echo '</label>';
 2337         echo '<div class="col-xs-8">';
 2338         echo '<button type="submit" name="updatealo" id="updatealo" '
 2339             . 'class="btn btn-info btn-block">';
 2340         echo _('Update');
 2341         echo '</button>';
 2342         echo '<input type="hidden" name="alosend" value="1"/>';
 2343         echo '</div>';
 2344         echo '</div>';
 2345         echo '</div>';
 2346         echo '</form>';
 2347         echo '</div>';
 2348         echo '</div>';
 2349         echo '</div>';
 2350         unset(
 2351             $this->data,
 2352             $this->form,
 2353             $this->headerData,
 2354             $this->templates,
 2355             $this->attributes
 2356         );
 2357     }
 2358     /**
 2359      * Displays Host Inventory
 2360      *
 2361      * @return void
 2362      */
 2363     public function hostInventory()
 2364     {
 2365         unset(
 2366             $this->data,
 2367             $this->form,
 2368             $this->headerData,
 2369             $this->templates,
 2370             $this->attributes
 2371         );
 2372         $this->attributes = array(
 2373             array('class' => 'col-xs-4'),
 2374             array('class' => 'col-xs-8 form-group'),
 2375         );
 2376         $this->templates = array(
 2377             '${field}',
 2378             '${input}',
 2379         );
 2380         $cpus = array('cpuman', 'spuversion');
 2381         foreach ($cpus as &$x) {
 2382             $this->obj->get('inventory')
 2383                 ->set(
 2384                     $x,
 2385                     implode(
 2386                         ' ',
 2387                         array_unique(
 2388                             explode(
 2389                                 ' ',
 2390                                 $this->obj->get('inventory')->get($x)
 2391                             )
 2392                         )
 2393                     )
 2394                 )
 2395                 ->set('hostID', $this->obj->get('id'));
 2396             unset($x);
 2397         }
 2398         $Inv = $this->obj->get('inventory');
 2399         $puser = $Inv->get('primaryUser');
 2400         $other1 = $Inv->get('other1');
 2401         $other2 = $Inv->get('other2');
 2402         $sysman = $Inv->get('sysman');
 2403         $sysprod = $Inv->get('sysproduct');
 2404         $sysver = $Inv->get('sysversion');
 2405         $sysser = $Inv->get('sysserial');
 2406         $systype = $Inv->get('systype');
 2407         $sysuuid = $Inv->get('sysuuid');
 2408         $biosven = $Inv->get('biosvendor');
 2409         $biosver = $Inv->get('biosversion');
 2410         $biosdate = $Inv->get('biosdate');
 2411         $mbman = $Inv->get('mbman');
 2412         $mbprod = $Inv->get('mbproductname');
 2413         $mbver = $Inv->get('mbversion');
 2414         $mbser = $Inv->get('mbserial');
 2415         $mbast = $Inv->get('mbasset');
 2416         $cpuman = $Inv->get('cpuman');
 2417         $cpuver = $Inv->get('cpuversion');
 2418         $cpucur = $Inv->get('cpucurrent');
 2419         $cpumax = $Inv->get('cpumax');
 2420         $mem = $Inv->getMem();
 2421         $hdmod = $Inv->get('hdmodel');
 2422         $hdfirm = $Inv->get('hdfirmware');
 2423         $hdser = $Inv->get('hdserial');
 2424         $caseman = $Inv->get('caseman');
 2425         $casever = $Inv->get('caseversion');
 2426         $caseser = $Inv->get('caseserial');
 2427         $caseast = $Inv->get('caseasset');
 2428         $fields = array(
 2429             '<label for="pu">'
 2430             . _('Primary User')
 2431             . '</label>' => '<div class="input-group">'
 2432             . '<input class="form-control" type="text" value="'
 2433             . $puser
 2434             . '" name="pu" id="pu"/>'
 2435             . '</div>',
 2436             '<label for="other1"/>'
 2437             . _('Other Tag #1')
 2438             . '</label>' => '<div class="input-group">'
 2439             . '<input class="form-control" type="text" value="'
 2440             . $other1
 2441             . '" name="other1" id="other1"/>'
 2442             . '</div>',
 2443             '<label for="other2"/>'
 2444             . _('Other Tag #2')
 2445             . '</label>' => '<div class="input-group">'
 2446             . '<input class="form-control" type="text" value="'
 2447             . $other2
 2448             . '" name="other2" id="other2"/>'
 2449             . '</div>',
 2450             _('System Manufacturer') => $sysman,
 2451             _('System Product') => $sysprod,
 2452             _('System Version') => $sysver,
 2453             _('System Serial Number') => $sysser,
 2454             _('System UUID') => $sysuuid,
 2455             _('System Type') => $systype,
 2456             _('BIOS Vendor') => $biosven,
 2457             _('BIOS Version') => $biosver,
 2458             _('BIOS Date') => $biosdate,
 2459             _('Motherboard Manufacturer') => $mbman,
 2460             _('Motherboard Product Name') => $mbprod,
 2461             _('Motherboard Version') => $mbver,
 2462             _('Motherboard Serial Number') => $mbser,
 2463             _('Motherboard Asset Tag') => $mbast,
 2464             _('CPU Manufacturer') => $cpuman,
 2465             _('CPU Version') => $cpuver,
 2466             _('CPU Normal Speed') => $cpucur,
 2467             _('CPU Max Speed') => $cpumax,
 2468             _('Memory') => $mem,
 2469             _('Hard Disk Model') => $hdmod,
 2470             _('Hard Disk Firmware') => $hdfirm,
 2471             _('Hard Disk Serial Number') => $hdser,
 2472             _('Chassis Manufacturer') => $caseman,
 2473             _('Chassis Version') => $casever,
 2474             _('Chassis Serial') => $caseser,
 2475             _('Chassis Asset') => $caseast,
 2476             '<label for="updateinv">'
 2477             . _('Make Changes?')
 2478             . '</label>' => '<button name="update" type="submit" class="'
 2479             . 'btn btn-info btn-block" id="updateinv">'
 2480             . _('Update')
 2481             . '</button>'
 2482         );
 2483         $this->title = _('Host Hardware Inventory');
 2484         if ($this->obj->get('inventory')->isValid()) {
 2485             array_walk($fields, $this->fieldsToData);
 2486         }
 2487         self::$HookManager
 2488             ->processEvent(
 2489                 'HOST_INVENTORY',
 2490                 array(
 2491                     'headerData' => &$this->headerData,
 2492                     'data' => &$this->data,
 2493                     'templates' => &$this->templates,
 2494                     'attributes' => &$this->attributes
 2495                 )
 2496             );
 2497         echo '<!-- Inventory -->';
 2498         echo '<div class="tab-pane fade" id="host-hardware-inventory">';
 2499         echo '<div class="panel panel-info">';
 2500         echo '<div class="panel-heading text-center">';
 2501         echo '<h4 class="title">';
 2502         echo $this->title;
 2503         echo '</h4>';
 2504         echo '</div>';
 2505         echo '<div class="panel-body">';
 2506         echo '<form class="form-horizontal" method="post" action="'
 2507             . $this->formAction
 2508             . '&tab=host-hardware-inventory">';
 2509         $this->render(12);
 2510         echo '</form>';
 2511         echo '</div>';
 2512         echo '</div>';
 2513         echo '</div>';
 2514         unset(
 2515             $this->data,
 2516             $this->form,
 2517             $this->headerData,
 2518             $this->templates,
 2519             $this->attributes
 2520         );
 2521     }
 2522     /**
 2523      * Display host virus information.
 2524      *
 2525      * @return void
 2526      */
 2527     public function hostVirus()
 2528     {
 2529         unset(
 2530             $this->data,
 2531             $this->form,
 2532             $this->headerData,
 2533             $this->templates,
 2534             $this->attributes
 2535         );
 2536         $this->headerData = array(
 2537             _('Virus Name'),
 2538             _('File'),
 2539             _('Mode'),
 2540             _('Date'),
 2541             _('Clear'),
 2542         );
 2543         $this->attributes = array(
 2544             array(),
 2545             array(),
 2546             array(),
 2547             array(),
 2548             array(),
 2549         );
 2550         $this->templates = array(
 2551             '<a href="http://www.google.com/search?q='
 2552             . '${virus_name}" target="_blank">${virus_name}</a>',
 2553             '${virus_file}',
 2554             '${virus_mode}',
 2555             '${virus_date}',
 2556             sprintf(
 2557                 '<input type="checkbox" id="vir_del${virus_id}" '
 2558                 . 'class="delvid" name="delvidarr[]" value="${virus_id}"/>'
 2559                 . '<label for="${virus_id}" class="icon icon-hand" '
 2560                 . 'title="%s ${virus_name}">'
 2561                 . '<i class="icon fa fa-minus-circle link"></i>'
 2562                 . '</label>',
 2563                 _('Delete')
 2564             ),
 2565         );
 2566         Route::listem(
 2567             'virus',
 2568             'name',
 2569             false,
 2570             array('mac' => $this->obj->getMyMacs())
 2571         );
 2572         $Viruses = json_decode(
 2573             Route::getData()
 2574         );
 2575         $Viruses = $Viruses->viruss;
 2576         foreach ((array)$Viruses as &$Virus) {
 2577             if (!in_array($Virus->mac, $this->obj->getMyMacs())) {
 2578                 continue;
 2579             }
 2580             switch (strtolower($Virus->mode)) {
 2581             case 'q':
 2582                 $mode = _('Quarantine');
 2583                 break;
 2584             case 's':
 2585                 $mode = _('Report');
 2586                 break;
 2587             default:
 2588                 $mode = _('N/A');
 2589                 break;
 2590             }
 2591             $this->data[] = array(
 2592                 'virus_name' => $Virus->name,
 2593                 'virus_file' => $Virus->file,
 2594                 'virus_mode' => $mode,
 2595                 'virus_date' => $Virus->date,
 2596                 'virus_id' => $Virus->id,
 2597             );
 2598             unset($Virus);
 2599         }
 2600         self::$HookManager
 2601             ->processEvent(
 2602                 'HOST_VIRUS',
 2603                 array(
 2604                     'headerData' => &$this->headerData,
 2605                     'data' => &$this->data,
 2606                     'templates' => &$this->templates,
 2607                     'attributes' => &$this->attributes
 2608                 )
 2609             );
 2610         $paneltype = 'info';
 2611         if (is_array($this->data) && count($this->data) > 0) {
 2612             $paneltype = 'warning';
 2613         }
 2614         echo '<!-- Virus -->';
 2615         echo '<div class="tab-pane fade" id="host-virus-history">';
 2616         echo '<div class="panel panel-info">';
 2617         echo '<div class="panel-heading text-center">';
 2618         echo '<h4 class="title">';
 2619         echo _('Host Virus History');
 2620         echo '</h4>';
 2621         echo '</div>';
 2622         echo '<div class="panel-body">';
 2623         echo '<form class="form-horizontal" method="post" action="'
 2624             . $this->formAction
 2625             . '&tab=host-virus-history">';
 2626         echo '<h4 class="title text-center">';
 2627         echo '<a href="#">';
 2628         echo '<div class="checkbox">';
 2629         echo '<input type="checkbox" class="delvid" id="all" '
 2630             . 'name="delvid" value="all"/>';
 2631         echo '<label for="all">';
 2632         echo _('Clear all history');
 2633         echo '</label>';
 2634         echo '</div>';
 2635         echo '</a>';
 2636         echo '</h4>';
 2637         echo '<div class="panel panel-'
 2638             . $paneltype
 2639             . '">';
 2640         echo '<div class="panel-heading text-center">';
 2641         echo '<h4 class="title">';
 2642         echo _('Virus Report');
 2643         echo '</h4>';
 2644         echo '</div>';
 2645         echo '<div class="panel-body">';
 2646         $this->render(12);
 2647         echo '</div>';
 2648         echo '</div>';
 2649         echo '</form>';
 2650         echo '</div>';
 2651         echo '</div>';
 2652         echo '</div>';
 2653         unset(
 2654             $this->data,
 2655             $this->form,
 2656             $this->headerData,
 2657             $this->templates,
 2658             $this->attributes
 2659         );
 2660     }
 2661     /**
 2662      * Display Login History for Host.
 2663      *
 2664      * @return void
 2665      */
 2666     public function hostLoginHistory()
 2667     {
 2668         unset(
 2669             $this->data,
 2670             $this->form,
 2671             $this->headerData,
 2672             $this->templates,
 2673             $this->attributes
 2674         );
 2675         $this->headerData = array(
 2676             _('Time'),
 2677             _('Action'),
 2678             _('Username'),
 2679             _('Description')
 2680         );
 2681         $this->attributes = array(
 2682             array(),
 2683             array(),
 2684             array(),
 2685             array(),
 2686         );
 2687         $this->templates = array(
 2688             '${user_time}',
 2689             '${action}',
 2690             '${user_name}',
 2691             '${user_desc}',
 2692         );
 2693         $dte = filter_input(INPUT_GET, 'dte');
 2694         if (!$dte) {
 2695             self::niceDate()->format('Y-m-d');
 2696         }
 2697         $Dates = self::getSubObjectIDs(
 2698             'UserTracking',
 2699             array(
 2700                 'id' => $this->obj->get('users')
 2701             ),
 2702             'date'
 2703         );
 2704         if (count($Dates) > 0) {
 2705             rsort($Dates);
 2706             $dateSel = self::selectForm(
 2707                 'dte',
 2708                 $Dates,
 2709                 $dte,
 2710                 false,
 2711                 'loghist-date'
 2712             );
 2713         }
 2714         Route::listem(
 2715             'usertracking',
 2716             'name',
 2717             false,
 2718             array(
 2719                 'hostID' => $this->obj->get('id'),
 2720                 'date' => $dte,
 2721                 'action' => array('', 0, 1)
 2722             )
 2723         );
 2724         $UserLogins = json_decode(
 2725             Route::getData()
 2726         );
 2727         $UserLogins = $UserLogins->usertrackings;
 2728         $Data = array();
 2729         foreach ((array)$UserLogins as &$UserLogin) {
 2730             $time = self::niceDate(
 2731                 $UserLogin->datetime
 2732             )->format('U');
 2733             if (!isset($Data[$UserLogin->username])) {
 2734                 $Data[$UserLogin->username] = array();
 2735             }
 2736             if (array_key_exists('login', $Data[$UserLogin->username])) {
 2737                 if ($UserLogin->action > 0) {
 2738                     $this->data[] = array(
 2739                         'action' => _('Logout'),
 2740                         'user_name' => $UserLogin->username,
 2741                         'user_time' => (
 2742                             self::niceDate()
 2743                             ->setTimestamp($time - 1)
 2744                             ->format('Y-m-d H:i:s')
 2745                         ),
 2746                         'user_desc' => _('Logout not found')
 2747                         . '<br/>'
 2748                         . _('Setting logout to one second prior to next login')
 2749                     );
 2750                     $Data[$UserLogin->username] = array();
 2751                 }
 2752             }
 2753             if ($UserLogin->action > 0) {
 2754                 $Data[$UserLogin->username]['login'] = true;
 2755                 $this->data[] = array(
 2756                     'action' => _('Login'),
 2757                     'user_name' => $UserLogin->username,
 2758                     'user_time' => (
 2759                         self::niceDate()
 2760                         ->setTimestamp($time)
 2761                         ->format('Y-m-d H:i:s')
 2762                     ),
 2763                     'user_desc' => $UserLogin->description
 2764                 );
 2765             } elseif ($UserLogin->action < 1) {
 2766                 $this->data[] = array(
 2767                     'action' => _('Logout'),
 2768                     'user_name' => $UserLogin->username,
 2769                     'user_time' => (
 2770                         self::niceDate()
 2771                         ->setTimestamp($time)
 2772                         ->format('Y-m-d H:i:s')
 2773                     ),
 2774                     'user_desc' => $UserLogin->description
 2775                 );
 2776                 $Data[$UserLogin->username] = array();
 2777             }
 2778             unset($UserLogin);
 2779         }
 2780         self::$HookManager
 2781             ->processEvent(
 2782                 'HOST_USER_LOGIN',
 2783                 array(
 2784                     'headerData' => &$this->headerData,
 2785                     'data' => &$this->data,
 2786                     'templates' => &$this->templates,
 2787                     'attributes' => &$this->attributes
 2788                 )
 2789             );
 2790         echo '<!-- Login History -->';
 2791         echo '<div class="tab-pane fade" id="host-login-history">';
 2792         echo '<div class="panel panel-info">';
 2793         echo '<div class="panel-heading text-center">';
 2794         echo '<h4 class="title">';
 2795         echo _('Host Login History');
 2796         echo '</h4>';
 2797         echo '</div>';
 2798         echo '<div class="panel-body">';
 2799         echo '<form class="form-horizontal" method="post" action="'
 2800             . $this->formAction
 2801             . '&tab=host-login-history">';
 2802         if (count($Dates) > 0) {
 2803             echo '<div class="form-group">';
 2804             echo '<label class="control-label col-xs-4" for="dte">';
 2805             echo _('View History For');
 2806             echo '</label>';
 2807             echo '<div class="col-xs-8">';
 2808             echo $dateSel;
 2809             echo '</div>';
 2810             echo '</div>';
 2811         }
 2812         echo '<div class="panel panel-info">';
 2813         echo '<div class="panel-heading text-center">';
 2814         echo '<h4 class="title">';
 2815         echo _('Selected Logins');
 2816         echo '</h4>';
 2817         echo '</div>';
 2818         echo '<div class="panel-body">';
 2819         $this->render(12);
 2820         echo '</div>';
 2821         echo '</div>';
 2822         echo '<div class="panel panel-info">';
 2823         echo '<div class="panel-heading text-center">';
 2824         echo '<h4 class="title">';
 2825         echo _('History Graph');
 2826         echo '</h4>';
 2827         echo '</div>';
 2828         echo '<div class="panel-body" id="login-history">';
 2829         echo '</div>';
 2830         echo '</div>';
 2831         echo '</form>';
 2832         echo '</div>';
 2833         echo '</div>';
 2834         echo '</div>';
 2835         unset(
 2836             $this->data,
 2837             $this->form,
 2838             $this->headerData,
 2839             $this->templates,
 2840             $this->attributes
 2841         );
 2842     }
 2843     /**
 2844      * Display host imaging history.
 2845      *
 2846      * @return void
 2847      */
 2848     public function hostImageHistory()
 2849     {
 2850         unset(
 2851             $this->data,
 2852             $this->form,
 2853             $this->headerData,
 2854             $this->templates,
 2855             $this->attributes
 2856         );
 2857         $this->headerData = array(
 2858             _('Engineer'),
 2859             _('Imaged From'),
 2860             _('Start'),
 2861             _('End'),
 2862             _('Duration'),
 2863             _('Image'),
 2864             _('Type'),
 2865             _('State'),
 2866         );
 2867         $this->templates = array(
 2868             '${createdBy}',
 2869             sprintf(
 2870                 '<small>%s: ${group_name}</small><br/><small>%s: '
 2871                 . '${node_name}</small>',
 2872                 _('Storage Group'),
 2873                 _('Storage Node')
 2874             ),
 2875             '<small>${start_date}</small><br/><small>${start_time}</small>',
 2876             '<small>${end_date}</small><br/><small>${end_time}</small>',
 2877             '${duration}',
 2878             '${image_name}',
 2879             '${type}',
 2880             '${state}',
 2881         );
 2882         $this->attributes = array(
 2883             array(),
 2884             array(),
 2885             array(),
 2886             array(),
 2887             array(),
 2888             array(),
 2889             array(),
 2890             array(),
 2891         );
 2892         Route::listem(
 2893             'imaginglog',
 2894             'name',
 2895             false,
 2896             array('hostID' => $this->obj->get('id'))
 2897         );
 2898         $Logs = json_decode(
 2899             Route::getData()
 2900         );
 2901         $Logs = $Logs->imaginglogs;
 2902         $imgTypes = array(
 2903             'up' => _('Capture'),
 2904             'down' => _('Deploy'),
 2905         );
 2906         foreach ((array)$Logs as &$Log) {
 2907             $start = $Log->start;
 2908             $finish = $Log->finish;
 2909             if (!self::validDate($start)
 2910                 || !self::validDate($finish)
 2911             ) {
 2912                 continue;
 2913             }
 2914             $diff = self::diff($start, $finish);
 2915             $start = self::niceDate($start);
 2916             $finish = self::niceDate($finish);
 2917             $TaskIDs = self::getSubObjectIDs(
 2918                 'Task',
 2919                 array(
 2920                     'checkInTime' => $Log->start,
 2921                     'hostID' => $this->obj->get('id')
 2922                 )
 2923             );
 2924             $taskID = @max($TaskIDs);
 2925             if (!$taskID) {
 2926                 continue;
 2927             }
 2928             Route::indiv('task', $taskID);
 2929             $Task = json_decode(
 2930                 Route::getData()
 2931             );
 2932             $groupName = $Task->storagegroup->name;
 2933             $nodeName = $Task->storagenode->name;
 2934             $typeName = $Task->type->name;
 2935             if (!$typeName) {
 2936                 $typeName = $Log->type;
 2937             }
 2938             if (in_array($typeName, array('up', 'down'))) {
 2939                 $typeName = $imgTypes[$typeName];
 2940             }
 2941             $stateName = $Task->state->name;
 2942             unset($Task);
 2943             $createdBy = (
 2944                 $Log->createdBy ?:
 2945                 self::$FOGUser->get('name')
 2946             );
 2947             $Image = $Log->image;
 2948             if (!$Image->id) {
 2949                 $imgName = $Image;
 2950                 $imgPath = _('N/A');
 2951             } else {
 2952                 $imgName = $Image->name;
 2953                 $imgPath = $Image->path;
 2954             }
 2955             $this->data[] = array(
 2956                 'createdBy' => $createdBy,
 2957                 'group_name' => $groupName,
 2958                 'node_name' => $nodeName,
 2959                 'start_date' => $start->format('Y-m-d'),
 2960                 'start_time' => $start->format('H:i:s'),
 2961                 'end_date' => $finish->format('Y-m-d'),
 2962                 'end_time' => $finish->format('H:i:s'),
 2963                 'duration' => $diff,
 2964                 'image_name' => $imgName,
 2965                 'type' => $typeName,
 2966                 'state' => $stateName,
 2967             );
 2968             unset($Image, $Log);
 2969         }
 2970         self::$HookManager
 2971             ->processEvent(
 2972                 'HOST_IMAGE_HIST',
 2973                 array(
 2974                     'headerData' => &$this->headerData,
 2975                     'data' => &$this->data,
 2976                     'templates' => &$this->templates,
 2977                     'attributes' => &$this->attributes
 2978                 )
 2979             );
 2980         echo '<!-- Image History -->';
 2981         echo '<div class="tab-pane fade" id="host-image-history">';
 2982         echo '<div class="panel panel-info">';
 2983         echo '<div class="panel-heading text-center">';
 2984         echo '<h4 class="title">';
 2985         echo _('Host Imaging History');
 2986         echo '</h4>';
 2987         echo '</div>';
 2988         echo '<div class="panel-body">';
 2989         $this->render(12);
 2990         echo '</div>';
 2991         echo '</div>';
 2992         echo '</div>';
 2993         unset(
 2994             $this->data,
 2995             $this->form,
 2996             $this->headerData,
 2997             $this->templates,
 2998             $this->attributes
 2999         );
 3000     }
 3001     /**
 3002      * Display host snapin history
 3003      *
 3004      * @return void
 3005      */
 3006     public function hostSnapinHistory()
 3007     {
 3008         unset(
 3009             $this->data,
 3010             $this->form,
 3011             $this->headerData,
 3012             $this->templates,
 3013             $this->attributes
 3014         );
 3015         $this->headerData = array(
 3016             _('Snapin Name'),
 3017             _('Start Time'),
 3018             _('Complete'),
 3019             _('Duration'),
 3020             _('Return Code')
 3021         );
 3022         $this->templates = array(
 3023             '${snapin_name}',
 3024             '${snapin_start}',
 3025             '${snapin_end}',
 3026             '${snapin_duration}',
 3027             '${snapin_return}'
 3028         );
 3029         $this->attributes = array(
 3030             array(),
 3031             array(),
 3032             array(),
 3033             array(),
 3034             array()
 3035         );
 3036         $SnapinJobIDs = self::getSubObjectIDs(
 3037             'SnapinJob',
 3038             array(
 3039                 'hostID' => $this->obj->get('id')
 3040             )
 3041         );
 3042         $doneStates = array(
 3043             self::getCompleteState(),
 3044             self::getCancelledState()
 3045         );
 3046         Route::listem(
 3047             'snapintask',
 3048             'name',
 3049             false,
 3050             array('jobID' => $SnapinJobIDs)
 3051         );
 3052         $SnapinTasks = json_decode(
 3053             Route::getData()
 3054         );
 3055         $SnapinTasks = $SnapinTasks->snapintasks;
 3056         foreach ((array)$SnapinTasks as &$SnapinTask) {
 3057             $Snapin = $SnapinTask->snapin;
 3058             $start = self::niceDate($SnapinTask->checkin);
 3059             $end = self::niceDate($SnapinTask->complete);
 3060             if (!self::validDate($start)) {
 3061                 continue;
 3062             }
 3063             if (!in_array($SnapinTask->stateID, $doneStates)) {
 3064                 $diff = _('Snapin task not completed');
 3065             } elseif (!self::validDate($end)) {
 3066                 $diff = _('No complete time recorded');
 3067             } else {
 3068                 $diff = self::diff($start, $end);
 3069             }
 3070             $this->data[] = array(
 3071                 'snapin_name' => $Snapin->name,
 3072                 'snapin_start' => $start->format('Y-m-d H:i:s'),
 3073                 'snapin_end' => sprintf(
 3074                     '<span data-toggle="tooltip" data-placement="left" '
 3075                     . 'class="icon" title="%s">%s</span>',
 3076                     $end->format('Y-m-d H:i:s'),
 3077                     $SnapinTask->state->name
 3078                 ),
 3079                 'snapin_duration' => $diff,
 3080                 'snapin_return'=> $SnapinTask->return,
 3081             );
 3082             unset($SnapinTask);
 3083         }
 3084         self::$HookManager
 3085             ->processEvent(
 3086                 'HOST_SNAPIN_HIST',
 3087                 array(
 3088                     'headerData' => &$this->headerData,
 3089                     'data' => &$this->data,
 3090                     'templates' => &$this->templates,
 3091                     'attributes' => &$this->attributes
 3092                 )
 3093             );
 3094         echo '<div class="tab-pane fade" id="host-snapin-history">';
 3095         echo '<div class="panel panel-info">';
 3096         echo '<div class="panel-heading text-center">';
 3097         echo '<h4 class="title">';
 3098         echo _('Host Snapin History');
 3099         echo '</h4>';
 3100         echo '</div>';
 3101         echo '<div class="panel-body">';
 3102         $this->render(12);
 3103         echo '</div>';
 3104         echo '</div>';
 3105         echo '</div>';
 3106         unset(
 3107             $this->data,
 3108             $this->form,
 3109             $this->headerData,
 3110             $this->templates,
 3111             $this->attributes
 3112         );
 3113     }
 3114     /**
 3115      * Edits an existing item.
 3116      *
 3117      * @return void
 3118      */
 3119     public function edit()
 3120     {
 3121         $this->title = sprintf(
 3122             '%s: %s',
 3123             _('Edit'),
 3124             $this->obj->get('name')
 3125         );
 3126         $approve = filter_input(INPUT_GET, 'approveHost');
 3127         if ($approve) {
 3128             $this
 3129                 ->obj
 3130                 ->set(
 3131                     'pending',
 3132                     0
 3133                 );
 3134             if ($this->obj->save()) {
 3135                 self::setMessage(_('Host approved'));
 3136             } else {
 3137                 self::setMessage(_('Host approval failed.'));
 3138             }
 3139             self::redirect(
 3140                 '?node='
 3141                 . $this->node
 3142                 . '&sub=edit&id='
 3143                 . $this->obj->get('id')
 3144             );
 3145         }
 3146         if ($this->obj->get('pending')) {
 3147             echo '<div class="panel panel-info">';
 3148             echo '<div class="panel-heading">';
 3149             echo '<h4 class="title">';
 3150             echo _('Approve Host');
 3151             echo '</h4>';
 3152             echo '</div>';
 3153             echo '<div class="panel-body">';
 3154             echo '<a href="'
 3155                 . $this->formAction
 3156                 . '&approveHost=1">'
 3157                 . _('Approve this host?')
 3158                 . '</a>';
 3159             echo '</div>';
 3160             echo '</div>';
 3161         }
 3162         $confirmMac = filter_input(
 3163             INPUT_GET,
 3164             'confirmMAC'
 3165         );
 3166         $approveAll = filter_input(
 3167             INPUT_GET,
 3168             'approveAll'
 3169         );
 3170         if ($confirmMac) {
 3171             try {
 3172                 $this->obj->addPendtoAdd($confirmMac);
 3173                 if ($this->obj->save()) {
 3174                     $msg = _('MAC')
 3175                         . ': '
 3176                         . $confirmMac
 3177                         . ' '
 3178                         . _('Approved')
 3179                         . '!';
 3180                     self::setMessage($msg);
 3181                     unset($msg);
 3182                 }
 3183             } catch (Exception $e) {
 3184                 self::setMessage($e->getMessage());
 3185             }
 3186             self::redirect(
 3187                 '?node='
 3188                 . $this->node
 3189                 . '&sub=edit&id='
 3190                 . $this->obj->get('id')
 3191             );
 3192         } elseif ($approveAll) {
 3193             self::getClass('MACAddressAssociationManager')
 3194                 ->update(
 3195                     array(
 3196                         'hostID' => $this->obj->get('id')
 3197                     ),
 3198                     '',
 3199                     array(
 3200                         'pending' => 0
 3201                     )
 3202                 );
 3203             $msg = sprintf(
 3204                 '%s.',
 3205                 _('All Pending MACs approved')
 3206             );
 3207             self::setMessage($msg);
 3208             self::redirect(
 3209                 sprintf(
 3210                     '?node=%s&sub=edit&id=%s',
 3211                     $this->node,
 3212                     (int)$_POST['id']
 3213                 )
 3214             );
 3215         }
 3216         echo '<div class="col-xs-9 tab-content">';
 3217         $this->hostGeneral();
 3218         if (!$this->obj->get('pending')) {
 3219             $this->basictasksOptions();
 3220         }
 3221         $this->adFieldsToDisplay(
 3222             $this->obj->get('useAD'),
 3223             $this->obj->get('ADDomain'),
 3224             $this->obj->get('ADOU'),
 3225             $this->obj->get('ADUser'),
 3226             '',
 3227             $this->obj->get('ADPassLegacy'),
 3228             $this->obj->get('enforce')
 3229         );
 3230         $this->hostPrinters();
 3231         $this->hostSnapins();
 3232         $this->hostService();
 3233         $this->hostPMDisplay();
 3234         $this->hostInventory();
 3235         $this->hostVirus();
 3236         $this->hostLoginHistory();
 3237         $this->hostImageHistory();
 3238         $this->hostSnapinHistory();
 3239         self::$HookManager->processEvent(
 3240             'HOST_EDIT_EXTRA',
 3241             array(
 3242                 'Host' => &$this->obj,
 3243                 'data' => &$this->data,
 3244                 'headerData' => &$this->headerData,
 3245                 'templates' => &$this->templates,
 3246                 'attributes' => &$this->attributes,
 3247                 'formAction' => &$this->formAction,
 3248                 'render' => &$this
 3249             )
 3250         );
 3251         echo '</div>';
 3252     }
 3253     /**
 3254      * Host active directory post element.
 3255      *
 3256      * @return void
 3257      */
 3258     public function hostADPost()
 3259     {
 3260         $useAD = isset($_POST['domain']);
 3261         $domain = trim(
 3262             filter_input(
 3263                 INPUT_POST,
 3264                 'domainname'
 3265             )
 3266         );
 3267         $ou = trim(
 3268             filter_input(
 3269                 INPUT_POST,
 3270                 'ou'
 3271             )
 3272         );
 3273         $user = trim(
 3274             filter_input(
 3275                 INPUT_POST,
 3276                 'domainuser'
 3277             )
 3278         );
 3279         $pass = trim(
 3280             filter_input(
 3281                 INPUT_POST,
 3282                 'domainpassword'
 3283             )
 3284         );
 3285         $passlegacy = trim(
 3286             filter_input(
 3287                 INPUT_POST,
 3288                 'domainpasswordlegacy'
 3289             )
 3290         );
 3291         $enforce = isset($_POST['enforcesel']);
 3292         $this->obj->setAD(
 3293             $useAD,
 3294             $domain,
 3295             $ou,
 3296             $user,
 3297             $pass,
 3298             true,
 3299             true,
 3300             $passlegacy,
 3301             $productKey,
 3302             $enforce
 3303         );
 3304     }
 3305     /**
 3306      * Host power management post.
 3307      *
 3308      * @return void
 3309      */
 3310     public function hostPMPost()
 3311     {
 3312         $onDemand = (int)isset($_POST['onDemand']);
 3313         $items = array();
 3314         $flags = array('flags' => FILTER_REQUIRE_ARRAY);
 3315         if (isset($_POST['pmupdate'])) {
 3316             $items = filter_input_array(
 3317                 INPUT_POST,
 3318                 array(
 3319                     'scheduleCronMin' => $flags,
 3320                     'scheduleCronHour' => $flags,
 3321                     'scheduleCronDOM' => $flags,
 3322                     'scheduleCronMonth' => $flags,
 3323                     'scheduleCronDOW' => $flags,
 3324                     'pmid' => $flags,
 3325                     'action' => $flags
 3326                 )
 3327             );
 3328             extract($items);
 3329             if (!$action) {
 3330                 throw new Exception(
 3331                     _('You must select an action to perform')
 3332                 );
 3333             }
 3334             $items = array();
 3335             foreach ((array)$pmid as $index => &$pm) {
 3336                 $onDemandItem = array_search(
 3337                     $pm,
 3338                     $onDemand
 3339                 );
 3340                 $items[] = array(
 3341                     $pm,
 3342                     $this->obj->get('id'),
 3343                     $scheduleCronMin[$index],
 3344                     $scheduleCronHour[$index],
 3345                     $scheduleCronDOM[$index],
 3346                     $scheduleCronMonth[$index],
 3347                     $scheduleCronDOW[$index],
 3348                     $onDemandItem !== -1
 3349                     && $onDemand[$onDemandItem] === $pm ?
 3350                     1 :
 3351                     0,
 3352                     $action[$index]
 3353                 );
 3354                 unset($pm);
 3355             }
 3356             self::getClass('PowerManagementManager')
 3357                 ->insertBatch(
 3358                     array(
 3359                         'id',
 3360                         'hostID',
 3361                         'min',
 3362                         'hour',
 3363                         'dom',
 3364                         'month',
 3365                         'dow',
 3366                         'onDemand',
 3367                         'action'
 3368                     ),
 3369                     $items
 3370                 );
 3371         }
 3372         if (isset($_POST['pmsubmit'])) {
 3373             $min = trim(
 3374                 filter_input(
 3375                     INPUT_POST,
 3376                     'scheduleCronMin'
 3377                 )
 3378             );
 3379             $hour = trim(
 3380                 filter_input(
 3381                     INPUT_POST,
 3382                     'scheduleCronHour'
 3383                 )
 3384             );
 3385             $dom = trim(
 3386                 filter_input(
 3387                     INPUT_POST,
 3388                     'scheduleCronDOM'
 3389                 )
 3390             );
 3391             $month = trim(
 3392                 filter_input(
 3393                     INPUT_POST,
 3394                     'scheduleCronMonth'
 3395                 )
 3396             );
 3397             $dow = trim(
 3398                 filter_input(
 3399                     INPUT_POST,
 3400                     'scheduleCronDOW'
 3401                 )
 3402             );
 3403             $action = trim(
 3404                 filter_input(
 3405                     INPUT_POST,
 3406                     'action'
 3407                 )
 3408             );
 3409             if ($onDemand && $action === 'wol') {
 3410                 $this->obj->wakeOnLAN();
 3411                 return;
 3412             }
 3413             self::getClass('PowerManagement')
 3414                 ->set('hostID', $this->obj->get('id'))
 3415                 ->set('min', $min)
 3416                 ->set('hour', $hour)
 3417                 ->set('dom', $dom)
 3418                 ->set('month', $month)
 3419                 ->set('dow', $dow)
 3420                 ->set('onDemand', $onDemand)
 3421                 ->set('action', $action)
 3422                 ->save();
 3423         }
 3424         if (isset($_POST['pmdelete'])) {
 3425             $pmid = filter_input_array(
 3426                 INPUT_POST,
 3427                 array(
 3428                     'rempowermanagements' => $flags
 3429                 )
 3430             );
 3431             $pmid = $pmid['rempowermanagements'];
 3432             self::getClass('PowerManagementManager')
 3433                 ->destroy(
 3434                     array(
 3435                         'id' => $pmid
 3436                     )
 3437                 );
 3438         }
 3439     }
 3440     /**
 3441      * Host printer post.
 3442      *
 3443      * @return void
 3444      */
 3445     public function hostPrinterPost()
 3446     {
 3447         if (isset($_POST['levelup'])) {
 3448             $this
 3449                 ->obj
 3450                 ->set(
 3451                     'printerLevel',
 3452                     filter_input(
 3453                         INPUT_POST,
 3454                         'level'
 3455                     )
 3456                 );
 3457         }
 3458         if (isset($_POST['updateprinters'])) {
 3459             $printers = filter_input_array(
 3460                 INPUT_POST,
 3461                 array(
 3462                     'printer' => array(
 3463                         'flags' => FILTER_REQUIRE_ARRAY
 3464                     )
 3465                 )
 3466             );
 3467             $printers = $printers['printer'];
 3468             if (count($printers) > 0) {
 3469                 $this
 3470                     ->obj
 3471                     ->addPrinter(
 3472                         $printers
 3473                     );
 3474             }
 3475         }
 3476         if (isset($_POST['defaultsel'])) {
 3477             $this->obj->updateDefault(
 3478                 filter_input(
 3479                     INPUT_POST,
 3480                     'default'
 3481                 ),
 3482                 isset($_POST['default'])
 3483             );
 3484         }
 3485         if (isset($_POST['printdel'])) {
 3486             $printers = filter_input_array(
 3487                 INPUT_POST,
 3488                 array(
 3489                     'printerRemove' => array(
 3490                         'flags' => FILTER_REQUIRE_ARRAY
 3491                     )
 3492                 )
 3493             );
 3494             $printers = $printers['printerRemove'];
 3495             if (count($printers) > 0) {
 3496                 $this
 3497                     ->obj
 3498                     ->removePrinter(
 3499                         $printers
 3500                     );
 3501             }
 3502         }
 3503     }
 3504     /**
 3505      * Host snapin post
 3506      *
 3507      * @return void
 3508      */
 3509     public function hostSnapinPost()
 3510     {
 3511         if (isset($_POST['updatesnapins'])) {
 3512             $snapins = filter_input_array(
 3513                 INPUT_POST,
 3514                 array(
 3515                     'snapin' => array(
 3516                         'flags' => FILTER_REQUIRE_ARRAY
 3517                     )
 3518                 )
 3519             );
 3520             $snapins = $snapins['snapin'];
 3521             if (count($snapins) > 0) {
 3522                 $this
 3523                     ->obj
 3524                     ->addSnapin($snapins);
 3525             }
 3526         }
 3527         if (isset($_POST['snapdel'])) {
 3528             $snapins = filter_input_array(
 3529                 INPUT_POST,
 3530                 array(
 3531                     'snapinRemove' => array(
 3532                         'flags' => FILTER_REQUIRE_ARRAY
 3533                     )
 3534                 )
 3535             );
 3536             $snapins = $snapins['snapinRemove'];
 3537             if (count($snapins) > 0) {
 3538                 $this
 3539                     ->obj
 3540                     ->removeSnapin(
 3541                         $snapins
 3542                     );
 3543             }
 3544         }
 3545     }
 3546     /**
 3547      * Update the actual thing.
 3548      *
 3549      * @return void
 3550      */
 3551     public function hostServicePost()
 3552     {
 3553         $x = filter_input(INPUT_POST, 'x');
 3554         $y = filter_input(INPUT_POST, 'y');
 3555         $r = filter_input(INPUT_POST, 'r');
 3556         $tme = filter_input(INPUT_POST, 'tme');
 3557         $modOn = filter_input_array(
 3558             INPUT_POST,
 3559             array(
 3560                 'modules' => array(
 3561                     'flags' => FILTER_REQUIRE_ARRAY
 3562                 )
 3563             )
 3564         );
 3565         $modOn = $modOn['modules'];
 3566         if (isset($_POST['modulesend'])) {
 3567             $this->obj->set('modules', $modOn);
 3568         }
 3569         if (isset($_POST['dispupdate'])) {
 3570             $this->obj->setDisp($x, $y, $r);
 3571         }
 3572         if (isset($_POST['alosend'])) {
 3573             $this->obj->setAlo($tme);
 3574         }
 3575     }
 3576     /**
 3577      * Updates the host when form is submitted
 3578      *
 3579      * @return void
 3580      */
 3581     public function editPost()
 3582     {
 3583         self::$HookManager->processEvent(
 3584             'HOST_EDIT_POST',
 3585             array('Host' => &$this->obj)
 3586         );
 3587         try {
 3588             global $tab;
 3589             switch ($tab) {
 3590             case 'host-general':
 3591                 $this->hostGeneralPost();
 3592                 break;
 3593             case 'host-active-directory':
 3594                 $this->hostADPost();
 3595                 break;
 3596             case 'host-powermanagement':
 3597                 $this->hostPMPost();
 3598                 break;
 3599             case 'host-printers':
 3600                 $this->hostPrinterPost();
 3601                 break;
 3602             case 'host-snapins':
 3603                 $this->hostSnapinPost();
 3604                 break;
 3605             case 'host-service':
 3606                 $this->hostServicePost();
 3607                 break;
 3608             case 'host-hardware-inventory':
 3609                 $pu = filter_input(INPUT_POST, 'pu');
 3610                 $other1 = filter_input(INPUT_POST, 'other1');
 3611                 $other2 = filter_input(INPUT_POST, 'other2');
 3612                 if (isset($_POST['update'])) {
 3613                     $this->obj
 3614                         ->get('inventory')
 3615                         ->set('primaryUser', $pu)
 3616                         ->set('other1', $other1)
 3617                         ->set('other2', $other2)
 3618                         ->set('hostID', $this->obj->get('id'))
 3619                         ->save();
 3620                 }
 3621                 break;
 3622             case 'host-login-history':
 3623                 $dte = filter_input(INPUT_POST, 'dte');
 3624                 self::redirect(
 3625                     '?node='
 3626                     . $this->node
 3627                     . '&sub=edit&id='
 3628                     . $this->obj->get('id')
 3629                     . '&dte='
 3630                     . $dte
 3631                     . '#'
 3632                     . $tab
 3633                 );
 3634                 break;
 3635             case 'host-virus-history':
 3636                 $delvid = filter_input(INPUT_POST, 'delvid');
 3637                 $delvidarr = filter_input_array(
 3638                     INPUT_POST,
 3639                     array(
 3640                         'delvidarr' => array(
 3641                             'flags' => FILTER_REQUIRE_ARRAY
 3642                         )
 3643                     )
 3644                 );
 3645                 $delvidarr = $delvidarr['delvidarr'];
 3646                 if ($delvid == 'all') {
 3647                     $this->obj->clearAVRecordsForHost();
 3648                 } else {
 3649                     self::getClass('VirusManager')
 3650                         ->destroy(
 3651                             array(
 3652                                 'id' => $delvidarr
 3653                             )
 3654                         );
 3655                 }
 3656                 $msg = json_encode(
 3657                     array('msg' => _('Virus items removed!'))
 3658                 );
 3659                 echo $msg;
 3660                 exit;
 3661             }
 3662             if (!$this->obj->save()) {
 3663                 throw new Exception(_('Host Update Failed'));
 3664             }
 3665             $this->obj->setAD();
 3666             if ($tab == 'host-general') {
 3667                 $igstuff = filter_input_array(
 3668                     INPUT_POST,
 3669                     array(
 3670                         'igimage' => array(
 3671                             'flags' => FILTER_REQUIRE_ARRAY
 3672                         ),
 3673                         'igclient' => array(
 3674                             'flags' => FILTER_REQUIRE_ARRAY
 3675                         )
 3676                     )
 3677                 );
 3678                 $igimage = $igstuff['igimage'];
 3679                 $igclient = $igstuff['igclient'];
 3680                 $this->obj->ignore($igimage, $igclient);
 3681             }
 3682             $hook = 'HOST_EDIT_SUCCESS';
 3683             $msg = json_encode(
 3684                 array(
 3685                     'msg' => _('Host updated!'),
 3686                     'title' => _('Host Update Success')
 3687                 )
 3688             );
 3689         } catch (Exception $e) {
 3690             $hook = 'HOST_EDIT_FAIL';
 3691             $msg = json_encode(
 3692                 array(
 3693                     'error' => $e->getMessage(),
 3694                     'title' => _('Host Update Fail')
 3695                 )
 3696             );
 3697         }
 3698         self::$HookManager
 3699             ->processEvent(
 3700                 $hook,
 3701                 array('Host' => &$this->obj)
 3702             );
 3703         echo $msg;
 3704         exit;
 3705     }
 3706     /**
 3707      * Saves host to a selected or new group depending on action.
 3708      *
 3709      * @return void
 3710      */
 3711     public function saveGroup()
 3712     {
 3713         $group = filter_input(INPUT_POST, 'group');
 3714         $newgroup = filter_input(INPUT_POST, 'group_new');
 3715         $hostids = filter_input(
 3716             INPUT_POST,
 3717             'hostIDArray'
 3718         );
 3719         $hostids = array_values(
 3720             array_filter(
 3721                 array_unique(
 3722                     explode(',', $hostids)
 3723                 )
 3724             )
 3725         );
 3726         try {
 3727             $Group = new Group($group);
 3728             if ($newgroup) {
 3729                 $Group
 3730                     ->set('name', $newgroup)
 3731                     ->load('name');
 3732             }
 3733             $Group->addHost($hostids);
 3734             if (!$Group->save()) {
 3735                 throw new Exception(_('Failed to create new Group'));
 3736             }
 3737             $msg = json_encode(
 3738                 array(
 3739                     'msg' => _('Successfully added selected hosts to the group!'),
 3740                     'title' => _('Host Add to Group Success')
 3741                 )
 3742             );
 3743         } catch (Exception $e) {
 3744             $msg = json_encode(
 3745                 array(
 3746                     'error' => $e->getMessage(),
 3747                     'title' => _('Host Add to Group Fail')
 3748                 )
 3749             );
 3750         }
 3751         echo $msg;
 3752         exit;
 3753     }
 3754     /**
 3755      * Gets the host user tracking info.
 3756      *
 3757      * @return void
 3758      */
 3759     public function hostlogins()
 3760     {
 3761         $date = filter_input(INPUT_GET, 'dte');
 3762         $MainDate = self::niceDate($date)
 3763             ->getTimestamp();
 3764         $MainDate_1 = self::niceDate($date)
 3765             ->modify('+1 day')
 3766             ->getTimestamp();
 3767         Route::listem(
 3768             'UserTracking',
 3769             'name',
 3770             'ASC',
 3771             array(
 3772                 'hostID' => $this->obj->get('id'),
 3773                 'action' => array('', 0, 1)
 3774             )
 3775         );
 3776         $UserTracks = json_decode(
 3777             Route::getData()
 3778         );
 3779         $UserTracks = $UserTracks->usertrackings;
 3780         $data = null;
 3781         $Data = array();
 3782         foreach ((array)$UserTracks as &$Login) {
 3783             $ldate = self::niceDate($Login->date)
 3784                 ->format('Y-m-d');
 3785             if ($Login->hostID != $this->obj->get('id')
 3786                 || $ldate != $date
 3787                 || !in_array($Login->action, array('', 0, 1))
 3788             ) {
 3789                 continue;
 3790             }
 3791             $time = self::niceDate($Login->datetime);
 3792             $Data[$Login->username] = array(
 3793                 'user' => $Login->username,
 3794                 'min' => $MainDate,
 3795                 'max' => $MainDate_1
 3796             );
 3797             if (array_key_exists('login', $Data[$Login->username])) {
 3798                 if ($Login->action > 0) {
 3799                     $Data[$Login->username]['logout'] = (int)$time - 1;
 3800                     $data[] = $Data[$Login->username];
 3801                 } elseif ($Login->action < 1) {
 3802                     $Data[$Login->username]['logout'] = (int)$time;
 3803                     $data[] = $Data[$Login->username];
 3804                 }
 3805                 $Data[$Login->username] = array(
 3806                     'user' => $Login->username,
 3807                     'min' => $MainDate,
 3808                     'max' => $MainDate_1
 3809                 );
 3810             }
 3811             if ($Login->action > 0) {
 3812                 $Data[$Login->username]['login'] = (int)$time;
 3813             }
 3814             unset($Login);
 3815         }
 3816         unset($UserTracks);
 3817         echo json_encode($data);
 3818         exit;
 3819     }
 3820 }