From 8f215ba9ceb395f262517855a99d7d2d303ca760 Mon Sep 17 00:00:00 2001 From: wimpie Date: Thu, 12 Aug 2004 12:46:55 +0000 Subject: MANY changes - now generates peers/pap-chap secrets files (no chatscript yet) (not all usefull ppp options included yet) - still not ready for prime time yet --- (limited to 'noncore/settings/networksettings2/ppp') diff --git a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui index 826843a..0c5f4c8 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui +++ b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui @@ -11,7 +11,7 @@ 0 0 - 249 + 245 209 @@ -57,11 +57,11 @@ margin - 0 + 3 spacing - 0 + 2 QRadioButton @@ -191,15 +191,54 @@ - QRadioButton + QLayoutWidget name - PapChap_RB - - - text - Pap/Chap/EAP + Layout3 + + + margin + 0 + + + spacing + 6 + + + QRadioButton + + name + Pap_RB + + + text + Pap + + + + QRadioButton + + name + Chap_RB + + + text + Chap + + + + QRadioButton + + name + EAP_RB + + + text + EAP + + + QLayoutWidget @@ -275,9 +314,9 @@ spacing - 1 + 2 - + QLabel name @@ -288,7 +327,7 @@ Server - + QLabel name @@ -299,54 +338,25 @@ Secret - - QComboBox - - - text - PAP - - - - - text - CHAP - - - - - text - EAP - - - - name - AuthMethod_CB - - - - QLabel + + QLineEdit name - TextLabel1 + Server_LE text - Client + * - - QLabel + + QLineEdit name - TextLabel1_4 - - - text - Method + Secret_LE - + QLineEdit name @@ -357,45 +367,17 @@ * - - QLineEdit + + QLabel name - Server_LE + TextLabel1 text - * - - - - QLineEdit - - name - Secret_LE + Client - - - name - Spacer7 - - - orientation - Horizontal - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - @@ -417,7 +399,7 @@ - PapChap_RB + Pap_RB toggled(bool) GroupBox3 setEnabled(bool) @@ -428,5 +410,17 @@ GroupBox1 setEnabled(bool) + + Chap_RB + toggled(bool) + GroupBox3 + setEnabled(bool) + + + EAP_RB + toggled(bool) + GroupBox3 + setEnabled(bool) + diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp index f305cc4..450d560 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp @@ -9,6 +9,13 @@ PPPAuthEdit::PPPAuthEdit( QWidget * Parent ) : PPPAuthGUI( Parent ){ } +bool PPPAuthEdit::PAP_Checked( void ) { + return ( Pap_RB->isChecked() || + Chap_RB->isChecked() || + EAP_RB->isChecked() + ); +} + QString PPPAuthEdit::acceptable( void ) { if( Login_RB->isChecked() ) { if( LoginSend_LE->text().isEmpty() ) @@ -19,7 +26,7 @@ QString PPPAuthEdit::acceptable( void ) { return tr("Password send missing"); if( PasswordExpect_LE->text().isEmpty() ) return tr("Password expect missing"); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { if( Client_LE->text().isEmpty() ) return tr("Pap/Chap/EAP client id missing"); if( Server_LE->text().isEmpty() ) @@ -34,14 +41,13 @@ bool PPPAuthEdit::commit( PPPData_t & D ) { bool SM = 0; if( ( D.Auth.Mode == 0 && ! Login_RB->isChecked() ) || - ( D.Auth.Mode == 1 && ! PapChap_RB->isChecked() ) || + ( D.Auth.Mode == 1 && ! PAP_Checked() ) || ( D.Auth.Mode == 2 && ! Terminal_RB->isChecked() ) ) { // mode modifed SM = 1; D.Auth.Mode = ( Login_RB->isChecked() ) ? 0 : - ( ( PapChap_RB->isChecked() ) ? - 1 : 2 ); + ( PAP_Checked() ) ? 1 : 2; } if( Login_RB->isChecked() ) { @@ -49,11 +55,17 @@ bool PPPAuthEdit::commit( PPPData_t & D ) { TXTM( D.Auth.Login.Send, LoginSend_LE, SM ); TXTM( D.Auth.Password.Expect, PasswordExpect_LE, SM ); TXTM( D.Auth.Password.Send, PasswordSend_LE, SM ); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { TXTM( D.Auth.Client, Client_LE, SM ); TXTM( D.Auth.Server, Server_LE, SM ); TXTM( D.Auth.Secret, Secret_LE, SM ); - CIM( D.Auth.PCEMode, AuthMethod_CB, SM ); + if( Pap_RB->isChecked() ) { + D.Auth.PCEMode = 0; + } else if( Chap_RB->isChecked() ) { + D.Auth.PCEMode = 1; + } else if( EAP_RB->isChecked() ) { + D.Auth.PCEMode = 2; + } } return SM; } @@ -62,13 +74,23 @@ void PPPAuthEdit::showData( PPPData_t & D ) { switch( D.Auth.Mode ) { case 0 : - Login_RB->isChecked(); + Login_RB->setChecked( TRUE ); break; case 1 : - PapChap_RB->isChecked(); + switch( D.Auth.PCEMode ) { + case 0 : + Pap_RB->setChecked( TRUE ); + break; + case 1 : + Chap_RB->setChecked( TRUE ); + break; + case 2 : + EAP_RB->setChecked( TRUE ); + break; + } break; case 2 : - Terminal_RB->isChecked(); + Terminal_RB->setChecked( TRUE ); break; } @@ -80,6 +102,4 @@ void PPPAuthEdit::showData( PPPData_t & D ) { Client_LE->setText( D.Auth.Client ); Server_LE->setText( D.Auth.Server ); Secret_LE->setText( D.Auth.Secret ); - - AuthMethod_CB->setCurrentItem( D.Auth.PCEMode ); } diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.h b/noncore/settings/networksettings2/ppp/PPPAuthedit.h index cbd540e..2392569 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.h +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.h @@ -9,6 +9,8 @@ public : QString acceptable( void ); bool commit( PPPData_t & Data ); void showData( PPPData_t & Data ); + bool PAP_Checked( void ); + private : diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index b7edf87..ff4465c 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,6 +1,10 @@ +#include +#include #include "ppp_NN.h" #include "ppp_NNI.h" +QStringList * PPPNetNode::ProperFiles = 0; + static const char * PPPNeeds[] = { "line", "modem", @@ -11,6 +15,17 @@ static const char * PPPNeeds[] = * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { + + // proper files : will leak + ProperFiles =new QStringList; + *ProperFiles << "peers"; + *ProperFiles << "chatscript"; + + // system files + NSResources->addSystemFile( + "pap-secrets", "/tmp/pap-secrets", 0 ); + NSResources->addSystemFile( + "chap-secrets", "/tmp/chap-secrets", 0 ); } /** @@ -39,15 +54,17 @@ const char * PPPNetNode::provides( void ) { return "connection"; } -bool PPPNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; +QStringList * PPPNetNode::properFiles( void ) { + return ProperFiles; + } -bool PPPNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; +// need to generate : +// /etc/ppp/pap-secrets +// /etc/ppp/pap-secrets +bool PPPNetNode::hasDataForFile( const QString & S ) { + return S == "pap-secrets" || + S == "chap-secrets" ; } QString PPPNetNode::genNic( long NicNr ) { diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h index b1483c4..249be5a 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.h +++ b/noncore/settings/networksettings2/ppp/ppp_NN.h @@ -7,35 +7,32 @@ class APPP; class PPPNetNode : public ANetNode{ - Q_OBJECT + Q_OBJECT public: - PPPNetNode(); - virtual ~PPPNetNode(); + PPPNetNode(); + virtual ~PPPNetNode(); - virtual const QString pixmapName() - { return "Devices/ppp"; } + virtual const QString pixmapName() + { return "Devices/ppp"; } - virtual const QString nodeDescription() ; + virtual bool hasDataForFile( const QString & S ); - virtual ANetNodeInstance * createInstance( void ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - - virtual QString genNic( long NicNr ); + virtual QString genNic( long NicNr ); + virtual QStringList * properFiles( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); + + static QStringList * ProperFiles; }; extern "C" diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index d0fd31c..ba639de 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp @@ -1,3 +1,5 @@ +#include +#include #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" @@ -113,9 +115,107 @@ void APPP::commit( void ) { } } -bool APPP::generateDataForCommonFile( - SystemFile & , - long) { - return 1; +QFile * APPP::openFile( const QString & ID ) { + QFile * F = 0; + QString S; + + if( ID == "peers" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() ); + + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } else if ( ID == "chatscripts" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() + ".chat" ); + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } + if( F ) { + Log(("Generate proper file %s = %s\n", + ID.latin1(), F->name().latin1())); + } + return F; } +short APPP::generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + short rvl, rvd; + + rvl = 1; + rvd = 1; + + if( ID == "pap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if( ID == "chap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { + // used for both EAP and Chap + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if ( ID == "peers" ) { + QFileInfo FI(Path); + Log(("Generate PPP for %s\n", ID.latin1() )); + + TS << "connect \"/usr/sbin/chat -v -f /etc/ppp/" + << FI.baseName() + << ".chat\"" + << endl; + + if( Data.IP.GWIsDefault ) { + TS << "defaultroute" + << endl; + } + + TS << "linkname " + << removeSpaces( ID.latin1() ) + << endl; + + // insert other data here + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } else if ( ID == "chatscripts" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; +} diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.h b/noncore/settings/networksettings2/ppp/ppp_NNI.h index 989c2f0..0bf8fa9 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.h +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.h @@ -7,6 +7,7 @@ class PPPNetNode; class PPPEdit; +class QTextStream; class APPP : public ANetNodeInstance { @@ -14,24 +15,26 @@ public : APPP( PPPNetNode * PNN ); - QWidget * edit( QWidget * parent ); - QString acceptable( void ); - void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) + { if( RT == 0 ) { RT = new PPPRun( this, Data ); + } return RT->runtimeInfo(); } + QWidget * edit( QWidget * parent ); + QString acceptable( void ); + void commit( void ); + virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } + virtual QFile * openFile( const QString & ID ); + short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); -- cgit v0.9.0.2