Skip to content

Commit

Permalink
Move config option to ini files + printer touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
GM-Script-Writer-62850 committed Sep 8, 2014
1 parent c009dba commit 1ef89b5
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 57 deletions.
20 changes: 10 additions & 10 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -221,39 +221,39 @@ Frequently asked questions/issues:
Internal Configuration Options:
Free Space Warning
This puts a warning on the page if you are low on disk space
low is defined on line 2 of config.php
low is defined on line 2 of config.ini
Fortunes
This setting is on line 3 of config.php
This setting is on line 3 of config.ini
This setting is ignored if the program fortune is not installed
If it is not working and fortune is installed you may need to update line 201 of index.php with the correct path
Extra Scanners
This is a developer tool used for simulating scanners
This is just for testing the search for scanners feature
This is set on line 4 of config.php
This is set on line 4 of config.ini
Check For Updates
Every 24 hours the scanner will check for updates, This is checked on page load
It only checks the Internet if the last check was over 24 hours ago
This is set on line 5 of config.php
This is set on line 5 of config.ini
Enable Login
There are 2 ways, one is pretty and one is not, but the not so pretty one is more secure
Look under apache tricks for the secure one
The pretty one is enabled on line 6 of config.php
The pretty one is enabled on line 6 of config.ini
Session Duration
This defines the maximum duration a user stays logged in
This is set on line 7 of config.php
This is set on line 7 of config.ini
Default Theme
The default theme is set on line 8 of config.php, you can get the theme code on the 'Configure' page
The default theme is set on line 8 of config.ini, you can get the theme code on the 'Configure' page
by clicking the 'Save' button under 'Color Scheme'
Dark Picker
Tells the page whether or not to use the dark color picker theme by default
This is set on line 9 of config.php
This is set on line 9 of config.ini
Ruler Increment
This tells the ruler what measurement system to use
This is set on line 10 of config.php
This is set on line 10 of config.ini
Time Zone
This overrides the system time zone that is set in php.ini as well as auto detect
This may not be of use for PHP versions older than 5.1
This is set on line 11 of config.php
This is set on line 11 of config.ini

Credit where credit is due:
PHiLLIP KLiEWER
Expand Down
16 changes: 16 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; This file contains the configuration option that are loaded by config.php
FreeSpaceWarn = 2048 ; In Megabytes, Warning is displayed if there is less then the amount specified
Fortune = true ; Enable/disable fortunes in the debug console
ExtraScanners = false ; Adds sample scanners from ./inc/scanhelp/
CheckForUpdates = true ; Enables auto update checking
RequireLogin = false ; Require user to login (A 'geek' could bypass this without too much trouble using JavaScript); Create the user 'root' 1st, also Authorization is root's password
SessionDuration = 86400 ; Max time (in seconds) signed in is 24hrs (irrelevant with the above off)
Theme = '383838.B84E40.407EB4.202020.408080.FF0.FFF.3B133B.FFF.F00.FFF' ; Default Color Scheme
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 mean printing is disabled, 1 means integrated printer, 2 means upload printer, 3 means upload/integrated printing
; No need to mess with these
NAME = "PHP Scanner Server" ; Application Name
VER = "1.4-11_dev" ; Scanner Version
SAE_VER = "1.4" ; Scanner Access Enabler version
33 changes: 16 additions & 17 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php // Global Varables
$FreeSpaceWarn=2048;// In Megabytes, Warning is displayed if there is less then the amount specified
$Fortune=true;// Enable/disable fortunes in the debug console
$ExtraScanners=false;// Adds sample scanners from ./inc/scanhelp/
$CheckForUpdates=true;// Enables auto update checking
$RequireLogin=false;// Require user to login (A 'geek' could bypass this without too much trouble using JavaScript); Create the user 'root' 1st, also Authorization is root's password
$SessionDuration=86400;// Max time (in seconds) signed in is 24hrs (irrelevant with the above off)
$Theme='383838.B84E40.407EB4.202020.408080.FF0.FFF.3B133B.FFF.F00.FFF'; // Default Color Scheme
$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 mean printing is disabled, 1 means integrated printer, 2 means upload printer, 3 means upload/integrated printing
// Do not edit stuff below this line

$NAME="PHP Scanner Server";
$VER="1.4-11_dev";
$SAE_VER="1.4"; // Scanner Access Enabler version
<?php // Global Variables are now stored in config.ini
$cfg=parse_ini_file('config.ini');
$FreeSpaceWarn=(integer)$cfg['FreeSpaceWarn'];
$Fortune=(bool)$cfg['Fortune'];
$ExtraScanners=(bool)$cfg['ExtraScanners'];
$CheckForUpdates=(bool)$cfg['CheckForUpdates'];
$RequireLogin=(bool)$cfg['RequireLogin'];
$SessionDuration=(integer)$cfg['SessionDuration'];
$Theme=(string)$cfg['Theme'];
$DarkPicker=(bool)$cfg['DarkPicker'];
$RulerIncrement=(double)$cfg['RulerIncrement'];
$TimeZone=(string)$cfg['TimeZone'];
$Printer=(integer)$cfg['Printer'];
$NAME=(string)$cfg['NAME'];
$VER=(string)$cfg['VER'];
$SAE_VER=(string)$cfg['SAE_VER'];

