Advertisement
Guest User

Untitled

a guest
Jun 29th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.00 KB | None | 0 0
  1. #!/bin/sh
  2. # 2014 :P raphik
  3. tDirVid="/tmp/pruebas/video"
  4. tDirAud="/tmp/pruebas/audio"
  5. tDirFot="/tmp/pruebas/foto"
  6. tDirDes="/tmp/pruebas/descargas"
  7. echo -e "Content-type:text/html\n\n"
  8. read -t 1 cadena
  9. # Si no se le pasan argumentos se visualiza, por defecto, la carpeta Video ordenada por Nombre
  10. if [ ! "$cadena" ] ; then
  11.   cadena="VidNom=VidNom"
  12. fi
  13. # Si se ha pulsado el botón "Borrar"
  14. if [ ${cadena:7:6} == "Borrar" ]; then
  15.   # Selecciona el directorio en el que están los ficheros que se borrarán
  16.   vCar=${cadena:0:3}
  17.   case $vCar in
  18.     Vid)  tDir=$tDirVid;;
  19.     Aud)  tDir=$tDirAud;;
  20.     Fot)  tDir=$tDirFot;;
  21.     Des)  tDir=$tDirDes;;
  22.   esac
  23.   # OPERACIONES DE BORRADO
  24.   cadena=$(echo -e $cadena | sed 's/%0D%0A//g; s/%C2%A0/\\x20/g; s/%/\\x/g')
  25.   oldIFS=$IFS
  26.   IFS=' &'
  27.   for line in ${cadena:14}
  28.   do
  29.   x=$(echo -e ${line:7})
  30.   rm "$tDir/$(echo -e ${line:7})"
  31.   done
  32.   IFS=$oldIFS
  33.   # Misma carpeta, mismo orden
  34.   cadena="${cadena:0:6}=${cadena:0:6}"
  35. fi
  36. # Nueva carpeta, nuevo orden
  37. cadena="${cadena:7:6}=${cadena:7:6}"
  38.  
  39. tClassFichaVid='fichaIna'; tClassFichaAud='fichaIna'; tClassFichaFot='fichaIna'; tClassFichaDes='fichaIna'
  40. vCar=${cadena:0:3}
  41. case $vCar in
  42.   Vid)  tDir=$tDirVid; tClassFichaVid='fichaAct';;
  43.   Aud)  tDir=$tDirAud; tClassFichaAud='fichaAct';;
  44.   Fot)  tDir=$tDirFot; tClassFichaFot='fichaAct';;
  45.   Des)  tDir=$tDirDes; tClassFichaDes='fichaAct';;
  46. esac
  47.  
  48. tNom='Nombre'; tTam='Tamaño'; tFec='Fecha'
  49. vOrd=${cadena:3:3}
  50. case $vOrd in
  51.   Nom)  tNom='↑ Nombre ↑'; tOrd='-leh';;
  52.   Tam)  tTam='↓ Tamaño ↓'; tOrd='-lehS';;
  53.   Fec)  tFec='↓ Fecha ↓'; tOrd='-leht';;
  54. esac
  55.  
  56. x=$(ls $tOrd $tDir)
  57.  
  58. # Cálculos de espacio
  59. tEspDisco=$(df -h $tDir | sed -n 2p | awk '{print $2}')
  60. nEspDisco=$(df $tDir | sed -n 2p | awk '{print $2}')
  61. nEspLibre=$(df $tDir | sed -n 2p | awk '{print $4}')
  62. nEspCarpeta=$(du -sx $tDir | awk '{print $1}')
  63. nPorcentajeLibre=$(( $nEspLibre * 100 / $nEspDisco ))
  64. nPorcentajeCarpeta=$(( $nEspCarpeta * 100 / $nEspDisco ))
  65. nPorcentajeOtras=$(( 100 - nPorcentajeLibre - nPorcentajeCarpeta ))
  66.  
  67. echo "<html><meta charset='utf-8'><head><title>PRUEBA</title>"
  68. echo "<style type='text/css'>"
  69. echo "table { border-collapse:collapse; width:100%}"
  70. echo "tr.ficha { text-align:center;}"
  71. 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;}"
  72. echo "td.fichaAct { color:Black; background-color:PaleTurquoise; cursor:default;}"
  73. echo "td.fichaIna { color:Black; background-color:CadetBlue; cursor:pointer;}"
  74. echo "td.fichaIna:hover { color:Black; background-color:MediumTurquoise;}"
  75.  
  76. echo "caption { color:black; background-color:PaleTurquoise; text-align:center; padding:15px 25px 0px 25px;}"
  77. echo "span.lib { color:LightSalmon;}"
  78. echo "span.car { color:HotPink;}"
  79. echo "span.otr { color:Purple;}"
  80. echo "div.lib { background-color:LightSalmon;}"
  81. echo "div.car { background-color:HotPink;}"
  82. echo "div.otr { background-color:Purple; height:10px;}"
  83. echo "tr.cab { background-color:PaleTurquoise;}"
  84. echo "input.cab { width: 100%;}"
  85. echo "button { width:100%;}"
  86. echo "tr.dhi { color:black; background-color:LightCyan;}"
  87. echo "tr.dlo { color:black; background-color:PaleTurquoise;}"
  88. echo "td.bor { text-align:right; padding:0px 15px 0px 15px;}"
  89. echo "td.nom { text-align:left; padding:0px 15px 0px 15px;}"
  90. echo "td.tam { text-align:right; padding:0px 15px 0px 15px;}"
  91. echo "td.fec { text-align:right; padding:0px 15px 0px 15px;}"
  92. echo "</style>"
  93. echo "</head>"
  94.  
  95. echo "<body>"
  96. echo "<div align=left style='margin:0px 50px auto;'>"
  97. #    4 FICHAS
  98. echo "<form id='id_fCar' action='' method='POST'><input id='id_iCar' type='hidden' name=$vCar$vOrd></form>"
  99.  
  100. echo "<table><tr class='ficha'>"
  101. echo "<td class='ficha $tClassFichaVid' onclick='document.getElementById(\"id_iCar\").value=\"Vid$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Video</td>"
  102. echo "<td class='ficha $tClassFichaAud' onclick='document.getElementById(\"id_iCar\").value=\"Aud$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Audio</td>"
  103. echo "<td class='ficha $tClassFichaFot' onclick='document.getElementById(\"id_iCar\").value=\"Fot$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Foto</td>"
  104. echo "<td class='ficha $tClassFichaDes' onclick='document.getElementById(\"id_iCar\").value=\"Des$vOrd\"; document.getElementById(\"id_fCar\").submit();'>Descargas</td>"
  105. echo "</tr></table>"
  106.  
  107. echo "<table>"
  108. echo "<caption>"
  109. #     INFO ESPACIO
  110. echo "<div _style='text-align:left'>"
  111. echo "  <span class='lib'>&#9733; </span>Libre: $nPorcentajeLibre% &nbsp;&nbsp;&nbsp;&nbsp;"
  112. echo "  <span class='car'>&#9733; </span>Esta carpeta: $nPorcentajeCarpeta% &nbsp;&nbsp;&nbsp;&nbsp;"
  113. echo "  <span class='otr'>&#9733; </span>Otras carpetas: $nPorcentajeOtras%"
  114. echo "</div>"
  115. #     BARRA DE PORCENTAJES
  116. echo "<div class='otr'  style='position:relative';>"
  117. echo "  <div class='lib' style='position:absolute; left:0px; top:0px; width:$nPorcentajeLibre%; height:100%;'></div>"
  118. echo "  <div class='car' style='position:absolute; left:$nPorcentajeLibre%; top:0px; width:$nPorcentajeCarpeta%; height:100%;'></div>"
  119. echo "</div>"
  120. #     TAMAÑO DEL DISCO
  121. echo "<div _style='text-align:left'>"
  122. echo "<span class='tot'>Tamaño del disco: $tEspDisco</span>"
  123. echo "</div>"
  124. echo "</caption>"
  125. #     4 BOTONES - CABECERA DEL LISTADO
  126. echo "<form id='id_borrar' action='' method='POST'></form>"
  127. echo "<form id='id_fOrd' action='' method='POST'><input id='id_iOrd' type='hidden' name='$vCar$vOrd'></form>"
  128.  
  129. echo "<tr class='cab'>"
  130. 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>"
  131. echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Nom\"; document.getElementById(\"id_fOrd\").submit();'>$tNom</button></td>"
  132. echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Tam\"; document.getElementById(\"id_fOrd\").submit();'>$tTam</button></td>"
  133. echo "<td><button type='submit' onclick='document.getElementById(\"id_iOrd\").value=\"$vCar\Fec\"; document.getElementById(\"id_fOrd\").submit();'>$tFec</button></td>"
  134. echo "</tr>"
  135. #     LÍNEAS DE DETALLE
  136. if [ $nEspCarpeta == 0 ] ; then
  137.   echo "<tr class='dlo' align=center><td colspan=4><h2>LA CARPETA ESTÁ VACÍA</h2></tr></td>"
  138. else
  139. #     reservamos el IFS actual y fijamos uno nuevo para que detecte el final de la línea(HEX '0a')
  140. oldIFS=$IFS
  141. IFS=$'\r'
  142. echo $x | awk '{if(NR%2) print "<tr class='dhi'>"; else print "<tr class='dlo'>";}; \
  143.  {print "<td class='bor' >"NR"<input form='id_borrar' type='checkbox' name='borrar' value=\42"}; \
  144.  {x=substr($0,68); gsub(/ /,"\\&nbsp;",x); print x}; \
  145.  {print "\42></td><td class='nom'>"}; \
  146.  {x=substr($0,68); gsub(/ /,"\\&nbsp;",x); print x}; \
  147.  {print "</td><td class='tam'>" $5 "</td><td class='fec'>"$8,$7,$10"</tr>"} \
  148. ;'
  149. #     restauramos el IFS primitivo
  150. IFS=$oldIFS
  151. fi
  152. echo "</table>"
  153. echo "</div>"
  154. echo "</body>"
  155. echo "</html>"
  156. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement