pull/141/head
icret 2023-03-09 00:38:24 +08:00
parent a7ab58f4b9
commit 68ae0e6ede
11 changed files with 1214 additions and 70 deletions

View File

@ -952,7 +952,7 @@ auto_delete(); //定时删除
<a href="<?php echo is_file(APP_ROOT . '/docs/index.html') ? '../docs' : 'https://icret.github.io/EasyImages2.0/#/'; ?>" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="使用手册"><i class="icon icon-book"></i> Manual</span></a> <a href="<?php echo is_file(APP_ROOT . '/docs/index.html') ? '../docs' : 'https://icret.github.io/EasyImages2.0/#/'; ?>" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="使用手册"><i class="icon icon-book"></i> Manual</span></a>
<a href="https://t.me/Easy_Image" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="EasyImage Telegram Group"><i class="icon icon-comments-alt"></i> Telegram</span></a> <a href="https://t.me/Easy_Image" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="EasyImage Telegram Group"><i class="icon icon-comments-alt"></i> Telegram</span></a>
<a href="https://github.com/icret/EasyImages2.0/discussions" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="GitHub 社区"><i class="icon icon-comments-alt"></i> Discuss</span></a> <a href="https://github.com/icret/EasyImages2.0/discussions" target="_blank"><span class="label label-badge label-primary" data-toggle="tooltip" title="GitHub 社区"><i class="icon icon-comments-alt"></i> Discuss</span></a>
<span data-toggle="tooltip" title="当前版本更新日志"><button type="button" class="btn btn-sm btn-primary label label-badge label-primary" data-toggle="modal" data-moveable="true" ata-size="sm" data-scroll-inside="true" data-icon="heart" data-title="当前版本更新日志" data-custom="<pre style='background-color: rgba(0, 0, 0, 0);border-color:rgba(0, 0, 0, 0);'><?php echo getVersion('name') . '<br/><br/>' . getVersion('body'); ?></pre>"><i class="icon icon-github"></i> <?php echo get_current_version(); ?></button></span> <span data-toggle="tooltip" title="当前版本"><button type="button" class="btn btn-sm btn-primary label label-badge label-primary" data-toggle="modal" data-moveable="true" ata-size="sm" data-scroll-inside="true" data-icon="heart" data-title="当前版本更新日志" data-custom="<pre style='background-color: rgba(0, 0, 0, 0);border-color:rgba(0, 0, 0, 0);'><?php echo getVersion('name') . '<br/><br/>' . getVersion('body'); ?></pre>"><i class="icon icon-github"></i> <?php echo get_current_version(); ?></button></span>
<span data-toggle="tooltip" title="您的赞美是我开发的动力!"><button type="button" class="btn btn-sm btn-danger label label-badge label-danger" data-toggle="modal" data-moveable="true" data-size="sm" data-icon="heart" data-title="您的赞美是我开发的动力!" data-custom="<ul class='nav nav-tabs'><li class='active'><a data-tab href='#wechat'><i class='icon icon-wechat' style='color:#329d38;'> 微信</i></a></li><li><a data-tab href='#alipay'><i class='icon icon-zhifubao-square' style='color:#1970fc;'> 支付宝</i></a></li></ul><div class='tab-content'><div class='tab-pane active' id='wechat'><img src='../public/images/wechat.jpg'></div><div class='tab-pane' id='alipay'><img src='../public/images/alipay.jpg'></div></div>"><i class="icon icon-yen"></i><small>打赏开发者</small></button></span> <span data-toggle="tooltip" title="您的赞美是我开发的动力!"><button type="button" class="btn btn-sm btn-danger label label-badge label-danger" data-toggle="modal" data-moveable="true" data-size="sm" data-icon="heart" data-title="您的赞美是我开发的动力!" data-custom="<ul class='nav nav-tabs'><li class='active'><a data-tab href='#wechat'><i class='icon icon-wechat' style='color:#329d38;'> 微信</i></a></li><li><a data-tab href='#alipay'><i class='icon icon-zhifubao-square' style='color:#1970fc;'> 支付宝</i></a></li></ul><div class='tab-content'><div class='tab-pane active' id='wechat'><img src='../public/images/wechat.jpg'></div><div class='tab-pane' id='alipay'><img src='../public/images/alipay.jpg'></div></div>"><i class="icon icon-yen"></i><small>打赏开发者</small></button></span>
</p> </p>
<h6>程序依赖</h6> <h6>程序依赖</h6>

View File

