diff -Nru old/etc/inc/interfaces.inc new/etc/inc/interfaces.inc
--- old/etc/inc/interfaces.inc	2004-08-22 11:41:15.000000000 +0200
+++ new/etc/inc/interfaces.inc	2004-10-18 20:51:44.000000000 +0200
@@ -431,6 +431,10 @@
 	$wancfg = $config['interfaces']['wan'];
 	$pppoecfg = $config['pppoe'];
 	
+	if (!$pppoecfg['ondemand']) {
+		$pppoecfg['ondemand'] = "disable";
+	}
+
 	/* generate mpd.conf */
 	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
 	if (!$fd) {
@@ -442,9 +446,11 @@
 pppoe:
 	new -i ng0 pppoe pppoe
 	set iface route default
-	set iface disable on-demand
-	set iface idle 0
 	set iface up-script /usr/local/sbin/ppp-linkup
+	set iface down-script /usr/local/sbin/ppp-linkdown
+	set iface {$pppoecfg['ondemand']} on-demand
+	set iface addrs 10.0.0.1 10.0.0.2
+	set iface idle {$pppoecfg['timeout']}
 	set bundle disable multilink
 	set bundle authname "{$pppoecfg['username']}"
 	set bundle password "{$pppoecfg['password']}"
@@ -497,6 +503,10 @@
 	$wancfg = $config['interfaces']['wan'];
 	$pptpcfg = $config['pptp'];
 	
+	if (!$pptpcfg['ondemand']) {
+		$pptpcfg['ondemand'] = "disable";
+	}
+
 	/* generate mpd.conf */
 	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
 	if (!$fd) {
@@ -508,9 +518,11 @@
 pptp:
 	new -i ng0 pptp pptp
 	set iface route default
-	set iface disable on-demand
-	set iface idle 0
 	set iface up-script /usr/local/sbin/ppp-linkup
+	set iface down-script /usr/local/sbin/ppp-linkdown
+	set iface {$pptpcfg['ondemand']} on-demand
+	set iface addrs {$pptpcfg['local']} {$pptpcfg['remote']}
+	set iface idle {$pptpcfg['timeout']}
 	set bundle disable multilink
 	set bundle authname "{$pptpcfg['username']}"
 	set bundle password "{$pptpcfg['password']}"
diff -Nru old/usr/local/sbin/ppp-linkdown new/usr/local/sbin/ppp-linkdown
--- old/usr/local/sbin/ppp-linkdown	1970-01-01 01:00:00.000000000 +0100
+++ new/usr/local/sbin/ppp-linkdown	2004-10-09 18:18:43.000000000 +0200
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# flush entries from NAT table
+/sbin/ipnat -CF
diff -Nru old/usr/local/www/interfaces_wan.php new/usr/local/www/interfaces_wan.php
--- old/usr/local/www/interfaces_wan.php	2004-08-22 11:41:15.000000000 +0200
+++ new/usr/local/www/interfaces_wan.php	2004-10-18 21:02:45.000000000 +0200
@@ -37,12 +37,16 @@
 $pconfig['username'] = $config['pppoe']['username'];
 $pconfig['password'] = $config['pppoe']['password'];
 $pconfig['provider'] = $config['pppoe']['provider'];
+$pconfig['pppoe_dialondemand'] = $config['pppoe']['ondemand'];
+$pconfig['pppoe_idletimeout'] = $config['pppoe']['timeout'];
 
 $pconfig['pptp_username'] = $config['pptp']['username'];
 $pconfig['pptp_password'] = $config['pptp']['password'];
 $pconfig['pptp_local'] = $config['pptp']['local'];
 $pconfig['pptp_subnet'] = $config['pptp']['subnet'];
 $pconfig['pptp_remote'] = $config['pptp']['remote'];
+$pconfig['pptp_dialondemand'] = $config['pptp']['ondemand'];
+$pconfig['pptp_idletimeout'] = $config['pptp']['timeout'];
 
 $pconfig['bigpond_username'] = $config['bigpond']['username'];
 $pconfig['bigpond_password'] = $config['bigpond']['password'];
@@ -88,12 +92,22 @@
 		$reqdfieldsn = explode(",", "IP address,Subnet bit count,Gateway");
 		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
 	} else if ($_POST['type'] == "PPPoE") {
-		$reqdfields = explode(" ", "username password");
-		$reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
+		if ($_POST['pppoe_dialondemand']) {
+			$reqdfields = explode(" ", "username password pppoe_dialondemand pppoe_idletimeout");
+			$reqdfieldsn = explode(",", "PPPoE username,PPPoE password,Dial On Demand,Idle Timeout Value");
+		} else {
+			$reqdfields = explode(" ", "username password");
+			$reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
+		}
 		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
 	} else if ($_POST['type'] == "PPTP") {
-		$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
-		$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
+		if ($_POST['pptp_dialondemand']) {
+			$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
+			$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address,Dial On Demand,Idle Timeout Value");
+		} else {
+			$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
+			$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
+		}
 		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
 	} else if ($_POST['type'] == "BigPond") {
 		$reqdfields = explode(" ", "bigpond_username bigpond_password");
@@ -113,6 +127,9 @@
 	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
 		$input_errors[] = "The service name contains invalid characters.";
 	}
+	if ($_POST['pppoe_idletimeout'] && !is_numericint($_POST['pppoe_idletimeout'])) {
+		$input_errors[] = "The Idle Timeout Value must be an integer.";
+	}
 	if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local']))) {
 		$input_errors[] = "A valid PPTP local IP address must be specified.";
 	}
