Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / tools / crypter
1 #!/usr/bin/perl
2
3 #************************************************************************
4 #*   IRC - Internet Relay Chat, tools/crypter
5 #*   Copyright (C) 1991 Sean Batt
6 #*
7 #*   This program is free software; you can redistribute it and/or modify
8 #*   it under the terms of the GNU General Public License as published by
9 #*   the Free Software Foundation; either version 1, or (at your option)
10 #*   any later version.
11 #*
12 #*   This program is distributed in the hope that it will be useful,
13 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #*   GNU General Public License for more details.
16 #*
17 #*   You should have received a copy of the GNU General Public License
18 #*   along with this program; if not, write to the Free Software
19 #*   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #*
21 #*   $Id: crypter,v 1.2 2002-03-07 22:52:57 ghostwolf Exp $
22 #*/
23
24 #From Sean Batt sean@coombs.anu.edu.au
25 #
26 #Temporary output file
27 #
28 $tmpfile = "/tmp/ircd.conf.tmp";
29
30 #
31 #Original ircd.conf file
32 #
33 $ircdconf = @ARGV[0];
34
35 print "crypting ",$ircdconf,"\n";
36 @saltset = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '.', '/');
37
38 umask(0077);
39 open ($ircdout, ">$tmpfile") || die "open $!";
40
41 while ($text = <>) {
42 #if its not an "O" line we can ignore it
43     $text =~ /^o/i || print ($ircdout $text) && next;
44     chop($text);
45     @oline = split(':', $text);
46     $salt = $saltset[rand(time)%64].$saltset[(rand(time)>>6)%64];
47     $oline[2] = crypt(@oline[2], $salt);
48     print ($ircdout join(':',@oline)."\n");
49 }
50 close ($ircdout);
51 close ($ircdin);
52 print "/bin/cp ",$tmpfile," ",$ircdconf,"\n";
53 (fork()==0) ? exec("/bin/cp", $tmpfile, $ircdconf) : wait;
54 print "",$ircdconf," has been crypted successfully!\n";
55
56 #unlink($tmpfile);