function LDAPtest() { global $SAMSConf; global $USERConf; if ($USERConf->ToWebInterfaceAccess("C") != 1) { exit(0); } $info = array(); $lang = "./lang/lang.{$SAMSConf->LANG}"; require $lang; //create the LDAP connection $adldserver = GetAuthParameter("ldap", "ldapserver"); $basedn = GetAuthParameter("ldap", "basedn"); $adadmin = GetAuthParameter("ldap", "adadmin"); $adadminpasswd = GetAuthParameter("ldap", "adadminpasswd"); $usersrdn = GetAuthParameter("ldap", "usersrdn"); $usersfilter = GetAuthParameter("ldap", "usersfilter"); $usernameattr = GetAuthParameter("ldap", "usernameattr"); $groupsrdn = GetAuthParameter("ldap", "groupsrdn"); $groupsfilter = GetAuthParameter("ldap", "groupsfilter"); print "<H1>Test LDAP connection</H1>"; include 'ldap.php'; $samsldap = new sams_ldap($adldserver, $basedn, $usersrdn, $usersfilter, $usernameattr, $groupsrdn, $groupsfilter, $adadmin, $adadminpasswd); if ($samsldap != NULL) { $groupdata = $samsldap->GetGroupsData(); print "<H2>LDAP groups</H2>"; print "<TABLE CLASS=samstable>"; print "<TH width=5%>No"; print "<TH >Name"; print "<TH >gid"; print "<TH >Description"; for ($j = 0; $j < $groupdata['groupscount']; $j++) { echo "<TR><TD>{$j}<TD> " . $groupdata['cn'][$j]; echo "<TD> " . $groupdata['gidNumber'][$j]; echo "<TD> " . $groupdata['description'][$j]; } echo "</TABLE>"; $userdata = $samsldap->GetUsersData(); print "<H2>LDAP users</H2>"; print "<TABLE CLASS=samstable>"; print "<TH width=5%>No"; print "<TH >Name"; print "<TH >Display name"; for ($j = 0; $j < $userdata['userscount']; $j++) { echo "<TR><TD>{$j}<TD> " . $userdata['uid'][$j]; echo "<TD> " . $userdata['name'][$j]; } echo "</TABLE>"; } }
function UserIDAuthenticate($userid, $password) { $this->userid = $userid; $request = "SELECT s_nick,s_passwd,s_domain,s_gauditor,squiduser.s_group_id,s_autherrorc,s_autherrort,s_user_id FROM squiduser WHERE s_user_id='{$userid}'"; if ($this->LoadUserVariables($request) > 0) { $host = GetAuthParameter("ldap", "ldapserver"); $basedn = GetAuthParameter("ldap", "basedn"); $usersrdn = GetAuthParameter("ldap", "usersrdn"); $usersfilter = GetAuthParameter("ldap", "usersfilter"); $usernameattr = GetAuthParameter("ldap", "usernameattr"); $groupsrdn = GetAuthParameter("ldap", "groupsrdn"); $groupsfilter = GetAuthParameter("ldap", "groupsfilter"); include 'src/ldap.php'; $samsldap = new sams_ldap($host, $basedn, $usersrdn, $usersfilter, $usernameattr, $groupsrdn, $groupsfilter, $user, $passwd); if ($samsldap->Authenticate($this->UserName, $password)) { $this->authOk = 1; } } return $this->authOk; }
function ImportFromLDAPForm() { global $SAMSConf; global $USERConf; $lang = "./lang/lang.{$SAMSConf->LANG}"; require $lang; if ($USERConf->ToWebInterfaceAccess("UC") != 1) { exit(0); } $DB = new SAMSDB(); PageTop("importfromldap-48.jpg", " {$authadldbuttom_3_importfromldap_ImportFromLDAPForm_1} "); require_once "src/ldap.php"; //print("<FORM NAME=\"AddDomainUsers\" ACTION=\"main.php\">\n"); $adldserver = GetAuthParameter("ldap", "ldapserver"); $basedn = GetAuthParameter("ldap", "basedn"); $adadmin = GetAuthParameter("ldap", "adadmin"); $adadminpasswd = GetAuthParameter("ldap", "adadminpasswd"); $usersrdn = GetAuthParameter("ldap", "usersrdn"); $usersfilter = GetAuthParameter("ldap", "usersfilter"); $usernameattr = GetAuthParameter("ldap", "usernameattr"); $groupsrdn = GetAuthParameter("ldap", "groupsrdn"); $groupsfilter = GetAuthParameter("ldap", "groupsfilter"); $samsldap = new sams_ldap($adldserver, $basedn, $usersrdn, $usersfilter, $usernameattr, $groupsrdn, $groupsfilter, $adadmin, $adadminpasswd); print "<FORM NAME=\"AddFromAD\" ACTION=\"main.php\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"show\" id=Show value=\"exe\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"function\" id=function value=\"importfromldap\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" id=filename value=\"authldapbuttom_3_importfromldap.php\">\n"; /* */ $groupinfo = $samsldap->GetGroupsData(); echo "<TABLE WIDTH=90%>"; print "<TR><TD WIDTH=30%><B>{$authadldbuttom_3_importfromldap_ImportFromLDAPForm_2}:\n"; print "<TD WIDTH=70%><SELECT NAME=\"addgroupname[]\" SIZE=15 TABINDEX=30 MULTIPLE>\n"; for ($i = 0; $i < $groupinfo['groupscount']; $i++) { $groupname = $groupinfo['cn'][$i]; $gid = $groupinfo['gidNumber'][$i]; if (SearchAuthParameter("ldap", "ldapgroup", "{$groupname}") == 0) { print "<OPTION VALUE=\"{$groupname}\"> {$groupname} \n"; } } print "</SELECT>\n"; print "<TR><TD><B>{$usersbuttom_1_domain_AddUsersFromDomainForm_6}"; print "<TD><INPUT TYPE=\"CHECKBOX\" NAME=\"enabled\" CHECKED>"; print "<TR>\n"; print "<TD>\n"; print "{$shablonnew_NewShablonForm_3}:\n"; print "<TD>\n"; print "<INPUT TYPE=\"TEXT\" NAME=\"defaulttraf\" SIZE=6 VALUE=\"100\"> <B> 0 - unlimited traffic\n"; print "<TR>\n"; print "<TD>\n"; print "{$shablonnew_NewShablonForm_10}\n"; print "<TD>\n"; print "<SELECT NAME=\"period\" onchange=EnterPeriod(AddDomainUsers) {$CCLEAN}> \n"; print "<OPTION value=\"M\" SELECTED>{$shablonnew_NewShablonForm_11}\n"; print "<OPTION value=\"W\">{$shablonnew_NewShablonForm_12}\n"; print "<OPTION value=\"A\">{$shablonnew_NewShablonForm_13}\n"; print "</SELECT>\n"; print "<SCRIPT LANGUAGE=JAVASCRIPT> \n"; print "function EnterPeriod(formname) \n"; print "{ \n"; print " var period=formname.period.value; \n"; print " var clryear=formname.clryear.value; \n"; print " var clrmonth=formname.clrmonth.value; \n"; print " var clrday=formname.clrday.value; \n"; print " if(period==\"A\") \n"; print " {\n"; print " formname.newperiod.disabled=false; \n"; print " formname.clryear.disabled=false; \n"; print " formname.clrmonth.disabled=false; \n"; print " formname.clrday.disabled=false; \n"; print " }\n"; print " else \n"; print " {\n"; print " formname.newperiod.disabled=true; \n"; print " formname.clryear.disabled=true; \n"; print " formname.clrmonth.disabled=true; \n"; print " formname.clrday.disabled=true; \n"; print " }\n"; print "}\n"; print "</SCRIPT> \n"; $month = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); $days = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $YCLRVALUE = strftime("%Y"); $MCLRVALUE = strftime("%m"); $DCLRVALUE = strftime("%d"); if ($DCLRVALUE + 1 > $days[$MCLRVALUE]) { $DCLRVALUE = 1; $MCLRVALUE += 1; if ($MCLRVALUE > 12) { $MCLRVALUE = 1; $YCLRVALUE += 1; } } else { $DCLRVALUE += 1; } print "<TR><TD>\n"; print "<TD> {$shablonnew_NewShablonForm_14}: \n"; print "<INPUT TYPE=\"TEXT\" NAME=\"newperiod\" SIZE=5 DISABLED>{$shablonnew_NewShablonForm_15}\n"; print "<TR><TD><TD> {$shablonnew_NewShablonForm_16}: \n"; print "<BR><INPUT TYPE=\"TEXT\" NAME=\"clryear\" SIZE=4 DISABLED VALUE=\"{$YCLRVALUE}\">:\n"; print "<INPUT TYPE=\"TEXT\" NAME=\"clrmonth\" SIZE=2 DISABLED VALUE=\"{$MCLRVALUE}\">:\n"; print "<INPUT TYPE=\"TEXT\" NAME=\"clrday\" SIZE=2 DISABLED VALUE=\"{$DCLRVALUE}\">\n"; print "<TR><TD>{$AddTRangeForm_trangetray_1}:<TD><SELECT NAME=\"trange\" ID=\"trange\" >\n"; $num_rows = $DB->samsdb_query_value("SELECT * FROM timerange "); while ($row = $DB->samsdb_fetch_array()) { print "<OPTION VALUE={$row['s_trange_id']}> {$row['s_name']} ({$row['s_timestart']} - {$row['s_timeend']} )"; } print "</SELECT>\n"; print "</TABLE>\n"; print "<INPUT TYPE=\"SUBMIT\" value=\"Import\">\n"; print "</FORM>\n"; }
function AddUsersFromLDAPForm() { global $SAMSConf; global $USERConf; $lang = "./lang/lang.{$SAMSConf->LANG}"; require $lang; if (isset($_GET["ldapgroup"])) { $ldapgroup = $_GET["ldapgroup"]; } if (isset($_GET["getgroup"])) { $getgroup = $_GET["getgroup"]; } if (isset($_GET["addgroupname"])) { $addgroupname = $_GET["addgroupname"]; } if ($USERConf->ToWebInterfaceAccess("UC") != 1) { exit; } PageTop("user.jpg", " {$usersbuttom_1_domain_AddUsersFromDomainForm_1} LDAP"); $DB = new SAMSDB(); $adldserver = GetAuthParameter("ldap", "ldapserver"); $basedn = GetAuthParameter("ldap", "basedn"); $adadmin = GetAuthParameter("ldap", "adadmin"); $adadminpasswd = GetAuthParameter("ldap", "adadminpasswd"); $usersrdn = GetAuthParameter("ldap", "usersrdn"); $usersfilter = GetAuthParameter("ldap", "usersfilter"); $usernameattr = GetAuthParameter("ldap", "usernameattr"); $groupsrdn = GetAuthParameter("ldap", "groupsrdn"); $groupsfilter = GetAuthParameter("ldap", "groupsfilter"); include 'ldap.php'; $samsldap = new sams_ldap($adldserver, $basedn, $usersrdn, $usersfilter, $usernameattr, $groupsrdn, $groupsfilter, $adadmin, $adadminpasswd); if ($samsldap != NULL) { print "<FORM NAME=\"SelectUsersGroup\" ACTION=\"main.php\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"show\" id=Show value=\"exe\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"function\" value=\"addusersfromldapform\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" id=filename value=\"authldapbuttom_2_usersadd.php\">\n"; if ($addgroupname == "_allgroups_" || $addgroupname == "") { $a = $samsldap->GetUsersData(); } else { $a = $samsldap->GetUsersWithPrimaryGroupID($addgroupname); $b = $samsldap->GetUsersWithSecondaryGroupID($addgroupname); for ($i = 0; $i < $a['userscount']; $i++) { $user = $a['uid'][$i]; $username = $a['name'][$i]; print "<B>{$user}</B> ({$username}) <BR>\n"; } } $groupinfo = $samsldap->GetGroupsData(); $SELECTED = ""; if ($addgroupname == "_allgroups_" || $addgroupname == "") { $SELECTED = "SELECTED"; } print "<TR><TD>{$usersbuttom_1_adldap_AddUsersFromAdLDAPForm_1}\n"; print "<TD><SELECT NAME=\"addgroupname\">\n"; print "<OPTION VALUE=\"_allgroups_\"> {$usersbuttom_1_adldap_AddUsersFromAdLDAPForm_5} \n"; for ($i = 0; $i < $groupinfo['groupscount']; $i++) { $groupname = $groupinfo['cn'][$i]; $gid = $groupinfo['gidNumber'][$i]; $SELECTED = ""; if ($groupname == $addgroupname) { $SELECTED = "SELECTED"; } print "<OPTION VALUE=\"{$groupname}\" {$SELECTED}> {$groupname} \n"; } print "</SELECT>\n"; print "</TABLE>\n"; print "<INPUT TYPE=\"SUBMIT\" value=\"{$usersbuttom_1_adldap_AddUsersFromAdLDAPForm_2}\" >\n"; print "<P>\n"; print "</FORM>\n"; print "<FORM NAME=\"AddDomainUsers\" ACTION=\"main.php\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"domain\" id=Show value=\"{$domain}\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"show\" id=Show value=\"exe\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"function\" id=function value=\"addusersfromldap\">\n"; print "<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" id=filename value=\"authldapbuttom_2_usersadd.php\">\n"; if (strlen($ldapgroup) > 0 && $ldapgroup != "_allgroups_" && $ldapgroup != "_gettxtinput_") { printf("<B>{$usersbuttom_1_adldap_AddUsersFromAdLDAPForm_4}: {$ldapgroup}</B><BR>"); } else { if (strlen($ldapgroup) > 0 && $ldapgroup == "_gettxtinput_") { printf("<B>{$usersbuttom_1_adldap_AddUsersFromAdLDAPForm_4}: {$getgroup}</B><BR>"); } else { print "<BR><B>{$usersbuttom_1_domain_AddUsersFromDomainForm_2}</B><BR>"; } } print "<SELECT NAME=\"username[]\" MULTIPLE>\n"; for ($i = 0; $i < $a['userscount']; $i++) { $user = $a['uid'][$i]; $username = $a['name'][$i]; $num_rows = $DB->samsdb_query_value("SELECT * FROM squiduser WHERE s_nick='{$user}'"); if ($num_rows == 0) { print "<OPTION VALUE=\"{$user}\"> <B>{$user}</B> ({$username}) \n"; } $DB->free_samsdb_query(); } for ($i = 0; $i < $b['userscount']; $i++) { $user = $b['uid'][$i]; $username = $b['name'][$i]; $num_rows = $DB->samsdb_query_value("SELECT * FROM squiduser WHERE s_nick='{$user}'"); if ($num_rows == 0) { print "<OPTION VALUE=\"{$user}\"> <B>{$user}</B> ({$username}) \n"; } $DB->free_samsdb_query(); } print "</SELECT>\n"; print "<P>"; print "<TABLE>\n"; print "<TR><TD><P>\n"; print "<TR><TD>\n"; print "<TR><TD>\n"; print "<B>{$usersbuttom_1_domain_AddUsersFromDomainForm_3} \n"; print "<TD>\n"; print "<SELECT NAME=\"groupname\" ID=\"groupname\" SIZE=1 TABINDEX=30 >\n"; $num_rows = $DB->samsdb_query_value("SELECT * FROM sgroup"); while ($row2 = $DB->samsdb_fetch_array()) { print "<OPTION VALUE=\"{$row2['s_group_id']}\"> {$row2['s_name']} \n"; } $DB->free_samsdb_query(); print "</SELECT>\n"; print "<TR>\n"; print "<TD>\n"; print "<B>{$usersbuttom_1_domain_AddUsersFromDomainForm_4} \n"; print "<TD>\n"; print "<SELECT NAME=\"usershablon\" ID=\"usershablon\" SIZE=1 TABINDEX=30 > \n"; $num_rows = $DB->samsdb_query_value("SELECT s_shablon_id, s_name FROM shablon"); while ($row = $DB->samsdb_fetch_array()) { print "<OPTION VALUE={$row['s_shablon_id']}> {$row['s_name']}\n"; } $DB->free_samsdb_query(); print "</SELECT>"; print "<TR><TD><B>{$usersbuttom_1_domain_AddUsersFromDomainForm_6}"; print "<TD><INPUT TYPE=\"CHECKBOX\" NAME=\"enabled\" CHECKED>"; print "</TABLE>\n"; print "<INPUT TYPE=\"SUBMIT\" value=\"{$usersbuttom_1_domain_AddUsersFromDomainForm_5}\">\n"; print "</FORM>\n"; /* print("<FORM NAME=\"AddDomainUsers\" ACTION=\"main.php\">\n"); print("<SCRIPT language=JAVASCRIPT>\n"); print("function SelectADGroup(formname)\n"); print("{\n"); print(" var group=formname.addgroupname.value; \n"); print(" var getgroup=formname.getgroup.value; \n"); print(" var str=\"main.php?show=exe&ldapgroup=\"+group+\"&getgroup=\"+getgroup+\"&function=addusersfromldapform&filename=authldapbuttom_2_usersadd.php\"; \n"); print(" parent.basefrm.location.href=str;\n"); print("}\n"); print("function EnableTxtInput(formname)\n"); print("{\n"); print(" value=document.forms[\"AddDomainUsers\"].elements[\"addgroupname\"].value;\n"); print(" if(value==\"_gettxtinput_\") \n"); print(" {\n"); print(" document.forms[\"AddDomainUsers\"].elements[\"getgroup\"].disabled=false\n"); print(" }\n"); print(" else \n"); print(" {\n"); print(" document.forms[\"AddDomainUsers\"].elements[\"getgroup\"].disabled=true\n"); print(" }\n"); print("}\n"); print("</SCRIPT> \n"); print("<INPUT TYPE=\"HIDDEN\" NAME=\"domain\" id=Show value=\"$domain\">\n"); print("<INPUT TYPE=\"HIDDEN\" NAME=\"show\" id=Show value=\"exe\">\n"); print("<INPUT TYPE=\"HIDDEN\" NAME=\"function\" id=function value=\"addusersfromldapap\">\n"); print("<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" id=filename value=\"authldapbuttom_2_usersadd.php\">\n"); print("<TABLE>\n"); print("<TR><TD><P>\n"); print("<TR><TD>\n"); print("<B>$usersbuttom_1_domain_AddUsersFromDomainForm_7\n"); print("<TD>\n"); print("<INPUT TYPE=\"TEXT\" NAME=\"domainname\" id=Show VALUE=\"$basedn\">\n"); print("<TR><TD>\n"); print("<B>$usersbuttom_1_domain_AddUsersFromDomainForm_3 \n"); print("<TD>\n"); print("<SELECT NAME=\"groupname\" ID=\"groupname\" SIZE=1 TABINDEX=30 >\n"); $num_rows=$DB->samsdb_query_value("SELECT * FROM sgroup"); while($row2=$DB->samsdb_fetch_array()) { print("<OPTION VALUE=\"$row2[s_group_id]\"> $row2[s_name] "); } $DB->free_samsdb_query(); print("</SELECT>\n"); print("<TR>\n"); print("<TD>\n"); print("<B>$usersbuttom_1_domain_AddUsersFromDomainForm_4 \n"); print("<TD>\n"); print("<SELECT NAME=\"usershablon\" ID=\"usershablon\" SIZE=1 TABINDEX=30 >\n"); $num_rows=$DB->samsdb_query_value("SELECT s_shablon_id, s_name FROM shablon"); while($row=$DB->samsdb_fetch_array()) { print("<OPTION VALUE=$row[s_shablon_id]> $row[s_name]"); } $DB->free_samsdb_query(); print("</SELECT>"); print("<TR><TD><B>$usersbuttom_1_domain_AddUsersFromDomainForm_6"); print("<TD><INPUT TYPE=\"CHECKBOX\" NAME=\"enabled\" CHECKED>"); print("</TABLE>\n"); print("<INPUT TYPE=\"SUBMIT\" value=\"$usersbuttom_1_domain_AddUsersFromDomainForm_5\">\n"); print("</FORM>\n"); */ } exit(0); }