本文整理汇总了PHP中sanitize_path函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_path函数的具体用法?PHP sanitize_path怎么用?PHP sanitize_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct()
{
global $lang, $dB;
$this->dB = $dB;
// Parse the definitions to this object.. This nos not necessary but in case of changes...
$this->root_url = __CHV_RELATIVE_ROOT__;
$this->base_url = __CHV_BASE_URL__;
$this->path_images = rtrim(__CHV_PATH_IMAGES__, '/') . '/';
$this->path_theme = __CHV_PATH_THEME__;
// Parse the params
$this->request_uri = $_SERVER['REQUEST_URI'];
$this->script_name = $_SERVER['SCRIPT_NAME'];
$this->valid_request = sanitize_path($this->request_uri);
// Build the canonical request
// All the dirs will have a traling slash no matter in what whe are (Linux, Windows, etc)
$this->canonical_request = '/' . $this->valid_request;
if (is_dir(__CHV_ROOT_DIR__ . $this->valid_request)) {
$this->canonical_request .= '/';
}
$this->handled_request = $this->root_url == '/' ? $this->valid_request : str_ireplace($this->root_url, '', $this->add_trailing_slashes($this->request_uri));
$this->request_array = explode('/', rtrim(str_replace("//", "/", str_replace("?", "/", $this->handled_request)), '/'));
$this->base_request = $this->request_array[0];
// Override this vars just for the admin area
if ($this->base_request == chevereto_config('admin_folder')) {
$this->root_url = __CHV_RELATIVE_ADMIN__;
$this->base_url = __CHV_ADMIN_URL__;
}
// If the request is invalid we make a 301 redirection to the canonical url.
if ($this->root_url !== $this->request_uri and $this->canonical_request !== $this->request_uri) {
$this->redirect($this->base_redirection($this->canonical_request), 301);
}
// It's a valid request on admin or index.php?
if ($this->base_request !== chevereto_config('admin_folder')) {
if ($this->is_index()) {
$this->proccess_request();
}
} else {
// Admin credentials
if (!check_value(chevereto_config('admin_password'))) {
$admin_password_errors[] = 'You need to set the admin password in <code>$config[\'admin_password\']</code>';
}
if (chevereto_config('admin_password') == 'password') {
$admin_password_errors[] = 'You haven\'t changed the default admin password. Please set this value in <code>$config[\'admin_password\']</code>';
}
if (check_value($admin_password_errors) && !is_localhost()) {
chevereto_die($admin_password_errors, 'Config error', array('You need to fix the configuration related to the admin credentials before use this area.'));
}
require_once __CHV_PATH_ADMIN_CLASSES__ . 'class.adminhandler.php';
$handler = new AdminHandler($this->valid_request);
die;
}
}
示例2: updates
public function updates()
{
$builtin_path = SHOPP_PATH . '/templates';
$theme_path = sanitize_path(STYLESHEETPATH . '/shopp');
if (Shopp::str_true($this->form('theme_templates')) && !is_dir($theme_path)) {
$this->form['theme_templates'] = 'off';
$this->notice(Shopp::__("Shopp theme templates can't be used because they don't exist."), 'error');
}
if (empty($this->form('catalog_pagination'))) {
$this->form['catalog_pagination'] = 0;
}
// Recount terms when this setting changes
if ($this->form('outofstock_catalog') != shopp_setting('outofstock_catalog')) {
$taxonomy = ProductCategory::$taxon;
$terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids'));
if (!empty($terms)) {
wp_update_term_count_now($terms, $taxonomy);
}
}
shopp_set_formsettings();
$this->notice(Shopp::__('Presentation settings saved.'), 'notice', 20);
}
示例3: processAlbumEdit
//.........这里部分代码省略.........
}
if (isset($_POST[$prefix . 'reset_rating'])) {
$album->set('total_value', 0);
$album->set('total_votes', 0);
$album->set('used_ips', 0);
}
$pubdate = $album->setPublishDate(sanitize($_POST['publishdate-' . $prefix]));
$album->setExpireDate(sanitize($_POST['expirationdate-' . $prefix]));
$fail = '';
processCredentials($album, $suffix);
$oldtheme = $album->getAlbumTheme();
if (isset($_POST[$prefix . 'album_theme'])) {
$newtheme = sanitize($_POST[$prefix . 'album_theme']);
if ($oldtheme != $newtheme) {
$album->setAlbumTheme($newtheme);
}
}
if (isset($_POST[$prefix . 'album_watermark'])) {
$album->setWatermark(sanitize($_POST[$prefix . 'album_watermark'], 3));
$album->setWatermarkThumb(sanitize($_POST[$prefix . 'album_watermark_thumb'], 3));
}
$album->setShow(isset($_POST[$prefix . 'Published']));
zp_apply_filter('save_album_custom_data', NULL, $prefix, $album);
zp_apply_filter('save_album_utilities_data', $album, $prefix);
$album->save();
// Move/Copy/Rename the album after saving.
$movecopyrename_action = '';
if (isset($_POST['a-' . $prefix . 'MoveCopyRename'])) {
$movecopyrename_action = sanitize($_POST['a-' . $prefix . 'MoveCopyRename'], 3);
}
if ($movecopyrename_action == 'delete') {
$dest = dirname($album->name);
if ($album->remove()) {
if ($dest == '/' || $dest == '.') {
$dest = '';
}
$redirectto = $dest;
} else {
$notify = "&mcrerr=7";
}
}
if ($movecopyrename_action == 'move') {
$dest = sanitize_path($_POST['a' . $prefix . '-albumselect']);
// Append the album name.
$dest = ($dest ? $dest . '/' : '') . (strpos($album->name, '/') === FALSE ? $album->name : basename($album->name));
if ($dest && $dest != $album->name) {
if ($suffix = $album->isDynamic()) {
// be sure there is a .alb suffix
if (substr($dest, -4) != '.' . $suffix) {
$dest .= '.' . suffix;
}
}
if ($e = $album->move($dest)) {
$notify = "&mcrerr=" . $e;
} else {
$redirectto = $dest;
}
} else {
// Cannot move album to same album.
$notify = "&mcrerr=3";
}
} else {
if ($movecopyrename_action == 'copy') {
$dest = sanitize_path($_POST['a' . $prefix . '-albumselect']);
if ($dest && $dest != $album->name) {
if ($e = $album->copy($dest)) {
$notify = "&mcrerr=" . $e;
}
} else {
// Cannot copy album to existing album.
// Or, copy with rename?
$notify = '&mcrerr=3';
}
} else {
if ($movecopyrename_action == 'rename') {
$renameto = sanitize_path($_POST['a' . $prefix . '-renameto']);
$renameto = str_replace(array('/', '\\'), '', $renameto);
if (dirname($album->name) != '.') {
$renameto = dirname($album->name) . '/' . $renameto;
}
if ($renameto != $album->name) {
if ($suffix = $album->isDynamic()) {
// be sure there is a .alb suffix
if (substr($renameto, -4) != '.' . $suffix) {
$renameto .= '.' . $suffix;
}
}
if ($e = $album->rename($renameto)) {
$notify = "&mcrerr=" . $e;
} else {
$redirectto = $renameto;
}
} else {
$notify = "&mcrerr=3";
}
}
}
}
return $notify;
}
示例4: themepath
/**
* Update the stored path to the activated theme
*
* Automatically updates the Ecart theme path setting when the
* a new theme is activated.
*
* @since 1.1
*
* @return void
**/
function themepath () {
global $Ecart;
$Ecart->Settings->save('theme_templates',addslashes(sanitize_path(STYLESHEETPATH.'/'."ecart")));
}
示例5: presentation
public function presentation()
{
if (!current_user_can('shopp_settings_presentation')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
$builtin_path = SHOPP_PATH . '/templates';
$theme_path = sanitize_path(STYLESHEETPATH . '/shopp');
$term_recount = false;
if (!empty($_POST['save'])) {
check_admin_referer('shopp-settings-presentation');
$updated = __('Shopp presentation settings saved.', 'Shopp');
if (isset($_POST['settings']['theme_templates']) && $_POST['settings']['theme_templates'] == 'on' && !is_dir($theme_path)) {
$_POST['settings']['theme_templates'] = 'off';
$updated = __('Shopp theme templates can\'t be used because they don\'t exist.', 'Shopp');
}
if (empty($_POST['settings']['catalog_pagination'])) {
$_POST['settings']['catalog_pagination'] = 0;
}
// Recount terms when this setting changes
if (isset($_POST['settings']['outofstock_catalog']) && $_POST['settings']['outofstock_catalog'] != shopp_setting('outofstock_catalog')) {
$term_recount = true;
}
shopp_set_formsettings();
$this->notice(Shopp::__('Presentation settings saved.'), 'notice', 20);
}
if ($term_recount) {
$taxonomy = ProductCategory::$taxon;
$terms = get_terms($taxonomy, array('hide_empty' => 0, 'fields' => 'ids'));
if (!empty($terms)) {
wp_update_term_count_now($terms, $taxonomy);
}
}
// Copy templates to the current WordPress theme
if (!empty($_POST['install'])) {
check_admin_referer('shopp-settings-presentation');
copy_shopp_templates($builtin_path, $theme_path);
}
$status = 'available';
if (!is_dir($theme_path)) {
$status = 'directory';
} else {
if (!is_writable($theme_path)) {
$status = 'permissions';
} else {
$builtin = array_filter(scandir($builtin_path), 'filter_dotfiles');
$theme = array_filter(scandir($theme_path), 'filter_dotfiles');
if (empty($theme)) {
$status = 'ready';
} else {
if (array_diff($builtin, $theme)) {
$status = 'incomplete';
}
}
}
}
$category_views = array('grid' => __('Grid', 'Shopp'), 'list' => __('List', 'Shopp'));
$row_products = array(2, 3, 4, 5, 6, 7);
$productOrderOptions = ProductCategory::sortoptions();
$productOrderOptions['custom'] = __('Custom', 'Shopp');
$orderOptions = array('ASC' => __('Order', 'Shopp'), 'DESC' => __('Reverse Order', 'Shopp'), 'RAND' => __('Shuffle', 'Shopp'));
$orderBy = array('sortorder' => __('Custom arrangement', 'Shopp'), 'created' => __('Upload date', 'Shopp'));
include $this->ui('presentation.php');
}
示例6: html_encode
} else {
$r = '?page=edit&album=' . html_encode(pathurlencode($ret = sanitize_path($return)));
if (strpos($return, '*') === 0) {
$r .= '&tab=subalbuminfo';
$star = '*';
} else {
$star = '';
}
$backurl = 'admin-edit.php' . $r . '&return=' . $star . html_encode(pathurlencode($ret));
}
}
if (isset($_REQUEST['album'])) {
if (isset($_POST['album'])) {
$folder = sanitize_path(urldecode($_POST['album']));
} else {
$folder = sanitize_path($_GET['album']);
}
if (!empty($folder)) {
$album = newAlbum($folder);
if (!$album->isMyItem(ALBUM_RIGHTS)) {
if (!zp_apply_filter('admin_managed_albums_access', false, $return)) {
header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php');
exitZP();
}
}
}
$albumparm = '&album=' . pathurlencode($folder);
}
if (isset($_GET['refresh'])) {
if (empty($imageid)) {
$metaURL = $backurl;
示例7: shopp_setting
weightUnit = '<?php
echo shopp_setting('weight_unit');
?>
',
dimensionUnit = '<?php
echo shopp_setting('dimension_unit');
?>
',
storage = '<?php
echo shopp_setting('product_storage');
?>
',
productspath = '<?php
/* realpath needed for relative paths */
chdir(WP_CONTENT_DIR);
echo addslashes(trailingslashit(sanitize_path(realpath(shopp_setting('products_path')))));
?>
',
imageupload_debug = <?php
echo defined('SHOPP_IMAGEUPLOAD_DEBUG') && SHOPP_IMAGEUPLOAD_DEBUG ? 'true' : 'false';
?>
,
fileupload_debug = <?php
echo defined('SHOPP_FILEUPLOAD_DEBUG') && SHOPP_FILEUPLOAD_DEBUG ? 'true' : 'false';
?>
,
dimensionsRequired = <?php
echo $Shopp->Shipping->dimensions ? 'true' : 'false';
?>
,
startWeekday = <?php
示例8: getRSSAlbumnameAndCollection
/**
* Returns the albumname and TRUE or FALSE for the collection mode (album + subalbums)
*
* @param string $arrayfield "albumfolder" or "collection"
* @return mixed
*/
function getRSSAlbumnameAndCollection($arrayfield)
{
$arrayfield = sanitize($arrayfield);
if (!empty($arrayfield)) {
if (isset($_GET['albumname'])) {
$albumfolder = sanitize_path($_GET['albumname']);
if (!file_exists(ALBUM_FOLDER_SERVERPATH . '/' . $albumfolder)) {
$albumfolder = NULL;
}
$collection = FALSE;
} else {
if (isset($_GET['folder'])) {
$albumfolder = sanitize_path($_GET['folder']);
if (!file_exists(ALBUM_FOLDER_SERVERPATH . '/' . $albumfolder)) {
$albumfolder = NULL;
$collection = FALSE;
} else {
$collection = TRUE;
}
} else {
$albumfolder = NULL;
$collection = FALSE;
}
}
$array = array("albumfolder" => $albumfolder, "collection" => $collection);
return $array[$arrayfield];
}
}
示例9: define
}
/*** Workaround the admin request ***/
if (preg_match('/\\/admin\\//', $_SERVER['REQUEST_URI'])) {
define('access', 'admin');
define('SKIP_MAINTENANCE', true);
}
/*** Include the core functions ***/
file_exists(__CHV_FILE_FUNCTIONS__) ? require_once __CHV_FILE_FUNCTIONS__ : die('Can\'t find <strong>' . __CHV_FILE_FUNCTIONS__ . '</strong>. Make sure you have uploaded this file.');
require_once __CHV_PATH_INCLUDES__ . 'template.functions.php';
/*** Set some url paths ***/
define('__CHV_URL_SYSTEM_JS__', absolute_to_url(__CHV_PATH_SYSTEM_JS__));
define('__CHV_URL_THEME__', absolute_to_url(__CHV_PATH_THEME__));
define('__CHV_URL_UPDATE_SCRIPT__', __CHV_BASE_URL__ . 'update.php');
// Virtual paths
define('__CHV_VIRTUALFOLDER_IMAGE__', sanitize_path($config['virtual_folder_image']));
define('__CHV_VIRTUALFOLDER_UPLOADED__', sanitize_path($config['virtual_folder_uploaded']));
/*** Call the dB class ***/
require_once __CHV_PATH_CLASSES__ . 'class.db.php';
$dB = new dB();
/*** Call the Login class ***/
require_once __CHV_PATH_CLASSES__ . 'class.login.php';
$Login = new Login();
/*** Call the ShortURL class ***/
require_once __CHV_PATH_CLASSES__ . 'class.shorturl.php';
$ShortURL = new ShortURL();
/*** Flood protection ***/
if (preg_match('/upload/', access)) {
$flood = is_upload_flood();
}
/*** maintenance ***/
if (preg_match('/upload|API|pref/', access) && chevereto_config('maintenance')) {
示例10: str_replace
if (!empty($title) && $newAlbum) {
$album->setTitle($title);
}
if ($new) {
$album->setOwner($_zp_current_admin_obj->getUser());
}
$album->save();
} else {
$AlbumDirName = str_replace(SERVERPATH, '', $_zp_gallery->albumdir);
zp_error(gettext("The album could not be created in the “albums” folder. This is usually a permissions problem. Try setting the permissions on the “albums” and “cache” folders to be world-writable using a shell:") . " <code>chmod 777 " . $AlbumDirName . '/' . CACHEFOLDER . '/' . "</code>, " . gettext("or use your FTP program to give everyone write permissions to those folders."));
}
foreach ($_FILES['files']['error'] as $key => $error) {
$filecount++;
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES['files']['tmp_name'][$key];
$name = sanitize_path($_FILES['files']['name'][$key]);
$soename = seoFriendly($name);
$error = zp_apply_filter('check_upload_quota', UPLOAD_ERR_OK, $tmp_name);
if (!$error) {
if (Gallery::validImage($name) || Gallery::validImageAlt($name)) {
if (strrpos($soename, '.') === 0) {
$soename = md5($name) . $soename;
}
// soe stripped out all the name.
if (!$error) {
$uploadfile = $targetPath . '/' . internalToFilesystem($soename);
if (file_exists($uploadfile)) {
$append = '_' . time();
$soename = stripSuffix($soename) . $append . '.' . getSuffix($soename);
$uploadfile = $targetPath . '/' . internalToFilesystem($soename);
}
示例11: save_product
//.........这里部分代码省略.........
}
// Save prices that there are updates for
foreach($_POST['price'] as $i => $option) {
if (empty($option['id'])) {
$Price = new Price();
$option['product'] = $Product->id;
} else $Price = new Price($option['id']);
$option['sortorder'] = array_search($i,$_POST['sortorder'])+1;
// Remove VAT amount to save in DB
if ($base['vat'] && isset($option['tax']) && $option['tax'] == "on") {
$option['price'] = (floatvalue($option['price'])/(1+$taxrate));
$option['saleprice'] = (floatvalue($option['saleprice'])/(1+$taxrate));
}
$option['shipfee'] = floatvalue($option['shipfee']);
$option['weight'] = floatvalue($option['weight']);
if (isset($options['dimensions']) && is_array($options['dimensions']))
foreach ($option['dimensions'] as &$dimension)
$dimension = floatvalue($dimension);
$Price->updates($option);
$Price->save();
if (!empty($option['download'])) $Price->attach_download($option['download']);
if (!empty($option['downloadpath'])) { // Attach file specified by URI/path
if (!empty($Price->download->id) || (empty($Price->download) && $Price->load_download())) {
$File = $Price->download;
} else $File = new ProductDownload();
$stored = false;
$tmpfile = sanitize_path($option['downloadpath']);
$File->storage = false;
$Engine = $File->_engine(); // Set engine from storage settings
$File->parent = $Price->id;
$File->context = "price";
$File->type = "download";
$File->name = !empty($option['downloadfile'])?$option['downloadfile']:basename($tmpfile);
$File->filename = $File->name;
if ($File->found($tmpfile)) {
$File->uri = $tmpfile;
$stored = true;
} else $stored = $File->store($tmpfile,'file');
if ($stored) {
$File->readmeta();
$File->save();
}
} // END attach file by path/uri
}
unset($Price);
}
// No variation options at all, delete all variation-pricelines
if (!empty($Product->prices) && is_array($Product->prices)
&& (empty($_POST['options']['v']) || empty($_POST['options']['a']))) {
foreach ($Product->prices as $priceline) {
// Skip if not tied to variation options
if ($priceline->optionkey == 0) continue;
if ((empty($_POST['options']['v']) && $priceline->context == "variation")
示例12: header
header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php');
exit;
}
}
$sql = "SELECT `id` FROM " . prefix('albums') . " WHERE `folder`=" . db_quote($folder);
$row = query_single_row($sql);
$id = $row['id'];
}
if (!empty($id)) {
$imagewhere = "WHERE `albumid`={$id}";
$r = " {$folder}";
$albumwhere = "WHERE `parentid`={$id}";
}
}
if (isset($_REQUEST['return'])) {
$ret = sanitize_path($_REQUEST['return']);
}
if (!empty($ret)) {
$ret = '&return=' . $ret;
}
$metaURL = $starturl = '?' . $type . 'refresh=start' . $albumparm . '&XSRFToken=' . getXSRFToken('refresh') . $ret;
}
}
printAdminHeader($tab, 'refresh');
if (!empty($metaURL)) {
?>
<meta http-equiv="refresh" content="1; url=<?php
echo $metaURL;
?>
" />
<?php
示例13: open
/**
* Initializing routine for the session management.
*
* @since 1.1
*
* @return boolean
**/
function open ($path,$name) {
$this->path = $path;
if (empty($this->path)) $this->path = sanitize_path(realpath(ECART_TEMP_PATH));
$this->trash(); // Clear out any residual session information before loading new data
if (empty($this->session)) $this->session = session_id(); // Grab our session id
$this->ip = $_SERVER['REMOTE_ADDR']; // Save the IP address making the request
if (!isset($_COOKIE[ECART_SECURE_KEY])) $this->securekey();
return true;
}
示例14: load_ecarts_wpconfig
/**
* Read the wp-config file to import WP settings without loading all of WordPress
*
* @since 1.1
* @return boolean If the load was successful or not
**/
function load_ecarts_wpconfig () {
global $table_prefix;
$configfile = 'wp-config.php';
$loadfile = 'wp-load.php';
$wp_config_path = $wp_abspath = false;
$syspath = explode('/',$_SERVER['SCRIPT_FILENAME']);
$uripath = explode('/',$_SERVER['SCRIPT_NAME']);
$rootpath = array_diff($syspath,$uripath);
$root = '/'.join('/',$rootpath);
$filepath = dirname(!empty($_SERVER['SCRIPT_FILENAME'])?$_SERVER['SCRIPT_FILENAME']:__FILE__);
if ( file_exists(sanitize_path($root).'/'.$loadfile))
$wp_abspath = $root;
if ( isset($_SERVER['ECART_WPCONFIG_PATH'])
&& file_exists(sanitize_path($_SERVER['ECART_WPCONFIG_PATH']).'/'.$configfile) ) {
// SetEnv ECART_WPCONFIG_PATH /path/to/wpconfig
// and ECART_ABSPATH used on webserver site config
$wp_config_path = $_SERVER['ECART_WPCONFIG_PATH'];
} elseif ( strpos($filepath, $root) !== false ) {
// Ecart directory has DOCUMENT_ROOT ancenstor, find wp-config.php
$fullpath = explode ('/', sanitize_path($filepath) );
while (!$wp_config_path && ($dir = array_pop($fullpath)) !== null) {
if (file_exists( sanitize_path(join('/',$fullpath)).'/'.$loadfile ))
$wp_abspath = join('/',$fullpath);
if (file_exists( sanitize_path(join('/',$fullpath)).'/'.$configfile ))
$wp_config_path = join('/',$fullpath);
}
} elseif ( file_exists(sanitize_path($root).'/'.$configfile) ) {
$wp_config_path = $root; // WordPress install in DOCUMENT_ROOT
} elseif ( file_exists(sanitize_path(dirname($root)).'/'.$configfile) ) {
$wp_config_path = dirname($root); // wp-config up one directory from DOCUMENT_ROOT
}
$wp_config_file = sanitize_path($wp_config_path).'/'.$configfile;
if ( $wp_config_path !== false )
$config = file_get_contents($wp_config_file);
else return false;
preg_match_all('/^\s*?(define\(\s*?\'(.*?)\'\s*?,\s*(.*?)\);)/m',$config,$defines,PREG_SET_ORDER);
foreach($defines as $defined) if (!defined($defined[2])) {
list($line,$line,$name,$value) = $defined;
$value = str_replace('__FILE__',"'$wp_abspath/$loadfile'",$value);
$value = safe_define_ev($value);
// Override ABSPATH with ECART_ABSPATH
if ($name == "ABSPATH" && isset($_SERVER['ECART_ABSPATH'])
&& file_exists(sanitize_path($_SERVER['ECART_ABSPATH']).'/'.$loadfile))
$value = rtrim(sanitize_path($_SERVER['ECART_ABSPATH']),'/').'/';
define($name,$value);
}
// Get the $table_prefix value
preg_match('/(\$table_prefix\s*?=.+?);/m',$config,$match);
$table_prefix = safe_define_ev($match[1]);
if(function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
return true;
}
示例15: handleOptionSave
static function handleOptionSave($themename, $themealbum)
{
$notify = '';
$list = array();
foreach ($_POST as $key => $param) {
if ($param) {
if (strpos($key, 'ipBlocker_ip_') !== false) {
if (preg_match("/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\$/", $param)) {
$p = explode('_', substr($key, 13));
$list[$p[1]][$p[0]] = $param;
}
}
}
}
foreach ($list as $key => $range) {
if (!array_key_exists('start', $range) || !array_key_exists('end', $range)) {
unset($list[$key]);
$notify .= gettext('IP address format error') . '<br />';
}
}
setOption('ipBlocker_list', serialize($list));
purgeOption('ipBlocker_import');
if (!empty($_POST['ipBlocker_import'])) {
$file = SERVERPATH . '/' . UPLOAD_FOLDER . '/' . sanitize_path($_POST['ipBlocker_import']);
if (file_exists($file)) {
$import_list = array();
// insert current list into import list for posterity
foreach ($list as $range) {
$ipa = explode('.', $range['end']);
$ipend = sprintf('%03u.%03u.%03u.%03u', @$ipa[0], @$ipa[1], @$ipa[2], @$ipa[3]);
$ipa = explode('.', $range['start']);
do {
$current = sprintf('%03u.%03u.%03u.%03u', @$ipa[0], @$ipa[1], @$ipa[2], @$ipa[3]);
$ipa[3]++;
if ($ipa[3] > 255) {
$ipa[3] = 0;
$ipa[2]++;
if ($ipa[2] > 255) {
$ipa[2] = 0;
$ipa[2]++;
if ($ipa[1] > 255) {
$ipa[1] = 0;
$ipa[0]++;
if ($ipa[0] > 255) {
break;
}
}
}
}
$import_list[] = $current;
} while ($current < $ipend);
}
$import = explode("\n", file_get_contents($file));
foreach ($import as $ip) {
$ip = trim($ip);
if ($ip) {
$ipa = explode('.', $ip);
$import_list[] = sprintf('%03u.%03u.%03u.%03u', @$ipa[0], @$ipa[1], @$ipa[2], @$ipa[3]);
}
}
$list = array();
if (!empty($import_list)) {
$import_list = array_unique($import_list);
// remove duplicates
sort($import_list);
//now make a range pair list for the storage.
$current = $start = array_shift($import_list);
$end = $start;
$clean = false;
while (!empty($import_list)) {
$try = trim(array_shift($import_list));
if ($try) {
// ignore empty lines
$ipa = explode('.', $current);
$ipa[3]++;
if ($ipa[3] > 255) {
$ipa[3] = 0;
$ipa[2]++;
if ($ipa[2] > 255) {
$ipa[2] = 0;
$ipa[2]++;
if ($ipa[1] > 255) {
$ipa[1] = 0;
$ipa[0]++;
if ($ipa[0] > 255) {
break;
}
}
}
}
$next = sprintf('%03u.%03u.%03u.%03u', @$ipa[0], @$ipa[1], @$ipa[2], @$ipa[3]);
$current = $try;
if ($clean = $current != $next) {
$list[] = array('start' => $start, 'end' => $end);
$start = $end = $current;
} else {
$end = $next;
}
}
}
//.........这里部分代码省略.........