Skip to content

A simple, lightweight, self hosted webservice to easily share files and links via an short custom URL

License

Notifications You must be signed in to change notification settings

Friedinger/Webshare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webshare

Webshare: A simple, lightweight, self hosted webservice to easily share files and links via an short custom URL.

Version 2.2

Features

  • Share files with an easy to remember, custom URL
  • Shorten every URL (custom service like Bitly)
  • Set expiration dates for shares (deleted on first attempt post expiration)
  • Store files in a custom directory on the webserver
  • Store share data in a MySQL database
  • Show existing shares in admin page
  • Delete shares from admin page

Installation

  1. Download the source code from the latest release.

  2. Unzip the files and upload them to your webserver.

  3. Move the file to the correct location:

    • The files in the home directory must be inside the root directory of the webserver. They can be moved into a subdirectory and the content of the index.php file can also be executed by another custom file for advanced usage. The .htaccess file just redirects all requests to the index.php file.
    • The webshare directory must be outside directory of the root directory of the webserver to prevent direct access. You can move the files to your own destination, only the files inside the function directory should remain together in one directory.
  4. Create MySQL table for Webshare:

    It should have the following structure:

    name type null default
    uri varchar(50) no none
    type varchar(50) no none
    value varchar(200) no none
    password varchar(200) yes NULL
    expireDate datetime yes NULL
    createDate datetime no current_timestamp()

    Make uri a primary key index to ensure unique short links.

    For an easy installation you can use the install.sql file provided with webshare.

  5. Adjust the index.php file: Set the require paths to the Webshare.php and webshareConfig.php files so that they get loaded properly.

  6. Adjust config file:

    • Set the webshare install path when you moved the index.php file into a subdirectory of root directory.
    • Set path to file storage.
    • Set path to admin, view, password and delete page.
    • Set the database login information for Webshare.
    • Change the action executed on an error 404.
    • Limit access to admin page by validating the login state (recommended) or use an authentication with an .htaccess file.
    • Change action if admin page was requested but user is not authenticated.

Customization

To customize your Webshare installation to your personal design, you can replace or modify the default sample pages provided in the webshare directory. There are just some elements the pages must offer.

General outputs

The Webshare\Output object provides a variety of information about the current share:

  • Webshare\Output::$uri: The uri of the share
  • Webshare\Output::$value: The value of the share, either the link or the filename. Should not be used in password page, because it provides information without entering the password.
  • Webshare\Output::$expireDate: The timestamp when the share will expire
  • Webshare\Output::$createDate: The timestamp of the share creation time
  • Webshare\Output::$status: Status information about the current share action, can only be used on some pages.
  • Webshare\Output::link($uri, $text, $longLink): Function to output a link to an URI in webshare, for example the admin page. $uri sets the URI to link to, $text adjusts the text that is visible (default is the link itself), $longLink controls wether the link should just be the URI / text or an complete link with hostname and option to copy it.

Admin page

The admin page must offer a form to add a share which consists of the following parts:

<form method="post" enctype="multipart/form-data">
	<input type="text" name="uri" pattern="[a-z0-9_-]+" required /><br />
	<input type="file" name="file" /><br />
	<input type="text" name="link" /><br />
	<input type="text" name="password" /><br />
	<input type="datetime-local" name="expireDate" /><br />
	<input type="submit" name="submit" /><br />
</form>

To display messages after attempting to add a share you can use the status provided with php in the Webshare\Output::$status variable. It can have the following values, check out sample admin page for an example of handling these values:

  • success: The share was successfully added
  • errorUri: Share adding failed because the uri is already in use
  • errorBoth: Share adding failed because file and link were offered and not just one of them
  • errorUploadSize: Share adding failed because upload size limit was exceeded
  • error: Share adding failed for another reason

To display the list of existing shares, a table must be added to the admin page. The output object and its variable $shareList output the table data, the links allow sorting the table by the different columns.

<table>
	<th><a href="?sort=uri">URI</a></th>
	<th><a href="?sort=type">Type</a></th>
	<th><a href="?sort=value">Value</a></th>
	<th><a href="?sort=password">Password</a></th>
	<th><a href="?sort=expireDate">Expire Date</a></th>
	<th><a href="?sort=createDate">Create Date</a></th>
	<th>Action</th>
	<?= Webshare\Output::$shareList ?>
</table>

A sample admin page can be found here.

View page

The view page should display an preview of the requested file. Therefore the following php code must be included to output the preview.

<?= Webshare\Output::$sharePreview ?>

A sample view page can be found here.

Password page

The password page must contain a form to enter the password to access the protected share.

<form method="post">
	<label>Password: </label><input type="password" name="password" /><br />
	<input type="submit" value="Submit password" name="submit" /><br />
</form>

The status of the password access is provided by the Webshare\Output::$status variable. Its value is set to incorrect if the entered password is not correct. If the password matches the user is directly redirected to the share without displaying any message.

A sample password page can be found here.

Delete page

The delete page must include a form to confirm the deletion of a share. For that reason, a the following form should be used:

<form method="post">
	<input type="hidden" name="share" value="<?= Webshare\Output::$uri ?>" />
	<input type="submit" name="submit" value="Delete" /><br />
</form>

To inform the user about a successful deletion, the status of the deletion is provided by the Webshare\Output::$status variable. It can have the following values:

  • success: The share was successfully deleted
  • error: An error occurred during the deletion
  • Something else or unset: Default output before confirming the deletion

A sample password page can be found here.

Credit and license

© 2023 Friedinger

License: MIT License

About

A simple, lightweight, self hosted webservice to easily share files and links via an short custom URL

Topics

Resources

License

Stars

Watchers

Forks