00001 #include "multiauthplugininterface.h"
00002 #include "multiauthcommon.h"
00003
00004
00005 #include <opie2/odebug.h>
00006 #include <opie2/oapplication.h>
00007 #include <opie2/ocontactaccessbackend_vcard.h>
00008 #include <opie2/ocontactaccess.h>
00009
00010
00011 #include <qpe/qpeapplication.h>
00012 #include <qpe/qlibrary.h>
00013 #include <qpe/qcom.h>
00014 #include <qtextview.h>
00015 #include <qdir.h>
00016
00017
00018 #include <unistd.h>
00019 #include <qpe/config.h>
00020
00021 namespace Opie {
00022 namespace Security {
00023
00024 SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, const QString& c,
00025 bool modal, bool fullscreen = FALSE )
00026 : QDialog( parent, name, modal,
00027 fullscreen ?
00028 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
00029 {
00030 if ( fullscreen ) {
00031 QRect desk = qApp->desktop()->geometry();
00032 setGeometry( 0, 0, desk.width(), desk.height() );
00033 }
00034
00035 QString text("<H3>" + tr("Please contact the owner (directions follow), or try again clicking of this screen (and waiting for the penalty time) if you are the legitimate owner") + "</H3>");
00036 text += c;
00037 tv = new QTextView(this);
00038 tv->setText(text);
00039
00040 tv->viewport()->installEventFilter(this);
00041 }
00042
00043 void SecOwnerDlg::resizeEvent( QResizeEvent * )
00044 {
00045 tv->resize( size() );
00046 }
00047
00048 bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e)
00049 {
00050 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
00051 accept();
00052 return TRUE;
00053 }
00054 return QWidget::eventFilter(o, e);
00055 }
00056
00057 void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); }
00058
00059
00060 namespace Internal {
00062 int runPlugins() {
00063
00064 SecOwnerDlg *oi = 0;
00065
00066 QString vfilename = Global::applicationFileName("addressbook",
00067 "businesscard.vcf");
00068 Opie::OPimContactAccess acc( "multiauth", vfilename,
00069 new Opie::OPimContactAccessBackend_VCard( "multiauth", vfilename ) );
00070 if ( acc.load() ) {
00071 Opie::OPimContact contact = acc.allRecords()[0];
00072 if ( !contact.isEmpty() )
00073 oi = new SecOwnerDlg(0, 0, contact.toRichText(), TRUE, TRUE);
00074 }
00075
00076 Config config("Security");
00077 config.setGroup("Plugins");
00078 QStringList plugins = config.readListEntry("IncludePlugins", ',');
00079
00080
00081
00082 if (plugins.isEmpty() == true) {
00083 owarn << "No authentication plugin has been configured yet!" << oendl;
00084 odebug << "Letting the user in..." << oendl;
00085 if(oi) delete oi;
00086 return 0;
00087 }
00088 config.setGroup("Misc");
00089 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1);
00090 int nbSuccess = 0;
00091
00092
00093
00094
00095 QString path = QPEApplication::qpeDir() + "plugins/security";
00096 QStringList::Iterator libIt;
00097
00098 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) {
00099 QInterfacePtr<MultiauthPluginInterface> iface;
00100 QLibrary *lib = new QLibrary( path + "/" + *libIt );
00101
00102 if ( lib->queryInterface(
00103 IID_MultiauthPluginInterface,
00104 (QUnknownInterface**)&iface ) == QS_OK )
00105 {
00106
00107 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl;
00108 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl;
00109
00110 int resultCode;
00111 int tries = 0;
00112
00113
00114 resultCode = iface->plugin()->authenticate();
00115
00116
00117 QString resultMessage;
00118 switch (resultCode)
00119 {
00120 case MultiauthPluginObject::Success:
00121 resultMessage = "Success!";
00122 nbSuccess++;
00123 break;
00124 case MultiauthPluginObject::Failure:
00125 resultMessage = "Failure...";
00126 break;
00127 case MultiauthPluginObject::Skip:
00128 resultMessage = "Skip";
00129 break;
00130 }
00131 odebug << "Plugin result: " << resultMessage << oendl;
00132
00133
00134 while (resultCode == MultiauthPluginObject::Failure)
00135 {
00136 tries++;
00137 owarn << "This plugin has failed " << tries << " times already" << oendl;
00138
00139
00140 if (oi)
00141 {
00142 oi->exec();
00143 odebug << "Contact information displayed" << oendl;
00144 }
00145
00148 sleep(2 * tries);
00149
00150 if (oi)
00151 {
00152 oi->hide();
00157 odebug << "Contact information hidden" << oendl;
00158 }
00159
00160
00161 resultCode = iface->plugin()->authenticate();
00162
00163
00164 switch (resultCode)
00165 {
00166 case MultiauthPluginObject::Success:
00167 resultMessage = "Success!";
00168 nbSuccess++;
00169 break;
00170 case MultiauthPluginObject::Failure:
00171 resultMessage = "Failure...";
00172 break;
00173 case MultiauthPluginObject::Skip:
00174 resultMessage = "Skip";
00175 break;
00176 }
00177 odebug << "Plugin result: " << resultMessage << oendl;
00178 }
00179 delete lib;
00180
00181 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin)
00182 {
00183 if(oi) delete oi;
00184
00185 return 0;
00186 }
00187 } else {
00188 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl;
00189 delete lib;
00190 }
00191 }
00192 delete oi;
00193 return 1;
00194 }
00195
00196 }
00197 }
00198 }