Skip to content

Commit

Permalink
Release 1.7-18
Browse files Browse the repository at this point in the history
  • Loading branch information
GM-Script-Writer-62850 committed Jun 16, 2020
1 parent 3f833f3 commit 745357c
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 75 deletions.
16 changes: 13 additions & 3 deletions README
Expand Up @@ -327,21 +327,31 @@ Internal Configuration Options:
Setting this option to 2 enables it ONLY for uploaded content via the Printer page
Setting this option to 3 enables it for both uploading documents and printing scanned documents
This is set on line 12 of config.ini
ReplacePrinter
This allows you to disable the client side printing button in favor of the intigrrated one
This option is ignored if the integrated printer is disabled
This is set on line 13 of config.ini
BusterPrintBug
Debian Buster has a issue with printing PDF files under some conditions
Setting this option to 0 leaves mitigations disabled
Setting this option to 1 converts the PDF to a ps file before printing using the pdf2ps command, this may reduce quality, but is faster than 2
Setting this option to 2 reformats the PDF using the convert command (pdf -> pdf)
This is set on line 14 of config.ini
HomePage
This option allows one to change the home page within the scanner server
While is supports a vast number of pages, the only options I consider useful are Scan and Printer
This is set on line 13 of config.ini
This is set on line 15 of config.ini
ShowRawFormat
This option allows one to show or hide the scanner option to change the raw scan format (pnm or tiff)
By default this option is hidden for the sake of simplicity
This is set on line 14 of config.ini
This is set on line 16 of config.ini
RawScanFormat
This option allows one to change the default raw format regardless of the ShowRawFormat setting
There is no real reason to pick one over the other, unless you one or the other does not work
See Issue #23: https://github.com/GM-Script-Writer-62850/PHP-Scanner-Server/issues/23
Setting this option to 0 makes the default format pnm
Setting this option to 1 makes the default format tiff
This is set on line 15 of config.ini
This is set on line 17 of config.ini

