Пример #1
0
 /**
  * Remove one or more types
  *
  * @return  void  Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.delete', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         Notify::warning(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Check if the type is being used
         $rt = Type::oneOrFail($id);
         $usage = Resource::all()->whereEquals('type', $id)->total();
         if ($usage) {
             Notify::error(Lang::txt('COM_RESOURCES_TYPE_BEING_USED', $id));
             continue;
         }
         // Delete the type
         if (!$rt->destroy()) {
             Notify::error($rt->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_RESOURCES_ITEMS_REMOVED', $i));
     }
     // Redirect
     $this->cancelTask();
 }
Пример #2
0
 /**
  * Display sessions
  *
  * @return  void
  */
 public function sessionsTask()
 {
     // Get filters
     $filters = array('appname' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.appname', 'appname', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'start'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     // Get the list of sessions
     $rows = array();
     // Get a count of all sessions (for pagination)
     $total = count($rows);
     // Get a list of all apps for the filters bar
     $apps = Resource::all()->whereEquals('type', $this->config->get('windows_type'))->rows();
     // Get a list of all active sessions for specified app
     $appname = Request::getVar('appname', '');
     $sessions = array();
     if (!empty($appname)) {
         exec('/usr/bin/hz-aws-appstream getappsessions --appid' . ' "' . $appname . '"', $rawsessions);
         $sessions = array();
         foreach ($rawsessions as $s) {
             $sessionsArray = explode("|", $s);
             if (sizeof($sessionsArray) == 4) {
                 $sessions[] = array("sessionid" => $sessionsArray[0], "status" => $sessionsArray[2], "opaquedata" => $sessionsArray[3]);
             }
             //else
             //	$sessions[] = array("sessionid" => $sessionsArray[0], "status" => "cannot parse", "opaquedata" => "cannot parse");
         }
         usort($sessions, function ($a, $b) {
             return strcmp($a['status'], $b['status']);
         });
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('rows', $rows)->set('apps', $apps)->set('sessions', $sessions)->set('total', 0)->setErrors($this->getErrors())->setLayout('sessions')->display();
 }