Anope IRC Services

Anope Development => Modules => Topic started by: Jan Milants on January 12, 2011, 11:30:00 PM

Title: misc_sqlcmd + Anope PHP API
Post by: Jan Milants on January 12, 2011, 11:30:00 PM
For whatever reason (probably to give ppl something to get them to stop moaning ::)) I decided to give heinz's old misc_sqlcmd module an update to support latest anope 1.8 and make it work a bit better.. maybe even add a simple example PHP class for interfacing with it.. it depends on whether that ll be to any use to anyone.

I've spend most of the spare time I had the last couple of days on this and am nearing completion (without any form of testing as of yet though :-[) so now I'd need to know if anyone ever even used it and what they think was missing.. I won't be implementing anope's entire API, nor will I spend time on stuff that ll not be used so I will only be adding things as they are requested.

Keep in mind it won't be exactly the same as the old module.. I've removed some stuff too, mainly things I think would be better off being checked before sending the command to anope. Incoming data is still validated, but for example for access list changes, rights aren't checked, that s up to the called.. keeps the module a bit slimmer :)

This is not meant as a replacement for the live-sql being implemented in 1.9, not do I personally like the design very much (XML-RPC FTW 8)) but this is the quickest and easiest to do send some kind of updates to anope in 1.8.. it also helped that the old misc_sqlcmd module was more or less working whereas there s no working xml-rpc module to be found  ::)
Title: Re: misc_sqlcmd update [v.3.0.0]
Post by: Jan Milants on January 14, 2011, 09:05:16 PM
First release is available on modules site: (

Basic functionality has been tested, but as I have no intention of actually using this module myself - I don't even own a network any more these days - I will have to rely on user feedback to locate and fix and remaining bugs.
So no point in waiting and hoping for a version with less bugs (ideally, it's already bug free :) ) as without input and proof I'm not wasting my time by doing this no further changes will be made..  ::)
Title: Re: misc_sqlcmd update
Post by: Luke on January 23, 2011, 06:39:15 PM
Hi, the module sounds like a good one. I would like to use it but there is no support for windows atm. So if possible if you dont mind could you compile it for windows?
Title: Re: misc_sqlcmd update
Post by: katsklaw on January 24, 2011, 01:52:27 AM
Hi, the module sounds like a good one. I would like to use it but there is no support for windows atm. So if possible if you dont mind could you compile it for windows?

I find it worth the extra resources to learn how and install all the software needed to compile myself since it's likely you can and will run into this scenario again. Likely the next time you want a module.

Compiling isn't hard and is well documented.
Title: Re: misc_sqlcmd update
Post by: Jan Milants on January 24, 2011, 08:14:35 AM
I thought someone on irc mentioned it didn't compile on windows.. though I am not sure whether he had installed and compiled anope with mysql support.. something this module obviously requires...

That said, windows support isn't a priority atm... I might look into it when packing the next release if doesn't require any major changes.. so far haven't had much feedback though so no telling when there ll be something worth releasing...
Title: misc_sqlcmd update + PHP API
Post by: Jan Milants on April 04, 2011, 10:14:23 PM
I released 3.1.0 to the modules site.

The people that I know use this module have been using GIT for a while so it should be stable though be aware a number of things changes:
 - lots of fixes..
 - table structure
 - handling of passwords..
Check the updated documentation for the new command syntax and I refer to the GIT history for a more detailed changes list.

Probably the most important change though: as of now there is a fully implemented PHP API to wrap the commands supported by the module. I have not yet had the chance to write some example code or a manual for it, but the code is well documented so it shouldn't be so hard to figure out.

The API can be found in my GIT (;a=summary) and until I ve got a chance to write some examples I won't make any actual "release" of that codebase...
Find the generated PHP documentation here (

To get started, you won't need to know the inner workings of the entire API, the wrappers can be found in the *Serv classes or if you want to skip the validation parts, the AnopeWriter class. (For reading anopes DB cf. AnopeReader..)

Note that unlike the module itself the PHP API is not yet considered very stable so pls report any issues..
Title: Re: misc_sqlcmd + Anope PHP API
Post by: shaggy on September 09, 2011, 03:26:46 AM
Sorry to dig up an old thread but I thought it might be useful for some.

I've quickly zipped up the files needed to get this to work and function right. I've also included an example/explanation file which should hopefully help anyone who is having trouble.

As long as the module is setup and installed correctly the script is almost ready to go. You just need to update some configuration and it'll be working like a charm.

Download: (

Hope it helps and good luck to all!
Title: Re: misc_sqlcmd + Anope PHP API
Post by: luc on January 13, 2014, 05:37:46 PM
Can someone please be so nick to give me an example sql for nick register ??

the mediafire link is down
Title: Re: misc_sqlcmd + Anope PHP API
Post by: Jan Milants on January 14, 2014, 09:05:57 AM
The following is a short bit of example code for using the full high level API..
Code: [Select]


/* 0 - Include the API.. */
require_once "Class/";

/* 1 - Configure the Anope PHP API.. */
AnopeConfig::$StrictPasswords true;
AnopeConfig::$RestrictOperNicks false;
AnopeConfig::$NSForceEmail false;
AnopeConfig::$NSMaxAliases 8;
AnopeConfig::$NSNoGroupChange false;
AnopeConfig::$NSGuestNickPrefix "Guest";
AnopeConfig::$NSSecureAdmins true;
AnopeConfig::$CSAccessMax 50;
AnopeConfig::$ServicesRoot "Viper";

/* 2 - Create an instance of the AnopeWriter so we can read and write from and to anopes DB
 * If you only neeed to read, create an AnopeReader instead. 
 * We pass along encryption type, db name, salt, db host and user & pass to connect to sqb server */
$writer = new AnopeWriter('None''anope''qd9sd1DS23hW$Q''''admin''admin');

/* 3 - Tell the high level Anope functions which database connector to use..
 * in this case we use the writer we have just created.. */

/* So now, lets login with Username 'Viper' and password 'viper'.. */
$user NickServ::identify("Viper""viper");

// If we got a user instance, login was successfull.. if we got a number, it s an error code..
if (is_object($user)) {
echo "Login success. User: " $user->display '<br>';
// Store the user in the session.. this should be kept until the user logs out.
$_SESSION['user'] = $user;

/* Now that we are logged in, lets make botserv say something on a channel.. */
$ret BotServ::say($user"#services""It works fine..");
if ($ret 0) {
// It s a command ID.. command was inserted into the DB and will be parsed by anope shortly.
echo "Success. Command id: $ret. <br>";
} else {
// If it s a negative number, it s an error code.
echo "Failure. Error code: $ret. <br>";
} else {
echo "Login failed: $user";

// Register a nickname test..
$cmd_id NickServ::register("test""testing");
"command to register 'test' inserted with id $cmd_id. <br>";

This uses the classes and other utils I build around the module.. you could also only use the functions that directly insert the commands, bypassing the checks done in the high level API (eg, with nick register it would first check whether the nick isn't already registered), but you would have to make sure you handle the possible error cases in your code.

directly inserting the commands would be done through the AnopeWriter class:
(Note that step 1 & 2 as shown in the code sample above must be run as well to configure the API and)
Code: [Select]
/*Include the API.. */
require_once "Class/";

/* Create an in[url]stan[/url]ce of the AnopeWriter so we can read and write from and to anopes DB
 * If you only neeed to read, create an AnopeReader instead. 
 * We pass along encryption type, db name, salt, db host and user & pass to connect to sqb server */
$writer = new AnopeWriter('None''anope''qd9sd1DS23hW$Q''''admin''admin');

$nick 'test';
$pass 'testing';

I hope that gives an idea of his to use the functions.. note that everything is documented in code..
The documentation generated for the classes and functions here ( should help, but you can just as well take a quick look at the code in eclipse..

edit: Added Autoloader::init() call which is now required..