<commit_before>package core;

import org.apache.commons.configuration.ConfigurationException;
import shared.MsgEvent;
import shared.MsgEventType;
import shared.PluginInterface;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.*;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Enumeration;
import java.util.Map;

public class CommandExec {

	public CommandExec()
	{

	}

	public MsgEvent cmdExec(MsgEvent ce) throws IOException, ConfigurationException {

        try {

            if (ce.getMsgType() == MsgEventType.CONFIG) //this is only for controller detection
            {
                //create for initial discovery
                if ((ce.getMsgBody() != null) && (ce.getParam("set_region") != null) && (ce.getParam("set_agent") != null)) {
                    if (ce.getMsgBody().equals("comminit")) {
                        if (Boolean.parseBoolean(ce.getParam("is_active"))) {
                            AgentEngine.region = ce.getParam("set_region");
                            AgentEngine.config.setRegionName(AgentEngine.region);
                            AgentEngine.agent = ce.getParam("set_agent");
                            AgentEngine.config.setAgentName(AgentEngine.agent);
                            AgentEngine.isCommInit = true;
                            if (Boolean.parseBoolean(ce.getParam("is_regional_controller"))) {
                                AgentEngine.isRegionalController = true;
                            }
                            System.out.println("REGION NAME:[" + AgentEngine.config.getRegion() + "]");
                            System.out.println("REGION CONTROLLER:[" + AgentEngine.isRegionalController + "]");
                            System.out.println("AGENT NAME:[" + AgentEngine.config.getAgentName() + "]");
                            return null;
                        }
                    }
                }
                        else if (ce.getParam("configtype").equals("pluginadd")) {
                            Map<String, String> hm = AgentEngine.pluginsconfig.buildPluginMap(ce.getParam("configparams"));

                            hm.remove("configtype");
                            String plugin = AgentEngine.pluginsconfig.addPlugin(hm);
                            ce.setParam("plugin", plugin);
                            boolean isEnabled = AgentEngine.enablePlugin(plugin, false);
                            if (!isEnabled) {
                                ce.setMsgBody("Failed to Add Plugin:" + plugin);
                                AgentEngine.pluginsconfig.removePlugin(plugin);
                            } else {
                                ce.setMsgBody("Added Plugin:" + plugin);
                            }
                            return ce;
                        } else if (ce.getParam("configtype").equals("plugininventory")) {
                            String pluginList = "";
                            File jarLocation = new File(AgentEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
                            String parentDirName = jarLocation.getParent(); // to get the parent dir name

                            File folder = new File(parentDirName + "/plugins");
                            if (folder.exists()) {
                                File[] listOfFiles = folder.listFiles();

                                for (int i = 0; i < listOfFiles.length; i++) {
                                    if (listOfFiles[i].isFile()) {
                                        System.out.println("Found Plugin: " + listOfFiles[i].getName());
                                        pluginList = pluginList + listOfFiles[i].getName() + ",";<commit_msg>You are not wrong, just an ahole<commit_after>package core;

import org.apache.commons.configuration.ConfigurationException;
import shared.MsgEvent;
import shared.MsgEventType;
import shared.PluginInterface;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.*;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Enumeration;
import java.util.Map;

public class CommandExec {

	public CommandExec()
	{

	}

	public MsgEvent cmdExec(MsgEvent ce) throws IOException, ConfigurationException {

        try {

            if (ce.getMsgType() == MsgEventType.CONFIG) //this is only for controller detection
            {
                //create for initial discovery
                if ((ce.getMsgBody() != null) && (ce.getParam("set_region") != null) && (ce.getParam("set_agent") != null)) {
                    if (ce.getMsgBody().equals("comminit")) {
                        if (Boolean.parseBoolean(ce.getParam("is_active"))) {
                            AgentEngine.region = ce.getParam("set_region");
                            AgentEngine.config.setRegionName(AgentEngine.region);
                            AgentEngine.agent = ce.getParam("set_agent");
                            AgentEngine.config.setAgentName(AgentEngine.agent);
                            AgentEngine.isCommInit = true;
                            if (Boolean.parseBoolean(ce.getParam("is_regional_controller"))) {
                                AgentEngine.isRegionalController = true;
                            }
                            System.out.println("REGION NAME:[" + AgentEngine.config.getRegion() + "]");
                            System.out.println("REGION CONTROLLER:[" + AgentEngine.isRegionalController + "]");
                            System.out.println("AGENT NAME:[" + AgentEngine.config.getAgentName() + "]");

                        }
                    }
                    return null;
                }
                        else if (ce.getParam("configtype").equals("pluginadd")) {
                            Map<String, String> hm = AgentEngine.pluginsconfig.buildPluginMap(ce.getParam("configparams"));

                            hm.remove("configtype");
                            String plugin = AgentEngine.pluginsconfig.addPlugin(hm);
                            ce.setParam("plugin", plugin);
                            boolean isEnabled = AgentEngine.enablePlugin(plugin, false);
                            if (!isEnabled) {
                                ce.setMsgBody("Failed to Add Plugin:" + plugin);
                                AgentEngine.pluginsconfig.removePlugin(plugin);
                            } else {
                                ce.setMsgBody("Added Plugin:" + plugin);
                            }
                            return ce;
                        } else if (ce.getParam("configtype").equals("plugininventory")) {
                            String pluginList = "";
                            File jarLocation = new File(AgentEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
                            String parentDirName = jarLocation.getParent(); // to get the parent dir name

                            File folder = new File(parentDirName + "/plugins");
                            if (folder.exists()) {
                                File[] listOfFiles = folder.listFiles();

                                for (int i = 0; i < listOfFiles.length; i++) {
                                    if (listOfFiles[i].isFile()) {
                                        System.out.println("Found Plugin: " + listOfFiles[i].getName());
                                        pluginList = pluginList + listOfFiles[i].getName() + ",";
{'fraction_non_alphanumeric': 0.10727320125130343, 'fraction_numerical': 0.00026068821689259646, 'mean_word_length': 1.4608723540731239, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1063298', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1744, 'n_words': 326}