diff --git a/Images/1.png b/Images/1.png index fc62279..fa6aaef 100644 Binary files a/Images/1.png and b/Images/1.png differ diff --git a/Images/2.png b/Images/2.png index ac674ea..470cc4d 100644 Binary files a/Images/2.png and b/Images/2.png differ diff --git a/Images/3.png b/Images/3.png index 386de4d..8ee6e2b 100644 Binary files a/Images/3.png and b/Images/3.png differ diff --git a/Images/4.png b/Images/4.png index 98fea97..18bc6bb 100644 Binary files a/Images/4.png and b/Images/4.png differ diff --git a/Images/5.png b/Images/5.png index 2005d71..3c3ffcc 100644 Binary files a/Images/5.png and b/Images/5.png differ diff --git a/README.md b/README.md index d21c627..7207984 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ WebFM is a media and file viewer. 2. Use php -S 0.0.0.0:yourDesiredPort 3. Use ufw or gufw to open the port on your computer to the network. 4. Place files or start uploading some to the folders. +5. Single clic icons and thumbnails to open files. +6. Double click the text name to change the file's or folder's name and press enter to set it. +7. Right-click to get context menu options. Notes: 1. Folders and files CAN NOT have & or ' in the names. Otherwise, you can't access that item with the viewer. @@ -14,7 +17,6 @@ Notes: 4. The media and image pane can be moved by dragging from the transparentish bar that has the close button and other controls. 5. Edit the resources/php/config.php file and put your own programs there. - # TO-DO 1. Allow for move, copy, delete functionality. 2. Allow for creating folders through the web interface. @@ -23,9 +25,7 @@ Notes: 5. Impliment themes functionality. 6. Look to refactor code. - # Images - ![1 Home](Images/1.png) ![2 Images Listed](Images/2.png) ![3 Image Open](Images/3.png) diff --git a/index.html b/index.html index 2a743d3..1844e63 100644 --- a/index.html +++ b/index.html @@ -7,20 +7,22 @@ - +

- - - - - + + +
+
+ + +
    Path:  