@ -194,30 +194,19 @@ if ($handle->uploaded) {
/** 后续处理 */ /** 后续处理 */
// 使用fastcgi_finish_request操作 // 使用fastcgi_finish_request操作
if (function_exists('fastcgi_finish_request')) { // fastcgi_finish_request 模式 if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
fastcgi_finish_request(); // 同IP上传日志
// 记录同IP上传次数 @write_ip_upload_count_logs();
@write_ip_upload_count_logs(); // 日志
// 上传日志 @write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
@write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size, $tokenID); // 鉴黄
// 鉴黄 @process_checkImg($processUrl);
@process_checkImg($processUrl); // 水印
// 水印 @water($handle->file_dst_pathname);
@water($handle->file_dst_pathname); // 压缩
// 压缩 @process_compress($handle->file_dst_pathname);
@process_compress($handle->file_dst_pathname); // 上传至其他位置
} else { // 普通模式 // @any_upload($pathIMG, APP_ROOT . $pathIMG, 'upload');
// 记录同IP上传次数
@write_ip_upload_count_logs();
// 上传日志
@write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size, $tokenID);
// 鉴黄
@process_checkImg($processUrl);
// 水印
@water($handle->file_dst_pathname);
// 压缩
@process_compress($handle->file_dst_pathname);
}
unset($handle); unset($handle);
} }

View File

