Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/caiorss/fserver

Standalone, single-file file sharing web server written in Kotlin and Javalin web framework.
https://github.com/caiorss/fserver

file java kotlin server sharing utility web

Last synced: 8 days ago
JSON representation

Standalone, single-file file sharing web server written in Kotlin and Javalin web framework.

Awesome Lists containing this project

README

        

* FServer - Micro File Sharing Server
** Overview

FServer is a micro file sharing web server for sharing files and
directories on the local network or over the internet. FServer is
easier to modify and maintain as it is written in Kotlin.

*Features*

+ Easier usage, not required any system administration or
complicated configuration files.

+ Single-jar file and zero dependencies.

+ Sharing multiple directories

+ Serve static web sites or any directory containing an index.html file.

+ File upload

+ Hide/display pictures

+ Optional: session/based and form-based authentication.

+ Image thumbnail of PDF files, requires --pdf
command line switch. [EXPERIMENTAL]

+ Response web page layout which makes it mobile-friendly and
usable from tablets and smartphones.

*Implementation*

+ Written in Kotlin for JVM (Java Virtual Machine)

+ Build System: Gradle + Gradle-Kotlin DSL

*Libraries Used*

+ Web Framework:
+ https://javalin.io/

+ Command Line:
+ https://ajalt.github.io/clikt/

+ Logging:
+ http://www.slf4j.org/

+ Toml configuration file:
+ https://github.com/mwanji/toml4j

+ Apache PDFBox library for manipulating and displaying PDF files
+ https://pdfbox.apache.org/

+ Javascript library for pan, zooming and pinching on mobile/touchscreen devices.
+ https://github.com/hammerjs/hammer.js

** Download Binary Release

Binary Releases can be download from:

+ https://github.com/caiorss/fserver/releases/

