Added ssl fingerprint support for testing purposes
[jimb.git] / services / actions.php
blob3e888050014b09c1e5a2f050e2ba5d37652b865a
1 <?php
2 /**
3 * JIMBS (Jabber Instant Messaging Bot Services)
4 * Copyright (C) 2010 Martin Kelm
5 * This file is part of JIMB.
7 * JIMB is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * JIMB is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with JIMB; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * @file Services actions
22 * @package JIMB
23 * @subpackage Services
24 * @author Martin Kelm <martinkelm@idxsolutions.de>
25 * @copyright 2010 Martin Kelm
28 require_once(dirname(__FILE__).'/database.cfg.php');
29 require_once(dirname(__FILE__).'/database.class.php');
30 require_once(dirname(__FILE__).'/inputParser.class.php');
31 require_once(dirname(__FILE__).'/mods/modDates.php');
32 require_once(dirname(__FILE__).'/mods/modReminders.php');
33 require_once(dirname(__FILE__).'/mods/modDictionary.php');
35 $database = database::getInstance();
36 $database->setConnectionData(
37 $databaseCfg['host'], $databaseCfg['user'], $databaseCfg['pass'], $databaseCfg['db']
39 if ($database->connect()) {
40 $inputParser = new inputParser();
41 $mods = array();
42 $mods['dates'] = new modDates($database);
43 $mods['reminders'] = new modReminders($database);
44 $mods['dictionary'] = new modDictionary();
45 $modKeys = array_keys($mods);
47 $msgs = array();
49 $res = $database->query("SELECT jid, message FROM queue_in");
50 if ($res) {
51 while ($row = $res->fetch_assoc()) {
52 $parsed = $inputParser->parseInput($row['message'], $row['jid']);
53 if ($parsed['module'] !== NULL && $parsed['command'] !== NULL) {
54 if (isset($mods[$parsed['module']])) {
55 $result = $mods[$parsed['module']]->perform($parsed, $row['jid']);
56 if (!empty($result)) {
57 $msgs[$row['jid']][] = $result;
63 $res = $database->query("TRUNCATE TABLE queue_in");
64 if (is_array($msgs) && count($msgs) > 0) {
65 foreach ($msgs as $jid => $jidMsgs) {
66 if (is_array($jidMsgs) && count($jidMsgs) > 0) {
67 foreach ($jidMsgs as $msg) {
68 $sql = sprintf(
69 "INSERT INTO queue_out (jid, message) VALUES ('%s', '%s')",
70 $jid, $msg
72 $database->query($sql);
78 $database->close();