@ -0,0 +1,968 @@
<?php
/*
* This file is part of the `nicolab/php-ftp-client` package.
*
* (c) Nicolas Tallefourtane <dev@nicolab.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Nicolas Tallefourtane http://nicolab.net
*/
// namespace FtpClient;
// use \Countable;
/**
* The FTP and SSL-FTP client for PHP.
*
* @method bool alloc(int $filesize, string &$result = null) Allocates space for a file to be uploaded
* @method bool append(string $remote_file, string $local_file, int $mode = FTP_BINARY) Append the contents of a file to another file on the FTP server
* @method bool cdup() Changes to the parent directory
* @method bool chdir(string $directory) Changes the current directory on a FTP server
* @method int chmod(int $mode, string $filename) Set permissions on a file via FTP
* @method bool delete(string $path) Deletes a file on the FTP server
* @method bool exec(string $command) Requests execution of a command on the FTP server
* @method bool fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server and saves to an open file
* @method bool fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Uploads from an open file to the FTP server
* @method mixed get_option(int $option) Retrieves various runtime behaviours of the current FTP stream
* @method bool get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server
* @method int mdtm(string $remote_file) Returns the last modified time of the given file
* @method array mlsd(string $remote_dir) Returns a list of files in the given directory
* @method int nb_continue() Continues retrieving/sending a file (non-blocking)
* @method int nb_fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to an open file (non-blocking)
* @method int nb_fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Stores a file from an open file to the FTP server (non-blocking)
* @method int nb_get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to a local file (non-blocking)
* @method int nb_put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Stores a file on the FTP server (non-blocking)
* @method bool pasv(bool $pasv) Turns passive mode on or off
* @method bool put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Uploads a file to the FTP server
* @method string pwd() Returns the current directory name
* @method bool quit() Closes an FTP connection
* @method array raw(string $command) Sends an arbitrary command to an FTP server
* @method bool rename(string $oldname, string $newname) Renames a file or a directory on the FTP server
* @method bool set_option(int $option, mixed $value) Set miscellaneous runtime FTP options
* @method bool site(string $command) Sends a SITE command to the server
* @method int size(string $remote_file) Returns the size of the given file
* @method string systype() Returns the system type identifier of the remote FTP server
*
* @author Nicolas Tallefourtane <dev@nicolab.net>
*/
class FtpClient implements Countable
{
/**
* The connection with the server.
*
* @var resource
*/
protected $conn;
/**
* PHP FTP functions wrapper.
*
* @var FtpWrapper
*/
private $ftp;
/**
* Constructor.
*
* @param resource|null $connection
* @throws FtpException If FTP extension is not loaded.
*/
public function __construct($connection = null)
{
if (!extension_loaded('ftp')) {
throw new FtpException('FTP extension is not loaded!');
}
if ($connection) {
$this->conn = $connection;
}
$this->setWrapper(new FtpWrapper($this->conn));
}
/**
* Close the connection when the object is destroyed.
*/
public function __destruct()
{
if ($this->conn) {
$this->ftp->close();
}
}
/**
* Call an internal method or a FTP method handled by the wrapper.
*
* Wrap the FTP PHP functions to call as method of FtpClient object.
* The connection is automaticaly passed to the FTP PHP functions.
*
* @param string $method
* @param array $arguments
* @return mixed
* @throws FtpException When the function is not valid
*/
public function __call($method, array $arguments)
{
return $this->ftp->__call($method, $arguments);
}
/**
* Overwrites the PHP limit
*
* @param string|null $memory The memory limit, if null is not modified
* @param int $time_limit The max execution time, unlimited by default
* @param bool $ignore_user_abort Ignore user abort, true by default
* @return FtpClient
*/
public function setPhpLimit($memory = null, $time_limit = 0, $ignore_user_abort = true)
{
if (null !== $memory) {
ini_set('memory_limit', $memory);
}
ignore_user_abort($ignore_user_abort);
set_time_limit($time_limit);
return $this;
}
/**
* Get the help information of the remote FTP server.
*
* @return array
*/
public function help()
{
return $this->ftp->raw('help');
}
/**
* Open a FTP connection.
*
* @param string $host
* @param bool $ssl
* @param int $port
* @param int $timeout
*
* @return FtpClient
* @throws FtpException If unable to connect
*/
public function connect($host, $ssl = false, $port = 21, $timeout = 90)
{
if ($ssl) {
$this->conn = $this->ftp->ssl_connect($host, $port, $timeout);
} else {
$this->conn = $this->ftp->connect($host, $port, $timeout);
}
if (!$this->conn) {
throw new FtpException('Unable to connect');
}
return $this;
}
/**
* Closes the current FTP connection.
*
* @return bool
*/
public function close()
{
if ($this->conn) {
$this->ftp->close();
$this->conn = null;
}
}
/**
* Get the connection with the server.
*
* @return resource
*/
public function getConnection()
{
return $this->conn;
}
/**
* Get the wrapper.
*
* @return FtpWrapper
*/
public function getWrapper()
{
return $this->ftp;
}
/**
* Logs in to an FTP connection.
*
* @param string $username
* @param string $password
*
* @return FtpClient
* @throws FtpException If the login is incorrect
*/
public function login($username = 'anonymous', $password = '')
{
$result = $this->ftp->login($username, $password);
if ($result === false) {
throw new FtpException('Login incorrect');
}
return $this;
}
/**
* Returns the last modified time of the given file.
* Return -1 on error
*
* @param string $remoteFile
* @param string|null $format
*
* @return int
*/
public function modifiedTime($remoteFile, $format = null)
{
$time = $this->ftp->mdtm($remoteFile);
if ($time !== -1 && $format !== null) {
return date($format, $time);
}
return $time;
}
/**
* Changes to the parent directory.
*
* @throws FtpException
* @return FtpClient
*/
public function up()
{
$result = $this->ftp->cdup();
if ($result === false) {
throw new FtpException('Unable to get parent folder');
}
return $this;
}
/**
* Returns a list of files in the given directory.
*
* @param string $directory The directory, by default is "." the current directory
* @param bool $recursive
* @param callable $filter A callable to filter the result, by default is asort() PHP function.
* The result is passed in array argument,
* must take the argument by reference !
* The callable should proceed with the reference array
* because is the behavior of several PHP sorting
* functions (by reference ensure directly the compatibility
* with all PHP sorting functions).
*
* @return array
* @throws FtpException If unable to list the directory
*/
public function nlist($directory = '.', $recursive = false, $filter = 'sort')
{
if (!$this->isDir($directory)) {
throw new FtpException('"'.$directory.'" is not a directory');
}
$files = $this->ftp->nlist($directory);
if ($files === false) {
throw new FtpException('Unable to list directory');
}
$result = array();
$dir_len = strlen($directory);
// if it's the current
if (false !== ($kdot = array_search('.', $files))) {
unset($files[$kdot]);
}
// if it's the parent
if(false !== ($kdot = array_search('..', $files))) {
unset($files[$kdot]);
}
if (!$recursive) {
$result = $files;
// working with the reference (behavior of several PHP sorting functions)
$filter($result);
return $result;
}
// utils for recursion
$flatten = function (array $arr) use (&$flatten) {
$flat = [];
foreach ($arr as $k => $v) {
if (is_array($v)) {
$flat = array_merge($flat, $flatten($v));
} else {
$flat[] = $v;
}
}
return $flat;
};
foreach ($files as $file) {
$file = $directory.'/'.$file;
// if contains the root path (behavior of the recursivity)
if (0 === strpos($file, $directory, $dir_len)) {
$file = substr($file, $dir_len);
}
if ($this->isDir($file)) {
$result[] = $file;
$items = $flatten($this->nlist($file, true, $filter));
foreach ($items as $item) {
$result[] = $item;
}
} else {
$result[] = $file;
}
}
$result = array_unique($result);
$filter($result);
return $result;
}
/**
* Creates a directory.
*
* @see FtpClient::rmdir()
* @see FtpClient::remove()
* @see FtpClient::put()
* @see FtpClient::putAll()
*
* @param string $directory The directory
* @param bool $recursive
* @return bool
*/
public function mkdir($directory, $recursive = false)
{
if (!$recursive or $this->isDir($directory)) {
return $this->ftp->mkdir($directory);
}
$result = false;
$pwd = $this->ftp->pwd();
$parts = explode('/', $directory);
foreach ($parts as $part) {
if ($part == '') {
continue;
}
if (!@$this->ftp->chdir($part)) {
$result = $this->ftp->mkdir($part);
$this->ftp->chdir($part);
}
}
$this->ftp->chdir($pwd);
return $result;
}
/**
* Remove a directory.
*
* @see FtpClient::mkdir()
* @see FtpClient::cleanDir()
* @see FtpClient::remove()
* @see FtpClient::delete()
* @param string $directory
* @param bool $recursive Forces deletion if the directory is not empty
* @return bool
* @throws FtpException If unable to list the directory to remove
*/
public function rmdir($directory, $recursive = true)
{
if ($recursive) {
$files = $this->nlist($directory, false, 'rsort');
// remove children
foreach ($files as $file) {
$this->remove($file, true);
}
}
// remove the directory
return $this->ftp->rmdir($directory);
}
/**
* Empty directory.
*
* @see FtpClient::remove()
* @see FtpClient::delete()
* @see FtpClient::rmdir()
*
* @param string $directory
* @return bool
*/
public function cleanDir($directory)
{
if (!$files = $this->nlist($directory)) {
return $this->isEmpty($directory);
}
// remove children
foreach ($files as $file) {
$this->remove($file, true);
}
return $this->isEmpty($directory);
}
/**
* Remove a file or a directory.
*
* @see FtpClient::rmdir()
* @see FtpClient::cleanDir()
* @see FtpClient::delete()
* @param string $path The path of the file or directory to remove
* @param bool $recursive Is effective only if $path is a directory, {@see FtpClient::rmdir()}
* @return bool
*/
public function remove($path, $recursive = false)
{
if ($path == '.' || $path == '..') {
return false;
}
try {
if (@$this->ftp->delete($path)
or ($this->isDir($path)
and $this->rmdir($path, $recursive))) {
return true;
} else {
// in special cases the delete can fail (for example, at Symfony's "r+e.gex[c]a(r)s" directory)
$newPath = preg_replace('/[^A-Za-z0-9\/]/', '', $path);
if ($this->rename($path, $newPath)) {
if (@$this->ftp->delete($newPath)
or ($this->isDir($newPath)
and $this->rmdir($newPath, $recursive))) {
return true;
}
}
}
return false;
} catch (\Exception $e) {
return false;
}
}
/**
* Check if a directory exist.
*
* @param string $directory
* @return bool
* @throws FtpException
*/
public function isDir($directory)
{
$pwd = $this->ftp->pwd();
if ($pwd === false) {
throw new FtpException('Unable to resolve the current directory');
}
if (@$this->ftp->chdir($directory)) {
$this->ftp->chdir($pwd);
return true;
}
$this->ftp->chdir($pwd);
return false;
}
/**
* Check if a directory is empty.
*
* @param string $directory
* @return bool
*/
public function isEmpty($directory)
{
return $this->countItems($directory, null, false) === 0 ? true : false;
}
/**
* Scan a directory and returns the details of each item.
*
* @see FtpClient::nlist()
* @see FtpClient::rawlist()
* @see FtpClient::parseRawList()
* @see FtpClient::dirSize()
* @param string $directory
* @param bool $recursive
* @return array
*/
public function scanDir($directory = '.', $recursive = false)
{
return $this->parseRawList($this->rawlist($directory, $recursive));
}
/**
* Returns the total size of the given directory in bytes.
*
* @param string $directory The directory, by default is the current directory.
* @param bool $recursive true by default
* @return int The size in bytes.
*/
public function dirSize($directory = '.', $recursive = true)
{
$items = $this->scanDir($directory, $recursive);
$size = 0;
foreach ($items as $item) {
$size += (int) $item['size'];
}
return $size;
}
/**
* Count the items (file, directory, link, unknown).
*
* @param string $directory The directory, by default is the current directory.
* @param string|null $type The type of item to count (file, directory, link, unknown)
* @param bool $recursive true by default
* @return int
*/
public function countItems($directory = '.', $type = null, $recursive = true)
{
$items = (null === $type ? $this->nlist($directory, $recursive)
: $this->scanDir($directory, $recursive));
$count = 0;
foreach ($items as $item) {
if (null === $type or $item['type'] == $type) {
$count++;
}
}
return $count;
}
/**
* Count the items (file, directory, link, unknown).
* This method call `countItems()` with the default arguments.
*
* @see countItems
* @return int
*/
public function count(): int
{
return $this->countItems();
}
/**
* Downloads a file from the FTP server into a string
*
* @param string $remote_file
* @param int $mode
* @param int $resumepos
* @return string|null
*/
public function getContent($remote_file, $mode = FTP_BINARY, $resumepos = 0)
{
$handle = fopen('php://temp', 'r+');
if ($this->ftp->fget($handle, $remote_file, $mode, $resumepos)) {
rewind($handle);
return stream_get_contents($handle);
}
return null;
}
/**
* Uploads a file to the server from a string.
*
* @param string $remote_file
* @param string $content
* @return FtpClient
* @throws FtpException When the transfer fails
*/
public function putFromString($remote_file, $content)
{
$handle = fopen('php://temp', 'w');
fwrite($handle, $content);
rewind($handle);
if ($this->ftp->fput($remote_file, $handle, FTP_BINARY)) {
return $this;
}
throw new FtpException('Unable to put the file "'.$remote_file.'"');
}
/**
* Uploads a file to the server.
*
* @param string $local_file
* @return FtpClient
* @throws FtpException When the transfer fails
*/
public function putFromPath($local_file)
{
$remote_file = basename($local_file);
$handle = fopen($local_file, 'r');
if ($this->ftp->fput($remote_file, $handle, FTP_BINARY)) {
rewind($handle);
return $this;
}
throw new FtpException(
'Unable to put the remote file from the local file "'.$local_file.'"'
);
}
/**
* Upload files.
*
* @param string $source_directory
* @param string $target_directory
* @param int $mode
* @return FtpClient
*/
public function putAll($source_directory, $target_directory, $mode = FTP_BINARY)
{
$d = dir($source_directory);
// do this for each file in the directory
while ($file = $d->read()) {
// to prevent an infinite loop
if ($file != "." && $file != "..") {
// do the following if it is a directory
if (is_dir($source_directory.'/'.$file)) {
if (!$this->isDir($target_directory.'/'.$file)) {
// create directories that do not yet exist
$this->ftp->mkdir($target_directory.'/'.$file);
}
// recursive part
$this->putAll(
$source_directory.'/'.$file, $target_directory.'/'.$file,
$mode
);
} else {
// put the files
$this->ftp->put(
$target_directory.'/'.$file, $source_directory.'/'.$file,
$mode
);
}
}
}
$d->close();
return $this;
}
/**
* Downloads all files from remote FTP directory
*
* @param string $source_directory The remote directory
* @param string $target_directory The local directory
* @param int $mode
* @return FtpClient
*/
public function getAll($source_directory, $target_directory, $mode = FTP_BINARY)
{
if ($source_directory != ".") {
if ($this->ftp->chdir($source_directory) == false) {
throw new FtpException("Unable to change directory: ".$source_directory);
}
if (!(is_dir($target_directory))) {
mkdir($target_directory);
}
chdir($target_directory);
}
$contents = $this->ftp->nlist(".");
foreach ($contents as $file) {
if ($file == '.' || $file == '..') {
continue;
}
$this->ftp->get($target_directory."/".$file, $file, $mode);
}
$this->ftp->chdir("..");
chdir("..");
return $this;
}
/**
* Returns a detailed list of files in the given directory.
*
* @see FtpClient::nlist()
* @see FtpClient::scanDir()
* @see FtpClient::dirSize()
* @param string $directory The directory, by default is the current directory
* @param bool $recursive
* @return array
* @throws FtpException
*/
public function rawlist($directory = '.', $recursive = false)
{
if (!$this->isDir($directory)) {
throw new FtpException('"'.$directory.'" is not a directory.');
}
if (strpos($directory, " ") > 0) {
$ftproot = $this->ftp->pwd();
$this->ftp->chdir($directory);
$list = $this->ftp->rawlist("");
$this->ftp->chdir($ftproot);
} else {
$list = $this->ftp->rawlist($directory);
}
$items = array();
if (!$list) {
return $items;
}
if (false == $recursive) {
foreach ($list as $path => $item) {
$chunks = preg_split("/\s+/", $item);
// if not "name"
if (!isset($chunks[8]) || strlen($chunks[8]) === 0 || $chunks[8] == '.' || $chunks[8] == '..') {
continue;
}
$path = $directory.'/'.$chunks[8];
if (isset($chunks[9])) {
$nbChunks = count($chunks);
for ($i = 9; $i < $nbChunks; $i++) {
$path .= ' '.$chunks[$i];
}
}
if (substr($path, 0, 2) == './') {
$path = substr($path, 2);
}
$items[ $this->rawToType($item).'#'.$path ] = $item;
}
return $items;
}
$path = '';
foreach ($list as $item) {
$len = strlen($item);
if (!$len
// "."
|| ($item[$len-1] == '.' && $item[$len-2] == ' '
// ".."
or $item[$len-1] == '.' && $item[$len-2] == '.' && $item[$len-3] == ' ')
) {
continue;
}
$chunks = preg_split("/\s+/", $item);
// if not "name"
if (!isset($chunks[8]) || strlen($chunks[8]) === 0 || $chunks[8] == '.' || $chunks[8] == '..') {
continue;
}
$path = $directory.'/'.$chunks[8];
if (isset($chunks[9])) {
$nbChunks = count($chunks);
for ($i = 9; $i < $nbChunks; $i++) {
$path .= ' '.$chunks[$i];
}
}
if (substr($path, 0, 2) == './') {
$path = substr($path, 2);
}
$items[$this->rawToType($item).'#'.$path] = $item;
if ($item[0] == 'd') {
$sublist = $this->rawlist($path, true);
foreach ($sublist as $subpath => $subitem) {
$items[$subpath] = $subitem;
}
}
}
return $items;
}
/**
* Parse raw list.
*
* @see FtpClient::rawlist()
* @see FtpClient::scanDir()
* @see FtpClient::dirSize()
* @param array $rawlist
* @return array
*/
public function parseRawList(array $rawlist)
{
$items = array();
$path = '';
foreach ($rawlist as $key => $child) {
$chunks = preg_split("/\s+/", $child, 9);
if (isset($chunks[8]) && ($chunks[8] == '.' or $chunks[8] == '..')) {
continue;
}
if (count($chunks) === 1) {
$len = strlen($chunks[0]);
if ($len && $chunks[0][$len-1] == ':') {
$path = substr($chunks[0], 0, -1);
}
continue;
}
// Prepare for filename that has space
$nameSlices = array_slice($chunks, 8, true);
$item = [
'permissions' => $chunks[0],
'number' => $chunks[1],
'owner' => $chunks[2],
'group' => $chunks[3],
'size' => $chunks[4],
'month' => $chunks[5],
'day' => $chunks[6],
'time' => $chunks[7],
'name' => implode(' ', $nameSlices),
'type' => $this->rawToType($chunks[0]),
];
if ($item['type'] == 'link' && isset($chunks[10])) {
$item['target'] = $chunks[10]; // 9 is "->"
}
// if the key is not the path, behavior of ftp_rawlist() PHP function
if (is_int($key) || false === strpos($key, $item['name'])) {
array_splice($chunks, 0, 8);
$key = $item['type'].'#'
.($path ? $path.'/' : '')
.implode(' ', $chunks);
if ($item['type'] == 'link') {
// get the first part of 'link#the-link.ext -> /path/of/the/source.ext'
$exp = explode(' ->', $key);
$key = rtrim($exp[0]);
}
$items[$key] = $item;
} else {
// the key is the path, behavior of FtpClient::rawlist() method()
$items[$key] = $item;
}
}
return $items;
}
/**
* Convert raw info (drwx---r-x ...) to type (file, directory, link, unknown).
* Only the first char is used for resolving.
*
* @param string $permission Example : drwx---r-x
*
* @return string The file type (file, directory, link, unknown)
* @throws FtpException
*/
public function rawToType($permission)
{
if (!is_string($permission)) {
throw new FtpException('The "$permission" argument must be a string, "'
.gettype($permission).'" given.');
}
if (empty($permission[0])) {
return 'unknown';
}
switch ($permission[0]) {
case '-':
return 'file';
case 'd':
return 'directory';
case 'l':
return 'link';
default:
return 'unknown';
}
}
/**
* Set the wrapper which forward the PHP FTP functions to use in FtpClient instance.
*
* @param FtpWrapper $wrapper
* @return FtpClient
*/
protected function setWrapper(FtpWrapper $wrapper)
{
$this->ftp = $wrapper;
return $this;
}
}

