Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

multiauthconfig.cpp

Go to the documentation of this file.
00001 #include <opie2/odebug.h>
00002 #include <opie2/oresource.h>
00003 #include <opie2/multiauthpassword.h>
00004 
00005 #include <qgroupbox.h>
00006 #include <qvgroupbox.h>
00007 #include <qlayout.h>
00008 #include <qlabel.h>
00009 #include <qhbox.h>
00010 #include <qheader.h>
00011 #include <qvbox.h>
00012 #include <qwhatsthis.h>
00013 #include <qtoolbutton.h>
00014 #include <qstringlist.h>
00015 #include <qdir.h>
00016 #include <qpe/qlibrary.h>
00017 #include <qpe/qpeapplication.h>
00018 
00019 #include "multiauthconfig.h"
00020 
00021 
00022 using Opie::Security::MultiauthPluginInterface;
00023 using Opie::Security::MultiauthPluginObject;
00024 using Opie::Security::MultiauthConfigWidget;
00026 struct MultiauthPlugin {
00027     MultiauthPlugin() : library( 0 ), iface( 0 ), pluginObject( 0 ) {}
00029     QLibrary *library;
00031     QInterfacePtr<MultiauthPluginInterface> iface;
00033     MultiauthPluginObject *pluginObject;
00035     QString name;
00037     bool active;
00039     int pos;
00040 };
00041 
00043 static QValueList<MultiauthPlugin> pluginList;
00044 
00045 
00047 class ToolButton : public QToolButton {
00048 
00049     public:
00050         ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
00051             : QToolButton( parent, name ) {
00052                 setPixmap( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) );
00053                 setAutoRaise( TRUE );
00054                 setFocusPolicy( QWidget::NoFocus );
00055                 setToggleButton( t );
00056                 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
00057             }
00058 };
00059 
00060     MultiauthGeneralConfig::MultiauthGeneralConfig(MultiauthConfig * parentConfig, QWidget * parent, const char * name = "general Opie-multiauthentication config widget")
00061 : QWidget(parent, name), m_onStart(0), m_onResume(0), m_noProtectConfig(0), m_explanScreens(0), m_nbSuccessMin(0), m_tryButton(0)
00062 {
00063     // keep track of the MultiauthConfig parent in one of our attributes
00064     m_parentConfig = parentConfig;
00065     QVBoxLayout *vb = new QVBoxLayout(this);
00066     vb->setSpacing(11);
00067     vb->setMargin(11);
00068     vb->setAlignment( Qt::AlignTop );
00069 
00070     QGroupBox *lockBox = new QGroupBox(0, Qt::Vertical, tr("When to lock Opie"), this, "lock box");
00071     vb->addWidget(lockBox);
00072     QGridLayout *boxLayout = new QGridLayout( lockBox->layout() );
00073     m_onStart = new QCheckBox( tr( "on Opie start" ), lockBox, "lock on opie start");
00074     m_onResume = new QCheckBox( tr( "on Opie resume" ), lockBox, "lock on opie resume");
00075     boxLayout->addWidget(m_onStart, 0, 0);
00076     boxLayout->addWidget(m_onResume, 0, 1);
00077 
00078     QGroupBox *nbBox = new QGroupBox(0, Qt::Vertical, tr("Multiple plugins authentication"), this, "nb box");
00079     vb->addWidget(nbBox);
00080     QGridLayout *nbBoxLayout = new QGridLayout( nbBox->layout() );
00081     m_nbSuccessMin = new QSpinBox(nbBox);
00082     QLabel *lNbSuccessMin = new QLabel( tr( "Required successes" ), nbBox);
00083     nbBoxLayout->addWidget(m_nbSuccessMin, 0, 0);
00084     nbBoxLayout->addWidget(lNbSuccessMin, 0, 1);
00085     m_nbSuccessMin->setMinValue(1); // the max value is defined in MultiauthConfig constructor
00086 
00087     QGroupBox *devBox = new QGroupBox(0, Qt::Vertical, tr("Options"), this, "dev box");
00088     vb->addWidget(devBox);
00089     QGridLayout *devBoxLayout = new QGridLayout( devBox->layout() );
00090     m_noProtectConfig = new QCheckBox( tr("Don't protect this config screen"), devBox, "don't protect config");
00091     m_explanScreens = new QCheckBox( tr("Show explanatory screens"), devBox, "Show explan. screens");
00092     devBoxLayout->addWidget(m_noProtectConfig, 0, 0);
00093     devBoxLayout->addWidget(m_explanScreens, 1, 0);
00094 
00095     QVGroupBox *tryBox = new QVGroupBox(tr("Testing"), this, "try box");
00096     vb->addWidget(tryBox);
00097     m_tryButton = new QPushButton( tr("Test the authentication now"), tryBox, "try button");
00098     connect( m_tryButton, SIGNAL(clicked()), this, SLOT(tryAuth()) );
00099 
00100 }
00101 
00103 MultiauthGeneralConfig::~MultiauthGeneralConfig()
00104 {}
00105 
00107 void MultiauthGeneralConfig::tryAuth()
00108 {
00109     QMessageBox confirmSave(
00110                          tr("Attention"),
00111                          "<p>" + tr("You must save your current settings before trying to authenticate. Press OK to accept and launch a simulated authentication process.") + "</p><p><em>" +
00112                          tr("If you don't like the result of this test, don't forget to change your settings before you exit the configuration application!") + "</em></p>",
00113                          QMessageBox::Warning,
00114                          QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
00115                          0, QString::null, TRUE, WStyle_StaysOnTop);
00116     confirmSave.setButtonText(QMessageBox::Cancel, tr("Cancel"));
00117     confirmSave.setButtonText(QMessageBox::Yes, tr("OK"));
00118 
00119     if ( confirmSave.exec() == QMessageBox::Yes)
00120     {
00121         owarn << "writing config as user accepted" << oendl;
00122         m_parentConfig->writeConfigs();
00123         owarn << "testing authentication" << oendl;
00124         // launch the authentication in testing mode
00125         Opie::Security::MultiauthPassword::authenticate(Opie::Security::TestNow);
00126     }
00127 }
00128 
00129 
00131 static void test_and_start() {
00132     Config pcfg("Security");
00133     pcfg.setGroup( "Misc" );
00134     bool protectConfigDialog = ! pcfg.readBoolEntry("noProtectConfig", true);
00135 
00136     if (protectConfigDialog && Opie::Security::Internal::runPlugins() != 0) {
00137         owarn << "authentication failed, not showing opie-security" << oendl;
00138         exit( -1 );
00139     }
00140 }
00141 
00142 
00143 
00144     MultiauthConfig::MultiauthConfig(QWidget* par, const char* w = "MultiauthConfig dialog",  WFlags f = 0)
00145 : QDialog(par, w, TRUE, f),
00146     m_mainTW(0), m_pluginListView(0), m_pluginListWidget(0),
00147     m_generalConfig(0), m_loginWidget(0), m_syncWidget(0),
00148     m_nbSuccessReq(0), m_plugins_changed(false)
00149 {
00150     /* Initializes the global configuration window
00151     */
00152     test_and_start();
00153 
00154     /* Checks (and memorizes) if any authentication plugins are
00155      * installed on the system
00156      */
00157     QString path = QPEApplication::qpeDir() + "plugins/security";
00158     QDir dir( path, "lib*.so" );
00159     QStringList list = dir.entryList();
00160 
00161     m_pluginsInstalled = ! list.isEmpty();
00162     if (m_pluginsInstalled == false)
00163         owarn << "no authentication plugins installed! Talking about it in the last tab..." << oendl;
00164 
00165     setCaption( tr( "Security configuration" ) );
00166     QVBoxLayout *layout = new QVBoxLayout( this );
00167     m_mainTW = new Opie::Ui::OTabWidget( this, "main tab widget" );
00168     layout->addWidget(m_mainTW);
00169 
00170     if (m_pluginsInstalled)
00171     {
00172         m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget");
00173         QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget);
00174         pluginListLayout->setSpacing(6);
00175         pluginListLayout->setMargin(11);
00176         QLabel * pluginListTitle = new QLabel( tr( "Load which plugins in what order:" ), m_pluginListWidget );
00177         pluginListLayout->addWidget(pluginListTitle);
00178         QHBox * pluginListHB = new QHBox(m_pluginListWidget);
00179         pluginListLayout->addWidget(pluginListHB);
00180 
00181         m_pluginListView = new QListView(pluginListHB);
00182         m_pluginListView->addColumn("PluginList");
00183         m_pluginListView->header()->hide();
00184         m_pluginListView->setSorting(-1);
00185         QWhatsThis::add(m_pluginListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the order they will appear in" ));
00186 
00187         QVBox * pluginListVB = new QVBox(pluginListHB);
00188         new ToolButton( pluginListVB, tr( "Move Up" ), "up",  this , SLOT( moveSelectedUp() ) );
00189         new ToolButton( pluginListVB, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) );
00190         m_mainTW->addTab( m_pluginListWidget, "pass", tr( "plugins" ) );
00191 
00192         connect ( m_pluginListView , SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( pluginsChanged ( ) ) );
00193 
00194         // general Opie multi-authentication configuration tab
00195         m_generalConfig = new MultiauthGeneralConfig(this, m_mainTW);
00196         m_mainTW->addTab(m_generalConfig, "SettingsIcon", tr( "Authentication") );
00197 
00198     }
00199     // login settings page
00200     m_loginWidget = new LoginBase(m_mainTW, "login config widget");
00201     m_mainTW->addTab(m_loginWidget, "security/users", tr( "Login") );
00202 
00203     // sync settings page
00204     m_syncWidget = new SyncBase( m_mainTW, "sync config widget" );
00205     m_mainTW->addTab(m_syncWidget, "security/sync", tr( "Sync") );
00206 
00207     // read the "Security" Config file and update our UI
00208     readConfig();
00209 
00210 
00211     if (m_pluginsInstalled)
00212     {
00213         /* loads plugins configuration widgets in mainTW tabs and in pluginListView
00214         */
00215 
00216         loadPlugins();
00217 
00218         for ( int i = pluginList.count() - 1; i >= 0; i-- ) {
00219             MultiauthPlugin plugin = pluginList[i];
00220 
00221             // load the config widgets in the tabs
00222             // (configWidget will return 0l if there is no configuration GUI)
00223             MultiauthConfigWidget* widget = plugin.pluginObject->configWidget(m_mainTW);
00224             if ( widget != 0l ) {
00225                 odebug << "plugin " << plugin.name << " has a configuration widget" << oendl;
00226                 configWidgetList.append(widget);
00227                 m_mainTW->addTab( widget, plugin.pluginObject->pixmapNameConfig(),
00228                                   plugin.pluginObject->pluginName() );
00229             }
00230             // set the order/activate tab
00231             QPixmap icon = Opie::Core::OResource::loadPixmap( plugin.pluginObject->pixmapNameWidget(),
00232                                                               Opie::Core::OResource::SmallIcon );
00233             QCheckListItem * item = new QCheckListItem(m_pluginListView, plugin.pluginObject->pluginName(), QCheckListItem::CheckBox );
00234             if ( !icon.isNull() ) {
00235                 item->setPixmap( 0, icon );
00236             }
00237             if ( m_excludePlugins.find( plugin.name ) == m_excludePlugins.end() ) {
00238                 item->setOn( TRUE );
00239             }
00240             m_plugins[plugin.name] = item;
00241         }
00242 
00243         // set the first tab as default.
00244         m_mainTW->setCurrentTab(m_pluginListWidget);
00245 
00246         // put the number of plugins as the max number of req. auth.
00247         m_generalConfig->m_nbSuccessMin->setMaxValue( pluginList.count() );
00248     }
00249     else
00250     {
00251         /* we don't have any installed plugin there. Let's tell
00252          * that to the user in a third tab, using the m_pluginListWidget widget
00253          */
00254         m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget (no plugins warning)");
00255         QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget);
00256         pluginListLayout->setSpacing(11);
00257         pluginListLayout->setMargin(11);
00258         pluginListLayout->setAlignment( Qt::AlignTop );
00259         QVGroupBox *warningBox = new QVGroupBox(tr("Important notice"), m_pluginListWidget, "noPlugins warning box");
00260         pluginListLayout->addWidget(warningBox);
00261         QLabel * warningText = new QLabel( "<p>" + tr("To be able to protect your PDA with one or more authentication plugins (for example, a simple PIN authentication), you must install at least one <em>opie-securityplugin-*</em> package! Once you have done that, you will be able to configure your PDA protection here.") + "</p>", warningBox );
00262 
00263         m_mainTW->addTab(m_pluginListWidget, "security/Security", tr( "Locking") );
00264 
00265         // set the first tab as default.
00266         m_mainTW->setCurrentTab(m_loginWidget);
00267     }
00268 
00269     showMaximized();
00270 }
00271 
00273 MultiauthConfig::~MultiauthConfig()
00274 {
00275 }
00276 
00278 void MultiauthConfig::writeConfigs() {
00279     MultiauthConfigWidget* confWidget = 0;
00280     for ( confWidget = configWidgetList.first(); confWidget != 0;
00281           confWidget = configWidgetList.next() )
00282         confWidget->writeConfig();
00283 
00284     writeConfig();
00285 }
00286 
00288 void MultiauthConfig::accept() {
00289     writeConfigs();
00290     QDialog::accept();
00291 }
00292 
00293 void MultiauthConfig::done( int r ) {
00294     QDialog::done( r );
00295     close();
00296 }
00297 
00299 void MultiauthConfig::moveSelectedUp()
00300 {
00301     QListViewItem *item = m_pluginListView->selectedItem();
00302     if ( item && item->itemAbove() ) {
00303         item->itemAbove()->moveItem( item );
00304     }
00305 }
00306 
00308 void MultiauthConfig::moveSelectedDown()
00309 {
00310     QListViewItem *item = m_pluginListView->selectedItem();
00311     if ( item && item->itemBelow() ) {
00312         item->moveItem( item->itemBelow() );
00313     }
00314 }
00315 
00317 void MultiauthConfig::readConfig()
00318 {
00319     // pointer, so we release this Config when we want
00320     Config* pcfg = new Config("Security");
00321 
00322     if (m_pluginsInstalled)
00323     {
00324         pcfg->setGroup( "Misc" );
00325         m_generalConfig->m_onStart->setChecked( pcfg->readBoolEntry( "onStart", false ) );
00326         m_generalConfig->m_onResume->setChecked( pcfg->readBoolEntry( "onResume", false ) );
00327         m_generalConfig->m_nbSuccessMin->setValue( pcfg->readNumEntry( "nbSuccessMin", 1 ) );
00328         m_generalConfig->m_noProtectConfig->setChecked( pcfg->readBoolEntry( "noProtectConfig", true) );
00329         m_generalConfig->m_explanScreens->setChecked( pcfg->readBoolEntry( "explanScreens", true ) );
00330 
00331         pcfg->setGroup( "Plugins" );
00332         m_excludePlugins = pcfg->readListEntry( "ExcludePlugins", ',' );
00333         m_allPlugins = pcfg->readListEntry( "AllPlugins", ',' );
00334     }
00335 
00336     /* Login and Sync stuff */
00337     pcfg->setGroup("Sync");
00338     int auth_peer = pcfg->readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
00339     int auth_peer_bits = pcfg->readNumEntry("auth_peer_bits",24);
00340 
00341     pcfg->setGroup("SyncMode");
00342     int mode = pcfg->readNumEntry("Mode",2); // Default to Sharp
00343     switch( mode ) {
00344         case 0x01:
00345             m_syncWidget->syncModeCombo->setCurrentItem( 0 );
00346             break;
00347         case 0x02:
00348         default:
00349             m_syncWidget->syncModeCombo->setCurrentItem( 1 );
00350             break;
00351         case 0x04:
00352             m_syncWidget->syncModeCombo->setCurrentItem( 2 );
00353             break;
00354     }
00355     /*
00356        cfg.setGroup("Remote");
00357        if ( telnetAvailable() )
00358        telnet->setChecked(cfg.readEntry("allow_telnet"));
00359        else
00360        telnet->hide();
00361 
00362        if ( sshAvailable() )
00363        ssh->setChecked(cfg.readEntry("allow_ssh"));
00364        else
00365        ssh->hide();
00366        */
00367 
00368     // release the Config handler
00369     delete pcfg;
00370     // indeed, selectNet will open the config file...
00371     selectNet(auth_peer,auth_peer_bits,TRUE);
00372 
00373     connect( m_syncWidget->syncnet, SIGNAL(textChanged(const QString&)),
00374              this, SLOT(setSyncNet(const QString&)));
00375 
00376 
00377 
00378     QString configFile = QPEApplication::qpeDir() + "etc/opie-login.conf";
00379     Config loginCfg(configFile,Config::File);
00380 
00381     loginCfg.setGroup("General");
00382     autoLoginName=loginCfg.readEntry("AutoLogin","");
00383 
00384     if (autoLoginName.stripWhiteSpace().isEmpty()) {
00385         autoLogin=false;
00386     } else {
00387         autoLogin=true;
00388     }
00389 
00390 
00391     connect(m_loginWidget->autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool)));
00392     connect(m_loginWidget->userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int)));
00393     connect(m_syncWidget->restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults()));
00394     connect(m_syncWidget->deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry()));
00395 
00396     loadUsers();
00397     updateGUI();
00398 
00399 }
00400 
00401 void MultiauthConfig::writeConfig()
00402 {
00403     Config pcfg("Security");
00404 
00405     if (m_pluginsInstalled)
00406     {
00407         pcfg.setGroup( "Plugins" );
00408         QStringList exclude;
00409         QStringList include;
00410         QStringList allPlugins;
00411 
00412         QListViewItemIterator list_it( m_pluginListView );
00413 
00414         // this makes sure the names get saved in the order selected
00415         for ( ; list_it.current(); ++list_it ) {
00416             QMap <QString, QCheckListItem *>::Iterator it;
00417             for ( it = m_plugins.begin(); it != m_plugins. end (); ++it ) {
00418                 if ( list_it.current() == (*it) && !(*it)-> isOn () ) {
00419                     exclude << it.key();
00420                 } else if ( list_it.current() == (*it) && (*it)-> isOn () ){
00421                     include << it.key();
00422                 }
00423                 if ( list_it.current() == (*it) ) {
00424                     allPlugins << it.key();
00425                 }
00426             }
00427         }
00428         pcfg.writeEntry( "ExcludePlugins", exclude, ',' );
00429         pcfg.writeEntry( "IncludePlugins", include, ',' );
00430         pcfg.writeEntry( "AllPlugins",  allPlugins, ',' );
00431 
00432         pcfg.setGroup( "Misc" );
00433         pcfg.writeEntry( "onStart",  m_generalConfig->m_onStart->isChecked() );
00434         pcfg.writeEntry( "onResume",  m_generalConfig->m_onResume->isChecked() );
00435         pcfg.writeEntry( "nbSuccessMin",  m_generalConfig->m_nbSuccessMin->text() );
00436         pcfg.writeEntry( "noProtectConfig",  m_generalConfig->m_noProtectConfig->isChecked() );
00437         pcfg.writeEntry( "explanScreens",  m_generalConfig->m_explanScreens->isChecked() );
00438     }
00439 
00440     /* Login and Sync stuff */
00441 
00442     pcfg.setGroup("Sync");
00443     int auth_peer=0;
00444     int auth_peer_bits;
00445     QString sn = m_syncWidget->syncnet->currentText();
00446     parseNet(sn,auth_peer,auth_peer_bits);
00447 
00448     //this is the *selected* (active) net range
00449     pcfg.writeEntry("auth_peer",auth_peer);
00450     pcfg.writeEntry("auth_peer_bits",auth_peer_bits);
00451 
00452     //write back all other net ranges in *cleartext*
00453     for (int i=0; i<10; i++) {
00454         QString target;
00455         target.sprintf("net%d", i);
00456         if ( i < m_syncWidget->syncnet->count() )
00457             pcfg.writeEntry(target, m_syncWidget->syncnet->text(i));
00458         else // no more entry in the syncnet list -> we clear the line
00459             pcfg.writeEntry(target, "");
00460     }
00461 
00462 #ifdef ODP
00463 #error "Use 0,1,2 and use Launcher"
00464 #endif
00465     /* keep the old code so we don't use currentItem directly */
00466     int value = 0x02;
00467     switch( m_syncWidget->syncModeCombo->currentItem() ) {
00468         case 0:
00469             value = 0x01;
00470             break;
00471         case 1:
00472             value = 0x02;
00473             break;
00474         case 2:
00475             value = 0x04;
00476             break;
00477     }
00478     pcfg.setGroup("SyncMode");
00479     pcfg.writeEntry( "Mode", value );
00480 
00481     /*
00482        pcfg.setGroup("Remote");
00483        if ( telnetAvailable() )
00484        pcfg.writeEntry("allow_telnet",telnet->isChecked());
00485        if ( sshAvailable() )
00486        pcfg.writeEntry("allow_ssh",ssh->isChecked());
00487     // ### write ssh/telnet sys config files
00488     */
00489 
00490     //release the Config handler
00491     pcfg.write();
00492 
00493     QString configFile = QPEApplication::qpeDir() + "etc/opie-login.conf";
00494     Config loginCfg(configFile,Config::File);
00495     loginCfg.setGroup("General");
00496 
00497     if (autoLogin) {
00498         loginCfg.writeEntry("AutoLogin",autoLoginName);
00499     } else {
00500         loginCfg.removeEntry("AutoLogin");
00501     }
00502 
00503 }
00504 
00506 void MultiauthConfig::pluginsChanged() {
00507     m_plugins_changed = true;
00508 }
00509 
00511 void MultiauthConfig::loadPlugins() {
00512 
00513     QString path = QPEApplication::qpeDir() + "plugins/security";
00514     QDir dir( path, "lib*.so" );
00515 
00516     QStringList list = dir.entryList();
00517     QStringList::Iterator it;
00518 
00519     // temporary list used to sort plugins
00520     QMap<QString, MultiauthPlugin> sortList;
00521 
00522     for ( it = list.begin(); it != list.end(); ++it ) {
00523         QInterfacePtr<MultiauthPluginInterface> iface;
00524         QLibrary *lib = new QLibrary( path + "/" + *it );
00525         QString libPath(path + "/" + *it);
00526 
00527         if ( lib->queryInterface( IID_MultiauthPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) {
00528             MultiauthPlugin plugin;
00529             plugin.library = lib;
00530             plugin.iface = iface;
00531             plugin.name = QString(*it);
00532 
00533             // find out if plugins should be launched
00534             if ( m_excludePlugins.grep( *it ).isEmpty() ) {
00535                 plugin.active = true;
00536             } else {
00537                 plugin.active = false;
00538             }
00539 
00540             plugin.pluginObject = plugin.iface->plugin();
00541 
00542             // "prebuffer" it in one more list, to get the sorting done
00543             sortList.insert( plugin.name, plugin );
00544 
00545             // on first start the list is off course empty
00546             if ( m_allPlugins.isEmpty() ) {
00547                 pluginList.append( plugin );
00548             }
00549             // if plugin is not yet in the list, add it to the layout too
00550             else if ( !m_allPlugins.contains( plugin.name ) ) {
00551                 pluginList.append( plugin );
00552             }
00553 
00554         } else {
00555             delete lib;
00556         }
00557 
00558     } // end for
00559 
00560     // put m_allPlugins tempPlugin objects into pluginList
00561     if ( !m_allPlugins.isEmpty() ) {
00562         MultiauthPlugin tempPlugin;
00563         QStringList::Iterator stringit;
00564         for( stringit = m_allPlugins.begin(); stringit !=  m_allPlugins.end(); ++stringit ) {
00565             tempPlugin = ( sortList.find( *stringit ) ).data();
00566             if ( !( (tempPlugin.name).isEmpty() ) ) {
00567                 pluginList.append( tempPlugin );
00568             }
00569         }
00570     }
00571 
00572 }
00573 
00574 void MultiauthConfig::deleteListEntry()
00575 {
00576     m_syncWidget->syncnet->removeItem(m_syncWidget->syncnet->currentItem());
00577 }
00578 
00579 void MultiauthConfig::restoreDefaults()
00580 {
00581     QMessageBox unrecbox(
00582                          tr("Attention"),
00583                          "<p>" + tr("All user-defined net ranges will be lost.") + "</p>",
00584                          QMessageBox::Warning,
00585                          QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
00586                          0, QString::null, TRUE, WStyle_StaysOnTop);
00587     unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
00588     unrecbox.setButtonText(QMessageBox::Yes, tr("OK"));
00589 
00590     if ( unrecbox.exec() == QMessageBox::Yes)
00591     {
00592         m_syncWidget->syncnet->clear();
00593         insertDefaultRanges();
00594     }
00595     m_syncWidget->syncModeCombo->setCurrentItem( 2 );
00596 }
00597 
00598 void MultiauthConfig::insertDefaultRanges()
00599 {
00600     m_syncWidget->syncnet->insertItem( "192.168.129.0/24" );
00601     m_syncWidget->syncnet->insertItem( "192.168.1.0/24" );
00602     m_syncWidget->syncnet->insertItem( "192.168.0.0/16" );
00603     m_syncWidget->syncnet->insertItem( "172.16.0.0/12" );
00604     m_syncWidget->syncnet->insertItem( "10.0.0.0/8" );
00605     m_syncWidget->syncnet->insertItem( "1.0.0.0/8" );
00606     m_syncWidget->syncnet->insertItem( tr( "Any" ) );
00607     m_syncWidget->syncnet->insertItem( tr( "None" ) );
00608 }
00609 
00610 void MultiauthConfig::updateGUI()
00611 {
00612     m_loginWidget->autologinToggle->setChecked(autoLogin);
00613     m_loginWidget->userlist->setEnabled(autoLogin);
00614 }
00615 
00616 void MultiauthConfig::selectNet(int auth_peer,int auth_peer_bits, bool update)
00617 {
00618     QString sn;
00619     if ( auth_peer_bits == 0 && auth_peer == 0 ) {
00620         sn = tr("Any");
00621     } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
00622         sn = tr("None");
00623     } else {
00624         sn =
00625             QString::number((auth_peer>>24)&0xff) + "."
00626             + QString::number((auth_peer>>16)&0xff) + "."
00627             + QString::number((auth_peer>>8)&0xff) + "."
00628             + QString::number((auth_peer>>0)&0xff) + "/"
00629             + QString::number(auth_peer_bits);
00630     }
00631 
00632     //insert user-defined list of netranges upon start
00633     if (update) {
00634         //User selected/active netrange first
00635         m_syncWidget->syncnet->insertItem( tr(sn) );
00636         Config cfg("Security");
00637         cfg.setGroup("Sync");
00638 
00639         //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe
00640         QString test = cfg.readEntry("net0","");
00641         if (test.isEmpty()) {
00642             insertDefaultRanges();
00643         } else {
00644             // 10 ought to be enough for everybody... :)
00645             // If you need more, don't forget to edit applySecurity() as well
00646             bool already_there=FALSE;
00647             for (int i=0; i<10; i++) {
00648                 QString target, netrange;
00649                 target.sprintf("net%d", i);
00650                 netrange = cfg.readEntry(target,"");
00651                 if (! netrange.isEmpty()){
00652                     //make sure we have no "twin" entries
00653                     for (int i=0; i<m_syncWidget->syncnet->count(); i++) {
00654                         if ( m_syncWidget->syncnet->text(i) == netrange ) {
00655                             already_there=TRUE;
00656                         }
00657                     }
00658                     if (! already_there) {
00659                         m_syncWidget->syncnet->insertItem( netrange );
00660                     } else {
00661                         already_there=FALSE;
00662                     }
00663                 }
00664             }
00665         }
00666     }
00667 
00668     for (int i=0; i<m_syncWidget->syncnet->count(); i++) {
00669         if ( m_syncWidget->syncnet->text(i).left(sn.length()) == sn ) {
00670             m_syncWidget->syncnet->setCurrentItem(i);
00671             return;
00672         }
00673     }
00674     odebug << "No match for \"" << sn << "\"" << oendl;
00675 }
00676 
00677 void MultiauthConfig::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
00678 {
00679     auth_peer=0;
00680     if ( sn == tr("Any") ) {
00681         auth_peer = 0;
00682         auth_peer_bits = 0;
00683     } else if ( sn == tr("None") ) {
00684         auth_peer = 0;
00685         auth_peer_bits = 32;
00686     } else {
00687         int x=0;
00688         for (int i=0; i<4; i++) {
00689             int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
00690             auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
00691             x = nx+1;
00692         }
00693         uint n = (uint)sn.find(' ',x)-x;
00694         auth_peer_bits = sn.mid(x,n).toInt();
00695     }
00696 }
00697 
00698 void MultiauthConfig::loadUsers()
00699 {
00700     QFile passwd("/etc/passwd");
00701     if ( passwd.open(IO_ReadOnly) ) {
00702         QTextStream t( &passwd );
00703         QString s;
00704         QStringList account;
00705         while ( !t.eof() ) {
00706             account = QStringList::split(':',t.readLine());
00707             // Hide disabled accounts and some special accounts
00708             if (*account.at(1)!="*" && *account.at(0)!="ppp" && *account.at(0)!="messagebus") {
00709 
00710                 m_loginWidget->userlist->insertItem(*account.at(0));
00711                 // Highlight this item if it is set to m_loginWidget->autologinToggle
00712                 if ( *account.at(0) == autoLoginName)
00713                     m_loginWidget->userlist->setCurrentItem(m_loginWidget->userlist->count()-1);
00714             }
00715         }
00716         passwd.close();
00717     }
00718 
00719 }
00720 
00721 void MultiauthConfig::toggleAutoLogin(bool val)
00722 {
00723     autoLogin=val;
00724     m_loginWidget->userlist->setEnabled(val);
00725     // if autoLogin is true, we will set by default the login currently visible in the userlist
00726     if (autoLogin)
00727         autoLoginName=m_loginWidget->userlist->currentText();
00728 }
00729 
00730 
00731 
00732 
00733 void MultiauthConfig::setSyncNet(const QString& sn)
00734 {
00735     int auth_peer,auth_peer_bits;
00736     parseNet(sn,auth_peer,auth_peer_bits);
00737     selectNet(auth_peer,auth_peer_bits,FALSE);
00738 }
00739 
00740 void MultiauthConfig::changeLoginName( int idx )
00741 {
00742     autoLoginName = m_loginWidget->userlist->text(idx);;
00743     updateGUI();
00744 }
00745 
00747 bool MultiauthConfig::telnetAvailable() const
00748 {
00749     return FALSE;
00750 }
00751 
00753 bool MultiauthConfig::sshAvailable() const
00754 {
00755     return FALSE;
00756 }
00757 

Generated on Sat Nov 5 16:15:58 2005 for OPIE by  doxygen 1.4.2