@@ -122,6 +139,9 @@
 	if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote']))) {
 		$input_errors[] = "A valid PPTP remote IP address must be specified.";
 	}
+	if ($_POST['pptp_idletimeout'] && !is_numericint($_POST['pptp_idletimeout'])) {
+		$input_errors[] = "The Idle Timeout Value must be an integer.";
+	}
 	if (($_POST['bigpond_authserver'] && !is_domain($_POST['bigpond_authserver']))) {
 		$input_errors[] = "The authentication server name contains invalid characters.";
 	}
@@ -155,11 +175,15 @@
 		unset($config['pppoe']['username']);
 		unset($config['pppoe']['password']);
 		unset($config['pppoe']['provider']);
+		unset($config['pppoe']['ondemand']);
+		unset($config['pppoe']['timeout']);
 		unset($config['pptp']['username']);
 		unset($config['pptp']['password']);
 		unset($config['pptp']['local']);
 		unset($config['pptp']['subnet']);
 		unset($config['pptp']['remote']);
+		unset($config['pptp']['ondemand']);
+		unset($config['pptp']['timeout']);
 		unset($config['bigpond']['username']);
 		unset($config['bigpond']['password']);
 		unset($config['bigpond']['authserver']);
@@ -178,6 +202,8 @@
 			$config['pppoe']['username'] = $_POST['username'];
 			$config['pppoe']['password'] = $_POST['password'];
 			$config['pppoe']['provider'] = $_POST['provider'];