View File

@ -0,0 +1,20 @@
<?php
/*
* This file is part of the `nicolab/php-ftp-client` package.
*
* (c) Nicolas Tallefourtane <dev@nicolab.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Nicolas Tallefourtane http://nicolab.net
*/
// namespace FtpClient;
/**
* The FtpException class.
* Exception thrown if an error on runtime of the FTP client occurs.
* @inheritDoc
* @author Nicolas Tallefourtane <dev@nicolab.net>
*/
class FtpException extends \Exception {}

View File

@ -0,0 +1,116 @@
<?php
/*
* This file is part of the `nicolab/php-ftp-client` package.
*
* (c) Nicolas Tallefourtane <dev@nicolab.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Nicolas Tallefourtane http://nicolab.net
*/
// namespace FtpClient;
/**
* Wrap the PHP FTP functions
*
* @method bool alloc(int $filesize, string &$result = null) Allocates space for a file to be uploaded
* @method bool cdup() Changes to the parent directory
* @method bool chdir(string $directory) Changes the current directory on a FTP server
* @method int chmod(int $mode, string $filename) Set permissions on a file via FTP
* @method bool close() Closes an FTP connection
* @method bool delete(string $path) Deletes a file on the FTP server
* @method bool exec(string $command) Requests execution of a command on the FTP server
* @method bool fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server and saves to an open file
* @method bool fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Uploads from an open file to the FTP server
* @method mixed get_option(int $option) Retrieves various runtime behaviours of the current FTP stream
* @method bool get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server
* @method bool login(string $username, string $password) Logs in to an FTP connection
* @method int mdtm(string $remote_file) Returns the last modified time of the given file
* @method bool mkdir(string $directory) Creates a directory
* @method array mlsd(string $remote_dir) Returns a list of files in the given directory
* @method int nb_continue() Continues retrieving/sending a file (non-blocking)
* @method int nb_fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to an open file (non-blocking)
* @method int nb_fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Stores a file from an open file to the FTP server (non-blocking)
* @method int nb_get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to a local file (non-blocking)
* @method int nb_put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Stores a file on the FTP server (non-blocking)
* @method array nlist(string $directory) Returns a list of file names in the given directory; remote_dir parameter may also include arguments
* @method bool pasv(bool $pasv) Turns passive mode on or off
* @method bool put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Uploads a file to the FTP server
* @method string pwd() Returns the current directory name
* @method bool quit() Closes an FTP connection
* @method array raw(string $command) Sends an arbitrary command to an FTP server
* @method array rawlist(string $directory, bool $recursive = false) Returns a detailed list of files in the given directory
* @method bool rename(string $oldname, string $newname) Renames a file or a directory on the FTP server
* @method bool rmdir(string $directory) Removes a directory
* @method bool set_option(int $option, mixed $value) Set miscellaneous runtime FTP options
* @method bool site(string $command) Sends a SITE command to the server
* @method int size(string $remote_file) Returns the size of the given file
* @method string systype() Returns the system type identifier of the remote FTP server
*
* @author Nicolas Tallefourtane <dev@nicolab.net>
*/
class FtpWrapper
{
/**
* The connection with the server
*
* @var resource
*/
protected $conn;
/**
* Constructor.
*
* @param resource &$connection The FTP (or SSL-FTP) connection (takes by reference).
*/
public function __construct(&$connection)
{
$this->conn = &$connection;
}
/**
* Forward the method call to FTP functions
*
* @param string $function
* @param array $arguments
* @return mixed
* @throws FtpException When the function is not valid
*/
public function __call($function, array $arguments)
{
$function = 'ftp_' . $function;
if (function_exists($function)) {
array_unshift($arguments, $this->conn);
return @call_user_func_array($function, $arguments);
}
throw new FtpException("{$function} is not a valid FTP function");
}
/**
* Opens a FTP connection
*
* @param string $host
* @param int $port
* @param int $timeout
* @return resource
*/
public function connect($host, $port = 21, $timeout = 90)
{
return @ftp_connect($host, $port, $timeout);
}
/**
* Opens a Secure SSL-FTP connection
* @param string $host
* @param int $port
* @param int $timeout
* @return resource
*/
public function ssl_connect($host, $port = 21, $timeout = 90)
{
return @ftp_ssl_connect($host, $port, $timeout);
}
}

