aboutsummaryrefslogtreecommitdiff
path: root/includes/vendor/ozh
diff options
context:
space:
mode:
Diffstat (limited to 'includes/vendor/ozh')
-rw-r--r--includes/vendor/ozh/bookmarkletgen/README.md74
-rw-r--r--includes/vendor/ozh/bookmarkletgen/src/Ozh/Bookmarkletgen/Bookmarkletgen.php197
-rw-r--r--includes/vendor/ozh/phpass/README.md45
-rw-r--r--includes/vendor/ozh/phpass/src/Ozh/Phpass/PasswordHash.php371
4 files changed, 687 insertions, 0 deletions
diff --git a/includes/vendor/ozh/bookmarkletgen/README.md b/includes/vendor/ozh/bookmarkletgen/README.md
new file mode 100644
index 0000000..e091b3a
--- /dev/null
+++ b/includes/vendor/ozh/bookmarkletgen/README.md
@@ -0,0 +1,74 @@
+# Bookmarklet Gen [![](https://travis-ci.org/ozh/bookmarkletgen.svg?branch=master)](https://travis-ci.org/ozh/bookmarkletgen)
+
+Convert readable Javascript code into bookmarklet links
+
+## Features
+
+- removes comments
+
+- compresses code by removing extraneous spaces, but not within literal strings.
+ Example:
+ ```javascript
+ function someName( param ) {
+ alert( "this is a string" )
+ }
+ ```
+ will return:
+ ```javascript
+ function%20someName(param){alert("this%20is%20a%20string")}
+ ```
+- encodes what needs to be encoded
+
+- wraps code into a self invoking function ready for bookmarking
+
+This is basically a slightly enhanced PHP port of the excellent Bookmarklet Crunchinator:
+http://ted.mielczarek.org/code/mozilla/bookmarklet.html
+
+## Installation
+
+If you are using Composer, add this requirement to your `composer.json` file and run `composer install`:
+
+ {
+ "require": {
+ "ozh/phpass": "1.2.0"
+ }
+ }
+
+Or simply in the command line : `composer install ozh/bookmarkletgen`
+
+If you're not using composer, download the class file and include it manually.
+
+## Example
+
+```php
+<?php
+$javascript = <<<CODE
+var link="http://google.com/"; // destination
+window.location = link;
+CODE;
+
+require 'vendor/autoload.php'; // if you install using Composer
+require 'path/to/Bookmarkletgen.php'; // otherwise
+
+$book = new \Ozh\Bookmarkletgen\Bookmarkletgen;
+$link = $book->crunch( $javascript );
+
+printf( '<a href="%s">bookmarklet</a>', $link );
+```
+
+will print:
+
+```html
+<a href="javascript:(function()%7Bvar%20link%3D%22http%3A%2F%2Fgoogle.com%2F%22%3Bwindow.location%3Dlink%3B%7D)()%3B">bookmarklet</a>
+```
+
+## Tests
+
+This library comes with unit tests to make sure the resulting crunched Javascript is valid code.
+
+This library requires PHP 5.3. Tests are failing on HHVM because of an external binary issue (`phantomjs`) but things should work anyway on HHVM too.
+
+## License
+
+Do whatever the hell you want to do with it
+
diff --git a/includes/vendor/ozh/bookmarkletgen/src/Ozh/Bookmarkletgen/Bookmarkletgen.php b/includes/vendor/ozh/bookmarkletgen/src/Ozh/Bookmarkletgen/Bookmarkletgen.php
new file mode 100644
index 0000000..d49e9a7
--- /dev/null
+++ b/includes/vendor/ozh/bookmarkletgen/src/Ozh/Bookmarkletgen/Bookmarkletgen.php
@@ -0,0 +1,197 @@
+<?php
+
+/**
+ * BookmarkletGen : converts readable Javascript code into a bookmarklet link
+ *
+ * Features :
+ * - removes comments
+ * - compresses code, not literal strings
+ * Example:
+ * function someName( param ) { alert( "this is a string" ) }
+ * will return:
+ * function%20someName(param){alert("this is a string")}
+ * - wraps code into a self invoking function
+ *
+ * This is basically a slightly enhanced PHP port of the excellent Bookmarklet Crunchinator
+ * http://ted.mielczarek.org/code/mozilla/bookmarklet.html
+ *
+ */
+namespace Ozh\Bookmarkletgen;
+
+class Bookmarkletgen {
+
+ private $literal_strings = array();
+
+ /**
+ * Main function, calls all others
+ *
+ * @param string $code Javascript code to bookmarkletify
+ * @return string Bookmarklet link
+ */
+ public function crunch( $code ) {
+ $out = "(function() {\n" . $code . "\n})();";
+
+ $out = $this->replace_strings( $out );
+ $out = $this->kill_comments( $out );
+ $out = $this->compress_white_space( $out );
+ $out = $this->combine_strings( $out );
+ $out = $this->restore_strings( $out );
+ $out = $this->encodeURIComponent( $out );
+ $out = 'javascript:' . $out;
+
+ return $out;
+ }
+
+ /**
+ * PHP port of Javascript function encodeURIComponent
+ *
+ * From http://stackoverflow.com/a/1734255/36850
+ *
+ * @since
+ * @param string $str String to encode
+ * @return string Encoded string
+ */
+ //
+ private function encodeURIComponent( $str ) {
+ $revert = array(
+ '%21'=>'!', '%2A'=>'*', '%28'=>'(', '%29'=>')',
+ );
+
+ return strtr( rawurlencode( $str ), $revert );
+ }
+
+ /**
+ * Kill comment lines and blocks
+ *
+ * @param string $code Commented Javascript code
+ * @return string Commentless code
+ */
+ private function kill_comments( $code ) {
+ $code = preg_replace( '!\s*//.+$!m', '', $code );
+ $code = preg_replace( '!/\*.+?\*/!sm', '', $code ); // s modifier: dot matches new lines
+
+ return $code;
+ }
+
+ /**
+ * Compress white space
+ *
+ * Remove some extraneous spaces and make the whole script a one liner
+ *
+ * @param string $code Javascript code
+ * @return string Compressed code
+ */
+ private function compress_white_space( $code ) {
+ // Tabs to space, no more than 1 consecutive space
+ $code = preg_replace( '!\t!m', ' ', $code );
+ $code = preg_replace( '![ ]{2,}!m', ' ', $code );
+
+ // Remove uneccessary white space around operators, braces and brackets.
+ // \xHH sequence is: !%&()*+,-/:;<=>?[]\{|}~
+ $code = preg_replace( '/\s([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])/m', "$1", $code );
+ $code = preg_replace( '/([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])\s/m', "$1", $code );
+
+ // Split on each line, trim leading/trailing white space, kill empty lines, combine everything in one line
+ $code = preg_split( '/\r\n|\r|\n/', $code );
+ foreach( $code as $i => $line ) {
+ $code[ $i ] = trim( $line );
+ }
+ $code = implode( '', $code );
+
+ return $code;
+ }
+
+ /**
+ * Combine any consecutive strings
+ *
+ * In the case we have two consecutive quoted strings (eg: "hello" + "world"), save a couple more
+ * length and combine them
+ *
+ * @param string $code Javascript code
+ * @return string Javascript code
+ */
+ private function combine_strings( $code ) {
+ $code = preg_replace('/"\+"/m', "", $code);
+ $code = preg_replace("/'\+'/m", "", $code);
+
+ return $code;
+ }
+
+
+ /**
+ * Replace all literal strings (eg: "hello world") with a placeholder and collect them in an array
+ *
+ * The idea is that strings cannot be trimmed or white-space optimized: take them out first before uglifying
+ * the code, then we'll reinject them back in later
+ *
+ * @param string $code Javascript code
+ * @return string Javascript code with placeholders (eg "__1__") instead of literal strings
+ */
+ private function replace_strings( $code ) {
+ $return = "";
+ $literal = "";
+ $quoteChar = "";
+ $escaped = false;
+
+ // Split script into individual lines.
+ $lines = explode("\n", $code);
+ $count = count( $lines );
+ for( $i = 0; $i < $count; $i++ ) {
+
+ $j = 0;
+ $inQuote = false;
+ while ($j < strlen( $lines[$i] ) ) {
+ $c = $lines[ $i ][ $j ];
+
+ // If not already in a string, look for the start of one.
+ if (!$inQuote) {
+ if ($c == '"' || $c == "'") {
+ $inQuote = true;
+ $escaped = false;
+ $quoteChar = $c;
+ $literal = $c;
+ }
+ else {
+ $return .= $c;
+ }
+ }
+
+ // Already in a string, look for end and copy characters.
+ else {
+ if ($c == $quoteChar && !$escaped) {
+ $inQuote = false;
+ $literal .= $quoteChar;
+ $return .= "__" . count( $this->literal_strings ) . "__";
+ $this->literal_strings[ count( $this->literal_strings ) ] = $literal;
+ }
+ else if ($c == "\\" && !$escaped) {
+ $escaped = true;
+ }
+ else {
+ $escaped = false;
+ }
+ $literal .= $c;
+ }
+ $j++;
+ }
+ $return .= "\n";
+ }
+
+ return $return;
+ }
+
+ /**
+ * Restore literal strings by replacing their placeholders with actual strings
+ *
+ * @param string $code Javascript code with placeholders
+ * @return string Javascript code with actual strings
+ */
+ private function restore_strings( $code ) {
+ foreach( $this->literal_strings as $i => $string ) {
+ $code = preg_replace( '/__' . $i . '__/', $string, $code, 1 );
+ }
+
+ return $code;
+ }
+
+}
diff --git a/includes/vendor/ozh/phpass/README.md b/includes/vendor/ozh/phpass/README.md
new file mode 100644
index 0000000..5d116bc
--- /dev/null
+++ b/includes/vendor/ozh/phpass/README.md
@@ -0,0 +1,45 @@
+Openwall Phpass, modernized
+===========================
+
+[![Build Status](https://secure.travis-ci.org/ozh/phpass.png?branch=master)](http://travis-ci.org/ozh/phpass)
+
+This is Openwall's [Phpass](http://openwall.com/phpass/), based on the 0.3 release, but modernized slightly:
+
+- Namespaced
+- Composer support (Autoloading)
+- PHP 5 style
+- Unit Tested
+
+The modernization has been done by Hautelook, from whom I stole this library to repackage it for PHP 5.3 to 7.1 compatibility in a single file and branch (Hautelook's port consisting of two branches, one for PHP 5.3 to 5.5, and another one for 5.6+)
+
+## Installation ##
+
+Add this requirement to your `composer.json` file and run `composer.phar install`:
+
+ {
+ "require": {
+ "ozh/phpass": "1.2.0"
+ }
+ }
+
+## Usage ##
+
+The following example shows how to hash a password (to then store the hash in the database), and how to check whether a provided password is correct (hashes to the same value):
+
+``` php
+<?php
+
+namespace Your\Namespace;
+
+use Ozh\Phpass\PasswordHash;
+
+require_once(__DIR__ . "/vendor/autoload.php");
+
+$passwordHasher = new PasswordHash(8,false);
+
+$password = $passwordHasher->HashPassword('secret');
+var_dump($password);
+
+$passwordMatch = $passwordHasher->CheckPassword('secret', "$2a$08$0RK6Yw6j9kSIXrrEOc3dwuDPQuT78HgR0S3/ghOFDEpOGpOkARoSu");
+var_dump($passwordMatch);
+
diff --git a/includes/vendor/ozh/phpass/src/Ozh/Phpass/PasswordHash.php b/includes/vendor/ozh/phpass/src/Ozh/Phpass/PasswordHash.php
new file mode 100644
index 0000000..609a6f8
--- /dev/null
+++ b/includes/vendor/ozh/phpass/src/Ozh/Phpass/PasswordHash.php
@@ -0,0 +1,371 @@
+<?php
+
+namespace Ozh\Phpass;
+
+/**
+ *
+ * Portable PHP password hashing framework.
+ *
+ * Originally written by Solar Designer <solar at openwall.com> in 2004-2006
+ *
+ * Modernized by Hautelook at https://github.com/hautelook/phpass
+ *
+ * Slightly repacked by Ozh to extend compatibility from PHP 5.3 to 7.1 in a single file
+ *
+ * There's absolutely no warranty.
+ *
+ * The homepage URL for this framework is:
+ *
+ * http://www.openwall.com/phpass/
+ *
+ * Please be sure to update the Version line if you edit this file in any way.
+ * It is suggested that you leave the main version number intact, but indicate
+ * your project name (after the slash) and add your own revision information.
+ *
+ * Please do not change the "private" password hashing method implemented in
+ * here, thereby making your hashes incompatible. However, if you must, please
+ * change the hash type identifier (the "$P$") to something different.
+ *
+ * Obviously, since this code is in the public domain, the above are not
+ * requirements (there can be none), but merely suggestions.
+ *
+ * @author Solar Designer <[email protected]>
+ */
+class PasswordHash
+{
+ private $itoa64;
+ private $iteration_count_log2;
+ private $portable_hashes;
+ private $random_state;
+
+ /**
+ * Constructor
+ *
+ * @param int $iteration_count_log2
+ * @param boolean $portable_hashes
+ */
+ public function __construct($iteration_count_log2, $portable_hashes)
+ {
+ $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+
+ if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
+ $iteration_count_log2 = 8;
+ }
+ $this->iteration_count_log2 = $iteration_count_log2;
+
+ $this->portable_hashes = $portable_hashes;
+
+ $this->random_state = microtime();
+ if (function_exists('getmypid')) {
+ $this->random_state .= getmypid();
+ }
+ }
+
+ /**
+ * @param int $count
+ * @return String
+ */
+ public function get_random_bytes($count)
+ {
+ $output = '';
+
+ if (is_callable('random_bytes')) {
+ return random_bytes($count);
+ }
+
+ if (@is_readable('/dev/urandom') &&
+ ($fh = @fopen('/dev/urandom', 'rb'))) {
+ $output = fread($fh, $count);
+ fclose($fh);
+ }
+
+ if (strlen($output) < $count) {
+ $output = '';
+ for ($i = 0; $i < $count; $i += 16) {
+ $this->random_state =
+ md5(microtime() . $this->random_state);
+ $output .=
+ pack('H*', md5($this->random_state));
+ }
+ $output = substr($output, 0, $count);
+ }
+
+ return $output;
+ }
+
+ /**
+ * @param String $input
+ * @param int $count
+ * @return String
+ */
+ public function encode64($input, $count)
+ {
+ $output = '';
+ $i = 0;
+ do {
+ $value = ord($input[$i++]);
+ $output .= $this->itoa64[$value & 0x3f];
+ if ($i < $count) {
+ $value |= ord($input[$i]) << 8;
+ }
+ $output .= $this->itoa64[($value >> 6) & 0x3f];
+ if ($i++ >= $count) {
+ break;
+ }
+ if ($i < $count) {
+ $value |= ord($input[$i]) << 16;
+ }
+ $output .= $this->itoa64[($value >> 12) & 0x3f];
+ if ($i++ >= $count) {
+ break;
+ }
+ $output .= $this->itoa64[($value >> 18) & 0x3f];
+ } while ($i < $count);
+
+ return $output;
+ }
+
+ /**
+ * @param String $input
+ * @return String
+ */
+ public function gensalt_private($input)
+ {
+ $output = '$P$';
+ $output .= $this->itoa64[min($this->iteration_count_log2 +
+ ((PHP_VERSION >= '5') ? 5 : 3), 30)];
+ $output .= $this->encode64($input, 6);
+
+ return $output;
+ }
+
+ /**
+ * @param String $password
+ * @param String $setting
+ * @return String
+ */
+ public function crypt_private($password, $setting)
+ {
+ $output = '*0';
+ if (substr($setting, 0, 2) == $output) {
+ $output = '*1';
+ }
+
+ $id = substr($setting, 0, 3);
+ # We use "$P$", phpBB3 uses "$H$" for the same thing
+ if ($id != '$P$' && $id != '$H$') {
+ return $output;
+ }
+
+ $count_log2 = strpos($this->itoa64, $setting[3]);
+ if ($count_log2 < 7 || $count_log2 > 30) {
+ return $output;
+ }
+
+ $count = 1 << $count_log2;
+
+ $salt = substr($setting, 4, 8);
+ if (strlen($salt) != 8) {
+ return $output;
+ }
+
+ // We're kind of forced to use MD5 here since it's the only
+ // cryptographic primitive available in all versions of PHP
+ // currently in use. To implement our own low-level crypto
+ // in PHP would result in much worse performance and
+ // consequently in lower iteration counts and hashes that are
+ // quicker to crack (by non-PHP code).
+ if (PHP_VERSION >= '5') {
+ $hash = md5($salt . $password, TRUE);
+ do {
+ $hash = md5($hash . $password, TRUE);
+ } while (--$count);
+ } else {
+ $hash = pack('H*', md5($salt . $password));
+ do {
+ $hash = pack('H*', md5($hash . $password));
+ } while (--$count);
+ }
+
+ $output = substr($setting, 0, 12);
+ $output .= $this->encode64($hash, 16);
+
+ return $output;
+ }
+
+ /**
+ * @param String $input
+ * @return String
+ */
+ public function gensalt_extended($input)
+ {
+ $count_log2 = min($this->iteration_count_log2 + 8, 24);
+ // This should be odd to not reveal weak DES keys, and the
+ // maximum valid value is (2**24 - 1) which is odd anyway.
+ $count = (1 << $count_log2) - 1;
+
+ $output = '_';
+ $output .= $this->itoa64[$count & 0x3f];
+ $output .= $this->itoa64[($count >> 6) & 0x3f];
+ $output .= $this->itoa64[($count >> 12) & 0x3f];
+ $output .= $this->itoa64[($count >> 18) & 0x3f];
+
+ $output .= $this->encode64($input, 3);
+
+ return $output;
+ }
+
+ /**
+ * @param String $input
+ * @return String
+ */
+ public function gensalt_blowfish($input)
+ {
+ // This one needs to use a different order of characters and a
+ // different encoding scheme from the one in encode64() above.
+ // We care because the last character in our encoded string will
+ // only represent 2 bits. While two known implementations of
+ // bcrypt will happily accept and correct a salt string which
+ // has the 4 unused bits set to non-zero, we do not want to take
+ // chances and we also do not want to waste an additional byte
+ // of entropy.
+ $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+
+ $output = '$2a$';
+ $output .= chr(ord('0') + $this->iteration_count_log2 / 10);
+ $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
+ $output .= '$';
+
+ $i = 0;
+ do {
+ $c1 = ord($input[$i++]);
+ $output .= $itoa64[$c1 >> 2];
+ $c1 = ($c1 & 0x03) << 4;
+ if ($i >= 16) {
+ $output .= $itoa64[$c1];
+ break;
+ }
+
+ $c2 = ord($input[$i++]);
+ $c1 |= $c2 >> 4;
+ $output .= $itoa64[$c1];
+ $c1 = ($c2 & 0x0f) << 2;
+
+ $c2 = ord($input[$i++]);
+ $c1 |= $c2 >> 6;
+ $output .= $itoa64[$c1];
+ $output .= $itoa64[$c2 & 0x3f];
+ } while (1);
+
+ return $output;
+ }
+
+ /**
+ * @param String $password
+ */
+ public function HashPassword($password)
+ {
+ $random = '';
+
+ if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
+ $random = $this->get_random_bytes(16);
+ $hash =
+ crypt($password, $this->gensalt_blowfish($random));
+ if (strlen($hash) == 60) {
+ return $hash;
+ }
+ }
+
+ if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
+ if (strlen($random) < 3) {
+ $random = $this->get_random_bytes(3);
+ }
+ $hash =
+ crypt($password, $this->gensalt_extended($random));
+ if (strlen($hash) == 20) {
+ return $hash;
+ }
+ }
+
+ if (strlen($random) < 6) {
+ $random = $this->get_random_bytes(6);
+ }
+
+ $hash =
+ $this->crypt_private($password,
+ $this->gensalt_private($random));
+ if (strlen($hash) == 34) {
+ return $hash;
+ }
+
+ // Returning '*' on error is safe here, but would _not_ be safe
+ // in a crypt(3)-like function used _both_ for generating new
+ // hashes and for validating passwords against existing hashes.
+ return '*';
+ }
+
+ /**
+ * @param String $password
+ * @param String $stored_hash
+ * @return boolean
+ */
+ public function CheckPassword($password, $stored_hash)
+ {
+ $hash = $this->crypt_private($password, $stored_hash);
+ if ($hash[0] == '*') {
+ $hash = crypt($password, $stored_hash);
+ }
+
+ return hash_equals($stored_hash, $hash);
+ }
+}
+
+
+/**
+ * hash_equals compatibility function
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ *
+ * Source: https://github.com/bcit-ci/CodeIgniter/blob/3.1.4/system/core/compat/hash.php
+ * For PHP < 5.6
+ */
+if ( ! function_exists('hash_equals'))
+{
+ /**
+ * hash_equals()
+ *
+ * @link http://php.net/hash_equals
+ * @param string $known_string
+ * @param string $user_string
+ * @return bool
+ */
+ function hash_equals($known_string, $user_string)
+ {
+ if ( ! is_string($known_string))
+ {
+ trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING);
+ return FALSE;
+ }
+ elseif ( ! is_string($user_string))
+ {
+ trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING);
+ return FALSE;
+ }
+ elseif (($length = strlen($known_string)) !== strlen($user_string))
+ {
+ return FALSE;
+ }
+ $diff = 0;
+ for ($i = 0; $i < $length; $i++)
+ {
+ $diff |= ord($known_string[$i]) ^ ord($user_string[$i]);
+ }
+ return ($diff === 0);
+ }
+}
+