diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README | 12 | ||||
-rw-r--r-- | feed.php | 43 | ||||
-rw-r--r-- | fsfeed.db.default | bin | 0 -> 6144 bytes | |||
-rw-r--r-- | get.php | 20 | ||||
-rw-r--r-- | index.php | 73 |
6 files changed, 149 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b30fb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +fsfeed.db @@ -0,0 +1,12 @@ +# Introduction # +fsfeed is a simple PHP app that turns directory paths into Atom feeds. It's useful to run it +on an insecure file server to notify users of file or folder updates. Users can also download +files from their newsreader, provided that the web server has read access to the file. + +By using a combination of the path and modification time as the URN of an entry, it can mark +an updated file as new in the newsreader. + +fsfeed is not and probably never will be, recursive. + +# Usage # +Just copy the fsfeed folder to where your web server can run it from and rename fsfeed.db.default to fsfeed.db. diff --git a/feed.php b/feed.php new file mode 100644 index 0000000..ab89c9c --- /dev/null +++ b/feed.php @@ -0,0 +1,43 @@ +<?php +//// +// fsfeed/feed.php +// turn a path into an Atom feed +error_reporting(E_ALL|E_STRICT); +ini_set('display_errors', 'On'); +$db = new PDO('sqlite:fsfeed.db'); +$stmt = $db->prepare('SELECT * FROM path WHERE id = ?'); +$stmt->execute(array($_GET['f'])); +$rows = current($stmt->fetchAll()); +$path = $rows['path']; +header('Content-Type: application/atom+xml'); +echo '<?xml version="1.0" encoding="utf-8"?>'; +?> +<feed xmlns="http://www.w3.org/2005/Atom"> +<title>fsfeed - <?php echo $path ?></title> + <updated><?php echo strftime('%Y-%m-%dT%TZ') ?></updated> + <author> + <name>fsfeed 0.1</name> + </author> + <id>urn:uuid:<?php echo sha1($path) ?></id> +<?php + + foreach(glob("{$path}/*", GLOB_NOSORT) as $p): + + $uuid = sha1($p.filemtime($p)); + $ts = strftime('%Y-%m-%dT%TZ', filemtime($p)); + $created = strftime('%c', filectime($p)); + $updated = strftime('%c', filemtime($p)); + $size = round(filesize($p)/pow(1024, 2), 2); + $summary = sprintf("Created: %s\nUpdated: %s\nSize: %s MB", $created, $updated, $size); + $link = $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/get.php?f='.urlencode($p); + +?> + <entry> + <title><?php echo basename($p) ?></title> + <id>urn:uuid:<?php echo $uuid ?></id> + <link href="http://<?php echo $link ?>"/> + <updated><?php echo $ts ?></updated> + <summary><?php echo $summary ?></summary> + </entry> +<?php endforeach ?> +</feed> diff --git a/fsfeed.db.default b/fsfeed.db.default Binary files differnew file mode 100644 index 0000000..df8dec1 --- /dev/null +++ b/fsfeed.db.default @@ -0,0 +1,20 @@ +<?php +//// +// fsfeed/get.php +// download a file +$path = $_GET['f']; +if (file_exists($path)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename='.basename($path)); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . filesize($path)); + ob_clean(); + flush(); + readfile($path); + exit; +} +?>
\ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..356288f --- /dev/null +++ b/index.php @@ -0,0 +1,73 @@ +<?php +//// +// fsfeed/index.php +// manage directory feeds +$msg = 'fsfeed 0.1'; +$db = new PDO('sqlite:fsfeed.db'); +if (isset($_POST['delete'])) { + $stmt = $db->prepare('DELETE FROM path WHERE id = ?'); + $stmt->execute(array($_POST['delete'])); + $msg = 'Path deleted'; +} +if (isset($_POST['add'])) { + if (!realpath($_POST['path']) || empty($_POST['path'])) { + $msg = "Invalid path: {$_POST['path']}"; + } else { + $stmt = $db->prepare('INSERT INTO path (path) VALUES (?)'); + $stmt->execute(array($_POST['path'])); + $msg = 'Path added'; + } +} +$rows = $db->query('SELECT * FROM path')->fetchAll(); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <title>fsfeed</title> + <style type="text/css" media="screen"> + body, input, button { + font: 1.2em "Lucida Grande", "Trebuchet MS", Verdana, sans-serif; + } + table { + width:80%; + margin: 200px auto; + } + input[type="text"] { + width: 80%; + } + td, th { + padding:5px; + text-align:left; + } + th { + background:#444; + color:#fff; + } + </style> +</head> + +<body> + <form method="post" action="#"> + <table> + <thead> + <tr> + <th colspan="2"><?php echo $msg ?></th> + </tr> + </thead> +<?php foreach ($rows as $r): ?> + <tr> + <td><a href="feed.php?f=<?php echo $r['id'] ?>" target="_blank"><?php echo $r['path'] ?></a></td> + <td style="width:40px"><button name="delete" value="<?php echo $r['id'] ?>"/>Delete</td> + </tr> +<?php endforeach ?> + <tr> + <td><input type="text" name="path"/></td> + <td><input type="submit" name="add" value="Add Path"/></td> + </tr> + </table> + </form> +</body> +</html> |