wraith.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use Digest::MD5 qw(md5 md5_hex md5_base64);
  5. use Encode qw(encode_utf8);
  6. my $script = 'wraith-auth';
  7. my $ver = '1.0';
  8. my $dev = 'bryan';
  9. my $email = 'bryan@shatow.net';
  10. my $url = '';
  11. IRC::register( "$script", "$ver", '', '' );
  12. sub cmd_auth {
  13. my($data,$server,$witem) = @_;
  14. if (!$data) {
  15. Irssi:print "Usage: /auth hash\nbefore you can do that, type /set auth, then /set all of the variables that show.\n";
  16. } else {
  17. Irssi::print auth($data);
  18. }
  19. }
  20. sub auth($) {
  21. my($data,$server,$witem) = @_;
  22. my ($secpass,$authkey,$botdump,$hash);
  23. #lets use the right word for the hash.
  24. my @words = split " ", $data;
  25. if ($data =~ /^\-Auth/) {
  26. $hash = $words[1];
  27. } else {
  28. $hash = $words[0];
  29. }
  30. # Irssi::print "Authing: $hash";
  31. $secpass = Irssi::settings_get_str('auth_secpass');
  32. $authkey = Irssi::settings_get_str('auth_authkey');
  33. $botdump = $hash . $secpass . $authkey ;
  34. return md5_hex(encode_utf8($botdump));
  35. }
  36. #this must handle both auth. and -Auth
  37. Irssi::signal_add "message private", sub {
  38. my ($server, $text, $nick, $address, $target) = @_;
  39. my ($msg, $data, $password);
  40. my (@servers) = Irssi::servers();
  41. if ($msg =~ /^\255\251\001/) {
  42. $msg = substr($text,3);
  43. } else {
  44. $msg = $text;
  45. }
  46. # if ($nick =~ /^\(/) { #this is a psybnc dcc chat.
  47. # } else { #normal msg
  48. # $password = Irssi::settings_get_str('auth_password');
  49. # if ($msg =~ /^auth\./) { #msg back password
  50. # send auth $password;
  51. # }
  52. # }
  53. if ($msg =~ /^\-Auth/) {
  54. $server = $servers[0];
  55. my $cmd = "/MSG $nick +Auth " . auth($msg);
  56. $server->command("$cmd");
  57. }
  58. };
  59. #this must handle -Auth
  60. Irssi::signal_add "dcc chat message", sub {
  61. my ($dcc, $text) = @_;
  62. my ($msg,$data);
  63. my (@servers) = Irssi::servers();
  64. if ($msg =~ /^\255\251\001/) {
  65. $msg = substr($text,3);
  66. } else {
  67. $msg = $text;
  68. }
  69. if ($msg =~ /^\-Auth/) {
  70. # my $cmd = "/MSG =". $dcc->{nick} . " +Auth ". auth($msg);
  71. $server = $servers[0];
  72. my $cmd = "+Auth ". auth($msg);
  73. $server->command("/MSG =". $dcc->{nick} . " ". $cmd);
  74. # $dcc->send("$cmd");
  75. # send +Auth auth($msg);
  76. }
  77. };
  78. #Irssi::settings_add_str('auth', 'auth_password', '');
  79. Irssi::settings_add_str('auth', 'auth_secpass', '');
  80. Irssi::settings_add_str('auth', 'auth_authkey', '');
  81. Irssi::command_bind("auth", "cmd_auth");
  82. Irssi::print "Wraith authorization script by bryan loaded.";