Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: misc_sqlcmd + Anope PHP API  (Read 10450 times)

0 Members and 1 Guest are viewing this topic.

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
misc_sqlcmd + Anope PHP API
« 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  ::)
« Last Edit: April 04, 2011, 10:18:19 PM by Jan Milants »
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: misc_sqlcmd update [v.3.0.0]
« Reply #1 on: January 14, 2011, 09:05:16 PM »

First release is available on modules site: http://modules.anope.org/index.php?page=view&id=82.

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..  ::)
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Luke

  • Anope User
  • Offline Offline
  • Posts: 1
Re: misc_sqlcmd update
« Reply #2 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?
Thanks
Logged

katsklaw

  • Supporter
  • Anope User
  • Offline Offline
  • Posts: 537
Re: misc_sqlcmd update
« Reply #3 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?
Thanks

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. http://wiki.anope.org/index.php/Windows:1.8#Compiling
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: misc_sqlcmd update
« Reply #4 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...
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
misc_sqlcmd update + PHP API
« Reply #5 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 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..
« Last Edit: April 05, 2011, 12:48:36 PM by Jan Milants »
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

shaggy

  • Anope User
  • Offline Offline
  • Posts: 1
Re: misc_sqlcmd + Anope PHP API
« Reply #6 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: anope_sqlcmd_PHP_HELP.zip

Hope it helps and good luck to all!
Logged

luc

  • Anope User
  • Offline Offline
  • Posts: 3
Re: misc_sqlcmd + Anope PHP API
« Reply #7 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
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: misc_sqlcmd + Anope PHP API
« Reply #8 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]
<?php

session_start
();

/* 0 - Include the API.. */
require_once "Class/Autoloader.inc.php";
Autoloader::init();
Autoloader::inclDir("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''127.0.0.1''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.. */
NickServ::init($writer);

/* 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");
echo 
"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]
<?php
/*Include the API.. */
require_once "Class/Autoloader.inc.php";
Autoloader::init();
Autoloader::inclDir("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''127.0.0.1''admin''admin');

$nick 'test';
$pass 'testing';
$email'viper@anope.org';
$writer->regNick($nick$pass$email);
$>

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..
« Last Edit: January 16, 2014, 03:19:11 PM by Jan Milants »
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)
Pages: [1]   Go Up