Advertisement

08.07.2008 at 12:49AM PDT, ID: 23628523
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.9

perl script installation

Asked by akiles99 in Perl Programming Language

Hi,

How to install this perl script...

Cheers,
akilesStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
#!/usr/bin/env perl
 
use 5.008;
use strict;
use warnings;
use Config;
$Config{useithreads} or die('requires threads');
 
use threads;
use threads::shared;
use IO::Socket::INET;
use Time::HiRes qw(usleep);
use POSIX qw(pause);
use Log::Dispatch;
use Log::Dispatch::File;
use Log::Dispatch::Screen;
 
use Nominet;
 
use constant 'DOMAINS_FILE' => 'domains.txt';
use constant 'DAC_HOST' => 'dac.nic.uk';
use constant 'DAC_PORT' => 2043;
use constant 'DAC_DELAY' => 187 * 1000; # in microseconds
 
my @domains :shared;
our $log;
 
&main();
exit;
 
sub main() {
	my $logfile = Log::Dispatch::File->new('name' => 'dac_read', 'min_level' => 'debug', 'filename' => 'dac_read.log');
	my $logscreen = Log::Dispatch::Screen->new('name' => 'dac_read_screen', 'min_level' => 'debug', 'stderr' => 0);
 
	$log = Log::Dispatch->new;
	$log->add($logfile);
	$log->add($logscreen);
 
	$log->log('level' => 'debug' , 'message' => "* main: logging initialized\n");
 
	$SIG{'HUP'} = \&read_domains;
 
	$log->log('level' => 'debug', 'message' => "* main: installed SIGHUP handler\n");
 
	&read_domains();
 
	my $dac_sock = IO::Socket::INET->new('PeerAddr' => DAC_HOST,
					     'PeerPort' => DAC_PORT,
					     'Proto'    => 'tcp'
					    ) or die "IO::Socket::INET->new() failed: $!";
 
	sleep(5);
 
	my $dac_fd = $dac_sock->fileno();
 
	my $dac_write_thr = threads->create(\&dac_write, $dac_fd);
	&dac_read($dac_fd);
 
	$log->log('level' => 'debug', 'message' => "* main: returned from DAC reader. closing DAC sock...\n");
 
	$dac_sock->close();
 
	$log->log('level' => 'debug', 'message' => "* main: closed DAC sock.\n");
 
	$log->log('level' => 'notice', 'message' => "* main: terminating\n");
 
	return;
}
 
sub log_init() {
	my $logfile = Log::Dispatch::File->new('name' => 'epp_file', 'min_level' => 'debug', 'filename' => 'epp.log');
	my $logscreen = Log::Dispatch::Screen->new('name' => 'epp_screen', 'min_level' => 'debug', 'stderr' => 0);
 
	$log = Log::Dispatch->new;
	$log->add($logfile);
	$log->add($logscreen);
 
	return;
}
 
sub dac_read($) {
	my $fd = shift;
 
	$log->log('level' => 'debug', 'message' => "* DAC reader: thread started\n");
 
	my $sock = IO::Socket->new_from_fd($fd, 'r') or $log->log_and_die('level' => 'error', 'message' => "* DAC reader: IO::Socket->new_from_fd() failed: $!\n");
 
	Nominet::connect();
 
	my $epp_update = 0;
 
	$/ = "\r\n";
 
	while (my $result = <$sock>) {
		chomp $result;
 
		$result =~ m/^([^,]+),([YNERIB])(,(.+))?/;
		my ($domain, $status, $rest) = ($1, $2, $4);
 
		if ($status eq 'N') {
			$log->log('level' => 'notice', 'message' => "* result: AVAILABLE ($domain)\n");
			Nominet::create($domain);
		} else {
			if ($status eq 'Y') {
				$log->log('level' => 'info', 'message' => "* result: unavailable ($domain ... $rest)\n");
			} elsif ($status eq 'B') {
				$log->log('level' => 'info', 'message' => "* result: blocked ($domain, $rest seconds)\n");
 
				lock(@domains);
 
				$log->log('level' => 'debug', 'message' => "* block: got lock, blocking for $rest seconds\n");
 
				sleep($rest);
 
				$log->log('level' => 'debug', 'message' => "* block: unblocked\n");
			} elsif (($status eq 'E') || ($status eq 'r') || ($status eq 'I')) {
				$log->log('level' => 'notice', 'message' => "* result: got '$status' ($domain)\n");
			} else {
				$log->log('level' => 'notice', 'message' => "* result: unknown result ($domain ... $status)\n");
			}
 
			$log->log('level' => 'debug', 'message' => "* DAC reader: adding domain '$domain' back to list. getting lock...\n");
 
			{
				lock(@domains);
				push(@domains, lc($domain));
			}
 
			$log->log('level' => 'debug', 'message' => "* DAC reader: lock released\n");
		}
 
		my $time = time();
		my $delta = $epp_update - $time;
		if ($delta <= 0) {
			$log->log('level' => 'debug', 'message' => "* DAC reader: EPP needs noop (time=$time,epp update=$epp_update,delta=$delta)\n");
			$epp_update = $time + ((5 * 60) + 30);
			Nominet::noop();
			$log->log('level' => 'debug', 'message' => "* DAC reader: EPP noop sent\n");
		} else {
			$log->log('level' => 'debug', 'message' => "* DAC reader: EPP doesn't need noop (time=$time,epp update=$epp_update,delta=$delta)\n");
		}
	}
 
	Nominet::disconnect();
 
	return;
}
 
