<commit_before><?php
/*
 * Copyright 2009-2010 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under GPLv3
 * (see COPYING for full license text)
 *
 */

class File_mod extends Model {

  function __construct()
  {
    parent::Model();
  }

  function new_id()
  {
    $id = $this->random_id(3,6);

    if ($this->id_exists($id) || $id == 'file') {
      return $this->new_id();
    } else {
      return $id;
    }
  }

  function id_exists($id)
  {
    if(!$id) {
      return false;
    }

    $sql = '
      SELECT id
      FROM `files`
      WHERE `id` = ?
      LIMIT 1';
    $query = $this->db->query($sql, array($id));

    if ($query->num_rows() == 1) {
      return true;
    } else {
      return false;
    }
  }

  function get_filedata($id)
  {
    $sql = '
      SELECT hash,filename
      FROM `files`
      WHERE `id` = ?
      LIMIT 1';
    $query = $this->db->query($sql, array($id));

    if ($query->num_rows() == 1) {
      $return = $query->result_array();
      return $return[0];
    } else {
      return false;
    }
  }

  function folder($hash) {
    return $this->config->item('upload_path').'/'.substr($hash, 0, 3);
  }

  function file($hash) {
    return $this->folder($hash).'/'.$hash;
  }

  function hash_password($password)
  {
    return sha1($this->config->item('passwordsalt').$password);
  }

  function get_password()
  {
    $password = $this->input->post('password');
    if ($password !== false) {
      return $this->hash_password($password);
    }
    return 'NULL';
  }

  function add_file($hash, $id, $filename)
  {
    $query = $this->db->query('
      INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`)
      VALUES (?, ?, ?, ?, ?)',
      array($hash, $id, $filename, $this->get_password(), time()));
  }

  function show_url($id, $mode)
  {
    $data = array();

    if ($mode) {
      $data['url'] = site_url($id).'/'.$mode;
    } else {
      $data['url'] = site_url($id).'/';
    }

    if (strstr($_SERVER['HTTP_USER_AGENT'], 'libcurl')) {
      echo $data['url'];
    } else {
      $this->load->view('file/header', $data);
      $this->load->view('file/show_url', $data);
      $this->load->view('file/footer', $data);
    }
  }
<commit_msg>add HTTP Basic Auth password support<commit_after><?php
/*
 * Copyright 2009-2010 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under GPLv3
 * (see COPYING for full license text)
 *
 */

class File_mod extends Model {

  function __construct()
  {
    parent::Model();
  }

  function new_id()
  {
    $id = $this->random_id(3,6);

    if ($this->id_exists($id) || $id == 'file') {
      return $this->new_id();
    } else {
      return $id;
    }
  }

  function id_exists($id)
  {
    if(!$id) {
      return false;
    }

    $sql = '
      SELECT id
      FROM `files`
      WHERE `id` = ?
      LIMIT 1';
    $query = $this->db->query($sql, array($id));

    if ($query->num_rows() == 1) {
      return true;
    } else {
      return false;
    }
  }

  function get_filedata($id)
  {
    $sql = '
      SELECT hash,filename
      FROM `files`
      WHERE `id` = ?
      LIMIT 1';
    $query = $this->db->query($sql, array($id));

    if ($query->num_rows() == 1) {
      $return = $query->result_array();
      return $return[0];
    } else {
      return false;
    }
  }

  function folder($hash) {
    return $this->config->item('upload_path').'/'.substr($hash, 0, 3);
  }

  function file($hash) {
    return $this->folder($hash).'/'.$hash;
  }

  function hash_password($password)
  {
    return sha1($this->config->item('passwordsalt').$password);
  }

  function get_password()
  {
    $password = $this->input->post('password');
    if ($password !== false) {
      return $this->hash_password($password);
    } elseif (isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] != '') {
      return $this->hash_password($_SERVER['PHP_AUTH_PW']);
    }
    return 'NULL';
  }

  function add_file($hash, $id, $filename)
  {
    $query = $this->db->query('
      INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`)
      VALUES (?, ?, ?, ?, ?)',
      array($hash, $id, $filename, $this->get_password(), time()));
  }

  function show_url($id, $mode)
  {
    $data = array();

    if ($mode) {
      $data['url'] = site_url($id).'/'.$mode;
    } else {
      $data['url'] = site_url($id).'/';
    }

    if (strstr($_SERVER['HTTP_USER_AGENT'], 'libcurl')) {
      echo $data['url'];
    } else {
      $this->load->view('file/header', $data);
      $this->load->view('file/show_url', $data);
      $this->load->view('file/footer', $data);
    }
  }

{'fraction_non_alphanumeric': 0.2057800956106041, 'fraction_numerical': 0.008257279443720122, 'mean_word_length': 2.516424751718869, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 62, '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': '5885758', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1618, 'n_words': 318}