View File

@ -18,12 +18,12 @@ if (empty($_REQUEST)) {
$img = rand_imgurl() . '/public/images/404.png'; $img = rand_imgurl() . '/public/images/404.png';
if (isset($_GET['url'])) { if (isset($_GET['url'])) {
$img = $_GET['url']; $img = strip_tags($_GET['url']);
} }
// 解密删除 // 解密删除
if (isset($_GET['hash'])) { if (isset($_GET['hash'])) {
$delHash = $_GET['hash']; $delHash = strip_tags($_GET['hash']);
$delHash = urlHash($delHash, 1); $delHash = urlHash($delHash, 1);
if ($config['image_recycl']) { if ($config['image_recycl']) {
@ -51,6 +51,8 @@ if (isset($_GET['hash'])) {
// 否则直接删除 // 否则直接删除
getDel($delHash, 'url'); getDel($delHash, 'url');
} }
// FTP
// any_upload($delHash, null, 'delete');
} }
// 检查登录后再处理url删除请求 // 检查登录后再处理url删除请求
@ -58,20 +60,24 @@ if (is_who_login('admin')) {
// 广场页面删除 // 广场页面删除
if (isset($_GET['url'])) { if (isset($_GET['url'])) {
getDel($_GET['url'], 'url'); getDel(strip_tags($_GET['url']), 'url');
// FTP
// any_upload(parse_url($_GET['url'])['path'], null, 'delete');
} }
// 从管理页面删除 // 从管理页面删除
if (isset($_GET['url_admin_inc'])) { if (isset($_GET['url_admin_inc'])) {
$del_url = $_GET['url_admin_inc']; $del_url = strip_tags($_GET['url_admin_inc']);
if ($config['hide_path']) { if ($config['hide_path']) {
$del_url = $config['domain'] . $config['path'] . parse_url($del_url)['path']; $del_url = $config['domain'] . $config['path'] . parse_url($del_url)['path'];
} }
getDel($del_url, 'url'); getDel($del_url, 'url');
// FTP
// any_upload(parse_url($del_url)['path'], null, 'delete');
} }
// 回收 // 回收
if (isset($_GET['recycle_url'])) { if (isset($_GET['recycle_url'])) {
$recycle_url = $_GET['recycle_url']; $recycle_url = strip_tags($_GET['recycle_url']);
$recycle_url = parse_url($recycle_url)['path']; $recycle_url = parse_url($recycle_url)['path'];
if (file_exists(APP_ROOT . $recycle_url)) { if (file_exists(APP_ROOT . $recycle_url)) {
checkImg($recycle_url, 3); checkImg($recycle_url, 3);
@ -95,18 +101,16 @@ if (is_who_login('admin')) {
} }
} }
} else { } else {
if (isset($_GET['url'])) { echo '
echo ' <script>
<script> new $.zui.Messager("请使用管理员账号登录再删除!", {
new $.zui.Messager("请使用管理员账号登录再删除!", { type: "danger", // 定义颜色主题
type: "danger", // 定义颜色主题 icon: "exclamation-sign" // 定义消息图标
icon: "exclamation-sign" // 定义消息图标 }).show();
}).show(); // 延时2s跳转
// 延时2s跳转 window.setTimeout("window.location=\'/../admin/index.php \'",3000);
window.setTimeout("window.location=\'/../admin/index.php \'",3000); </script>
</script> ';
';
}
} }
?> ?>
<div class="col-md-4 col-md-offset-4"> <div class="col-md-4 col-md-offset-4">

View File

@ -1696,7 +1696,14 @@ function auto_delete()
return false; return false;
} }
function write_login_log($user, $password, $messege) /**
* 记录登录日志
* @param String $user 登录用户
* @param String $pass 登录密码
* @param String $msg 登录提示
*/
function write_login_log($user, $pass, $msg)
{ {
$log_path = APP_ROOT . '/admin/logs/login/'; $log_path = APP_ROOT . '/admin/logs/login/';
$log_file = $log_path . date('/Y-m-') . 'logs.php'; $log_file = $log_path . date('/Y-m-') . 'logs.php';
@ -1706,6 +1713,48 @@ function write_login_log($user, $password, $messege)
if (!is_file($log_file)) file_put_contents($log_file, '<?php /** 登录日志 */ exit; ?>' . PHP_EOL, FILE_APPEND | LOCK_EX); if (!is_file($log_file)) file_put_contents($log_file, '<?php /** 登录日志 */ exit; ?>' . PHP_EOL, FILE_APPEND | LOCK_EX);
/** 写入日志 */ /** 写入日志 */
$log = '时间: ' . date('Y-m-d H:i:s') . ' IP: ' . real_ip() . ' 账号: ' . $user . ' 密码: ' . $password . ' 消息: ' . $messege; $log = '时间: ' . date('Y-m-d H:i:s') . ' IP: ' . real_ip() . ' 账号: ' . $user . ' 密码: ' . $pass . ' 消息: ' . $msg;
file_put_contents($log_file, $log . PHP_EOL, FILE_APPEND | LOCK_EX); file_put_contents($log_file, $log . PHP_EOL, FILE_APPEND | LOCK_EX);
} }
/**
* 其他上传
* 支持: FTP
* @param String $remoteFile 远程地址
* @param String $localFile 本地地址
* @param String $way 使用方式 upload 上传 | delete 删除
*
*/
function any_upload($remoteFile = null, $localFile = null, $way = 'upload')
{
global $config;
if (!$config['ftp_status']) exit;
require_once __DIR__ . '/FtpClient/FtpClient.php';
require_once __DIR__ . '/FtpClient/FtpException.php';
require_once __DIR__ . '/FtpClient/FtpWrapper.php';
$ftp = new FtpClient();
// FTP 基本信息
$ftp->connect($config['ftp_host'], $config['ftp_ssl'], $config['ftp_port'], $config['ftp_time']);
// FTP账号密码
$ftp->login($config['ftp_user'], $config['ftp_pass']);
// FTP主动|被动
$ftp->pasv($config['ftp_pasv']);
switch ($way) {
case 'upload':
// 创建文件夹
$ftp->mkdir(pathinfo($remoteFile, PATHINFO_DIRNAME), 0755, true);
// 上传文件 远端->本地
$ftp->put($remoteFile, $localFile);
break;
case 'delete':
$ftp->delete($remoteFile);
return true;
break;
}
$ftp->close();
}

View File

@ -17,6 +17,8 @@ if (isset($_POST['del_url_array'])) {
$del_num = count($del_url_array); $del_num = count($del_url_array);
for ($i = 0; $i < $del_num; $i++) { for ($i = 0; $i < $del_num; $i++) {
getDel($del_url_array[$i], 'url'); getDel($del_url_array[$i], 'url');
// FTP
// any_upload($del_url_array[$i], null, 'delete');
} }
} }

View File

@ -217,30 +217,19 @@ if ($handle->uploaded) {
/** 后续处理 */ /** 后续处理 */
// 使用fastcgi_finish_request操作 // 使用fastcgi_finish_request操作
if (function_exists('fastcgi_finish_request')) { // fastcgi_finish_request 模式 if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
fastcgi_finish_request(); // 同IP上传日志
// 同IP上传日志 @write_ip_upload_count_logs();
@write_ip_upload_count_logs(); // 日志
// 日志 @write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
@write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size); // 鉴黄
// 鉴黄 @process_checkImg($processUrl);
@process_checkImg($processUrl); // 水印
// 水印 @water($handle->file_dst_pathname);
@water($handle->file_dst_pathname); // 压缩
// 压缩 @process_compress($handle->file_dst_pathname);
@process_compress($handle->file_dst_pathname); // 上传至其他位置
} else { // 普通模式 // @any_upload($pathIMG, APP_ROOT . $pathIMG, 'upload');
// 记录同IP上传次数
@write_ip_upload_count_logs();
// 日志
@write_upload_logs($pathIMG, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
// 鉴黄
@process_checkImg($processUrl);
// 水印
@water($handle->file_dst_pathname);
// 压缩
@process_compress($handle->file_dst_pathname);
}
unset($handle); unset($handle);
} }

File diff suppressed because one or more lines are too long

View File

@ -130,7 +130,6 @@ mustLogin();
flash_swf_url: '<?php static_cdn(); ?>/public/static/zui/lib/uploader/Moxie.xap', flash_swf_url: '<?php static_cdn(); ?>/public/static/zui/lib/uploader/Moxie.xap',
// sign // sign
multipart_params: { multipart_params: {
// 'sign': new Date().format("YYYYMMddhh"),
'sign': new Date().format("YYYYMMddhh"), 'sign': new Date().format("YYYYMMddhh"),
}, },
// 预览图尺寸 // 预览图尺寸