<commit_before>#!/usr/bin/python
# archipelModuleHypervisorTest.py
# 
# Copyright (C) 2010 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# we need to import the package containing the class to surclass
import xmpp
import uuid
import os, commands
import re
from archipel.utils import *
import archipel.core



class TNXMPPServerController:
    
    def __init__(self, entity, exec_path, exec_user):
        """
        initialize the module
        @type entity TNArchipelEntity
        @param entity the module entity
        @type entity String
        @param entity the path of the ejabberdctl command
        """
        self.entity                 = entity
        self.ejabberdctl_path       = exec_path
        self.ejabberdctl_user       = exec_user
        
        # permissions
        self.entity.permission_center.create_permission("xmppserver_groups_create", "Authorizes user to create shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_delete", "Authorizes user to delete shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_list", "Authorizes user to list shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_addusers", "Authorizes user to add users in shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_deleteusers", "Authorizes user to remove users from shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_users_register", "Authorizes user to register XMPP users", False);
        self.entity.permission_center.create_permission("xmppserver_users_unregister", "Authorizes user to unregister XMPP users", False);
        self.entity.permission_center.create_permission("xmppserver_users_list", "Authorizes user to list XMPP users", False);
    
    
    def generate_command(self, command):
        """generate the ejabberdctl command"""
        return "su - %s -c '%s %s'" % (self.ejabberdctl_user, self.ejabberdctl_path, command)
    
    ### XMPP Processing for shared groups
    
    def process_groups_iq(self, conn, iq):
        """
        this method is invoked when a ARCHIPEL_NS_XMPPSERVER_GROUPS IQ is received.
        
        it understands IQ of type:
            - create
            - delete
            - list
            - addusers
            - deleteusers
        
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        action = self.entity.check_acp(conn, iq)
        self.entity.check_perm(conn, iq, action, -1, prefix="xmppserver_groups_")
        reply = None
        
        if      action == "create":         reply = self.iq_group_create(iq)
        elif    action == "delete":         reply = self.iq_group_delete(iq)
        elif    action == "list":           reply = self.iq_group_list(iq)
        elif    action == "addusers":       reply = self.iq_group_add_users(iq)
        elif    action == "deleteusers":    reply = self.iq_group_delete_users(iq)
        
        if (reply):
            conn.send(reply)
            raise xmpp.protocol.NodeProcessed
    
    
    def iq_group_create(self, iq):
        """
        create a new shared roster
        
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply       = iq.buildReply("result")
            groupID     = iq.getTag("query").getTag("archipel").getAttr("id")
            groupName   = iq.getTag("query").getTag("archipel").getAttr("name")
            groupDesc   = iq.getTag("query").getTag("archipel").getAttr("description")
            server      = self.entity.jid.getDomain()
            cmd         = self.generate_command("srg-create %s %s \"\'%s\'\" \"\'%s\'\" %s"  % (groupID, server, groupName, groupDesc, groupID))
            
            self.entity.log.debug("console command is : %s" % cmd)
            if os.system(cmd):
                raise Exception("EJABBERDCTL command error : %s" % cmd)
            <commit_msg>fix shared group creation. close #46<commit_after>#!/usr/bin/python
# archipelModuleHypervisorTest.py
# 
# Copyright (C) 2010 <NAME> <<EMAIL>>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# we need to import the package containing the class to surclass
import xmpp
import uuid
import os, commands
import re
from archipel.utils import *
import archipel.core



class TNXMPPServerController:
    
    def __init__(self, entity, exec_path, exec_user):
        """
        initialize the module
        @type entity TNArchipelEntity
        @param entity the module entity
        @type entity String
        @param entity the path of the ejabberdctl command
        """
        self.entity                 = entity
        self.ejabberdctl_path       = exec_path
        self.ejabberdctl_user       = exec_user
        
        # permissions
        self.entity.permission_center.create_permission("xmppserver_groups_create", "Authorizes user to create shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_delete", "Authorizes user to delete shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_list", "Authorizes user to list shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_addusers", "Authorizes user to add users in shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_groups_deleteusers", "Authorizes user to remove users from shared groups", False);
        self.entity.permission_center.create_permission("xmppserver_users_register", "Authorizes user to register XMPP users", False);
        self.entity.permission_center.create_permission("xmppserver_users_unregister", "Authorizes user to unregister XMPP users", False);
        self.entity.permission_center.create_permission("xmppserver_users_list", "Authorizes user to list XMPP users", False);
    
    
    def generate_command(self, command):
        """generate the ejabberdctl command"""
        return "su - %s -c '%s %s'" % (self.ejabberdctl_user, self.ejabberdctl_path, command)
    
    ### XMPP Processing for shared groups
    
    def process_groups_iq(self, conn, iq):
        """
        this method is invoked when a ARCHIPEL_NS_XMPPSERVER_GROUPS IQ is received.
        
        it understands IQ of type:
            - create
            - delete
            - list
            - addusers
            - deleteusers
        
        @type conn: xmpp.Dispatcher
        @param conn: ths instance of the current connection that send the stanza
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        """
        action = self.entity.check_acp(conn, iq)
        self.entity.check_perm(conn, iq, action, -1, prefix="xmppserver_groups_")
        reply = None
        
        if      action == "create":         reply = self.iq_group_create(iq)
        elif    action == "delete":         reply = self.iq_group_delete(iq)
        elif    action == "list":           reply = self.iq_group_list(iq)
        elif    action == "addusers":       reply = self.iq_group_add_users(iq)
        elif    action == "deleteusers":    reply = self.iq_group_delete_users(iq)
        
        if (reply):
            conn.send(reply)
            raise xmpp.protocol.NodeProcessed
    
    
    def iq_group_create(self, iq):
        """
        create a new shared roster
        
        @type iq: xmpp.Protocol.Iq
        @param iq: the received IQ
        
        @rtype: xmpp.Protocol.Iq
        @return: a ready to send IQ containing the result of the action
        """
        try:
            reply       = iq.buildReply("result")
            groupID     = iq.getTag("query").getTag("archipel").getAttr("id")
            groupName   = iq.getTag("query").getTag("archipel").getAttr("name")
            groupDesc   = iq.getTag("query").getTag("archipel").getAttr("description")
            server      = self.entity.jid.getDomain()
            cmd         = self.generate_command("srg-create %s %s \\\"%s\\\" \\\"%s\\\" %s"  % (groupID, server, groupName, groupDesc, groupID))
            
            self.entity.log.debug("console command is : %s" % cmd)
            if os.system(cmd):
                raise Exception("EJABBERDCTL command error : %s" % cmd)
            
{'fraction_non_alphanumeric': 0.09112078566366305, 'fraction_numerical': 0.001417434443656981, 'mean_word_length': 2.5215686274509803, 'pattern_counts': {'":': 10, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4888568', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2761, 'n_words': 829}