diff --git a/roles/copr/backend/files/lighttpd/lighttpd.conf b/roles/copr/backend/files/lighttpd/lighttpd.conf index 60c50d82ee..a235bc5b76 100644 --- a/roles/copr/backend/files/lighttpd/lighttpd.conf +++ b/roles/copr/backend/files/lighttpd/lighttpd.conf @@ -80,8 +80,17 @@ server.modules = ( "mod_access", "mod_setenv", "mod_redirect", + "mod_indexfile", + "mod_cgi" ) +cgi.assign = ( ".pl" => "/usr/bin/perl", + ".cgi" => "/usr/bin/perl", + ".rb" => "/usr/bin/ruby", + ".erb" => "/usr/bin/eruby", + ".py" => "/usr/bin/python", + ".php" => "/usr/bin/php" ) + ## ####################################################################### @@ -302,8 +311,8 @@ server.max-connections = 1024 ## index-file.names = ( "index.php", "index.rb", "index.html", ## "index.htm", "default.htm" ) ## -index-file.names += ( - "index.xhtml", "index.html", "index.htm", "default.htm", "index.php" +index-file.names = ( + "/dir-generator.php" ) ## diff --git a/roles/copr/backend/files/lighttpd/lighttpd_dev.conf b/roles/copr/backend/files/lighttpd/lighttpd_dev.conf index 2c19f67fbc..ba3d6b7482 100644 --- a/roles/copr/backend/files/lighttpd/lighttpd_dev.conf +++ b/roles/copr/backend/files/lighttpd/lighttpd_dev.conf @@ -80,8 +80,17 @@ server.modules = ( "mod_access", "mod_setenv", "mod_redirect", + "mod_indexfile", + "mod_cgi" ) +cgi.assign = ( ".pl" => "/usr/bin/perl", + ".cgi" => "/usr/bin/perl", + ".rb" => "/usr/bin/ruby", + ".erb" => "/usr/bin/eruby", + ".py" => "/usr/bin/python", + ".php" => "/usr/bin/php" ) + ## ####################################################################### @@ -302,8 +311,8 @@ server.max-connections = 1024 ## index-file.names = ( "index.php", "index.rb", "index.html", ## "index.htm", "default.htm" ) ## -index-file.names += ( - "index.xhtml", "index.html", "index.htm", "default.htm", "index.php" +index-file.names = ( + "/dir-generator.php" ) ## diff --git a/roles/copr/backend/tasks/main.yml b/roles/copr/backend/tasks/main.yml index 1214cc4525..67df17ef79 100644 --- a/roles/copr/backend/tasks/main.yml +++ b/roles/copr/backend/tasks/main.yml @@ -22,6 +22,7 @@ - python-glanceclient - python-neutronclient - python-keystoneclient + - php-cli - name: make copr dirs file: state=directory path={{ item }} @@ -98,6 +99,9 @@ notify: - restart lighttpd +- name: install custom lighttpd template for directory listings + template: src="lighttpd/dir-generator.php.j2" dest="/var/lib/copr/public_html/dir-generator.php" owner=copr group=copr mode=0755 + - name: start webserver service: state=started enabled=yes name=lighttpd diff --git a/roles/copr/backend/templates/lighttpd/dir-generator.php.j2 b/roles/copr/backend/templates/lighttpd/dir-generator.php.j2 new file mode 100755 index 0000000000..53f2964ddb --- /dev/null +++ b/roles/copr/backend/templates/lighttpd/dir-generator.php.j2 @@ -0,0 +1,449 @@ +" . $path . " is not a valid path."); +} + + +// +// Get the size in bytes of a folder +// +function foldersize($path) { + $size = 0; + if($handle = @opendir($path)){ + while(($file = readdir($handle)) !== false) { + if(is_file($path."/".$file)){ + $size += filesize($path."/".$file); + } + + if(is_dir($path."/".$file)){ + if($file != "." && $file != "..") { + $size += foldersize($path."/".$file); + } + } + } + } + + return $size; +} + + +// +// This function returns the file size of a specified $file. +// +function format_bytes($size, $precision=0) { + $sizes = array('B', 'B', 'E', 'P', 'B', 'G', 'M', 'K', 'B'); + $total = count($sizes); + + while($total-- && $size > 1024) $size /= 1024; + return sprintf('%.'.$precision.'f', $size).$sizes[$total]; +} + + +// +// This function returns the mime type of $file. +// +function get_file_type($file) { + global $image_types, $movie_types; + + $pos = strrpos($file, "."); + if ($pos === false) { + return "Text File"; + } + + $ext = rtrim(substr($file, $pos+1), "~"); + if(in_array($ext, $image_types)) { + $type = "Image File"; + + } elseif(in_array($ext, $movie_types)) { + $type = "Video File"; + + } elseif(in_array($ext, $archive_types)) { + $type = "Compressed Archive"; + + } elseif(in_array($ext, $document_types)) { + $type = "Type Document"; + + } elseif(in_array($ext, $font_types)) { + $type = "Type Font"; + + } else { + $type = "File"; + } + + return(strtoupper($ext) . " " . $type); +} + + + +// Print the heading stuff +$vpath = ($path != "./")?$path:""; +print " +
+".$item." | "; + } else { + print "".$item." | "; + } +} +print "||
---|---|---|---|
../ | "; + print ""; + print " | "; + print " | Directory |
" .htmlentities($folder['name']). "/ | "; + print "" . date('Y-M-d H:m:s', $folder['modtime']) . " | "; + print "" . (($calculate_folder_size)?format_bytes($folder['size'], 2):'--') . " | "; + print "" . $folder['file_type'] . " |
" .htmlentities($file['name']). " | "; + print "" . date('Y-M-d H:m:s', $file['modtime']) . " | "; + print "" . format_bytes($file['size'],2) . " | "; + print "" . $file['file_type'] . " |