]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_sslinfo.cpp
86af1d6148c3849b89551cb6dd92ef705a9a7ee7
[user/henk/code/inspircd.git] / src / modules / extra / m_sslinfo.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "transport.h"
16
17 /* $ModDesc: Provides /sslinfo command used to test who a mask matches */
18 /* $ModDep: transport.h */
19
20 /** Handle /SSLINFO
21  */
22 class CommandSSLInfo : public Command
23 {
24  public:
25         CommandSSLInfo (InspIRCd* Instance) : Command(Instance,"SSLINFO", 0, 1)
26         {
27                 this->source = "m_sslinfo.so";
28                 this->syntax = "<nick>";
29         }
30
31         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
32         {
33                 User* target = ServerInstance->FindNick(parameters[0]);
34                 ssl_cert* cert;
35
36                 if (target)
37                 {
38                         if (target->GetExt("ssl_cert", cert))
39                         {
40                                 if (cert->GetError().length())
41                                 {
42                                         user->WriteServ("NOTICE %s :*** Error:             %s", user->nick.c_str(), cert->GetError().c_str());
43                                 }
44                                 user->WriteServ("NOTICE %s :*** Distinguised Name: %s", user->nick.c_str(), cert->GetDN().c_str());
45                                 user->WriteServ("NOTICE %s :*** Issuer:            %s", user->nick.c_str(), cert->GetIssuer().c_str());
46                                 user->WriteServ("NOTICE %s :*** Key Fingerprint:   %s", user->nick.c_str(), cert->GetFingerprint().c_str());
47                                 return CMD_LOCALONLY;
48                         }
49                         else
50                         {
51                                 user->WriteServ("NOTICE %s :*** No SSL certificate information for this user.", user->nick.c_str());
52                                 return CMD_FAILURE;
53                         }
54                 }
55                 else
56                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nickname", user->nick.c_str(), parameters[0].c_str());
57
58                 return CMD_FAILURE;
59         }
60 };
61
62 class ModuleSSLInfo : public Module
63 {
64         CommandSSLInfo* newcommand;
65  public:
66         ModuleSSLInfo(InspIRCd* Me)
67                 : Module(Me)
68         {
69
70                 newcommand = new CommandSSLInfo(ServerInstance);
71                 ServerInstance->AddCommand(newcommand);
72
73         }
74
75
76         virtual ~ModuleSSLInfo()
77         {
78         }
79
80         virtual Version GetVersion()
81         {
82                 return Version("$Id$", VF_VENDOR, API_VERSION);
83         }
84 };
85
86 MODULE_INIT(ModuleSSLInfo)
87