<commit_before><?php

include_once (ROOT_DIR . '/lib/DDoSDefinitionManager.php');
include_once (ROOT_DIR . '/lib/RouterManager.php');
include_once (ROOT_DIR . '/lib/ACLManager.php');
include_once (ROOT_DIR . '/lib/ActionManager.php');
include_once (ROOT_DIR . '/lib/MailAlertManager.php');
include_once (ROOT_DIR . '/lib/cli/CLIOutput.php');

class CLICreate {

    protected $cli;

    public function __construct() {
        $this->cli = new CLIOutput();
    }

    public function createExclusion($argv) {
        $actionmgr = new ActionManager();

        if ($actionmgr->createExcludedAction($argv[3], $argv[4])) {
            echo("OK\n");
        }
    }

    public function createDefinition($argv) {
        $defmgr = new DDoSDefinitionManager();

        if ($defmgr->createDDoSDefinition($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8])) {
            echo("OK\n");
        }
    }
    
    public function createThreshold($argv) {
        $defmgr = new DDoSDefinitionManager();

        if ($defmgr->createDDoSThreshold($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9], $argv[10])) {
            echo("OK\n");
        }
    }

    public function createRouter($argv) {
        $routermgr = new RouterManager();

        if ($routermgr->createRouter($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9], $argv[10])) {
            echo("OK\n");
        }
    }

    public function createACL($argv) {
        $aclmgr = new ACLManager();

        if ($aclmgr->createACL($argv[3], $argv[4], $argv[5], $argv[6], $argv[7])) {
            echo("OK\n");
        }
    }

    public function createAction($argv) {
        $split = explode(';', $argv[5]);
        foreach ($split as $s) {
            $res = explode('=', $s);
            $parameters[$res[0]] = $res[1];
        }

        $actionmgr = new ActionManager();

        if ($actionmgr->createAction($argv[3], $argv[4], $parameters, $argv[6])) {
            echo("OK\n");
        }
    }
    
    public function createMailAlert($argv){
        $mailmgr = new MailAlertManager();<commit_msg>Add input validation for ACL types<commit_after><?php

include_once (ROOT_DIR . '/lib/DDoSDefinitionManager.php');
include_once (ROOT_DIR . '/lib/RouterManager.php');
include_once (ROOT_DIR . '/lib/ACLManager.php');
include_once (ROOT_DIR . '/lib/ActionManager.php');
include_once (ROOT_DIR . '/lib/MailAlertManager.php');
include_once (ROOT_DIR . '/lib/cli/CLIOutput.php');

class CLICreate {

    protected $cli;

    public function __construct() {
        $this->cli = new CLIOutput();
    }

    public function createExclusion($argv) {
        $actionmgr = new ActionManager();

        if ($actionmgr->createExcludedAction($argv[3], $argv[4])) {
            echo("OK\n");
        }
    }

    public function createDefinition($argv) {
        $defmgr = new DDoSDefinitionManager();

        if ($defmgr->createDDoSDefinition($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8])) {
            echo("OK\n");
        }
    }
    
    public function createThreshold($argv) {
        $defmgr = new DDoSDefinitionManager();

        if ($defmgr->createDDoSThreshold($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9], $argv[10])) {
            echo("OK\n");
        }
    }

    public function createRouter($argv) {
        $routermgr = new RouterManager();

        if ($routermgr->createRouter($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9], $argv[10])) {
            echo("OK\n");
        }
    }

    public function createACL($argv) {
        $aclmgr = new ACLManager();
        
        if(!($argv[5] == "protected" || $argv[5] == "outside")){
            echo("Cannot add ACL, type must be either \"protected\" or \"outside\"\n");
            return false;
        }

        if ($aclmgr->createACL($argv[3], $argv[4], $argv[5], $argv[6], $argv[7])) {
            echo("OK\n");
        }
    }

    public function createAction($argv) {
        $split = explode(';', $argv[5]);
        foreach ($split as $s) {
            $res = explode('=', $s);
            $parameters[$res[0]] = $res[1];
        }

        $actionmgr = new ActionManager();

        if ($actionmgr->createAction($argv[3], $argv[4], $parameters, $argv[6])) {
            echo("OK\n");
        }
    }
    
    public function createMailAlert($argv){
        $mailmgr = new MailAlertManager();
{'fraction_non_alphanumeric': 0.18796652341099299, 'fraction_numerical': 0.01719068084143859, 'mean_word_length': 2.5603864734299515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '473540', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1455, 'n_words': 276}