Diffstat (limited to 'noncore/settings/networksettings2/ppp/ppp_NNI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/ppp/ppp_NNI.cpp | 108 |
1 files changed, 104 insertions, 4 deletions
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,24 +1,26 @@ +#include <qfile.h> +#include <qfileinfo.h> #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.DNS.ServerAssigned = 1; Data.DNS.DomainName = ""; Data.Auth.Mode = 0; Data.Auth.Login.Expect = "ogin:"; Data.Auth.Password.Expect = "assword:"; Data.Auth.PCEMode = 0; Data.Auth.Client = "*"; Data.Auth.Server = "*"; Data.Auth.Secret = ""; Data.IP.IPAutomatic = 1; Data.IP.IPAddress = ""; Data.IP.IPSubMask = ""; Data.IP.GWAutomatic = 1; Data.IP.GWAddress = ""; Data.IP.GWIsDefault = 1; GUI = 0; RT = 0; @@ -92,30 +94,128 @@ void APPP::saveSpecificAttribute( QTextStream & TS ) { TS << "ipautomatic=" << ( ( Data.IP.IPAutomatic ) ? "yes" : "no" ) << endl; TS << "gwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; TS << "gwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; TS << "ipaddress=" << Data.IP.IPAddress << endl; TS << "ipsubmask=" << Data.IP.IPSubMask << endl; TS << "gwaddress=" << Data.IP.GWAddress << endl; } QWidget * APPP::edit( QWidget * parent ) { GUI = new PPPEdit( parent ); GUI->showData( Data ); return GUI; } QString APPP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void APPP::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -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; +} |