sub dac_write($) {
	my $fd = shift;
 
	my $logfile = Log::Dispatch::File->new('name' => 'dac_write', 'min_level' => 'debug', 'filename' => 'dac_write.log');
	my $logscreen = Log::Dispatch::Screen->new('name' => 'dac_write_screen', 'min_level' => 'debug', 'stderr' => 0);
 
	$log = Log::Dispatch->new;
	$log->add($logfile);
	$log->add($logscreen);
 
	$log->log('level' => 'debug', 'message' => "* DAC writer: logging initialized\n");
 
	$log->log('level' => 'debug', 'message' => "* DAC writer: thread started (fd=$fd)\n");
 
	my $sock = IO::Socket->new_from_fd($fd, 'w') or $log->log_and_die('level' => 'error', 'message' => "* DAC writer: IO::Socket->new_from_fd() failed: $!\n");
 
	for (;;) {
		my $domain;
 
		$log->log('level' => 'debug', 'message' => "* DAC writer: getting lock...\n");
 
		{
			lock(@domains);
			$domain = shift(@domains);
		}
 
		$log->log('level' => 'debug', 'message' => "* DAC writer: lock released\n");
 
		if (defined($domain)) {
			$log->log('level' => 'debug', 'message' => "* DAC writer: sending '$domain'\n");
 
			my $msg = "$domain\r\n";
			syswrite($sock, $msg, length($msg));
			#print $sock "$domain\r\n";
			#$sock->flush();
		} else {
			$log->log('level' => 'debug', 'message' => "* DAC writer: no domains in list\n");
		}
 
		$log->log('level' => 'debug', 'message' => "* DAC writer: sleeping\n");
		usleep(DAC_DELAY);
		$log->log('level' => 'debug', 'message' => "* DAC writer: woke up\n");
	}
 
	return;
}
 
sub read_file($) {
	my $filename = shift;
 
	$log->log('level' => 'debug', 'message' => "* read file: opening $filename\n");
 
	open(IN, "<$filename") or $log->log_and_die('level' => 'error', 'message' => "* read file: open() failed: $!\n");
 
	my @ret;
 
	while (my $line = <IN>) {
		chomp $line;
		push @ret, lc($line);
	}
 
	close(IN);
 
	return @ret;
}
 
sub read_domains() {
	lock(@domains);
	@domains = &read_file(DOMAINS_FILE);
 
	$log->log('level' => 'debug', 'message' => "* read domains: finished reading, list:\n");
 
	foreach my $domain (@domains) {
		$log->log('level' => 'debug', 'message' => "* domain: '$domain'\n");
	}
 
	return;
}
[+][-]08.07.2008 at 01:17AM PDT, ID: 22178836

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: Tintin
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.07.2008 at 01:56AM PDT, ID: 22179021

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.07.2008 at 01:56AM PDT, ID: 22179025

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.07.2008 at 02:09AM PDT, ID: 22179094

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628