+			$config['pppoe']['ondemand'] = $_POST['pppoe_dialondemand'];
+			$config['pppoe']['timeout'] = $_POST['pppoe_idletimeout'];
 		} else if ($_POST['type'] == "PPTP") {
 			$wancfg['ipaddr'] = "pptp";
 			$config['pptp']['username'] = $_POST['pptp_username'];
@@ -185,6 +211,8 @@
 			$config['pptp']['local'] = $_POST['pptp_local'];
 			$config['pptp']['subnet'] = $_POST['pptp_subnet'];
 			$config['pptp']['remote'] = $_POST['pptp_remote'];
+			$config['pptp']['ondemand'] = $_POST['pptp_dialondemand'];
+			$config['pptp']['timeout'] = $_POST['pptp_idletimeout'];
 		} else if ($_POST['type'] == "BigPond") {
 			$wancfg['ipaddr'] = "bigpond";
 			$config['bigpond']['username'] = $_POST['bigpond_username'];
@@ -218,12 +246,32 @@
 <link href="gui.css" rel="stylesheet" type="text/css">
 <script language="JavaScript">
 <!--
-function type_change() {
+function enable_change(enable_change) {
+	if (document.iform.pppoe_dialondemand.checked || enable_change) {
+		document.iform.pppoe_idletimeout.disabled = 0;
+        } else {
+		document.iform.pppoe_idletimeout.disabled = 1;
+        }
+}
+
+function enable_change_pptp(enable_change_pptp) {
+	if (document.iform.pptp_dialondemand.checked || enable_change_pptp) {
+		document.iform.pptp_idletimeout.disabled = 0;
+		document.iform.pptp_local.disabled = 0;
+		document.iform.pptp_remote.disabled = 0;
+        } else {
+		document.iform.pptp_idletimeout.disabled = 1;
+        }
+}
+
+function type_change(enable_change,enable_change_pptp) {
 	switch (document.iform.type.selectedIndex) {
 		case 0:
 			document.iform.username.disabled = 1;
 			document.iform.password.disabled = 1;
 			document.iform.provider.disabled = 1;
+			document.iform.pppoe_dialondemand.disabled = 1;
+			document.iform.pppoe_idletimeout.disabled = 1;
 			document.iform.ipaddr.disabled = 0;
 			document.iform.subnet.disabled = 0;
 			document.iform.gateway.disabled = 0;
@@ -232,6 +280,8 @@
 			document.iform.pptp_local.disabled = 1;
 			document.iform.pptp_subnet.disabled = 1;
 			document.iform.pptp_remote.disabled = 1;
+			document.iform.pptp_dialondemand.disabled = 1;
+			document.iform.pptp_idletimeout.disabled = 1;
 			document.iform.bigpond_username.disabled = 1;
 			document.iform.bigpond_password.disabled = 1;
 			document.iform.bigpond_authserver.disabled = 1;
@@ -243,6 +293,8 @@
 			document.iform.username.disabled = 1;
 			document.iform.password.disabled = 1;
 			document.iform.provider.disabled = 1;
+			document.iform.pppoe_dialondemand.disabled = 1;
+			document.iform.pppoe_idletimeout.disabled = 1;
 			document.iform.ipaddr.disabled = 1;
 			document.iform.subnet.disabled = 1;
 			document.iform.gateway.disabled = 1;
@@ -251,6 +303,8 @@
 			document.iform.pptp_local.disabled = 1;
 			document.iform.pptp_subnet.disabled = 1;
 			document.iform.pptp_remote.disabled = 1;
+			document.iform.pptp_dialondemand.disabled = 1;
+			document.iform.pptp_idletimeout.disabled = 1;
 			document.iform.bigpond_username.disabled = 1;
 			document.iform.bigpond_password.disabled = 1;
 			document.iform.bigpond_authserver.disabled = 1;
@@ -262,6 +316,12 @@
 			document.iform.username.disabled = 0;
 			document.iform.password.disabled = 0;
 			document.iform.provider.disabled = 0;
+			document.iform.pppoe_dialondemand.disabled = 0;
+			if (document.iform.pppoe_dialondemand.checked || enable_change) {
+				document.iform.pppoe_idletimeout.disabled = 0;
+			} else {
+				document.iform.pppoe_idletimeout.disabled = 1;
+			}
 			document.iform.ipaddr.disabled = 1;
 			document.iform.subnet.disabled = 1;
 			document.iform.gateway.disabled = 1;
@@ -270,6 +330,8 @@
 			document.iform.pptp_local.disabled = 1;
 			document.iform.pptp_subnet.disabled = 1;
 			document.iform.pptp_remote.disabled = 1;
+			document.iform.pptp_dialondemand.disabled = 1;
+			document.iform.pptp_idletimeout.disabled = 1;
 			document.iform.bigpond_username.disabled = 1;
 			document.iform.bigpond_password.disabled = 1;
 			document.iform.bigpond_authserver.disabled = 1;
@@ -281,6 +343,8 @@
 			document.iform.username.disabled = 1;
 			document.iform.password.disabled = 1;
 			document.iform.provider.disabled = 1;
+			document.iform.pppoe_dialondemand.disabled = 1;
+			document.iform.pppoe_idletimeout.disabled = 1;
 			document.iform.ipaddr.disabled = 1;
 			document.iform.subnet.disabled = 1;
 			document.iform.gateway.disabled = 1;
@@ -289,6 +353,12 @@
 			document.iform.pptp_local.disabled = 0;
 			document.iform.pptp_subnet.disabled = 0;
 			document.iform.pptp_remote.disabled = 0;
+			document.iform.pptp_dialondemand.disabled = 0;
+			if (document.iform.pptp_dialondemand.checked || enable_change_pptp) {
+				document.iform.pptp_idletimeout.disabled = 0;
+			} else {
+				document.iform.pptp_idletimeout.disabled = 1;
+			}
 			document.iform.bigpond_username.disabled = 1;
 			document.iform.bigpond_password.disabled = 1;
 			document.iform.bigpond_authserver.disabled = 1;
@@ -300,6 +370,8 @@
 			document.iform.username.disabled = 1;
 			document.iform.password.disabled = 1;
 			document.iform.provider.disabled = 1;
+			document.iform.pppoe_dialondemand.disabled = 1;
+			document.iform.pppoe_idletimeout.disabled = 1;
 			document.iform.ipaddr.disabled = 1;
 			document.iform.subnet.disabled = 1;
 			document.iform.gateway.disabled = 1;
@@ -308,6 +380,8 @@
 			document.iform.pptp_local.disabled = 1;
 			document.iform.pptp_subnet.disabled = 1;
 			document.iform.pptp_remote.disabled = 1;
+			document.iform.pptp_dialondemand.disabled = 1;
+			document.iform.pptp_idletimeout.disabled = 1;
 			document.iform.bigpond_username.disabled = 0;
 			document.iform.bigpond_password.disabled = 0;
 			document.iform.bigpond_authserver.disabled = 0;
@@ -425,6 +499,19 @@
                     empty</span></td>
                 </tr>
                 <tr> 
+                  <td valign="top" class="vncell">Dial on demand</td>
+                  <td class="vtable"><input name="pppoe_dialondemand" type="checkbox" id="pppoe_dialondemand" value="enable" <?php if ($pconfig['pppoe_dialondemand'] == "enable") echo "checked"; ?> onClick="enable_change(false)" > 
+                    <strong>Enable Dial-On-Demand mode</strong><br>
+		    This option causes the interface to operate in dial-on-demand mode, allowing you to have a <i>virtual full time</i> connection. An OPEN event causes the interface to be configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected. Moreover, after an idle timeout, the interface is not brought down; further traffic will bring the link back up again.</td>
+                </tr>
+                <tr>
+                  <td valign="top" class="vncell">Idle Timeout Value</td>
+                  <td class="vtable">
+                    <input name="pppoe_idletimeout" type="text" class="formfld" id="pppoe_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pppoe_idletimeout']);?>">
+                    seconds<br>
+    If no qualifying outgoing packets are transmitted for <i>seconds</i> seconds, the connection is brought down. An idle timeout of zero disables this feature.</td>
+                </tr>
+                <tr> 
                   <td colspan="2" valign="top" height="16"></td>
                 </tr>
                 <tr> 
@@ -457,7 +544,20 @@
                   <td class="vtable"> <input name="pptp_remote" type="text" class="formfld" id="pptp_remote" size="20" value="<?=htmlspecialchars($pconfig['pptp_remote']);?>"> 
                   </td>
                 </tr>
-				<tr> 
+                <tr> 
+                  <td valign="top" class="vncell">Dial on demand</td>
+                  <td class="vtable"><input name="pptp_dialondemand" type="checkbox" id="pptp_dialondemand" value="enable" <?php if ($pconfig['pptp_dialondemand'] == "enable") echo "checked"; ?> onClick="enable_change_pptp(false)" > 
+                    <strong>Enable Dial-On-Demand mode</strong><br>
+		    This option causes the interface to operate in dial-on-demand mode, allowing you to have a <i>virtual full time</i> connection. An OPEN event causes the interface to be configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected. Moreover, after an idle timeout, the interface is not brought down; further traffic will bring the link back up again.</td>
+                </tr>
+                <tr>
+                  <td valign="top" class="vncell">Idle Timeout Value</td>
+                  <td class="vtable">
+                    <input name="pptp_idletimeout" type="text" class="formfld" id="pptp_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pptp_idletimeout']);?>">
+                    seconds<br>
+    If no qualifying outgoing packets are transmitted for <i>seconds</i> seconds, the connection is brought down. An idle timeout of zero disables this feature.</td>
+                </tr>
+                <tr> 
                   <td colspan="2" valign="top" height="16"></td>
                 </tr>
                 <tr> 
@@ -515,7 +615,7 @@
                 </tr>
                 <tr> 
                   <td width="100" valign="top">&nbsp;</td>
-                  <td> &nbsp;<br> <input name="Submit" type="submit" class="formbtn" value="Save"> 
+                  <td> &nbsp;<br> <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change_pptp(true)&&enable_change(true)"> 
                   </td>
                 </tr>
               </table>
diff -Nru old/usr/local/www/status_interfaces.php new/usr/local/www/status_interfaces.php
--- old/usr/local/www/status_interfaces.php	2004-08-22 11:41:15.000000000 +0200
+++ new/usr/local/www/status_interfaces.php	2004-10-18 20:37:22.000000000 +0200
@@ -132,6 +132,33 @@
 					$ifinfo['macaddr'] = $matches[1];
 				}
 			}
+
+			/* get pppoe link status for dial on demand */
+			unset($ifconfiginfo);
+			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
+
+			$ifinfo['pppoelink'] = "up";
+
+			foreach ($ifconfiginfo as $ici) {
+				if (strpos($ici, 'LINK0')!==false) {
+					$ifinfo['pppoelink'] = "down";
+				}
+			}
+		}
+
+		/* get ppptp link status for dial on demand */
+		if (($ifdescr == "wan") && ($config['interfaces']['wan']['ipaddr'] == "pptp")) {
+			
+			unset($ifconfiginfo);
+			exec("/sbin/ifconfig " . $ifinfo['if'], $ifconfiginfo);
+
+			$ifinfo['pptplink'] = "up";
+
+			foreach ($ifconfiginfo as $ici) {
+				if (strpos($ici, 'LINK0')!==false) {
+					$ifinfo['pptplink'] = "down";
+				}
+			}
 		}
 	}
 	
@@ -175,7 +202,19 @@
                 <td width="78%" class="listr"> 
                   <?=htmlspecialchars($ifinfo['status']);?>
                 </td>
-              </tr><?php if ($ifinfo['macaddr']): ?>
+              </tr><?php if ($ifinfo['pppoelink']): ?>
+              <tr> 
+                <td width="22%" class="listhdrr">PPPoE</td>
+                <td width="78%" class="listr"> 
+                  <?=htmlspecialchars($ifinfo['pppoelink']);?>
+                </td>
+              </tr><?php  endif; if ($ifinfo['pptplink']): ?>
+              <tr> 
+                <td width="22%" class="listhdrr">PPTP</td>
+                <td width="78%" class="listr"> 
+                  <?=htmlspecialchars($ifinfo['pptplink']);?>
+                </td>
+              </tr><?php  endif; if ($ifinfo['macaddr']): ?>
               <tr> 
                 <td width="22%" class="listhdrr">MAC address</td>
                 <td width="78%" class="listr"> 
