<commit_before><?php

/**
 * Description of OpsActions
 *
 * @author jeremy
 */
class OpsActions extends Actions
{
  public static function executePostCommit()
  {
    $payload = json_decode($_REQUEST['payload'], true);
    if ($payload['ref'] === 'refs/heads/master')
    {
      Actions::returnErrorIf(!isset($_SERVER['HTTP_X_HUB_SIGNATURE']), "HTTP header 'X-Hub-Signature' is missing.");

      list($algo, $hash) = explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE'], 2) + array('', '');
      Actions::returnErrorIf(!in_array($algo, hash_algos(), TRUE), 'Invalid hash algorithm "' . $algo . '"');

      $rawPost = file_get_contents('php://input');
      $secret = Config::get('github_key');
      Actions::returnErrorIf($hash !== hash_hmac($algo, $rawPost, $secret), 'Hash does not match. "' . $secret . '"' . ' algo: ' . $algo . '$');

      file_put_contents(ROOT_DIR . '/data/writeable/NEEDS_UPDATE', '');
    }

    return [null, []];
  }

  public static function executeLogUpload()
  {
    $log = isset($_POST['log']) ? urldecode($_POST['log']) : null;
    $name = isset($_POST['name']) ?
            preg_replace('/[^A-Za-z0-9_-]+/', '', substr(trim(urldecode($_POST['name'])),0,50)) :
            null;

    Actions::returnErrorIf(!$log || !$name, "Required params: log, name");

    $awsKey = Config::get('aws_log_access_key');
    $awsSecret = Config::get('aws_log_secret_key');

    Actions::returnErrorIf(!$awsKey || !$awsSecret, "Missing AWS credentials");

    $tmpFile = tempnam(sys_get_temp_dir(), 'lbryinstalllog');
    file_put_contents($tmpFile, $log);

    Actions::returnErrorIf(filesize($tmpFile) > 1024*1024*2, "File is too large");

    S3::$useExceptions = true;
    S3::setAuth($awsKey, $awsSecret);
    S3::putObject(S3::inputFile($tmpFile, false), 'lbry-install-logs', $name);
    unlink($tmpFile);

    return [null, []];
  }
}
<commit_msg>better names for uploaded logs<commit_after><?php

/**
 * Description of OpsActions
 *
 * @author jeremy
 */
class OpsActions extends Actions
{
  public static function executePostCommit()
  {
    $payload = json_decode($_REQUEST['payload'], true);
    if ($payload['ref'] === 'refs/heads/master')
    {
      Actions::returnErrorIf(!isset($_SERVER['HTTP_X_HUB_SIGNATURE']), "HTTP header 'X-Hub-Signature' is missing.");

      list($algo, $hash) = explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE'], 2) + array('', '');
      Actions::returnErrorIf(!in_array($algo, hash_algos(), TRUE), 'Invalid hash algorithm "' . $algo . '"');

      $rawPost = file_get_contents('php://input');
      $secret = Config::get('github_key');
      Actions::returnErrorIf($hash !== hash_hmac($algo, $rawPost, $secret), 'Hash does not match. "' . $secret . '"' . ' algo: ' . $algo . '$');

      file_put_contents(ROOT_DIR . '/data/writeable/NEEDS_UPDATE', '');
    }

    return [null, []];
  }

  public static function executeLogUpload()
  {
    $log = isset($_POST['log']) ? urldecode($_POST['log']) : null;
    if (isset($_POST['name']))
    {
      $name = substr(trim(urldecode($_POST['name'])),0,50);
    }
    elseif (isset($_POST['date']))
    {
      $name = substr(trim(urldecode($_POST['date'])),0,20) . '_' .
              substr(trim(urldecode($_POST['hash'])),0,20) . '_' .
              substr(trim(urldecode($_POST['sys'])),0,50)  . '_' .
              substr(trim(urldecode($_POST['type'])),0,20);
    }
    else
    {
      $name = null;
    }

    $name = preg_replace('/[^A-Za-z0-9_-]+/', '', $name);

    Actions::returnErrorIf(!$log || !$name, "Required params: log, name");

    $awsKey = Config::get('aws_log_access_key');
    $awsSecret = Config::get('aws_log_secret_key');

    Actions::returnErrorIf(!$awsKey || !$awsSecret, "Missing AWS credentials");

    $tmpFile = tempnam(sys_get_temp_dir(), 'lbryinstalllog');
    file_put_contents($tmpFile, $log);

    Actions::returnErrorIf(filesize($tmpFile) > 1024*1024*2, "File is too large");

    S3::$useExceptions = true;
    S3::setAuth($awsKey, $awsSecret);
    S3::putObject(S3::inputFile($tmpFile, false), 'lbry-install-logs', $name);
    unlink($tmpFile);

    return [null, []];
  }
}

{'fraction_non_alphanumeric': 0.20481049562682216, 'fraction_numerical': 0.012147716229348883, 'mean_word_length': 3.9305389221556886, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '395768', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1403, 'n_words': 232}