sysfileAction.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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,';
  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. public function editAction()
  90. {
  91. if($str=$this->iscaozuo())return $str;
  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. $pathinfo=pathinfo($path);
  98. $filename = $pathinfo['basename'];
  99. $filesize = filesize($path);
  100. $content = file_get_contents($path);
  101. $encode = mb_detect_encoding($content, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
  102. if($encode && $encode != "UTF-8"){
  103. $content = iconv($encode,'utf-8',$content);
  104. }
  105. $this->smartydata['filename'] = $filename;
  106. $fileext = strtolower(substr($path,strripos($path,'.')+1));
  107. $this->smartydata['fileext'] = $fileext;
  108. $this->smartydata['content'] = $content;
  109. $this->smartydata['filepath'] = $this->jm->base64encode($path);
  110. $this->smartydata['filesize'] = $this->rock->formatsize($filesize);
  111. }
  112. private function delfolder($path)
  113. {
  114. $this->fileall = array();
  115. $this->folderall = array();
  116. $this->getallfile($path);
  117. $total = count($this->fileall);
  118. if($this->fileall)foreach($this->fileall as $file)unlink($file);
  119. if($this->folderall)foreach($this->folderall as $file)rmdir($file);
  120. if(is_dir($path))rmdir($path);
  121. return '共删除'.$total.'个文件';
  122. }
  123. /**
  124. * 清理
  125. */
  126. public function clearlogsAjax()
  127. {
  128. if($str=$this->iscaozuo())return $str;
  129. $path = ''.UPDIR.'/logs';
  130. return $this->delfolder($path);
  131. }
  132. private function getallfile($path)
  133. {
  134. $dir_arr = @scandir($path);
  135. $darr1= $rows = array();
  136. if($dir_arr)foreach($dir_arr as $key=>$val){
  137. if($val == '.' || $val == '..'){
  138. }else{
  139. $mulu = $path.'/'.$val.'';
  140. if(is_dir($mulu)){
  141. $this->getallfile($mulu);
  142. $this->folderall[] = $mulu;
  143. }else{
  144. $this->fileall[] = $mulu;
  145. }
  146. }
  147. }
  148. }
  149. /**
  150. * 删除文件
  151. */
  152. public function delfileAjax()
  153. {
  154. if($str=$this->iscaozuo())return $str;
  155. $path = $this->jm->base64decode($this->get('path'));
  156. if(isempt($path))return '无效文件';
  157. $isdel = 0;
  158. foreach($this->isdelmu as $sdif)if(strpos($path, $sdif)===0)$isdel=1;
  159. if($isdel==0)return '此文件禁止删除';
  160. if(is_dir($path))return $this->delfolder($path);
  161. unlink($path);
  162. return '删除成功';
  163. }
  164. public function svnupdateAjax()
  165. {
  166. $cmd = '"'.getconfig('svnpath').'" /command:update /closeonend:1 /path:"'.ROOT_PATH.'"';
  167. c('socket')->udpsend($cmd);
  168. return '已发送svn更新';
  169. }
  170. }
粤ICP备19079148号