示例#1
0
        protected static bool ResetAdmin()
        {
            bool bRet = true;

            try
            {
                SBConfigStor.Directory dTmp = new SBConfigStor.Directory();
                if (dTmp == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    bool   bRes    = true;
                    string sUserid = "";

                    bool bFound = SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid);
                    if (!bFound)
                    {
                        // Add admin user before continuing.

                        Console.Error.WriteLine("WARNING: Admin user not found, adding now.");

                        SBConfigStor.Users.User uTmp = new SBConfigStor.Users.User();
                        uTmp.Username = g_sAdminUsername;

                        SBConfigStor.Directory.AddUser(uTmp);

                        bFound = SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid);
                        if (!bFound)
                        {
                            bRes = false;
                            Console.Error.WriteLine("ERROR: Couldn't find admin user that was just added to the DB!");
                        }
                    }

                    // Set the password
                    if (bRes)
                    {
                        bRes = dTmp.SetPassByUserid(sUserid, g_sAdminUsername.ToUpper(), g_sAdminUsername.ToLower());
                        if (!bRes)
                        {
                            Console.Error.WriteLine("ERROR:  Couldn't set the password.");
                        }
                        else
                        {
                            Console.WriteLine("Admin password was reset.");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(bRet);
        }         // ResetAdmin
示例#2
0
        }         // ResetAdmin

        protected static int SetAdminPassword(string i_sOldPassword, string i_sNewPassword)
        {
            int iExitCode = EXIT_CODE_UNKNOWN_ERROR;

            try
            {
                SBConfigStor.Directory directory = new SBConfigStor.Directory();

                if (directory == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    if (directory.Authenticate(g_sAdminUsername, i_sOldPassword))
                    {
                        string sUserid = "";

                        if (SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid))
                        {
                            bool bRes = directory.SetPassByUserid(sUserid, i_sNewPassword.ToUpper(), i_sNewPassword);
                            if (!bRes)
                            {
                                Console.Error.WriteLine("ERROR: Couldn't set the password.");
                            }
                            else
                            {
                                iExitCode = EXIT_CODE_SUCCESS;
                                Console.WriteLine("Admin password was set to '{0}'.", i_sNewPassword);
                            }
                        }
                        else
                        {
                            // This should not be possible, as we have already authenticated the admin user.

                            Console.Error.WriteLine("ERROR: Admin user not found.");
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("ERROR: Old password incorrect.");
                    }
                }
            }
            catch (Exception exc)
            {
                iExitCode = EXIT_CODE_UNKNOWN_ERROR;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(iExitCode);
        }
示例#3
0
        protected static bool AddUser(string i_sUsername, string i_sPassword, string i_sDefaultWebpage)
        {
            bool          bRet  = true;
            StringBuilder sbSql = null;

            try
            {
                SBConfigStor.Directory dTmp = new SBConfigStor.Directory();
                if (dTmp == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    bool   bRes    = true;
                    string sUserid = "";


                    // Create the user

                    SBConfigStor.Users.User uTmp = new SBConfigStor.Users.User();
                    uTmp.Username = i_sUsername;

                    SBConfigStor.Directory.AddUser(uTmp);

                    bool bFound = SBConfigStor.Directory.GetUseridByUsername(i_sUsername, out sUserid);
                    if (!bFound)
                    {
                        bRes = false;
                        Console.Error.WriteLine("ERROR: Couldn't find user that was just added to the DB!");
                    }
                    else
                    {
                        Console.WriteLine("  User created.");

                        // Set the password
                        if (bRes)
                        {
                            bRes = dTmp.SetPassByUserid(sUserid, i_sUsername, i_sPassword);
                            if (!bRes)
                            {
                                Console.Error.WriteLine("ERROR:  Couldn't set the password.");
                            }
                            else
                            {
                                Console.WriteLine("  User's password set.");
                            }
                        }

                        if ((i_sDefaultWebpage == null) || (i_sDefaultWebpage.Length <= 0))
                        {
                            // Not an error, just don't do anything.
                        }
                        else
                        {
                            // Set the default webpage
                            sbSql = new StringBuilder();
                            sbSql.AppendFormat("INSERT INTO tblUserParams (uUserId, iParamType, sParamName, sParamValue) VALUES ('{0}', '{1}', '{2}', '{3}');", sUserid, (int)(UserPrefs.eParamType.DefaultWebpage), UserPrefs.eParamType.DefaultWebpage.ToString(), i_sDefaultWebpage);

                            bRes = RunSqlCmd(sbSql.ToString());
                            if (bRes)
                            {
                                Console.WriteLine("  User's default webpage set.");
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(bRet);
        }         // AddUser
示例#4
0
        private static int ImportDirectory(string i_sFileType, string i_sFileName, bool i_bMerge)
        {
            int iExitCode = EXIT_CODE_SUCCESS;

            IImportParser importParser = null;

            switch (i_sFileType.ToLower())
            {
            case "csv":
                importParser = new CsvImportParser();
                break;

            case "allworx":
                importParser = new AllworxImportParser();
                break;

            case "shoretel":
                importParser = new ShoreTelImportParser();
                break;

            default:
                iExitCode = EXIT_CODE_ILLEGAL_ARGUMENT;
                Console.Error.WriteLine("ERROR: Invalid type specified {0} - valid types are: csv, allworx, shoretel", i_sFileType);
                break;
            }

            if (null != importParser)
            {
                byte[] importBytes = GetBytesFromImportFile(i_sFileName);

                if ((null != importBytes) && (importBytes.Length > 0))
                {
                    bool bContinueImport = true;

                    if (!i_bMerge)
                    {
                        bContinueImport = DeleteAllUsersExceptAdmin();
                    }

                    if (bContinueImport)
                    {
                        SBConfigStor.Directory sbcDir = new SBConfigStor.Directory();
                        SBConfigStor.Directory.eImportStatus importStatus = sbcDir.Persist(importBytes, importParser, GetNumberOfUsersThatCanBeAdded());

                        if (SBConfigStor.Directory.eImportStatus.eFailure == importStatus)
                        {
                            iExitCode = EXIT_CODE_IMPORT_ERROR;
                            Console.Error.WriteLine("ERROR: There was an error importing the file ('{0}', '{1}').", i_sFileType, i_sFileName);
                        }
                        else
                        {
                            if (SBConfigStor.Directory.eImportStatus.eIncomplete == importStatus)
                            {
                                iExitCode = EXIT_CODE_IMPORT_INCOMPLETE;
                                Console.Error.WriteLine("WARNING: Import incomplete since licensed number of Directory Entries exceeded.");
                            }

                            ConfigParams.SetVoicexmlDirty(true);
                        }
                    }
                    else
                    {
                        iExitCode = EXIT_CODE_IMPORT_ERROR;
                    }
                }
                else
                {
                    iExitCode = EXIT_CODE_IMPORT_ERROR;
                    Console.Error.WriteLine("ERROR: Import file was empty or doesn't exist {0}.", i_sFileName);
                }
            }

            return(iExitCode);
        }