function changecomputername() { if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") { $_POST["userid"] = $_POST["userid"] . "\$"; } $comp = new computers($_POST["userid"]); $MAC = $comp->ComputerMacAddress; $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"])); $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]); $actualdn = $comp->dn; $newrdn = "cn={$_POST["NewHostname"]}\$"; $ldap = new clladp(); if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) { echo "Unable to preg_match {$actualdn}\n"; return; } $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn); if ($newDN == null) { echo "Unable to preg_match {$actualdn} -> {$re[1]}\n"; return; } if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, null)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}"; return; } $upd["uid"][0] = $_POST["NewHostname"] . '$'; if (!$ldap->Ldap_modify($newDN, $upd)) { echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}"; return; } $ocs = new ocs($MAC); $ocs->ComputerName = $_POST["NewHostname"]; $ocs->ComputerIP = $comp->ComputerIP; $ocs->EditComputer(); }
function changecomputername() { if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") { $_POST["userid"] = $_POST["userid"] . "\$"; } $comp = new computers($_POST["userid"]); $MAC = $comp->ComputerMacAddress; $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"])); $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]); $actualdn = $comp->dn; $newrdn = "cn={$_POST["NewHostname"]}\$"; $ldap = new clladp(); if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) { echo "Unable to preg_match {$actualdn}\n"; return; } $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn); if ($newDN == null) { echo "Unable to preg_match {$actualdn} -> {$re[1]}\n"; return; } if ($ldap->ExistsDN("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}")) { $ldap->ldap_delete("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"); } $newParent = "ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"; if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, $newParent)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\n\nActual DN:{$actualdn}\nExpected DN:{$newrdn}"; return; } $upd["uid"][0] = $_POST["NewHostname"] . '$'; if (!$ldap->Ldap_modify($newDN, $upd)) { echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}"; return; } $ocs = new ocs($MAC); $ocs->ComputerName = $_POST["NewHostname"]; $ocs->ComputerIP = $comp->ComputerIP; $ocs->EditComputer(); if (IsPhysicalAddress($comp->ComputerMacAddress)) { include_once dirname(__FILE__) . "/ressources/class.mysql.inc"; $uid = $comp->ComputerIDFromMAC($comp->ComputerMacAddress); $comp = new computers($uid); $sql = "UPDATE dhcpd_fixed SET `hostname`='{$comp->ComputerRealName}' WHERE `mac`='{$comp->ComputerMacAddress}'"; $q = new mysql(); $q->QUERY_SQL($sql, "artica_backup"); } }
function rename_group() { $tpl = new templates(); if ($_SESSION["uid"] != -100) { if ($_GET["ou"] != $_SESSION["ou"]) { } echo $tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}"); die; } $gp = new groups($_GET["group-id"]); if ($_SESSION["uid"] != -100) { if ($gp->ou != $_SESSION["ou"]) { echo $tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}"); die; } } $ldap = new clladp(); $newname = $_GET["new-name"]; if (trim($newname) == null) { return null; } $actualdn = $gp->dn; if (preg_match('#cn=(.+?),(.+)#', $actualdn, $re)) { $branch = $re[2]; } $newdn = "cn={$newname}"; $newdn2 = "{$newdn},{$branch}"; $ldap = new clladp(); if ($ldap->ExistsDN($newdn2)) { return null; } writelogs("Rename {$actualdn} to {$newdn}", __CLASS__ . '/' . __FUNCTION__, __FILE__); if (!$ldap->Ldap_rename_dn($newdn, $actualdn, $branch)) { echo $tpl->_ENGINE_parse_body("{GROUP_RENAME} {failed}\n {$ldap->ldap_last_error}"); } }