2016-01-21 22:12:19 +01:00
|
|
|
<?php
|
|
|
|
# PAPERWEB - GPLv3 licence
|
|
|
|
# Copyright 2016 Yves Gablin
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2016-01-29 20:34:08 +01:00
|
|
|
$CONF = parse_ini_file('paperweb.ini.php');
|
2016-01-21 22:12:19 +01:00
|
|
|
|
|
|
|
if (array_key_exists('doDownload', $_REQUEST)) {
|
2016-01-28 20:53:25 +01:00
|
|
|
$date = @$_REQUEST['date'];
|
|
|
|
$page = @$_REQUEST['page'];
|
|
|
|
$datearg = escapeshellarg($date);
|
|
|
|
$pagearg = escapeshellarg($page);
|
2016-01-26 22:51:15 +01:00
|
|
|
|
|
|
|
# -M and -R are used instead of -D to avoid storing the data in RAM
|
2016-01-29 20:34:08 +01:00
|
|
|
$json = exec("sudo -u {$CONF['USER']} {$CONF['PATH']} -M {$datearg} -p {$pagearg}");
|
2016-01-26 22:51:15 +01:00
|
|
|
if ($json) {
|
|
|
|
$meta = json_decode($json, true);
|
2016-01-29 11:35:50 +01:00
|
|
|
$knownetag = trim(@$_SERVER['HTTP_IF_NONE_MATCH'], ' "');
|
|
|
|
if ($meta['etag'] == $knownetag) {
|
|
|
|
header('HTTP/1.1 304 Not Modified');
|
|
|
|
} else {
|
|
|
|
$ext = explode('/', $meta['mime'])[1];
|
|
|
|
header("Content-Type: {$meta['mime']}");
|
|
|
|
header("ETag: \"{$meta['etag']}\"");
|
|
|
|
header("Content-Disposition: inline; filename=\"{$date}_{$page}.{$ext}\"");
|
2016-01-29 20:34:08 +01:00
|
|
|
passthru("sudo -u {$CONF['USER']} {$CONF['PATH']} -R {$datearg} -p {$pagearg}");
|
2016-01-29 11:35:50 +01:00
|
|
|
}
|
2016-01-26 22:51:15 +01:00
|
|
|
}
|
2016-01-21 22:12:19 +01:00
|
|
|
} else {
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en"><head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>PaperWeb, a simple web interface for Paperwork</title>
|
|
|
|
<link rel="stylesheet" href="paperweb.css"/>
|
|
|
|
</head><body>
|
|
|
|
<form method="POST">
|
|
|
|
<header>
|
|
|
|
<h1>PaperWeb, a simple web interface for Paperwork</h1>
|
|
|
|
<p><label>Space-separated date prefixes (<var>YYYY</var>, <var>YYYYMM</var> or <var>YYYYMMDD</var>, eg: <samp>201512 2016</samp>):
|
|
|
|
<input name="D" value="<?php echo htmlentities(@$_REQUEST['D']); ?>"></label></p>
|
|
|
|
<p><label>Space-separated substrings of labels (quotes allowed, eg: <samp>invoice "state tax"</samp>):
|
|
|
|
<input name="L" value="<?php echo htmlentities(@$_REQUEST['L']); ?>"/></label></p>
|
|
|
|
<p><label>Space-separated substrings of keywords (quotes allowed, eg: <samp>"check account" contact</samp>):
|
|
|
|
<input name="K" value="<?php echo htmlentities(@$_REQUEST['K']); ?>"/></label></p>
|
|
|
|
<p><button type="submit" name="doQuery" value="1">Refresh</button></p>
|
|
|
|
</header>
|
|
|
|
<section id="result">
|
|
|
|
<?php
|
|
|
|
if (array_key_exists('doQuery', $_REQUEST)) {
|
|
|
|
$pattern='/(?<=")(?:[^"]|\\\\")*[^" ](?:[^"]|\\\\")*(?=")|[^ "]+/';
|
|
|
|
preg_match_all($pattern, $_REQUEST['D'], $matches);
|
|
|
|
$dates = escapeshellarg(implode('|', $matches[0]));
|
|
|
|
preg_match_all($pattern, $_REQUEST['L'], $matches);
|
|
|
|
$labels = escapeshellarg(implode('|', $matches[0]));
|
|
|
|
preg_match_all($pattern, $_REQUEST['K'], $matches);
|
|
|
|
$words = escapeshellarg(implode('|', $matches[0]));
|
2016-01-29 20:34:08 +01:00
|
|
|
$json = exec("sudo -u {$CONF['USER']} {$CONF['PATH']} -Q -d {$dates} -l {$labels} -k {$words} -i");
|
2016-01-21 22:12:19 +01:00
|
|
|
unset($_REQUEST['doThumbnails']);
|
|
|
|
unset($_REQUEST['thumbnailsDone']);
|
|
|
|
unset($_REQUEST['currentDoc']);
|
|
|
|
} else {
|
|
|
|
$json = @$_REQUEST['queryDone'];
|
|
|
|
}
|
|
|
|
if ($json) {
|
2016-01-26 19:55:42 +01:00
|
|
|
if ($json == '[]') {
|
|
|
|
?>
|
|
|
|
<p>No result.</p>
|
|
|
|
<?php
|
|
|
|
} else {
|
|
|
|
$current = (array_key_exists('doThumbnails', $_REQUEST) ? $_REQUEST['doThumbnails'] : @$_REQUEST['currentDoc']);
|
2016-01-21 22:12:19 +01:00
|
|
|
?>
|
|
|
|
<h2>Documents found</h2>
|
|
|
|
<input type="hidden" name="queryDone" value="<?php echo htmlentities($json); ?>"/>
|
|
|
|
<?php
|
2016-01-26 19:55:42 +01:00
|
|
|
foreach (json_decode($json, true) as $doc) {
|
2016-01-21 22:12:19 +01:00
|
|
|
?>
|
2016-01-26 22:51:15 +01:00
|
|
|
<button type="submit" name="doThumbnails" value="<?php echo htmlentities($doc['folder']); ?>"<?php
|
|
|
|
if ($doc['folder'] == $current) {
|
2016-01-26 19:55:42 +01:00
|
|
|
echo ' disabled="disabled"';
|
|
|
|
}
|
2016-01-21 22:12:19 +01:00
|
|
|
?>>
|
|
|
|
<h3><?php echo preg_replace('/^(....)(..)(..).*$/', '$1-$2-$3', $doc['folder']); ?></h3>
|
|
|
|
<p><?php echo $doc['count']; ?> pages (<?php echo ($doc['type']=='pdf'?'PDF':'images'); ?>)</p>
|
2016-01-26 19:55:42 +01:00
|
|
|
<?php if (count($doc['labels'])) { ?>
|
2016-01-21 22:12:19 +01:00
|
|
|
<ul>
|
2016-01-26 19:55:42 +01:00
|
|
|
<?php foreach ($doc['labels'] as $lab) { ?>
|
2016-01-21 22:12:19 +01:00
|
|
|
<li><?php echo htmlentities($lab); ?></li>
|
2016-01-26 19:55:42 +01:00
|
|
|
<?php } ?>
|
2016-01-21 22:12:19 +01:00
|
|
|
</ul>
|
2016-01-26 19:55:42 +01:00
|
|
|
<?php } ?>
|
2016-01-21 22:12:19 +01:00
|
|
|
</button>
|
|
|
|
<?php
|
2016-01-26 19:55:42 +01:00
|
|
|
}
|
2016-01-21 22:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</section>
|
|
|
|
<section id="thumbs">
|
|
|
|
<?php
|
|
|
|
if (array_key_exists('doThumbnails', $_REQUEST)) {
|
2016-01-26 22:51:15 +01:00
|
|
|
$date = $_REQUEST['doThumbnails'];
|
2016-01-21 22:12:19 +01:00
|
|
|
$datearg = escapeshellarg($date);
|
2016-01-29 20:34:08 +01:00
|
|
|
$json = exec("sudo -u {$CONF['USER']} {$CONF['PATH']} -T {$datearg}");
|
2016-01-21 22:12:19 +01:00
|
|
|
} else {
|
|
|
|
$json = @$_REQUEST['thumbnailsDone'];
|
2016-01-26 22:51:15 +01:00
|
|
|
$date = @$_REQUEST['currentDoc'];
|
2016-01-21 22:12:19 +01:00
|
|
|
}
|
|
|
|
if ($json) {
|
|
|
|
?>
|
|
|
|
<h2>Pages</h2>
|
|
|
|
<input type="hidden" name="thumbnailsDone" value="<?php echo htmlentities($json); ?>"/>
|
2016-01-26 22:51:15 +01:00
|
|
|
<input type="hidden" name="currentDoc" value="<?php echo htmlentities($date); ?>"/>
|
2016-01-21 22:12:19 +01:00
|
|
|
<?php
|
|
|
|
foreach (json_decode($json, true) as $n => $p) {
|
|
|
|
$nump = $n+1;
|
|
|
|
?>
|
2016-01-26 22:51:15 +01:00
|
|
|
<a target="_blank" href="?<?php echo htmlentities("doDownload=1&date={$date}&page={$nump}"); ?>"><img
|
2016-01-21 22:12:19 +01:00
|
|
|
src="data:<?php echo $p['mime']; ?>;base64,<?php echo $p['data']; ?>"
|
|
|
|
width="<?php echo $p['width']; ?>" height="<?php echo $p['height']; ?>"
|
|
|
|
alt="Page <?php echo $nump; ?>"/></a>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</section>
|
|
|
|
</form>
|
|
|
|
<footer><p>PaperWeb - Copyright 2016 Yves Gablin - Based on Paperwork by jflesch.</p></footer>
|
|
|
|
</body></html>
|
|
|
|
<?php
|
|
|
|
}
|