+ [[https://github.com/caiorss/fserver/releases/download/v0.1/][Release v0.1]] - Artifact: [[https://github.com/caiorss/fserver/releases/download/v0.1/fserver.jsh][fserver.jsh]]

*Example: Donwload and running artifact from command line*

Download artifact:

#+BEGIN_SRC sh
$ curl -O -L https://github.com/caiorss/fserver/releases/download/v0.1/fserver.js
$ chmod +x fserver.jsh
#+END_SRC

Run the server:
+ $ ./fserver.jsh [PARAMETERS] ...
+ $ sh fserver.jsh [PARAMETERS] ...
+ $ java -jar fserver.jsh [PARAMETERS] ...

#+BEGIN_SRC sh
$ sh ./fserver.jsh
Usage: fserver [OPTIONS] COMMAND [ARGS]...

FServer - micro file sharing server

Options:
-h, --help Show this message and exit

Commands:
dir Serve a single directory
mdir Serve multiple directories
config Start server from user-provided configuration file.
test Run server in demonstration mode.
dummy Dummy command
#+END_SRC

Share single directory (current directory):
+ The site will be available in the URL http://localhost:9042 or
~http://:9042/~, in this case:
http://192.165.15.154:9042.

#+BEGIN_SRC sh
$ ./fserver.jsh dir ~/Documents --port=9042
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/

https://javalin.io/documentation

[main] INFO org.eclipse.jetty.util.log - Logging initialized @286ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[INFO] File Web Server URL => http://192.165.15.154:9042
... ... ... ... ...
#+END_SRC

** Example: Serve multiple directories

+ Part 1: Start the server.

+ --port=9025
+ => Server listent to port 9025 (default 9080)

+ --upload
+ => Enable upload which is disabled by default.

+ --auth=myuser:mypass
+ => Enable authentication with 'myuser' as login and 'mypass' as password.

+ etc:/etc
+ => Shares the directory /etc which is mapped to the URL http://localhost:9025/directory/etc

+ downloads:~/Downloads
+ => Shares the directory ~/Downloads which is mapped to the URL http://localhost:9025/directory/downloads

#+BEGIN_SRC sh
$ java -jar build/libs/fserver-fat.jar mdir --port=9025 \
--upload \
--showpath \
--auth=myuser:mypass \
etc:/etc currentdir:. downloads:~/Downloads
#+END_SRC

Output:

#+BEGIN_SRC sh

[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/

https://javalin.io/documentation

[main] INFO org.eclipse.jetty.util.log - Logging initialized @309ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:9025/
[main] INFO io.javalin.Javalin - Javalin started in 190ms \o/
[qtp214074868-15] INFO org.eclipse.jetty.util.TypeUtil - JVM Runtime does not support Modules
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
#+END_SRC

To enable TSL, use command line option --tslcert=::
+ When the TSL is enabled, the URL becomes 'https' instead of
'http'. So the site is also acessible from https://localhost:9025
(Local host).
+ The web browser scary warning can be ignored as in this case, the
TSL is being used to _encrypt the connection_ over the local network
(LAN) or the over the internet.

#+BEGIN_SRC sh
$ java -jar build/libs/fserver-fat.jar mdir --port=9025 \
--tslcert=mypassword:./cert-test.tsl
--upload \
--showpath \
--auth=myuser:mypass \
etc:/etc currentdir:. downloads:~/Downloads

#+END_SRC

+ Part 2: Browser the URL http://localhost.com:9025 or http://:9025

Login Page:

[[file:images/page_login.png][file:images/page_login.png]]

Index page: contains the shared directories pages.

[[file:images/page_index.png][file:images/page_index.png]]

Directory listing 1:

[[file:images/page_directory1.png][file:images/page_directory1.png]]

Directory listing 2:

[[file:images/page_directory2.png][file:images/page_directory2.png]]

Directory listing 3: (Mobile, responsive design mode)

[[file:images/page_mobile.png][file:images/page_mobile.png]]

** Example: Start server from configuration file

The FServer application can also be initialized from a TOML configuration
file, which is a human-readable format.

File: server-conf.toml

#+BEGIN_SRC sh
[FSERVER]
# Current port that the server will listen to.
port = 9080

# Authentication (Optiona): :
auth = "myuser:mypassword"

# Show/hide path of shared directories in the index page.
showdirectory = false

# Enable/disable upload
upload = true

# Enable PDF Thumbnail [EXPERIMENTAL FEATURE]
pdfthumbnail = true

# Key-value pairs
# :
paths = [
, "desk:~/Desktop"
, "files:~/Downloads/firefox/"
# Static web site html (contains an index.html file)
, "conf:/etc"
]
#+END_SRC

This configuration:

+ Listen incoming http connection at port 9080

+ Set authentication: 'myuser' as username and 'mypassword' as
password. This field can be disabled by commenting it.

+ Creates the following pages/URLs
+ http://localhost:9090/directory/desk => Shows the content of the directory ~/Desktop
+ http://localhost:9090/directory/files => Shows the content of the directory ~/Downloads/firefox
+ http://localhost:9090/directory/conf => Shows the content of the directory /etc

Running:

+ $ java -jar build/libs/fserver-fat.jar config server-conf.toml

#+BEGIN_SRC sh
$ java -jar build/libs/fserver-fat.jar config server-conf.toml

[INFO] Server listening port: 9080 => URL: http://localhost:9080
[INFO] Server authentication login = user:pass
Shared directories =
=> desk:~/Desktop
=> files:~/Downloads
=> wiki:~/Documents/wiki
=> etc:/etc
------------------------------------------------------------
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/

https://javalin.io/documentation

[main] INFO org.eclipse.jetty.util.log - Logging initialized @342ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:9080/
[main] INFO io.javalin.Javalin - Javalin started in 189ms \o/
[qtp2042495840-16] INFO org.eclipse.jetty.util.TypeUtil - JVM Runtime does not support Modules

#+END_SRC

** Example: Start server from configuration file with SSL/TSL

*STEP 1:* Create a self-signed certificate by running the following
command and typing 'yes' to the final prompt. If there is already an
existing one, skip this step. This step generates the certificate file
test-cert.jks with password set to 'mypassword'.

#+BEGIN_SRC sh
$ keytool -genkey -keyalg RSA -storetype PKCS12 -alias sec_server \
-keystore test-cert.jks \
-storepass mypassword \
-validity 1000000 -keysize 2048
#+END_SRC

*STEP 2:* Create the configuration file server-conf.toml with the
following content:

File: server-conf.toml

#+BEGIN_SRC sh
[FSERVER]
# Current port that the server will listen to.
port = 9080

# Authentication (Optiona): :
auth = "myuser:mypassword"

# Show/hide path of shared directories in the index page.
showdirectory = false

# Enable/disable upload
upload = true

# If 'tslcert' variable is set with :
# it enables SSL/TSL which makes the connection encrypted.
#
# The server URL becomes 'https://:'
# instead of 'http://:'
tslcert = "mypassword:./test-cert.jks"

# Key-value pairs
# :
paths = [
, "desk:~/Desktop"
, "files:~/Downloads/firefox/"
# Static web site html (contains an index.html file)
, "conf:/etc"
]
#+END_SRC

*STEP 3:* Run server. When SSL/TSL is enabled, the server URL becomes
https://server-address:9080 or https://localhost:9080 when accessing
from local host.

#+BEGIN_SRC sh
$ java -jar build/libs/fserver-fat.jar config config.toml
#+END_SRC

** Building

Note: The compilation requires a gradle and Kotlin installation:

*Build*

#+BEGIN_SRC sh
$ gradle build
#+END_SRC

*Test*

+ $ java -jar build/libs/fserver-fat.jar

#+BEGIN_SRC sh
$ java -jar build/libs/fserver-fat.jar

Usage: commandmain [OPTIONS] COMMAND [ARGS]...

Options:
-h, --help Show this message and exit

Commands:
dir Serve a single directory
mdir Serve multiple directories
config Start server from user-provided configuration file.
test Run server in demonstration mode.
dummy Dummy command

#+END_SRC
** Show help

*Show help for all commands*

#+BEGIN_SRC
$ java -jar build/libs/fserver-fat.jar
Usage: fserver [OPTIONS] COMMAND [ARGS]...

FServer - micro file sharing server

Options:
-h, --help Show this message and exit

Commands:
dir Serve a single directory
mdir Serve multiple directories
config Start server from user-provided configuration file.
test Run server in demonstration mode.
dummy Dummy command

#+END_SRC

*Show help for the command 'dir*'

+ $ java -jar build/libs/fserver-fat.jar dir --help

#+BEGIN_SRC txt
$ java -jar build/libs/fserver-fat.jar dir -h
Usage: fserver dir [OPTIONS] PATH

Serve a single directory

Options:
--port INT Http Server port (default 9080)
--auth TEXT Enable Authentication. :
--upload Enable upload
--showpath Show absolute paths of shared directories
--pdf Render thumbnails of PDF files of listed directories
-h, --help Show this message and exit

Arguments:
PATH Directory to be served

#+END_SRC

*Show help for the command mdir*

#+BEGIN_SRC txt
$ java -jar build/libs/fserver-fat.jar mdir -h
Usage: fserver mdir [OPTIONS] [PATHLIST]...

Serve multiple directories

Options:
--port INT Http Server port (default 9080)
--auth TEXT Enable Authentication. :
--upload Enable upload
--showpath Show absolute paths of shared directories
--pdf Render thumbnails of PDF files of listed directories
--tslcert TEXT TSL/SSL Certificate and passwrod :
-h, --help Show this message and exit

Arguments:
PATHLIST Directories => : to be served

#+END_SRC