Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

604 lines
13 KiB

  1. #!perl
  2. #
  3. # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
  4. use strict;
  5. use IO::File;
  6. use Getopt::Std;
  7. use ExtUtils::MakeMaker qw(prompt);
  8. use vars qw($opt_d $opt_o);
  9. use Config;
  10. ##
  11. ##
  12. ##
  13. my %cfg = ();
  14. my @cfg = ();
  15. my($libnet_cfg,$msg,$ans,$def,$have_old);
  16. ##
  17. ##
  18. ##
  19. sub valid_host
  20. {
  21. my $h = shift;
  22. defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
  23. }
  24. ##
  25. ##
  26. ##
  27. sub test_hostnames (\@)
  28. {
  29. my $hlist = shift;
  30. my @h = ();
  31. my $host;
  32. my $err = 0;
  33. foreach $host (@$hlist)
  34. {
  35. if(valid_host($host))
  36. {
  37. push(@h, $host);
  38. next;
  39. }
  40. warn "Bad hostname: '$host'\n";
  41. $err++;
  42. }
  43. @$hlist = @h;
  44. $err ? join(" ",@h) : undef;
  45. }
  46. ##
  47. ##
  48. ##
  49. sub Prompt
  50. {
  51. my($prompt,$def) = @_;
  52. $def = "" unless defined $def;
  53. chomp($prompt);
  54. if($opt_d)
  55. {
  56. print $prompt,," [",$def,"]\n";
  57. return $def;
  58. }
  59. prompt($prompt,$def);
  60. }
  61. ##
  62. ##
  63. ##
  64. sub get_host_list
  65. {
  66. my($prompt,$def) = @_;
  67. $def = join(" ",@$def) if ref($def);
  68. my @hosts;
  69. do
  70. {
  71. my $ans = Prompt($prompt,$def);
  72. $ans =~ s/(\A\s+|\s+\Z)//g;
  73. @hosts = split(/\s+/, $ans);
  74. }
  75. while(@hosts && defined($def = test_hostnames(@hosts)));
  76. \@hosts;
  77. }
  78. ##
  79. ##
  80. ##
  81. sub get_hostname
  82. {
  83. my($prompt,$def) = @_;
  84. my $host;
  85. while(1)
  86. {
  87. my $ans = Prompt($prompt,$def);
  88. $host = ($ans =~ /(\S*)/)[0];
  89. last
  90. if(!length($host) || valid_host($host));
  91. $def =""
  92. if $def eq $host;
  93. print <<"EDQ";
  94. *** ERROR:
  95. Hostname `$host' does not seem to exist, please enter again
  96. or a single space to clear any default
  97. EDQ
  98. }
  99. length $host
  100. ? $host
  101. : undef;
  102. }
  103. ##
  104. ##
  105. ##
  106. sub get_bool ($$)
  107. {
  108. my($prompt,$def) = @_;
  109. chomp($prompt);
  110. my $val = Prompt($prompt,$def ? "yes" : "no");
  111. $val =~ /^y/i ? 1 : 0;
  112. }
  113. ##
  114. ##
  115. ##
  116. sub get_netmask ($$)
  117. {
  118. my($prompt,$def) = @_;
  119. chomp($prompt);
  120. my %list;
  121. @list{@$def} = ();
  122. MASK:
  123. while(1) {
  124. my $bad = 0;
  125. my $ans = Prompt($prompt) or last;
  126. if($ans eq '*') {
  127. %list = ();
  128. next;
  129. }
  130. if($ans eq '=') {
  131. print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
  132. next;
  133. }
  134. unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
  135. warn "Bad netmask '$ans'\n";
  136. next;
  137. }
  138. my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
  139. if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
  140. warn "Bad netmask '$ans'\n";
  141. next MASK;
  142. }
  143. foreach my $byte (@ip) {
  144. if ( $byte > 255 ) {
  145. warn "Bad netmask '$ans'\n";
  146. next MASK;
  147. }
  148. }
  149. my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
  150. if ($remove) {
  151. delete $list{$mask};
  152. }
  153. else {
  154. $list{$mask} = 1;
  155. }
  156. }
  157. [ keys %list ];
  158. }
  159. ##
  160. ##
  161. ##
  162. sub default_hostname
  163. {
  164. my $host;
  165. my @host;
  166. foreach $host (@_)
  167. {
  168. if(defined($host) && valid_host($host))
  169. {
  170. return $host
  171. unless wantarray;
  172. push(@host,$host);
  173. }
  174. }
  175. return wantarray ? @host : undef;
  176. }
  177. ##
  178. ##
  179. ##
  180. getopts('do:');
  181. $libnet_cfg = "$Config{installsitelib}/Net/libnet.cfg"
  182. unless(defined($libnet_cfg = $opt_o));
  183. my %oldcfg = ();
  184. $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
  185. if( -f $libnet_cfg )
  186. {
  187. %oldcfg = ( %{ do $libnet_cfg } );
  188. }
  189. elsif (eval { require Net::Config })
  190. {
  191. $have_old = 1;
  192. %oldcfg = %Net::Config::NetConfig;
  193. }
  194. map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
  195. $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
  196. $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
  197. #---------------------------------------------------------------------------
  198. if($have_old && !$opt_d)
  199. {
  200. $msg = <<EDQ;
  201. Ah, I see you already have installed libnet before.
  202. Do you want to modify/update your configuration (y|n) ?
  203. EDQ
  204. $opt_d = 1
  205. unless get_bool($msg,0);
  206. }
  207. #---------------------------------------------------------------------------
  208. $msg = <<EDQ;
  209. This script will prompt you to enter hostnames that can be used as
  210. defaults for some of the modules in the libnet distribution.
  211. To ensure that you do not enter an invalid hostname, I can perform a
  212. lookup on each hostname you enter. If your internet connection is via
  213. a dialup line then you may not want me to perform these lookups, as
  214. it will require you to be on-line.
  215. Do you want me to perform hostname lookups (y|n) ?
  216. EDQ
  217. $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
  218. print <<EDQ unless $cfg{'test_exist'};
  219. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  220. OK I will not check if the hostnames you give are valid
  221. so be very cafeful
  222. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  223. EDQ
  224. #---------------------------------------------------------------------------
  225. print <<EDQ;
  226. The following questions all require a list of host names, separated
  227. with spaces. If you do not have a host available for any of the
  228. services, then enter a single space, followed by <CR>. To accept the
  229. default, hit <CR>
  230. EDQ
  231. $msg = 'Enter a list of available NNTP hosts :';
  232. $def = $oldcfg{'nntp_hosts'} ||
  233. [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
  234. $cfg{'nntp_hosts'} = get_host_list($msg,$def);
  235. #---------------------------------------------------------------------------
  236. $msg = 'Enter a list of available SMTP hosts :';
  237. $def = $oldcfg{'smtp_hosts'} ||
  238. [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
  239. $cfg{'smtp_hosts'} = get_host_list($msg,$def);
  240. #---------------------------------------------------------------------------
  241. $msg = 'Enter a list of available POP3 hosts :';
  242. $def = $oldcfg{'pop3_hosts'} || [];
  243. $cfg{'pop3_hosts'} = get_host_list($msg,$def);
  244. #---------------------------------------------------------------------------
  245. $msg = 'Enter a list of available SNPP hosts :';
  246. $def = $oldcfg{'snpp_hosts'} || [];
  247. $cfg{'snpp_hosts'} = get_host_list($msg,$def);
  248. #---------------------------------------------------------------------------
  249. $msg = 'Enter a list of available PH Hosts :' ;
  250. $def = $oldcfg{'ph_hosts'} ||
  251. [ default_hostname('dirserv') ];
  252. $cfg{'ph_hosts'} = get_host_list($msg,$def);
  253. #---------------------------------------------------------------------------
  254. $msg = 'Enter a list of available TIME Hosts :' ;
  255. $def = $oldcfg{'time_hosts'} || [];
  256. $cfg{'time_hosts'} = get_host_list($msg,$def);
  257. #---------------------------------------------------------------------------
  258. $msg = 'Enter a list of available DAYTIME Hosts :' ;
  259. $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
  260. $cfg{'daytime_hosts'} = get_host_list($msg,$def);
  261. #---------------------------------------------------------------------------
  262. $msg = <<EDQ;
  263. Do you have a firewall/ftp proxy between your machine and the internet
  264. If you use a SOCKS firewall answer no
  265. (y|n) ?
  266. EDQ
  267. if(get_bool($msg,0)) {
  268. $msg = <<'EDQ';
  269. What series of FTP commands do you need to send to your
  270. firewall to connect to an external host.
  271. user/pass => external user & password
  272. fwuser/fwpass => firewall user & password
  273. 0) None
  274. 1) -----------------------
  275. USER user@remote.host
  276. PASS pass
  277. 2) -----------------------
  278. USER fwuser
  279. PASS fwpass
  280. USER user@remote.host
  281. PASS pass
  282. 3) -----------------------
  283. USER fwuser
  284. PASS fwpass
  285. SITE remote.site
  286. USER user
  287. PASS pass
  288. 4) -----------------------
  289. USER fwuser
  290. PASS fwpass
  291. OPEN remote.site
  292. USER user
  293. PASS pass
  294. 5) -----------------------
  295. USER user@fwuser@remote.site
  296. PASS pass@fwpass
  297. 6) -----------------------
  298. USER fwuser@remote.site
  299. PASS fwpass
  300. USER user
  301. PASS pass
  302. 7) -----------------------
  303. USER user@remote.host
  304. PASS pass
  305. AUTH fwuser
  306. RESP fwpass
  307. Choice:
  308. EDQ
  309. $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
  310. $ans = Prompt($msg,$def);
  311. $cfg{'ftp_firewall_type'} = 0+$ans;
  312. $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
  313. $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
  314. }
  315. else {
  316. delete $cfg{'ftp_firewall'};
  317. }
  318. #---------------------------------------------------------------------------
  319. if (defined $cfg{'ftp_firewall'})
  320. {
  321. print <<EDQ;
  322. By default Net::FTP assumes that it only needs to use a firewall if it
  323. cannot resolve the name of the host given. This only works if your DNS
  324. system is setup to only resolve internal hostnames. If this is not the
  325. case and your DNS will resolve external hostnames, then another method
  326. is needed. Net::Config can do this if you provide the netmasks that
  327. describe your internal network. Each netmask should be entered in the
  328. form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
  329. EDQ
  330. $def = [];
  331. if(ref($oldcfg{'local_netmask'}))
  332. {
  333. $def = $oldcfg{'local_netmask'};
  334. print "Your current netmasks are :\n\n\t",
  335. join("\n\t",@{$def}),"\n\n";
  336. }
  337. print "
  338. Enter one netmask at each prompt, prefix with a - to remove a netmask
  339. from the list, enter a '*' to clear the whole list, an '=' to show the
  340. current list and an empty line to continue with Configure.
  341. ";
  342. my $mask = get_netmask("netmask :",$def);
  343. $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
  344. }
  345. #---------------------------------------------------------------------------
  346. ###$msg =<<EDQ;
  347. ###
  348. ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
  349. ###then enter a list of hostames
  350. ###
  351. ###Enter a list of available SOCKS hosts :
  352. ###EDQ
  353. ###
  354. ###$def = $cfg{'socks_hosts'} ||
  355. ### [ default_hostname($ENV{SOCKS5_SERVER},
  356. ### $ENV{SOCKS_SERVER},
  357. ### $ENV{SOCKS4_SERVER}) ];
  358. ###
  359. ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
  360. #---------------------------------------------------------------------------
  361. print <<EDQ;
  362. Normally when FTP needs a data connection the client tells the server
  363. a port to connect to, and the server initiates a connection to the client.
  364. Some setups, in particular firewall setups, can/do not work using this
  365. protocol. In these situations the client must make the connection to the
  366. server, this is called a passive transfer.
  367. EDQ
  368. if (defined $cfg{'ftp_firewall'}) {
  369. $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
  370. $def = $oldcfg{'ftp_ext_passive'} || 0;
  371. $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
  372. $msg = "\nShould all other FTP connections be passive (y|n) ?";
  373. }
  374. else {
  375. $msg = "\nShould all FTP connections be passive (y|n) ?";
  376. }
  377. $def = $oldcfg{'ftp_int_passive'} || 0;
  378. $cfg{'ftp_int_passive'} = get_bool($msg,$def);
  379. #---------------------------------------------------------------------------
  380. $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
  381. $ans = Prompt("\nWhat is your local internet domain name :",$def);
  382. $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
  383. #---------------------------------------------------------------------------
  384. $msg = <<EDQ;
  385. If you specified some default hosts above, it is possible for me to
  386. do some basic tests when you run `make test'
  387. This will cause `make test' to be quite a bit slower and, if your
  388. internet connection is via dialup, will require you to be on-line
  389. unless the hosts are local.
  390. Do you want me to run these tests (y|n) ?
  391. EDQ
  392. $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
  393. #---------------------------------------------------------------------------
  394. $msg = <<EDQ;
  395. To allow Net::FTP to be tested I will need a hostname. This host
  396. should allow anonymous access and have a /pub directory
  397. What host can I use :
  398. EDQ
  399. $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
  400. if $cfg{'test_hosts'};
  401. print "\n";
  402. #---------------------------------------------------------------------------
  403. chmod(0644, $libnet_cfg);
  404. my $fh = IO::File->new($libnet_cfg, "w") or
  405. die "Cannot create `$libnet_cfg': $!";
  406. print "Writing $libnet_cfg\n";
  407. print $fh "{\n";
  408. my $key;
  409. foreach $key (keys %cfg) {
  410. my $val = $cfg{$key};
  411. if(!defined($val)) {
  412. $val = "undef";
  413. }
  414. elsif(ref($val)) {
  415. $val = '[' . join(",",
  416. map {
  417. my $v = "undef";
  418. if(defined $_) {
  419. ($v = $_) =~ s/'/\'/sog;
  420. $v = "'" . $v . "'";
  421. }
  422. $v;
  423. } @$val ) . ']';
  424. }
  425. else {
  426. $val =~ s/'/\'/sog;
  427. $val = "'" . $val . "'" if $val =~ /\D/;
  428. }
  429. print $fh "\t'",$key,"' => ",$val,",\n";
  430. }
  431. print $fh "}\n";
  432. $fh->close;
  433. ############################################################################
  434. ############################################################################
  435. exit 0;