Exemple #1
0
bool DropUserHandler::handleURI(URI& uri)
{
    if (uri.action != "drop_user")
        return false;

    wxWindow* w = getParentWindow(uri);
    UserPtr u = extractMetadataItemPtrFromURI<User>(uri);
    if (!u || !w)
        return true;
    ServerPtr s = u->getServer();
    if (!s)
        return true;

    if (wxNO == wxMessageBox(_("Are you sure?"), _("Removing User"),
        wxYES_NO|wxICON_QUESTION))
        return true;

    ProgressDialog pd(w, _("Connecting to Server..."), 1);
    pd.doShow();
    IBPP::Service svc;
    if (!getService(s.get(), svc, &pd, true)) // true = need SYSDBA password
        return true;

    try
    {
        svc->RemoveUser(wx2std(u->getUsername()));
        s->notifyObservers();
    }
    catch(IBPP::Exception& e)
    {
        wxMessageBox(e.what(), _("Error"),
            wxOK | wxICON_WARNING);
    }
    return true;
}
Exemple #2
0
void* RestoreThread::Entry()
{
    wxDateTime now;
    wxString msg;

    try
    {
        msg.Printf(_("Connecting to server %s..."), serverM.c_str());
        logImportant(msg);
        IBPP::Service svc = IBPP::ServiceFactory(wx2std(serverM),
            wx2std(usernameM), wx2std(passwordM));
        svc->Connect();

        now = wxDateTime::Now();
        msg.Printf(_("Database restore started %s"), now.FormatTime().c_str());
        logImportant(msg);
        svc->StartRestore(wx2std(bkfileM), wx2std(dbfileM), pagesizeM, brfM);
        while (true)
        {
            if (TestDestroy())
            {
                now = wxDateTime::Now();
                msg.Printf(_("Database restore canceled %s"),
                    now.FormatTime().c_str());
                logImportant(msg);
                break;
            }
            const char* c = svc->WaitMsg();
            if (c == 0)
            {
                now = wxDateTime::Now();
                msg.Printf(_("Database restore finished %s"),
                    now.FormatTime().c_str());
                logImportant(msg);
                break;
            }
            msg = c;
            logProgress(msg);
        }
        svc->Disconnect();
    }
    catch (IBPP::Exception& e)
    {
        now = wxDateTime::Now();
        msg.Printf(_("Database restore canceled %s due to IBPP exception:\n\n"),
            now.FormatTime().c_str());
        msg += e.what();
        logError(msg);
    }
    catch (...)
    {
        now = wxDateTime::Now();
        msg.Printf(_("Database restore canceled %s due to exception"),
            now.FormatTime().c_str());
        logError(msg);
    }
    return 0;
}
Exemple #3
0
UserPtrs Server::getUsers(ProgressIndicator* progressind)
{
    usersM.clear();
    IBPP::Service svc;
    if (!fr::getService(this, svc, progressind, true))   // true = SYSDBA
        return usersM;

    std::vector<IBPP::User> usr;
    svc->GetUsers(usr);
    for (std::vector<IBPP::User>::iterator it = usr.begin();
            it != usr.end(); ++it)
    {
        UserPtr u(new User(shared_from_this(), *it));
        usersM.push_back(u);
    }


    std::sort(usersM.begin(), usersM.end(), SortUsers());
    return usersM;
}
Exemple #4
0
//-----------------------------------------------------------------------------
bool Server::getService(IBPP::Service& svc, ProgressIndicator* progressind,
                        bool sysdba)
{
    if (progressind)
    {
        progressind->initProgress(_("Connecting..."),
                                  databasesM.size() + 2, 0, 1);
    }

    // check if we already had some successful connections
    if (!serviceSysdbaPasswordM.isEmpty())  // we have sysdba pass
    {
        if (progressind)
        {
            progressind->setProgressMessage(_("Using current SYSDBA password"));
            progressind->stepProgress();
        }
        try
        {
            svc = IBPP::ServiceFactory(wx2std(getConnectionString()),
                                       "SYSDBA", wx2std(serviceSysdbaPasswordM));
            svc->Connect();
            return true;
        }
        catch(IBPP::Exception&)   // keep going if connect fails
        {
            serviceSysdbaPasswordM.clear();
        }
    }
    if (progressind && progressind->isCanceled())
        return false;
    // check if we have non-sysdba connection
    if (!sysdba && !serviceUserM.isEmpty())
    {
        if (progressind)
        {
            progressind->setProgressMessage(QString::fromLatin1("Using current %1 password")
                                            .arg(serviceUserM));
            progressind->stepProgress();
        }
        try
        {
            svc = IBPP::ServiceFactory(wx2std(getConnectionString()),
                                       wx2std(serviceUserM), wx2std(servicePasswordM));
            svc->Connect();
            return true;
        }
        catch(IBPP::Exception&)   // keep going if connect fails
        {
            serviceUserM.clear();
            servicePasswordM.clear();
        }
    }

    // first try connected databases
    for (DatabasePtrs::iterator ci = databasesM.begin();
            ci != databasesM.end(); ++ci)
    {
        if (progressind && progressind->isCanceled())
            return false;
        if (!(*ci)->isConnected())
            continue;
        // Use the user name and password of the connected user
        // instead of the stored ones.
        IBPP::Database& db = (*ci)->getIBPPDatabase();
        if (sysdba && std2wx(db->Username()).toUpper() != QString::fromLatin1("SYSDBA"))
            continue;
        if (progressind)
        {
            progressind->setProgressMessage(_("Using password of: ") +
                                            std2wx(db->Username()) + QString::fromLatin1("@") + (*ci)->getName_());
            progressind->stepProgress();
        }
        try
        {
            svc = IBPP::ServiceFactory(wx2std(getConnectionString()),
                                       db->Username(), db->UserPassword());
            svc->Connect();
            if (sysdba)
                serviceSysdbaPasswordM = std2wx(db->UserPassword());
            else
            {
                serviceUserM = std2wx(db->Username());
                servicePasswordM = std2wx(db->UserPassword());
            }
            return true;
        }
        catch(IBPP::Exception&)   // keep going if connect fails
        {
        }
    }

    // when the operation is not canceled try to user/pass of disconnected DBs
    for (DatabasePtrs::const_iterator ci = databasesM.begin();
            ci != databasesM.end(); ++ci)
    {
        if (progressind && progressind->isCanceled())
            return false;
        if ((*ci)->isConnected())
            continue;
        QString user = (*ci)->getUsername();
        QString pwd = (*ci)->getDecryptedPassword();
        if (pwd.isEmpty() || sysdba && user.toUpper() != QString::fromLatin1("SYSDBA"))
            continue;
        if (progressind)
        {
            progressind->setProgressMessage(_("Using password of: ") +
                                            user + QString::fromLatin1("@") + (*ci)->getName_());
            progressind->stepProgress();
        }
        try
        {
            svc = IBPP::ServiceFactory(wx2std(getConnectionString()),
                                       wx2std(user), wx2std(pwd));
            svc->Connect();
            if (sysdba)
                serviceSysdbaPasswordM = pwd;
            else
            {
                serviceUserM = user;
                servicePasswordM = pwd;
            }
            return true;
        }
        catch(IBPP::Exception&)   // keep going if connect fails
        {
        }
    }
    return false;
}
Exemple #5
0
bool UserPropertiesHandler::handleURI(URI& uri)
{
    bool addUser = uri.action == "add_user";
    bool editUser = uri.action == "edit_user";
    if (!addUser && !editUser)
        return false;

    wxWindow* w = getParentWindow(uri);
    ServerPtr server;
    UserPtr user;
    wxString title(_("Modify User"));
    if (addUser)
    {
        server = extractMetadataItemPtrFromURI<Server>(uri);
        if (!server)
            return true;
        title = _("Create New User");
        user.reset(new User(server));
    }
    else
    {
        user = extractMetadataItemPtrFromURI<User>(uri);
        if (!user)
            return true;
#ifdef __WXGTK__
        if (user->getUsername() == "SYSDBA")
        {
            showWarningDialog(w, _("The password for the SYSDBA user should not be changed here."),
                _("The appropriate way to change the password of the SYSDBA user is to run the changeDBAPassword.sh script in Firebird's bin directory.\n\nOtherwise the scripts will not be updated."),
                AdvancedMessageDialogButtonsOk(), config(), "DIALOG_warn_sysdba_change",
                _("Do not show this information again"));
        }
#endif
        server = user->getServer();
        if (!server)
            return true;
    }

    UserDialog d(w, title, addUser);
    d.setUser(user);
    if (d.ShowModal() == wxID_OK)
    {
        ProgressDialog pd(w, _("Connecting to Server..."), 1);
        pd.doShow();
        IBPP::Service svc;
        if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password
            return true;

        try
        {
            IBPP::User u;
            user->assignTo(u);
            if (addUser)
                svc->AddUser(u);
            else
                svc->ModifyUser(u);
            server->notifyObservers();
        }
        catch(IBPP::Exception& e)
        {
            wxMessageBox(e.what(), _("Error"),
                wxOK | wxICON_WARNING);
        }
    }
    return true;
}
bool DatabaseInfoHandler::handleURI(URI& uri)
{
    bool isEditSweep, isEditForcedWrites, isEditReserve, isEditReadOnly,
        isEditPageBuffers;

    isEditSweep = (uri.action == "edit_db_sweep_interval");
    isEditForcedWrites = (uri.action == "edit_db_forced_writes");
    isEditReserve = (uri.action == "edit_db_reserve_space");
    isEditReadOnly = (uri.action == "edit_db_read_only");
    isEditPageBuffers = (uri.action == "edit_db_page_buffers");

    if (!isEditSweep && !isEditForcedWrites && !isEditReserve
        && !isEditReadOnly && !isEditPageBuffers)
    {
        return false;
    }

    DatabasePtr d = extractMetadataItemPtrFromURI<Database>(uri);
    wxWindow* w = getParentWindow(uri);

    // when either the database or the window does not exist
    // return immediately. Because this function returns whether
    // the specified uri is handled, return true.
    if (!d || !w || !d->isConnected())
         return true;

    IBPP::Database& db = d->getIBPPDatabase();
    IBPP::Service svc = IBPP::ServiceFactory(
        wx2std(d->getServer()->getConnectionString()),
        db->Username(), db->UserPassword());
    svc->Connect();

    if (isEditSweep || isEditPageBuffers)
    {
        long oldValue = 0;
        wxString title, label;
        if (isEditSweep)
        {
            oldValue = d->getInfo().getSweep();
            title = _("Enter the new Sweep Interval");
            label = _("Sweep Interval"); 
        }
        else if (isEditPageBuffers)
        {
            oldValue = d->getInfo().getBuffers();
            title = _("Enter the new value for Page Buffers");
            label = _("Page Buffers"); 
        }

        while (true)
        {
            wxString s;
            long value = oldValue;
            s = ::wxGetTextFromUser(title, label,
                wxString::Format("%d", value), w);

            // return from the iteration when the entered string is empty, in
            // case of cancelling the operation.
            if (s.IsEmpty())
                break;
            if (!s.ToLong(&value))
                continue;
            // return from the iteration when the interval has not changed
            if (value == oldValue)
                break;

            if (isEditSweep)
                svc->SetSweepInterval(wx2std(d->getPath()), value);
            else if (isEditPageBuffers)
                svc->SetPageBuffers(wx2std(d->getPath()), value);

            // Before reloading the info, re-attach to the database
            // otherwise the sweep interval won't be changed for FB Classic
            // Server.
            db->Disconnect();
            db->Connect();
            d->loadInfo();
            break;
        }
    }

    else if (isEditForcedWrites || isEditReserve || isEditReadOnly)
    {
        bool fw = !d->getInfo().getForcedWrites();
        bool reserve = !d->getInfo().getReserve();
        bool ro = !d->getInfo().getReadOnly();

        // setting these properties requires that the database is
        // disconnected.
        db->Disconnect();

        if (isEditForcedWrites)
            svc->SetSyncWrite(wx2std(d->getPath()), fw);
        if (isEditReserve)
            svc->SetReserveSpace(wx2std(d->getPath()), reserve);
        if (isEditReadOnly)
            svc->SetReadOnly(wx2std(d->getPath()), ro);

        db->Connect();

        // load the database info because the info values are changed.
        d->loadInfo();
    }

    svc->Disconnect();
    return true;
}