@@ -35,8 +37,18 @@ + + + + + + + + - - + + + + diff --git a/resources/css/main.css b/resources/css/main.css index 00a2fe8..9517dfa 100644 --- a/resources/css/main.css +++ b/resources/css/main.css @@ -101,17 +101,41 @@ .movieStyle { float: left; width: 15em; - height: 10em; + height: 8.5em; overflow: hidden; margin: 0.5em; padding: 0.5em; } -.movieTitle { - width: 15em; +.dirTitle, .fileTitle, .movieTitle { white-space: nowrap; text-overflow: ellipsis; + text-align: center; overflow: hidden; + border-style: none; + font-size: 75%; +} + +.dirTitle, .fileTitle { + width: auto; + background-color: #00000000; + color: #ffffff; +} + +.movieTitle { + width: 18em; + background-color: #ffffff00; + color: #ffffff; +} + +.thumbnail { + width: 12em; + height: 6.5em; +} + +.systemIcon { + width: 2em; + height: auto; } .iconImg { @@ -136,7 +160,10 @@ /* Hover events */ -.closeBttn:hover, .popOutBttn:hover { +.dirTitle:hover, +.iconImg:hover, +.closeBttn:hover, +.popOutBttn:hover { cursor: pointer; } @@ -151,8 +178,6 @@ clear: both; } -.errorStyling { background-color: rgb(255,0,0); } - .error { color: rgb(255, 0, 0); } .warnning { color: rgb(255, 168, 0); } .success { color: rgb(136, 204, 39); } diff --git a/resources/images/icons/arc.png b/resources/images/icons/arc.png new file mode 100644 index 0000000..3c28050 Binary files /dev/null and b/resources/images/icons/arc.png differ diff --git a/resources/images/icons/bin.png b/resources/images/icons/bin.png new file mode 100644 index 0000000..2cc77a0 Binary files /dev/null and b/resources/images/icons/bin.png differ diff --git a/resources/images/icons/doc.png b/resources/images/icons/doc.png new file mode 100644 index 0000000..213a43d Binary files /dev/null and b/resources/images/icons/doc.png differ diff --git a/resources/images/icons/folder.png b/resources/images/icons/folder.png new file mode 100644 index 0000000..0108b21 Binary files /dev/null and b/resources/images/icons/folder.png differ diff --git a/resources/images/icons/html.png b/resources/images/icons/html.png new file mode 100644 index 0000000..3010f33 Binary files /dev/null and b/resources/images/icons/html.png differ diff --git a/resources/images/icons/img.png b/resources/images/icons/img.png new file mode 100644 index 0000000..d41e7a2 Binary files /dev/null and b/resources/images/icons/img.png differ diff --git a/resources/images/icons/pdf.png b/resources/images/icons/pdf.png new file mode 100644 index 0000000..0876aaa Binary files /dev/null and b/resources/images/icons/pdf.png differ diff --git a/resources/images/icons/scrip.png b/resources/images/icons/scrip.png new file mode 100644 index 0000000..7310250 Binary files /dev/null and b/resources/images/icons/scrip.png differ diff --git a/resources/images/icons/text.png b/resources/images/icons/text.png new file mode 100644 index 0000000..90ded78 Binary files /dev/null and b/resources/images/icons/text.png differ diff --git a/resources/js/ajax.js b/resources/js/ajax.js index ee60156..e915fe9 100644 --- a/resources/js/ajax.js +++ b/resources/js/ajax.js @@ -81,10 +81,12 @@ function updatePage(returnData) { var dir = dirs[i].innerHTML; if (dir != "resources/") { - insertArea.innerHTML += "
" - + dir - + ""; + insertArea.innerHTML += "
" + + "" + +""; } } @@ -92,28 +94,29 @@ function updatePage(returnData) { size = videos .length; for (i = 0; i < size; i++) { var thumbnail = videos[i].children[0].innerHTML; - var videoPth = videos[i].children[1].innerHTML; - var vidNme = videos[i].children[2].innerHTML; + var vidNme = videos[i].children[1].innerHTML; - insertArea.innerHTML += "" - + "\""" - + "

" + vidNme + "

" + insertArea.innerHTML += "" + + "\""" + + "" + ""; } // Insert images - size = images.length; + var path = document.getElementById("path").innerHTML; + size = images.length; + for (i = 0; i < size; i++) { var thumbnail = images[i].children[0].innerHTML; - var imgTitle = images[i].children[1].innerHTML; - if (!imgTitle.includes("favicon.png") && !imgTitle.includes("000.png") && - !imgTitle.includes("000.jpg") && !imgTitle.includes("000.gif")) { - insertArea.innerHTML += "\"""; + if (!thumbnail.includes("favicon.png") && !thumbnail.includes("000.png") && + !thumbnail.includes("000.jpg") && !thumbnail.includes("000.gif")) { + insertArea.innerHTML += "\"""; } } @@ -121,20 +124,52 @@ function updatePage(returnData) { if (images[0].children[0].innerHTML.includes("000.jpg") || images[0].children[0].innerHTML.includes("000.png") || images[0].children[0].innerHTML.includes("000.gif")) { - updateBG(images[0].children[0].innerHTML); - } else { updateBG("resources/images/backgrounds/000.jpg"); } - } else { updateBG("resources/images/backgrounds/000.jpg"); } + updateBG(path + images[0].children[0].innerHTML); + } else { + updateBG("resources/images/backgrounds/000.jpg"); + } + } else { + updateBG("resources/images/backgrounds/000.jpg"); + } // Insert files size = files.length; for (i = 0; i < size; i++) { - var filePath = files[i].children[0].innerHTML; - var fileName = files[i].children[1].innerHTML + var fileName = files[i].children[0].innerHTML; + var iconImg = ""; + } else if (fileName.includes(".7z") || fileName.includes(".7zip") || + fileName.includes(".zip") || fileName.includes(".tar.gz") || + fileName.includes(".tar.xz") || fileName.includes(".gz") || + fileName.includes(".rar") || fileName.includes(".jar")) { + iconImg += " src=\"resources/images/icons/arc.png\" />"; + } else if (fileName.includes(".pdf")) { + iconImg += " src=\"resources/images/icons/pdf.png\" />"; + } else if (fileName.includes(".html")) { + iconImg += " src=\"resources/images/icons/html.png\" />"; + } else if (fileName.includes(".txt") || fileName.includes(".conf")) { + iconImg += " src=\"resources/images/icons/text.png\" />"; + } else if (fileName.includes(".iso") || fileName.includes(".img")) { + iconImg += " src=\"resources/images/icons/img.png\" />"; + } else if (fileName.includes(".sh") || fileName.includes(".batch") || + fileName.includes(".exe")) { + iconImg += " src=\"resources/images/icons/scrip.png\" />"; + } else { + iconImg += " src=\"resources/images/icons/bin.png\" />"; + } if (fileName != "sse.php" && fileName != "upload.php" && fileName != "open.php" && fileName != "process.php") { - insertArea.innerHTML += "
" + fileName + ""; + insertArea.innerHTML += "
" + + iconImg + + "" + + ""; } } } diff --git a/resources/js/controlers.js b/resources/js/controlers.js deleted file mode 100644 index 560c517..0000000 --- a/resources/js/controlers.js +++ /dev/null @@ -1,82 +0,0 @@ -function showImg(imgLoc) { - var imgView = document.getElementById("imgView"); - var toPlayerButton = "
"; - var popButton = "
"; - var CloseBttn = "
X
"; - - imgView.style.display = "block"; - imgView.innerHTML = CloseBttn + popButton + toPlayerButton; - imgView.innerHTML += "
"; - - dragContainer(imgView); // Set for dragging events -} - -function showMedia(media) { - var tempRef = media.toLowerCase(); - if (tempRef.includes(".mkv") || tempRef.includes(".avi") || tempRef.includes(".flv") || - tempRef.includes(".mov") || tempRef.includes(".m4v") || tempRef.includes(".mpg") || - tempRef.includes(".wmv") || tempRef.includes(".mpeg") || tempRef.includes(".psf")) { - openInLocalProg(media); - } else { - var mediaView = document.getElementById("fileView"); - var toPlayerButton = "
"; - var popButton = "
"; - var CloseBttn = "
X
"; - - mediaView.style.display = "block"; - mediaView.innerHTML = CloseBttn + popButton + toPlayerButton; - mediaView.innerHTML += ""; - - dragContainer(mediaView); // Set for dragging events - } -} - -function openInLocalProg(media) { - var xhttp = new XMLHttpRequest(); - - xhttp.open("POST", "resources/php/open.php", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("media=" + media); -} - -function tgglServerMsgView() { - var serverMsgView = document.getElementById("toggleServerMsg"); - if (serverMsgView.style.display == "none") { - serverMsgView.style.display = "block"; - } else { - serverMsgView.style.display = "none"; - } -} - -function closeImg() { - var imgView = document.getElementById("imgView"); - imgView.style.display = "none"; -} - -function closeMedia() { - var mediaView = document.getElementById("fileView"); - mediaView.style.display = "none"; - mediaView.children[3].src = ""; -} - -function clearDirCookie() { - var expireDate = "Thu, 01 Jan 1970 00:00:00 UTC"; - document.cookie = "dirQuery=; expires=" + expireDate; - location.reload(); -} - -function onloadSetBG() { updateBG("resources/images/backgrounds/000.jpg"); } -function updateBG(bgImg) { document.getElementById("bg").src = bgImg; } - - -// SSE events if supported -if(typeof(EventSource) !== "undefined") { - var source = new EventSource("resources/php/sse.php"); - source.onmessage = function(event) { - if (event.data === "updateListing") { - getDirSSE(); - } - }; -} else { - console.log("SSE Not Supported In Browser..."); -} diff --git a/resources/js/dragContainer.js b/resources/js/dragContainerEvents.js similarity index 100% rename from resources/js/dragContainer.js rename to resources/js/dragContainerEvents.js diff --git a/resources/js/fileSystemControls.js b/resources/js/fileSystemControls.js new file mode 100644 index 0000000..0737ad9 --- /dev/null +++ b/resources/js/fileSystemControls.js @@ -0,0 +1,128 @@ +var formerFileName = ""; + +function showImg(imgLoc) { + var path = document.getElementById("path").innerHTML; + var imgView = document.getElementById("imgView"); + var fullImage = path + imgLoc; + var toPlayerButton = "
"; + var popButton = "
"; + var CloseBttn = "
X
"; + imgView.style.display = "block"; + imgView.innerHTML = CloseBttn + popButton + toPlayerButton; + + imgView.innerHTML += "
"; + dragContainer(imgView); // Set for dragging events +} + +function showMedia(media) { + var path = document.getElementById("path").innerHTML; + var tempRef = media.toLowerCase(); + var fullMedia = path + media; + + if (tempRef.includes(".mp4") || tempRef.includes(".webm") || + tempRef.includes(".mp3") || tempRef.includes(".ogg") || + tempRef.includes(".pdf") || tempRef.includes(".flac")) { + var mediaView = document.getElementById("fileView"); + var toPlayerButton = "
"; + var popButton = "
"; + var CloseBttn = "
X
"; + + mediaView.style.display = "block"; + mediaView.innerHTML = CloseBttn + popButton + toPlayerButton; + mediaView.innerHTML += ""; + + dragContainer(mediaView); // Set for dragging events + } else { + openInLocalProg(fullMedia); + } +} + +function openInLocalProg(media) { + var xhttp = new XMLHttpRequest(); + + xhttp.open("POST", "resources/php/open.php", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("media=" + media); +} + +function enableEdit(obj) { + obj.style.backgroundColor = "#ffffffff"; + obj.style.color = '#000000ff'; + obj.readOnly = ''; + formerFileName = obj.value; +} + +function disableEdits(obj) { + obj.style.backgroundColor = "#ffffff00"; + obj.style.color = '#ffffff'; + obj.value = formerFileName; + obj.readOnly = "true"; +} + +function renameItem(obj) { + var path = document.getElementById("path").innerHTML; + var oldName = formerFileName; + var newName = obj.value; + var formData = "oldName=" + oldName + "&newName=" + newName + "&path=" + path; + var xhttp = new XMLHttpRequest(); + + console.log("Old name: " + oldName); + console.log("New name: " + newName); + + xhttp.open("POST", "resources/php/rename.php", false); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send(formData); + + getDirSSE(); +} + +function createDir() { + var path = document.getElementById("path").innerHTML; + var newItem = document.getElementById("NewItem").value; + var fullPth = path + newItem; + var xhttp = new XMLHttpRequest(); + + xhttp.open("POST", "resources/php/newFileOrDir.php", false); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("item=" + fullPth + "&isDir=dir"); + getDirSSE(); +} + +function createFile() { + var path = document.getElementById("path").innerHTML; + var newItem = document.getElementById("NewItem").value; + var fullPth = path + newItem; + + var xhttp = new XMLHttpRequest(); + + xhttp.open("POST", "resources/php/newFileOrDir.php", false); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("item=" + fullPth + "&isFile=file"); + getDirSSE(); +} + +function startDeleteItem(item) { + // Get the item name + itemObj = item; +} + +function deleteItem(item) { + var path = document.getElementById("path").innerHTML; + + // Clicked yes to delete and there is an item + if (itemObj != undefined && itemObj != null) { + var fullPth = path + itemObj; + var answer = confirm("Are you sure you want to delete: " + fullPth); + if (answer == true) { + var xhttp = new XMLHttpRequest(); + + xhttp.open("POST", "resources/php/delete.php", false); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("item=" + fullPth); + + console.log("Deleted: " + fullPth); + itemObj = null; + getDirSSE(); + } + } +} diff --git a/resources/js/uiControls.js b/resources/js/uiControls.js new file mode 100644 index 0000000..40e0205 --- /dev/null +++ b/resources/js/uiControls.js @@ -0,0 +1,46 @@ + +function tgglServerMsgView() { + var serverMsgView = document.getElementById("toggleServerMsg"); + if (serverMsgView.style.display == "none") { + serverMsgView.style.display = "block"; + } else { + serverMsgView.style.display = "none"; + } +} + +function closeImg() { + var imgView = document.getElementById("imgView"); + imgView.style.display = "none"; +} + +function closeMedia() { + var mediaView = document.getElementById("fileView"); + mediaView.style.display = "none"; + mediaView.children[3].src = ""; +} + +function clearDirCookie() { + var expireDate = "Thu, 01 Jan 1970 00:00:00 UTC"; + document.cookie = "dirQuery=; expires=" + expireDate; + location.reload(); +} + +function clearDlList() { + document.getElementById("CLEARBTTN").click(); +} + +function onloadSetBG() { updateBG("resources/images/backgrounds/000.jpg"); } +function updateBG(bgImg) { document.getElementById("bg").src = bgImg; } + + +// SSE events if supported +if(typeof(EventSource) !== "undefined") { + var source = new EventSource("resources/php/sse.php"); + source.onmessage = function(event) { + if (event.data === "updateListing") { + getDirSSE(); + } + }; +} else { + console.log("SSE Not Supported In Browser..."); +} diff --git a/resources/js/uiEvents.js b/resources/js/uiEvents.js new file mode 100644 index 0000000..2600787 --- /dev/null +++ b/resources/js/uiEvents.js @@ -0,0 +1,49 @@ +// ondblclick +document.onclick = function (event) { + var obj = event.target; + var callingID = obj.id; + var classNM = obj.className; + + // Left click detect + if (event.which == 1) { + if (callingID == "dirID") { + var node = obj.parentNode; + getDir(node.children[1].value); + } else if (callingID == "movieID") { + var node = obj.parentNode; + showMedia(node.children[1].value); + } else if (callingID == "fileID") { + var node = obj.parentNode; + showMedia(node.children[1].value); + } else if (callingID == "imageID") { + showImg(obj.alt); + } else if (callingID == "titleID") { + enableEdit(obj); + } + // Right click detect + } else if (event.which == 3) { + if (callingID == "imageID") { + startDeleteItem(obj.alt); + } else if (callingID == "dirID" || callingID == "fileID" || + callingID == "movieID") { + var node = obj.parentNode; + startDeleteItem(node.children[1].value); + } else if (classNM == "fileStyle" || classNM == "dirStyle" || + classNM == "movieStyle") { + startDeleteItem(obj.children[1].value); + } + } +} + +document.onkeydown = function (event) { + var obj = event.target; + var callingID = event.target.id; + var keyCodeVal = event.keyCode; + + // If keycode == Enter + if (keyCodeVal == 13) { + if (callingID == "titleID") { + renameItem(obj); + } + } +} diff --git a/resources/php/delete.php b/resources/php/delete.php new file mode 100644 index 0000000..207de76 --- /dev/null +++ b/resources/php/delete.php @@ -0,0 +1,22 @@ + diff --git a/resources/php/newFileOrDir.php b/resources/php/newFileOrDir.php new file mode 100644 index 0000000..592c5d0 --- /dev/null +++ b/resources/php/newFileOrDir.php @@ -0,0 +1,21 @@ + diff --git a/resources/php/open.php b/resources/php/open.php index 74db9ea..8560229 100644 --- a/resources/php/open.php +++ b/resources/php/open.php @@ -3,19 +3,24 @@ function openFile($FILE) { include 'config.php'; - if (preg_match('(mkv|wmv|mp4|webm|avi|m4v|ogv|flv)', strtolower($FILE)) === 1) { - shell_exec('cd ../../ && ' . $MEDIAPLAYER . ' "' . $FILE . '" &'); - } else if (preg_match('(png|jpg|jpeg|gif)', strtolower($FILE)) === 1) { - shell_exec('cd ../../ && ' . $IMGVIEWER . ' "' . $FILE . '" &'); - } else if (preg_match('(psf|mp3|ogg|flac)', strtolower($FILE)) === 1) { - shell_exec('cd ../../ && ' . $MUSICPLAYER . ' "' . $FILE . '" &'); - } else if (preg_match('(pdf)', strtolower($FILE)) === 1) { - shell_exec('cd ../../ && ' . $PDFVIEWER . ' "' . $FILE . '" &'); + if (preg_match('(.mkv|.avi|.flv|.mov|.m4v|.mpg|.wmv|.mpeg)', strtolower($FILE)) === 1) { + shell_exec($MEDIAPLAYER . " \"" . $FILE . "\" &"); + } else if (preg_match('(.png|.jpg|.jpeg|.gif)', strtolower($FILE)) === 1) { + shell_exec($IMGVIEWER . ' "' . $FILE . '" &'); + } else if (preg_match('(.psf|.mp3|.ogg|.flac)', strtolower($FILE)) === 1) { + shell_exec($MUSICPLAYER . ' "' . $FILE . '" &'); + } else if (preg_match('(.txt)', strtolower($FILE)) === 1) { + shell_exec($TEXTVIEWER . ' "' . $FILE . '" &'); + } else if (preg_match('(.pdf)', strtolower($FILE)) === 1) { + shell_exec($PDFVIEWER . ' "' . $FILE . '" &'); + // Has to be below b/c pdf somehow regesters and an office app.... wtf.... + } else if (preg_match('(.odt|.doc|.docx|.rtf)', strtolower($FILE)) === 1) { + shell_exec($OFFICEPROG . ' "' . $FILE . '" &'); } - } +chdir("../../"); if (isset($_POST["media"])) { openFile($_POST["media"]); } diff --git a/resources/php/process.php b/resources/php/process.php index 83cf4ad..9358550 100644 --- a/resources/php/process.php +++ b/resources/php/process.php @@ -1,40 +1,35 @@ " - . "" . $CLEANPATH . ""; + . "" . $PATH . ""; $dirContents = scandir($PATH); foreach ($dirContents as $fileName) { - $fullPath = $CLEANPATH . $fileName; + $fullPath = $PATH . $fileName; if (is_dir($PATH . $fileName)) { $GeneratedXML .= "" . $fileName . "/"; } elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) { $NAMEHASH = hash('sha256', $fileName); - if (!file_exists('../images/thumbnails/' . $NAMEHASH . '.jpg')) { - shell_exec('../ffmpegthumbnailer -t 65% -s 320 -c jpg -i "' - . $PATH . $fileName . '" -o ../images/thumbnails/' + if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) { + shell_exec('resources/ffmpegthumbnailer -t 65% -s 320 -c jpg -i "' + . $fullPath . '" -o resources/images/thumbnails/' . $NAMEHASH . '.jpg'); } $GeneratedXML .= "" . "/resources/images/thumbnails/" . $NAMEHASH . ".jpg" - . "" . $fullPath . "" . "" . $fileName . "" . ""; } elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) { $GeneratedXML .= "" - . "". $fullPath . "" . "" . $fileName . "" . ""; } else { $GeneratedXML .= "" - . "" . $fullPath . "" . "" . $fileName . "" . ""; } @@ -44,10 +39,11 @@ function dirListing($PATH) { } // Determin action +chdir("../../"); if (isset($_POST['dirQuery'])) { dirListing(trim($_POST['dirQuery'])); } else { - echo "

Error! Illegal Access Method!

"; + echo "

Error! Illegal Access Method!

"; } ?> diff --git a/resources/php/rename.php b/resources/php/rename.php new file mode 100644 index 0000000..3873d26 --- /dev/null +++ b/resources/php/rename.php @@ -0,0 +1,12 @@ + diff --git a/resources/php/sse.php b/resources/php/sse.php index 3cfe746..c1efeb6 100644 --- a/resources/php/sse.php +++ b/resources/php/sse.php @@ -1,13 +1,10 @@ Server: [Warnning] --> This file already exists. Overwriting it."; @@ -55,13 +55,14 @@ function uploadFiles($targetDir) { echo ""; // Prompt an update clint side when sse checks that there is updateListing. - $myfile = fopen("../vars.txt", "wa+"); + $myfile = fopen("../vars.txt", "w+"); $txt = "updateListing"; fwrite($myfile, $txt); fclose($myfile); } // Check access type. +chdir("../../"); if(isset($_POST["UploadFiles"])) { uploadFiles($_POST["DIRPATHUL"]); } else {