Exemple #1
0
        internal static bool GetFTPUserGroups(string UserName)
        {
            string usernme         = FTPUser.GetMasterUser(); /// persalnumber;
            string pwd             = FTPUser.GetMasterPwd();
            string get_ldap_string = FTPUser.GetLDAPString();
            string ldapstring      = "LDAP://" + FTPUser.GetIPaddressString() + "/CN=FTP_ACCESS," + get_ldap_string;

            DirectoryEntry dsDirectoryEntry = new DirectoryEntry(ldapstring, usernme, pwd);

            //string s = null;

            XmlNodeList Users = GetUserList();
            XmlNode     User  = ApplicationSettings.Settings.CreateElement("User");

            User.Attributes.Append(ApplicationSettings.Settings.CreateAttribute("UserName"));
            User.Attributes.Append(ApplicationSettings.Settings.CreateAttribute("Password"));
            User.Attributes.Append(ApplicationSettings.Settings.CreateAttribute("RootDirectory"));
            User.Attributes.Append(ApplicationSettings.Settings.CreateAttribute("PermissionSet"));
            User.Attributes.Append(ApplicationSettings.Settings.CreateAttribute("Enabled"));
            Settings.DocumentElement.SelectSingleNode("UserAccount").AppendChild(User);

            User.Attributes[0].Value = UserName.ToUpper();

            return(true);
        }
Exemple #2
0
        //internal static Collection GetGroupUsers(string strGroupName)
        //{
        //    string usr = FTPUser.GetMasterUser(); /// persalnumber;
        //    string pwd = FTPUser.GetMasterPwd();
        //    string get_ldap_string = FTPUser.GetAppOUContext();
        //    string ldapstring = "LDAP://" + FTPUser.GetIPaddressString() + "/CN=FTP_ACCESS," + get_ldap_string;

        //    DirectoryEntry de = new DirectoryEntry(ldapstring, usernme, pwd);
        //    DirectorySearcher ds = new DirectorySearcher(de);
        //    Collection sbGroupUsers = null;
        //    {
        //        ds.PropertiesToLoad.Add("memberOf");
        //        try
        //        {
        //            SearchResultCollection dsResultColl = ds.FindAll();

        //            short shtCounter = 0;

        //            if (dsResultColl == null)
        //            { return null; }
        //            //ResultPropertyCollection myResultPropColl;
        //            //strUsers = dsResultColl.Properties["memberOf"].IndexOf(shtCounter).ToString();
        //            //sbGroupUsers.Add(strUsers.ToString().Trim());
        //            //sbGroupUsers.Add(ControlChars.CrLf);

        //            foreach (string myKey in myResultPropColl.PropertyNames)
        //            {
        //                string tab = "    ";
        //                Console.WriteLine(myKey + " = ");
        //                foreach (Object myCollection in myResultPropColl[myKey])
        //                {
        //                    Console.WriteLine(tab + myCollection);
        //                }
        //            }

        //            ds.Dispose();
        //            de.Dispose();
        //        }

        //        catch (Exception ex)
        //        {
        //            Interaction.MsgBox("Error in GetGroupUsers Function" + Constants.vbNewLine + ex.Message.ToString(), MsgBoxStyle.Information, "Active Directory Error");
        //        }
        //    }
        //    return sbGroupUsers;
        //}

        public static StringCollection GetFTPUsers3()
        {
            string usr             = FTPUser.GetMasterUser(); /// persalnumber;
            string pwd             = FTPUser.GetMasterPwd();
            string get_ldap_string = FTPUser.GetAppOUContext();

            StringCollection col = new StringCollection();

            string ldapstring = "LDAP://" + FTPUser.GetIPaddressString() + "/CN=FTP_ACCESS," + get_ldap_string;

            try
            {
                DirectoryEntry    de = new DirectoryEntry(ldapstring, usr, pwd);
                DirectorySearcher ds = new DirectorySearcher(de);
                SearchResult      sr = ds.FindOne();
                if (sr != null)
                {
                    DirectoryEntry           myde = sr.GetDirectoryEntry();
                    string                   mySearchResultPath = sr.Path;
                    ResultPropertyCollection myResultPropColl;
                    myResultPropColl = sr.Properties;
                    foreach (string user in myde.Properties)
                    {
                        Interaction.MsgBox(user.ToString(), MsgBoxStyle.OkOnly, "System Message");
                    }
                    de.Dispose();
                    myde.Dispose();
                }
                else
                {
                    //Console.WriteLine("The '" + myLDAPPath + "' path not found.");
                }
            }
            catch (Exception ex)
            {
                Interaction.MsgBox(ex.Message);
            }
            return(col);
        }
Exemple #3
0
        internal static XmlNodeList GetFTPUsers()
        {
            string usr             = FTPUser.GetMasterUser();
            string pwd             = FTPUser.GetMasterPwd();
            string get_ldap_string = FTPUser.GetAppOUContext();
            string ldapstring      = "LDAP://" + FTPUser.GetIPaddressString() + "/CN=FTP_ACCESS," + get_ldap_string;

            DirectoryEntry         dsDirectoryEntry  = new DirectoryEntry(ldapstring, usr, pwd);
            XmlNodeList            UserGroups        = null;
            SearchResultCollection dsResultCollecion = null;
            XmlAttribute           UserAttributes    = null;
            XmlNode User = null;

            int i = 0;

            DirectorySearcher dsSearcher = new DirectorySearcher(dsDirectoryEntry);

            dsSearcher.PropertiesToLoad.Add("memberOf");

            try
            {
                dsResultCollecion = dsSearcher.FindAll();
                if (dsResultCollecion == null)
                {
                    return(null);
                }
                for (i = 0; i <= (dsResultCollecion.PropertiesLoaded.LongLength - 1); i++)
                {
                    User.Value = dsResultCollecion.PropertiesLoaded[0].ToString();
                    User.Attributes.Append(UserAttributes);
                    UserGroups[i].AppendChild(User);
                }
            }
            catch (Exception ex)
            {
                Interaction.MsgBox(ex.ToString());
            }
            return(UserGroups);
        }
Exemple #4
0
        public static Collection GetUserGroups(string _persalnumber)
        {
            string usr             = FTPUser.GetMasterUser();
            string pwd             = FTPUser.GetMasterPwd();
            string get_ldap_string = FTPUser.GetAppOUContext();
            string ldapstring      = "LDAP://" + FTPUser.GetIPaddressString() + "/CN=FTP_ACCESS," + get_ldap_string;

            DirectoryEntry dsDirectoryEntry = new DirectoryEntry(ldapstring, usr, pwd);

            int    bytCounter = 0;
            string strGroups  = null;

            Microsoft.VisualBasic.Collection UserGroups = new Microsoft.VisualBasic.Collection();
            StringBuilder     sbUserGroups = new StringBuilder();
            DirectorySearcher dsSearcher   = new DirectorySearcher(dsDirectoryEntry);

            dsSearcher.PropertiesToLoad.Add("memberOf");

            try
            {
                SearchResult dsResult = dsSearcher.FindOne();
                if (dsResult == null)
                {
                    return(null);
                }
                for (bytCounter = 0; bytCounter <= (dsResult.Properties["memberOf"].Count - 1); bytCounter++)
                {
                    strGroups = dsResult.Properties["memberOf"][0].ToString();
                    UserGroups.Add(strGroups);
                }
            }
            catch (Exception)
            {
            }
            return(UserGroups);
        }