sysfileAction.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. class sysfileClassAction extends Action
  3. {
  4. public $notedit,$isdelmu;
  5. public function initAction()
  6. {
  7. $this->isdelmu = array(''.UPDIR.'/logs', ''.UPDIR.'/sqllog',''.UPDIR.'/cache', ''.UPDIR.'/data/'.(date('Y')-1).'');
  8. }
  9. public function getdataAjax()
  10. {
  11. $notedit = ',exe,dll,zip,rar,gz,ocx,png,gif,jpg,ico,mp4,wmv,frx,psd,doc,docx,xls,xlsx,ppt,pptx,pdf,odt,';
  12. $this->notedit = $notedit;
  13. $rows = array();
  14. $path = '';
  15. $isope= getconfig('sysfileview');
  16. if($this->adminid!=1 || getconfig('system')=='demo' || !$isope){
  17. if($this->adminid!=1)$rows[]=array('name'=>'非admin管理员不能查看');
  18. if(getconfig('system')=='demo')$rows[]=array('name'=>'演示不能查看');
  19. if(!$isope)$rows[]=array('name'=>'系统配置文件没有打开sysfileview选项,不能查看,可配置加上\'sysfileview\'=>true,即可');
  20. }else{
  21. $path = $this->jm->base64decode($this->get('path'));
  22. $rows = $this->getfilelist($path);
  23. }
  24. $total = count($rows);
  25. return array(
  26. 'rows' => $rows,
  27. 'totalCount'=> $total,
  28. 'success' => true,
  29. 'nowpath' => $path
  30. );
  31. }
  32. private function getfilelist($path)
  33. {
  34. $chk = c('check');
  35. $php5= version_compare(PHP_VERSION, '7.0.0','<');
  36. $dir_arr = @scandir(ROOT_PATH.'/'.$path);
  37. $darr1= $rows = array();
  38. foreach($dir_arr as $key=>$val){
  39. if($val == '.' || $val == '..'){
  40. }else{
  41. if($php5 && $chk->isincn($val))$val = iconv('gb2312','utf-8', $val);
  42. $mulu = $path.'/'.$val.'';
  43. if(!$path)$mulu = $val;
  44. if(is_dir($mulu)){
  45. $isdel = 0;
  46. foreach($this->isdelmu as $sdif)if(strpos($mulu, $sdif)===0)$isdel=1;
  47. $rows[] = array(
  48. 'name' => $val,
  49. 'type'=>'folder-close-alt',
  50. 'lei'=>0,
  51. 'isdel'=>$isdel,
  52. 'path'=> $this->jm->base64encode($mulu)
  53. );
  54. }else{
  55. $suhs = $this->getfilew($val, $mulu,'',0);
  56. if($suhs)$darr1[] = $suhs;
  57. }
  58. }
  59. }
  60. foreach($darr1 as $k=>$rs)$rows[] = $rs;
  61. return $rows;
  62. }
  63. private function getfilew($val,$mulu,$sm='',$isdel=0)
  64. {
  65. if(!file_exists($mulu))return false;
  66. $fileext = strtolower(substr($val,strripos($val,'.')+1));
  67. $isedit = 1;
  68. if(contain($this->notedit,','.$fileext.','))$isedit = 0;
  69. foreach($this->isdelmu as $sdif)if(strpos($mulu, $sdif)===0)$isdel=1;
  70. return array(
  71. 'name' => $val,
  72. 'type' => 'file',
  73. 'lei'=>1,
  74. 'filesize' => $this->rock->formatsize(filesize($mulu)),
  75. 'createdt' => date('Y-m-d H:i:s',filectime($mulu)),
  76. 'lastdt' => date('Y-m-d H:i:s',filemtime($mulu)),
  77. 'path' => $this->jm->base64encode($mulu),
  78. 'fileext' => $fileext,
  79. 'isedit' => $isedit,
  80. 'isdel' => $isdel,
  81. 'explain' => $sm
  82. );
  83. }
  84. private function iscaozuo()
  85. {
  86. if($this->adminid!=1 || getconfig('system')=='demo' || !getconfig('sysfileview'))return '禁止操作';
  87. return '';
  88. }
  89. private $nowpath = '';
  90. private function getpaths()
  91. {
  92. $path = $this->jm->base64decode($this->get('path'));
  93. if(isempt($path))return '无效路径';
  94. $path = str_replace('\\','/', $path);
  95. $path = str_replace(array('../','..'),'', $path);
  96. if(!file_exists(ROOT_PATH.'/'.$path))return '文件不存在';
  97. $this->nowpath = $path;
  98. return '';
  99. }
  100. public function editAction()
  101. {
  102. if($str=$this->iscaozuo())return $str;
  103. if($str=$this->getpaths())return $str;
  104. $path = $this->nowpath;
  105. $pathinfo= pathinfo($path);
  106. $filename = $pathinfo['basename'];
  107. $filesize = filesize($path);
  108. $content = file_get_contents($path);
  109. $encode = mb_detect_encoding($content, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
  110. if($encode && $encode != "UTF-8"){
  111. $content = iconv($encode,'utf-8',$content);
  112. }
  113. $this->smartydata['filename'] = $filename;
  114. $fileext = strtolower(substr($path,strripos($path,'.')+1));
  115. $this->smartydata['fileext'] = $fileext;
  116. $this->smartydata['content'] = $content;
  117. $this->smartydata['filepath'] = $this->jm->base64encode($path);
  118. $this->smartydata['filesize'] = $this->rock->formatsize($filesize);
  119. }
  120. public function editeAction()
  121. {
  122. $this->editAction();
  123. }
  124. //加载文件内容
  125. public function loadfileAction()
  126. {
  127. if($str=$this->iscaozuo())return $str;
  128. if($str=$this->getpaths())return $str;
  129. $path = $this->nowpath;
  130. $lx = (int)$this->get('lx');
  131. $paths = str_replace('/','@', $path);
  132. $earr = false;
  133. if($lx == 0){
  134. $earr = array();
  135. $bar = glob(''.UPDIR.'/logs/editfile/'.$paths.'_*');
  136. foreach($bar as $k=>$fil1){
  137. $dna = explode('_', $fil1);
  138. $earr[] = array(
  139. 'path' => $this->jm->base64encode($fil1),
  140. 'optdt'=> date('Y-m-d H:i:s', $dna[1])
  141. );
  142. }
  143. }
  144. return array(
  145. 'content' => file_get_contents($path),
  146. 'earr' => $earr
  147. );
  148. }
  149. //保存文件
  150. public function savefileAction()
  151. {
  152. if($str=$this->iscaozuo())return $str;
  153. if($str=$this->getpaths())return $str;
  154. $path = $this->nowpath;
  155. $content = $this->jm->base64decode($this->post('content'));
  156. $oldcont = file_get_contents($path);
  157. $nfile = ''.UPDIR.'/logs/editfile/'.str_replace('/','@', $path).'_'.time().'';
  158. $this->rock->createtxt($nfile, $oldcont);
  159. $bool = @file_put_contents($path, $content);
  160. if(!$bool)return '保存失败';
  161. return 'ok';
  162. }
  163. //创建文件
  164. public function createfileAjax()
  165. {
  166. if($str=$this->iscaozuo())return $str;
  167. $path = $this->jm->base64decode($this->get('path'));
  168. $file = $this->jm->base64decode($this->get('file'));
  169. if($path)$path.='/';
  170. $this->rock->createtxt(''.$path.''.$file.'', ' ');
  171. return '创建成功';
  172. }
  173. private function delfolder($path)
  174. {
  175. $this->fileall = array();
  176. $this->folderall = array();
  177. $this->getallfile($path);
  178. $total = count($this->fileall);
  179. if($this->fileall)foreach($this->fileall as $file)unlink($file);
  180. if($this->folderall)foreach($this->folderall as $file)rmdir($file);
  181. if(is_dir($path))rmdir($path);
  182. return '共删除'.$total.'个文件';
  183. }
  184. /**
  185. * 清理
  186. */
  187. public function clearlogsAjax()
  188. {
  189. if($str=$this->iscaozuo())return $str;
  190. $path = ''.UPDIR.'/logs';
  191. return $this->delfolder($path);
  192. }
  193. private function getallfile($path)
  194. {
  195. $dir_arr = @scandir($path);
  196. $darr1= $rows = array();
  197. if($dir_arr)foreach($dir_arr as $key=>$val){
  198. if($val == '.' || $val == '..'){
  199. }else{
  200. $mulu = $path.'/'.$val.'';
  201. if(is_dir($mulu)){
  202. $this->getallfile($mulu);
  203. $this->folderall[] = $mulu;
  204. }else{
  205. $this->fileall[] = $mulu;
  206. }
  207. }
  208. }
  209. }
  210. /**
  211. * 删除文件
  212. */
  213. public function delfileAjax()
  214. {
  215. if($str=$this->iscaozuo())return $str;
  216. $path = $this->jm->base64decode($this->get('path'));
  217. if(isempt($path))return '无效文件';
  218. $path = str_replace('../','',$path);
  219. $isdel = 0;
  220. foreach($this->isdelmu as $sdif)if(strpos($path, $sdif)===0)$isdel=1;
  221. if($isdel==0)return '此文件禁止删除';
  222. if(is_dir($path))return $this->delfolder($path);
  223. unlink($path);
  224. return '删除成功';
  225. }
  226. public function svnupdateAjax()
  227. {
  228. $cmd = '"'.getconfig('svnpath').'" /command:update /closeonend:1 /path:"'.ROOT_PATH.'"';
  229. c('socket')->udpsend($cmd);
  230. return '已发送svn更新';
  231. }
  232. }
粤ICP备19079148号