<commit_before><?php
/**
 * Check object
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2007-2012, <NAME>
 * @version 1.0
 * @package objects
 * @category classes
 * @subpackage backend
 * @filesource
 */
class Check extends MySqlObj
{
  use logTrait;
    public static $RIGHT = 'CHK';

    public $id = -1;
    public $name = '';
    public $description = '';
    public $frequency = 0;
    public $lua = <<<CODE
  function check()
    return 0;
  end
CODE;
    public $m_error = '';
    public $m_warn = '';
    public $f_noalerts = 0;
    public $f_root = 0;
    public $t_add = -1;
    public $t_upd = -1;

    public $a_sgroup = array();
    public $f_except = array();

    public function link()
    {
        return '<a href="/view/w/check/i/'.$this->id.'">'.$this.'</a>';
    }

    public function valid($new = true)
    { /* validate form-based fields */
        $ret = array();

        if (empty($this->name)) {
            $ret[] = 'Missing Name';
        } else {
            if ($new) { /* check for already-exist */
        $check = new Check();
                $check->name = $this->name;
                if (!$check->fetchFromField('name')) {
                    $this->name = '';
                    $ret[] = 'Check Name already exist';
                    $check = null;
                }
            }
        }

    /* @TODO: Add LUA Validation code */

    if (count($ret)) {
        return $ret;
    } else {
        return;
    }
    }

  private function getLuaObject(&$s) {
      $lua = new Lua();
      $lua->registerCallback('exec', array(&$s, 'exec'));
      $lua->registerCallback('findBin', array(&$s, 'findBin'));
      $lua->registerCallback('isFile', array(&$s, 'isFile'));
      return $lua;
  }

  private function getStatusFromRet($ret) {

          $rc = -1;
          $msg = 'Check failed';
          if (!empty($ret)) {
              if (is_numeric($ret)) {
                  $rc = $ret;
                  $msg = '';
              } elseif (preg_match('/^([^:]*):([^$]*)/', $ret, $match)) {
                  if (is_numeric($match[1])) {
                      $rc = $match[1];
                      if (isset($match[2])) {
                          $msg = $match[2];
                      }
                  } else {
                      $rc = -1;
                  }
              }
          } else {
              $rc = 0;
              $msg = '';
          }
      return array('rc' => $rc, 'msg' => $msg);
  }

  private updateResult(&$r, $ret) {
      // update message accordingly
      switch ($r->rc) {
        case 0:
          $r->f_ack = 1;
          $r->message = '';
          $r->details = $ret['msg'];
        break;
        case -1: // WARNING
          $r->f_ack = 0;<commit_msg>fixed missing keyword<commit_after><?php
/**
 * Check object
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2007-2012, <NAME>
 * @version 1.0
 * @package objects
 * @category classes
 * @subpackage backend
 * @filesource
 */
class Check extends MySqlObj
{
  use logTrait;
    public static $RIGHT = 'CHK';

    public $id = -1;
    public $name = '';
    public $description = '';
    public $frequency = 0;
    public $lua = <<<CODE
  function check()
    return 0;
  end
CODE;
    public $m_error = '';
    public $m_warn = '';
    public $f_noalerts = 0;
    public $f_root = 0;
    public $t_add = -1;
    public $t_upd = -1;

    public $a_sgroup = array();
    public $f_except = array();

    public function link()
    {
        return '<a href="/view/w/check/i/'.$this->id.'">'.$this.'</a>';
    }

    public function valid($new = true)
    { /* validate form-based fields */
        $ret = array();

        if (empty($this->name)) {
            $ret[] = 'Missing Name';
        } else {
            if ($new) { /* check for already-exist */
        $check = new Check();
                $check->name = $this->name;
                if (!$check->fetchFromField('name')) {
                    $this->name = '';
                    $ret[] = 'Check Name already exist';
                    $check = null;
                }
            }
        }

    /* @TODO: Add LUA Validation code */

    if (count($ret)) {
        return $ret;
    } else {
        return;
    }
    }

  private function getLuaObject(&$s) {
      $lua = new Lua();
      $lua->registerCallback('exec', array(&$s, 'exec'));
      $lua->registerCallback('findBin', array(&$s, 'findBin'));
      $lua->registerCallback('isFile', array(&$s, 'isFile'));
      return $lua;
  }

  private function getStatusFromRet($ret) {

          $rc = -1;
          $msg = 'Check failed';
          if (!empty($ret)) {
              if (is_numeric($ret)) {
                  $rc = $ret;
                  $msg = '';
              } elseif (preg_match('/^([^:]*):([^$]*)/', $ret, $match)) {
                  if (is_numeric($match[1])) {
                      $rc = $match[1];
                      if (isset($match[2])) {
                          $msg = $match[2];
                      }
                  } else {
                      $rc = -1;
                  }
              }
          } else {
              $rc = 0;
              $msg = '';
          }
      return array('rc' => $rc, 'msg' => $msg);
  }

  private function updateResult(&$r, $ret) {
      // update message accordingly
      switch ($r->rc) {
        case 0:
          $r->f_ack = 1;
          $r->message = '';
          $r->details = $ret['msg'];
        break;
        case -1: // WARNING
          $r->f_ack = 0;
{'fraction_non_alphanumeric': 0.1734564548252761, 'fraction_numerical': 0.010139416983523447, 'mean_word_length': 1.4399293286219081, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, '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': '4357582', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1682, 'n_words': 402}