Advertisement
Guest User

Untitled

a guest
Sep 11th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4.  * Image-Creator / Sample
  5.  * Part of PHP-Barcode 0.3pl1
  6.  
  7.  * (C) 2001,2002,2003,2004 by Folke Ashberg <folke@ashberg.de>
  8.  
  9.  * The newest version can be found at http://www.ashberg.de/bar
  10.  
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  */
  26.  
  27. /*
  28.  * call
  29.  * http://localhost/barcode.php?code=012345678901
  30.  *   or
  31.  * http://localhost/barcode.php?code=012345678901&encoding=EAN&scale=4&mode=png
  32.  *
  33.  */
  34.  
  35. define('INDEX_AUTH', '1');
  36.  
  37. if (!defined('SENAYAN_BASE_DIR')) {
  38.     require '../../sysconfig.inc.php';
  39. }
  40.  
  41. function scinfo()
  42. {
  43.     $host = $_SERVER['HTTP_HOST'];
  44.     $path = $_SERVER['SCRIPT_NAME'];
  45.     $dir = explode('/', $path);
  46.     $file = $dir[count($dir)-1];
  47.     unset($dir[count($dir)-1]);
  48.     $dir = implode('/', $dir);
  49.     return array($host, $dir, $file);
  50. }
  51.  
  52. function checkref($mode = 'module')
  53. {
  54.     $ref = false;
  55.     if (isset($_SERVER['HTTP_REFERER']))
  56.     {
  57.         $ref_url = $_SERVER['HTTP_REFERER'];
  58.         $ref_part = (object) parse_url($ref_url);
  59.         $ref_host = isset($ref_part->host) ? $ref_part->host : '';
  60.         $ref_ip = isset($ref_part->host) ? gethostbyname($ref_host) : '';
  61.         $ref_path = isset($ref_part->path) ? $ref_part->path : '/';
  62.         $ref_dir = explode('/', $ref_path);
  63.         unset($ref_dir[count($ref_dir)-1]);
  64.         $ref_dir = implode('/', $ref_dir);
  65.         $ref_admin = $ref_host . $ref_dir;
  66.         $ref_q = isset($ref_part->query) ? $ref_part->query : '';
  67.         $ref_req = $ref_admin . '?' . $ref_q;
  68.  
  69.         list($dest_host, $dest_dir, $dest_file) = scinfo();
  70.         $dest_path = $_SERVER['SCRIPT_NAME'];
  71.         $dest_ip = gethostbyname($dest_host);
  72.         $dest_dir = explode('/', SENAYAN_WEB_ROOT_DIR);
  73.         unset($dest_dir[count($dest_dir)-3]);
  74.         unset($dest_dir[count($dest_dir)-2]);
  75.         unset($dest_dir[count($dest_dir)-1]);
  76.         $dest_dir = implode('/', $dest_dir);
  77.         $dest_admin = $dest_host . $dest_dir . 'admin';
  78.         $dest_plugin = $dest_admin . '/modules/plugins';
  79.         $dest_q = 'mod=plugins';
  80.         $dest_req = $dest_admin . '?' . $dest_q;
  81.         switch ($mode)
  82.         {
  83.             case "host":
  84.                 if ($ref_host == $dest_host)
  85.                     $ref = true;
  86.                 break;
  87.             case "ip":
  88.                 if ($ref_ip == $dest_ip)
  89.                     $ref = true;
  90.                 break;
  91.             case "admin":
  92.                 $is_admin = explode($dest_admin, $ref_admin);
  93.                 if (empty($is_admin[0]))
  94.                     $ref = true;
  95.                 break;
  96.             case "module":
  97.             default:
  98.                 if ($ref_req == $dest_req)
  99.                     $ref = true;
  100.         }
  101.         if ($ref_path == $dest_path)
  102.             $ref = true;
  103.     }
  104.     if ($ref !== true)
  105.         die(sprintf('<div>%s!</div>', 'Invalid referer'));
  106.     else
  107.         return;
  108. }
  109.  
  110. checkref('admin');
  111. $get = (object) $_GET;
  112. $allowed_scale = array(1, 2, 3, 4, 5, 6);
  113. if ( ! isset($get->scale) OR (isset($get->scale) AND ! in_array($get->scale, $allowed_scale)))
  114.     $get->scale = 2;
  115.  
  116. // include php-barcode lib
  117. require "php-barcode.php";
  118.  
  119. // http vars
  120. $code = isset($get->code) ? trim($get->code) : '1234567890';
  121. $encoding = isset($get->encoding) ? trim($get->encoding) : '128';
  122. $scale = isset($get->scale) ? trim($get->scale) : '2';
  123. $mode = isset($get->mode) ? trim($get->mode) : 'png';
  124.  
  125. // output the barcode
  126. barcode_print($code, $encoding, $scale, $mode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement