sysfileAction.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. class sysfileClassAction extends Action
  3. {
  4. public function initAction()
  5. {
  6. $this->isdelmu = array(''.UPDIR.'/logs', ''.UPDIR.'/sqllog',''.UPDIR.'/cache', ''.UPDIR.'/data/'.(date('Y')-1).'');
  7. }
  8. public function getdataAjax()
  9. {
  10. $notedit = ',exe,dll,zip,rar,gz,ocx,png,gif,jpg,ico,mp4,wmv,frx,psd,';
  11. $this->notedit = $notedit;
  12. $rows = array();
  13. $path = '';
  14. $isope= getconfig('sysfileview');
  15. if($this->adminid!=1 || getconfig('system')=='demo' || !$isope){
  16. if($this->adminid!=1)$rows[]=array('name'=>'非admin管理员不能查看');
  17. if(getconfig('system')=='demo')$rows[]=array('name'=>'演示不能查看');
  18. if(!$isope)$rows[]=array('name'=>'系统配置文件没有打开sysfileview选项,不能查看,可配置加上\'sysfileview\'=>true,即可');
  19. }else{
  20. $path = $this->jm->base64decode($this->get('path'));
  21. $rows = $this->getfilelist($path);
  22. }
  23. $total = count($rows);
  24. return array(
  25. 'rows' => $rows,
  26. 'totalCount'=> $total,
  27. 'success' => true,
  28. 'nowpath' => $path
  29. );
  30. }
  31. private function getfilelist($path)
  32. {
  33. $chk = c('check');
  34. $php5= version_compare(PHP_VERSION, '7.0.0','<');
  35. $dir_arr = @scandir(ROOT_PATH.'/'.$path);
  36. $darr1= $rows = array();
  37. foreach($dir_arr as $key=>$val){
  38. if($val == '.' || $val == '..'){
  39. }else{
  40. if($php5 && $chk->isincn($val))$val = iconv('gb2312','utf-8', $val);
  41. $mulu = $path.'/'.$val.'';
  42. if(!$path)$mulu = $val;
  43. if(is_dir($mulu)){
  44. $isdel = 0;
  45. foreach($this->isdelmu as $sdif)if(strpos($mulu, $sdif)===0)$isdel=1;
  46. $rows[] = array(
  47. 'name' => $val,
  48. 'type'=>'folder-close-alt',
  49. 'lei'=>0,
  50. 'isdel'=>$isdel,
  51. 'path'=> $this->jm->base64encode($mulu)
  52. );
  53. }else{
  54. $suhs = $this->getfilew($val, $mulu,'',0);
  55. if($suhs)$darr1[] = $suhs;
  56. }
  57. }
  58. }
  59. foreach($darr1 as $k=>$rs)$rows[] = $rs;
  60. return $rows;
  61. }
  62. private function getfilew($val,$mulu,$sm='',$isdel=0)
  63. {
  64. if(!file_exists($mulu))return false;
  65. $fileext = strtolower(substr($val,strripos($val,'.')+1));
  66. $isedit = 1;
  67. if(contain($this->notedit,','.$fileext.','))$isedit = 0;
  68. foreach($this->isdelmu as $sdif)if(strpos($mulu, $sdif)===0)$isdel=1;
  69. return array(
  70. 'name' => $val,
  71. 'type' => 'file',
  72. 'lei'=>1,
  73. 'filesize' => $this->rock->formatsize(filesize($mulu)),
  74. 'createdt' => date('Y-m-d H:i:s',filectime($mulu)),
  75. 'lastdt' => date('Y-m-d H:i:s',filemtime($mulu)),
  76. 'path' => $this->jm->base64encode($mulu),
  77. 'fileext' => $fileext,
  78. 'isedit' => $isedit,
  79. 'isdel' => $isdel,
  80. 'explain' => $sm
  81. );
  82. }
  83. private function iscaozuo()
  84. {
  85. if($this->adminid!=1 || getconfig('system')=='demo' || !getconfig('sysfileview'))return '禁止操作';
  86. return '';
  87. }
  88. public function editAction()
  89. {
  90. if($str=$this->iscaozuo())return $str;
  91. $path = $this->jm->base64decode($this->get('path'));
  92. if(isempt($path))return '无效路径';
  93. if(!file_exists(ROOT_PATH.'/'.$path))return '文件不存在';
  94. $pathinfo=pathinfo($path);
  95. $filename = $pathinfo['basename'];
  96. $filesize = filesize($path);
  97. $content = file_get_contents($path);
  98. $encode = mb_detect_encoding($content, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
  99. if($encode && $encode != "UTF-8"){
  100. $content = iconv($encode,'utf-8',$content);
  101. }
  102. $this->smartydata['filename'] = $filename;
  103. $fileext = strtolower(substr($path,strripos($path,'.')+1));
  104. $this->smartydata['fileext'] = $fileext;
  105. $this->smartydata['content'] = $content;
  106. $this->smartydata['filepath'] = $this->jm->base64encode($path);
  107. $this->smartydata['filesize'] = $this->rock->formatsize($filesize);
  108. }
  109. private function delfolder($path)
  110. {
  111. $this->fileall = array();
  112. $this->folderall = array();
  113. $this->getallfile($path);
  114. $total = count($this->fileall);
  115. if($this->fileall)foreach($this->fileall as $file)unlink($file);
  116. if($this->folderall)foreach($this->folderall as $file)rmdir($file);
  117. if(is_dir($path))rmdir($path);
  118. return '共删除'.$total.'个文件';
  119. }
  120. /**
  121. * 清理
  122. */
  123. public function clearlogsAjax()
  124. {
  125. if($str=$this->iscaozuo())return $str;
  126. $path = ''.UPDIR.'/logs';
  127. return $this->delfolder($path);
  128. }
  129. private function getallfile($path)
  130. {
  131. $dir_arr = @scandir($path);
  132. $darr1= $rows = array();
  133. if($dir_arr)foreach($dir_arr as $key=>$val){
  134. if($val == '.' || $val == '..'){
  135. }else{
  136. $mulu = $path.'/'.$val.'';
  137. if(is_dir($mulu)){
  138. $this->getallfile($mulu);
  139. $this->folderall[] = $mulu;
  140. }else{
  141. $this->fileall[] = $mulu;
  142. }
  143. }
  144. }
  145. }
  146. /**
  147. * 删除文件
  148. */
  149. public function delfileAjax()
  150. {
  151. if($str=$this->iscaozuo())return $str;
  152. $path = $this->jm->base64decode($this->get('path'));
  153. if(isempt($path))return '无效文件';
  154. $isdel = 0;
  155. foreach($this->isdelmu as $sdif)if(strpos($path, $sdif)===0)$isdel=1;
  156. if($isdel==0)return '此文件禁止删除';
  157. if(is_dir($path))return $this->delfolder($path);
  158. unlink($path);
  159. return '删除成功';
  160. }
  161. public function svnupdateAjax()
  162. {
  163. $cmd = '"'.getconfig('svnpath').'" /command:update /closeonend:1 /path:"'.ROOT_PATH.'"';
  164. c('socket')->udpsend($cmd);
  165. return '已发送svn更新';
  166. }
  167. }
粤ICP备19079148号