feat: 后端全量更新 - 含所有本次需求

- Contract.php: 返回合约账户余额(balance_contract)
- My.php: 地址管理增加BTC/ETH
- AppContract.php: 一键平仓(closeall)
- AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2)
- site.php: 手续费减半(0.018→0.009)
- agent_permission_setup.sql: 代理权限SQL
- crypto_news_crawler.py: 新闻自动采集脚本
This commit is contained in:
li
2026-03-30 20:16:32 +08:00
commit 1b24994e74
6721 changed files with 1308571 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class api extends Controller{
function __construct(){
parent::__construct();
}
/**
* 通用文件预览方案
* image,media,cad,office,webodf,pdf,epub,swf,text
* 跨域:epub,pdf,odf,[text];
* @return [type] [description]
*/
public function view(){
if(!isset($this->in['path'])){
show_tips('参数错误!');
}
$this->checkAccessToken();
$this->setIdentify();
$this->display('view.html');
}
private function setIdentify(){
if(! $_SESSION['accessPlugin'] ){
session_start();
$_SESSION['accessPlugin'] = 'ok';
session_write_close();
}
}
public function checkAccessToken(){
$model = $this->loadModel('Plugin');
$config = $model->getConfig('fileView');
if(!$config['apiKey']){
return;
}
$timeTo = isset($this->in['timeTo'])?intval($this->in['timeTo']):'';
$token = md5($config['apiKey'].$this->in['path'].$timeTo);
//show_tips(array($config['apiKey'],$token,$this->in));
if($token != $this->in['token']){
show_tips('token 错误!');
}
if($timeTo != '' && $timeTo <= time()){
show_tips('token已失效!');
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class app extends Controller{
function __construct() {
parent::__construct();
$this->sql=new FileCache(USER_SYSTEM.'apps.php');
}
/**
* 用户首页展示
*/
public function index() {
$this->display('index.html');
}
public function initApp(){
//为空则不初始化桌面
if(!$this->config['settingSystem']['desktopFolder']){
return;
}
$list = $this->sql->get();
$newUserApp = $this->config['settingSystem']['newUserApp'];
$default = explode(',',$newUserApp);
$info = array();
foreach ($default as $key) {
$info[$key] = $list[$key];
}
$desktop = iconv_system(HOME.DESKTOP_FOLDER.'/');
if($GLOBALS['isRoot'] == 1){
$desktop = iconv_system(MYHOME.DESKTOP_FOLDER.'/');
}
mk_dir($desktop);
if(!path_writeable($desktop)){
return;
}
foreach ($info as $key => $data) {
if (!is_array($data)) {
continue;
}
$path = $desktop.iconv_system($key).'.oexe';
unset($data['name']);
unset($data['desc']);
unset($data['group']);
file_put_contents($path, json_encode($data));
}
}
/**
* 用户app 添加、编辑
*/
public function userApp() {
$path = _DIR($this->in['path']);
if(get_path_ext($path) != 'oexe'){
$path .= '.oexe';
}
if (!checkExt($path)) {
show_json(LNG('error'));exit;
}
$data = $this->_init();
unset($data['name']);
unset($data['path']);
unset($data['desc']);
unset($data['group']);
$res = file_put_contents($path, json_encode($data));
show_json(LNG('success'));
}
/**
* 获取列表
*/
public function get() {
$list = array();
if (!isset($this->in['group']) || $this->in['group']=='all') {
$list = $this->sql->get();
}else{
$list = $this->sql->get(array('group',$this->in['group']));
}
$list = array_reverse($list);
show_json($list);
}
/**
* 添加
*/
public function add() {
$res=$this->sql->set(rawurldecode($this->in['name']),$this->_init());
if($res) show_json(LNG('success'));
show_json(LNG('error_repeat'),false);
}
/**
* 编辑
*/
public function edit() {
//查找到一条记录,修改为该数组
$this->sql->remove(rawurldecode($this->in['old_name']));
if($this->sql->set(rawurldecode($this->in['name']),$this->_init())){
show_json(LNG('success'));
}
show_json(LNG('error_repeat'),false);
}
/**
* 删除
*/
public function del() {
if($this->sql->remove(rawurldecode($this->in['name']))){
show_json(LNG('success'));
}
show_json(LNG('error'),false);
}
public function getUrlTitle(){
$html = curl_get_contents($this->in['url']);
$result = match_text($html,"<title>(.*)<\/title>");
if (strlen($result)>50) {
$result = mb_substr($result,0,50,'utf-8');
}
if (!$result || strlen($result) == 0) {
$result = $this->in['url'];
$result = str_replace(array('http://','&','/'),array('','@','-'), $result);
}
show_json($result);
}
private function _init(){
$data = rawurldecode($this->in['data']);
$arr = json_decode($data,true);
if(!is_array($arr)){
show_json(LNG('error'),false);
}
return $arr;
}
}
@@ -0,0 +1,32 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class desktop extends Controller{
function __construct() {
parent::__construct();
}
public function index() {
$wap = is_wap() && (!isset($_COOKIE['forceWap']) || $_COOKIE['forceWap'] == '1');
$desktopApps = include(DATA_PATH.'system/desktop_app.php');
$wall = $this->config['user']['wall'];
if( !strstr($wall,'/') ){
$wall = STATIC_PATH.'images/wall_page/'.$wall.'.jpg';
}
$wall = str_replace('&amp;','&',$wall);
$desktop = iconv_system(HOME.DESKTOP_FOLDER.'/');
if($GLOBALS['isRoot'] == 1){
$desktop = iconv_system(MYHOME.DESKTOP_FOLDER.'/');
}
mk_dir($desktop);
$this->assign('wall',$wall);
$this->assign('desktopApps',$desktopApps);
$this->display('index.html');
}
}
@@ -0,0 +1,152 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class editor extends Controller{
function __construct() {
parent::__construct();
}
// 多文件编辑器
public function index(){
$this->themeSet();
$this->display('editor.html');
}
// 单文件编辑
public function edit(){
$this->themeSet();
$this->display('edit.html');
}
private function themeSet(){
$setClass = '';
//获取编辑器配置数据
$editorConfig = $this->config['editorDefault'];
$configFile = USER.'data/editor_config.php';
if (!file_exists(iconv_system($configFile))) {//不存在则创建
$sql=FileCache::save($configFile,$editorConfig);
}else{
$editorConfig=FileCache::load($configFile);
}
$blackTheme = array("ambiance","idle_fingers","monokai","pastel_on_dark","twilight",
"solarized_dark","tomorrow_night_blue","tomorrow_night_eighties");
if(in_array($editorConfig['theme'],$blackTheme)){
$setClass = 'class="code-theme-black"';
}
$this->assign('editorConfig',json_encode($editorConfig));//获取编辑器配置信息
$this->assign('codeThemeBlack',$setClass);//获取编辑器配置信息
}
// 获取文件数据
public function fileGet(){
if(isset($this->in['fileUrl'])){
$pass = $this->config['settingSystem']['systemPassword'];
$fileUrl = $this->in['fileUrl'];
if(!request_url_safe($fileUrl)){
show_json(LNG('url error!'),false);
}
$urlInfo = parse_url_query($fileUrl);
if( isset($urlInfo['fid']) &&
strlen(Mcrypt::decode($urlInfo['fid'],$pass)) != 0
){
$filepath = Mcrypt::decode($urlInfo['fid'],$pass);
$displayName = get_path_this($filepath);
if(isset($urlInfo['downFilename'])){
$displayName = rawurldecode($urlInfo['downFilename']);
}
}else{
$displayName = rawurldecode($urlInfo['name']);
$filepath = $fileUrl.'&accessToken='.access_token_get();
}
}else{
$displayName = rawurldecode($this->in['filename']);
$filepath =_DIR($this->in['filename']);
if (!file_exists($filepath)){
show_json(LNG('not_exists'),false);
}
if (!path_readable($filepath)){
show_json(LNG('no_permission_read_all'),false);
}
if (filesize($filepath) >= 1024*1024*20){
show_json(LNG('edit_too_big'),false);
}
}
$fileContents=file_get_contents($filepath);//文件内容
//echo $fileContents;exit;
if(isset($this->in['charset']) && $this->in['charset']){
$charset = strtolower($this->in['charset']);
}else{
$charset = get_charset($fileContents);
}
if ($charset !='' &&
$charset !='utf-8' &&
function_exists("mb_convert_encoding")
){
$fileContents = @mb_convert_encoding($fileContents,'utf-8',$charset);
}
$data = array(
'ext' => get_path_ext($displayName),
'name' => iconv_app(get_path_this($displayName)),
'filename' => $displayName,
'charset' => $charset,
'base64' => true,// 部分防火墙编辑文件误判问题处理
'content' => base64_encode($fileContents)
);
show_json($data);
}
public function fileSave(){
$fileStr = rawurldecode($this->in['filestr']);
$path =_DIR($this->in['path']);
if(isset($this->in['create_file']) && !file_exists($path)){//不存在则创建
if(!@touch($path)){
show_json(LNG('create_error'),false);
}
}
if (!path_writeable($path)) show_json(LNG('no_permission_write_file'),false);
//支持二进制文件读写操作(base64方式)
if(isset($this->in['base64'])){
$fileStr = base64_decode($fileStr);
}
$charset = strtolower($this->in['charset']);
if(isset($this->in['charsetSave'])){
$charset = strtolower($this->in['charsetSave']);
}
if ( $charset !='' &&
$charset != 'utf-8' &&
$charset != 'ascii' &&
function_exists("mb_convert_encoding")
) {
$fileStr = @mb_convert_encoding($fileStr,$charset,'utf-8');
}
$fp=fopen($path,'wb');
fwrite($fp,$fileStr);
fclose($fp);
show_json(LNG('save_success'));
}
/*
* 获取编辑器配置信息
*/
public function setConfig(){
$file = USER.'data/editor_config.php';
if (!path_writeable(iconv_system($file))) {//配置不可写
show_json(LNG('no_permission_write_file'),false);
}
$key= $this->in['k'];
$value = $this->in['v'];
if ($key !='' && $value != '') {
$sql=new FileCache($file);
$sql->set($key,$value);//没有则添加一条
show_json(LNG('setting_success'));
}else{
show_json(LNG('error'),false);
}
}
}
File diff suppressed because it is too large Load Diff
+82
View File
@@ -0,0 +1,82 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class fav extends Controller{
private $sql;
function __construct(){
parent::__construct();
$this->sql=new FileCache(USER.'data/fav.php');
}
/**
* 获取收藏夹json
*/
public function get() {
show_json($this->sql->get());
}
/**
* 添加
*/
public function add() {
$name = $this->in['name'];
$path = $this->in['path'];
if($this->sql->get($name)){//已存在则自动重命名
$index = 0;
while ($this->sql->get($name.'('.$index.')')) {
$index ++;
}
$name = $name.'('.$index.')';
}
$res=$this->sql->set(
$name,
array(
'name' => $name,
'path' => $path,
'ext' => $this->in['ext'],
'type' => $this->in['type']
)
);
show_json(LNG('success'));
}
/**
* 编辑
*/
public function edit() {
$this->in['name'] = $this->in['name'];
$this->in['path'] = $this->in['path'];
$this->in['nameTo'] = $this->in['nameTo'];
$newFav = $this->sql->get($this->in['name']);
if(!isset($newFav['type'])){
$newFav['type'] = 'folder';
}
//查找到一条记录,修改为该数组
$toArray=array(
'name'=>$this->in['nameTo'],
'path'=>$this->in['pathTo'],
'type'=>$newFav['type']
);
$this->sql->remove($this->in['name']);
if($this->sql->set($this->in['nameTo'],$toArray)){
show_json(LNG('success'));
}
show_json(LNG('error_repeat'),false);
}
/**
* 删除
*/
public function del() {
$this->in['name'] = $this->in['name'];
if($this->sql->remove($this->in['name'])){
show_json(LNG('success'));
}
show_json(LNG('error'),false);
}
}
@@ -0,0 +1,223 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*
*
* 插件管理:页面;列表;
*/
class pluginApp extends Controller{
function __construct() {
parent::__construct();
}
//?pluginApp/to/epubReader/index&a=1
//?pluginApp/to/epubReader/&a=1 ==>ignore index;
public function to() {
$route = $this->in['URLremote'];
if(count($route) >= 3){
$app = clear_html($route[2]);
$action = $route[3];
if(count($route) == 3){
$action = 'index';
}
$model = $this->loadModel('Plugin');
if(!$model->checkAuth($app)){
if(!$_SESSION['kodLogin']){
show_tips("出错了!您尚未登录",APP_HOST,3);
}
show_tips("出错了!插件未开启,或您没有{$app}插件的权限!");
}
$appConfig = $model->getConfig($app);
if(!$appConfig['pluginAuthOpen'] && !$this->checkAccessPlugin()){
if(!$_SESSION['kodLogin']){
show_tips("出错了!您尚未登录",APP_HOST,3);
}
show_tips("出错了!插件未开启,或您没有{$app}插件的权限");
}
Hook::trigger("pluginRun.before",$app.'Plugin.'.$action);
Hook::trigger($app.'Plugin.'.$action.'.before');
Hook::apply($app.'Plugin.'.$action);
Hook::trigger($app.'Plugin.'.$action.'.after');
Hook::trigger("pluginRun.after",$app.'Plugin.'.$action);
}
}
//权限认证
private function checkAccessPlugin(){
if( $_SESSION['kodLogin'] == true ||
$_SESSION['accessPlugin'] == 'ok' ||
$this->checkAccessShare()
){
return true;
}
return false;
}
private function checkAccessShare(){
if(!isset($this->in['path'])){
return false;
}
$share = KOD_USER_SHARE;
if(substr(urldecode($this->in['path']),0,strlen($share)) == $share){
return true;
}
return false;
}
//plugin manager
public function index() {
$this->display('index.html');
}
public function appList(){
$model = $this->loadModel('Plugin');
$list = $model->viewList();
show_json($list);
}
public function changeStatus(){
if( !isset($this->in['app']) ||
!isset($this->in['status'])){
show_json(LNG('data_not_full'),false);
}
$app = $this->in['app'];
$status = $this->in['status']?1:0;
$model = $this->loadModel('Plugin');
//启用插件则检测配置文件,必填字段是否为空;为空则调用配置
if($status){
$config = $model->getConfig($app);
$package = $model->getPackageJson($app);
$needConfig = false;
foreach($package['configItem'] as $key=>$item) {
if( (isset($item['require']) && $item['require']) &&
(!isset($item['value']) || $item['value'] === '' || $item['value'] === null) &&
(!isset($config[$key]) || $config[$key] == "")
){
$needConfig = true;
break;
}
}
if($needConfig){
show_json('needConfig',false);
}
}
$model->changeStatus($app,$status);
$list = $model->viewList();
show_json($list);
}
public function setConfig(){
if( !$this->in['app'] ||
!$this->in['value']){
show_json(LNG('data_not_full'),false);
}
$json = $this->in['value'];
$app = $this->in['app'];
$model = $this->loadModel('Plugin');
//重置为默认配置
if($json == 'reset'){
$json = $model->getConfigDefault($app);
}else{
if(!is_array($json)){
show_json($json,false);
}
}
$model->changeStatus($app,1);
$model->setConfig($app,$json);
show_json(LNG('success'));
}
// download=>fileSize=>unzip=>remove
public function install(){
if(!preg_match("/^[0-9a-zA-Z_]*$/",$this->in['app'])) show_json("error!",false);
$app = _DIR_CLEAR($this->in['app']);
$appPath = PLUGIN_DIR.$app.'.zip';
$appPathTemp = $appPath.'.downloading';
switch($this->in['step']){
case 'check':
$info = $this->pluginInfo($app);
if(!is_array($info)){
show_json(false,false);
}
echo json_encode($info);
break;
case 'download':
if(!is_writable(PLUGIN_DIR)){
show_json(LNG("no_permission_write").': '.PLUGIN_DIR,false);
}
$info = $this->pluginInfo($app);
if(!$info || !$info['code']){
show_json(LNG('error'),false);
}
$result = Downloader::start($info['data'],$appPath);
show_json($result['data'],!!$result['code'],$app);
break;
case 'fileSize':
if(file_exists($appPath)){
show_json(filesize($appPath));
}
if(file_exists($appPathTemp)){
show_json(filesize($appPathTemp));
}
show_json(0,false);
break;
case 'unzip':
//hook log
$GLOBALS['isRoot'] = 1;
if(!file_exists($appPath)){
show_json(LNG("error"),false);
}
$result = KodArchive::extract($appPath,PLUGIN_DIR.$app.'/');
del_file($appPathTemp);
del_file($appPath);
show_json($result['data'],!!$result['code']);
break;
case 'remove':
del_file($appPathTemp);
del_file($appPath);
show_json(LNG('success'));
break;
case 'update':
show_json(Hook::apply($app.'Plugin.update'));
break;
default:break;
}
}
private function pluginInfo($app){
$api = $this->config['settings']['pluginServer'].'plugin/install';
$param = array(
"app" => $app,
"version" => KOD_VERSION,
"versionHash" => $this->config['settingSystem']['versionHash'],
"systemOS" => $this->config['systemOS'],
"phpVersion" => PHP_VERSION,
"channel" => INSTALL_CHANNEL,
"lang" => I18n::getType()
);
$info = url_request($api,'POST',$param);
$result = false;
if($info && $info['data']){
$result = json_decode($info['data'],true);
}
return $result;
}
public function unInstall(){
if( !$this->in['app']){
show_json(LNG('data_not_full'),false);
}
if(!preg_match("/^[0-9a-zA-Z_]*$/",$this->in['app'])) show_json("error!",false);
$model = $this->loadModel('Plugin');
$model->remove($this->in['app']);
del_dir(PLUGIN_DIR.$this->in['app']);
$list = $model->viewList();
show_json($list);
}
}
@@ -0,0 +1,147 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class setting extends Controller{
private $sql;
function __construct(){
parent::__construct();
}
/**
* 用户首页展示
*/
public function index() {
$this->display('index.html');
}
/**
* 用户首页展示
*/
public function slider() {
switch ($this->in['slider']) {
case 'about':show_json(file_get_contents(LANGUAGE_PATH.I18n::getType().'/about.html'));break;
case 'help':show_json(file_get_contents(LANGUAGE_PATH.I18n::getType().'/help.html'));break;
case 'member':break;
case 'fav':break;
case 'user':
case 'theme':
case 'wall':
show_json(array(
'settingAll' => $this->config['settingAll'],
'user' => $this->config['user'],
'wallpageDesktop' => $this->config['settingSystem']['wallpageDesktop'],
'wallpageLogin' => $this->config['settingSystem']['wallpageLogin'],
));
break;
case 'system':
if($GLOBALS['isRoot']){
if(isset($this->in['env_check'])){
show_json(php_env_check());
}
$result = $this->config['settingSystem'];
unset($result['systemPassword']);
show_json($result,true);
}else{
show_json('error',false);
}
break;
default:break;
}
}
public function phpInfo(){
phpinfo();
}
//管理员 系统设置全局数据
public function systemSetting(){
$settingFile = USER_SYSTEM.'system_setting.php';
$data = json_decode($this->in['data'],true);
if (!$data) {
show_json(LNG('error'),false);
}
$setting = $GLOBALS['config']['settingSystem'];
foreach ($data as $key => $value){
if ($key=='menu') {
$setting[$key] = $value;
}else{
$setting[$key] = rawurldecode($value);
}
}
//为了保存更多的数据;不直接覆盖文件 $data->setting_file;
FileCache::save($settingFile,$setting);
show_json(LNG('success'));
}
public function systemTools(){
$action = $this->in['action'];
switch($action){
case 'clearCache':$this->_clearCache();break;
case 'clearSession':$this->_clearSession();break;
case 'clearUserRecycle':$this->_clearUserRecycle();break;
default:break;
}
show_json(LNG('success'),true);
}
private function _clearSession(){
del_dir(KOD_SESSION);
}
private function _clearCache(){
del_dir(TEMP_PATH);
mk_dir(TEMP_PATH.'log');
mk_dir(TEMP_PATH.'thumb');
}
private function _clearUserRecycle(){
$sql = systemMember::loadData();
$user_arr = $sql->get();
foreach ($user_arr as $key => $user) {
$userPath = iconv_system(USER_PATH.$user['path']."/");
$pathArr = array(
$userPath.'data/temp',
$userPath.'data/share_temp',
$userPath.'recycle_kod'
);
foreach ($pathArr as $value) {
del_dir($value);
mk_dir($value);
}
}
}
/**
* 参数设置
* 可以同时修改多个:key=a,b,c&value=1,2,3
* 防xss 做过滤
*/
public function set(){
$file = USER.'data/config.php';
if (!path_writeable(iconv_system($file))) {//配置不可写
show_json(LNG('no_permission_write_file'),false);
}
$key = $this->in['k'];
$value = $this->in['v'];
if ($key !='' && $value != '') {
$conf = $this->config['user'];
if(!strpos($key,',')){//多个参数,value不能包含','
$conf[$key] = clear_html($value);
}else{
$arr_k = explode(',', $key);
$arr_v = explode(',',$value);
$num = count($arr_k);
for ($i=0; $i < $num; $i++) {
$conf[$arr_k[$i]] = clear_html($arr_v[$i]);
}
}
FileCache::save($file,$conf);
show_json(LNG('setting_success'));
}else{
show_json(LNG('error'),false);
}
}
}
+631
View File
@@ -0,0 +1,631 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class share extends Controller{
private $sql;
private $shareInfo;
private $sharePath;
private $path;
function __construct(){
parent::__construct();
$auth = systemRole::getInfo(1);//经过role检测
$arrNotCheck = array('commonJs','manifest','manifestJS');
if(substr($this->in['fileUrl'],0,4) == 'http'){
$arrNotCheck[] = 'fileGet';
}
if (!in_array(ACT,$arrNotCheck)){
$this->initShare();
$this->checkShare();
$this->assign('canDownload',$this->shareInfo['notDownload']=='1'?0:1);
}
//需要检查下载权限的Action
$arrCheckDownload = array('fileDownload','zipDownload');//'fileProxy','fileGet'
if (in_array(ACT,$arrCheckDownload)){
if ($this->shareInfo['notDownload']=='1') {
show_json(LNG('share_not_download_tips'),false);
}
}
}
private function initShare(){
if(isset($this->in['user'])){
$this->initShareOld();
return;
}
$this->path = _DIR($this->in['path']);
$this->shareInfo = $GLOBALS['kodShareInfo'];
$user = systemMember::getInfo($GLOBALS['kodPathId']);
$userHome = user_home_path($user);
define('USER',USER_PATH.$user['path'].'/');
define('USER_TEMP',USER.'data/share_temp/');
define('HOME',$userHome);
}
private function checkShare(){
$shareInfo = $this->shareInfo;
if(!$this->shareInfo){
$this->_error(LNG('share_error_user'));
}
if (isset($shareInfo['timeTo'])&&
strlen($shareInfo['timeTo'])!=0) {
$date = strtotime($shareInfo['timeTo']);
if (time() > $date) {
$this->_error(LNG('share_error_time'));
}
}
//密码检测
if ($shareInfo['sharePassword']=='') return;
if (!isset($this->in['password'])){
if ($_SESSION['password_'.$this->in['sid']]==$shareInfo['sharePassword']){
return;
}
$this->_error('password');
}else{
if ($this->in['password'] == $shareInfo['sharePassword']) {
session_start();
$_SESSION['password_'.$this->in['sid']]=$shareInfo['sharePassword'];
session_write_close();
show_json('success');
}else{
show_json(LNG('share_error_password'),false);
}
}
}
private function initShareOld(){
if (!isset($this->in['user']) || !isset($this->in['sid'])) {
$this->_error(LNG('share_error_param'));
}
$member = systemMember::loadData();
$user = $member->get($this->in['user']);
if (!is_array($user) || !isset($user['password'])){
$this->_error(LNG('share_error_user'));
}
$userHome = user_home_path($user);
define('USER',USER_PATH.$user['path'].'/');
define('USER_TEMP',USER.'data/share_temp/');
define('HOME',$userHome);
$shareData = USER_PATH.$user['path'].'/data/share.php';
if (!file_exists(iconv_system($shareData))) {
$this->_error(LNG('share_error_user'));
}
$this->sql=new FileCache($shareData);
$list = $this->sql->get();
if (!isset($this->in['sid']) ||! $list[$this->in['sid']]){
$this->_error(LNG('share_error_sid'));
}
$this->shareInfo = $list[$this->in['sid']];
$sharePath = _DIR_CLEAR($this->shareInfo['path']);
if ($user['role'] != '1') {
$sharePath = HOME.ltrim($sharePath,'/');
}
if ($this->shareInfo['type'] != 'file'){
$sharePath=rtrim($sharePath,'/').'/';
}
$sharePath = iconv_system($sharePath);
if (!file_exists($sharePath)) {
$this->_error(LNG('share_error_path'));
}
$this->sharePath = $sharePath;
if($this->shareInfo['type'] == 'file'){
$this->path = $sharePath;
}else if(isset($this->in['path'])){
$this->path = $sharePath.$this->_clear($this->in['path']);
}else{
$this->path = $sharePath;
}
$this->path = _DIR_CLEAR($this->path);
$GLOBALS['kodPathPre'] = iconv_app(_DIR_CLEAR($sharePath));
//debug_out($GLOBALS['kodPathPre'],$GLOBALS['kodPathId'],$this->shareInfo,$this->path,$sharePath);
}
private function _clear($path){
return iconv_system(_DIR_CLEAR($path));
}
private function _error($msg){
$this->assign('configTheme','mac');
$this->assign('msg',$msg);
$this->display('tips.html');
exit;
}
//==========================
//页面统一注入变量
private function _assignInfo(){
$config = FileCache::load(USER.'data/config.php');
if (count($config)<1) {
$config = $GLOBALS['config']['settingDefault'];
}
$this->assign('configTheme',$config['theme']);
$this->shareInfo['sharePassword'] = '';
$this->shareInfo['path'] = get_path_this(iconv_app($this->path));
$this->assign('shareInfo',$this->shareInfo);
}
//下载次数统计
private function _shareDownloadAdd(){
$this->shareInfo['numDownload'] = abs(intval($this->shareInfo['numDownload'])) +1;
$this->sql->set($this->in['sid'],$this->shareInfo);
}
//==========================
/*
* 文件浏览
*/
public function file() {
$this->shareViewAdd();
if ($this->shareInfo['type']!='file') {
//$this->shareInfo['name'] = get_path_this($this->path);
}
$size = filesize($this->path);
$this->shareInfo['size'] = size_format($size);
$this->_assignInfo();
$this->display('file.html');
}
/*
* 文件夹浏览
*/
public function folder() {
$this->shareViewAdd();
if(isset($this->in['path']) && $this->in['path'] !=''){
$dir = '/'._DIR_CLEAR($this->in['path']);
}else{
$dir = '/';//首次进入系统,不带参数
}
$dir = '/'.trim($dir,'/').'/';
$this->_assignInfo();
$this->assign('dir',$dir);
if ($this->config['forceWap']) {
$this->display('explorerWap.html');
}else{
$this->display('explorer.html');
}
}
/*
* 代码阅读
*/
public function codeRead() {
$this->shareViewAdd();
$this->_assignInfo();
$this->display('editor.html');
}
//浏览次数统计
private function shareViewAdd(){
$this->shareInfo['numDownload'] = isset($this->shareInfo['numDownload'])?$this->shareInfo['numDownload']:0;
$this->shareInfo['numView'] = isset($this->shareInfo['numView'])?$this->shareInfo['numView']:0;
$this->shareInfo['numView'] = abs(intval($this->shareInfo['numView'])) +1;
$this->sql->set($this->in['sid'],$this->shareInfo);
}
public function commonJs(){
$out = ob_get_clean();
$versionDesc = isset($this->config['settings']['versionDesc'])?$this->config['settings']['versionDesc']:"";
$theConfig = array(
'environment' => STATIC_JS,
'lang' => I18n::getType(),
'systemOS' => $this->config['systemOS'],
'isRoot' => 0,
'webRoot' => '',
'webHost' => HOST,
'appHost' => APP_HOST,
'staticPath' => STATIC_PATH,
'appIndex' => $_SERVER['SCRIPT_NAME'],
'version' => KOD_VERSION,
'versionBuild' => KOD_VERSION_BUILD,
'versionDesc' => $versionDesc,
'kodID' => md5(BASIC_PATH.$this->config['settingSystem']['systemPassword']),
'jsonData' => "",
'sharePage' => 'share',
'settings' => array(
'updloadChunkSize' => file_upload_size(),
'updloadThreads' => $this->config['settings']['updloadThreads'],
'updloadBindary' => $this->config['settings']['updloadBindary'],
'uploadCheckChunk' => $this->config['settings']['uploadCheckChunk'],
'paramRewrite' => $this->config['settings']['paramRewrite'],
'pluginServer' => $this->config['settings']['pluginServer'],
//'appType' => $this->config['settings']['appType']
),
//虚拟目录
'KOD_GROUP_PATH' => KOD_GROUP_PATH,
'KOD_GROUP_SHARE' => KOD_GROUP_SHARE,
'KOD_USER_SELF' => KOD_USER_SELF,
'KOD_USER_SHARE' => KOD_USER_SHARE,
'KOD_USER_RECYCLE' => KOD_USER_RECYCLE,
'KOD_USER_FAV' => KOD_USER_FAV,
'KOD_GROUP_ROOT_SELF' => KOD_GROUP_ROOT_SELF,
'KOD_GROUP_ROOT_ALL' => KOD_GROUP_ROOT_ALL,
'ST' => $this->in['st'],
'ACT' => $this->in['act'],
);
if(ST.''.ACT == 'explorer.fileView'){
unset($theConfig['sharePage']);
}
$userConfig = $GLOBALS['config']['settingDefault'];
if(isset($this->in['user'])){
$member = systemMember::loadData();
$user = $member->get($this->in['user']);
$userConfig = FileCache::load(USER_PATH.$user['path'].'/'.'data/config.php');
}
if(isset($this->config['settingSystem']['versionHash'])){
$theConfig['versionHash'] = $this->config['settingSystem']['versionHash'];
$theConfig['versionHashUser'] = $this->config['settingSystem']['versionHashUser'];
}
$theConfig['userConfig'] = $userConfig;
$useTime = mtime() - $GLOBALS['config']['appStartTime'];
header("Content-Type: application/javascript; charset=utf-8");
echo 'if(typeof(kodReady)=="undefined"){kodReady=[];}';
Hook::trigger('user.commonJs.insert',$this->in['st'],$this->in['act']);
echo ';AUTH=[];';
echo 'G='.json_encode($theConfig).';';
$lang = json_encode_force(I18n::getAll());
if(!$lang){
$lang = '{}';
}
echo 'LNG='.$lang.';G.useTime='.$useTime.';';
}
//chrome安装: 必须https;serviceWorker引入处理;manifest配置; [manifest.json配置目录同sw.js引入];
public function manifest(){
$json = file_get_contents(BASIC_PATH.'static/others/app/manifest.json');
$name = stristr(I18n::getType(),'zh') ? '可道云':'kodExplorer';
$static = STATIC_PATH == './static/' ? APP_HOST.'static/':STATIC_PATH;
$assign = array(
"{{name}}" => $name,
"{{appDesc}}" => LNG('common.copyright.name'),
"{{static}}" => $static,
);
$json = str_replace(array_keys($assign),array_values($assign),$json);
header("Content-Type: application/javascript; charset=utf-8");
echo $json;
}
public function manifestJS(){
header("Content-Type: application/javascript; charset=utf-8");
echo file_get_contents(BASIC_PATH.'static/others/app/sw.js');
}
//========ajax function============
public function pathInfo(){
$infoList = json_decode($this->in['dataArr'],true);
foreach ($infoList as &$val) {
$val['path'] = $this->sharePath.$this->_clear($val['path']);
}
$data = path_info_muti($infoList,LNG('time_type_info'));
$data['path'] = _DIR_OUT($data['path']);
//属性查看,单个文件则生成临时下载地址。没有权限则不显示
if (count($infoList)==1 && $infoList[0]['type']!='folder') {//单个文件
$file = $infoList[0]['path'];
if($this->shareInfo['notDownload']!='1'){
$data['downloadPath'] = _make_file_proxy($file);
}
if($data['size'] < 100*1024|| isset($this->in['getMd5'])){
$data['fileMd5'] = @md5_file($file);
}else{
$data['fileMd5'] = "...";
}
//获取图片尺寸
$ext = get_path_ext($file);
if(in_array($ext,array('jpg','gif','png','jpeg','bmp')) ){
$size = ImageThumb::imageSize($file);
if($size){
$data['imageSize'] = $size;
}
}
}
show_json($data);
}
public function fileSave(){
show_json(LNG('no_permission'),false);
}
// 单文件编辑
public function edit(){
$member = systemMember::loadData();
$user = $member->get($this->in['user']);
$codeConfig = FileCache::load(USER_PATH.$user['path'].'/data/editor_config.php');
if(!is_array($codeConfig)){
$codeConfig = $GLOBALS['config']['editorDefault'];
}
$black_theme = array("ambiance","idle_fingers","monokai","pastel_on_dark","twilight",
"solarized_dark","tomorrow_night_blue","tomorrow_night_eighties");
$setClass = "";
if(in_array($codeConfig['theme'],$black_theme)){
$setClass = 'class="code-theme-black"';
}
$this->_assignInfo();
$this->assign('editorConfig',json_encode($codeConfig));//获取编辑器配置信息
$this->assign('codeThemeBlack',$setClass);//获取编辑器配置信息
$this->display('edit.html');
}
public function pathList(){
$list=$this->_path($this->path);
show_json($list);
}
public function treeList(){
$path=$this->path;
if (isset($this->in['project'])) {
$path = $this->sharePath.$this->_clear($this->in['project']);
}
if (isset($this->in['path'])) {
$path = $this->sharePath.$this->_clear($this->in['path']);
}
if (isset($this->in['name'])){
$path=$path.'/'.$this->_clear($this->in['name']);
}
$listFile = ($this->in['app'] == 'editor'?true:false);//编辑器内列出文件
$list=$this->_path($path,$listFile,true);
function sort_by_key($a, $b){
if ($a['name'] == $b['name']) return 0;
return ($a['name'] > $b['name']) ? 1 : -1;
}
usort($list['folderList'], "sort_by_key");
usort($list['fileList'], "sort_by_key");
$result = array_merge($list['folderList'],$list['fileList']);
if ($this->in['app'] != 'editor') {
$result =$list['folderList'];
}
if (isset($this->in['type']) && $this->in['type']=='init') {
$result = array(
array(
'name' => iconv_app(get_path_this($path)),
'children' => $result,
//'menuType' => "menuTreeRoot",
'open' => true,
'type' => 'folder',
'path' => '/',
'isParent' => count($result)>0?true:false
)
);
}
show_json($result);
}
public function search(){
if (!isset($this->in['search'])) show_json(LNG('please_inpute_search_words'),false);
$isContent = intval($this->in['is_content']);
$isCase = intval($this->in['is_case']);
$ext= trim($this->in['ext']);
$list = path_search(
$this->path,
rawurldecode($this->in['search']),
$isContent,$ext,$isCase);
show_json(_DIR_OUT($list));
}
/**
* 上传,html5拖拽 flash 多文件
*/
public function fileUpload(){
$fileName = $_FILES['file']['name']? $_FILES['file']['name']:$GLOBALS['in']['name'];
$GLOBALS['isRoot']=0;
$GLOBALS['auth']['extNotAllow'] = "htm|html|php|phtml|pwml|asp|aspx|ascx|jsp|pl|htaccess|shtml|shtm|phtm";
if(!checkExt($fileName)){
show_json(LNG('no_permission_ext'),false);
}
$savePath = $this->sharePath.$this->_clear($this->in['upload_to']);
if (!path_writeable($savePath)) show_json(LNG('no_permission_write'),false);
if ($savePath == '') show_json(LNG('upload_error_big'),false);
if (strlen($this->in['fullPath']) > 1) {//folder drag upload
$fullPath = _DIR_CLEAR(rawurldecode($this->in['fullPath']));
$fullPath = get_path_father($fullPath);
$fullPath = iconv_system($fullPath);
if (mk_dir($savePath.$fullPath)) {
$savePath = $savePath.$fullPath;
}
}
//分片上传
$tempDir = iconv_system(USER_TEMP);
mk_dir($tempDir);
if (!path_writeable($tempDir)) show_json(LNG('no_permission_write'),false);
upload($savePath,$tempDir,'rename');
}
//代理输出
public function fileProxy(){
$mime = get_file_mime(get_path_ext($this->path));
if($mime == 'text/plain' && is_file($this->path)){//文本则转编码
$fileContents = file_get_contents($this->path);
$charset=get_charset($fileContents);
if ($charset!='' || $charset!='utf-8') {
$fileContents=mb_convert_encoding($fileContents,'utf-8',$charset);
}
echo $fileContents;
return;
}
$download = isset($_GET['download']);
$filename = isset($_GET['downFilename'])?$_GET['downFilename']:false;
file_put_out($this->path,$download,$filename);
}
public function fileDownload(){
$this->_shareDownloadAdd();
file_put_out($this->path,true);
}
//文件下载后删除,用于文件夹下载
public function fileDownloadRemove(){
if ($this->shareInfo['notDownload']=='1') {
show_json(LNG('share_not_download_tips'),false);
}
$path = get_path_this(_DIR_CLEAR($this->in['path']));
$path = iconv_system(USER_TEMP.$path);
file_put_out($path,true);
del_file($path);
}
public function zipDownload(){
$this->_shareDownloadAdd();
$userTemp = iconv_system(USER_TEMP);
if(!file_exists($userTemp)){
mkdir($userTemp);
}else{//清除未删除的临时文件,一天前
$list = path_list($userTemp,true,false);
$maxTime = 3600*24;
if ($list['fileList']>=1) {
for ($i=0; $i < count($list['fileList']); $i++) {
$createTime = $list['fileList'][$i]['mtime'];//最后修改时间
if(time() - $createTime >$maxTime){
del_file($list['fileList'][$i]['path'].$list['fileList'][$i]['name']);
}
}
}
}
$zipFile = $this->zip($userTemp);
show_json(LNG('zip_success'),true,get_path_this($zipFile));
}
private function zip($zipPath){
if (!isset($zipPath)) {
show_json(LNG('share_not_download_tips'),false);
}
ignore_timeout();
$zipList = json_decode($this->in['dataArr'],true);
$listNum = count($zipList);
$files = array();
for ($i=0; $i < $listNum; $i++) {
$item = $this->path.$this->_clear($zipList[$i]['path']);
if(file_exists($item)){
$files[] = $item;
}
}
if(count($files)==0){
show_json(LNG('not_exists'),false);
}
//指定目录
if (count($files) == 1) {
$pathThisName=get_path_this($files[0]);
}else{
$pathThisName=get_path_this(get_path_father($files[0]));
}
$zipname = $zipPath.$pathThisName.'.zip';
$zipname = get_filename_auto($zipname,date('_H-i-s'));
KodArchive::create($zipname,$files);
return iconv_app($zipname);
}
// 获取文件数据
public function fileGet(){
if(isset($this->in['fileUrl'])){ //http
$displayName = $this->in['name'];
$filepath = $this->in['fileUrl'];
if(!request_url_safe($filepath)){
show_json(LNG('url error!'),false);
}
}else{
$displayName = _DIR_CLEAR($this->in['filename']);
$filepath= $this->sharePath.iconv_system($displayName);
if (!path_readable($filepath)){
show_json(LNG('no_permission_read'),false);
}
if (filesize($filepath) >= 1024*1024*20){
show_json(LNG('edit_too_big'),false);
}
if (!file_exists($filepath)){
show_json(LNG('not_exists'),false);
}
}
$fileContents=file_get_contents($filepath);//文件内容
$charset=get_charset($fileContents);
if ($charset!='' &&
$charset!='utf-8' &&
function_exists("mb_convert_encoding")
){
$fileContents=@mb_convert_encoding($fileContents,'utf-8',$charset);
}
$data = array(
'ext' => get_path_ext($displayName),
'name' => iconv_app(get_path_this($displayName)),
'filename' => $displayName,
'charset' => $charset,
'base64' => true,// 部分防火墙编辑文件误判问题处理
'content' => base64_encode($fileContents)
);
show_json($data);
}
public function image(){
$thumbWidth = 250;
if(isset($this->in['thumbWidth'])){
$thumbWidth = intval($this->in['thumbWidth']);//自定义预览大图
}
if(substr($this->path,0,4) == 'http'){
header('Location: '.$this->in['path']);
exit;
}
if (@filesize($this->path) <= 1024*50 ||
!function_exists('imagecolorallocate') ||
get_path_ext($this->path) == 'gif') {//小于50k、不支持gd库、gif图 不再生成缩略图
file_put_out($this->path,false);
return;
}
if (!is_dir(DATA_THUMB)){
mk_dir(DATA_THUMB);
}
$image = $this->path;
$imageMd5 = @md5_file($image).'_'.$thumbWidth;//文件md5
if (strlen($imageMd5)<5) {
$imageMd5 = md5($image).'_'.$thumbWidth;
}
$imageThumb = DATA_THUMB.$imageMd5.'.png';
if (!file_exists($imageThumb)){//如果拼装成的url不存在则没有生成过
if (get_path_father($image)==DATA_THUMB){//当前目录则不生成缩略图
$imageThumb=$this->path;
}else {
$cm = new ImageThumb($image,'file');
$cm->prorate($imageThumb,$thumbWidth,$thumbWidth);//生成等比例缩略图
}
}
if (!file_exists($imageThumb) ||
filesize($imageThumb)<100){//缩略图生成失败则使用原图
$imageThumb=$this->path;
}
file_put_out($imageThumb,false);
file_put_out($imageThumb);//输出
}
//获取文件列表&哦exe文件json解析
private function _path($dir,$listFile=true,$check_children=false){
$list = path_list($dir,$listFile,true);
$listNew = array('fileList'=>array(),'folderList'=>array());
$pathHidden = $this->config['settingSystem']['pathHidden'];
$exName = explode(',',$pathHidden);
foreach ($list['fileList'] as $key => $val) {
if (in_array($val['name'],$exName)) continue;
if ($val['ext'] == 'oexe'){
$path = iconv_system($val['path']);
$json = json_decode(@file_get_contents($path),true);
if(is_array($json)) $val = array_merge($val,$json);
}
$listNew['fileList'][] = $val;
}
foreach ($list['folderList'] as $key => $val) {
if (in_array($val['name'],$exName)) continue;
$listNew['folderList'][] = $val;
}
$s = _DIR_OUT($listNew);
return _DIR_OUT($listNew);
}
}
@@ -0,0 +1,279 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
//群组管理【管理员调用,or组空间大小变更】
//根目录id为1==》共享空间
class systemGroup extends Controller{
public static $staticSql = null;
private $sql;
function __construct() {
parent::__construct();
$this->sql= self::loadData();
$this->_init();
}
//保证只加载一次文件
public static function loadData(){
if(is_null(self::$staticSql)){
self::$staticSql = systemGroupData();
}
return self::$staticSql;
}
public static function getInfo($theId){
$sql = self::loadData();
return $sql->get($theId);
}
/**
* 空间使用变更
* @param [type] $theId [userID or groupID]
* @param [type] $sizeAdd [变更的大小 sizeMax G为单位 sizeUse Byte为单位]
*/
public static function spaceChange($theId,$sizeAdd=false){
$sql = self::loadData();
$info = $sql->get($theId);
if(!is_array($info)){
show_json(LNG('data_not_full'),false);
}
if($sizeAdd===false){//重置用户空间;避免覆盖、解压等导致的问题
$pathinfo = _path_info_more(GROUP_PATH.$info['path'].'/');
$currentUse = $pathinfo['size'];
if(isset($info['homePath']) && file_exists(iconv_system($info['homePath']))){
$pathinfo = _path_info_more(iconv_system($info['homePath']));
$currentUse += $pathinfo['size'];
}
}else{
$currentUse = floatval($info['config']['sizeUse'])+floatval($sizeAdd);
}
$info['config']['sizeUse'] = $currentUse<0?0:$currentUse;
$sql->set($theId,$info);
}
/**
* 空间剩余检测
* 1073741824 —— 1G
*/
public static function spaceCheck($theId){
$sql = self::loadData();
$info = $sql->get($theId);
if(!is_array($info)){
show_json(LNG('data_not_full'),false);
}
$sizeUse = floatval($info['config']['sizeUse']);
$sizeMax = floatval($info['config']['sizeMax']);
if($sizeMax!=0 && $sizeMax*1073741824<$sizeUse){
show_json(LNG('space_is_full'),false);
}
}
//管理员调用
//===================
private function _init(){
if(count($this->sql->get()) > 0) return;
$default = array(
'1' =>array(
'groupID' => '1',
'name' => 'root',
'parentID' => '',
'children' => '',
'config' => array('sizeMax' => floatval(1.5),
'sizeUse' => floatval(1024*1024)),//总大小,目前使用大小
'path' => 'root',
'createTime'=> time(),
)
);
$this->sql->reset($default);
$this->initDir($default[0]['path']);
}
//删除 path id
public static function _filterList($list,$filter_key = 'path'){
if($GLOBALS['isRoot']) return $list;
foreach ($list as $key => &$val) {
unset($val[$filter_key]);
}
return $list;
}
public function get() {
$items = self::_filterList($this->sql->get());
show_json($items,true);
}
/**
* 群组添加
* systemGroup/add&name=t1&parentID=101&sizeMax=0
*/
public function add(){
if (!isset($this->in['name']) || //必填项
!isset($this->in['parentID']) ||
!isset($this->in['sizeMax'])
) show_json(LNG('data_not_full'),false);
//名称可以重复
$groupID = $this->sql->getMaxId().'';
$groupName = rawurldecode($this->in['name']);
$groupInfo = array(
'groupID' => $groupID,
'name' => $groupName,
'parentID' => $this->in['parentID'],
'children' => '',
'config' => array('sizeMax' => floatval($this->in['sizeMax']),//G
'sizeUse' => floatval(1024*1024)),//总大小,目前使用大小
'path' => make_path($groupName),
'createTime'=> time(),
);
if(file_exists(iconv_system(GROUP_PATH.$groupInfo['path'])) ){
$groupInfo['path'] = make_path($groupInfo['path'].'_'.$groupInfo['groupID']);
}
//用户组目录
if( isset($this->in['homePath'])){
$homePath = _DIR(rawurldecode($this->in['homePath']));
if(file_exists($homePath)){
$groupInfo['homePath'] = iconv_app($homePath);
}
}else{
unset($groupInfo['homePath']);
}
$this->_parentChildChange($groupInfo,true);//更新父节点
if ($this->sql->set($groupID,$groupInfo)) {
$this->initDir($groupInfo['path']);
show_json(LNG('success'));
}
show_json(LNG('error'),false);
}
/**
* 编辑 systemGroup/edit&groupID=101&name=warlee&sizeMax=0
*/
public function edit() {
if (!$this->in['groupID']) show_json(LNG('data_not_full'),false);
$groupInfo = $this->sql->get($this->in['groupID']);
if(!is_array($groupInfo)){//用户不存在
show_json(LNG('not_exists'),false);
}
//name sizeMax parentID
if(isset($this->in['name'])){
$groupInfo['name'] = rawurldecode($this->in['name']);
}
if(isset($this->in['sizeMax'])){
$groupInfo['config']['sizeMax'] = floatval($this->in['sizeMax']);
}
if( isset($this->in['parentID']) &&
$groupInfo['parentID']!= '' && //根目录不能修改父节点
$this->in['parentID']!=$groupInfo['parentID']){//父节点变更
$childChange = explode(',',$groupInfo['children']);
if( in_array($this->in['parentID'],$childChange)
|| $this->in['parentID'] == $this->in['groupID']){//不能移动到子节点;死循环
show_json(LNG('current_has_parent'),false);
}
self::spaceChange($this->in['groupID']);//重置用户使用空间
$this->_parentChildChange($groupInfo,false);//向所有父节点,删除包含此节点的children
$groupInfo['parentID'] = $this->in['parentID'];
$this->_parentChildChange($groupInfo,true);//向所有新的父节点,添加包含此节点的children
}
//用户组目录
if( isset($this->in['homePath'])){
$groupInfo['homePath'] = _DIR(rawurldecode($this->in['homePath']));
if(!file_exists($groupInfo['homePath'])){
show_json(LNG('not_exists'),false);
}
$groupInfo['homePath'] = iconv_app($groupInfo['homePath']);
}else{
unset($groupInfo['homePath']);
}
if($groupInfo != $this->sql->get($this->in['groupID'])){
$this->sql->set($this->in['groupID'],$groupInfo);
}
show_json(LNG('success'));
}
/**
* 删除 ?systemMember/del&userID=102
*/
public function del() {
if (!isset($this->in['groupID'])) show_json(LNG('data_not_full'),false);
if (strlen($this->in['groupID']) <= 1) show_json(LNG('default_user_can_not_do'),false);
$groupInfo = $this->sql->get($this->in['groupID']);
$this->_parentChildChange($groupInfo,false);//向所有父节点,删除包含此节点的children
$this->sql->set(//将该节点的子节点的父节点设置为根目录
array('parentID',$groupInfo["groupID"]),
array('parentID','1')
);
systemMember::groupRemoveUserUpdate($groupInfo["groupID"]);//用户所在组变更
$this->sql->remove($this->in['groupID']);
if( strlen($groupInfo['path'])!=0){
del_dir(iconv_system(GROUP_PATH.$groupInfo['path'].'/'));
show_json(LNG('success'));
}
show_json(LNG('error'),false);
}
//============内部处理函数=============
//回溯更改节点的children
private function _parentChildChange($groupInfo,$isAdd){
if(!is_array($groupInfo)){
show_json(LNG('not_exists'),false);
}
if($groupInfo['parentID'] == 1){
return;
}
$childChange = explode(',',$groupInfo['children']);
if($childChange[0]==''){
unset($childChange[0]);
}
$childChange[] = $groupInfo['groupID'];//包含当前
while(strlen($groupInfo['groupID'])>2){//节点id从100开始
$groupInfo = $this->sql->get($groupInfo['parentID']);
if(!is_array($groupInfo)){
show_json(LNG('not_exists'),false);
}
$childrenNew = explode(',',$groupInfo['children']);
if($childrenNew[0]==''){
unset($childrenNew[0]);
}
if($isAdd){//添加
foreach ($childChange as $key=>$val) {
$childrenNew[] = $val;
}
}else{//删除
foreach ($childrenNew as $key=>$val) {
if(in_array($val,$childChange))
unset($childrenNew[$key]);
}
}
$childStr = implode(',',$childrenNew);
if($childStr != $groupInfo['children']){//有变更
$groupInfo['children'] = $childStr;
$this->sql->set($groupInfo['groupID'],$groupInfo);
}
}
}
//
/**
*初始化用户数据和配置。
*/
public function initDir($path){
$root = array('home','data');
$newGroupFolder = $this->config['settingSystem']['newGroupFolder'];
$home = explode(',',$newGroupFolder);
$path = GROUP_PATH.$path.'/';
foreach ($root as $dir) {
mk_dir(iconv_system($path.$dir));
}
foreach ($home as $dir) {
mk_dir(iconv_system($path.'home/'.$dir));
}
}
}
@@ -0,0 +1,529 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
//用户管理【管理员配置用户,or用户空间大小变更】
class systemMember extends Controller{
public static $staticSql = null;
private $sql;
function __construct() {
parent::__construct();
$this->tpl = TEMPLATE.'member/';
$this->sql= self::loadData();
}
//保证只加载一次文件
public static function loadData(){
if(is_null(self::$staticSql)){
self::$staticSql = systemMemberData();
}
return self::$staticSql;
}
public static function getInfo($theId){
$sql = self::loadData();
return $sql->get($theId);
}
/**
* 空间使用变更
* @param [type] $theId [userID or groupID]
* @param [type] $sizeAdd [变更的大小 sizeMax G为单位 sizeUse Byte为单位]
*/
public static function spaceChange($theId,$sizeAdd=false){
$sql = self::loadData();
$info = $sql->get($theId);
if(!is_array($info)){
show_json(LNG('data_not_full'),false);
}
if($sizeAdd===false){//重置用户空间;避免覆盖、解压等导致的问题
$pathinfo = _path_info_more(iconv_system(USER_PATH.$info['path'].'/'));
$currentUse = $pathinfo['size'];
if(isset($info['homePath']) && file_exists(iconv_system($info['homePath']))){
$pathinfo = _path_info_more(iconv_system($info['homePath']));
$currentUse += $pathinfo['size'];
}
}else{
$currentUse = floatval($info['config']['sizeUse'])+floatval($sizeAdd);
}
$info['config']['sizeUse'] = $currentUse<0?0:$currentUse;
$sql->set($theId,$info);
}
/**
* 空间剩余检测
* 1073741824 —— 1G
*/
public static function spaceCheck($theId){
$sql = self::loadData();
$info = $sql->get($theId);
if(!is_array($info)){
show_json(LNG('data_not_full'),false);
}
$sizeUse = floatval($info['config']['sizeUse']);
$sizeMax = floatval($info['config']['sizeMax']);
if($sizeMax!=0 && $sizeMax*1073741824<$sizeUse){
show_json(LNG('space_is_full'),false);
}
}
// 组删除后,所属该组的用户都删除;全局调用
public static function groupRemoveUserUpdate($groupID){
$sql = self::loadData();
$userAll = $sql->get();
foreach ($userAll as $key => $val) {
if(in_array($groupID,array_keys($val['groupInfo']))){
unset($val['groupInfo'][$groupID]);
$sql->set($val['userID'],$val);
}
}
}
// 权限组删除,所属该组的用户删除权限id
public static function roleRemoveUserUpdate($roleId){
$sql = self::loadData();
$userAll = $sql->get();
foreach ($userAll as $key => $val) {
if($val['role'] == $roleId){
$val['role'] = '';
$sql->set($val['userID'],$val);
}
}
}
//获取当前用户在某个群组的权限id; false|[id]
//兼容旧版本 'read'|'write'|false
public static function userAuthGroup($groupID){
$result = self::_userAuthGroupRole($groupID);
if($result === false) return false;
$result = $result == 'read' ? "1" : $result;
$result = $result == 'write' ? "2" : $result;
if(!is_array($GLOBALS['config']['pathRoleGroup'][$result])){
$result = "1";
}
return $result;
}
//获取在某个组的用户
public static function userAtGroup($groupID){
$sql = self::loadData();
$allUser = self::_filterList($sql->get());
if($groupID=='0'){
return $allUser;
}
$selectUser = array();
foreach ($allUser as $val) {
if(isset($val['groupInfo'][$groupID])){
$selectUser[] = $val;
}
}
return $selectUser;
}
//缓存用户共享对象=======================================
public static function userShareSql($userID){
static $userShareArr;
if(!is_array($userShareArr)){
$userShareArr = array();
}
if(!isset($userShareArr[$userID])){
$userInfo = systemMember::getInfo($userID);
if(!isset($userInfo['path'])){
return;
}
$sql = new FileCache(USER_PATH.$userInfo['path'].'/data/share.php');
$userShareArr[$userID] = $sql;
}
return $userShareArr[$userID];
}
//获取某个用户共享列表
public static function userShareList($userID){
$sql = self::userShareSql($userID);
$list = $sql->get();
if($userID == $_SESSION['kodUser']['userID']){//自己的列表则展示密码;否则清空密码
return $list;
}
//含有密码则不罗列
foreach($list as $key=>&$val){
if($val['sharePassword']){
unset($list[$key]);
}
}
return $list;
}
//获取某个用户某个共享
public static function userShareGet($userID,$name){
$sql = self::userShareSql($userID);
return $sql->get('name',$name);
}
//判断自己对某个组的权限 return false/'read'/'write'
public static function _userAuthGroupRole($groupID){
$sql = self::loadData();
$userInfo = $sql->get($_SESSION['kodUser']['userID']);
$groupInfo = $userInfo['groupInfo'];//自己所在的组
if(!is_array($groupInfo)){
return false;
}
if(isset($groupInfo[$groupID])){
return $groupInfo[$groupID];
}
$role = false;
$plist = array();
foreach ($groupInfo as $key => $value) {//
$group = systemGroup::getInfo($key);//测试组,是否在用户所在组的子组
$arr = explode(',',$group['children']);
if (in_array($groupID,$arr)) {
//return $groupInfo[$key]; // 找到最近的父级部门,而非第一个
if(empty($plist)){
$plist = $arr;
$role = $groupInfo[$key];
}else if(in_array($group['groupID'], $plist)){
$plist = $arr;
$role = $groupInfo[$key];
}
}
}
return $role;
}
//删除 path id
public static function _filterList($list,$filter_key = 'path'){
if($GLOBALS['isRoot']) return $list;
foreach ($list as $key => &$val) {
unset($val[$filter_key]);
unset($val['password']);
}
return $list;
}
//后台管理=====================
//管理员调用===================
/**
* 获取用户列表数据,根据用户组筛选;默认输出所有用户
*/
public function get($groupID='0') {
$result = self::userAtGroup($groupID);
foreach($result as $key=>&$val){
unset($val['password']);
}
show_json($result);
}
/**
* 获取用户列表数据,根据用户组筛选;默认输出所有用户
*/
public function getByName($name = '') {
if(!$name){
$name = $this->in['name'];
}
$result = $this->sql->get(array('name',$name));
if(is_array($result) && count($result)>0){
$arr = array_values($result);
unset($arr[0]['password']);
show_json($arr[0]);
}
show_json(LNG("not_exists"),false);
}
/**
* 用户添加
* systemMember/add&name=warlee&password=123&sizeMax=0&groupInfo={"0":"read","10":"write"}&role=default
*/
public function add($user = false){
if (!isset($this->in['name']) || //必填项
!isset($this->in['password']) ||
!isset($this->in['role']) ||
!isset($this->in['groupInfo']) || //{"0":"read","100":"read"}
!isset($this->in['sizeMax'])
){
show_json(LNG('data_not_full'),false);
}
$name = trim(rawurldecode($this->in['name']));
$password = rawurldecode($this->in['password']);
$groupInfo = json_decode(rawurldecode($this->in['groupInfo']),true);
if(!is_array($groupInfo)){
show_json(LNG('systemMember_group_error'),false);
}
if($this->sql->get(array('name',$name))){
show_json(LNG('error_repeat'),false,$name);
}
//非系统管理员,不能添加系统管理员
if(!$GLOBALS['isRoot'] && $this->in['role']=='1'){
show_json(LNG('group_role_error'),false);
}
$userArray = array();
if(isset($this->in['isImport'])){
$arr = explode("\n",$name);
foreach($arr as $v){
if(trim($v)!=''){
$userArray[] = trim($v);
}
}
}else{
$userArray[] = $name;
}
$nickName = 0;
if(isset($this->in['nickName'])){
$nickName = trim(rawurldecode($this->in['nickName']));
}
//批量添加
$errorArr = array();
foreach ($userArray as $val) {
if($this->sql->get('name',$val)){//已存在
$errorArr[] = $val;
continue;
}
$userID = $this->sql->getMaxId().'';
$userInfo = array(
'userID' => $userID,
'name' => $val,
'nickName' => $nickName ? $nickName : $val,
'password' => md5($password),
'role' => $this->in['role'],
'config' => array('sizeMax' => floatval($this->in['sizeMax']),//M
'sizeUse' => 1024*1024),//总大小,目前使用大小
'groupInfo' => $groupInfo,
'path' => make_path($val),
'status' => 1, //0禁用;1启用
'lastLogin' => '', //最后登录时间 首次登陆则激活
'createTime'=> time(),
);
if(file_exists(iconv_system(USER_PATH.$userInfo['path'])) ){
$userInfo['path'] = $userInfo['path'].'_'.$userInfo['userID'];
}
//用户组目录
if( isset($this->in['homePath'])){
$homePath = _DIR(rawurldecode($this->in['homePath']));
if(file_exists($homePath)){
$userInfo['homePath'] = iconv_app($homePath);
}
}else{
unset($userInfo['homePath']);
}
if ($this->sql->set($userID,$userInfo)) {
$this->initDir($userInfo['path']);
}else{
$errorArr[] = $val;
}
}
$success = count($userArray)-count($errorArr);
$msg = LNG('success');
if(count($errorArr) > 0 ){
$msg = LNG('word_success').' : '.$success.', ';//部分失败
if($success == 0 ){
$msg = LNG('error_repeat');
}
$msg .= LNG('word_error').' : '.count($errorArr);
}
if($success==count($userArray)){
show_json($msg,true,$success);
}else{
show_json($msg,false,implode("\n",$errorArr));
}
}
/**
* 编辑 systemMember/edit&userID=101&name=warlee&password=123&sizeMax=0
* &groupInfo={%220%22:%22read%22,%22100%22:%22read%22}&role=default
*/
public function edit() {
if (!$this->in['userID']) show_json(LNG('data_not_full'),false);
$userID = $this->in['userID'];
$userInfo = $this->sql->get($userID);
if(!$userInfo){//用户不存在,或者默认用户不能修改
show_json(LNG('error'),false);
}
//非系统管理员,不能将别人设置为系统管理员
if(!$GLOBALS['isRoot'] && $this->in['role']=='1'){
show_json(LNG('group_role_error'),false);
}
//非系统管理员,不能修改系统管理员
if(!$GLOBALS['isRoot'] && $userInfo['role']=='1'){
show_json(LNG('group_role_error_admin'),false);
}
//管理员自己不能添加自己到非管理员组
if($GLOBALS['isRoot']
&& $_SESSION['kodUser']['userID']==$userID
&& $this->in['role']!='1'){
show_json(LNG('error'),false);
}
//修改为一个已存在的名字则提示
$theName = trim(rawurldecode($this->in['name']));
if($userInfo['name']!=$theName){
if($this->sql->get(array('name',$theName))){
show_json(LNG('error_repeat'),false);
}
}
$this->in['name'] = rawurlencode($theName);//还原
$editArr = array('name','nickName','role','password','groupInfo','homePath','status','sizeMax');
foreach ($editArr as $key) {
if(!isset($this->in[$key])) continue;
$userInfo[$key] = rawurldecode($this->in[$key]);
if($key == 'password'){
$userInfo['password'] = md5($userInfo[$key]);
}else if($key == 'sizeMax'){
$userInfo['config']['sizeMax'] = floatval($userInfo[$key]);
}else if($key == 'groupInfo'){//分组信息
$userInfo['groupInfo'] = json_decode(rawurldecode($this->in['groupInfo']),true);
}
}
//用户组目录
if( isset($this->in['homePath'])){
$userInfo['homePath'] = _DIR(rawurldecode($this->in['homePath']));
if(!file_exists($userInfo['homePath'])){
show_json(LNG('not_exists'),false);
}
$userInfo['homePath'] = iconv_app($userInfo['homePath']);
}else{
unset($userInfo['homePath']);
}
if($this->sql->set($userID,$userInfo)){
//self::spaceChange($userID);//重置用户使用空间
show_json(LNG('success'),true,$userInfo);
}
show_json(LNG('error_repeat'),false);
}
/**
* 用户批量操作 systemMember/doAction&action=&userID=[101,222,131]&param=
* action :
* -------------
* del 删除用户
* statusSet 启用&禁用 param=0/1
* roleSet 权限组 param=roleID
* groupReset 重置分组 param=group_json
* groupRemoveFrom 从某个组删除 param=groupID
* groupAdd 添加到某个分组 param=group_json
*/
public function doAction() {
if (!isset($this->in['userID'])){
show_json(LNG('username_can_not_null'),false);
}
$action = $this->in['action'];
$userArr = json_decode($this->in['userID'],true);
if(!is_array($userArr)){
show_json(LNG('error'),false);
}
if (in_array('1', $userArr)){//批量处理,不处理系统管理员admin
show_json(LNG('default_user_can_not_do'),false);
}
foreach ($userArr as $userID) {
switch ($action) {
case 'del'://删除
$userInfo = $this->sql->get($userID);
if($this->sql->remove($userID) && $userInfo['name']!=''){
del_dir(iconv_system(USER_PATH.$userInfo['path'].'/'));
}
break;
case 'statusSet'://禁用&启用
$status = intval($this->in['param']);
$this->sql->set(array('userID',$userID),array('status',$status));
break;
case 'spaceSet'://批量设置用户空间大小
$value = intval($this->in['param']);
$userInfo = $this->sql->get($userID);
$userInfo['config']['sizeMax'] = $value;
$this->sql->set($userID,$userInfo);
break;
case 'roleSet'://设置权限组
$role = $this->in['param'];
//非系统管理员,不能将别人设置为系统管理员
if(!$GLOBALS['isRoot'] && $role=='1'){
show_json(LNG('group_role_error'),false);
}
$this->sql->set(array('userID',$userID),array('role',$role));
break;
case 'groupReset'://设置分组
$groupArr = json_decode($this->in['param'],true);
if(!is_array($groupArr)){
show_json(LNG('error'),false);
}
$this->sql->set(array('userID',$userID),array('groupInfo',$groupArr));
break;
case 'groupRemoveFrom'://从某个组移除
$groupID = $this->in['param'];
$userInfo = $this->sql->get($userID);
unset($userInfo['groupInfo'][$groupID]);
$this->sql->set($userID,$userInfo);
break;
case 'groupAdd'://添加到某个组
$groupArr = json_decode($this->in['param'],true);
if(!is_array($groupArr)){
show_json(LNG('error'),false);
}
$userInfo = $this->sql->get($userID);
foreach ($groupArr as $key => $value) {
$userInfo['groupInfo'][$key] = $value;
}
$this->sql->set($userID,$userInfo);
default:break;
}
}
show_json(LNG('success'));
}
public function initInstall(){
$sql = systemMember::loadData();
$list = $sql->get();
foreach ($list as $id => &$info) {//创建用户目录及初始化
$path = make_path($info['name']);
$this->initDir($path);
$info['path'] = $path;
$info['createTime'] = time();
}
$sql->reset($list);
//初始化群组目录
$homeFolders = explode(',',$this->config['settingSystem']['newGroupFolder']);
$sql = systemGroup::loadData();
$list = $sql->get();
foreach ($list as $id => &$info) {//创建用户目录及初始化
$path = make_path($info['name']);
$rootPath = GROUP_PATH.$path.'/';
foreach ($homeFolders as $dir) {
mk_dir(iconv_system($rootPath.'home/'.$dir));
}
$info['path'] = $path;
$info['createTime'] = time();
}
$sql->reset($list);
}
//============内部处理函数=============
/**
*初始化用户数据和配置。
*/
public function initDir($path){
$userFolder = array('home','recycle_kod','data');
$homeFolders = explode(',',$this->config['settingSystem']['newUserFolder']);
$rootPath = USER_PATH.$path.'/';
foreach ($userFolder as $dir) {
mk_dir(iconv_system($rootPath.$dir));
}
foreach ($homeFolders as $dir) {
mk_dir(iconv_system($rootPath.'home/'.$dir));
}
FileCache::save($rootPath.'data/config.php',$this->config['settingDefault']);
}
}
@@ -0,0 +1,170 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class systemRole extends Controller{
public static $staticSql = null;
private $sql;
function __construct(){
parent::__construct();
$this->sql= self::loadData();
}
//保证只加载一次文件
public static function loadData(){
if(is_null(self::$staticSql)){
self::$staticSql = systemRoleData();
}
return self::$staticSql;
}
public static function getInfo($theId){
$sql = self::loadData();
return $sql->get($theId);
}
//获取所有权限组
//用户组权限
public function get() {
if(isset($this->in['group_role'])){
$this->in['action'] == 'get';
$this->roleGroupAction();
}
show_json($this->sql->get());
}
/**
* 权限添加
*/
public function add(){
$role = $this->_initData();
$roleId = $role['roleID'] = $this->sql->getMaxId().'';
$this->_checkExist( $this->sql->get(),array('name',$role['name']),$roleId );
if ($this->sql->set($role['roleID'],$role)) {
show_json(LNG('success'),true,$role['roleID']);
}
show_json(LNG('error'),false);
}
/**
* 编辑
*/
public function edit(){
$role = $this->_initData();
$roleId = $this->in['roleID'];
$this->_checkExist( $this->sql->get(),array('name',$role['name']),$roleId );
if ($this->sql->set($roleId,$role)){
show_json(LNG('success'),true,$roleId);
}
show_json(LNG('error'),false);
}
/**
* 删除
*/
public function del() {
if (!isset($this->in['roleID'])) show_json(LNG('data_not_full'),false);
if (strlen($this->in['roleID']) <= 1) show_json(LNG('default_user_can_not_do'),false);
systemMember::roleRemoveUserUpdate($this->in['roleID']);//用户所在权限组变更
if($this->sql->remove($this->in['roleID'])){
show_json(LNG('success'));
}
show_json(LNG('error'),false);
}
/**
* 用户组权限列表配置
* 增删改查
*/
public function roleGroupAction(){
$sql = new FileCache(USER_SYSTEM.'system_role_group.php');
switch ($this->in['action']) {
case 'get':
$roleGroup = $sql->get();
if($roleGroup['1']['name'] == 'read'){
$roleGroup['1']['name'] = LNG('system_role_read');
}
if($roleGroup['2']['name'] == 'write'){
$roleGroup['2']['name'] = LNG('system_role_write');
}
show_json($roleGroup,true,$this->config['pathRoleDefine']);
break;
case 'add':
$roleId = $sql->getMaxId().'';
$roleArr = json_decode($this->in['role_arr'],true);
if(!is_array($roleArr)) show_json(LNG('error'),false);
if(!trim($roleArr['name'])) show_json(LNG("data_not_full"),false);
$this->_checkExist( $sql->get(),array('name',$roleArr['name']),$roleId);
if ($sql->set($roleId,$roleArr)) {
show_json(array($roleId),true,$sql->get());
}
show_json(LNG('error'),false);
break;
case 'set':
$roleId = $this->in['roleID'];
$roleArr = json_decode($this->in['role_arr'],true);
if(!is_array($roleArr)) show_json(LNG('error'),false);
if(!trim($roleArr['name'])) show_json(LNG("data_not_full"),false);
$this->_checkExist( $sql->get(),array('name',$roleArr['name']),$roleId);
if ($sql->set($roleId,$roleArr)){
show_json(LNG('success'),true,$sql->get());
}
show_json(LNG('error'),false);
break;
case 'del':
$roleId = $this->in['roleID'];
if(in_array($roleId,array("1","2"))){
show_json(LNG('default_user_can_not_do'),false);
}
if($sql->remove($this->in['roleID'])){
show_json(LNG('success'),true,$sql->get());
}
show_json(LNG('error'),false);
break;
default:break;
}
}
//检测是否存在
private function _checkExist($data,$find,$checkID){
$findData = array();
foreach ($data as $key => $val) {
if ($val[$find[0]] == $find[1]) {
$findData[$key] = $data[$key];
}
}
if(is_array($findData) && count($findData)>0 ){
$key = array_keys($findData);$key=$key[0];
if($key != $checkID) show_json(LNG("error_repeat"),false);
}
}
//===========内部调用============
/**
* 初始化数据 get
* 只传键即可 &extNotAllow='php,jsp'&explorer.mkfile=1&explorer.pathRname=1
*/
private function _initData(){
if (strlen($this->in['name'])<1) show_json(LNG('groupname_can_not_null'),false);
$roleArr = array(
'name' => rawurldecode($this->in['name']),
'extNotAllow' => $this->in['extNotAllow']
);
foreach ($this->config['roleSetting'] as $key => $actions) {
foreach ($actions as $action) {
$keyUrl = $key.'_'.$action;//url explorer.mkdir => explorer_mkdir;
$keyAuth = $key.'.'.$action;
if (isset($this->in[$keyUrl])){
$roleArr[$keyAuth] = 1;
}else{
$roleArr[$keyAuth] = 0;
}
}
}
return $roleArr;
}
}
+653
View File
@@ -0,0 +1,653 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class user extends Controller{
private $user; //用户相关信息
private $auth; //用户所属组权限
private $notCheck;
function __construct(){
parent::__construct();
//php5.4 bug;需要重新读取一次
@session_start();
@session_write_close();
if(!isset($_SESSION)){//避免session不可写导致循环跳转
$this->login(DATA_PATH."<br/>".LNG('path_can_not_write_data') );
}else{
$this->user = &$_SESSION['kodUser'];
if(!isset($this->user['path']) && isset($this->user['name'])){//旧版本数据
$this->user['path'] = $this->user['name'];
}
}
//不需要判断的action
$this->notCheckST = array('share','debug');
$this->notCheckACT = array(
'loginFirst','login','logout','loginSubmit',
'checkCode','publicLink','qrcode','sso');
$this->notCheckApp = array();//'pluginApp.to'
if(!$this->user){
$this->notCheckApp = array('pluginApp.to','api.view');
}
$this->config['forceWap'] = is_wap() && (!isset($_COOKIE['forceWap']) || $_COOKIE['forceWap'] == '1');
if( isset($_GET['forceWap']) ){
$this->config['forceWap'] = $_GET['forceWap'];
}
}
public function bindHook(){
$this->loadModel('Plugin')->init();
$this->bindCheckPassword();
}
/**
* 登录状态检测;并初始化数据状态
*/
public function loginCheck(){
// CSRF-TOKEN更新后同步;关闭X-CSRF-TOKEN的httpOnly
if( ACT == 'commonJs' && isset($_SESSION['X-CSRF-TOKEN'])){
$this->_setCsrfToken();
}
if(in_array(ST,$this->notCheckST)) return;//不需要判断的控制器
if(in_array(ACT,$this->notCheckACT)) return;//不需要判断的action
if(in_array(ST.'.'.ACT,$this->notCheckApp)) return;//不需要判断的对应入口
if(isset($_SESSION['kodLogin']) && $_SESSION['kodLogin']===true && $this->user){
$user = systemMember::getInfo($this->user['userID']);
$this->_loginSuccess($user);
return;
}else if($_COOKIE['kodUserID']!='' && $_COOKIE['kodToken']!=''){
$user = systemMember::getInfo($_COOKIE['kodUserID']);
if (!is_array($user) || !isset($user['password'])) {
$this->logout();
}
if($this->_makeLoginToken($user) === $_COOKIE['kodToken']){
@session_start();//re start
$_SESSION['kodLogin'] = true;
$_SESSION['kodUser']= $user;
$_SESSION['X-CSRF-TOKEN'] = rand_string(20);
$this->_setCsrfToken();
setcookie('kodUserID', $_COOKIE['kodUserID'], time()+3600*24*100);
setcookie('kodToken',$_COOKIE['kodToken'],time()+3600*24*100);
//check if session work
@session_write_close();
unset($_SESSION);
@session_start();
if( !isset($_SESSION['kodUser']) ||
!is_array($_SESSION['kodUser'])){
$this->login(DATA_PATH."<br/>".LNG('path_can_not_write_data') );
}else{
$this->_loginSuccess($user);
}
return;
}
$this->logout();//session user数据不存在
}else{
if ($this->config['settingSystem']['autoLogin'] != '1') {
$this->logout();//不自动登录
}else{
if (!file_exists(USER_SYSTEM.'install.lock')) {
$this->display('install.html');
exit;
}
header('location:./index.php?user/loginSubmit&name=guest&password=guest');
exit;
}
}
}
private function _setCsrfToken(){
setcookie_header('X-CSRF-TOKEN',$_SESSION['X-CSRF-TOKEN'], time()+3600*24*100);
}
private function _loginSuccess($user){
$this->user = $user;
if(!$user){//false
show_tips('[Error Code:1001] user data error!');
}else if(!$user['path']){//服务器管理后立即生效
$this->login("Your 'path' is empty,please install again");
}else if($user['status'] == 0){
$this->login(LNG('login_error_user_not_use'));
}else if($user['role']==''){
$this->login(LNG('login_error_role'));
}
define('USER',USER_PATH.$this->user['path'].'/');//utf-8
define('USER_TEMP',USER.'data/temp/');
define('USER_RECYCLE',USER.'recycle_kod/');
@session_start();//re start
$_SESSION['kodUser']= $user;
@session_write_close();
if (!file_exists(iconv_system(USER))) {
$this->login("User/".get_path_this(USER)." ".LNG('not_exists'));
}
$user_home = user_home_path($this->user);//utf-8
define('HOME_PATH',$user_home);
if ($this->user['role'] == '1') {
define('MYHOME',$user_home);
define('HOME','');
$GLOBALS['webRoot'] = WEB_ROOT;//服务器目录
$GLOBALS['isRoot'] = 1;
}else{
define('HOME',$user_home);
define('MYHOME','/');
$GLOBALS['webRoot'] = '';//从服务器开始到用户目录
$GLOBALS['isRoot'] = 0;
}
$desktop = $this->config['settingSystem']['desktopFolder'];
if(isset($this->config['settingSystemDefault']['desktopFolder'])){
$desktop = $this->config['settingSystemDefault']['desktopFolder'];
}
define('DESKTOP_FOLDER',$desktop);
$this->config['user'] = FileCache::load(USER.'data/config.php');
if(!is_array($this->config['user'])){
$this->config['user'] = array();
}
foreach($this->config['settingDefault'] as $key=>$val){
if(!isset($this->config['user'][$key]) ){
$this->config['user'][$key] = $val;
}
}
}
private function _loginCheckPassword($user,$password){
if($this->checkPassword($password)) return;
if($user['role'] == '1'){ // 管理员,提示修改;
if(isset($_SESSION['adminPasswordTips'])) return;
@session_start();
$_SESSION['adminPasswordTips']= 1;
@session_write_close();
show_tips("安全提示:<br/><br/>密码长度必须大于6,同时包含英文和数字;<br/>强烈建议登陆后修改密码!",false);
}
show_tips("密码长度必须大于6,同时包含英文和数字;<br/>请联系管理员修改后再试!",false);
}
private function checkPassword($password){
if(defined('INSTALL_CHANNEL') && INSTALL_CHANNEL =='hikvision.com'){
$this->config['settingSystemDefault']['passwordCheck'] = '1';
}
if($this->config['settingSystemDefault']['passwordCheck'] == '0') return true;
$hasNumber = preg_match('/\d/',$password);
$hasChar = preg_match('/[A-Za-z]/',$password);
if( strlen($password) >= 6 && $hasNumber && $hasChar) return true;
return false;
}
private function bindCheckPassword(){
$action = strtolower(ST.'.'.ACT);
$check = array(
'user.changepassword' => 'passwordNew',
'systemmember.edit' => 'password',
'systemmember.add' => 'password',
);
if(!isset($check[$action])) return;
$password = $this->in[$check[$action]];
if($this->checkPassword($password)) return;
show_json("密码长度必须大于6,同时包含英文和数字;<br/>请联系管理员修改后再试!",false);
}
/**
* 共享kod登陆并跳转
* check: 校验方式:userID|userName|roleID|roleName|groupID|groupName,为空则所有登陆用户
* value: 对应的值
* link : 登陆后的跳转链接
*/
public function sso(){
$result = false;
$error = "未登录!";
if(!isset($_SESSION) || $_SESSION['kodLogin'] != 1){//避免session不可写导致循环跳转
$this->login($error);
}
$user = $_SESSION['kodUser'];
//admin 或者不填则允许所有kod用户登陆
if( $user['role'] == '1' ||
!isset($this->in['check']) ||
!isset($this->in['value']) ){
$result = true;
}
$checkValue = false;
switch ($this->in['check']) {
case 'userID':$checkValue = $user['userID'];break;
case 'userName':$checkValue = $user['name'];break;
case 'roleID':$checkValue = $user['role'];break;
case 'roleName':
$role = systemRole::getInfo($user['role']);
$checkValue = $role['name'];
break;
case 'groupID':
$checkValue = array_keys($user['groupInfo']);
break;
case 'groupName':
$checkValue = array();
foreach ($user['groupInfo'] as $groupID=>$val){
$item = systemGroup::getInfo($groupID);
$checkValue[] = $item['name'];
}
break;
default:break;
}
if(!$result && $checkValue != false){
if( (is_string($checkValue) && $checkValue == $this->in['value']) ||
(is_array($checkValue) && in_array($this->in['value'],$checkValue))
){
$result = true;
}else{
$error = clear_html($this->in['check']).' 没有权限, 配置权限需要为: "'
.clear_html($this->in['value']).'"';
}
}
if($result){
include(LIB_DIR.'api/sso.class.php');
SSO::sessionSet($this->in['app']);
header('location:'.$this->in['link']);
exit;
}
$this->login($error);
}
public function accessToken(){
if($_SESSION['kodLogin'] === true){
show_json(access_token_get(),true);
}else{
show_json('not login!',false);
}
}
//临时文件访问
public function publicLink(){
$pass = $this->config['settingSystem']['systemPassword'];
$fid = $this->in['fid'];//$this->in['fid'] 第三项
$path = Mcrypt::decode($fid,$pass);
if (strlen($path) == 0) {
show_json(LNG('error'),false);
}
$download = isset($_GET['download']);
$filename = isset($_GET['downFilename'])?$_GET['downFilename']:false;
file_put_out($path,$download,$filename);
}
public function commonJs(){
$out = ob_get_clean();
$basicPath = BASIC_PATH;
$userPath = USER_PATH;
$groupPath = GROUP_PATH;
if (!$GLOBALS['isRoot']) {//对非root用户隐藏地址
$basicPath = '/';
$userPath = '/';
$groupPath = '/';
}
$theConfig = array(
'environment' => STATIC_JS,
'lang' => I18n::getType(),
'systemOS' => $this->config['systemOS'],
'isRoot' => $GLOBALS['isRoot'],
'userID' => $this->user['userID'],
'webRoot' => $GLOBALS['webRoot'],
'webHost' => HOST,
'appHost' => APP_HOST,
'staticPath' => STATIC_PATH,
'appIndex' => $_SERVER['SCRIPT_NAME'],
'basicPath' => $basicPath,
'userPath' => $userPath,
'groupPath' => $groupPath,
'myhome' => MYHOME,
'myDesktop' => MYHOME.DESKTOP_FOLDER.'/',
'settings' => array(
'updloadChunkSize' => file_upload_size(),
'updloadThreads' => $this->config['settings']['updloadThreads'],
'updloadBindary' => $this->config['settings']['updloadBindary'],
'uploadCheckChunk' => $this->config['settings']['uploadCheckChunk'],
'paramRewrite' => $this->config['settings']['paramRewrite'],
'pluginServer' => $this->config['settings']['pluginServer'],
'appType' => $this->config['settings']['appType']
),
'phpVersion' => PHP_VERSION,
'version' => KOD_VERSION,
'versionBuild' => KOD_VERSION_BUILD,
'kodID' => md5(BASIC_PATH.$this->config['settingSystem']['systemPassword']),
'jsonData' => "",
'selfShare' => systemMember::userShareList($this->user['userID']),
'userConfig' => $this->config['user'],
'accessToken' => access_token_get(),
'versionEnv' => base64_encode(serverInfo()),
//虚拟目录
'KOD_GROUP_PATH' => KOD_GROUP_PATH,
'KOD_GROUP_SHARE' => KOD_GROUP_SHARE,
'KOD_USER_SELF' => KOD_USER_SELF,
'KOD_USER_SHARE' => KOD_USER_SHARE,
'KOD_USER_RECYCLE' => KOD_USER_RECYCLE,
'KOD_USER_FAV' => KOD_USER_FAV,
'KOD_GROUP_ROOT_SELF' => KOD_GROUP_ROOT_SELF,
'KOD_GROUP_ROOT_ALL' => KOD_GROUP_ROOT_ALL,
'ST' => $this->in['st'],
'ACT' => $this->in['act'],
);
if(isset($this->config['settingSystem']['versionHash'])){
$theConfig['versionHash'] = $this->config['settingSystem']['versionHash'];
$theConfig['versionHashUser'] = $this->config['settingSystem']['versionHashUser'];
}
if (!isset($GLOBALS['auth'])) {
$GLOBALS['auth'] = array();
}
$useTime = mtime() - $GLOBALS['config']['appStartTime'];
header("Content-Type: application/javascript; charset=utf-8");
echo 'if(typeof(kodReady)=="undefined"){kodReady=[];}';
Hook::trigger('user.commonJs.insert',$this->in['st'],$this->in['act']);
echo ';AUTH='.json_encode($GLOBALS['auth']).';';
echo 'G='.json_encode($theConfig).';';
$lang = json_encode_force(I18n::getAll());
if(!$lang){
$lang = '{}';
}
echo 'LNG='.$lang.';G.useTime='.$useTime.';';
}
public function appConfig(){
$theConfig = array(
'lang' => I18n::getType(),
'isRoot' => $GLOBALS['isRoot'],
'userID' => $this->user['userID'],
'myhome' => MYHOME,
'settings' => array(
'updloadChunkSize' => file_upload_size(),
'updloadThreads' => $this->config['settings']['updloadThreads'],
'uploadCheckChunk' => $this->config['settings']['uploadCheckChunk'],
),
'version' => KOD_VERSION,
'versionBuild' => KOD_VERSION_BUILD,
// 'userConfig' => $this->config['user'],
);
show_json($theConfig);
}
/**
* 登录view
*/
public function login($msg = ''){
if(isset($this->in['isAjax'])){
show_json($msg,false);
}
if (!file_exists(USER_SYSTEM.'install.lock')) {
chmod_path(BASIC_PATH,DEFAULT_PERRMISSIONS);
$this->display('install.html');
exit;
}
$this->assign('msg',$msg);
if (is_wap()) {
$this->display('loginWap.html');
}else{
$this->display('login.html');
}
exit;
}
/**
* 首次登录
*/
public function loginFirst(){
if (!file_exists(USER_SYSTEM.'install.lock')) {
touch(USER_SYSTEM.'install.lock');
if(!isset($this->in['password'])){
$this->in['password'] = 'admin';
}
$root = '1';
$sql = systemMember::loadData();
$user = array(//重置admin
'name' => 'admin',
'path' => "admin",
'password' => md5($this->in['password']),
'userID' => $root,
'role' => '1',
'config' => array('sizeMax'=>'0','sizeUse'=>1024),
'groupInfo' => array('1'=>'write'),
'createTime' => time(),
'status' => 1,
);
$sql->set($root,$user);
if( !$user['createTime'] ||
!$user['path'] ||
!file_exists(USER_PATH.$user['path'])
){
$member = new systemMember();
$member->initInstall();
}
}
header('location:./index.php?user/login');
exit;
}
/**
* 退出处理
*/
public function logout(){
session_start();
user_logout();
}
/**
* 登录数据提交处理;登陆跳转:
*
* 自动登陆:index.php?user/loginSubmit&name=guest&password=guest
* 登陆自动跳转:index.php?user/login&link=http://baidu.com
* api登陆:index.php?user/loginSubmit&login_token=ZGVtbw==|da9926fdab0c7c32ab2c329255046793
*/
public function loginSubmit(){
$apiLoginCheck = false;
if(isset($this->in['login_token'])){
$api_token = $this->config['settings']['apiLoginTonken'];
$param = explode('|',$this->in['login_token']);
if( strlen($api_token) < 5 ||
count($param) != 2 ||
md5(base64_decode($param[0]).$api_token) != $param[1]
){
$this->_loginDisplay("API 接口参数错误!",false);
}
$this->in['name'] = urlencode(base64_decode($param[0]));
$apiLoginCheck = true;
}else{
if(!isset($this->in['name']) || !isset($this->in['password'])) {
$this->_loginDisplay(LNG('login_not_null'),false);
}
if( need_check_code()
&& $this->in['name'] != 'guest'
&& $_SESSION['checkCode'] !== strtolower($this->in['checkCode']) ){
$this->_loginDisplay(LNG('code_error'),false);
}
}
$name = rawurldecode($this->in['name']);
$password = rawurldecode($this->in['password']);
if($this->in['salt']){
$key = substr($password,0,5)."2&$%@(*@(djfhj1923";
$password = Mcrypt::decode(substr($password,5),$key);
}
$member = systemMember::loadData();
$user = $member->get('name',$name);
if($apiLoginCheck && $user){//api自动登陆
}else if ($user === false || md5($password) !== $user['password']){
$this->_loginDisplay(LNG('password_error'),false);//$member->get()
}else if($user['status'] == 0){
$this->_loginDisplay(LNG('login_error_user_not_use'),false);
}else if($user['role']==''){
$this->_loginDisplay(LNG('login_error_role'),false);
}
//首次登陆,初始化app 没有最后登录时间
$this->_loginCheckPassword($user,$password);
$this->_loginSuccess($user);//登陆成功
if(!$user['lastLogin']){
$app = init_controller('app');
$app->initApp($user);
}
$user['lastLogin'] = time();//记录最后登录时间
$member->set($user['userID'],$user);
session_start();//re start 有新的修改后调用
$_SESSION['kodLogin'] = true;
$_SESSION['kodUser']= $user;
$_SESSION['X-CSRF-TOKEN'] = rand_string(20);
$this->_setCsrfToken();
setcookie('kodUserID', $user['userID'], time()+3600*24*100);
if ($this->in['rememberPassword'] == '1') {
setcookie('kodToken',$this->_makeLoginToken($user),time()+3600*24*100);
}
$this->_loginDisplay('ok',true);
}
private function _loginDisplay($msg,$success){
if(isset($this->in['isAjax'])){
if(isset($this->in['getToken']) && $success){
show_json(access_token_get(),true);
}
show_json($msg,$success);
}else{
if($success){
$href = './';
if(isset($this->in['link'])){
$href = rawurldecode($this->in['link']);
}
header('location:'.$href);
}else{
$this->login($msg);
}
}
exit;
}
//登陆token
private function _makeLoginToken($userInfo){
//$ua = $_SERVER['HTTP_USER_AGENT'];
$system_pass = $this->config['settingSystem']['systemPassword'];
return md5($userInfo['password'].$system_pass.$userInfo['userID']);
}
public function versionInstall(){
}
/**
* 修改密码
*/
public function changePassword(){
$passwordNow=rawurldecode($this->in['passwordNow']);
$passwordNew=rawurldecode($this->in['passwordNew']);
if (!$passwordNow && !$passwordNew)show_json(LNG('password_not_null'),false);
if ($this->user['password']==md5($passwordNow)){
$sql=systemMember::loadData();
$this->user['password'] = md5($passwordNew);
$sql->set($this->user['userID'],$this->user);
show_json('success');
}else {
show_json(LNG('old_password_error'),false);
}
}
//CSRF 防护;cookie设置:CSRF-TOKENheader:提交X-CSRF-TOKEN
//referer检测
private function _checkCSRF(){
$not_check = array('user.commonJs','pluginApp.index');
if( !$this->config['settingSystem']['csrfProtect'] ||
isset($this->in['accessToken']) ||
in_array(ST.'.'.ACT, $not_check)
){
return;
}
if( !isset($_SERVER['HTTP_X_CSRF_TOKEN'])||
$_SERVER['HTTP_X_CSRF_TOKEN'] != $_SESSION['X-CSRF-TOKEN']
){
show_json('token_error',false);
}
}
private function _checkKey($key){
if(!isset($this->in[$key])){
return '';
}
return is_string($this->in[$key])? rawurldecode($this->in[$key]):'';
}
private function initAuth(){
$auth = systemRole::getInfo($this->user['role']);
//向下版本兼容处理
//未定义;新版本首次使用默认开放的功能
if(!isset($auth['userShare.set'])){
$auth['userShare.set'] = 1;
}
if(!isset($auth['explorer.fileDownload'])){
$auth['explorer.fileDownload'] = 1;
}
//默认扩展功能 等价权限
$auth['user.commonJs'] = 1;//权限数据配置后输出到前端
$auth['explorer.pathDeleteRecycle'] = $auth['explorer.pathDelete'];
$auth['explorer.pathCopyDrag'] = $auth['explorer.pathCuteDrag'];
$auth['explorer.officeSave'] = $auth['editor.fileSave'];
$auth['explorer.fileSave'] = $auth['editor.fileSave'];
$auth['explorer.imageRotate'] = $auth['editor.fileSave'];
$auth['explorer.fileDownloadRemove']= $auth['explorer.fileDownload'];
$auth['explorer.zipDownload'] = $auth['explorer.fileDownload'];
$auth['explorer.unzipList'] = $auth['explorer.unzip'];
//彻底禁止下载;文件获取
//$auth['explorer.fileProxy'] = $auth['explorer.fileDownload'];
//$auth['editor.fileGet'] = $auth['explorer.fileDownload'];
//$auth['explorer.officeView'] = $auth['explorer.fileDownload'];
$auth['editor.fileGet'] = 1;
$auth['explorer.fileProxy'] = 1;
$auth['explorer.officeView']= 1;
$auth['explorer.pathList'] = 1;
$auth['explorer.treeList'] = 1;
if(!$auth['explorer.fileDownload']){
$auth['explorer.zip'] = 0;
}
$auth['userShare.del'] = $auth['userShare.set'];
$GLOBALS['auth'] = $auth;
}
/**
* 权限验证;统一入口检验
*/
public function authCheck(){
$this->initAuth();
if(in_array(ST,$this->notCheckST)) return;//不需要判断的控制器
if(in_array(ACT,$this->notCheckACT)) return;//不需要判断的action
if(in_array(ST.'.'.ACT,$this->notCheckApp)) return;//不需要判断的对应入口
if (!array_key_exists(ST,$this->config['roleSetting']) ) return;
if (!in_array(ACT,$this->config['roleSetting'][ST])) return;//输出处理过的权限
$this->_checkCSRF();
if (isset($GLOBALS['isRoot']) && $GLOBALS['isRoot'] == 1) return;
if ($GLOBALS['auth'][ST.'.'.ACT] != 1) show_json(LNG('no_permission'),false);
//扩展名限制:新建文件&上传文件&重命名文件&保存文件&zip解压文件
$check_arr = array(
'mkfile' => $this->_checkKey('path'),
'pathRname' => $this->_checkKey('rnameTo'),
'fileUpload'=> $_FILES['file']['name']? $_FILES['file']['name']:$GLOBALS['in']['name'],
'fileSave' => $this->_checkKey('path')
);
if (array_key_exists(ACT,$check_arr) && !checkExt($check_arr[ACT])){
show_json(LNG('no_permission_ext'),false);
}
}
public function checkCode() {
session_start();//re start
$captcha = new MyCaptcha(4);
$_SESSION['checkCode'] = $captcha->getString();
}
public function qrcode(){
$url = $this->in['url'];
if(function_exists('imagecolorallocate')){
ob_get_clean();
QRcode::png($this->in['url']);
}else{
header('location: https://demo.kodcloud.com/?user/view/qrcode&url='.rawurlencode($url));
}
}
}
@@ -0,0 +1,110 @@
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
class userShare extends Controller{
private $sql;
function __construct(){
parent::__construct();
$this->sql=new FileCache(USER.'data/share.php');
}
/**
* 获取
*/
public function get($ret = 0) {
$list = $this->sql->get();
foreach($list as $key=>&$val){
//unset($val['sharePassword']);
}
if($ret){
return $list;
}
show_json($list, true);
}
//检测该目录是否已被共享
public function checkByPath(){
$this->in['path'] = _DIR_CLEAR($this->in['path']);
$shareInfo = $this->sql->get('path',$this->in['path']);
if (!$shareInfo) {
show_json('',false);//没有找到
}else{
show_json($shareInfo,true,$this->get(1));
}
}
/**
* 编辑
*/
public function set(){
if (!$this->in['name'] || !$this->in['path'] || !$this->in['type']){
show_json(LNG('data_not_full'),false);
}
$shareInfo = array(
'mtime' => time(),//更新则记录最后时间
'sid' => isset($this->in['sid'])?$this->in['sid']:'',
'type' => $this->in['type'],
'path' => _DIR_CLEAR($this->in['path']),
'name' => $this->in['name'],
'showName' => isset($this->in['showName'])?$this->in['showName']:$this->in['name'],
'timeTo' => isset($this->in['timeTo'])?$this->in['timeTo']:'',
'sharePassword' => isset($this->in['sharePassword'])?$this->in['sharePassword']:'',
'codeRead' => isset($this->in['codeRead'])?$this->in['codeRead']:'',
'canUpload' => isset($this->in['canUpload'])?$this->in['canUpload']:'',
'notDownload' => isset($this->in['notDownload'])?$this->in['notDownload']:''
);
if(substr($shareInfo['path'],0,1) == '{'){//用户只能分享自己的目录;
show_json(LNG('path_can_not_action'),false);
}
$name = $shareInfo['name'];
$search = $this->sql->get('name',$name);
$i = 0;
while($i>200 || $search && $search['sid']!=$shareInfo['sid']){
$name = $shareInfo['name'].'('.$i.')';
$search = $this->sql->get('name',$name);
$i++;
}
if($i !=0){
$shareInfo['name'] = $name;
}
//含有sid则为更新,否则为插入
if (isset($this->in['sid']) && strlen($this->in['sid']) == 8) {
$infoNew = $this->sql->get($this->in['sid']);
foreach ($shareInfo as $key=>$val) {//只更新指定key
$infoNew[$key] = $val;
}
if($this->sql->set($this->in['sid'],$infoNew)){
show_json($infoNew,true,$this->get(1));
}
show_json(LNG('error'),false);
}else{//插入
$shareList = $this->sql->get();
$newId = rand_string(8);
while (isset($shareList[$newId])) {
$newId = rand_string(8);
}
$shareInfo['sid'] = $newId;
if($this->sql->set($newId,$shareInfo)){
show_json($shareInfo,true,$this->get(1));
}
show_json(LNG('error'),false);
}
show_json(LNG('error'),false);
}
/**
* 删除
*/
public function del() {
$list = json_decode($this->in['dataArr'],true);
foreach ($list as $val) {
$this->sql->remove($val['path']);
}
show_json(LNG('success'),true,$this->get(1));
}
}
File diff suppressed because one or more lines are too long