-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge-xchat.pl
126 lines (93 loc) · 2.74 KB
/
challenge-xchat.pl
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
#!/usr/bin/env perl
#
# challenge-xchat.pl
# Copyright (C) 2006 Lee Hardy <lee -at- leeh.co.uk>
# Copyright (C) 2006 ircd-ratbox development team
# Copyright (C) 2012 David Murdoch <Fersure -at- freenode>
#
# $Id$
package IRC::XChat::operchallenge;
use IPC::Open2;
use FileHandle;
#########################
# Configuration Variables
#########################
# respond_path: The absolute path to the "ratbox-respond" program.
my $respond_path = "/home/user/respond/ratbox-respond/ratbox-respond";
# private key path: The absolute path to your private key.
my $private_key_path = "/home/user/respond/ratbox-respond/private.key";
###################
# END CONFIGURATION
###################
my $script_name = "oper-challenge";
my $script_version = "1.1";
my $script_descr = "CHALLENGE opering script for use with ratbox/charybdis based ircds.";
Xchat::register($script_name, $script_version, $script_descr, "");
Xchat::print("Loading $script_name $script_version - $script_descr\n");
my $challenge;
my $keyphrase = "";
Xchat::hook_server("740", "handle_rpl_rsachallenge2");
Xchat::hook_server("741", "handle_rpl_endofrsachallenge2");
my $challenge_options = {
help_text => "Usage: /challenge <opername> [keyphrase]\n"
};
Xchat::hook_command("CHALLENGE", "handle_challenge", $challenge_options);
sub handle_challenge
{
my $opername = $_[0][1];
if(!$opername)
{
Xchat::print("Usage: /challenge <opername> [keyphrase]\n");
return Xchat::EAT_ALL;
}
$challenge = "";
$keyphrase = $_[0][2]
if($_[0][2]);
Xchat::command("QUOTE CHALLENGE $opername\n");
return Xchat::EAT_ALL;
}
sub handle_rpl_rsachallenge2
{
my $reply = $_[0][3];
# remove the initial ':'
$reply =~ s/^://;
$challenge .= $reply;
return Xchat::EAT_ALL;
}
sub handle_rpl_endofrsachallenge2
{
Xchat::print("oper-challenge: Received challenge, generating response..\n");
if(! -x $respond_path)
{
Xchat::print("oper-challenge: Unable to execute respond from $respond_path\n");
return Xchat::EAT_ALL;
}
if(! -r $private_key_path)
{
Xchat::print("oper-challenge: Unable to open $private_key_path\n");
}
unless(open2(*Reader, *Writer, "$respond_path $private_key_path"))
{
Xchat::print("oper-challenge: Unable to execute respond from $respond_path\n");
return Xchat::EAT_ALL;
}
print Writer "$keyphrase\n";
print Writer "$challenge\n";
# done for safety.. this may be irrelevant in perl!
$keyphrase =~ s/./0/g;
$keyphrase = "";
$challenge =~ s/./0/g;
$challenge = "";
my $output = scalar <Reader>;
chomp($output);
close(RESPOND);
if($output =~ /^Error:/)
{
Xchat::print("oper-challenge: $output\n");
return Xchat::EAT_ALL;
}
Xchat::print("oper-challenge: Received response, opering..\n");
Xchat::command("QUOTE CHALLENGE +$output");
return Xchat::EAT_ALL;
}
1;