Exemplo n.º 1
0
 /**
  * Get machine group data for current user
  *
  * @author 
  **/
 function get_machine_groups()
 {
     $out = array();
     if (isset($_SESSION['machine_groups'])) {
         // Get data for this unit
         $mg = new Machine_group();
         foreach ($_SESSION['machine_groups'] as $group) {
             if ($mg_data = $mg->all($group)) {
                 $out[] = $mg->all($group);
             } else {
                 $out[] = array('name' => 'Group ' . $group, 'groupid' => $group);
             }
         }
     } else {
         $mg = new Machine_group();
         $out = $mg->all();
     }
     //Apply filter
     $groups = get_filtered_groups();
     foreach ($out as &$group) {
         $group['checked'] = in_array($group['groupid'], $groups);
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
Exemplo n.º 2
0
 /**
  * Return Machinegroup data for groupid or all groups if groupid is empty
  *
  * @return void
  * @author
  **/
 function get_mg_data($groupid = "")
 {
     $out = array();
     // Get created Machine Groups
     $mg = new Machine_group();
     foreach ($mg->all($groupid) as $arr) {
         $out[$arr['groupid']] = $arr;
     }
     $reportdata = new Reportdata_model();
     // Get registered machine groups
     $reportdata = new Reportdata_model();
     foreach ($reportdata->get_groups(true) as $obj) {
         if (!isset($out[$obj->machine_group])) {
             $out[$obj->machine_group] = array('groupid' => $obj->machine_group, 'name' => 'Group ' . $obj->machine_group);
         }
         $out[$obj->machine_group]['cnt'] = $obj->cnt;
     }
     $obj = new View();
     $obj->view('json', array('msg' => array_values($out)));
 }
Exemplo n.º 3
0
/**
 * Lookup group id for passphrase
 *
 * @return integer group id
 * @author AvB
 **/
function passphrase_to_group($passphrase)
{
    $machine_group = new Machine_group();
    if ($machine_group->retrieve_one('property=? AND value=?', array('key', $passphrase))) {
        return $machine_group->groupid;
    }
    return 0;
}
Exemplo n.º 4
0
 /**
  * Set session properties
  *
  **/
 function set_session_props($show = false)
 {
     // Initialize session
     $this->authorized();
     // Check if we are in a session
     if (!isset($_SESSION['auth'])) {
         $msg = array('error' => 'unauthorized');
         $obj = new View();
         $obj->view('json', array('msg' => $msg));
         return;
     }
     // Default role is user
     $_SESSION['role'] = 'user';
     $_SESSION['role_why'] = 'Default role';
     // Find role in config for current user
     foreach (conf('roles', array()) as $role => $members) {
         // Check for wildcard
         if (in_array('*', $members)) {
             $_SESSION['role'] = $role;
             $_SESSION['role_why'] = 'Matched on wildcard (*) in ' . $role;
             break;
         }
         // Check if user or group is present in members
         foreach ($members as $member) {
             if (strpos($member, '@') === 0) {
                 // groups (start with @)
                 if (in_array(substr($member, 1), $_SESSION['groups'])) {
                     $_SESSION['role'] = $role;
                     $_SESSION['role_why'] = 'member of ' . $member;
                     break 2;
                 }
             } else {
                 // user
                 if ($member == $_SESSION['user']) {
                     $_SESSION['role'] = $role;
                     $_SESSION['role_why'] = $member . ' in "' . $role . '" role array';
                     break 2;
                 }
             }
         }
     }
     // Check if Business Units are enabled in the config file
     $bu_enabled = conf('enable_business_units', FALSE);
     // Check if user is global admin
     if ($_SESSION['auth'] == 'noauth' or $_SESSION['role'] == 'admin') {
         unset($_SESSION['business_unit']);
     } elseif (!$bu_enabled) {
         // Regular user w/o business units enabled
         unset($_SESSION['business_unit']);
     } elseif ($bu_enabled) {
         // Authorized user, not in business unit
         $_SESSION['role'] = 'nobody';
         $_SESSION['role_why'] = 'Default role for Business Units';
         $_SESSION['business_unit'] = 0;
         // Lookup user in business units
         $bu = new Business_unit();
         if ($bu->retrieve_one("property IN ('manager', 'user') AND value=?", $_SESSION['user'])) {
             $_SESSION['role'] = $bu->property;
             // manager, user
             $_SESSION['role_why'] = $_SESSION['user'] . ' found in Business Unit ' . $bu->unitid;
             $_SESSION['business_unit'] = $bu->unitid;
         } else {
             // Lookup groups in Business Units
             foreach ($_SESSION['groups'] as $group) {
                 if ($bu->retrieve_one("property IN ('manager', 'user') AND value=?", '@' . $group)) {
                     $_SESSION['role'] = $bu->property;
                     // manager, user
                     $_SESSION['role_why'] = 'Group "' . $group . '" found in Business Unit ' . $bu->unitid;
                     $_SESSION['business_unit'] = $bu->unitid;
                     break;
                 }
             }
         }
     }
     // Set machine_groups
     if ($_SESSION['role'] == 'admin' or !$bu_enabled) {
         // Can access all defined groups (from machine_group)
         // and used groups (from reportdata)
         $mg = new Machine_group();
         $report = new Reportdata_model();
         $_SESSION['machine_groups'] = array_unique(array_merge($report->get_groups(), $mg->get_group_ids()));
     } else {
         // Only get machine_groups for business unit
         $_SESSION['machine_groups'] = $bu->get_machine_groups($bu->unitid);
     }
     // Show current session info
     if ($show) {
         $obj = new View();
         $obj->view('json', array('msg' => $_SESSION));
     }
 }