Coder Social home page Coder Social logo

pserwylo / dbfs Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 640 KB

WebDAV server which exposes individual database rows as files, allowing you to edit things such as templates in your favourite editor.

License: Other

PHP 100.00% Shell 0.01%

dbfs's Introduction

What is dbfs?

dbfs exposes values from a database as files.

Demo

Why?

Many website frameworks store templates (HTML/JS/CSS/other?) as values in a database. In order to allow designers to edit them, they typically need to either use dodgey web-based editors, or copy the templates into their favourite editor, and then when finished, copy it back into the databse.

This allows you to edit values from the database directly in your favourite editor, and will save them back into the databse when you save the file.

Demo

Shell session accessing files

Here is a shell session that shows how it would look to access the database values as files (using the example .config file) and the database shown below.

$ cat /etc/fstab

http://localhost:8000 /mnt/dbfs davfs rw,user,noauto 0 0


$ mount /mnt/dbfs

Please enter the username to authenticate with server
http://localhost:8000 or hit enter for none.
  Username: test
Please enter the password to authenticate user test with server
http://localhost:8000 or hit enter for none.
  Password:  
/sbin/mount.davfs: warning: the server does not support locks


$ ls /mnt/dbfs/

dbfs_test


$ ls /mnt/dbfs/dbfs_test/

CSS                               webpage_template - HTML
newsletter_template - HTML        webpage_template - JavaScript
newsletter_template - JavaScript


$ ls /mnt/dbfs/dbfs_test/CSS/

About.css  Contact.css  Home.css


$ cat /mnt/dbfs/dbfs_test/CSS/About.css

h1 {
	color: green;
}

body {

}


$ ls "/mnt/dbfs/dbfs_test/newsletter_template - HTML/"

Registration complete.html


$ cat "/mnt/dbfs/dbfs_test/newsletter_template - HTML/"

Your email has been registered.


$ echo "<p>Your registration is complete.</p>" > \
       "/mnt/dbfs/dbfs_test/newsletter_template - HTML/"


$ cat "/mnt/dbfs/dbfs_test/newsletter_template - HTML/"

<p>Your registration is complete.</p>

Database for above session

The above filesystem layout was provided from the following database:

mysql> SHOW TABLES;
+---------------------+
| Tables_in_dbfs_test |
+---------------------+
| newsletter_template |
| webpage_template    |
+---------------------+
2 rows in set (0.00 sec)

mysql> SHOW FIELDS FROM newsletter_template;
+--------------+-----------+------+-----+-------------------+-----------------------------+
| Field        | Type      | Null | Key | Default           | Extra                       |
+--------------+-----------+------+-----+-------------------+-----------------------------+
| id           | int(11)   | NO   | PRI | NULL              | auto_increment              |
| label        | char(255) | NO   |     | NULL              |                             |
| modifiedDate | timestamp | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| css_content  | text      | YES  |     | NULL              |                             |
| html_content | text      | YES  |     | NULL              |                             |
+--------------+-----------+------+-----+-------------------+-----------------------------+
5 rows in set (0.14 sec)

ql> SELECT html_content FROM newsletter_template;
+----------------------------------------+
| html_content                           |
+----------------------------------------+
| <p>Your registration is complete.</p>  |
+----------------------------------------+
1 row in set (0.00 sec)

TODO

  • Externalise SabreDAV dependency
  • Wildcard database for folders, so that if their table is in any database, then it can be exposed. Also allow wildcards in table names, such as "*_articles" which would match "news_articles" and "blog_articles".
  • Currently I presume we are using a MySQL database, because I append ';dbname=...' to the DSN for the PDO constructor.
  • Validate all of the config values for folders and return null if invalid (after logging a message).
  • Allow people to configure the authentication mechanism (e.g. Basic/Digest/LDAP)

Other Examples

Example Config File

The file dbfs.config contains documentation and examples for each of the config directives.

Example Database

Below is the SQL to create a test database, that should work well with the example dbfs.config that comes with dbfs.

We will have three fields all exposed from the one table.

CREATE DATABASE dbfs_test;

USE DATABASE dbfs_test;

CREATE TABLE webpage_template (
	id INT AUTO_INCREMENT PRIMARY KEY,
	label CHAR(255) NOT NULL,
	modifiedDate TIMESTAMP,
	css_content TEXT,
	js_content TEXT,
	html_content TEXT
);

INSERT INTO webpage_template ( 
	label, 
	css_content, 
	js_content, 
	html_content 
) VALUES ( 
	"Home",
	"h1 {\n\tcolor: red;\n}",
	"alert( 'Home page loaded' )",
	"<html>\n  <head><title>Home</title>\n  <body>\n  <h1>Home</h1>\n  </body>\n</html>"
), (
	"About",
	"h1 {\n\tcolor: green;\n}",
	"alert( 'About page loaded' )",
	"<html>\n  <head><title>About</title>\n  <body>\n  <h1>About</h1>\n  </body>\n</html>"
), (
	"Contact",
	"h1 {\n\tcolor: blue;\n}",
	"alert( 'Contact page loaded' )",
	"<html>\n  <head><title>Contact</title>\n  <body>\n  <h1>Contact</h1>\n  </body>\n</html>"
);

Example Server

PHP versions 5.4 and up have a built in webserver, that you can switch on by running the commandline php executable with the "-S" parameter.

The run-dev.sh script will start this server on localhost:8000

dbfs's People

Contributors

pserwylo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.