Revision: 8065 http://sourceforge.net/p/ipcop/svn/8065 Author: owes Date: 2016-01-10 09:26:44 +0000 (Sun, 10 Jan 2016) Log Message: ----------- checkip can sometimes take a long time (upto 120 seconds). Add locking in setddns, add IP storage for index.cgi and friends.
Modified Paths: -------------- ipcop/trunk/src/libs/general-functions.pl ipcop/trunk/src/scripts/setddns.pl ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0 Modified: ipcop/trunk/src/libs/general-functions.pl =================================================================== --- ipcop/trunk/src/libs/general-functions.pl 2016-01-10 09:24:29 UTC (rev 8064) +++ ipcop/trunk/src/libs/general-functions.pl 2016-01-10 09:26:44 UTC (rev 8065) @@ -941,8 +941,14 @@ || &General::IpInSubnet($ip, '100.64.0.0', '255.192.0.0')) { if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') { - my $RealIP = &General::FetchPublicIp; - $ip = (&General::validip($RealIP) ? $RealIP : 'unavailable'); + # Do not fetch internet IP but use stored IP from setddns +# my $RealIP = &General::FetchPublicIp; +# $ip = (&General::validip($RealIP) ? $RealIP : 'unavailable'); + + open(IP, '/var/ipcop/red/internet-ipaddress') or return 'unavailable'; + $ip = <IP>; + close(IP); + chomp $ip; } } return $ip; Modified: ipcop/trunk/src/scripts/setddns.pl =================================================================== --- ipcop/trunk/src/scripts/setddns.pl 2016-01-10 09:24:29 UTC (rev 8064) +++ ipcop/trunk/src/scripts/setddns.pl 2016-01-10 09:26:44 UTC (rev 8065) @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with IPCop. If not, see <http://www.gnu.org/licenses/>. # -# Copyright (c) 2002-2014 The IPCop Team +# Copyright (c) 2002-2016 The IPCop Team # # $Id$ # @@ -24,6 +24,7 @@ use strict; use IO::Socket; use Net::SSLeay; +use Fcntl qw(:flock); require '/usr/lib/ipcop/general-functions.pl'; require '/usr/lib/ipcop/ddns-lib.pl'; @@ -35,10 +36,12 @@ undef (@dummy); #Prototypes functions -sub encode_base64 ($;$); +sub encode_base64($;$); +sub myexit($); my $logDirName = "/var/log/dyndns"; my $id = 0; +my $lockfile; # Delete the logdir before fetching IP or doing anything else if ($ARGV[0] eq '--force') { @@ -55,11 +58,11 @@ if (! -e '/var/ipcop/red/active') { if (($ARGV[0] eq '--cron') || ($ARGV[0] eq '--force')) { # silently exit - exit 0 ; + myexit(0); } print "RED connection is down.\n"; - exit 1; + myexit(1); } my $ip; @@ -69,10 +72,24 @@ chomp $ip; } else { - &General::log('Dynamic DNS failure : unable to open local-ipaddress file.'); - exit 1; + &General::log('Dynamic DNS failure: unable to open local-ipaddress file.'); + myexit(2); } + +unless (open($lockfile, '>', '/var/lock/setddns')) { + &General::log("ERROR in setddns: open lockfile failed"); + myexit(3); +} +unless (flock($lockfile, LOCK_EX | LOCK_NB)) { + # Some other setddns is already running, GUI?, red up? + &General::log("setddns already running, cannot lock"); + # close and undef lockfile to avoid error message in myexit + close($lockfile); + undef($lockfile); + myexit(4); +} + # If IP is reserved network, we are behind a router. May we ask for our real public IP ? if ( &General::IpInSubnet($ip, '10.0.0.0', '255.0.0.0') || &General::IpInSubnet($ip, '172.16.0.0', '255.240.0.0') @@ -89,7 +106,8 @@ &General::readhash("$logDirName/fetchIpState", \%fetchIpState) if (-e "$logDirName/fetchIpState"); if ($ARGV[0] eq '--force') { - $fetchIpState{'BEHINDROUTERWAITLOOP'} = -1; # When forced option, fetch PublicIP now + # When forced option, fetch PublicIP now + $fetchIpState{'BEHINDROUTERWAITLOOP'} = -1; } # Increment counter modulo 4. When it is zero, fetch ip else exit @@ -97,14 +115,15 @@ $fetchIpState{'BEHINDROUTERWAITLOOP'} = ($fetchIpState{'BEHINDROUTERWAITLOOP'} + 1) % 4; &General::writehash("$logDirName/fetchIpState", \%fetchIpState); - exit 0 if ($fetchIpState{'BEHINDROUTERWAITLOOP'} ne 0); + myexit(0) if ($fetchIpState{'BEHINDROUTERWAITLOOP'} ne 0); my $RealIP = &General::FetchPublicIp; $ip = (&General::validip($RealIP) ? $RealIP : 'unavailable'); $fetchIpState{'FETCHED_IP'} = $ip; &General::writehash("$logDirName/fetchIpState", \%fetchIpState); &General::log("Dynamic DNS public router IP is: $ip"); - exit 0 if ($ip eq 'unavailable'); + myexit(0) if ($ip eq 'unavailable'); + system("echo $ip > /var/ipcop/red/internet-ipaddress"); } } @@ -1011,7 +1030,7 @@ unlink("$ipCacheFile.force") if (-e "$ipCacheFile.force"); } } -exit 0; +myexit(0); # Extracted from Base64.pm sub encode_base64 ($;$) { @@ -1034,3 +1053,15 @@ } $res; } + +sub myexit($) +{ + my $retcode = shift; + + if (defined($lockfile)) { + &General::log("ERROR in setddns: unlock failed") unless (flock($lockfile, LOCK_UN)); + close($lockfile); + } + + exit($retcode); +} Modified: ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0 =================================================================== --- ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0 2016-01-10 09:24:29 UTC (rev 8064) +++ ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0 2016-01-10 09:26:44 UTC (rev 8065) @@ -12,6 +12,7 @@ /home/httpd/cgi-bin/remote.cgi /home/httpd/cgi-bin/updates.cgi /home/httpd/cgi-bin/vpnca.cgi +/usr/lib/ipcop/general-functions.pl /usr/lib/ipcop/header.pl /usr/lib/ipcop/vpn-functions.pl /usr/local/bin/accountingctrl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Ipcop-svn mailing list Ipcop-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ipcop-svn