Credit where credit is due:
PHiLLIP KLiEWER
Expand Down
10 changes: 6 additions & 4 deletions config.ini
Expand Up @@ -9,11 +9,13 @@ Theme = '383838.B84E40.407EB4.202020.408080.FF0.FFF.3B133B.FFF.F00.FFF
DarkPicker = true ; Use the dark color picker by default (It is part of the theme manager)
RulerIncrement = 25.4 ; Controls the rulers number increments relative to millimeters [25.4=inches (25.4 mm = 1 in), 10=centimeters (10 mm = 1 cm)]
TimeZone = '' ; Time zone override (used with scan file names) List of settings is on this page: http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
Printer = 0 ; 0 means printing is disabled, 1 means integrated printer, 2 means upload printer, 3 means upload/integrated printing
Printer = 0 ; 0 means integrated printing is disabled, 1 means integrated printer, 2 means upload printer, 3 means upload/integrated printing
ReplacePrinter = false ; Set to false to allow the user to choose to print client side, true forces the user to use the integrated printer (only works if Printer is set to 1 or 3)
BusterPrintBug = 0 ; 0 means disabled, 1 will convert the file to a post script file, and 2 will reformat the file to print; 1 is faster than 2, but may affect quality more if any; known to affect Debian Buster Servers
HomePage = 'Scan' ; Defines the default page for the scanner server (Valid pages: Scan, Printer, Scans, Config, About, Access Enabler, Edit, Paper Manager, Device Notes, PHP Information, and Parallel-Form )
ShowRawFormat = false ; Show GUI option to change raw format
RawScanFormat = 0 ; Defines default raw scan format (pnm or tiff) use 0 for pnm and 1 for tiff
RawScanFormat = 0 ; Defines default raw scan format (pnm or tiff) use 0 for pnm and 1 for tiff
; No need to mess with the following
NAME = "PHP Scanner Server" ; Application Name
VER = "1.6-17" ; Scanner Version
SAE_VER = "1.4" ; Scanner Access Enabler version
VER = "1.7-18" ; Scanner Version
SAE_VER = "1.4" ; Scanner Access Enabler version
2 changes: 2 additions & 0 deletions config.php
Expand Up @@ -11,6 +11,8 @@
$RulerIncrement=(double)$cfg['RulerIncrement'];
$TimeZone=(string)$cfg['TimeZone'];
$Printer=(integer)$cfg['Printer'];
$ReplacePrinter=(bool)$cfg['ReplacePrinter'];
$BusterPrintBug=(int)$cfg['BusterPrintBug'];
$HomePage=(string)$cfg['HomePage'];
$ShowRawFormat=(bool)$cfg['ShowRawFormat'];
$RawScanFormat=(integer)$cfg['RawScanFormat'];
Expand Down
30 changes: 20 additions & 10 deletions download.php
Expand Up @@ -81,46 +81,53 @@ function returnFile($in,$out,$ext){
$file=$key;
if(is_numeric(strpos($file, "/")))
$file=substr($file,strrpos($file,"/")+1);
$file="Scan_$file";
if(!is_file("scans/file/$file"))
$name=$file;
$file="scans/file/Scan_$name";
if(!is_file($file))
continue;
$ext=substr($file,strrpos($file,'.')+1);
$width=$Pwidth;
$height=$Pheight;
$pdf->AddPage();
$pages+=1;
if(substr($name,-4)=='tiff'){// fpdf does not support tiff
shell_exec("convert '".escapeshellarg($file)."' '/tmp/$name.png'");
$file="/tmp/$name.png";
}
if($full){
if($ext=='txt'){
$pdf->SetFont('Arial','',$fontSize*0.75*($width/215.9));
$pdf->MultiCell(0,5,file_get_contents("scans/file/$file"),0,"L",false);
$pdf->MultiCell(0,5,file_get_contents($file),0,"L",false);
}
else{
$image=explode("x",shell_exec("identify -format '%wx%h' ".escapeshellarg("scans/file/$file")));
$image=explode("x",shell_exec("identify -format '%wx%h' ".escapeshellarg($file)));
if($height/$width<=$image[1]/$image[0])
$width=0;
else
$height=0;
$pdf->Image("scans/file/$file",$marginLeft,$marginTop,$width,$height);
$pdf->Image($file,$marginLeft,$marginTop,$width,$height);
}
}
else{
$pdf->SetFont('Arial','B',$fontSize*($width/215.9));
$pdf->MultiCell(0,$fontSize*($width/215.9),$file,0,"C",false);
$pdf->MultiCell(0,$fontSize*($width/215.9),$name,0,"C",false);
if($ext=='txt'){
$pdf->SetFont('Arial','',$fontSize*0.75*($width/215.9));
$pdf->MultiCell(0,5*($width/215.9),file_get_contents("scans/file/$file"),0,"L",false);
$pdf->MultiCell(0,5*($width/215.9),file_get_contents($file),0,"L",false);
}
else{
$image=explode("x",shell_exec("identify -format '%wx%h' ".escapeshellarg("scans/file/$file")));
$image=explode("x",shell_exec("identify -format '%wx%h' ".escapeshellarg($file)));
$width=$width-($marginLeft*2);
$height=$height-$marginTop*2-$fontSize*0.75*($Pwidth/215.9)/2;
if($height/$width<=$image[1]/$image[0])
$width=0;
else
$height=0;
$pdf->Image('scans/file/'.$file,$marginLeft,$marginTop/2+$fontSize*($Pwidth/215.9),$width,$height);
$pdf->Image($file,$marginLeft,$marginTop/2+$fontSize*($Pwidth/215.9),$width,$height);
}
}
if(substr($name,-4)=='tiff');
@unlink($file);
}
if($pages>0){
if(isset($_GET['printer'])&&($Printer % 2 != 0)){
Expand Down Expand Up @@ -190,8 +197,11 @@ function returnFile($in,$out,$ext){
if(is_file($file)){
if(filesize($file)>0)
returnFile($file,$name,$type);
else
else{
if($type=='pdf'&&strpos($output,'not allowed by the security policy')>0)
$output=$output."\n\n*** https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion";
returnFile(debug($cmd,$output),'Error.txt','txt');
}
@unlink($file);
}
else if(isset($output))
Expand Down
35 changes: 19 additions & 16 deletions index.php
Expand Up @@ -133,7 +133,7 @@ function genIconLinks($config,$file,$isBulk){
'href'=>"print.php?file=$URL",
'onclick'=>$GLOBALS['Printer'] % 2 == 0?'return true':"return PDF_popup('$sJS',true)",
'target'=>'_blank',
'disable'=>isset($config->{'print'}),
'disable'=>isset($config->{'print'})||($GLOBALS['Printer'] % 2 == 0&&substr($URL,-4)=='tiff'),
'tip'=>'Print',
'bulk'=>$GLOBALS['Printer'] % 2 == 0?"bulkPrint(this)":"PDF_popup(filesLst,true)"
),
Expand All @@ -151,7 +151,7 @@ function genIconLinks($config,$file,$isBulk){
),
'view'=>(object)array(
'href'=>"index.php?page=View&amp;file=$URL",
'disable'=>isset($config->{'view'}),
'disable'=>isset($config->{'view'})||substr($URL,-4)=='tiff',
'tip'=>'View',
'bulk'=>"bulkView(this)"
),
Expand Down Expand Up @@ -550,7 +550,7 @@ function quit(){

Footer('');

if($ACTION=="Search-For-Printers"&&$Printer>0){ # Find avalible printers on the system
if($ACTION=="Search-For-Printers"&&$Printer>0){ # Find available printers on the system
unset($file);
include('res/printer.php');
$json=(object)array();
Expand Down Expand Up @@ -586,13 +586,13 @@ function quit(){
if(SaveFile("config/printers.json",json_encode($json)))
Print_Message('Success',count($list).' Printer(s) have been found and configured.<br/><ul style="text-align:left"><li>'.implode("</li><li>",$list).'</li></ul>','center');
else
Print_Message('Failure','Bad news: <code>'.$user.'</code> does not have permission to write files to the <code>'.html(getcwd()).'/config</code> folder.','cetner');
Print_Message('Failure','Bad news: <code>'.$user.'</code> does not have permission to write files to the <code>'.html(getcwd()).'/config</code> folder.','center');
}
else
Print_Message('Error','No printers found!!!<br/>Please go to your <a href="http://'.$_SERVER['HTTP_HOST'].':631">CUPS</a> configuration to setup printers.','center');
}
else if($ACTION=="Search-For-Scanners"){ # Find avalible scanners on the system
/*$OP=json_decode( // Double quotes in varables break this
else if($ACTION=="Search-For-Scanners"){ // Find available scanners on the system
/*$OP=json_decode( // Double quotes in variables break this
"[".substr(
exe('scanimage -f "{\\"ID\\":%i,\\"INUSE\\":0,\\"DEVICE\\":\\"%d\\",\\"NAME\\":\\"%v %m %t\\"},"',true),
0,
Expand Down Expand Up @@ -1007,8 +1007,8 @@ function quit(){
while(file_exists("scans/thumb/Preview_$name-edit-$int.jpg")){
$int++;
}
$file="scans/file/Scan_$name-edit-$int.$ext";//scan
$name=str_replace("file/Scan_","thumb/Preview_",$file);//preview
$file="scans/file/Scan_$name-edit-$int.$ext";// Scan
$name=str_replace("file/Scan_","thumb/Preview_",$file);// Preview
if($FILETYPE==substr($file,strrpos($file,'.')+1)){
@rename($tmpFileRaw,$file);// Incorrect access denied message is generated
if(file_exists($tmpFileRaw)&&!file_exists($file)){// Just in-case it becomes accurate
Expand All @@ -1026,18 +1026,21 @@ function quit(){
exe("convert $tmpFile -fx '(r+g+b)/3' ".shell("/tmp/edit_scan_file$t.tif"),true);
exe("tesseract ".shell("/tmp/edit_scan_file$t.tif").' '.shell($S_FILENAMET)." -l ".shell($LANG),true);
unlink("/tmp/edit_scan_file$t.tif");
if(!file_exists("$S_FILENAMET.txt"))//In case tesseract fails
if(!file_exists("$S_FILENAMET.txt"))// In case tesseract fails
SaveFile("$S_FILENAMET.txt","");
}
$FILE=substr($name,0,strrpos($name,'.')+1).'jpg';//Preview
$FILE=substr($name,0,strrpos($name,'.')+1).'jpg';// Preview
if($FILETYPE!='txt'){
exe("convert ".shell($file)." -scale '450x471' ".shell($FILE),true);
$file=substr($file,16);
}
else{
exe("convert $tmpFile -scale '450x471' ".shell($FILE),true);
unlink($tmpFileRaw);
$file=substr($file,16,strrpos($file,'.')-10).'txt';
$file=substr($file,16,strrpos($file,'.')-15).'txt';
}
if(file_exists($tmpFileRaw)){
unlink($tmpFileRaw);
}
}
}
Expand All @@ -1063,7 +1066,7 @@ function quit(){
if($FILES[$i]=='.'||$FILES[$i]=='..')
continue;
$FILE=substr($FILES[$i],7,-3);
$FILE=substr(exe("cd 'scans/file/'; ls ".shell("Scan$FILE").'*',true),5);//Should only have one file listed
$FILE=substr(exe("cd 'scans/file/'; ls ".shell("Scan$FILE").'*',true),5);// Should only have one file listed
$IMAGE=$FILES[$i];
include "res/inc/editscans.php";
}
Expand All @@ -1080,7 +1083,7 @@ function quit(){
$CANNERS=json_decode(file_exists("config/scanners.json")?file_get_contents("config/scanners.json"):'[]');
if(strlen($SAVEAS)>0||$ACTION=="Scan Image"){
$langs=findLangs();
if(!validNum(Array($SCANNER,$BRIGHT,$CONTRAST,$SCALE,$ROTATE))||!in_array($LANG,$langs)||!in_array($QUALITY,explode("|",$CANNERS[$SCANNER]->{"DPI-$SOURCE"}))){//security check
if(!validNum(Array($SCANNER,$BRIGHT,$CONTRAST,$SCALE,$ROTATE))||!in_array($LANG,$langs)||!in_array($QUALITY,explode("|",$CANNERS[$SCANNER]->{"DPI-$SOURCE"}))){// Security check
Print_Message("No, you can not do that","Input data is invalid and most likely an attempt to run malicious code on the server <i>denied</i>",'center');
Footer('');
quit();
Expand Down Expand Up @@ -1217,7 +1220,7 @@ function quit(){
$SIZE_X=$scanner_w;
$SIZE_Y=$scanner_h;
}
else if($sizes[0]<=$scanner_w&&$sizes[1]<=$scanner_h&&$sizes[1]<=$scanner_w&&$sizes[0]<=$scanner_h){// fits both ways
else if($sizes[0]<=$scanner_w&&$sizes[1]<=$scanner_h&&$sizes[1]<=$scanner_w&&$sizes[0]<=$scanner_h){// Fits both ways
if($ORNT!="vert"){
$SIZE_X=$sizes[1];
$SIZE_Y=$sizes[0];
Expand All @@ -1227,11 +1230,11 @@ function quit(){
$SIZE_Y=$sizes[1];
}
}
else if($sizes[0]<=$scanner_w&&$sizes[1]<=$scanner_h){//fits tall way
else if($sizes[0]<=$scanner_w&&$sizes[1]<=$scanner_h){// Fits tall way
$SIZE_X=$sizes[0];
$SIZE_Y=$sizes[1];
}
else if($sizes[1]<=$scanner_w&&$sizes[0]<=$scanner_h){//fits wide way
else if($sizes[1]<=$scanner_w&&$sizes[0]<=$scanner_h){// Fits wide way
$SIZE_X=$sizes[1];
$SIZE_Y=$sizes[0];
}
Expand Down
11 changes: 7 additions & 4 deletions print.php
@@ -1,22 +1,22 @@
<!DOCTYPE html><html><head><meta charset="UTF-8"/><link rel="shortcut icon" href="res/images/favicon.png"/>
<style type="text/css">body,div{text-align:center;}div{padding:20px;display:inline-block;}.break div{padding:0;width:100%;page-break-after:always;}</style><title><?php
<style type="text/css">body,div{text-align:center;}div{padding:20px;display:inline-block;}.break div{padding:0;width:100%;page-break-after:always;}img{max-width:100%;}</style><title><?php
if(isset($_GET['file'])){
$files=json_decode('{"'.$_GET['file'].'":1}');
$files=(array)json_decode('{"'.$_GET['file'].'":1}');
$prefix='';
}
else if(isset($_GET['json'])){
$files=json_decode($_GET['json']);
$prefix='Scan_';
}
else
die('<title>Missing File</title></head><body><h1>Error</h1>No file(s) specifyed</body></html>');
die('<title>Missing File</title></head><body><h1>Error</h1>No file(s) specified</body></html>');
if(count($files)==1){
foreach($files as $file => $val)
echo htmlspecialchars(substr($file,strlen($prefix),strrpos($file,'.')-strlen($prefix)));
}
else
echo "Compilation";
?></title></head><body onload="if(total>1){if(confirm('Press OK, for only 1 image per page\nPress Cancel for as many as will fit per page')){document.body.className='break';}}window.print();window.close();"><?php
?></title></head><body onload="if(total>1){if(confirm('Press OK, for only 1 image per page\nPress Cancel for as many as will fit per page')){document.body.className='break';}}window.print();setTimeout(function(){window.close();},1)"><?php // setTimeout is for chrome
$ct=0;
foreach($files as $file => $val){
$ct++;
Expand All @@ -27,6 +27,9 @@
if($ext=="txt"){
echo "<pre>".htmlspecialchars(file_get_contents("scans/file/$file"))."</pre>";
}
else if($ext=="tiff"){
continue;
}
else{
$file=htmlspecialchars($file);
echo "<img alt=\"$file\" src=\"scans/file/$file\">";
Expand Down
2 changes: 1 addition & 1 deletion res/inc/edit-text.php
Expand Up @@ -7,7 +7,7 @@
while(file_exists("scans/thumb/Preview_$name-edit-$int.jpg")){
$int++;
}
copy("scans/thumb/$preview","scans/Preview_$name-edit-$int.jpg");
copy("scans/thumb/$preview","scans/thumb/Preview_$name-edit-$int.jpg");
if(SaveFile("scans/file/Scan_$name-edit-$int.txt",$_POST['file-text'])){
Print_Message("Saved","You have successfully edited $file",'center');
$file="$name-edit-$int.txt";
Expand Down
2 changes: 1 addition & 1 deletion res/inc/edit.php
Expand Up @@ -113,6 +113,6 @@
<h2><?php echo html($file); ?></h2>
<p>
<?php echo genIconLinks((object)array('edit'=>0),"Scan_$file",false); ?>
</p></div><!-- There are no line breaks on the next line to make the javascript ever so slightly faster -->
</p></div><!-- There are no line breaks on the next line to make the JavaScript ever so slightly faster -->
<div id="preview_img"><p><img alt="Preview" src="scans/thumb/Preview_<?php echo url(substr($file,0,strrpos($file,'.'))); ?>.jpg" title="Preview"/><img style="z-index:-1;" src="res/images/blank.gif" title="Processing" alt=""/></p></div>
</div>
2 changes: 1 addition & 1 deletion res/inc/header.php
Expand Up @@ -22,7 +22,7 @@
'<script type="text/javascript" src="'.$path.'jquery/colorpicker-custom/js/colorpicker.js"></script>';
else if($page=='Index Of')
echo '<link rel="stylesheet" type="text/css" href="'.$path.'res/indexOf.css"/>';
echo '<script type="text/javascript">var I='.$GLOBALS['RulerIncrement'].';</script>';
echo '<script type="text/javascript">var I='.$GLOBALS['RulerIncrement'].',ReplacePrinter='.($GLOBALS['ReplacePrinter']&&$GLOBALS['Printer'] % 2 !=0?'true':'false').';</script>';
?>
<script type="text/javascript" src="<?php echo $path; ?>res/model-dialog.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>res/cookie.js"></script>
Expand Down
17 changes: 8 additions & 9 deletions res/inc/scans.php
Expand Up @@ -47,13 +47,12 @@ function ageSeconds2Human($t){
'<button onclick="return selectScans(false);">Invert Selection</button> '.
'<button onclick="return selectScans(\'included\');">Select None</button>'.
'</p></div>';
//$FILES=explode("\n",substr(exe("cd 'scans/thumb'; ls -t 'Preview'*",true),0,-1));// seems to be slower
$FILES=scandir('scans/thumb');
$FILES=scandir('scans/file');
$i=array();
foreach($FILES as $FILE){
if($FILE=='.'||$FILE=='..')
continue;
$i[$FILE]=filemtime("scans/thumb/$FILE");
$i[$FILE]=filemtime("scans/file/$FILE");
}
arsort($i);
$FILES=array_keys($i);
Expand Down Expand Up @@ -102,21 +101,21 @@ function ageSeconds2Human($t){
continue;
}
if($filter===2){
if(filemtime("scans/thumb/$FILE")<$time)
if(filemtime("scans/file/$FILE")<$time)
continue;
}
else if($filter===1){
if(filemtime("scans/thumb/$FILE")>$time)
if(filemtime("scans/file/$FILE")>$time)
continue;
}
else if($filter===3){
if(!(filemtime("scans/thumb/$FILE")>$time[1]&&filemtime("scans/thumb/$FILE")<$time[0]))
if(!(filemtime("scans/file/$FILE")>$time[1]&&filemtime("scans/file/$FILE")<$time[0]))
continue;
}
}
$FILE=substr($FILE,7,-3);
$FILE=substr(exe("cd 'scans/file'; ls ".shell("Scan$FILE").'*',true),5,-1);//Should only have one file listed
$IMAGE=$FILES[$i];
$FILE=substr($FILE,5);
$IMAGE=strlen(substr($FILES[$i],strrpos($FILES[$i],'.')));// char count of file extension +1
$IMAGE="Preview".substr($FILES[$i],4,$IMAGE*-1).".jpg";
echo '<div class="box" id="'.html($FILE).'">'.
'<h2 ondblclick="toggleFile(this);" class="excluded">'.html($FILE).'</h2><p><span>'.
genIconLinks(null,"Scan_$FILE",false).'</span><br/>'.
Expand Down

0 comments on commit 745357c

Please sign in to comment.