PageRenderTime 25ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/respond/client-scripts/challenge-xchat.pl

https://github.com/alyx/sporksircd
Perl | 137 lines | 77 code | 36 blank | 24 comment | 7 complexity | 19ac8329f1176d35990e180b151a174f MD5 | raw file
  1. #!/usr/bin/perl -w
  2. #
  3. # challenge-xchat.pl
  4. # Copyright (C) 2006 Lee Hardy <lee -at- leeh.co.uk>
  5. # Copyright (C) 2006 ircd-ratbox development team
  6. #
  7. # $Id$
  8. package IRC::XChat::ratboxchallenge;
  9. use IPC::Open2;
  10. use FileHandle;
  11. #########################
  12. # Configuration Variables
  13. #########################
  14. # respond_path: The absolute path to the "ratbox-respond" program.
  15. my $respond_path = "/home/leeh/respond/respond/ratbox-respond";
  16. # private key path: The absolute path to your private key.
  17. my $private_key_path = "/home/leeh/respond/private.key";
  18. ###################
  19. # END CONFIGURATION
  20. ###################
  21. #####################
  22. # Version Information
  23. #
  24. # 1.0 - Initial version
  25. # 1.1 - Avoid leaving zombie ratbox-respond processes around
  26. #
  27. #####################
  28. my $script_name = "ratbox-challenge";
  29. my $script_version = "1.1";
  30. my $script_descr = "CHALLENGE opering script for use with ircd-ratbox";
  31. Xchat::register($script_name, $script_version, $script_descr, "");
  32. Xchat::print("Loading $script_name $script_version - $script_descr\n");
  33. my $pkg == __PACKAGE__;
  34. my $challenge;
  35. my $keyphrase = "";
  36. Xchat::hook_server("740", "${pkg}::handle_rpl_rsachallenge2");
  37. Xchat::hook_server("741", "${pkg}::handle_rpl_endofrsachallenge2");
  38. my $challenge_options = {
  39. help_text => "Usage: /challenge <opername> [keyphrase]\n"
  40. };
  41. Xchat::hook_command("CHALLENGE", "${pkg}::handle_challenge", $challenge_options);
  42. sub handle_challenge
  43. {
  44. my $opername = $_[0][1];
  45. if(!$opername)
  46. {
  47. Xchat::print("Usage: /challenge <opername> [keyphrase]\n");
  48. return Xchat::EAT_ALL;
  49. }
  50. $challenge = "";
  51. $keyphrase = $_[0][2]
  52. if($_[0][2]);
  53. Xchat::command("QUOTE CHALLENGE $opername\n");
  54. return Xchat::EAT_ALL;
  55. }
  56. sub handle_rpl_rsachallenge2
  57. {
  58. my $reply = $_[0][3];
  59. # remove the initial ':'
  60. $reply =~ s/^://;
  61. $challenge .= $reply;
  62. return Xchat::EAT_ALL;
  63. }
  64. sub handle_rpl_endofrsachallenge2
  65. {
  66. my $pid;
  67. Xchat::print("ratbox-challenge: Received challenge, generating response..\n");
  68. if(! -x $respond_path)
  69. {
  70. Xchat::print("ratbox-challenge: Unable to execute respond from $respond_path\n");
  71. return Xchat::EAT_ALL;
  72. }
  73. if(! -r $private_key_path)
  74. {
  75. Xchat::print("ratbox-challenge: Unable to open $private_key_path\n");
  76. }
  77. unless($pid = open2(*Reader, *Writer, $respond_path, $private_key_path))
  78. {
  79. Xchat::print("ratbox-challenge: Unable to execute respond from $respond_path\n");
  80. return Xchat::EAT_ALL;
  81. }
  82. print Writer "$keyphrase\n";
  83. print Writer "$challenge\n";
  84. # done for safety.. this may be irrelevant in perl!
  85. $keyphrase =~ s/./0/g;
  86. $keyphrase = "";
  87. $challenge =~ s/./0/g;
  88. $challenge = "";
  89. my $output = scalar <Reader>;
  90. chomp($output);
  91. waitpid $pid, 0;
  92. if($output =~ /^Error:/)
  93. {
  94. Xchat::print("ratbox-challenge: $output\n");
  95. return Xchat::EAT_ALL;
  96. }
  97. Xchat::print("ratbox-challenge: Received response, opering..\n");
  98. Xchat::command("QUOTE CHALLENGE +$output");
  99. return Xchat::EAT_ALL;
  100. }
  101. 1;