コード例 #1
0
ファイル: querylog.py プロジェクト: BiohZn/sbncng
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

from time import time
from datetime import datetime
from sbnc.plugin import Plugin, ServiceRegistry
from sbnc.event import Event
from sbnc.irc import match_command
from sbnc.proxy import Proxy
from plugins.ui import UIPlugin

proxy_svc = ServiceRegistry.get(Proxy.package)
ui_svc = ServiceRegistry.get(UIPlugin.package)

class QueryLogPlugin(Plugin):
    """Implements query log functionality."""
    
    package = 'info.shroudbnc.plugins.querylog'
    name = 'querylog'
    description = __doc__

    def __init__(self):
        proxy_svc.irc_command_received_event.add_listener(self._irc_privmsg_handler,
                                                          Event.PostObserver,
                                                          filter=match_command('PRIVMSG'))

        # register a client login handler so we can notify users about new messages
コード例 #2
0
ファイル: admincmd.py プロジェクト: BiohZn/sbncng
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

import string
import random
from sbnc.proxy import Proxy
from sbnc.plugin import Plugin, ServiceRegistry
from plugins.ui import UIPlugin, UIAccessCheck

proxy_svc = ServiceRegistry.get(Proxy.package)
ui_svc = ServiceRegistry.get(UIPlugin.package)


class AdminCommandPlugin(Plugin):
    """Implements basic admin commands."""

    package = "info.shroudbnc.plugins.admincmd"
    name = "AdminCmd"
    description = __doc__

    def __init__(self):
        ui_svc.register_command(
            "adduser",
            self._cmd_adduser_handler,
            "Admin",
コード例 #3
0
ファイル: sbncng.py プロジェクト: BiohZn/sbncng
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

try:
    import pydevd

    # Try to enable post-mortem debugging for exceptions
    pydevd.set_pm_excepthook()
except ImportError:
    pass

from sbnc.irc import ClientListener
from sbnc.proxy import Proxy
from sbnc.directory import DirectoryService
from sbnc.plugin import ServiceRegistry

dir_svc = ServiceRegistry.get(DirectoryService.package)
dir_svc.start('sqlite:///sbncng.db')
config_root = dir_svc.get_root_node()

proxy_svc = ServiceRegistry.get(Proxy.package)

print('sbncng (' + proxy_svc.version + ') - an object-oriented IRC bouncer')

proxy_svc.start(config_root)

execfile('plugins/plugin101.py')
execfile('plugins/ui.py')
execfile('plugins/awaycmd.py')
execfile('plugins/admincmd.py')
execfile('plugins/querylog.py')
コード例 #4
0
ファイル: ui.py プロジェクト: BiohZn/sbncng
class UIAccessCheck(object):
    """Helper functions for checking users' access."""

    @staticmethod
    def anyone(clientobj):
        """Returns True for any user."""

        return True

    @staticmethod    
    def admin(clientobj):
        """Returns True for any user who is an admin."""
 
        return clientobj.owner.admin

proxy_svc = ServiceRegistry.get(Proxy.package)

class UIPlugin(Plugin):
    """User interface plugin. Provides support for /msg -sBNC <command> and /sbnc <command>"""

    package = 'info.shroudbnc.plugins.ui'
    name = 'UIPlugin'
    description = __doc__

    _identity = '[email protected]'

    def __init__(self):
        self.commands = {}
        self.settings = {}
        self.usersettings = {}
        
コード例 #5
0
ファイル: directory.py プロジェクト: BiohZn/sbncng
 def init_on_load(self):
     dir_svc = ServiceRegistry.get(DirectoryService.package)
     self._session = dir_svc.get_session()
コード例 #6
0
ファイル: directory.py プロジェクト: BiohZn/sbncng
    def __init__(self):
        self._session = None
    
    def start(self, dsn, debug=False):
        """Initializes a database connection for the specified connection string."""
    
        engine = create_engine(dsn, echo=debug)
    
        metadata = _ModelBase.metadata
        metadata.create_all(engine)
    
        SessionClass = sessionmaker(bind=engine)
    
        self._session = SessionClass()
    
        try:
            root = self._session.query(Node).filter_by(name='root', parent=None).one()
        except NoResultFound:
            root = Node('root')
            self._session.add(root)
    
        self._root_node = root
    
    def get_session(self):
        return self._session
    
    def get_root_node(self):
        return self._root_node

ServiceRegistry.register(DirectoryService)
コード例 #7
0
ファイル: awaycmd.py プロジェクト: BiohZn/sbncng
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

from sbnc.plugin import Plugin, ServiceRegistry
from sbnc.proxy import Proxy
from sbnc.event import Event

proxy_svc = ServiceRegistry.get(Proxy.package)

class AwayCommandPlugin(Plugin):
    """Provides the 'away' setting and related functionality."""
    
    package = 'info.shroudbnc.plugins.awaycmd'
    name = 'awaycmd'
    description = __doc__

    def __init__(self):
        proxy_svc.client_registration_event.add_listener(self._client_registration_handler,
                                                         Event.PostObserver)

        proxy_svc.client_connection_closed_event.add_listener(self._client_closed_handler,
                                                       Event.PostObserver)
コード例 #8
0
ファイル: proxy.py プロジェクト: BiohZn/sbncng
        return Event.Handled

    def check_password(self, password):
        return password != None and self._config.get('password', None) == password

    def _get_last_reconnect(self):
        return self._config.get('last_reconnect', None)
    
    def _set_last_reconnect(self, value):
        self._config.set('last_reconnect', value)

    last_reconnect = property(_get_last_reconnect, _set_last_reconnect)
    
    def _get_password(self):
        return self._config.get('password', None)
    
    def _set_password(self, value):
        self._config.set('password', value)

    password = property(_get_password, _set_password)

    def _get_admin(self):
        return self._config.get('admin', None)
    
    def _set_admin(self, value):
        self._config.set('admin', value)

    admin = property(_get_admin, _set_admin)

ServiceRegistry.register(Proxy)