Monday, November 08, 2010 at 12:06 AM.
system.verbs.builtins.userland.portForward
on portForward (sourcePort=nil, destinationPort=nil, sourceAddr="any", adminPassword="", flSaveAdminPassword=false) { // by Eric Soroos
<<Changes
<<4/11/02; 6:25:37 PM by JES
<<New optional parameters: adminPassword -- the password to use for the sudo command; flSaveAdminPassword -- if true, the password is stored as a binary object in user.prefs.portForwardingAdminPassword.
<<5/8/01; 5:54:54 PM by ES
<<Port forward from secure ports to ones that don't require root access.
<<sudo sysctl -w net.inet.ip.forwarding=1
<<turns on ip forwarding
<<sudo ipfw add 102 fwd 127.0.0.1,2525 tcp from any to any 25 in
<<adds a rule at priority 102 (of 65k) to forward port 25 (mail) to port 2525 on the local machine interface.
<<Only applies to the incoming packet filter.
<<Wed, May 9, 2001 at 10:58:55 AM by ES
<<updated with source addr, dropping privs, and some extra quoted quotes
<<Sat, Jun 2, 2001 at 2:23:44 PM by YNH
<<Get source and destination port from user.inetd.config.http.
if not system.environment.isCarbon {
scriptError ("Can't start port forwarding because it is not supported on this platform.")};
local (resultString = "");
if sourcePort == nil { //PBS 06/02/01: get from user.inetd.config.http.apparentPort
sourcePort = user.inetd.config.http.apparentPort};
if destinationPort == nil { //PBS 06/02/01: get from user.inetd.config.http.port
destinationPort = user.inetd.config.http.port};
if adminPassword == "" {
Frontier.bringToFront ();
if not dialog.getPassword ("Admin password (for port forwarding)?", @adminPassword) {
return (false)}};
resultString = sys.unixShellCommand ("echo \"" +adminPassword + "\" | sudo -S /usr/sbin/sysctl -w net.inet.ip.forwarding=1");
if resultString == "" {
Frontier.bringToFront ();
dialog.alert ("Port forwarding failed.");
return (false)};
resultString = resultString + sys.unixShellCommand ("sudo /sbin/ipfw add 102 fwd 127.0.0.1," + destinationPort + " tcp from any to " + sourceAddr + " " + sourcePort + " in");
resultString = resultString + sys.unixShellCommand ("sudo -K"); // drop our privs Wed, May 9, 2001 at 10:58:11 AM by ES
<<dialog.alert (resultString)
if flSaveAdminPassword {
user.prefs.portForwardingAdminPassword = binary (adminPassword)};
return (true)};
bundle { //test code
portForward ()}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.