FOG en EHU  1.0.0(r304)
FOGenEHU
packages/web/lib/pages/HostManagementPage.class.php
Ir a la documentación de este archivo.
00001 <?php
00002 
00003 // Blackout - 12:36 PM 16/11/2011
00004 class HostManagementPage extends FOGPage
00005 {
00006         // Base variables
00007         var $name = 'Host Management';
00008         var $node = 'host';
00009         var $id = 'id';
00010 
00011         // Menu Items
00012         var $menu = array(
00013 
00014         );
00015         var $subMenu = array(
00016 
00017         );
00018 
00019         // __construct
00020         public function __construct($name = '')
00021         {
00022                 // Call parent constructor
00023                 parent::__construct($name);
00024 
00025                 // Header row
00026                 $this->headerData = array(
00027                                 '<input type="checkbox" name="toggle-checkbox" class="toggle-checkbox" checked="checked" />',
00028                                 '',
00029                                 _('Host Name'),
00030                                 //_('MAC'),
00031                                 _('IP Address'),
00032                                 '',
00033                                 ''
00034                 );
00035 
00036                 // Row templates
00037                 $this->templates = array(
00038                                 '<input type="checkbox" name="host[]" value="${id}" class="toggle-host" checked="checked" />',
00039                                 '<span class="icon ping"></span>',
00040                                 '<a href="?node=host&sub=edit&id=${id}" title="Edit">${name}</a><br /><small>${mac}</small>',
00041                                 //'${mac}',
00042                                 '${ip}',
00043                                 '<a href="?node=host&sub=deploy&sub=deploy&type=1&id=${id}"><span class="icon icon-download" title="Download"></span></a> <a href="?node=host&sub=deploy&sub=deploy&type=2&id=${id}"><span class="icon icon-upload" title="Upload"></span></a> <a href="?node=host&sub=deploy&sub=edit&id=${id}#host-tasks"><span class="icon icon-deploy" title="Deploy"></span></a>',
00044                                 '<a href="?node=host&sub=edit&id=${id}"><span class="icon icon-edit" title="Edit"></span></a> <a href="?node=host&sub=delete&id=${id}"><span class="icon icon-delete" title="Delete"></span></a>'
00045                 );
00046 
00047                 // Row attributes
00048                 $this->attributes = array(
00049                                 array('width' => 22),
00050                                 array('width' => 20),
00051                                 array(),
00052                                 array('width' => 90, 'class' => 'small'),
00053                                 //array('width' => 90, 'class' => 'small'),
00054                                 array('width' => 80, 'class' => 'c'),
00055                                 array('width' => 50, 'class' => 'c')
00056                 );
00057         }
00058 
00059         // Pages
00060         public function index()
00061         {
00062                 // Set title
00063                 $this->title = _('All Hosts');
00064 
00065                 // Find data -> Push data
00066                 foreach ($this->FOGCore->getClass('HostManager')->find() AS $Host)
00067                 {
00068                         $this->data[] = array(
00069                                         'id'    => $Host->get('id'),
00070                                         'name'  => $Host->get('name'),
00071                                         'mac'   => $Host->get('mac')->__toString(),
00072                                         'ip'    => $Host->get('ip')
00073                         );
00074                 }
00075 
00076                 // Hook
00077                 $this->HookManager->processEvent('HOST_DATA', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
00078 
00079                 // Output
00080                 $this->render();
00081         }
00082 
00083         public function search()
00084         {
00085                 // Set title
00086                 $this->title = _('Search');
00087 
00088                 // Set search form
00089                 //$this->searchFormURL = 'ajax/host.search.php';
00090                 //$this->searchFormURL = $this->formAction;
00091                 $this->searchFormURL = sprintf('%s?node=%s&sub=search', $_SERVER['PHP_SELF'], $this->node);
00092 
00093                 // Output
00094                 $this->render();
00095         }
00096 
00097         public function search_post()
00098         {
00099                 // Variables
00100                 $keyword = preg_replace('#%+#', '%', '%' . preg_replace('#[[:space:]]#', '%', $this->REQUEST['crit']) . '%');
00101                 $findWhere = array(
00102                                 'name'          => $keyword,
00103                                 'mac'           => $keyword,
00104                                 'ip'            => $keyword,
00105                                 'description'   => $keyword
00106                 );
00107 
00108                 // Find data -> Push data
00109                 foreach ($this->FOGCore->getClass('HostManager')->find($findWhere, 'OR') AS $Host)
00110                 {
00111                         $this->data[] = array(
00112                                         'id'    => $Host->get('id'),
00113                                         'name'  => $Host->get('name'),
00114                                         'mac'   => $Host->get('mac')->__toString(),
00115                                         'ip'    => $Host->get('ip')
00116                         );
00117                 }
00118 
00119                 // Hook
00120                 $this->HookManager->processEvent('HOST_DATA', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
00121 
00122                 // Output
00123                 $this->render();
00124         }
00125 
00126         public function add()
00127         {
00128                 // Set title
00129                 $this->title = _('New Host');
00130 
00131                 // Hook
00132                 $this->HookManager->processEvent('HOST_ADD');
00133 
00134                 // TODO: Put table rows into variables -> Add hooking
00135                 // TODO: Add tabs with other options
00136                 ?>
00137 <h2>
00138         <?php print _("Add new host definition"); ?>
00139 </h2>
00140 <form method="POST" action="<?php print $this->formAction; ?>">
00141         <input type="hidden" name="add" value="1" />
00142         <table cellpadding="0" cellspacing="0" border="0" width="100%">
00143                 <tr>
00144                         <td width="35%"><?php print _("Host Name"); ?></td>
00145                         <td><input type="text" name="host"
00146                                 value="<?php print $_POST['host']; ?>" maxlength="15"
00147                                 class="hostname-input" /> *</td>
00148                 </tr>
00149                 <tr>
00150                         <td><?php print _("Host IP"); ?></td>
00151                         <td><input type="text" name="ip" value="<?php print $_POST['ip']; ?>" />
00152                         </td>
00153                 </tr>
00154                 <tr>
00155                         <td><?php print _("Primary MAC"); ?></td>
00156                         <td><input type="text" id="mac" name="mac"
00157                                 value="<?php print $_POST['mac']; ?>" /> * &nbsp; <span
00158                                 id="priMaker"></span>
00159                         </td>
00160                 </tr>
00161                 <tr>
00162                         <td><?php print _("Host Description"); ?></td>
00163                         <td><textarea name="description" rows="5" cols="40">
00164                                         <?php print $_POST['description']; ?>
00165                                 </textarea></td>
00166                 </tr>
00167                 <tr>
00168                         <td><?php print _("Host Image"); ?></td>
00169                         <td><?php print $this->FOGCore->getClass('ImageManager')->buildSelectBox($_POST['image']);  ?>
00170                         </td>
00171                 </tr>
00172                 <tr>
00173                         <td><?php print _("Host Kernel"); ?></td>
00174                         <td><input type="text" name="kern"
00175                                 value="<?php print $_POST['kern']; ?>" /></td>
00176                 </tr>
00177                 <tr>
00178                         <td><?php print _("Host Kernel Arguments"); ?></td>
00179                         <td><input type="text" name="args"
00180                                 value="<?php print $_POST['args']; ?>" /></td>
00181                 </tr>
00182                 <tr>
00183                         <td><?php print _("Host Primary Disk"); ?></td>
00184                         <td><input type="text" name="dev"
00185                                 value="<?php print $_POST['dev']; ?>" /></td>
00186                 </tr>
00187         </table>
00188 
00189         <br />
00190         <h2>
00191                 <?php print _("Active Directory"); ?>
00192         </h2>
00193         <table cellpadding="0" cellspacing="0" border="0" width="100%">
00194                 <tr>
00195                         <td width="35%"><?php print _("Join Domain after image task"); ?></td>
00196                         <td><input id="adEnabled" type="checkbox" name="domain" value="on"
00197                         <?php print ($_POST['domain'] == 'on' ? ' selected="selected"' : ''); ?> />
00198                         </td>
00199                 </tr>
00200                 <tr>
00201                         <td><?php print _("Domain name"); ?></td>
00202                         <td><input id="adDomain" type="text" name="domainname"
00203                                 value="<?php print $_POST['domainname']; ?>" /></td>
00204                 </tr>
00205                 <tr>
00206                         <td><?php print _("Organizational Unit"); ?></td>
00207                         <td><input id="adOU" type="text" name="ou"
00208                                 value="<?php print $_POST['ou']; ?>" /> <?php print _("(Blank for default)"); ?>
00209                         </td>
00210                 </tr>
00211                 <tr>
00212                         <td><?php print _("Domain Username"); ?></td>
00213                         <td><input id="adUsername" type="text" name="domainuser"
00214                                 value="<?php print $_POST['domainuser']; ?>" /></td>
00215                 </tr>
00216                 <tr>
00217                         <td><?php print _("Domain Password"); ?></td>
00218                         <td><input id="adPassword" type="text" name="domainpassword"
00219                                 value="<?php print $_POST['domainpassword']; ?>" /> <?php print _("(Must be encrypted)"); ?>
00220                         </td>
00221                 </tr>
00222                 <tr>
00223                         <td>&nbsp;</td>
00224                         <td><input type="submit" value="<?php print _("Add"); ?>" /></td>
00225                 </tr>
00226         </table>
00227 </form>
00228 <?php
00229         }
00230 
00231         public function add_post()
00232         {
00233                 // Hook
00234                 $this->HookManager->processEvent('HOST_ADD_POST');
00235 
00236                 // POST ?
00237                 try
00238                 {
00239                         // Error checking
00240                         if (empty($_POST['host']))
00241                         {
00242                                 throw new Exception('Hostname is required');
00243                         }
00244                         if (empty($_POST['mac']))
00245                         {
00246                                 throw new Exception('MAC Address is required');
00247                         }
00248 
00249                         // Define new Image object with data provided
00250                         $Host = new Host(array(
00251                                         'name'          => $_POST['host'],
00252                                         'description'   => $_POST['description'],
00253                                         'ip'            => $_POST['ip'],
00254                                         'mac'           => new MACAddress($_POST['mac']),
00255                                         'osID'          => $_POST['os'],
00256                                         'imageID'       => $_POST['image'],
00257                                         'kernel'        => $_POST['kern'],
00258                                         'kernelArgs'    => $_POST['args'],
00259                                         'kernelDevice'  => $_POST['dev'],
00260                                         'useAD'         => ($_POST["domain"] == "on" ? '1' : '0'),
00261                                         'ADDomain'      => $_POST['domainname'],
00262                                         'ADOU'          => $_POST['ou'],
00263                                         'ADUser'        => $_POST['domainuser'],
00264                                         'ADPass'        => $_POST['domainpassword']
00265                         ));
00266                                 
00267                         // Save to database
00268                         if ($Host->save())
00269                         {
00270                                 // Hook
00271                                 $this->HookManager->processEvent('HOST_ADD_SUCCESS', array('Host' => &$Host));
00272 
00273                                 // Log History event
00274                                 $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', _('Host added'), $Host->get('id'), $Host->get('name')));
00275                                         
00276                                 // Set session message
00277                                 $this->FOGCore->setMessage(_('Host added'));
00278                                         
00279                                 // Redirect to new entry
00280                                 $this->FOGCore->redirect(sprintf('?node=%s&sub=edit&%s=%s', $this->REQUEST['node'], $this->id, $Host->get('id')));
00281                         }
00282                         else
00283                         {
00284                                 // Database save failed
00285                                 throw new Exception('Database update failed');
00286                         }
00287                 }
00288                 catch (Exception $e)
00289                 {
00290                         // Hook
00291                         $this->HookManager->processEvent('HOST_ADD_FAIL', array('Host' => &$Host));
00292                                 
00293                         // Log History event
00294                         $this->FOGCore->logHistory(sprintf('%s add failed: Name: %s, Error: %s', _('Host'), $_POST['name'], $e->getMessage()));
00295                                 
00296                         // Set session message
00297                         $this->FOGCore->setMessage($e->getMessage());
00298                                 
00299                         // Redirect to new entry
00300                         $this->FOGCore->redirect($this->formAction);
00301                 }
00302         }
00303 
00304         public function edit()
00305         {
00306                 // Find
00307                 $Host = new Host($this->REQUEST['id']);
00308 
00309                 // Title - set title for page title in window
00310                 $this->title = sprintf('%s: %s', _('Edit'), $Host->get('name'));
00311                 // But disable displaying in content
00312                 $this->titleEnabled = false;
00313 
00314                 // Hook
00315                 $this->HookManager->processEvent('HOST_EDIT', array('Host' => &$Host));
00316 
00317                 // TODO: Put table rows into variables -> Add hooking
00318                 // TODO: Add ping lookup + additional macs from original HTML (its awful and messy, needs a rewrite)
00319                 // TODO: Rewrite HTML & PHP
00320                 ?>
00321 <!--<form method="POST" action="<?php print $this->formAction; ?>">
00322                         <input type="hidden" name="id" value="<?php print $this->REQUEST['id']; ?>" />-->
00323 <div
00324         id="tab-container">
00325         <!-- General -->
00326         <div id="host-general">
00327                 <form method="POST"
00328                         action="<?php print $this->formAction; ?>&tab=host-general">
00329                         <input type="hidden" name="id"
00330                                 value="<?php print $this->REQUEST['id']; ?>" />
00331                         <h2>
00332                                 <?php print _("Edit host definition"); ?>
00333                         </h2>
00334                         <table cellpadding="0" cellspacing="0" border="0" width="100%">
00335                                 <tr>
00336                                         <td width="35%"><?php print _("Host Name"); ?></td>
00337                                         <td><input type="text" name="host"
00338                                                 value="<?php print $Host->get('name'); ?>" maxlength="15"
00339                                                 class="hostname-input" /> *</td>
00340                                 </tr>
00341                                 <tr>
00342                                         <td><?php print _("Host IP"); ?></td>
00343                                         <td><input type="text" name="ip"
00344                                                 value="<?php print $Host->get('ip'); ?>" /></td>
00345                                 </tr>
00346                                 <tr>
00347                                         <td><?php print _("Primary MAC"); ?></td>
00348                                         <td><input type="text" id="mac" name="mac"
00349                                                 value="<?php print $Host->get('mac'); ?>" /> * &nbsp; <span
00350                                                 id="priMaker"></span>
00351                                         </td>
00352                                 </tr>
00353                                 <tr>
00354                                         <td><?php print _("Host Description"); ?></td>
00355                                         <td><textarea name="description" rows="5" cols="40">
00356                                                         <?php print $Host->get('description'); ?>
00357                                                 </textarea></td>
00358                                 </tr>
00359                                 <tr>
00360                                         <td><?php print _("Host Image"); ?></td>
00361                                         <td><?php print $this->FOGCore->getClass('ImageManager')->buildSelectBox($Host->get('imageID')); ?>
00362                                         </td>
00363                                 </tr>
00364                                 <tr>
00365                                         <td><?php print _("Host Kernel"); ?></td>
00366                                         <td><input type="text" name="kern"
00367                                                 value="<?php print $Host->get('kernel'); ?>" /></td>
00368                                 </tr>
00369                                 <tr>
00370                                         <td><?php print _("Host Kernel Arguments"); ?></td>
00371                                         <td><input type="text" name="args"
00372                                                 value="<?php print $Host->get('kernelArgs'); ?>" /></td>
00373                                 </tr>
00374                                 <tr>
00375                                         <td><?php print _("Host Primary Disk"); ?></td>
00376                                         <td><input type="text" name="dev"
00377                                                 value="<?php print $Host->get('kernelDevice'); ?>" /></td>
00378                                 </tr>
00379                                 <tr>
00380                                         <td>&nbsp;</td>
00381                                         <td><input type="submit" value="<?php print _("Update"); ?>" /></td>
00382                                 </tr>
00383                         </table>
00384                 </form>
00385         </div>
00386 
00387         <!-- Basic Tasks -->
00388         <div id="host-tasks" class="organic-tabs-hidden">
00389                 <h2>
00390                         <?php print _('Host Tasks'); ?>
00391                 </h2>
00392                 <table cellpadding="0" cellspacing="0" border="0" width="100%">
00393                         <?php
00394 
00395                         // Find TaskTypes
00396                         $TaskTypes = $this->FOGCore->getClass('TaskTypeManager')->find(array('access' => array('both', 'host'), 'isAdvanced' => '0'), 'AND', 'id');
00397 
00398                         // Iterate -> Print
00399                         foreach ((array)$TaskTypes AS $TaskType)
00400                         {
00401                                 printf('<tr>
00402                                                 <td class="task-action"><a href="?node=%s&sub=deploy&type=%s&%s=%s"><img src="./images/%s" /><p>%s</p></a></td>
00403                                                 <td><p>%s</p></td>
00404                                                 </tr>',
00405                                                 $this->node,
00406                                                 $TaskType->get('id'),
00407                                                 $this->id,
00408                                                 $Host->get('id'),
00409                                                 $TaskType->get('icon'),
00410                                                 _($TaskType->get('name')),
00411                                                 _($TaskType->get('description'))
00412                                 );
00413                         }
00414 
00415                         ?>
00416                         <tr>
00417                                 <td class="task-action"><a
00418                                         href="<?php print $this->formAction; ?>#host-tasks"
00419                                         class="advanced-tasks-link"><img src="./images/host-advanced.png" />
00420                                                 <p>
00421                                                         <?php echo(_("Advanced")); ?>
00422                                                 </p> </a></td>
00423                                 <td><p>
00424                                                 <?php print _("View advanced tasks for this host."); ?>
00425                                         </p></td>
00426                         </tr>
00427                 </table>
00428 
00429                 <div id="advanced-tasks" class="hidden">
00430                         <h2>
00431                                 <?php print _('Advanced Actions'); ?>
00432                         </h2>
00433                         <table cellpadding="0" cellspacing="0" border="0" width="100%">
00434                                 <?php
00435                                         
00436                                 // Find TaskTypes
00437                                 $TaskTypes = $this->FOGCore->getClass('TaskTypeManager')->find(array('access' => array('both', 'host'), 'isAdvanced' => '1'), 'AND', 'id');
00438                                         
00439                                 // Iterate -> Print
00440                                 foreach ((array)$TaskTypes AS $TaskType)
00441                                 {
00442                                         printf('<tr>
00443                                                         <td class="task-action"><a href="?node=%s&sub=deploy&type=%s&%s=%s"><img src="./images/%s" /><p>%s</p></a></td>
00444                                                         <td><p>%s</p></td>
00445                                                         </tr>',
00446                                                         $this->node,
00447                                                         $TaskType->get('id'),
00448                                                         $this->id,
00449                                                         $Host->get('id'),
00450                                                         $TaskType->get('icon'),
00451                                                         _($TaskType->get('name')),
00452                                                         _($TaskType->get('description'))
00453                                         );
00454                                 }
00455                                         
00456                                 ?>
00457                         </table>
00458                 </div>
00459         </div>
00460 
00461         <!-- Active Directory -->
00462         <div id="host-active-directory" class="organic-tabs-hidden">
00463                 <form method="POST"
00464                         action="<?php print $this->formAction; ?>&tab=host-active-directory">
00465                         <input type="hidden" name="id"
00466                                 value="<?php print $this->REQUEST['id']; ?>" />
00467                         <h2>
00468                                 <?php print _("Active Directory"); ?>
00469                         </h2>
00470                         <table cellpadding=0 cellspacing=0 border=0 width="100%">
00471                                 <tr>
00472                                         <td><?php print _("Join Domain after image task"); ?></td>
00473                                         <td><input id='adEnabled' type="checkbox" name="domain"
00474                                         <?php print ($Host->get('useAD') == '1' ? ' checked="checked"' : ''); ?> />
00475                                         </td>
00476                                 </tr>
00477                                 <tr>
00478                                         <td><?php print _("Domain name"); ?></td>
00479                                         <td><input id="adDomain" class="smaller" type="text"
00480                                                 name="domainname" value="<?php print $Host->get('ADDomain'); ?>" />
00481                                         </td>
00482                                 </tr>
00483                                 <tr>
00484                                         <td><?php print _("Organizational Unit"); ?><br> <span
00485                                                 class="lightColor"><?php print _("(Blank for default)"); ?> </span>
00486                                         </td>
00487                                         <td><input size="50" style="width: 350px" id="adOU" class="smaller"
00488                                                 type="text" name="ou" value="<?php print $Host->get('ADOU'); ?>" />
00489                                         </td>
00490                                 </tr>
00491                                 <tr>
00492                                         <td><?php print _("Domain Username"); ?></td>
00493                                         <td><input id="adUsername" class="smaller" type="text"
00494                                                 name="domainuser" value="<?php print $Host->get('ADUser'); ?>" />
00495                                         </td>
00496                                 </tr>
00497                                 <tr>
00498                                         <td><?php print _("Domain Password"); ?><br /> <?php print _("(Must be encrypted)"); ?>
00499                                         </td>
00500                                         <td><input id="adPassword" class="smaller" type="text"
00501                                                 name="domainpassword" style="width: 250px"
00502                                                 value="<?php print $Host->get('ADPass'); ?>" /></td>
00503                                 </tr>
00504                                 <tr>
00505                                         <td colspan=2><center>
00506                                                         <br /> <input type="hidden" name="updatead" value="1" /><input
00507                                                                 type="submit" value="<?php print _("Update"); ?>" />
00508                                         
00509                                         </td>
00510                                 </tr>
00511                         </table>
00512                 </form>
00513         </div>
00514 
00515         <!-- Printers -->
00516         <div id="host-printers" class="organic-tabs-hidden">
00517                 <form method="POST"
00518                         action="<?php print $this->formAction; ?>&tab=host-printers">
00519                         <input type="hidden" name="id"
00520                                 value="<?php print $this->REQUEST['id']; ?>" />
00521                         <h2>
00522                                 <?php print _("Host Printer Configuration"); ?>
00523                         </h2>
00524                         <p>
00525                                 <?php print _("Select Management Level for this Host"); ?>
00526                         </p>
00527                         <p>
00528                                 <input type="radio" name="level" value="0"
00529                                 <?php print ($Host->get('printerLevel') === '0' || $Host->get('printerLevel') === '' ? ' checked="checked"' : ''); ?> />
00530                                 <?php print _("No Printer Management"); ?>
00531                                 <br /> <input type="radio" name="level" value="1"
00532                                 <?php print ($Host->get('printerLevel') === '1' ? ' checked="checked"' : ''); ?> />
00533                                 <?php print _("Add Only"); ?>
00534                                 <br /> <input type="radio" name="level" value="2"
00535                                 <?php print ($Host->get('printerLevel') === '2' ? ' checked="checked"' : ''); ?> />
00536                                 <?php print _("Add and Remove"); ?>
00537                                 <br />
00538                         </p>
00539 
00540                         <table cellpadding=0 cellspacing=0 border=0 width=100%>
00541                                 <thead>
00542                                         <tr class="header">
00543                                                 <td><?php print _("Default"); ?></td>
00544                                                 <td><?php print _("Printer Alias"); ?></td>
00545                                                 <td><?php print _("Printer Model"); ?></td>
00546                                                 <td><?php print _("Remove"); ?></td>
00547                                         </tr>
00548                                 </thead>
00549                                 <tbody>
00550                                         <?php
00551 
00552                                         foreach ($Host->getPrinters() AS $Printer)
00553                                         {
00554                                                 printf('<tr>
00555                                                                 <td>%s</td>
00556                                                                 <td>%s</td>
00557                                                                 <td>%s</td>
00558                                                                 <td><input type="checkbox" name="printerRemove[]" value="%s" /></td>
00559                                                                 </tr>',
00560                                                                 ($Printer->get('default') ? _('Yes') : ''),
00561                                                                 $Printer->get('name'),
00562                                                                 $Printer->get('model'),
00563                                                                 $Printer->get('id')
00564                                                 );
00565                                         }
00566 
00567                                         ?>
00568                                 </tbody>
00569                         </table>
00570 
00571                         <br /> <br />
00572                         <h2>Add new printer</h2>
00573                         <?php
00574                         print $this->FOGCore->getClass('PrinterManager')->buildSelectBox('', "prnt")
00575                         ?>
00576                         <br /> <input type="submit" value="<?php print _("Update"); ?>" />
00577                 </form>
00578         </div>
00579 
00580         <!-- Snapins -->
00581         <div id="host-snapins" class="organic-tabs-hidden">
00582                 <form method="POST"
00583                         action="<?php print $this->formAction; ?>&tab=host-snapins">
00584                         <input type="hidden" name="id"
00585                                 value="<?php print $this->REQUEST['id']; ?>" />
00586                         <h2>
00587                                 <?php print _("Snapins"); ?>
00588                         </h2>
00589 
00590                         <table cellpadding=0 cellspacing=0 border=0 width=100%>
00591                                 <thead>
00592                                         <tr class="header">
00593                                                 <td><?php print _("Snapin Name"); ?></td>
00594                                                 <td><?php print _("Remove"); ?></td>
00595                                         </tr>
00596                                 </thead>
00597                                 <tbody>
00598                                         <?php
00599 
00600                                         foreach ($Host->getSnapins() AS $Snapin)
00601                                         {
00602                                                 printf('<tr>
00603                                                                 <td>%s</td>
00604                                                                 <td><input type="checkbox" name="snapinRemove[]" value="%s" /></td>
00605                                                                 </tr>',
00606                                                                 $Snapin->get('name'),
00607                                                                 $Snapin->get('id')
00608                                                 );
00609                                         }
00610 
00611                                         ?>
00612                                 </tbody>
00613                         </table>
00614 
00615                         <br /> <br />
00616                         <h2>
00617                                 <?php print _("Add new snapin package"); ?>
00618                         </h2>
00619                         <?php print $this->FOGCore->getClass('SnapinManager')->buildSelectBox(); ?>
00620                         <p>
00621                                 <input type="submit" value="<?php print _("Update Snapins"); ?>" />
00622                         </p>
00623                 </form>
00624         </div>
00625 
00626         <!-- Service Configuration -->
00627         <div id="host-service" class="organic-tabs-hidden">
00628                 <form method="POST"
00629                         action="<?php print $this->formAction; ?>&tab=host-service">
00630                         <input type="hidden" name="id"
00631                                 value="<?php print $this->REQUEST['id']; ?>" />
00632                         <h2>
00633                                 <?php print _("Service Configuration"); ?>
00634                         </h2>
00635                         <fieldset>
00636                                 <legend>
00637                                         <?php print _("General"); ?>
00638                                 </legend>
00639                                 <table cellpadding=0 cellspacing=0 border=0 width="100%">
00640                                         <?php
00641 
00642                                         foreach ($this->FOGCore->getClass('ModuleManager')->find() AS $Module)
00643                                         {
00644                                                 printf('<tr><td width="270">%s</td><td><input type="checkbox" name="%s" value="1"%s /></td><td><span class="icon icon-help hand" title="%s"></span></td></tr>',
00645                                                                 $Module->get('name') . ' ' . _('Enabled?'),
00646                                                                 $Module->get('shortName'),
00647                                                                 ($Host->getModuleStatus($Module) ? ' checked="checked"' : ''),
00648                                                                 str_replace('"', '\"', $Module->get('description'))
00649                                                 );
00650 
00651                                         }
00652                                         ?>
00653 
00654                                         <tr>
00655                                                 <td>&nbsp;</td>
00656                                                 <td><input type="submit" value="<?php print _("Update"); ?>" /></td>
00657                                         </tr>
00658                                 </table>
00659                         </fieldset>
00660                         <fieldset>
00661                                 <legend>
00662                                         <?php print _("Host Screen Resolution"); ?>
00663                                 </legend>
00664                                 <table cellpadding=0 cellspacing=0 border=0 width="100%">
00665                                         <?php
00666                                         /*
00667                                          $x = "";
00668                                         $y = "";
00669                                         $r = "";
00670 
00671                                         $sql = "SELECT
00672                                         *
00673                                         FROM
00674                                         hostScreenSettings
00675                                         WHERE
00676                                         hssHostID = '$id'";
00677                                         $res = mysql_query( $sql ) or criticalError( mysql_error(), "FOG :: Database error!
00678                                                         while( $ar = mysql_fetch_array( $res ) )
00679                                                         {
00680                                                         $x = $ar["hssWidth"];
00681                                                         $y = $ar["hssHeight"];
00682                                                         $r = $ar["hssRefresh"];
00683                                                         }
00684                                                         */
00685                                         ?>
00686 
00687                                         <tr>
00688                                                 <td width="270"><?php print _("Screen Width (in pixels)"); ?></td>
00689                                                 <td><input type="text" name="x" value="<?php print $x; ?>" /></td>
00690                                                 <td><span class="icon icon-help hand"
00691                                                         title="<?php print _("This setting defines the screen horizontal resolution to be used with this host.  Leaving this field blank will force this host to use the global default setting"); ?>"></span>
00692                                                 </td>
00693                                         </tr>
00694                                         <tr>
00695                                                 <td width="270"><?php print _("Screen Height (in pixels)"); ?></td>
00696                                                 <td><input type="text" name="y" value="<?php print $y; ?>" /></td>
00697                                                 <td><span class="icon icon-help hand"
00698                                                         title="<?php print _("This setting defines the screen vertial resolution to be used with this host.  Leaving this field blank will force this host to use the global default setting"); ?>"></span>
00699                                                 </td>
00700                                         </tr>
00701                                         <tr>
00702                                                 <td width="270"><?php print _("Screen Refresh Rate"); ?></td>
00703                                                 <td><input type="text" name="r" value="<?php print $r; ?>" /></td>
00704                                                 <td><span class="icon icon-help hand"
00705                                                         title="<?php print _("This setting defines the screen refresh rate to be used with this host.  Leaving this field blank will force this host to use the global default setting"); ?>"></span>
00706                                                 </td>
00707                                         </tr>
00708                                         <tr>
00709                                                 <td>&nbsp;</td>
00710                                                 <td><input type="submit" value="<?php print _("Update"); ?>" /></td>
00711                                         </tr>
00712                                 </table>
00713                         </fieldset>
00714 
00715                         <fieldset>
00716                                 <legend>
00717                                         <?php print _("Auto Log Out Settings"); ?>
00718                                 </legend>
00719                                 <table cellpadding=0 cellspacing=0 border=0 width="100%">
00720                                         <?php
00721                                         /*
00722                                          $tme = "";
00723 
00724                                         $sql = "SELECT
00725                                         *
00726                                         FROM
00727                                         hostAutoLogOut
00728                                         WHERE
00729                                         haloHostID = '$id'";
00730                                         $res = mysql_query( $sql ) or criticalError( mysql_error(), "FOG :: Database error!
00731                                                         while( $ar = mysql_fetch_array( $res ) )
00732                                                         {
00733                                                         $tme = $ar["haloTime"];
00734                                                         }
00735                                                         */
00736                                         ?>
00737                                         <tr>
00738                                                 <td width="270"><?php print _("Auto Log Out Time (in minutes)"); ?>
00739                                                 </td>
00740                                                 <td><input type="text" name="tme" value="<?php print $tme; ?>" />
00741                                                 </td>
00742                                                 <td><span class="icon icon-help hand"
00743                                                         title="<?php print _("This setting defines the time to auto log out this host."); ?>"></span>
00744                                                 </td>
00745                                         </tr>
00746                                         <tr>
00747                                                 <td>&nbsp;</td>
00748                                                 <td><input type="submit" value="<?php print _("Update"); ?>" /></td>
00749                                         </tr>
00750                                 </table>
00751                         </fieldset>
00752                 </form>
00753         </div>
00754 
00755         <!-- Inventory -->
00756         <div id="host-hardware-inventory" class="organic-tabs-hidden">
00757                 <form method="POST"
00758                         action="<?php print $this->formAction; ?>&tab=host-hardware-inventory">
00759                         <input type="hidden" name="id"
00760                                 value="<?php print $this->REQUEST['id']; ?>" />
00761                         <h2>
00762                                 <?php print _("Host Hardware Inventory"); ?>
00763                         </h2>
00764 
00765                         <table cellpadding=0 cellspacing=0 border=0 width=100%>
00766                                 <?php
00767                                 $sql = "SELECT
00768                                 *
00769                                 FROM
00770                                 inventory
00771                                 WHERE
00772                                 iHostID = '" . $Host->get('id') . "'";
00773                                 $res = mysql_query( $sql ) or die( mysql_error() );
00774                                 if ( mysql_num_rows( $res ) > 0 )
00775                                 {
00776                                         while ( $ar = mysql_fetch_array( $res ) )
00777                                         {
00778                                                 // Get unique core and manufactor names
00779                                                 foreach (array('iCpuman','iCpuversion') AS $x) $ar[$x] = implode(' ', array_unique(explode(' ', $ar[$x])));
00780 
00781                                                 // TODO: UGLY!!!!!
00782                                                 ?>
00783                                 <tr>
00784                                         <td>&nbsp;</td>
00785                                         <td style='width: 200px'>&nbsp;<?php print _("Primary User"); ?>
00786                                         </td>
00787                                         <td>&nbsp;<input type="text"
00788                                                 value="<?php print $ar["iPrimaryUser"]; ?>" name="pu" />
00789                                         </td>
00790                                 </tr>
00791                                 <tr>
00792                                         <td>&nbsp;</td>
00793                                         <td>&nbsp;<?php print _("Other Tag #1"); ?>
00794                                         </td>
00795                                         <td>&nbsp;<input type="text"
00796                                                 value="<?php print $ar["iOtherTag"]; ?>" name="other1" />
00797                                         </td>
00798                                 </tr>
00799                                 <tr>
00800                                         <td>&nbsp;</td>
00801                                         <td>&nbsp;<?php print _("Other Tag #2"); ?>
00802                                         </td>
00803                                         <td>&nbsp;<input type="text"
00804                                                 value="<?php print $ar["iOtherTag1"]; ?>" name="other2" />
00805                                         </td>
00806                                 </tr>
00807                                 <tr>
00808                                         <td>&nbsp;</td>
00809                                         <td>&nbsp;<?php print _("System Manufacturer"); ?>
00810                                         </td>
00811                                         <td>&nbsp;<?php print $ar["iSysman"]; ?>
00812                                         </td>
00813                                 </tr>
00814                                 <tr>
00815                                         <td>&nbsp;</td>
00816                                         <td>&nbsp;<?php print _("System Product"); ?>
00817                                         </td>
00818                                         <td>&nbsp;<?php print $ar["iSysproduct"]; ?>
00819                                         </td>
00820                                 </tr>
00821                                 <tr>
00822                                         <td>&nbsp;</td>
00823                                         <td>&nbsp;<?php print _("System Version"); ?>
00824                                         </td>
00825                                         <td>&nbsp;<?php print $ar["iSysversion"]; ?>
00826                                         </td>
00827                                 </tr>
00828                                 <tr>
00829                                         <td>&nbsp;</td>
00830                                         <td>&nbsp;<?php print _("System Serial Number"); ?>
00831                                         </td>
00832                                         <td>&nbsp;<?php print $ar["iSysserial"]; ?>
00833                                         </td>
00834                                 </tr>
00835                                 <tr>
00836                                         <td>&nbsp;</td>
00837                                         <td>&nbsp;<?php print _("System Type"); ?>
00838                                         </td>
00839                                         <td>&nbsp;<?php print $ar["iSystype"]; ?>
00840                                         </td>
00841                                 </tr>
00842                                 <tr>
00843                                         <td>&nbsp;</td>
00844                                         <td>&nbsp;<?php print _("BIOS Vendor"); ?>
00845                                         </td>
00846                                         <td>&nbsp;<?php print $ar["iBiosvendor"]; ?>
00847                                         </td>
00848                                 </tr>
00849                                 <tr>
00850                                         <td>&nbsp;</td>
00851                                         <td>&nbsp;<?php print _("BIOS Version"); ?>
00852                                         </td>
00853                                         <td>&nbsp;<?php print $ar["iBiosversion"]; ?>
00854                                         </td>
00855                                 </tr>
00856                                 <tr>
00857                                         <td>&nbsp;</td>
00858                                         <td>&nbsp;<?php print _("BIOS Date"); ?>
00859                                         </td>
00860                                         <td>&nbsp;<?php print $ar["iBiosdate"]; ?>
00861                                         </td>
00862                                 </tr>
00863                                 <tr>
00864                                         <td>&nbsp;</td>
00865                                         <td>&nbsp;<?php print _("Motherboard Manufacturer"); ?>
00866                                         </td>
00867                                         <td>&nbsp;<?php print $ar["iMbman"]; ?>
00868                                         </td>
00869                                 </tr>
00870                                 <tr>
00871                                         <td>&nbsp;</td>
00872                                         <td>&nbsp;<?php print _("Motherboard Product Name"); ?>
00873                                         </td>
00874                                         <td>&nbsp;<?php print $ar["iMbproductname"]; ?>
00875                                         </td>
00876                                 </tr>
00877                                 <tr>
00878                                         <td>&nbsp;</td>
00879                                         <td>&nbsp;<?php print _("Motherboard Version"); ?>
00880                                         </td>
00881                                         <td>&nbsp;<?php print $ar["iMbversion"]; ?>
00882                                         </td>
00883                                 </tr>
00884                                 <tr>
00885                                         <td>&nbsp;</td>
00886                                         <td>&nbsp;<?php print _("Motherboard Serial Number"); ?>
00887                                         </td>
00888                                         <td>&nbsp;<?php print $ar["iMbserial"]; ?>
00889                                         </td>
00890                                 </tr>
00891                                 <tr>
00892                                         <td>&nbsp;</td>
00893                                         <td>&nbsp;<?php print _("Motherboard Asset Tag"); ?>
00894                                         </td>
00895                                         <td>&nbsp;<?php print $ar["iMbasset"]; ?>
00896                                         </td>
00897                                 </tr>
00898                                 <tr>
00899                                         <td>&nbsp;</td>
00900                                         <td>&nbsp;<?php print _("CPU Manufacturer"); ?>
00901                                         </td>
00902                                         <td>&nbsp;<?php print $ar["iCpuman"]; ?>
00903                                         </td>
00904                                 </tr>
00905                                 <tr>
00906                                         <td>&nbsp;</td>
00907                                         <td>&nbsp;<?php print _("CPU Version"); ?>
00908                                         </td>
00909                                         <td>&nbsp;<?php print $ar["iCpuversion"]; ?>
00910                                         </td>
00911                                 </tr>
00912                                 <tr>
00913                                         <td>&nbsp;</td>
00914                                         <td>&nbsp;<?php print _("CPU Normal Speed"); ?>
00915                                         </td>
00916                                         <td>&nbsp;<?php print $ar["iCpucurrent"]; ?>
00917                                         </td>
00918                                 </tr>
00919                                 <tr>
00920                                         <td>&nbsp;</td>
00921                                         <td>&nbsp;<?php print _("CPU Max Speed"); ?>
00922                                         </td>
00923                                         <td>&nbsp;<?php print $ar["iCpumax"]; ?>
00924                                         </td>
00925                                 </tr>
00926                                 <tr>
00927                                         <td>&nbsp;</td>
00928                                         <td>&nbsp;<?php print _("Memory"); ?>
00929                                         </td>
00930                                         <td>&nbsp;<?php print $ar["iMem"]; ?>
00931                                         </td>
00932                                 </tr>
00933                                 <tr>
00934                                         <td>&nbsp;</td>
00935                                         <td>&nbsp;<?php print _("Hard Disk Model"); ?>
00936                                         </td>
00937                                         <td>&nbsp;<?php print $ar["iHdmodel"]; ?>
00938                                         </td>
00939                                 </tr>
00940                                 <tr>
00941                                         <td>&nbsp;</td>
00942                                         <td>&nbsp;<?php print _("Hard Disk Firmware"); ?>
00943                                         </td>
00944                                         <td>&nbsp;<?php print $ar["iHdfirmware"]; ?>
00945                                         </td>
00946                                 </tr>
00947                                 <tr>
00948                                         <td>&nbsp;</td>
00949                                         <td>&nbsp;<?php print _("Hard Disk Serial Number"); ?>
00950                                         </td>
00951                                         <td>&nbsp;<?php print $ar["iHdserial"]; ?>
00952                                         </td>
00953                                 </tr>
00954                                 <tr>
00955                                         <td>&nbsp;</td>
00956                                         <td>&nbsp;<?php print _("Chassis Manufacturer"); ?>
00957                                         </td>
00958                                         <td>&nbsp;<?php print $ar["iCaseman"]; ?>
00959                                         </td>
00960                                 </tr>
00961                                 <tr>
00962                                         <td>&nbsp;</td>
00963                                         <td>&nbsp;<?php print _("Chassis Version"); ?>
00964                                         </td>
00965                                         <td>&nbsp;<?php print $ar["iCasever"]; ?>
00966                                         </td>
00967                                 </tr>
00968                                 <tr>
00969                                         <td>&nbsp;</td>
00970                                         <td>&nbsp;<?php print _("Chassis Serial"); ?>
00971                                         </td>
00972                                         <td>&nbsp;<?php print $ar["iCaseserial"]; ?>
00973                                         </td>
00974                                 </tr>
00975                                 <tr>
00976                                         <td>&nbsp;</td>
00977                                         <td>&nbsp;<?php print _("Chassis Asset"); ?>
00978                                         </td>
00979                                         <td>&nbsp;<?php print $ar["iCaseasset"]; ?>
00980                                         </td>
00981                                 </tr>
00982                                 <tr>
00983                                         <td>&nbsp;</td>
00984                                         <td colspan='2'><center>
00985                                                         <input type="hidden" name="update" value="1" /><input
00986                                                                 type="submit" value="<?php print _("Update"); ?>" />
00987                                         
00988                                         </td>
00989                                 </tr>
00990                                 <?php
00991                                         }
00992                                 }
00993                                 else
00994                                 {
00995                                         ?>
00996                                 <tr>
00997                                         <td colspan="3" class="c"><?php print _("No Inventory found for this host"); ?>
00998                                         </td>
00999                                 </tr>
01000                                 <?php
01001                                 }
01002                                 ?>
01003                         </table>
01004                 </form>
01005         </div>
01006 
01007         <!-- Virus -->
01008         <div id="host-virus-history" class="organic-tabs-hidden">
01009                 <form method="POST"
01010                         action="<?php print $this->formAction; ?>&tab=host-virus-history">
01011                         <input type="hidden" name="id"
01012                                 value="<?php print $this->REQUEST['id']; ?>" />
01013                         <h2>
01014                                 <?php print _("Virus History"); ?>
01015                                 (<a
01016                                         href="<?php print "?node=$GLOBALS[node]&sub=$GLOBALS[sub]&id=$GLOBALS[id]&delvid=all&tab=$GLOBALS[tab]"; ?>"><?php print _("clear all history"); ?>
01017                                 </a>)
01018                         </h2>
01019                         <table cellpadding=0 cellspacing=0 border=0 width=100%>
01020                                 <tr class="header">
01021                                         <td>&nbsp;<b><?php print _("Virus Name"); ?> </b>
01022                                         </td>
01023                                         <td><b><?php print _("File"); ?> </b></td>
01024                                         <td><b><?php print _("Mode"); ?> </b></td>
01025                                         <td><b><?php print _("Date"); ?> </b></td>
01026                                         <td><b><?php print _("Clear"); ?> </b></td>
01027                                 </tr>
01028                                 <?php
01029                                 $sql = "SELECT
01030                                 *
01031                                 FROM
01032                                 virus
01033                                 WHERE
01034                                 vHostMAC = '" . $Host->get('mac') . "'
01035                                 ORDER BY
01036                                 vDateTime, vName";
01037                                 $resSnap = mysql_query( $sql ) or die( mysql_error() );
01038                                 if ( mysql_num_rows( $resSnap ) > 0 )
01039                                 {
01040                                         $i = 0;
01041                                         while ( $arSp = mysql_fetch_array( $resSnap ) )
01042                                         {
01043                                                 ?>
01044                                 <tr <?php print ( $i++ % 2 == 0 ? ' class="alt"' : ''); ?>>
01045                                         <td>&nbsp;<a
01046                                                 href="http://www.google.com/search?q=<?php print $arSp["vName"]; ?>"
01047                                                 target="_blank"><?php print $arSp["vName"]; ?> </a>
01048                                         </td>
01049                                         <td><?php print $arSp["vOrigFile"]; ?></td>
01050                                         <td><?php print avModeToString( $arSp["vMode"] ); ?></td>
01051                                         <td><?php print $arSp["vDateTime"]; ?></td>
01052                                         <td><a
01053                                                 href="?node=$node&sub=$sub&id=<?php print $id; ?>&delvid=<?php print $arSp["vID"]; ?>"><img
01054                                                         src="images/deleteSmall.png" class="link" /> </a></td>
01055                                 </tr>
01056                                 <?php
01057                                         }
01058                                 }
01059                                 else
01060                                 {
01061                                         ?>
01062                                 <tr>
01063                                         <td colspan="5" class="c"><?php print _("No Virus Information Reported for this host."); ?>
01064                                         </td>
01065                                 </tr>
01066                                 <?php
01067                                 }
01068                                 ?>
01069                         </table>
01070                 </form>
01071         </div>
01072 
01073         <!-- Login History -->
01074         <div id="host-login-history" class="organic-tabs-hidden">
01075                 <form method="POST"
01076                         action="<?php print $this->formAction; ?>&tab=host-login-history">
01077                         <input type="hidden" name="id"
01078                                 value="<?php print $this->REQUEST['id']; ?>" />
01079                         <h2>
01080                                 <?php print _("Host Login History"); ?>
01081                         </h2>
01082                         <?php
01083 
01084                         $dte = mysql_real_escape_string($_POST["dte"]);
01085 
01086                         ?>
01087                         <p>
01088                                 View History for
01089                                 <?php
01090                                         
01091                                 $sql = "SELECT
01092                                 utDate as dte
01093                                 FROM
01094                                 userTracking
01095                                 WHERE
01096                                 utHostID = '" . $Host->get('id') . "'
01097                                 GROUP BY
01098                                 utDate
01099                                 ORDER BY
01100                                 utDate desc";
01101                                 $res = mysql_query( $sql ) or die( mysql_error() );
01102                                 ?>
01103                         
01104                         
01105                         <form id="dte" method="post"
01106                                 action="?node=$_GET[node]&sub=$_GET[sub]&id=$_GET[id]">
01107                                 <select name="dte" size="1">
01108                                         <?php
01109                                         $blFirst = true;
01110                                         while( $ar = mysql_fetch_array( $res ) )
01111                                         {
01112                                                 if ( $blFirst )
01113                                                 {
01114                                                         if ( $dte == null )
01115                                                                 $dte = $ar["dte"];
01116                                                 }
01117                                                         
01118                                                 $sel = "";
01119                                                 if ( $dte == $ar["dte"] )
01120                                                         $sel = ' selected="selected" ';
01121                                                         
01122                                                 ?>
01123                                         <option value="<?php print $ar["dte"]; ?>" $sel>
01124                                                 <?php print $ar["dte"]; ?>
01125                                         </option>
01126                                         <?php
01127                                         }
01128                                         ?>
01129                                 </select> <a href="#"
01130                                         onclick="document.getElementById('dte').submit();"><img
01131                                         src="images/go.png" class="noBorder" /> </a>
01132                         </form>
01133                         </p>
01134                         <?php
01135                         $sql = "SELECT
01136                         *
01137                         FROM
01138                         ( SELECT *, TIME(utDateTime) as tme FROM userTracking WHERE utHostID = '" . $Host->get('id') . "' and utDate = DATE('" . $dte . "') ) userTracking
01139                         ORDER BY
01140                         utDateTime";
01141                         $res = mysql_query( $sql ) or die( mysql_error() );
01142 
01143                         ?>
01144                         <table cellpadding=0 cellspacing=0 border=0 width=100%>
01145                                 <tr class="header">
01146                                         <td><b>&nbsp;<?php print _("Action"); ?>
01147                                         </b></td>
01148                                         <td><b>&nbsp;<?php print _("Username"); ?>
01149                                         </b></td>
01150                                         <td><b>&nbsp;<?php print _("Time"); ?>
01151                                         </b></td>
01152                                         <td><b>&nbsp;<?php print _("Description"); ?>
01153                                         </b></td>
01154                                 </tr>
01155 
01156                                 <?php
01157                                 $cnt = 0;
01158                                 $arAllUsers = array();
01159                                 while( $ar = mysql_fetch_array( $res ) )
01160                                 {
01161                                         if ( ! in_array( $ar["utUserName"], $arAllUsers ) )
01162                                                 $arAllUsers[] = $ar["utUserName"];
01163 
01164                                         ?>
01165                                 <tr <?php print ( $cnt++ % 2 == 0 ? ' class="alt"' : ''); ?>>
01166                                         <td>&nbsp;<?php print userTrackerActionToString( $ar["utAction"] ); ?>
01167                                         </td>
01168                                         <td>&nbsp;<?php print $ar["utUserName"]; ?>
01169                                         </td>
01170                                         <td>&nbsp;<?php print $ar["tme"]; ?>
01171                                         </td>
01172                                         <td>&nbsp;<?php print trimString( $ar["utDesc"], 60 ); ?>
01173                                         </td>
01174                                 </tr>
01175                                 <?php
01176                                 }
01177                                 ?>
01178 
01179                         </table>
01180 
01181                         <?php
01182 
01183                         $_SESSION["fog_logins"] = array();
01184 
01185                         for( $i = 0; $i < count( $arAllUsers ); $i++ )
01186                         {
01187                                 $sql = "SELECT
01188                                 utDateTime, utAction
01189                                 FROM
01190                                 ( SELECT *, TIME(utDateTime) as tme FROM userTracking WHERE utUserName = '<?php print mysql_real_escape_string( $arAllUsers[$i] ); ?>' and utHostID = '<?php print $id; ?>' and utDate = DATE('<?php print $dte; ?>') ) userTracking
01191                                 ORDER BY
01192                                 utDateTime";
01193                                 $res = mysql_query( $sql ) or die( mysql_error() );
01194                                 $tmpUserLogin = null;
01195                                 while( $ar = mysql_fetch_array( $res ) )
01196                                 {
01197                                         if ( $ar["utAction"] == "1" || $ar["utAction"] == "99" )
01198                                         {
01199                                                 $tmpUserLogin = new UserLoginEntry( $arAllUsers[$i] );
01200                                                 $tmpUserLogin->setLogInTime( $ar["utDateTime"] );
01201                                                 $tmpUserLogin->setClean( ($ar["utAction"] == "1") );
01202                                         }
01203                                         else if ( $ar["utAction"] == "0" )
01204                                         {
01205                                                 if ( $tmpUserLogin != null )
01206                                                         $tmpUserLogin->setLogOutTime( $ar["utDateTime"] );
01207 
01208 
01209                                                 $_SESSION["fog_logins"][] = serialize( $tmpUserLogin );
01210                                                 $tmpUserLogin = null;
01211                                         }
01212                                 }
01213                         }
01214 
01215                         if ( count( $_SESSION["fog_logins"] ) > 0 )
01216                         {
01217                                 ?>
01218                         <p>
01219                                 <img src="/phpimages/hostloginhistory.phpgraph.php" />
01220                         </p>
01221                         <?php
01222                         }
01223                         ?>
01224                 </form>
01225         </div>
01226 </div>
01227 <!-- </form> -->
01228 <?php
01229         }
01230 
01231         public function edit_post()
01232         {
01233                 // Find
01234                 $Host = new Host($this->REQUEST['id']);
01235 
01236                 // Hook
01237                 $this->HookManager->processEvent('HOST_EDIT_POST', array('Host' => &$Host));
01238 
01239                 // POST
01240                 try
01241                 {
01242                         // Error checking
01243                         if (empty($_POST['id']))
01244                         {
01245                                 throw new Exception('Host ID is required');
01246                         }
01247                                 
01248                         // Tabs
01249                         switch ($this->REQUEST['tab'])
01250                         {
01251                                 // General
01252                                 case 'host-general';
01253                                 // Error checking
01254                                 if (empty($_POST['mac']))
01255                                 {
01256                                         throw new Exception('MAC Address is required');
01257                                 }
01258                                         
01259                                 // Variables
01260                                 $mac = new MACAddress($_POST['mac']);
01261                                         
01262                                 // Error checking
01263                                 if (!$mac->isValid())
01264                                 {
01265                                         throw new Exception('MAC Address is not valid');
01266                                 }
01267 
01268                                 // Define new Image object with data provided
01269                                 $Host   ->set('name',           $_POST['host'])
01270                                 ->set('description',    $_POST['description'])
01271                                 ->set('ip',             $_POST['ip'])
01272                                 ->set('mac',            $mac)
01273                                 ->set('osID',           $_POST['os'])
01274                                 ->set('imageID',        $_POST['image'])
01275                                 ->set('kernel',         $_POST['kern'])
01276                                 ->set('kernelArgs',     $_POST['args'])
01277                                 ->set('kernelDevice',   $_POST['dev']);
01278                                         
01279                                 // Add Additional MAC Addresses
01280                                 $Host   ->set('additionalMACs', (array)$_POST['additionalMACs']);
01281                                         
01282                                 break;
01283 
01284                                 // Active Directory
01285                                 case 'host-active-directory';
01286 
01287                                 $Host   ->set('useAD',          ($_POST["domain"] == "on" ? '1' : '0'))
01288                                 ->set('ADDomain',       $_POST['domainname'])
01289                                 ->set('ADOU',           $_POST['ou'])
01290                                 ->set('ADUser',         $_POST['domainuser'])
01291                                 ->set('ADPass',         $_POST['domainpassword']);
01292                                         
01293                                 break;
01294 
01295                                 // Printers
01296                                 case 'host-printers';
01297 
01298                                 // Set printer level for Host
01299                                 $Host->set('printerLevel', (int)$this->REQUEST['level']);
01300 
01301                                 // Add
01302                                 if (!empty($this->REQUEST['prnt']))
01303                                 {
01304                                         $Host->addPrinter($this->REQUEST['prnt']);
01305                                 }
01306                                         
01307                                 // Remove
01308                                 if (!empty($this->REQUEST['printerRemove']))
01309                                 {
01310                                         $Host->removePrinter($this->REQUEST['printerRemove']);
01311                                 }
01312                                         
01313                                 // TODO: Set default printer
01314                                 /*
01315                                 if ( $_GET["default"] !== null )
01316                                 {
01317                                 setDefaultPrinter( $GLOBALS['conn'], $_GET["default"] );
01318                                 }
01319                                 */
01320                                         
01321                                 break;
01322 
01323                                 // Snapins
01324                                 case 'host-snapins';
01325                                         
01326                                 // Add
01327                                 if (!empty($this->REQUEST['snapin']))
01328                                 {
01329                                         $Host->addSnapin($this->REQUEST['snapin']);
01330                                 }
01331                                         
01332                                 // Remove
01333                                 if (!empty($this->REQUEST['snapinRemove']))
01334                                 {
01335                                         $Host->removeSnapin($this->REQUEST['snapinRemove']);
01336                                 }
01337                                         
01338                                 break;
01339                                         
01340                                 // Service
01341                                 case 'host-service';
01342                                 /*
01343                                         if ( $_GET["updatemodulestatus"] == "1" )
01344                                         {
01345 
01346                                 //$clientupdaterchecked = " checked=\"checked\" ";
01347                                 //$hostregisterchecked = " checked=\"checked\" ";
01348                                 //$printermanagerchecked = " checked=\"checked\" ";
01349                                 //$taskrebootchecked = " checked=\"checked\" ";
01350                                 //$usertrackerchecked = " checked=\"checked\" ";
01351                                         
01352                                         
01353                                 $dircleanupstate = "0";
01354                                 $usercleanupstate = "0";
01355                                 $displaymanagerstate = "0";
01356                                 $alostate = "0";
01357                                 $gfstate = "0";
01358                                 $snapinstate = "0";
01359                                 $hncstate = "0";
01360                                 $custate = "0";
01361                                 $hrstate = "0";
01362                                 $pmstate = "0";
01363                                 $trstate = "0";
01364                                 $utstate = "0";
01365 
01366                                 if ( $_POST["dircleanen"] == "on" ) $dircleanupstate = "1";
01367                                 if ( $_POST["usercleanen"] == "on" ) $usercleanupstate = "1";
01368                                 if ( $_POST["displaymanager"] == "on" ) $displaymanagerstate = "1";
01369                                 if ( $_POST["alo"] == "on" ) $alostate = "1";
01370                                 if ( $_POST["gf"] == "on" ) $gfstate = "1";
01371                                 if ( $_POST["snapin"] == "on" ) $snapinstate = "1";
01372                                 if ( $_POST["hostnamechanger"] == "on" ) $hncstate = "1";
01373                                 if ( $_POST["clientupdater"] == "on" ) $custate = "1";
01374                                 if ( $_POST["hostregister"] == "on" ) $hrstate = "1";
01375                                 if ( $_POST["printermanager"] == "on" ) $pmstate = "1";
01376                                 if ( $_POST["taskreboot"] == "on" ) $trstate = "1";
01377                                 if ( $_POST["usertracker"] == "on" ) $utstate = "1";
01378 
01379                                 setHostModuleStatus( $GLOBALS['conn'], $dircleanupstate, $id, 'dircleanup' );
01380                                 setHostModuleStatus( $GLOBALS['conn'], $usercleanupstate, $id, 'usercleanup' );
01381                                 setHostModuleStatus( $GLOBALS['conn'], $displaymanagerstate, $id, 'displaymanager' );
01382                                 setHostModuleStatus( $GLOBALS['conn'], $alostate, $id, 'autologout' );
01383                                 setHostModuleStatus( $GLOBALS['conn'], $gfstate, $id, 'greenfog' );
01384                                 setHostModuleStatus( $GLOBALS['conn'], $snapinstate, $id, 'snapin' );
01385                                 setHostModuleStatus( $GLOBALS['conn'], $hncstate, $id, 'hostnamechanger' );
01386                                 setHostModuleStatus( $GLOBALS['conn'], $custate, $id, 'clientupdater' );
01387                                 setHostModuleStatus( $GLOBALS['conn'], $hrstate, $id, 'hostregister' );
01388                                 setHostModuleStatus( $GLOBALS['conn'], $pmstate, $id, 'printermanager' );
01389                                 setHostModuleStatus( $GLOBALS['conn'], $trstate, $id, 'taskreboot' );
01390                                 setHostModuleStatus( $GLOBALS['conn'], $utstate, $id, 'usertracker' );
01391 
01392                                 // update screen settings
01393                                 $x = mysql_real_escape_string( $_POST["x"] );
01394                                 $y = mysql_real_escape_string( $_POST["y"] );
01395                                 $r = mysql_real_escape_string( $_POST["r"] );
01396                                 if ( $x == "" && $y == "" && $z == "" )
01397                                 {
01398                                 $sql = "DELETE FROM hostScreenSettings WHERE hssHostID = '$id'";
01399                                 $res = mysql_query( $sql, $GLOBALS['conn'] ) or criticalError( mysql_error(), _("FOG :: Database error!") );
01400                                 }
01401                                 else
01402                                 {
01403                                 $sql = "SELECT
01404                                 COUNT(*) as cnt
01405                                 FROM
01406                                 hostScreenSettings
01407                                 WHERE
01408                                 hssHostID = '$id'";
01409                                 $res = mysql_query( $sql, $GLOBALS['conn'] ) or criticalError( mysql_error(), _("FOG :: Database error!") );
01410                                 $blFound = false;
01411                                 while( $ar = mysql_fetch_array( $res ) )
01412                                 {
01413                                 if ( $ar["cnt"] > 0 ) $blFound = true;
01414                                 }
01415 
01416                                 if ( $blFound )
01417                                 {
01418                                 $sql = "UPDATE
01419                                 hostScreenSettings
01420                                 set
01421                                 hssWidth = '$x',
01422                                 hssHeight = '$y',
01423                                 hssRefresh = '$r'
01424                                 WHERE
01425                                 hssHostID = '$id'";
01426                                 }
01427                                 else
01428                                 {
01429                                 $sql = "INSERT INTO hostScreenSettings(hssHostID, hssWidth, hssHeight, hssRefresh) values('$id', '$x', '$y', '$r')";
01430                                 }
01431                                 if ( ! mysql_query( $sql, $GLOBALS['conn'] ) )
01432                                         criticalError( mysql_error(), _("FOG :: Database error!") );
01433                                 }
01434                                 // Update auto log off times.
01435                                 $tme = mysql_real_escape_string( $_POST["tme"] );
01436                                 $sql = "SELECT
01437                                 COUNT(*) as cnt
01438                                 FROM
01439                                 hostAutoLogOut
01440                                 WHERE
01441                                 haloHostID = '$id'";
01442                                 $res = mysql_query( $sql, $GLOBALS['conn'] ) or criticalError( mysql_error(), _("FOG :: Database error!") );
01443                                 $blFound = false;
01444                                 while( $ar = mysql_fetch_array( $res ) )
01445                                 {
01446                                 if ( $ar["cnt"] > 0 ) $blFound = true;
01447                                 }
01448 
01449                                 if ( $blFound )
01450                                 {
01451                                 $sql = "UPDATE
01452                                 hostAutoLogOut
01453                                 set
01454                                 haloTime = '$tme'
01455                                 WHERE
01456                                 haloHostID = '$id'";
01457                                 }
01458                                 else
01459                                 {
01460                                 $sql = "INSERT INTO hostAutoLogOut(haloHostID, haloTime) values('$id', '$tme')";
01461                                 }
01462                                 if ( ! mysql_query( $sql, $GLOBALS['conn'] ) )
01463                                         criticalError( mysql_error(), _("FOG :: Database error!") );
01464 
01465                                 }
01466                                 */
01467                                         
01468                                 break;
01469 
01470                                 // Hardware Inventory
01471                                 case 'host-hardware-inventory';
01472                                 /*
01473                                         if ( $_POST["update"] == "1" )
01474                                         {
01475 
01476                                 $prim = mysql_real_escape_string( $_POST["pu"] );
01477                                 $other1 = mysql_real_escape_string( $_POST["other1"] );
01478                                 $other2 = mysql_real_escape_string( $_POST["other2"] );
01479                                 $sql = "update inventory set iPrimaryUser = '$prim', iOtherTag = '$other1', iOtherTag1 ='$other2' where iHostID = '$id'";
01480                                 if ( !mysql_query( $sql, $GLOBALS['conn'] ) )
01481                                 {
01482                                 msgBox( mysql_error() );
01483                                 }
01484                                 }
01485                                 */
01486                                         
01487                                 break;
01488 
01489                                 // Virus History
01490                                 case 'host-virus-history';
01491                                 /*
01492                                         if ( $_GET["delvid"] !== null && is_numeric( $_GET["delvid"] ) )
01493                                         {
01494                                 $vid = mysql_real_escape_string( $_GET["delvid"] );
01495                                 clearAVRecord( $GLOBALS['conn'], $vid );
01496                                 }
01497 
01498                                 if ( $_GET["delvid"] == "all"  )
01499                                 {
01500                                 $member = getImageMemberFromHostID( $GLOBALS['conn'], $id );
01501                                 if ( $member != null )
01502                                 {
01503                                 clearAVRecordsForHost( $GLOBALS['conn'], $member->getMACColon() );
01504                                 }
01505                                 }
01506                                 */
01507                                         
01508                                 break;
01509                         }
01510 
01511                         // Save to database
01512                         if ($Host->save())
01513                         {
01514                                 // Hook
01515                                 $this->HookManager->processEvent('HOST_EDIT_SUCCESS', array('host' => &$Host));
01516 
01517                                 // Log History event
01518                                 $this->FOGCore->logHistory(sprintf('Host updated: ID: %s, Name: %s, Tab: %s', $Host->get('id'), $Host->get('name'), $this->REQUEST['tab']));
01519                                         
01520                                 // Set session message
01521                                 $this->FOGCore->setMessage('Host updated!');
01522                                         
01523                                 // Redirect to new entry
01524                                 $this->FOGCore->redirect(sprintf('?node=%s&sub=edit&%s=%s#%s', $this->REQUEST['node'], $this->id, $Host->get('id'), $this->REQUEST['tab']));
01525                         }
01526                         else
01527                         {
01528                                 // Database save failed
01529                                 throw new Exception('Database update failed');
01530                         }
01531                 }
01532                 catch (Exception $e)
01533                 {
01534                         // Hook
01535                         $this->HookManager->processEvent('HOST_EDIT_FAIL', array('Host' => &$Host));
01536                                 
01537                         // Log History event
01538                         $this->FOGCore->logHistory(sprintf('%s update failed: Name: %s, Tab: %s, Error: %s', _('Host'), $_POST['name'], $this->REQUEST['tab'], $e->getMessage()));
01539 
01540                         // Set session message
01541                         $this->FOGCore->setMessage($e->getMessage());
01542                                 
01543                         // Redirect
01544                         $this->FOGCore->redirect(sprintf('?node=%s&sub=edit&%s=%s#%s', $this->REQUEST['node'], $this->id, $Host->get('id'), $this->REQUEST['tab']));
01545                 }
01546         }
01547 
01548         public function delete()
01549         {
01550                 // Find
01551                 $Host = new Host($this->REQUEST['id']);
01552 
01553                 // Title
01554                 $this->title = sprintf('%s: %s', _('Remove'), $Host->get('name'));
01555 
01556                 // Hook
01557                 $this->HookManager->processEvent('HOST_ADD', array('Host' => &$Host));
01558 
01559                 // TODO: Put table rows into variables -> Add hooking
01560                 ?>
01561 <p class="c">
01562         <?php printf('%s <b>%s</b>?', _('Please confirm you want to delete'), $Host->get('name')); ?>
01563 </p>
01564 <form method="post" action="<?php print $this->formAction; ?>" class="c">
01565         <input type="submit" value="<?php print $this->title; ?>" />
01566 </form>
01567 <?php
01568         }
01569 
01570         public function delete_post()
01571         {
01572                 // Find
01573                 $Host = new Host($this->REQUEST['id']);
01574 
01575                 // Hook
01576                 $this->HookManager->processEvent('HOST_ADD_POST', array('Host' => &$Host));
01577 
01578                 // POST
01579                 try
01580                 {
01581                         // Error checking
01582                         if (!$Host->destroy())
01583                         {
01584                                 throw new Exception(_('Failed to destroy Host'));
01585                         }
01586                                 
01587                         // Hook
01588                         $this->HookManager->processEvent('HOST_DELETE_SUCCESS', array('Host' => &$Host));
01589                                 
01590                         // Log History event
01591                         $this->FOGCore->logHistory(sprintf('%s: ID: %s, Name: %s', _('Host deleted'), $Host->get('id'), $Host->get('name')));
01592                                 
01593                         // Set session message
01594                         $this->FOGCore->setMessage(sprintf('%s: %s', _('Host deleted'), $Host->get('name')));
01595                                 
01596                         // Redirect
01597                         $this->FOGCore->redirect(sprintf('?node=%s', $this->REQUEST['node']));
01598                 }
01599                 catch (Exception $e)
01600                 {
01601                         // Hook
01602                         $this->HookManager->processEvent('HOST_DELETE_FAIL', array('Host' => &$Host));
01603                                 
01604                         // Log History event
01605                         $this->FOGCore->logHistory(sprintf('%s %s: ID: %s, Name: %s', _('Host'), _('deleted'), $Host->get('id'), $Host->get('name')));
01606                                 
01607                         // Set session message
01608                         $this->FOGCore->setMessage($e->getMessage());
01609                                 
01610                         // Redirect
01611                         $this->FOGCore->redirect($this->formAction);
01612                 }
01613         }
01614 
01615         public function import()
01616         {
01617                 // Title
01618                 $this->title = _('Import Host List');
01619 
01620                 ?>
01621 <form enctype="multipart/form-data" method="POST"
01622         action="<?php print $this->formAction; ?>">
01623         <table cellpadding=0 cellspacing=0 border=0 width=90%>
01624                 <tr>
01625                         <td><?php print _("CSV File"); ?></td>
01626                         <td><input class="smaller" type="file" name="file" value="" /></td>
01627                 </tr>
01628                 <tr>
01629                         <td colspan=2><font><center>
01630                                                 <br /> <input class="smaller" type="submit"
01631                                                         value="<?php print _("Upload CSV"); ?>" />
01632                                         </center>
01633                         
01634                         </td>
01635                 </tr>
01636         </table>
01637 </form>
01638 <p>
01639         <?php print _('This page allows you to upload a CSV file of hosts into FOG to ease migration.  Right click <a href="./other/hostimport.csv">here</a> and select <strong>Save target as...</strong> or <strong>Save link as...</strong>  to download a template file.  The only fields that are required are hostname and MAC address.  Do <strong>NOT</strong> include a header row, and make sure you resave the file as a CSV file and not XLS!'); ?>
01640 </p>
01641 <?php
01642         }
01643 
01644         public function import_post()
01645         {
01646                 // TODO: Rewrite this... it works for now
01647                 try
01648                 {
01649                         // Error checking
01650                         if ($_FILES["file"]["error"] > 0)
01651                         {
01652                                 throw new Exception(sprintf('%s: %s', _('Error'), (is_array($_FILES["file"]["error"]) ? implode(', ', $_FILES["file"]["error"]) : $_FILES["file"]["error"])));
01653                         }
01654                         if (!file_exists($_FILES["file"]["tmp_name"]))
01655                         {
01656                                 throw new Exception('Could not find tmp filename');
01657                         }
01658                                 
01659                         $numSuccess = $numFailed = $numAlreadyExist = 0;
01660                                 
01661                         $handle = fopen($_FILES["file"]["tmp_name"], "r");
01662                         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
01663                         {
01664                                 // Ignore header data if left in CSV
01665                                 if (preg_match('#ie#', $data[0]))
01666                                 {
01667                                         continue;
01668                                 }
01669 
01670                                 $totalRows++;
01671                                 if ( count( $data ) < 6 && count( $data ) >= 2 )
01672                                 {
01673                                         try
01674                                         {
01675                                                 // Error checking
01676                                                 if ($this->FOGCore->getClass('HostManager')->doesHostExistWithMac(new MACAddress($data[0])))
01677                                                 {
01678                                                         throw new Exception('A Host with this MAC Address already exists');
01679                                                 }
01680                                                         
01681                                                 $Host = new Host(array(
01682                                                                 'name'          => $data[1],
01683                                                                 'description'   => $data[3] . ' ' . _('Uploaded by batch import on'),
01684                                                                 'ip'            => $data[2],
01685                                                                 'imageID'       => $data[5],
01686                                                                 'createdTime'   => time(),
01687                                                                 'createdBy'     => $this->FOGUser->get('name'),
01688                                                                 'mac'           => $data[0]
01689                                                 ));
01690 
01691                                                 if ($Host->save())
01692                                                 {
01693                                                         $numSuccess++;
01694                                                 }
01695                                                 else
01696                                                 {
01697                                                         $numFailed++;
01698                                                 }
01699                                                         
01700                                         }
01701                                         catch (Exception $e )
01702                                         {
01703                                                 $numFailed++;
01704                                                 $uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, $e->getMessage());
01705                                         }
01706                                 }
01707                                 else
01708                                 {
01709                                         $numFailed++;
01710                                         $uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, _('Invalid number of cells'));
01711                                 }
01712                         }
01713                         fclose($handle);
01714                 }
01715                 catch (Exception $e)
01716                 {
01717                         $error = $e->getMessage();
01718                 }
01719 
01720                 // Title
01721                 $this->title = 'Import Host Results';
01722 
01723                 // Output
01724                 ?>
01725 <table cellpadding=0 cellspacing=0 border=0 width=100%>
01726         <tr>
01727                 <td width="25%"><?php print _("Total Rows"); ?></td>
01728                 <td><?php print $totalRows; ?></td>
01729         </tr>
01730         <tr>
01731                 <td><?php print _("Successful Hosts"); ?></td>
01732                 <td><?php print $numSuccess; ?></td>
01733         </tr>
01734         <tr>
01735                 <td><?php print _("Failed Hosts"); ?></td>
01736                 <td><?php print $numFailed; ?></td>
01737         </tr>
01738         <tr>
01739                 <td><?php print _("Errors"); ?></td>
01740                 <td><?php print $uploadErrors; ?></td>
01741         </tr>
01742 </table>
01743 <?php
01744         }
01745 
01746         public function export()
01747         {
01748                 // Title
01749                 $this->title = _('TODO!');
01750         }
01751 
01752         public function export_post()
01753         {
01754 
01755         }
01756 
01757         public function deploy()
01758         {
01759                 // Find
01760                 $Host = new Host($this->REQUEST['id']);
01761                 $TaskType = new TaskType(($this->REQUEST['type'] ? $this->REQUEST['type'] : '1'));
01762 
01763                 // Title
01764                 $this->title = sprintf("%s '%s' %s '%s'", _('Deploy Task'), $TaskType->get('name'), _('to Host'), $Host->get('name'));
01765 
01766                 // Deploy
01767                 ?>
01768 <p class="c">
01769         <b><?php print _("Are you sure you wish to deploy these machines?"); ?>
01770         </b>
01771 </p>
01772 <form method="POST" action="<?php print $this->formAction; ?>"
01773         id="deploy-container">
01774         <div class="confirm-message">
01775                 <div class="advanced-settings">
01776                         <h2>
01777                                 <?php print _("Advanced Settings"); ?>
01778                         </h2>
01779                         <p>
01780                                 <input type="checkbox" name="shutdown" id="shutdown" value="1"
01781                                         autocomplete="off"> <label for="shutdown"><?php print _("Schedule <u>Shutdown</u> after task completion"); ?>
01782                                 </label>
01783                         </p>
01784                         <?php
01785                         if (!$TaskType->isDebug())
01786                         {
01787                                 ?>
01788                         <p>
01789                                 <input type="radio" name="scheduleType" id="scheduleInstant"
01790                                         value="instant" autocomplete="off" checked="checked" /> <label
01791                                         for="scheduleInstant"><?php print _("Schedule <u>Instant Deployment</u>"); ?>
01792                                 </label>
01793                         </p>
01794                         <p>
01795                                 <input type="radio" name="scheduleType" id="scheduleSingle"
01796                                         value="single" autocomplete="off" /> <label for="scheduleSingle"><?php print _("Schedule <u>Delayed Deployment</u>"); ?>
01797                                 </label>
01798                         </p>
01799                         <p class="hidden" id="singleOptions">
01800                                 <input type="text" name="scheduleSingleTime" id="scheduleSingleTime"
01801                                         autocomplete="off" />
01802                         </p>
01803                         <p>
01804                                 <input type="radio" name="scheduleType" id="scheduleCron"
01805                                         value="cron" autocomplete="off"> <label for="scheduleCron"><?php print _("Schedule <u>Cron-style Deployment</u>"); ?>
01806                                 </label>
01807                         </p>
01808                         <p class="hidden" id="cronOptions">
01809                                 <input type="text" name="scheduleCronMin" id="scheduleCronMin"
01810                                         placeholder="min" autocomplete="off" /> <input type="text"
01811                                         name="scheduleCronHour" id="scheduleCronHour" placeholder="hour"
01812                                         autocomplete="off" /> <input type="text" name="scheduleCronDOM"
01813                                         id="scheduleCronDOM" placeholder="dom" autocomplete="off" /> <input
01814                                         type="text" name="scheduleCronMonth" id="scheduleCronMonth"
01815                                         placeholder="month" autocomplete="off" /> <input type="text"
01816                                         name="scheduleCronDOW" id="scheduleCronDOW" placeholder="dow"
01817                                         autocomplete="off" />
01818                         </p>
01819                         <?php
01820                         }
01821                         ?>
01822                 </div>
01823         </div>
01824 
01825         <h2>
01826                 <?php print _('Hosts in Task'); ?>
01827         </h2>
01828         <table width="100%" cellspacing="0" cellpadding="0" border="0">
01829                 <tbody>
01830                         <tr>
01831                                 <td><?php print $Host->get('name'); ?></td>
01832                                 <td><?php print $Host->get('mac') . ($Host->get('ip') ? sprintf('(%s)', $Host->get('ip')) : ''); ?>
01833                                 </td>
01834                                 <td><?php print $Host->getImage()->get('name'); ?></td>
01835                         </tr>
01836                 </tbody>
01837         </table>
01838 
01839         <p class="c">
01840                 <input type="submit" value="<?php print $this->title; ?>" />
01841         </p>
01842 </form>
01843 <?php
01844         }
01845 
01846         public function deploy_post()
01847         {
01848                 // Find
01849                 $Host = new Host($this->REQUEST['id']);
01850 
01851                 // Title
01852                 $this->title = "Deploy Image to Host";
01853 
01854                 // Variables
01855                 $enableShutdown = ($this->REQUEST['shutdown'] == 1 ? true : false);
01856                 $enableSnapins = ($this->REQUEST['deploySnapins'] == 'true' ? true : false);
01857                 $enableDebug = ($this->REQUEST['debug'] == 'true' ? true : false);
01858                 $scheduledDeployTime = strtotime($this->REQUEST['scheduleSingleTime']);
01859                 $taskTypeID = $this->REQUEST['type'];
01860 
01861                 $taskName = '';
01862 
01863                 // Deploy
01864                 try
01865                 {
01866                         if ($this->REQUEST['scheduleType'] == 'single')
01867                         {
01868                                 // Scheduled Deployment
01869                                 // NOTE: Function will throw an exception if it fails
01870                                 $Host->createSingleRunScheduledPackage($taskTypeID, $taskName, $scheduledDeployTime, $enableShutdown, $enableSnapins);
01871 
01872                                 // Success
01873                                 printf('<div class="task-start-ok"><p>%s</p><p>%s</p></div>', sprintf(_('Successfully created task for deployment of <u>%s</u> to <u>%s</u>'), $Host->getImage()->get('name'), $Host->get('name')), _('Scheduled to start at:') . ' ' . $this->REQUEST['scheduleSingleTime']);
01874                                         
01875                         }
01876                         else if ($this->REQUEST['scheduleType'] == 'cron')
01877                         {
01878                                 // Cron Deployment
01879                                 // NOTE: Function will throw an exception if it fails
01880                                 $Host->createCronScheduledPackage($taskTypeID, $taskName, $this->REQUEST['scheduleCronMin'], $this->REQUEST['scheduleCronHour'], $this->REQUEST['scheduleCronDOM'], $this->REQUEST['scheduleCronMonth'], $this->REQUEST['scheduleCronDOW'], $enableShutdown, $enableSnapins);
01881 
01882                                 // Success
01883                                 printf('<div class="task-start-ok"><p>%s</p><p>%s</p></div>', sprintf(_('Successfully created task for deployment of <u>%s</u> to <u>%s</u>'), $Host->getImage()->get('name'), $Host->get('name')), _('Cron Schedule:') . ' ' . implode(' ', array($this->REQUEST['scheduleCronMin'], $this->REQUEST['scheduleCronHour'], $this->REQUEST['scheduleCronDOM'], $this->REQUEST['scheduleCronMonth'], $this->REQUEST['scheduleCronDOW'])));
01884                         }
01885                         else
01886                         {
01887                                 // Instant Deployment
01888                                 // NOTE: Function will throw an exception if it fails
01889                                 $Host->createImagePackage($taskTypeID, $taskName, $enableShutdown, $enableDebug, $enableSnapins);
01890 
01891                                 // Success
01892                                 printf('<div class="task-start-ok"><p>%s</p></div>', sprintf(_('Successfully created task for deployment of <u>%s</u> to <u>%s</u>'), $Host->getImage()->get('name'), $Host->get('name')));
01893                         }
01894                 }
01895                 catch (Exception $e)
01896                 {
01897                         // Failure
01898                         printf('<div class="task-start-failed"><p>%s</p><p>%s</p></div>', _('Failed to create deploy task'), $e->getMessage());
01899                 }
01900         }
01901 
01902         // Overrides
01903         public function render()
01904         {
01905                 // Render
01906                 parent::render();
01907 
01908                 // Add action-box
01909                 if (($this->sub == '' || in_array($this->sub, array('list', 'search'))) && !$this->FOGCore->isAJAXRequest() && !$this->FOGCore->isPOSTRequest())
01910                 {
01911                         ?>
01912 <form method="POST"
01913         action="<?php print sprintf('%s?node=%s&sub=save_group', $_SERVER['PHP_SELF'], $this->node); ?>"
01914         id="action-box">
01915         <input type="hidden" name="hostIDArray" id="hostIDArray" value=""
01916                 autocomplete="off" />
01917         <p>
01918                 <label for="group_new"><?php print _('Create new group'); ?> </label><input
01919                         type="text" name="group_new" id="group_new" autocomplete="off" />
01920         </p>
01921         <p class="c">OR</p>
01922         <p>
01923                 <label for="group"><?php print _('Add to group'); ?> </label>
01924                 <?php print $this->FOGCore->getClass('GroupManager')->buildSelectBox(); ?>
01925         </p>
01926         <p class="c">
01927                 <input type="submit"
01928                         value="<?php print _("Process Group Changes"); ?>" />
01929         </p>
01930 </form>
01931 <?php
01932                 }
01933         }
01934 
01935         public function save_group()
01936         {
01937                 try
01938                 {
01939                         // Error checking
01940                         if (empty($this->REQUEST['hostIDArray']))
01941                         {
01942                                 throw new Exception( _('No Hosts were selected') );
01943                         }
01944 
01945                         if (empty($this->REQUEST['group_new']) && empty($this->REQUEST['group']))
01946                         {
01947                                 throw new Exception( _('No Group selected and no new Group name entered') );
01948                         }
01949                                 
01950                         // Determine which method to use
01951                         // New group
01952                         if (!empty($this->REQUEST['group_new']))
01953                         {
01954                                 if (!$Group = current($this->FOGCore->getClass('GroupManager')->find(array('name' => $this->REQUEST['group_new']))))
01955                                 {
01956                                         $Group = new Group(array('name' => $this->REQUEST['group_new']));
01957                                                 
01958                                         if (!$Group->save())
01959                                         {
01960                                                 throw new Exception( _('Failed to create new Group') );
01961                                         }
01962                                 }
01963                         }
01964                         else
01965                                 // Existing group
01966                         {
01967                                 if (!$Group = current($this->FOGCore->getClass('GroupManager')->find(array('id' => $this->REQUEST['group']))))
01968                                 {
01969                                         throw new Exception( _('Invalid Group ID') );
01970                                 }
01971                         }
01972                                 
01973                         // Valid
01974                         if (!$Group->isValid())
01975                         {
01976                                 throw new Exception( _('Group is Invalid') );
01977                         }
01978                                 
01979                         // Main
01980                         foreach ((array)explode(',', $this->REQUEST['hostIDArray']) AS $hostID)
01981                         {
01982                                 //$Group->add('hosts', $hostID);
01983                                 $GroupAssociation = new GroupAssociation(array('hostID' => $hostID, 'groupID' => $Group->get('id')));
01984                                 $GroupAssociation->save();
01985                         }
01986                         
01987                         // Success
01988                         printf('<div class="task-start-ok"><p>%s</p></div>', sprintf(_('Successfully associated Hosts with Group <u>%s</u>'), $Group->get('name')));
01989                 }
01990                 catch (Exception $e)
01991                 {
01992                         // Failure
01993                         printf('<div class="task-start-failed"><p>%s</p><p>%s</p></div>', _('Failed to Associate Hosts with Group'), $e->getMessage());
01994                 }
01995         }
01996 }
01997 
01998 // Register page with FOGPageManager
01999 $FOGPageManager->register(new HostManagementPage());
 Todo Clases Archivos Funciones Variables Enumeraciones