Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # 2014 :P raphik
- tDirVid="/tmp/pruebas/video"
- tDirAud="/tmp/pruebas/audio"
- tDirFot="/tmp/pruebas/foto"
- tDirDes="/tmp/pruebas/descargas"
- echo -e "Content-type:text/html\n\n"
- read -t 1 cadena
- # Si no se le pasan argumentos se visualiza, por defecto, la carpeta Video ordenada por Nombre
- if [ ! "$cadena" ] ; then
- cadena="VidNom=VidNom"
- fi
- # Si se ha pulsado el botón "Borrar"
- if [ ${cadena:7:6} == "Borrar" ]; then
- # Selecciona el directorio en el que están los ficheros que se borrarán
- vCar=${cadena:0:3}
- case $vCar in
- Vid) tDir=$tDirVid;;
- Aud) tDir=$tDirAud;;
- Fot) tDir=$tDirFot;;
- Des) tDir=$tDirDes;;
- esac
- # OPERACIONES DE BORRADO
- cadena=$(echo -e $cadena | sed 's/%0D%0A//g; s/%C2%A0/\\x20/g; s/%/\\x/g')
- oldIFS=$IFS
- IFS=' &'
- for line in ${cadena:14}
- do
- x=$(echo -e ${line:7})
- rm "$tDir/$(echo -e ${line:7})"
- done
- IFS=$oldIFS
- # Misma carpeta, mismo orden
- cadena="${cadena:0:6}=${cadena:0:6}"
- fi
- # Nueva carpeta, nuevo orden
- cadena="${cadena:7:6}=${cadena:7:6}"
- tClassFichaVid='fichaIna'; tClassFichaAud='fichaIna'; tClassFichaFot='fichaIna'; tClassFichaDes='fichaIna'
- vCar=${cadena:0:3}
- case $vCar in
- Vid) tDir=$tDirVid; tClassFichaVid='fichaAct';;
- Aud) tDir=$tDirAud; tClassFichaAud='fichaAct';;
- Fot) tDir=$tDirFot; tClassFichaFot='fichaAct';;
- Des) tDir=$tDirDes; tClassFichaDes='fichaAct';;
- esac
- tNom='Nombre'; tTam='Tamaño'; tFec='Fecha'
- vOrd=${cadena:3:3}
- case $vOrd in
- Nom) tNom='↑ Nombre ↑'; tOrd='-leh';;
- Tam) tTam='↓ Tamaño ↓'; tOrd='-lehS';;
- Fec) tFec='↓ Fecha ↓'; tOrd='-leht';;
- esac
- x=$(ls $tOrd $tDir)
- # Cálculos de espacio
- tEspDisco=$(df -h $tDir | sed -n 2p | awk '{print $2}')
- nEspDisco=$(df $tDir | sed -n 2p | awk '{print $2}')
- nEspLibre=$(df $tDir | sed -n 2p | awk '{print $4}')
- nEspCarpeta=$(du -sx $tDir | awk '{print $1}')
- nPorcentajeLibre=$(( $nEspLibre * 100 / $nEspDisco ))
- nPorcentajeCarpeta=$(( $nEspCarpeta * 100 / $nEspDisco ))
- nPorcentajeOtras=$(( 100 - nPorcentajeLibre - nPorcentajeCarpeta ))
- echo "<html><meta charset='utf-8'><head><title>PRUEBA</title>"
- echo "<style type='text/css'>"
- echo "table { border-collapse:collapse; width:100%}"
- echo "tr.ficha { text-align:center;}"
- echo "td.ficha { width:25%; text-align:center; padding:10px 0px 5px 0px; border-top-left-radius:15px 30px; border-top-right-radius:15px 30px;}"
- echo "td.fichaAct { color:Black; background-color:PaleTurquoise; cursor:default;}"
- echo "td.fichaIna { color:Black; background-color:CadetBlue; cursor:pointer;}"
- echo "td.fichaIna:hover { color:Black; background-color:MediumTurquoise;}"
- echo "caption { color:black; background-color:PaleTurquoise; text-align:center; padding:15px 25px 0px 25px;}"
- echo "span.lib { color:LightSalmon;}"
- echo "span.car { color:HotPink;}"
- echo "span.otr { color:Purple;}"
- echo "div.lib { background-color:LightSalmon;}"
- echo "div.car { background-color:HotPink;}"
- echo "div.otr { background-color:Purple; height:10px;}"
- echo "tr.cab { background-color:PaleTurquoise;}"
- echo "input.cab { width: 100%;}"
- echo "button { width:100%;}"
- echo "tr.dhi { color:black; background-color:LightCyan;}"
- echo "tr.dlo { color:black; background-color:PaleTurquoise;}"
- echo "td.bor { text-align:right; padding:0px 15px 0px 15px;}"
- echo "td.nom { text-align:left; padding:0px 15px 0px 15px;}"
- echo "td.tam { text-align:right; padding:0px 15px 0px 15px;}"
- echo "td.fec { text-align:right; padding:0px 15px 0px 15px;}"
- echo "</style>"
- echo "</head>"
- echo "<body>"
- echo "<div align=left style='margin:0px 50px auto;'>"
- # 4 FICHAS
- echo "<form id='id_fCar' action='' method='POST'><input id='id_iCar' type='hidden' name=$vCar$vOrd></form>"
- echo "<table><tr class='ficha'>"
- echo "<td class='ficha $tClassFichaVid' onclick='document.getElementById(\"id_iCar\").value=\"Vid$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Video</td>"
- echo "<td class='ficha $tClassFichaAud' onclick='document.getElementById(\"id_iCar\").value=\"Aud$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Audio</td>"
- echo "<td class='ficha $tClassFichaFot' onclick='document.getElementById(\"id_iCar\").value=\"Fot$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Foto</td>"
- echo "<td class='ficha $tClassFichaDes' onclick='document.getElementById(\"id_iCar\").value=\"Des$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Descargas</td>"
- echo "</tr></table>"
- echo "<table>"
- echo "<caption>"
- # INFO ESPACIO
- echo "<div _style='text-align:left'>"
- echo " <span class='lib'>★ </span>Libre: $nPorcentajeLibre% "
- echo " <span class='car'>★ </span>Esta carpeta: $nPorcentajeCarpeta% "
- echo " <span class='otr'>★ </span>Otras carpetas: $nPorcentajeOtras%"
- echo "</div>"
- # BARRA DE PORCENTAJES
- echo "<div class='otr' style='position:relative';>"
- echo " <div class='lib' style='position:absolute; left:0px; top:0px; width:$nPorcentajeLibre%; height:100%;'></div>"
- echo " <div class='car' style='position:absolute; left:$nPorcentajeLibre%; top:0px; width:$nPorcentajeCarpeta%; height:100%;'></div>"
- echo "</div>"
- # TAMAÑO DEL DISCO
- echo "<div _style='text-align:left'>"
- echo "<span class='tot'>Tamaño del disco: $tEspDisco</span>"
- echo "</div>"
- echo "</caption>"
- # 4 BOTONES - CABECERA DEL LISTADO
- echo "<form id='id_borrar' action='' method='POST'></form>"
- echo "<form id='id_fOrd' action='' method='POST'><input id='id_iOrd' type='hidden' name='$vCar$vOrd'></form>"
- echo "<tr class='cab'>"
- echo "<td><input form='id_borrar' class='cab' type='submit' name='$vCar$vOrd' value='Borrar' onClick=\"return confirm('¿Está Ud. seguro de querer borrar?');\"></td>"
- echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Nom\"; document.getElementById(\"id_fOrd\").submit();'>$tNom</button></td>"
- echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Tam\"; document.getElementById(\"id_fOrd\").submit();'>$tTam</button></td>"
- echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Fec\"; document.getElementById(\"id_fOrd\").submit();'>$tFec</button></td>"
- echo "</tr>"
- # LÍNEAS DE DETALLE
- if [ $nEspCarpeta == 0 ] ; then
- echo "<tr class='dlo' align=center><td colspan=4><h2>LA CARPETA ESTÁ VACÍA</h2></tr></td>"
- else
- # reservamos el IFS actual y fijamos uno nuevo para que detecte el final de la línea(HEX '0a')
- oldIFS=$IFS
- IFS=$'\r'
- echo $x | awk '{if(NR%2) print "<tr class='dhi'>"; else print "<tr class='dlo'>";}; \
- {print "<td class='bor' >"NR"<input form='id_borrar' type='checkbox' name='borrar' value=\42"}; \
- {x=substr($0,68); gsub(/ /,"\\ ",x); print x}; \
- {print "\42></td><td class='nom'>"}; \
- {x=substr($0,68); gsub(/ /,"\\ ",x); print x}; \
- {print "</td><td class='tam'>" $5 "</td><td class='fec'>"$8,$7,$10"</tr>"} \
- ;'
- # restauramos el IFS primitivo
- IFS=$oldIFS
- fi
- echo "</table>"
- echo "</div>"
- echo "</body>"
- echo "</html>"
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement