Revision: 2691
          http://ipcop.svn.sourceforge.net/ipcop/?rev=2691&view=rev
Author:   owes
Date:     2009-04-11 09:36:41 +0000 (Sat, 11 Apr 2009)

Log Message:
-----------
We change profile in 2 places: pppsetup.cgi and rc.connectioncheck
Problem is we do it differently, biggest problem is the use of special 
characters which are filtered out in rc.connectioncheck but work OK for 
pppsetup.cgi

Make profile selection (and rewriting PPP info) a library sub.
Rewrite rc.connectioncheck later to use this.

Modified Paths:
--------------
    ipcop/trunk/html/cgi-bin/pppsetup.cgi
    ipcop/trunk/src/libs/general-functions.pl

Modified: ipcop/trunk/html/cgi-bin/pppsetup.cgi
===================================================================
--- ipcop/trunk/html/cgi-bin/pppsetup.cgi       2009-04-10 23:22:51 UTC (rev 
2690)
+++ ipcop/trunk/html/cgi-bin/pppsetup.cgi       2009-04-11 09:36:41 UTC (rev 
2691)
@@ -25,7 +25,6 @@
 
 our %pppsettings = ();
 my %temppppsettings = ();
-our %modemsettings = ();
 our %isdnsettings  = ();
 our %netsettings   = ();
 my %selected     = ();
@@ -339,9 +338,8 @@
     # write cgi vars to the file.
     &General::writehash("/var/ipcop/ppp/settings-$pppsettings{'PROFILE'}", 
\%pppsettings);
 
-    # make link and write secret file.
-    &updatesettings();
-    &writesecrets();
+    # Activate profile
+    &General::SelectProfile($pppsettings{'PROFILE'});
 
     &General::log("$Lang::tr{'profile saved'}: $pppsettings{'PROFILENAME'}");
     $profilenames[$pppsettings{'PROFILE'}] = $pppsettings{'PROFILENAME'};
@@ -358,9 +356,8 @@
     # need to write default values on disk when profile was empty
     &General::writehash("/var/ipcop/ppp/settings-$profile", \%pppsettings);
 
-    # make link and write corresponding secret
-    &updatesettings();
-    &writesecrets();
+    # Activate profile
+    &General::SelectProfile($profile);
 
     &General::log("$Lang::tr{'profile made current'}: 
$pppsettings{'PROFILENAME'}");
 }
@@ -376,8 +373,8 @@
     &initprofile();
     &General::writehash("/var/ipcop/ppp/settings-$profile", \%pppsettings);
 
-    # make link.
-    &updatesettings();
+    # Activate profile
+    &General::SelectProfile($profile);
     $profilenames[$profile] = $pppsettings{'PROFILENAME'};
 }
 else {
@@ -1258,49 +1255,7 @@
 
 &Header::closepage();
 
-sub updatesettings {
 
-    # make a link from the selected profile to the "default" one.
-    unlink('/var/ipcop/ppp/settings');
-    link("/var/ipcop/ppp/settings-$pppsettings{'PROFILE'}", 
'/var/ipcop/ppp/settings');
-    system('/usr/bin/touch', '/var/ipcop/ppp/updatesettings');
-    if ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
-
-        # eagle-usb.conf is in backup but link DSPcode.bin can't, so the link 
is created in rc.eagleusbadsl
-        open(FILE, ">//var/ipcop/eagle-usb/eagle-usb.conf") or die "Unable to 
write eagle-usb.conf file";
-        flock(FILE, 2);
-
-        # decimal to hexa
-        $modemsettings{'VPI'} = uc(sprintf('%X', $pppsettings{'VPI'}));
-        $modemsettings{'VCI'} = uc(sprintf('%X', $pppsettings{'VCI'}));
-        if ($pppsettings{'PROTOCOL'} eq 'RFC1483') {
-            $modemsettings{'Encapsulation'} = 1 + $pppsettings{'ENCAP'};
-        }
-        elsif ($pppsettings{'PROTOCOL'} eq 'RFC2364') {
-            $modemsettings{'Encapsulation'} = 6 - $pppsettings{'ENCAP'};
-        }
-        print FILE "<eaglectrl>\n";
-        print FILE "VPI=$modemsettings{'VPI'}\n";
-        print FILE "VCI=$modemsettings{'VCI'}\n";
-        print FILE "Encapsulation=$modemsettings{'Encapsulation'}\n";
-        print FILE "Linetype=0A\n";
-        print FILE "RatePollFreq=00000009\n";
-        print FILE "</eaglectrl>\n";
-        close FILE;
-    }
-
-}
-
-sub writesecrets {
-
-    # write secrets file.
-    open(FILE, ">/var/ipcop/ppp/secrets") or die "Unable to write secrets 
file.";
-    flock(FILE, 2);
-    print FILE "'$pppsettings{'USERNAME'}' * '$pppsettings{'PASSWORD'}'\n";
-    chmod 0600, "/var/ipcop/ppp/secrets";
-    close FILE;
-}
-
 sub initprofile {
 
     # if we arrive for the first time, profil 1 is empty

Modified: ipcop/trunk/src/libs/general-functions.pl
===================================================================
--- ipcop/trunk/src/libs/general-functions.pl   2009-04-10 23:22:51 UTC (rev 
2690)
+++ ipcop/trunk/src/libs/general-functions.pl   2009-04-11 09:36:41 UTC (rev 
2691)
@@ -1081,6 +1081,59 @@
     return $speedtouch;
 }
 