// Login Stuff
$Auth=true;
Expand Down
15 changes: 6 additions & 9 deletions download.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$Fpdf_loc="/usr/share/php/fpdf.php";
# Print commands are on lines 129 and 170
# Print commands are in res/printer.php
function debug($cmd,$output){
$here=posix_getpwuid(posix_geteuid());
$here=$here['name'].'@'.$_SERVER['SERVER_NAME'].':'.getcwd();
Expand Down Expand Up @@ -31,8 +31,8 @@ function returnFile($in,$out,$ext){
echo $in;
}
}
if(isset($_GET['printer'])){// get printer setting from config file
$Printer=intval(substr(shell_exec('cat config.php | grep \'^$Printer\' | cut -d \';\' -f1 | cut -d \'=\' -f 2'),0,-1));
if(isset($_GET['printer'])){// Get printer setting from config file
include('res/printer.php');
}
if(isset($_GET['file'])){
if(strpos($_GET['file'], "/")>-1)
Expand Down Expand Up @@ -125,9 +125,7 @@ function returnFile($in,$out,$ext){
if($_GET['printer']&&($Printer % 2 != 0)){
$file='/tmp/'.md5(time().rand()).'.pdf';
$pdf->Output($file,'F');
echo '<html><head><title>Printing...</title></head><body>The document should be printing<br/>Debug:</br>';
echo shell_exec("lp -d ".escapeshellarg($_GET['printer'])." $file");// This line makes it print when a PDF format is used
echo '</body></html>';
include('res/printer.php');
unlink($file);
}
else{
Expand Down Expand Up @@ -166,10 +164,9 @@ function returnFile($in,$out,$ext){
$file='/tmp/'.md5(time().rand()).'.pdf';
$cmd="convert $FILES+repage '$file'";
$output=shell_exec("$cmd 2>&1");// -page Letter -gravity center
echo '<html><head><title>Printing...</title></head><body>The document should be printing<br/>Debug:</br>';
echo shell_exec('lp -d '.escapeshellarg($_GET['printer'])." $file");// This line makes it print via the I don't care button
include('res/printer.php');
unlink($file);
die('</body></html>');
die();
}
$name=$ct==1?substr($file,0,strrpos($file,'.')).'.pdf':'Compilation.pdf';
$file='/tmp/'.md5(time().rand()).'.pdf';
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ function quit(){
else if(ini_get('date.timezone')==='' && version_compare(phpversion(), '5.1', '>=')){
date_default_timezone_set('UTC');
$GMT=intval(exe('date +%z',true))*36;
exe('echo "Warning, Guessing Time Zone:\n\tGuessed as GMT '.($GMT/60/60).'.\n\tdate.timezone is not set in your /etc/php5/apache2/php.ini file.\n\tIt is probally set on line 880.\n\tThere is also a override in '.getcwd().'/config.php on line 11."',true);
exe('echo "Warning, Guessing Time Zone:\n\tGuessed as GMT '.($GMT/60/60).'.\n\tdate.timezone is not set in your /etc/php5/apache2/php.ini file.\n\tIt is probably set on line 880.\n\tThere is also a override in '.getcwd().'/config.ini on line 11."',true);
}
for($i=2,$ct=count($files);$i<$ct;$i++){
$SCAN=shell("$CANDIR/".$files[$i]);
Expand Down
20 changes: 10 additions & 10 deletions res/inc/printer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
# Printer is on lines 36, 42, and 49
if($Printer==0||$Printer==1){
if($Printer<2){
Print_Message("Error","The Printing feature is disabled<br/>The Printer option (in <code>".getcwd()."/config.php</code> on line 12) needs to be set to 2 or 3 to use this page.","center");
Footer('');
die('');
Expand Down Expand Up @@ -29,24 +28,25 @@ function convertPHPSizeToBytes($sSize){// http://stackoverflow.com/questions/130
function getMaximumFileUploadSize(){// http://stackoverflow.com/questions/13076480/php-get-actual-maximum-upload-size
return min(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')));
}
if(isset($_FILES['pdf']) || isset($_POST['raw']) ){
if( isset($_FILES['pdf']) || isset($_POST['raw']) ){
if(isset($_POST['raw'])){
$file=time().rand();
SaveFile("/tmp/$file.txt",$_POST['raw']);
exe('lp -d '.shell($_POST['printer']).' /tmp/'.$file.'.txt',true); // This line makes it print RAW text
Print_Message('Printer','Text has been sent to '.html($_POST['printer']),'center');
unlink("/tmp/$file.txt");
$file='/tmp/'.md5(time().rand()).'.txt';
SaveFile($file,$_POST['raw']);
include('res/printer.php');
unlink($file);
}
else{
if(mime_content_type($_FILES['pdf']['tmp_name'])=='application/pdf'){
exe('lp -d '.shell($_POST['printer']).' '.$_FILES['pdf']['tmp_name'],true); // This line makes it print PDF files
$file=$_FILES['pdf']['tmp_name'];
include('res/printer.php');
}
else{
Print_Message('Error',html($_FILES['pdf']['name'].' does not look like a PDF'),$ALIGN);
}
}
unset($file);
}
$printers=explode("\n",exe('lpstat -a|awk \'{print $1}\'',true)); // This finds printer names
include('res/printer.php');
$sel='<select name="printer">';
for($i=0;$i<count($printers);$i=$i+1){
if(strlen($printers[$i])>0)
Expand Down
26 changes: 21 additions & 5 deletions res/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,26 @@ function PDF_popup(files,print){
if(typeof(files)=='string')
files='{"'+files.replace(/"/g,'\"')+'":1}';
else if(files.tagName=='form'||files.tagName=='FORM'){
alert(files.print.value);
// Apparently if I use the files.action property it sends format=files.format.value instead of files.format.value so I will just use window.open
window.open('download.php?type=pdf&json='+files.files.value+'&size='+files.size.value+'&'+files.format.value+
(files.print.value=='true'?'&printer='+encodeURIComponent(files.printer.value):''));
var url='download.php?type=pdf&json='+files.files.value+'&size='+files.size.value+'&'+files.format.value+
(files.print.value=='true'?'&printer='+encodeURIComponent(files.printer.value):'');
if(files.print.value=='true'){
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(){
if(httpRequest.readyState==4){
if(httpRequest.status==200){
var json=parseJSON(httpRequest.responseText);
alert(httpRequest.responseText);
printMsg(encodeHTML(json['printer']),'Your document is being processed:<br/><pre>'+encodeHTML(json['message'])+'</pre>','center',0);
}
else
printMsg('Error','A '+httpRequest.status+' error was encountered.','center',0);
}
};
httpRequest.open('GET', url);
httpRequest.send(null);
}
else// Apparently if I use the files.action property it sends format=files.format.value instead of files.format.value so I will just use window.open
window.open(url);
toggle('blanket');
return false;
}
Expand Down Expand Up @@ -839,7 +855,7 @@ function PDF_popup(files,print){
}
}
};
httpRequest2.open('GET', 'res/printer.php?nocache='+new Date().getTime());
httpRequest2.open('GET', 'res/printer.php?list&nocache='+new Date().getTime());
httpRequest2.send(null);
}
popup('blanket',290);
Expand Down
44 changes: 39 additions & 5 deletions res/printer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
<?php
# This file is used to get a list of printers via AJAX
# The printer.php file in the inc folder does the printer tab
# The download.php in the parent folder does the integrated printing
header('Content-type: plain/txt; charset=UTF-8');
echo str_replace("\n",",",substr(shell_exec('lpstat -a|awk \'{print $1}\''),0,-1));
# This file is used to handle all the print commands
# This file runs all the print commands, ../download.php and inc/printer.php call this page via include
$lpstat='lpstat -a | awk \'{print $1}\'';// command used to find printers
if(function_exists('exe')){// internal call via inc/printer.php
if(isset($file))

Print_Message(
$_POST['printer'],
'Your document is being processed:<br/><pre>'.html(
exe('lp -d '.shell($_POST['printer'])." $file",true) // Print via Printer page
).'</pre>',
'center'
);
else
$printers=explode("\n",exe($lpstat,true));
}
else if(isset($Printer)){ // internal call via include from ../download.php
header('Content-type: application/json; charset=UTF-8');
echo json_encode((object)array(
'printer'=>$_GET['printer'],
'message'=>shell_exec('lp -d '.escapeshellarg($_GET['printer'])." $file")// This line makes it print using the integrated printer
));
}
else{
$Printer=parse_ini_file(file_exists('res')?'config.ini':'../config.ini');
$Printer=(integer)$Printer['Printer'];
if(!function_exists('ext2mime')){// external call via browser
if($Printer==0){// Check if printer service is enabled
header('Content-type: application/json; charset=UTF-8');
echo '{"error":"Printer service is disabled"}';
}
else if(isset($_GET['list'])){// Return list of printers
header('Content-type: plain/txt; charset=UTF-8');
echo str_replace("\n",",",substr(shell_exec($lpstat),0,-1));
}
else
echo "Todo: Don't reload printer page, use AJAX";
}
}
?>

0 comments on commit 1ef89b5

Please sign in to comment.