Exemplo n.º 1
0
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "add_user_group":
             $gu = new Group_User();
             return $gu->doSpecificMassiveActions($input);
         case "force_user_ldap_update":
             if (Session::haveRight("user", "w")) {
                 $ids = array();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($this->getFromDB($key)) {
                             if ($this->fields["authtype"] == Auth::LDAP || $this->fields["authtype"] == Auth::EXTERNAL) {
                                 if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $this->fields["name"]), 1, $this->fields["auths_id"])) {
                                     $res['ok']++;
                                 } else {
                                     $res['ko']++;
                                 }
                             }
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             } else {
                 $res['noright']++;
             }
             break;
         case "change_authtype":
             if (!isset($input["authtype"]) || !isset($input["auths_id"])) {
                 return false;
             }
             if (Session::haveRight("user_authtype", "w")) {
                 $ids = array();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $ids[] = $key;
                     }
                 }
                 if (User::changeAuthMethod($ids, $input["authtype"], $input["auths_id"])) {
                     $res['ok']++;
                 } else {
                     $res['ko']++;
                 }
             } else {
                 $res['noright']++;
             }
             break;
         case "add_userprofile":
             $right = new Profile_User();
             if (isset($input['profiles_id']) && $input['profiles_id'] > 0 && isset($input['entities_id']) && $input['entities_id'] >= 0) {
                 $input2 = array();
                 $input2['entities_id'] = $input['entities_id'];
                 $input2['profiles_id'] = $input['profiles_id'];
                 $input2['is_recursive'] = $input['is_recursive'];
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $input2['users_id'] = $key;
                         if ($right->can(-1, 'w', $input2)) {
                             if ($right->add($input2)) {
                                 $res['ok']++;
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Exemplo n.º 2
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'force_user_ldap_update':
             foreach ($ids as $id) {
                 if ($item->can($id, UPDATE)) {
                     if ($item->fields["authtype"] == Auth::LDAP || $item->fields["authtype"] == Auth::EXTERNAL) {
                         if (AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $item->fields["name"]), 1, $item->fields["auths_id"])) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                     $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                 }
             }
             return;
         case 'change_authtype':
             $input = $ma->getInput();
             if (!isset($input["authtype"]) || !isset($input["auths_id"])) {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                 return;
             }
             if (Session::haveRight(self::$rightname, self::UPDATEAUTHENT)) {
                 if (User::changeAuthMethod($ids, $input["authtype"], $input["auths_id"])) {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
                 } else {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_NORIGHT);
                 $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 } else {
     if (isset($_POST["deletegroup"])) {
         if (count($_POST["item"])) {
             foreach ($_POST["item"] as $key => $val) {
                 if ($groupuser->can($key, DELETE)) {
                     $groupuser->delete(array('id' => $key));
                 }
             }
         }
         Event::log($_POST["users_id"], "users", 4, "setup", sprintf(__('%s deletes users from a group'), $_SESSION["glpiname"]));
         Html::back();
     } else {
         if (isset($_POST["change_auth_method"])) {
             Session::checkRight('user', User::UPDATEAUTHENT);
             if (isset($_POST["auths_id"])) {
                 User::changeAuthMethod(array($_POST["id"]), $_POST["authtype"], $_POST["auths_id"]);
             }
             Html::back();
         } else {
             if (isset($_GET["ext_auth"])) {
                 Html::header(User::getTypeName(Session::getPluralNumber()), '', "admin", "user");
                 User::showAddExtAuthForm();
                 Html::footer();
             } else {
                 if (isset($_POST['add_ext_auth_ldap'])) {
                     Session::checkRight("user", User::IMPORTEXTAUTHUSERS);
                     if (isset($_POST['login']) && !empty($_POST['login'])) {
                         AuthLdap::importUserFromServers(array('name' => $_POST['login']));
                     }
                     Html::back();
                 } else {
Exemplo n.º 4
0
     if ($ic->canCreate()) {
         foreach ($_POST["item"] as $key => $val) {
             $input = array('itemtype' => $_POST['itemtype'], 'items_id' => $key);
             if (!$ic->getFromDBforDevice($_POST['itemtype'], $key)) {
                 $ic->add($input);
             }
         }
     }
     break;
 case "change_authtype":
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             $ids[] = $key;
         }
     }
     User::changeAuthMethod($ids, $_POST["authtype"], $_POST["auths_id"]);
     break;
 case "unlock_ocsng_field":
     $fields = OcsServer::getLockableFields();
     if ($_POST['field'] == 'all' || isset($fields[$_POST['field']])) {
         foreach ($_POST["item"] as $key => $val) {
             if ($val == 1) {
                 if ($_POST['field'] == 'all') {
                     OcsServer::replaceOcsArray($key, array(), "computer_update");
                 } else {
                     OcsServer::deleteInOcsArray($key, $_POST['field'], "computer_update", true);
                 }
             }
         }
     }
     break;