⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 find_free.cgi

📁 BIND 9 dynamic DNS webmin module. This module supports both static and dynamic zones, and IPv4 and I
💻 CGI
字号:
#! /usr/bin/perl##    B9DDNS - BIND 9 dynamic DNS webmin module.#    Copyright (C) 2003 John Horne. <john.horne@plymouth.ac.uk>##    This program is free software; you can redistribute it and/or modify#    it under the terms of the GNU General Public License as published by#    the Free Software Foundation; either version 2 of the License, or#    (at your option) any later version.##    This program is distributed in the hope that it will be useful,#    but WITHOUT ANY WARRANTY; without even the implied warranty of#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#    GNU General Public License for more details.##    You should have received a copy of the GNU General Public License#    along with this program; if not, write to the Free Software#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.### Looks for free IP numbers.## Based on code by Ivan Andrian, <ivan.andrian@elettra.trieste.it>#use strict;no strict 'vars';require './b9ddns-lib.pl';my $freeXXXcount = my $freemaccount = my $mid = my $i = 0;my $cf = 1;my $conf = my $zone_conf = my $type = my $file = my $domain = '';my $hip = my $hname = '';my @recs = my @frecs = ();my %frecs = ();&ReadParse();$conf = &get_config();if ($in{'view'}) {	$conf = $conf->[$in{'view'}]->{'members'};}$zone_conf = $conf->[$in{'index'}]->{'members'};$type = &find('type', $zone_conf)->{'value'};$file = &find_value('file', $zone_conf);$domain = $conf->[$in{'index'}]->{'value'};%access = &get_module_acl();unless ($access{'findfree'}) {	&terror('findfree_nofind');}&header(&text('findfree_title'), '');print '<center><font size=+2>', &text('findfree_header', &arpa_to_ip($domain)),      '</font></center>';print '<hr>';if (@in == 2) {	&find_ips($in{'index'}, $in{'from'});}elsif (@in == 3) {	&find_ips($in{'index'}, $in{'from'}, $in{'to'});}elsif (@in == 4) {	$cf = $in{'cf'};	&find_ips($in{'index'}, $in{'from'}, $in{'to'}, $in{'cf'});}else {	&find_ips($in{'index'});}if (@in >= 3) {	@recs = &read_zone_file($file, $domain) if (defined($file));	@recs = grep { ($_->{'type'} eq 'A') || ($_->{'type'} eq 'PTR') } @recs;	if (@recs) {		@recs = &sort_records(@recs);		%frecs = &build_iprange($in{'from'}, $in{'to'});		for ($i = 0; $i < @recs; $i++) {			$hip = $hname = '';			if ($recs[$i]->{'type'} eq 'A') {				$hip = $recs[$i]->{'values'}->[0];				$hname = $recs[$i]->{'fqdn'};			}			else {				$hip = &arpa_to_ip($recs[$i]->{'fqdn'});				$hname = $recs[$i]->{'values'}->[0];			}					#			# 'freeXXX' hostnames are free IP's.			#			if ($cf & ($hname =~ /^free[^.]/io) &			    exists($frecs{$hip})) {				$frecs{$hip}->{'ttl'} = $recs[$i]->{'ttl'};				$frecs{$hip}->{'fqdn'} = $hname;				$freeXXXcount++;				$freemaccount++ if ($hname =~ /^freemac[^.]/io);			}			else {				delete $frecs{$hip};			}		}		@frecs = sort ffree_ip_sort_func values(%frecs); 		$mid = int((@frecs + 1) / 2);		print '<p align=center><b>Found ', @frecs, ' free IP number';		print 's' if (@frecs != 1);		if ($cf) {			print " ($freeXXXcount ",			      ($freeXXXcount == 1 ? 'is' : 'are'),			      ' <b>"freeXXX"</b> of which ', $freemaccount,			      ($freemaccount == 1 ? ' is' : ' are'),			      ' <b>"freemac"</b>)';			print '</p>';		}		print "<table width=100%><tr><td width=50% valign=top>\n";		&frecs_table(@frecs[0 .. $mid - 1]);		print "</td><td width=50% valign=top>\n";		if ($mid < @frecs) {			&frecs_table(@frecs[$mid .. $#frecs]);		}		print '</td></tr></table><p>';		print "<p>\n";	}}print '<hr>';&footer("edit_$type.cgi?index=$in{'index'}&view=$in{'view'}", 	$text{'recs_return'});exit;## build_iprange(fromIP, toIP)#sub build_iprange {	my $byte0 = my $byte1 = my $byte2 = my $byte3 = my $i = 0;	my @from = my @to = ();	my %frecs = ();	$_[0] =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/o;	@from = ($1, $2, $3, $4);	return @from if (@from != 4);	$_[1] =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/o;	@to = ($1, $2, $3, $4);	return @to if (@to != 4);	for ($i = 0; $i < 4; $i++) {		$from[$i] = ($from[$i] == 0) ? 1 : $from[$i];		$to[$i] = ($to[$i] == 255) ? 254 : $to[$i];	}	for ($byte0 = $from[0]; $byte0 <= $to[0]; $byte0++) {		for ($byte1 = ($byte0 == $from[0]) ? $from[1] : 1;			$byte1 <= ($byte0 == $to[0] ? $to[1] : 254);			$byte1++) {			for ($byte2 = ($byte0 == $from[0]) && (($byte1 == $from[1]) ? $from[2] : 1);				$byte2 <= (($byte0 == $to[0]) && (($byte1 == $to[1]) ? $to[2] : 254));				$byte2++) {				for ($byte3 = ($byte0 == $from[0]) && ($byte1 == $from[1]) && (($byte2 == $from[2]) ? $from[3] : 1);					$byte3 <= (($byte0 == $to[0]) && ($byte1 == $to[1]) && (($byte2 == $to[2]) ? $to[3] : 254));					$byte3++) {					$frecs{"$byte0.$byte1.$byte2.$byte3"}->{'ip'} = "$byte0.$byte1.$byte2.$byte3";					$frecs{"$byte0.$byte1.$byte2.$byte3"}->{'ttl'} = $text{'default'};					$frecs{"$byte0.$byte1.$byte2.$byte3"}->{'fqdn'} = '';				}			}		}	}	return %frecs;}## find_ips(zoneindex, from_ip, to_ip, consider_freeXX_names)## Display a form for searching for free IP numbers.#sub find_ips {	print '<form action=find_free.cgi>';	print '<input type=hidden name=index value="', $_[0], '">';	print '<input type=hidden name=view value="', $in{'view'}, '">';	print '<table border>';	print "<tr $tb><td><b>$text{'findfree_sopt'}</b></td></tr>\n";	print "<tr $cb><td><table>\n";	print "<tr><td><b>$text{'findfree_IPrange'}</b></td>\n";	print "<td><b>$text{'findfree_from'}</b></td>\n";	if (@_ >= 2) {		print '<td><input name=from value="', $_[1], '" size=30></td></tr>';	}	else {		print '<td><input name=from value="" size=30></td></tr>';	}	print '<tr><td>&nbsp;</td>';	print '<td><b>', $text{'findfree_to'}, '</b></td>';	if (@_ >= 3) {		print '<td><input name=to value="', $_[2], '" size=30></td></tr>';	}	else {		print '<td><input name=to value="" size=30></td></tr>';	}	print '<tr><td colspan=3 nowrap><b>', $text{'findfree_cf'}, "</b>\n";	printf ' &nbsp; <input type=radio name=cf value=1 %s> %s',	       &checked($cf), $text{'yes'};	printf '<input type=radio name=cf value=0 %s> %s</td></tr>',	       &checked(! $cf), $text{'no'};	print '<tr colspan=3><td><input type=submit value="',	      $text{'findfree_search'}, '"></td></tr>';	print "</table></td></tr></table></form>\n";	return;}## frecs_table(array_of_freerecords)#sub frecs_table {	my $i = 0;	my $rec = '';	print '<table border width=100%>';	print "<tr $tb><td><b>", $text{'recs_addr'}, '</b></td>',	      '<td><b>', $text{'recs_ttl'}, '</b></td>',	      '<td><b>', $text{'recs_name'}, '</b></td>',	      "</tr>\n";	for ($i = 0; $i < @_; $i++) {		$rec = $_[$i];		print "<tr $cb><td>$rec->{'ip'}</td>",		      '<td>', $rec->{'ttl'} ? $rec->{'ttl'} : $text{'default'},'</td>',		      '<td>', $rec->{'fqdn'} ? $rec->{'fqdn'} : '&nbsp;', '</td>',		      "</tr>\n";	}	print "</table>\n";	return;}sub ffree_ip_sort_func {	my $a1 = my $a2 = my $a3 = my $a4 = 0;	my $a = my $b = '';	$a->{'ip'} =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/o;	($a1, $a2, $a3, $a4) = ($1, $2, $3, $4);	$b->{'ip'} =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/o;	return	($a1 < $1) ? -1 :		($a1 > $1) ?  1 :		($a2 < $2) ? -1 :		($a2 > $2) ?  1 :		($a3 < $3) ? -1 :		($a3 > $3) ?  1 :		($a4 < $4) ? -1 :		($a4 > $4) ?  1 : 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -