paferafileserver

Crates.iopaferafileserver
lib.rspaferafileserver
version1.9.4
sourcesrc
created_at2023-04-18 06:55:55.296719
updated_at2024-11-01 16:30:55.872695
descriptionActix based HTML file manager designed for easy browsing of your filesystem, especially for Termux on Android
homepagehttps://pafera.com/
repositoryhttps://codeberg.org/pafera/paferafileserver
max_upload_size
id842227
size393,570
Pafera Technologies (pafera)

documentation

https://pafera.com/blog/1b9m21/2023/04/19/doessharingfileswithafriendhavetobesohard.en.html

README

PaferaFileServer: The Little File Server That Could

Version 1.9.4 By Jim Yu (me@pafera.com)

Released under the GPL 3+

Updates

The 1.9.4 version added

  • Updated cargo packages to latest versions

  • In slideshow view, you can now launch an image editor by pressing the "e" key. Set "imageeditor" to the path of your editor in paferafileserver.cfg, and "imageeditorargs" as a list of arguments to pass to the editor such as the following on OSX to launch GIMP

    "imageeditor": "open", "imageeditorargs": [ "-a", "gimp" ],

The 1.9.3 version added

  • Updated cargo packages to latest versions

  • Added "select to here" button for quicker selection process.

  • Added hotkey "f" to slideshow view to copy the current file to a folder called "Favorites" in the server root.

The 1.9.2 version added

  • Added support for running as an AppImage by using /tmp for the thumbnails directory.

The 1.9.1 version added

  • Changed popup menu background to black for more contrast.

  • Bug fixes for interoperability with the new Flutter Pafera Share app for iOS and Android. If you're willing to be a beta tester, please send me an email.

  • Bug fixes for rsync with special characters.

The 1.9.0 version added

  • Simple access control. Instead of one password for the entire system, now you can set read, write, and shell passwords individually to allow finer access to your system.

  • Added disablesshkeycheck for roaming IPs.

The 1.8.0 version added

  • Changed shared data from RwLock to channels to prevent blocking issues while running long rsyncs.

  • Changed thumbnail algorithms to try native rust solutions before resorting to ImageMagick and ffmpeg for faster performance.

    If your system does not have a copy of libffmpegthumbnailer already installed like Windows, please compile the library or comment out the used lines.

The 1.7.1 version added

  • Added the update flag to rsync to only sync newer versions of files.

