To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

DNS/Source: Difference between revisions

From ZNC
< DNS
Jump to navigation Jump to search
>Resistance
Restored from the code on the author's site.
 
>Efreak
m Changed header text, versions on all my modules.
Line 1: Line 1:
<pre>/*
<pre>/*
  * Copyright (C) 2004-2009  See the AUTHORS file for details.
  * Copyright (C) 2010 Efreak.
  *
  *
  * This program is free software; you can redistribute it and/or modify it
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
  * under the terms of the GNU General Public License version 2 as published
  * by the Free Software Foundation.
  * by the Free Software Foundation.  
  *
  *  
  * This module mostly coded by Efreak, with the class definition & lastseen code
  * If any other changes are made, update the version number to the latest ZNC
  * borrowed from lastseen & modified, and the rehash borrowed from ClientCommands & modified.
* version to reflect it, please. This makes things easier to know what
* version it works with; If you want to contribute code, let me know via IRC
  * and I'll ad you as a contributor on GitHub.
* -Efreak
  */
  */


Line 55: Line 58:
// PutModule("ToDo: allow this module to override znc's dns resolution to deny users access to specific servers (can this be done?")
// PutModule("ToDo: allow this module to override znc's dns resolution to deny users access to specific servers (can this be done?")
// PutModule("1.0 - initial version");
// PutModule("1.0 - initial version");
PutModule("2.0 - changed around resolve code to fix a crashing error when host doesnt resolve");
// PutModule("2.0 - changed around resolve code to fix a crashing error when host doesnt resolve");
PutModule("0.01 - changed version number to a different scheme");
}
}
}
}
Line 64: Line 68:
};
};


GLOBALMODULEDEFS(CDNSMod, "DNS Resolver.");</pre>
GLOBALMODULEDEFS(CDNSMod, "DNS Resolver. Version 0.01");</pre>
[[Category:Modules/Code]]

Revision as of 18:46, 31 August 2012

/*
 * Copyright (C) 2010 Efreak.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation. 
 * 
 * If any other changes are made, update the version number to the latest ZNC
 * version to reflect it, please. This makes things easier to know what
 * version it works with; If you want to contribute code, let me know via IRC
 * and I'll ad you as a contributor on GitHub.
 * -Efreak
 */




#include "User.h"
#include "IRCSock.h"
#include "znc.h"
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h> 
#include <arpa/inet.h>

using std::map;

class CDNSMod : public CGlobalModule {
public:
	GLOBALMODCONSTRUCTOR(CDNSMod) {}
   
	virtual ~CDNSMod() {}
   
	virtual void OnModCommand(const CString& sLine) {
		CString sCommand = sLine.Token(0).AsLower();
		CString tk2 = sLine.Token(1).AsLower(); 
      
/*
 *   DNS Resolution
 */
		if(sCommand=="dns"||sCommand=="resolve") {
			hostent * record = gethostbyname(tk2.c_str());
			if(record == NULL) {
				PutModule(tk2 + "%s is unavailable.");
			} else {
				in_addr * address = (in_addr * )record->h_addr;
				CString ip_address = CString(inet_ntoa(* address));
				PutModule(tk2 + " resolves to: " + ip_address + ".");
			}
		}
/*
 *   Help command (todo: implement token-based help)
 */
		else if (sCommand == "help") {
			PutModule("DNS: This module includes a DNS resolver. Usage: dns/resolve hostname Ex: dns localhost");
			PutModule("      message. Prefix defaults to 'ZNC Global Message: ', and can be changed by the arguments.");
//			PutModule("ToDo: allow this module to override znc's dns resolution to deny users access to specific servers (can this be done?")
//			PutModule("1.0 - initial version");
//			PutModule("2.0 - changed around resolve code to fix a crashing error when host doesnt resolve");
			PutModule("0.01 - changed version number to a different scheme");
		}
	}
   
protected:
   
private:
};

GLOBALMODULEDEFS(CDNSMod, "DNS Resolver. Version 0.01");