+#
+# Make a link from the selected profile to the "default" one.
+# And update the secrets file.
+#
+sub SelectProfile
+{
+    my $profilenr = shift;
+    our %modemsettings = ();
+    our %pppsettings = ();
+
+    die "No such profile: ${profilenr}" unless(-e 
"/var/ipcop/ppp/settings-${profilenr}");
+
+    unlink('/var/ipcop/ppp/settings');
+    link("/var/ipcop/ppp/settings-${profilenr}", '/var/ipcop/ppp/settings');
+    system('/usr/bin/touch', '/var/ipcop/ppp/updatesettings');
+
+    if ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
+
+        # eagle-usb.conf is in backup but link DSPcode.bin can't, so the link 
is created in rc.eagleusbadsl
+        open(FILE, ">//var/ipcop/eagle-usb/eagle-usb.conf") or die "Unable to 
write eagle-usb.conf file";
+        flock(FILE, 2);
+
+        # decimal to hexa
+        $modemsettings{'VPI'} = uc(sprintf('%X', $pppsettings{'VPI'}));
+        $modemsettings{'VCI'} = uc(sprintf('%X', $pppsettings{'VCI'}));
+        if ($pppsettings{'PROTOCOL'} eq 'RFC1483') {
+            $modemsettings{'Encapsulation'} = 1 + $pppsettings{'ENCAP'};
+        }
+        elsif ($pppsettings{'PROTOCOL'} eq 'RFC2364') {
+            $modemsettings{'Encapsulation'} = 6 - $pppsettings{'ENCAP'};
+        }
+        print FILE "<eaglectrl>\n";
+        print FILE "VPI=$modemsettings{'VPI'}\n";
+        print FILE "VCI=$modemsettings{'VCI'}\n";
+        print FILE "Encapsulation=$modemsettings{'Encapsulation'}\n";
+        print FILE "Linetype=0A\n";
+        print FILE "RatePollFreq=00000009\n";
+        print FILE "</eaglectrl>\n";
+        close FILE;
+    }
+
+    # Read pppsettings to be able to write username and password to secrets 
file
+    &General::readhash("/var/ipcop/ppp/settings-${profilenr}", \%pppsettings);
+
+    # Write secrets file
+    open(FILE, ">/var/ipcop/ppp/secrets") or die "Unable to write secrets 
file.";
+    flock(FILE, 2);
+    print FILE "'$pppsettings{'USERNAME'}' * '$pppsettings{'PASSWORD'}'\n";
+    chmod 0600, "/var/ipcop/ppp/secrets";
+    close FILE;
+}
+
+
 sub color_devices()
 {
     my @itfs = ('ORANGE', 'BLUE', 'GREEN', 'RED');


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Ipcop-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to