<commit_before><?php
// lib/php/plugins/dkim.php 20180511 - 20180511
// Copyright (C) 2015-2018 <NAME> <<EMAIL>> (AGPL-3.0)

class Plugins_Dkim extends Plugin
{
    protected
    $in = [
        'domain'    => '',
        'selector'  => 'dkim',
        'bits'      => '1024',
    ];

    public function create() : string
    {
error_log(__METHOD__);

        if ($_POST) {
error_log('this->in='.var_export($this->in,true));
            // check if domain is in vhosts
            extract($this->in);
            exec("sudo dkim add $selector $domain $bits 2>&1", $retArr, $retVal);
            util::log('<pre>' . trim(implode("\n", $retArr)) . '</pre>', $retVal ? 'danger' : 'success');
        }
        return $this->list();
    }

    public function list() : string
    {
error_log(__METHOD__);

//        $retArr = []; $retVal = null;
        exec("sudo dkim show 2>&1", $retArr, $retVal);
        $buf = '';
        $cnt = count($retArr);
        for($i = 0; $i < $cnt; $i++) {
            $buf .= ($i % 2 == 0) ? '
        <b>'.$retArr[$i].'</b><br>' : '
        <div style="word-break:break-all;font-family:monospace;width:100%;">' . $retArr[$i] . '</div><hr>';
        }
        return $this->t->list(['buf' => $buf]);
    }

}

?><commit_msg>Matched up plugins/dkim.php with sh dkim changes<commit_after><?php
// lib/php/plugins/dkim.php 20180511 - 20180515
// Copyright (C) 2015-2018 <NAME> <<EMAIL>> (AGPL-3.0)

class Plugins_Dkim extends Plugin
{
    protected
    $in = [
        'dnstxt'  => '',
        'domain'  => '',
        'keylen'  => '1024',
        'select'  => 'dkim',
    ];

    public function create() : string
    {
error_log(__METHOD__);

        if (util::is_post()) {
error_log('this->in='.var_export($this->in,true));

            extract($this->in);
            exec("sudo dkim add $domain $select $keylen 2>&1", $retArr, $retVal);
            util::log('<pre>' . trim(implode("\n", $retArr)) . '</pre>', $retVal ? 'danger' : 'success');
        }
        return $this->list();
    }

     public function read() : string
    {
error_log(__METHOD__);

error_log(var_export($this->in, true));

        $buf = '';
        [$select, $domain] = explode('._domainkey.', $this->in['dnstxt']);
error_log('select='.$select.', domain='.$domain);

        exec("sudo dkim show $domain 2>&1", $retArr, $retVal);
        $buf .= '
        <b>' . $retArr[0] . '</b>
        <a href="?o=dkim&m=delete&dnstxt=' . $retArr[0] . '" title="Remove DKIM" onClick="javascript: return confirm(\'Are you sure you want to remove: ' . $retArr[0] . '?\')">
          <i class="fas fa-trash fa-fw cursor-pointer text-danger"></i>
        </a><br>
        <div style="word-break:break-all;font-family:monospace;width:100%;">' . $retArr[1] . '</div>';
        return $this->t->list(['buf' => $buf]);
    }

    public function list() : string
    {
error_log(__METHOD__);

        $buf = '';
        exec("sudo dkim show 2>&1", $retArr, $retVal);
        $cnt = count($retArr);
        for($i = 0; $i < $cnt; $i++) {
            $buf .= ($i % 2 == 0) ? '
        <a href="?o=dkim&m=read&dnstxt=' . $retArr[$i] . '">' . $retArr[$i] . '</a><br>' : '
        <div style="word-break:break-all;font-family:monospace;width:100%;">' . $retArr[$i] . '</div><hr>';
        }
        return $this->t->list(['buf' => $buf]);
    }
}

?>
{'fraction_non_alphanumeric': 0.22509003601440578, 'fraction_numerical': 0.026710684273709484, 'mean_word_length': 2.3430290872617854, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 67, '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': '4478142', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1185, 'n_words': 232}