123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- load()->model('setting');
- load()->model('attachment');
- $dos = array('attachment', 'remote', 'buckets', 'oss', 'cos', 'qiniu', 'ftp', 'upload_remote');
- $do = in_array($do, $dos) ? $do : 'global';
- if ($do == 'upload_remote') {
- if (!empty($_W['setting']['remote_complete_info']['type'])) {
- $result = file_dir_remote_upload(ATTACHMENT_ROOT . 'images');
- if (is_error($result)) {
- iajax(1, $result['message']);
- } else {
- if (file_dir_exist_image(ATTACHMENT_ROOT . 'images')) {
- iajax(2);
- } else {
- iajax(0);
- }
- }
- } else {
- iajax(1, '请先填写并开启远程附件设置');
- }
- }
- if ($do == 'global') {
- if (empty($_W['setting']['upload'])) {
- $upload = $_W['config']['upload'];
- } else {
- $upload = $_W['setting']['upload'];
- }
- $post_max_size = ini_get('post_max_size');
- $post_max_size = $post_max_size > 0 ? bytecount($post_max_size) / 1024 : 0;
- $upload_max_filesize = ini_get('upload_max_filesize');
- if (checksubmit('submit')) {
- $harmtype = array('asp','php','jsp','js','css','php3','php4','php5','ashx','aspx','exe','cgi');
- switch ($_GPC['key']) {
- case 'attachment_limit':
- $upload['attachment_limit'] = max(0, intval($_GPC['value'])); break;
- case 'image_thumb':
- $upload['image']['thumb'] = empty($_GPC['value']) ? 0 : 1;
- break;
- case 'image_width':
- $upload['image']['width'] = intval($_GPC['value']); break;
- case 'image_extentions':
- $upload['image']['extentions'] = array();
- $image_extentions = explode("\n", safe_gpc_string($_GPC['value']));
- foreach ($image_extentions as $item) {
- $item = safe_gpc_string(trim($item));
- if (!empty($item) && !in_array($item, $harmtype) && !in_array($item, $upload['image']['extentions'])) {
- $upload['image']['extentions'][] = $item;
- }
- }
- break;
- case 'image_limit':
- $upload['image']['limit'] = max(0, min(intval($_GPC['value']), $post_max_size)); break;
- case 'image_zip_percentage':
- $zip_percentage = intval($_GPC['value']);
- $upload['image']['zip_percentage'] = $zip_percentage;
- if ($zip_percentage <= 0 || $zip_percentage > 100) {
- $upload['image']['zip_percentage'] = 100; }
- break;
- case 'audio_extentions':
- $upload['audio']['extentions'] = array();
- $audio_extentions = explode("\n", safe_gpc_string($_GPC['value']));
- foreach ($audio_extentions as $item) {
- $item = safe_gpc_string(trim($item));
- if (!empty($item) && !in_array($item, $harmtype) && !in_array($item, $upload['audio']['extentions'])) {
- $upload['audio']['extentions'][] = $item;
- }
- }
- break;
- case 'audio_limit':
- $upload['audio']['limit'] = max(0, min(intval($_GPC['value']), $post_max_size)); break;
- }
- setting_save($upload, 'upload');
- iajax(0, '更新设置成功', url('system/attachment'));
- }
- if (empty($upload['image']['thumb'])) {
- $upload['image']['thumb'] = 0;
- } else {
- $upload['image']['thumb'] = 1;
- }
- $upload['image']['width'] = intval($upload['image']['width']);
- if (empty($upload['image']['width'])) {
- $upload['image']['width'] = 800;
- }
- if (!empty($upload['image']['extentions']) && is_array($upload['image']['extentions'])) {
- $upload['image']['extentions'] = implode("\n", $upload['image']['extentions']);
- }
- if (!empty($upload['audio']['extentions']) && is_array($upload['audio']['extentions'])) {
- $upload['audio']['extentions'] = implode("\n", $upload['audio']['extentions']);
- }
- if(empty($upload['image']['zip_percentage'])) {
- $upload['image']['zip_percentage'] = 100;
- }
- }
- if ($do == 'remote') {
- $remote = $_W['setting']['remote_complete_info'];
- $remote_urls = array(
- 'alioss' => array('old_url' => $remote['alioss']['url']),
- 'ftp' => array('old_url' => $remote['ftp']['url']),
- 'qiniu' => array('old_url' => $remote['qiniu']['url']),
- 'cos' => array('old_url' => $remote['cos']['url']),
- );
- if (checksubmit('submit')) {
- $remote = array(
- 'type' => intval($_GPC['type']),
- 'ftp' => array(
- 'ssl' => intval($_GPC['ftp']['ssl']),
- 'host' => $_GPC['ftp']['host'],
- 'port' => $_GPC['ftp']['port'],
- 'username' => $_GPC['ftp']['username'],
- 'password' => strexists($_GPC['ftp']['password'], '*') ? $_W['setting']['remote_complete_info']['ftp']['password'] : $_GPC['ftp']['password'],
- 'pasv' => intval($_GPC['ftp']['pasv']),
- 'dir' => $_GPC['ftp']['dir'],
- 'url' => $_GPC['ftp']['url'],
- 'overtime' => intval($_GPC['ftp']['overtime']),
- ),
- 'alioss' => array(
- 'key' => $_GPC['alioss']['key'],
- 'secret' => strexists($_GPC['alioss']['secret'], '*') ? $_W['setting']['remote_complete_info']['alioss']['secret'] : $_GPC['alioss']['secret'],
- 'bucket' => $_GPC['alioss']['bucket'],
- 'internal' => $_GPC['alioss']['internal'],
- ),
- 'qiniu' => array(
- 'accesskey' => trim($_GPC['qiniu']['accesskey']),
- 'secretkey' => strexists($_GPC['qiniu']['secretkey'], '*') ? $_W['setting']['remote_complete_info']['qiniu']['secretkey'] : trim($_GPC['qiniu']['secretkey']),
- 'bucket' => trim($_GPC['qiniu']['bucket']),
- 'url' => trim($_GPC['qiniu']['url'])
- ),
- 'cos' => array(
- 'appid' => trim($_GPC['cos']['appid']),
- 'secretid' => trim($_GPC['cos']['secretid']),
- 'secretkey' => strexists(trim($_GPC['cos']['secretkey']), '*') ? $_W['setting']['remote_complete_info']['cos']['secretkey'] : trim($_GPC['cos']['secretkey']),
- 'bucket' => trim($_GPC['cos']['bucket']),
- 'local' => trim($_GPC['cos']['local']),
- 'url' => trim($_GPC['cos']['url'])
- )
- );
- if ($remote['type'] == ATTACH_OSS) {
- if (trim($remote['alioss']['key']) == '') {
- itoast('阿里云OSS-Access Key ID不能为空', '', '');
- }
- if (trim($remote['alioss']['secret']) == '') {
- itoast('阿里云OSS-Access Key Secret不能为空', '', '');
- }
- $buckets = attachment_alioss_buctkets($remote['alioss']['key'], $remote['alioss']['secret']);
- if (is_error($buckets)) {
- itoast('OSS-Access Key ID 或 OSS-Access Key Secret错误,请重新填写', '', '');
- }
- list($remote['alioss']['bucket'], $remote['alioss']['url']) = explode('@@', $_GPC['alioss']['bucket']);
- if (empty($buckets[$remote['alioss']['bucket']])) {
- itoast('Bucket不存在或是已经被删除', '', '');
- }
- $remote['alioss']['url'] = 'http://'.$remote['alioss']['bucket'].'.'.$buckets[$remote['alioss']['bucket']]['location'].'.aliyuncs.com';
- $remote['alioss']['ossurl'] = $buckets[$remote['alioss']['bucket']]['location'].'.aliyuncs.com';
- if(!empty($_GPC['custom']['url'])) {
- $url = trim($_GPC['custom']['url'],'/');
- if (!strexists($url, 'http://') && !strexists($url, 'https://')) {
- $url = 'http://'.$url;
- }
- $remote['alioss']['url'] = $url;
- }
- attachment_replace_article_remote_url($remote_urls['alioss']['old_url'], $remote['alioss']['url']);
- } elseif ($remote['type'] == ATTACH_FTP) {
- if (empty($remote['ftp']['host'])) {
- itoast('FTP服务器地址为必填项.', '', '');
- }
- if (empty($remote['ftp']['username'])) {
- itoast('FTP帐号为必填项.', '', '');
- }
- if (empty($remote['ftp']['password'])) {
- itoast('FTP密码为必填项.', '', '');
- }
- attachment_replace_article_remote_url($remote_urls['ftp']['old_url'], $_GPC['ftp']['url']);
- } elseif ($remote['type'] == ATTACH_QINIU) {
- if (empty($remote['qiniu']['accesskey'])) {
- itoast('请填写Accesskey', referer(), 'info');
- }
- if (empty($remote['qiniu']['secretkey'])) {
- itoast('secretkey', referer(), 'info');
- }
- if (empty($remote['qiniu']['bucket'])) {
- itoast('请填写bucket', referer(), 'info');
- }
- if (empty($remote['qiniu']['url'])) {
- itoast('请填写url', referer(), 'info');
- } else {
- $remote['qiniu']['url'] = strexists($remote['qiniu']['url'], 'http') ? trim($remote['qiniu']['url'], '/') : 'http://'. trim($remote['qiniu']['url'], '/');
- }
- attachment_replace_article_remote_url($remote_urls['qiniu']['old_url'], $remote['qiniu']['url']);
- $auth = attachment_qiniu_auth($remote['qiniu']['accesskey'], $remote['qiniu']['secretkey'], $remote['qiniu']['bucket']);
- if (is_error($auth)) {
- $message = $auth['message']['error'] == 'bad token' ? 'Accesskey或Secretkey填写错误, 请检查后重新提交' : 'bucket填写错误或是bucket所对应的存储区域选择错误,请检查后重新提交';
- itoast($message, referer(), 'info');
- }
- } elseif ($remote['type'] == ATTACH_COS) {
- if (empty($remote['cos']['appid'])) {
- itoast('请填写APPID', referer(), 'info');
- }
- if (empty($remote['cos']['secretid'])) {
- itoast('请填写SECRETID', referer(), 'info');
- }
- if (empty($remote['cos']['secretkey'])) {
- itoast('请填写SECRETKEY', referer(), 'info');
- }
- if (empty($remote['cos']['bucket'])) {
- itoast('请填写BUCKET', referer(), 'info');
- }
- $remote['cos']['bucket'] = str_replace("-{$remote['cos']['appid']}", '', trim($remote['cos']['bucket']));
- if (empty($url)) {
- $url = sprintf('https://%s-%s.cos%s.myqcloud.com', $bucket, $appid, $_GPC['local']);
- }
- if (empty($remote['cos']['url'])) {
- $remote['cos']['url'] = sprintf('https://%s-%s.cos%s.myqcloud.com', $remote['cos']['bucket'], $remote['cos']['appid'], $remote['cos']['local']);
- }
- $remote['cos']['url'] = rtrim($remote['cos']['url'], '/');
- attachment_replace_article_remote_url($remote_urls['cos']['old_url'], $remote['cos']['url']);
- $auth = attachment_cos_auth($remote['cos']['bucket'], $remote['cos']['appid'], $remote['cos']['secretid'], $remote['cos']['secretkey'], $remote['cos']['local']);
- if (is_error($auth)) {
- itoast($auth['message'], referer(), 'info');
- }
- }
- $_W['setting']['remote_complete_info']['type'] = $remote['type'];
- $_W['setting']['remote_complete_info']['alioss'] = $remote['alioss'];
- $_W['setting']['remote_complete_info']['ftp'] = $remote['ftp'];
- $_W['setting']['remote_complete_info']['qiniu'] = $remote['qiniu'];
- $_W['setting']['remote_complete_info']['cos'] = $remote['cos'];
- setting_save($_W['setting']['remote_complete_info'], 'remote');
- itoast('远程附件配置信息更新成功!', url('system/attachment/remote'), 'success');
- }
- $bucket_datacenter = attachment_alioss_datacenters();
- $local_attachment = file_dir_exist_image(ATTACHMENT_ROOT . 'images');
- }
- if ($do == 'buckets') {
- $key = $_GPC['key'];
- $secret = $_GPC['secret'];
- $buckets = attachment_alioss_buctkets($key, $secret);
- if (is_error($buckets)) {
- iajax(-1, '');
- }
- $bucket_datacenter = attachment_alioss_datacenters();
- $bucket = array();
- foreach ($buckets as $key => $value) {
- $value['loca_name'] = $key. '@@'. $bucket_datacenter[$value['location']];
- $bucket[] = $value;
- }
- iajax(1, $bucket, '');
- }
- if($do == 'ftp') {
- load()->library('ftp');
- $ftp_config = array(
- 'hostname' => trim($_GPC['host']),
- 'username' => trim($_GPC['username']),
- 'password' => strexists($_GPC['password'], '*') ? $_W['setting']['remote_complete_info']['ftp']['password'] : trim($_GPC['password']),
- 'port' => intval($_GPC['port']),
- 'ssl' => trim($_GPC['ssl']),
- 'passive' => trim($_GPC['pasv']),
- 'timeout' => intval($_GPC['overtime']),
- 'rootdir' => trim($_GPC['dir']),
- );
- $url = trim($_GPC['url']);
- $filename = 'MicroEngine.ico';
- $ftp = new Ftp($ftp_config);
- if (true === $ftp->connect()) {
- if ($ftp->upload(ATTACHMENT_ROOT .'images/global/'. $filename, $filename)) {
- load()->func('communication');
- $response = ihttp_get($url. '/'. $filename);
- if (is_error($response)) {
- iajax(-1, '配置失败,FTP远程访问url错误');
- }
- if (intval($response['code']) != 200) {
- iajax(-1, '配置失败,FTP远程访问url错误');
- }
- $image = getimagesizefromstring($response['content']);
- if (!empty($image) && strexists($image['mime'], 'image')) {
- iajax(0,'配置成功');
- } else {
- iajax(-1, '配置失败,FTP远程访问url错误');
- }
- } else {
- iajax(-1, '上传图片失败,请检查配置');
- }
- } else {
- iajax(-1, 'FTP服务器连接失败,请检查配置');
- }
- }
- if ($do == 'oss') {
- load()->model('attachment');
- $key = $_GPC['key'];
- $secret = strexists($_GPC['secret'], '*') ? $_W['setting']['remote_complete_info']['alioss']['secret'] : $_GPC['secret'];
- $bucket = $_GPC['bucket'];
- $buckets = attachment_alioss_buctkets($key, $secret);
- list($bucket, $url) = explode('@@', $_GPC['bucket']);
- $result = attachment_newalioss_auth($key, $secret, $bucket, $_GPC['internal']);
- if (is_error($result)) {
- iajax(-1, 'OSS-Access Key ID 或 OSS-Access Key Secret错误,请重新填写');
- }
- $ossurl = $buckets[$bucket]['location'].'.aliyuncs.com';
- if (!empty($_GPC['url'])) {
- if (!strexists($_GPC['url'], 'http://') && !strexists($_GPC['url'],'https://')) {
- $url = 'http://'. trim($_GPC['url']);
- } else {
- $url = trim($_GPC['url']);
- }
- $url = trim($url, '/').'/';
- } else {
- $url = 'http://'.$bucket.'.'.$buckets[$bucket]['location'].'.aliyuncs.com/';
- }
- load()->func('communication');
- $filename = 'MicroEngine.ico';
- $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
- if (is_error($response)) {
- iajax(-1, '配置失败,阿里云访问url错误');
- }
- if (intval($response['code']) != 200) {
- iajax(-1, '配置失败,阿里云访问url错误,请保证bucket为公共读取的');
- }
- $image = getimagesizefromstring($response['content']);
- if (!empty($image) && strexists($image['mime'], 'image')) {
- iajax(0,'配置成功');
- } else {
- iajax(-1, '配置失败,阿里云访问url错误');
- }
- }
- if ($do == 'qiniu') {
- load()->model('attachment');
- $_GPC['secretkey'] = strexists($_GPC['secretkey'], '*') ? $_W['setting']['remote_complete_info']['qiniu']['secretkey'] : $_GPC['secretkey'];
- $auth= attachment_qiniu_auth(trim($_GPC['accesskey']), trim($_GPC['secretkey']), trim($_GPC['bucket']));
- if (is_error($auth)) {
- iajax(-1, '配置失败,请检查配置。注:请检查存储区域是否选择的是和bucket对应<br/>的区域', '');
- }
- load()->func('communication');
- $url = $_GPC['url'];
- $url = strexists($url, 'http') ? trim($url, '/') : 'http://'.trim($url, '/');
- $filename = 'MicroEngine.ico';
- $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
- if (is_error($response)) {
- iajax(-1, '配置失败,七牛访问url错误');
- }
- if (intval($response['code']) != 200) {
- iajax(-1, '配置失败,七牛访问url错误,请保证bucket为公共读取的');
- }
- $image = getimagesizefromstring($response['content']);
- if (!empty($image) && strexists($image['mime'], 'image')) {
- iajax(0,'配置成功');
- } else {
- iajax(-1, '配置失败,七牛访问url错误');
- }
- }
- if ($do == 'cos') {
- load()->model('attachment');
- $url = $_GPC['url'];
- $appid = trim($_GPC['appid']);
- $secretid = trim($_GPC['secretid']);
- $secretkey = strexists($_GPC['secretkey'], '*') ? $_W['setting']['remote_complete_info']['cos']['secretkey'] : trim($_GPC['secretkey']);
- $bucket = str_replace("-{$appid}", '', trim($_GPC['bucket']));
- if (empty($url)) {
- $url = sprintf('https://%s-%s.cos%s.myqcloud.com', $bucket, $appid, $_GPC['local']);
- }
- $url = rtrim($url, '/');
- $auth= attachment_cos_auth($bucket, $appid, $secretid, $secretkey, $_GPC['local']);
- if (is_error($auth)) {
- iajax(-1, '配置失败,请检查配置' . $auth['message'], '');
- }
- load()->func('communication');
- $filename = 'MicroEngine.ico';
- $response = ihttp_request($url. '/'.$filename, array(), array('CURLOPT_REFERER' => $_SERVER['SERVER_NAME']));
- if (is_error($response)) {
- iajax(-1, '配置失败,腾讯cos访问url错误');
- }
- if (intval($response['code']) != 200) {
- iajax(-1, '配置失败,腾讯cos访问url错误,请保证bucket为公共读取的');
- }
- $image = getimagesizefromstring($response['content']);
- if (!empty($image) && strexists($image['mime'], 'image')) {
- iajax(0,'配置成功');
- } else {
- iajax(-1, '配置失败,腾讯cos访问url错误');
- }
- }
- template('system/attachment');
|