The 1.7.0 version added

  • Added option to autorun tasks in intervals from one minute to 60 minutes. This lets you do stuff like have your phone automatically upload any new photos whenever you join your home WiFi network, or run any command from your web browser for easy system maintenance.

    The tasks are defined in paferafileservertasks.cfg and look like this.

    { "tasks": [ { "autosyncminutes": 1, "command": [], "flags": 0, "hostname": "JimsMacBookAir", "log": [], "nextsynctime": 1695614027, "password": "9999", "syncfolderpath": "/shared", "title": "JimsMacBookAir - /shared" } }

    Set flags to 2 if you constantly switch IP addresses as I do when I'm traveling. That will skip ssh's key check and enable syncing on autodiscovery for any network for known hostnames.

  • Added discovery button to quickly open other servers on the same network. This same interface also lets you run tasks for each server.

The 1.6.3 version added

  • Added option to show files only when logged in so that the server can be used on public networks such as cafes and airports.

The 1.6.2 version added

  • Allowed filenames with special URL characters

The 1.6.1 version added

  • Updated all dependencies to latest versions

The 1.6 version added

  • Support for ffmpegthumbnailer to enable faster video thumbnails. Just set enableffmpegthumbnailer on the command line or paferafileserver.cfg.

The 1.5.1 version added

  • Bug fix for file uploads on Mac OSX

The 1.5 version added

  • QR Code button: Now instead of typing an URL, your tech illiterate friends can just use their camera to connect instead.

  • Mac OSX support: Much faster than waiting for Finder to create thumbnails, and usable from any device with a browser. Make sure to enable Remote Login in Settings and password less login with ssh-copy-id if you want to use rsync transfers.

  • Open With: Using the server to browse items on your own computer (127.0.0.1) now lets you open your files in the program of your choice. List such programs in paferafileserver.cfg such as

    {
      "openwith": [
        {
          "title":      "MPV",
          "path":       "/usr/bin/mpv",
          "args":       ["-fs"],
          "extensions": "videos"
        },
        {
          "title":      "GIMP",
          "path":       "/usr/bin/gimp",
          "args":       [],
          "extensions": "images"
        },
        {
          "title":      "Sublime",
          "path":       "/opt/sublime_text/sublime_text",
          "args":       [],
          "extensions": "c cpp php py rs"
        },
        {
          "title":      "Hex Editor",
          "path":       "/usr/bin/ghex",
          "args":       [],
          "extensions": "all"
        },
      ]
    }
    

    Extensions can be one of the file classes used for CSS highlighting, a list of space separated file extensions, or simply "all" to open every file on the system.

    For launching GUI apps on Mac OSX, use the open command such as

    {
      "title":      "VLC",
      "path":       "open",
      "args":       ["-a", "VLC"],
      "extensions": "videos"
    },
    

    For opening all files with its associated app on Linux, you can use

    {
      "title":      "Open with default",
      "path":       "xdg-open",
      "args":       [],
      "extensions": "all"
    },
    

    To do the same in Windows

    {
      "title":      "Open with default",
      "path":       "explorer",
      "args":       [],
      "extensions": "all"
    },
    

    And for OSX

    {
      "title":      "Open with default",
      "path":       "open",
      "args":       [],
      "extensions": "all"
    },
    

    If this is the only open handler and you switch "One Click Open" on, then it's almost like working with a native file manager in that you can just click to open any file on the system.

    Of course, Android has no equivalent since termux-open doesn't quite work on my phone yet, but we can't have everything we want, can we?

The 1.4 version added

  • Rsync support
  • Transcoding
  • Compressing and decompressing archives
  • Running shell commands inside the current folder

Introduction

Due to the complexity of the interface, I have written an entire article detailing this server app at https://pafera.com/blog/2023/04/18/doessharingfileswith.en.html

Small and quick HTTP file server designed for use on Android Termux so that you can quickly share files on your phone to your friends just by having them connect to your hotspot or IP address if you're on the same wireless network.

It also includes directory search, recursive directory search, a slideshow viewer, and a recursive slideshow viewer with hotkeys and swipe gesture support capable of handling hundreds of thousands of files with ease. Instances running on separate devices can also detect other servers and send files to each other just by clicking on the server name and entering the password.

Being written in Rust and using minimal scripting with a mini version of the Pafera Framework, I've found this browser based slide show to be almost as fast as native image viewers, and much faster than Windows Explorer... not that being faster than Explorer is much of a bar to clear.

The JavaScript based image viewer can be started by tapping on an image. Swipe left and right to change images, up to rename this image to imagefile.deleted for later house cleaning, and swipe down to exit the viewer and return to the directory listing. The up, down, left, and right arrow keys on the keyboard will do the exact same actions as swiping in those directions.

Image and video thumbnail generation requires ImageMagick's convert and ffmpeg to be installed on your Termux installation. Of course, this server will also work for any Linux or Windows system where those two programs are installed.

Note that for security reasons, this server will not actually delete any files. It will simply append ".deleted" to the filename so that you can restore accidentally deleted files at a later time just by removing the ".deleted" extension or selecting "Undelete" from the menu.

If you really want to delete a file, then you can delete a file twice or select "Permanent Delete" from the menu. Be careful with this option.

Hotkeys

Hotkeys are supported for most functions as given:

Normal View

v Change view style
i Show hidden files
s Sort files
a Select all
n Select none
r Rename selected files
m Move selected files
c Copy selected files
d Delete selected files
p Permanently delete selected files
u Undelete selected files
e Show recently changed files
t Search this folder
f Search this folder and any subfolders
w Set password
o Create new subfolder
z Start slide show
x Start deep slide show
h Show this hotkeys help

Slide Show View

Left Arrow Previous image
Right Arrow Next image
Up Arrow Delete image
Down Arrow/Escape Exit slide show
r Random image
g Go to image number
q Rotate 90 degrees counterclockwise
e Rotate 90 degrees clockwise

Command line usage:

paferafileserver [hostname=localhost] [serverroot=/home/jim] [password=password] [ip=0.0.0.0]
  [port=9999]

If you wanted to serve Jim's Pictures directory to all visitors on port 5000, you would use

paferafileserver serverroot=/home/jim/Pictures port=5000

If you don't specify serverroot, it will default to your home directory.

If you don't specify ip and port, it will default to 0.0.0.0:9999.

Additionally, the following options can be typed on the command line to disable certain functionality even if the user has the right password.

  • disabledelete
  • disablerename
  • disablemove
  • disablecopy
  • disablenewfolder
  • disabledelete
  • disablepermanentdelete
  • disablesend
  • disableupload

All command line arguments can also be specified in a JSON file called paferafileserver.cfg such as

{
  "hostname":               "JimsLaptop",
  "password":               "SecretPassword12345",
  "disabledelete":          1,
  "disablepermanentdelete": 1
}

For Android 5 and 6, Termux won't run since it requires 7 and above, so we must install UserLand's Debian distribution instead. It is quite a bit more complicated than Termux, but is still better than not being able to run Linux programs at all.

Once you have installed Userland and Debian, type

sudo apt install imagemagick ffmpeg iproute2 openssl

If you want to build from source, you'll also need

sudo apt install curl build-essential gcc make libssl-dev pkg-config

and change the image thumbnail code to call "convert" instead of "magick" "convert" since Debian's Imagemagick does not have the magick executable yet.

You can find your phone's filesystem under /host-rootfs, thus if you want to serve your SD card, you could use

paferafileserver serverroot=/host-rootfs/storage/emulated/legacy

Installation

The main source repository is at

https://codeberg.org/pafera/paferafileserver

Prebuilt binaries for Linux, Termux, and Windows can be found at

https://codeberg.org/pafera/paferafileserver/src/branch/main/bin

Contributing

All contributions are welcome, no matter how large or small. The current server is enough for my personal purposes, but off of the top of my head, some further improvements could be:

  • Sending files to a selectable destination directory instead of /Received
  • Translations for different languages

As always, have fun using this server, and I hope that it will be useful to you in some way! Much appreciation to all of the folks who have contributed to Rust, Cargo, crates.io, Actix, and the rest of the code used in this project.

Commit count: 0

cargo fmt