Project

General

Profile

« Previous | Next » 

Revision 67ee1ec5

Added by Ermal Luçi almost 17 years ago

  • Merge multiple PPPoE/PPTP interfaces from RELENG_1_MULTI_ANYTHING
  • Much improved rule generation speed
  • Many bug fixing in general of the interface handling

NOTE: this is only half part of the changes the other half will come after

View differences:

etc/inc/services.inc
461 461
		echo "services_dyndns_reset() being called $mt\n";
462 462
	}
463 463

  
464
	if (file_exists("{$g['vardb_path']}/ez-ipupdate.cache")) {
464
	if (file_exists("{$g['vardb_path']}/ez-ipupdate*.cache")) {
465 465
		conf_mount_rw();
466
		unlink("{$g['vardb_path']}/ez-ipupdate.cache");
466
		unlink("{$g['vardb_path']}/ez-ipupdate*.cache");
467 467
		conf_mount_ro();
468 468
	}
469 469

  
470
	if (file_exists("{$g['conf_path']}/ez-ipupdate.cache")) {
470
	if (file_exists("{$g['conf_path']}/ez-ipupdate*.cache")) {
471 471
		conf_mount_rw();
472
		unlink("{$g['conf_path']}/ez-ipupdate.cache");
472
		unlink("{$g['conf_path']}/ez-ipupdate*.cache");
473 473
		conf_mount_ro();
474 474
	}
475 475
	
476
	if (file_exists("{$g['conf_path']}/dyndns.cache")) {
476
	if (file_exists("{$g['conf_path']}/dyndns*.cache")) {
477 477
		conf_mount_rw();
478
		unlink("{$g['conf_path']}/dyndns.cache");
478
		unlink("{$g['conf_path']}/dyndns*.cache");
479 479
		conf_mount_ro();
480 480
	}
481 481

  
......
489 489
		echo "services_dyndns_configure() being called $mt\n";
490 490
	}
491 491

  
492
	$dyndnscfg = $config['dyndns'];
493
	$wancfg = $config['interfaces']['wan'];
494

  
495
	if (isset($dyndnscfg['enable'])) {
496

  
497
		if ($g['booting']) {
498
			echo "Starting DynDNS client...";
499
			if(isset($config['system']['use_old_dyndns'])) {
500
				echo " [Using ez-ipupdate] ";
501
				services_dyndns_configure_old();
502
				return;
503
			}
504
		} else {
505
			sleep(1);
506
			if(isset($config['system']['use_old_dyndns'])) {
507
				services_dyndns_configure_old();
508
				return;
492
	$dyndnscfg = $config['dyndnses']['dyndns'];
493

  
494
	if (is_array($dyndnscfg)) {
495
		foreach ($dyndnscfg as $dyndns) {
496
			if (!isset($dyndns['enable']))
497
				continue;
498
			/* determine interface name */
499
			if ($dyndns['interface'] == "wan")
500
				$if = get_real_wan_interface();
501
			else
502
				$if = convert_friendly_interface_to_real_interface_name($dyndns['interface']);
503

  
504
			if ($g['booting']) {
505
				echo "Starting DynDNS clients...";
506
				if (isset($config['system']['use_old_dyndns'])) {
507
					echo " [Using ez-ipupdate] ";
508
					services_dyndns_configure_old($if);
509
					continue;
510
				}
511
			} else {
512
				sleep(1);
513
				if (isset($config['system']['use_old_dyndns'])) {
514
					services_dyndns_configure_old($if);
515
					continue;
516
				}
509 517
			}
510
		}
511 518

  
512
		/* load up the dyndns.class */
513
		require_once("dyndns.class");
519
			/* load up the dyndns.class */
520
			require_once("dyndns.class");
514 521

  
515
		log_error("DynDns: Running updatedns()");
522
			log_error("DynDns: Running updatedns()");
516 523

  
517
		/* determine WAN interface name */
518
		$wanif = get_real_wan_interface();
519
		/* get ip */
520
		$ip = find_interface_ip($wanif);
524
			
525
			/* get ip */
526
			$ip = find_interface_ip($if);
521 527

  
522
		$dns = new updatedns($dnsService = $config['dyndns']['type'],
523
							 $dnsHost = $config['dyndns']['host'],
524
							 $dnsUser = $config['dyndns']['username'],
525
							 $dnsPass = $config['dyndns']['password'],
526
							 $dnsWilcard = $config['dyndns']['wildcard'],
527
							 $dnsMX = $config['dyndns']['mx']);
528
			$dns = new updatedns($dnsService = $dyndns['type'],
529
							 $dnsHost = $dyndns['host'],
530
							 $dnsUser = $dyndns['username'],
531
							 $dnsPass = $dyndns['password'],
532
							 $dnsWilcard = $dyndns['wildcard'],
533
							 $dnsMX = $dyndns['mx'], $dnsIf = $if);
534

  
535
		}
528 536

  
529 537
		if ($g['booting'])
530 538
			echo "done.\n";
......
533 541
	return 0;
534 542
}
535 543

  
536
function services_dyndns_configure_old() {
544
function services_dyndns_configure_old($if) {
537 545
	global $config, $g;
538 546
	if(isset($config['system']['developerspew'])) {
539 547
		$mt = microtime();
......
542 550

  
543 551
        /* kill any running ez-ipupdate */
544 552
        /* ez-ipupdate needs SIGQUIT instead of SIGTERM */
545
        sigkillbypid("{$g['varrun_path']}/ez-ipupdate.pid", "QUIT");
553
        sigkillbypid("{$g['varrun_path']}/ez-ipupdate_{$if}.pid", "QUIT");
546 554

  
547
        $dyndnscfg = $config['dyndns'];
555
        $dyndnscfg = $config['dyndnses']['dyndns'];
548 556
        $wancfg = $config['interfaces']['wan'];
549 557

  
550
        if (isset($dyndnscfg['enable'])) {
551

  
552
                if ($g['booting'])
553
                        echo "Starting DynDNS client...";
554
                else
555
                        sleep(1);
556

  
557
                /* determine WAN interface name */
558
                $wanif = get_real_wan_interface();
558
                sleep(1);
559 559

  
560 560
                /* write ez-ipupdate.conf */
561
                $fd = fopen("{$g['varetc_path']}/ez-ipupdate.conf", "w");
561
                $fd = fopen("{$g['varetc_path']}/ez-ipupdate_{$if}.conf", "w");
562 562
                if (!$fd) {
563
                        printf("Error: cannot open ez-ipupdate.conf in services_dyndns_configure().\n");
563
                        printf("Error: cannot open ez-ipupdate_{$if}.conf in services_dyndns_configure().\n");
564 564
                        return 1;
565 565
                }
566 566

  
567 567
                $ezipupdateconf = <<<EOD
568
service-type={$dyndnscfg['type']}
569
user={$dyndnscfg['username']}:{$dyndnscfg['password']}
570
host={$dyndnscfg['host']}
571
interface={$wanif}
568
service-type={$dyndns['type']}
569
user={$dyndns['username']}:{$dyndns['password']}
570
host={$dyndns['host']}
571
interface={$if}
572 572
max-interval=2073600
573
pid-file={$g['varrun_path']}/ez-ipupdate.pid
574
cache-file={$g['vardb_path']}/ez-ipupdate.cache
575
execute=/etc/rc.dyndns.storecache
573
pid-file={$g['varrun_path']}/ez-ipupdate_{$if}.pid
574
cache-file={$g['vardb_path']}/ez-ipupdate_{$if}.cache
575
execute=/etc/rc.dyndns.storecache {$g['vardb_path']}/ez-ipupdate_{$if}.cache
576 576
daemon
577 577

  
578 578
EOD;
579 579

  
580 580
                /* enable server[:port]? */
581
                if ($dyndnscfg['server']) {
582
                        if ($dyndnscfg['port'])
583
                                $ezipupdateconf .= "server={$dyndnscfg['server']}:{$dyndnscfg['port']}\n";
581
                if ($dyndns['server']) {
582
                        if ($dyndns['port'])
583
                                $ezipupdateconf .= "server={$dyndns['server']}:{$dyndns['port']}\n";
584 584
                        else
585
                                $ezipupdateconf .= "server={$dyndnscfg['server']}\n";
585
                                $ezipupdateconf .= "server={$dyndns['server']}\n";
586 586
                }
587 587

  
588 588
                /* enable MX? */
589
                if ($dyndnscfg['mx']) {
590
                        $ezipupdateconf .= "mx={$dyndnscfg['mx']}\n";
589
                if ($dyndns['mx']) {
590
                        $ezipupdateconf .= "mx={$dyndns['mx']}\n";
591 591
                }
592 592

  
593 593
                /* enable wildcards? */
594
                if (isset($dyndnscfg['wildcard'])) {
594
                if (isset($dyndns['wildcard'])) {
595 595
                        $ezipupdateconf .= "wildcard\n";
596 596
                }
597 597

  
......
600 600

  
601 601
                /* if we're booting, copy the cache file from /conf */
602 602
                if ($g['booting']) {
603
                        if (file_exists("{$g['conf_path']}/ez-ipupdate.cache")) {
604
                                copy("{$g['conf_path']}/ez-ipupdate.cache", "{$g['vardb_path']}/ez-ipupdate.cache");
603
                        if (file_exists("{$g['conf_path']}/ez-ipupdate_{$if}.cache")) {
604
                                copy("{$g['conf_path']}/ez-ipupdate_{$if}.cache", "{$g['vardb_path']}/ez-ipupdate_{$if}.cache");
605 605
                       }
606 606
                }
607 607

  
608 608
                /* run ez-ipupdate */
609
                mwexec("/usr/local/bin/ez-ipupdate -c {$g['varetc_path']}/ez-ipupdate.conf");
609
                mwexec("/usr/local/bin/ez-ipupdate -c {$g['varetc_path']}/ez-ipupdate_{$if}.conf");
610 610

  
611 611
                if ($g['booting'])
612 612
                        echo "done\n";
613
        }
614 613

  
615 614
        return 0;
616 615
}
......
906 905
	}
907 906

  
908 907
	/* Dynamic DNS updating active? */
909
	if (isset($config['dnsupdate']['enable'])) {
910

  
911
		$wanip = get_current_wan_address();
912
		if ($wanip) {
913

  
914
			$keyname = $config['dnsupdate']['keyname'];
915
			/* trailing dot */
916
			if (substr($keyname, -1) != ".")
917
				$keyname .= ".";
918

  
919
			$hostname = $config['dnsupdate']['host'];
920
			/* trailing dot */
921
			if (substr($hostname, -1) != ".")
922
				$hostname .= ".";
923

  
924
			/* write private key file
925
			   this is dumb - public and private keys are the same for HMAC-MD5,
926
			   but nsupdate insists on having both */
927
			$fd = fopen("{$g['varetc_path']}/K{$keyname}+157+00000.private", "w");
928
			$privkey .= <<<EOD
908
	if (is_array($config['dnsupdates']['dnsupdate'])) {
909
		foreach ($config['dnsupdates']['dnsupdate'] as $i => $dnsupdate) {
910
		if (!isset($dyndns['enable']))
911
				continue;
912
			/* determine interface name */
913
			if ($dyndns['interface'] == "wan")
914
				$if = get_real_wan_interface();
915
			else
916
				$if = convert_friendly_interface_to_real_interface_name($dyndns['interface']);
917

  
918
			$wanip = get_current_wan_address($if);
919
			if ($wanip) {
920

  
921
				$keyname = $dnsupdate['keyname'];
922
				/* trailing dot */
923
				if (substr($keyname, -1) != ".")
924
					$keyname .= ".";
925

  
926
				$hostname = $dnsupdate['host'];
927
				/* trailing dot */
928
				if (substr($hostname, -1) != ".")
929
					$hostname .= ".";
930

  
931
				/* write private key file
932
				   this is dumb - public and private keys are the same for HMAC-MD5,
933
				   but nsupdate insists on having both */
934
				$fd = fopen("{$g['varetc_path']}/K{$i}{$keyname}+157+00000.private", "w");
935
				$privkey .= <<<EOD
929 936
Private-key-format: v1.2
930 937
Algorithm: 157 (HMAC)
931
Key: {$config['dnsupdate']['keydata']}
938
Key: {$dnsupdate['keydata']}
932 939

  
933 940
EOD;
934
			fwrite($fd, $privkey);
935
			fclose($fd);
936

  
937
			/* write public key file */
938
			if ($config['dnsupdate']['keytype'] == "zone") {
939
				$flags = 257;
940
				$proto = 3;
941
			} else if ($config['dnsupdate']['keytype'] == "host") {
942
				$flags = 513;
943
				$proto = 3;
944
			} else if ($config['dnsupdate']['keytype'] == "user") {
945
				$flags = 0;
946
				$proto = 2;
947
			}
941
				fwrite($fd, $privkey);
942
				fclose($fd);
943

  
944
				/* write public key file */
945
				if ($dnsupdate['keytype'] == "zone") {
946
					$flags = 257;
947
					$proto = 3;
948
				} else if ($dnsupdate['keytype'] == "host") {
949
					$flags = 513;
950
					$proto = 3;
951
				} else if ($dnsupdate['keytype'] == "user") {
952
					$flags = 0;
953
					$proto = 2;
954
				}
948 955

  
949
			$fd = fopen("{$g['varetc_path']}/K{$keyname}+157+00000.key", "w");
950
			fwrite($fd, "{$keyname} IN KEY {$flags} {$proto} 157 {$config['dnsupdate']['keydata']}\n");
951
			fclose($fd);
952

  
953
			/* generate update instructions */
954
			$upinst = "";
955
			if (!empty($config['dnsupdate']['server']))
956
				$upinst .= "server {$config['dnsupdate']['server']}\n";
957
			$upinst .= "update delete {$config['dnsupdate']['host']} A\n";
958
			$upinst .= "update add {$config['dnsupdate']['host']} {$config['dnsupdate']['ttl']} A {$wanip}\n";
959
			$upinst .= "\n";	/* mind that trailing newline! */
960

  
961
			$fd = fopen("{$g['varetc_path']}/nsupdatecmds", "w");
962
			fwrite($fd, $upinst);
963
			fclose($fd);
964

  
965
			/* invoke nsupdate */
966
			$cmd = "/usr/sbin/nsupdate -k {$g['varetc_path']}/K{$keyname}+157+00000.key";
967
			if (isset($config['dnsupdate']['usetcp']))
968
				$cmd .= " -v";
969
			$cmd .= " {$g['varetc_path']}/nsupdatecmds";
970

  
971
			mwexec_bg($cmd);
956
				$fd = fopen("{$g['varetc_path']}/K{$keyname}+157+00000.key", "w");
957
				fwrite($fd, "{$keyname} IN KEY {$flags} {$proto} 157 {$dnsupdate['keydata']}\n");
958
				fclose($fd);
959

  
960
				/* generate update instructions */
961
				$upinst = "";
962
				if (!empty($dnsupdate['server']))
963
					$upinst .= "server {$dnsupdate['server']}\n";
964
				$upinst .= "update delete {$dnsupdate['host']} A\n";
965
				$upinst .= "update add {$dnsupdate['host']} {$dnsupdate['ttl']} A {$wanip}\n";
966
				$upinst .= "\n";	/* mind that trailing newline! */
967

  
968
				$fd = fopen("{$g['varetc_path']}/nsupdatecmds{$i}", "w");
969
				fwrite($fd, $upinst);
970
				fclose($fd);
971

  
972
				/* invoke nsupdate */
973
				$cmd = "/usr/sbin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
974
				if (isset($dnsupdate['usetcp']))
975
					$cmd .= " -v";
976
				$cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
977
	
978
				mwexec_bg($cmd);
979
			}
972 980
		}
973 981
	}
974 982

  
......
1340 1348
	}
1341 1349
}
1342 1350

  
1343
?>
1351
?>

Also available in: Unified diff