File manager - Edit - /home/autoph/public_html/tasks/s.tar
Back
.htaccess 0000644 00000000636 15025047026 0006350 0 ustar 00 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [QSA,L] # php -- BEGIN cPanel-generated handler, do not edit # Set the “ea-php54” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php54 .php .php5 .phtml </IfModule> # php -- END cPanel-generated handler, do not edit config.php 0000644 00000002513 15025047026 0006524 0 ustar 00 <?php // Hostname for your URL shortener $hostname = 'http://s.autohub.ph'; // PDO connection to the database $connection = new PDO('mysql:dbname=autoph_surl;host=localhost', 'autoph_surl', 'D]a!;pl8!Bj4'); // Choose your character set (default) $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; // The following are shuffled strings of the default character set. // You can uncomment one of the lines below to use a pre-generated set, // or you can generate your own using the PHP str_shuffle function. // Using shuffled characters will ensure your generated URLs are unique // to your installation and are harder to guess. // $chars = 'XPzSI6v5DqLuBtVWQARy2mfwkC14F8HUTOG0aJiYpNrl9Zxgbd3Khsno7jMeEc'; // $chars = 'PAC3mfIazxgF1lVK4wJ2WEHY0dcb87TrsZeBpL9vNUMGktROijnSoq5DX6yQhu'; // $chars = 'zFr7ALOJnGRxtKSs0oQT5NeZjdI1iX8DM2lHaCVyg4mUPp63BkEubc9qWfhwYv'; // $chars = 'u7oIws3pVWZMQjA4XhNtyvglkEer1C2J5YdT6zLiFm0ObPc8S9KaDHqRBnfUGx'; // $chars = 'gZ6hdO59XTJmUP31YMG7FvQyqjlKkf8zwitx0AcupDVs2RWCIBaNreob4nLHES'; // If you want your generated URLs to even harder to guess, you can set // the salt value below to any non empty value. This is especially useful for // encoding consecutive numbers. $salt = ''; // The padding length to use when the salt value is configured above. // The default value is 3. $padding = 3; ?> index.php 0000644 00000000320 15025047026 0006360 0 ustar 00 <?php require './shorty.php'; require './config.php'; $shorty = new Shorty($hostname, $connection); $shorty->set_chars($chars); $shorty->set_salt($salt); $shorty->set_padding($padding); $shorty->run(); ?> shorty.php 0000644 00000022560 15025047026 0006613 0 ustar 00 <?php /** * Shorty: A simple URL shortener. * * @copyright Copyright (c) 2011, Mike Cao <mike@mikecao.com> * @license MIT, http://www.opensource.org/licenses/mit-license.php */ class Shorty { /** * Default characters to use for shortening. * * @var string */ private $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; /** * Salt for id encoding. * * @var string */ private $salt = ''; /** * Length of number padding. */ private $padding = 1; /** * Hostname */ private $hostname = ''; /** * PDO database connection. * * @var object */ private $connection = null; /** * Whitelist of IPs allowed to save URLs. * If the list is empty, then any IP is allowed. * * @var array */ private $whitelist = array(); /** * Constructor * * @param string $hostname Hostname * @param object $connection Database connection */ public function __construct($hostname, $connection) { $this->hostname = $hostname; $this->connection = $connection; } /** * Gets the character set for encoding. * * @return string Set of characters */ public function get_chars() { return $this->chars; } /** * Sets the character set for encoding. * * @param string $chars Set of characters */ public function set_chars($chars) { if (!is_string($chars) || empty($chars)) { throw new Exception('Invalid input.'); } $this->chars = $chars; } /** * Gets the salt string for encoding. * * @return string Salt */ public function get_salt() { return $this->salt; } /** * Sets the salt string for encoding. * * @param string $salt Salt string */ public function set_salt($salt) { $this->salt = $salt; } /** * Gets the padding length. * * @return int Padding length */ public function get_padding() { return $this->padding; } /** * Sets the padding length. * * @param int $padding Padding length */ public function set_padding($padding) { $this->padding = $padding; } /** * Converts an id to an encoded string. * * @param int $n Number to encode * @return string Encoded string */ public function encode($n) { $k = 0; if ($this->padding > 0 && !empty($this->salt)) { $k = self::get_seed($n, $this->salt, $this->padding); $n = (int)($k.$n); } return self::num_to_alpha($n, $this->chars); } /** * Converts an encoded string into a number. * * @param string $s String to decode * @return int Decoded number */ public function decode($s) { $n = self::alpha_to_num($s, $this->chars); return (!empty($this->salt)) ? substr($n, $this->padding) : $n; } /** * Gets a number for padding based on a salt. * * @param int $n Number to pad * @param string $salt Salt string * @param int $padding Padding length * @return int Number for padding */ public static function get_seed($n, $salt, $padding) { $hash = md5($n.$salt); $dec = hexdec(substr($hash, 0, $padding)); $num = $dec % pow(10, $padding); if ($num == 0) $num = 1; $num = str_pad($num, $padding, '0'); return $num; } /** * Converts a number to an alpha-numeric string. * * @param int $num Number to convert * @param string $s String of characters for conversion * @return string Alpha-numeric string */ public static function num_to_alpha($n, $s) { $b = strlen($s); $m = $n % $b; if ($n - $m == 0) return substr($s, $n, 1); $a = ''; while ($m > 0 || $n > 0) { $a = substr($s, $m, 1).$a; $n = ($n - $m) / $b; $m = $n % $b; } return $a; } /** * Converts an alpha numeric string to a number. * * @param string $a Alpha-numeric string to convert * @param string $s String of characters for conversion * @return int Converted number */ public static function alpha_to_num($a, $s) { $b = strlen($s); $l = strlen($a); for ($n = 0, $i = 0; $i < $l; $i++) { $n += strpos($s, substr($a, $i, 1)) * pow($b, $l - $i - 1); } return $n; } /** * Looks up a URL in the database by id. * * @param string $id URL id * @return array URL record */ public function fetch($id) { $statement = $this->connection->prepare( 'SELECT * FROM urls WHERE id = ?' ); $statement->execute(array($id)); return $statement->fetch(PDO::FETCH_ASSOC); } /** * Attempts to locate a URL in the database. * * @param string $url URL * @return array URL record */ public function find($url) { $statement = $this->connection->prepare( 'SELECT * FROM urls WHERE url = ?' ); $statement->execute(array($url)); return $statement->fetch(PDO::FETCH_ASSOC); } /** * Stores a URL in the database. * * @param string $url URL to store * @return int Insert id */ public function store($url) { $datetime = date('Y-m-d H:i:s'); $statement = $this->connection->prepare( 'INSERT INTO urls (url, created) VALUES (?,?)' ); $statement->execute(array($url, $datetime)); return $this->connection->lastInsertId(); } /** * Updates statistics for a URL. * * @param int $id URL id */ public function update($id) { $datetime = date('Y-m-d H:i:s'); $statement = $this->connection->prepare( 'UPDATE urls SET hits = hits + 1, accessed = ? WHERE id = ?' ); $statement->execute(array($datetime, $id)); } /** * Sends a redirect to a URL. * * @param string $url URL */ public function redirect($url) { header("Location: $url", true, 301); exit(); } /** * Sends a 404 response. */ public function not_found() { header('Status: 404 Not Found'); exit( '<h1>404 Not Found</h1>'. str_repeat(' ', 512) ); } /** * Sends an error message. * * @param string $message Error message */ public function error($message) { exit("<h1>$message</h1>"); } /** * Adds an IP to allow saving URLs. * * @param string|array $ip IP address or array of IP addresses */ public function allow($ip) { if (is_array($ip)) { $this->whitelist = array_merge($this->whitelist, $ip); } else { array_push($this->whitelist, $ip); } } /** * Starts the program. */ public function run() { $q = str_replace('/', '', $_GET['q']); $url = ''; if (isset($_GET['url'])) { $url = urldecode($_GET['url']); } $format = ''; if (isset($_GET['format'])) { $format = strtolower($_GET['format']); } // If adding a new URL if (!empty($url)) { if (!empty($this->whitelist) && !in_array($_SERVER['REMOTE_ADDR'], $this->whitelist)) { $this->error('Not allowed.'); } if (preg_match('/^http[s]?\:\/\/[\w]+/', $url)) { $result = $this->find($url); // Not found, so save it if (empty($result)) { $id = $this->store($url); $url = $this->hostname.'/'.$this->encode($id); } else { $url = $this->hostname.'/'.$this->encode($result['id']); } // Display the shortened url switch ($format) { case 'text': exit($url); case 'json': header('Content-Type: application/json'); exit(json_encode(array('url' => $url))); case 'xml': header('Content-Type: application/xml'); exit(implode("\n", array( '<?xml version="1.0"?'.'>', '<response>', ' <url>'.htmlentities($url).'</url>', '</response>' ))); default: exit('<a href="'.$url.'">'.$url.'</a>'); } } else { $this->error('Bad input.'); } } // Lookup by id else { if (empty($q)) { $this->not_found(); return; } if (preg_match('/^([a-zA-Z0-9]+)$/', $q, $matches)) { $id = self::decode($matches[1]); $result = $this->fetch($id); if (!empty($result)) { $this->update($id); $this->redirect($result['url']); } else { $this->not_found(); } } } } } README.md 0000644 00000003071 15025047026 0006025 0 ustar 00 # Shorty Shorty is a simple URL shortener for PHP. ## Installation 1\. Download and extract the files to your web directory. 2\. Use the included `database.sql` file to create a table to hold your URLs. 3\. Configure your webserver. For **Apache**, edit your `.htaccess` file with the following: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [QSA,L] For **Nginx**, add the following to your server declaration: server { location / { rewrite ^/(.*)$ /index.php?q=$1; } } 4\. Edit the `config.php` file. ## Generating short URLs To generate a short URL, simply pass in a `url` query parameter to your Shorty installation: http://example.com/?url=http://www.google.com This will return a shortened URL such as: http://example.com/9xq When a user opens the short URL they will be redirected to the long URL location. By default, Shorty will generate an HTML response for all saved URLs. You can alter the response format by passing in a `format` query parameter. http://example.com/?url=http://www.google.com&format=text The possible formats are `html`, `xml`, `text`, and `json`. ## Whitelist By default anyone is allowed to enter a new URL for shortening. To restrict the saving of URLs to certain IP addresses, use the `allow` function: $shorty->allow('192.168.0.10'); ## Requirements * PHP 5.1+ * PDO extension ## License Shorty is licensed under the [MIT](https://github.com/mikecao/shorty/blob/master/LICENSE) license. LICENSE 0000644 00000002074 15025047026 0005555 0 ustar 00 MIT License Copyright (c) 2014 Mike Cao <mike@mikecao.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings