Skip to content

Commit

Permalink
add option to disable debugging features for production installs, enh…
Browse files Browse the repository at this point in the history
…ance receipt printing
  • Loading branch information
mike42 committed May 23, 2015
1 parent f1fe2d0 commit 3012082
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 105 deletions.
44 changes: 2 additions & 42 deletions README.md
Expand Up @@ -73,49 +73,9 @@ Now import the schema into phpmyadmin, from maintenance/schema/auth.sql, and the

Now cd /usr/share/auth.

Under site/, create a file called bg.jpg, with some company artwork, and config.php. Remembering database and LDAP settings, this is a basic config example.
Copy site.example/ to site/, and replace bg.jpg and logo.png with some company artwork, and config.php. Remembering database and LDAP settings, enter these in config.php.

<?php
/* Timezone for the ActionQueue */
date_default_timezone_set('UTC');

/* All other options */
$config = array(
'Database' =>
array(
'name' => 'auth_main',
'host' => 'localhost',
'user' => 'auth',
'password' => '...password here...'
),
'Util' =>
array(
'Cleanup' => 'Directory Cleanup Tools'
),
'pidfile' => '/var/run/lock/meta-auth.pid',
'logfile' => '/var/log/meta-auth.log',
'login' =>
array(
'url' => 'ldap://localhost',
'domain' => "dc=example,dc=com",
'service_id' => 'ldap1',
'admin' => array('admin'),
'assistant' => array(),
'assist' =>
array(
'domain_id' => 'default',
'service_id' => 'ldap1'
)
)
'ReceiptPrinter' => array( // Receipt printer, or 0.0.0.0 for no printer
'ip' => '0.0.0.0',
'port' => '9100',
'header' => 'Example',
'footer' => 'Terms and conditions'
)
);

Note: Debian 6 Uses /var/lock, not /var/run/lock.
(Note for lock files: Debian 6 Uses /var/lock, not /var/run/lock)

Open the database up and look at the 'service' table. If you are administering LDAP on localhost (this is the default set-up), then correct the domain name and password to make it work.

Expand Down
10 changes: 9 additions & 1 deletion lib/Auth.php
Expand Up @@ -83,5 +83,13 @@ static public function alphanumeric($inp) {
static public function normaliseName($inp) {
return strtolower(preg_replace("#[^-a-zA-Z0-9.'_]+#", "", trim($inp)));
}


/**
* Return true if debugging is enabled, false if not. Some functions log less
* data and remove dangerous features when debugging is off (a good idea for production installs)
*/
static public function isDebug() {
$conf = Auth::getConfig("login");
return isset($conf['debug']) && $conf['debug'] == true;
}
}
108 changes: 61 additions & 47 deletions lib/misc/ReceiptPrinter.php
Expand Up @@ -4,63 +4,77 @@ class ReceiptPrinter {
private static $conf; /* Config */

public static function init() {
require_once(dirname(__FILE__) . "/../vendor/escpos-php/escpos.php");
require_once(dirname(__FILE__) . "/../vendor/escpos-php/Escpos.php");
self::$conf = Auth::getConfig(__CLASS__);
}

public static function pwresetReceipt(AccountOwner_model $owner, $password) {
if(!isset(self::$conf['ip']) || self::$conf['ip'] == "0.0.0.0") {
return false;
}

if(!$fp = fsockopen(self::$conf['ip'], self::$conf['port'], $errno, $errstr, 2)) {
throw new Exception("Couldn't connect to receipt printer: $errno $errstr");
}

/* Header */
$printer = new escpos($fp);
$printer -> set_justification(escpos::JUSTIFY_CENTER);
$printer -> set_emphasis(true);
$printer -> text(self::$conf['header'] . "\n");
$printer -> set_emphasis(false);
$printer -> feed();
$printer -> text("User Account Information\n");
$printer -> feed(2);
$printer -> set_justification(escpos::JUSTIFY_LEFT);

/* User info */
$barcode = "";
$seen = array();
$printer -> text("User Account:\n " . $owner -> owner_firstname . " " . $owner -> owner_surname . "\n\n");
$printer -> text("Login name(s):\n");
foreach($owner -> list_Account as $acct) {
if(!isset($seen[$acct -> account_login])) {
$printer -> text(" " . $acct -> account_login . "\n");
$seen[$acct -> account_login] = true;
if(is_numeric($acct -> account_login) && ($barcode == "" || strlen($acct -> account_login) < strlen($barcode))) {
$barcode = $acct -> account_login;
try {
$connector = new NetworkPrintConnector(self::$conf['ip'], self::$conf['port']);
$profile = SimpleCapabilityProfile::getInstance();
$printer = new Escpos($connector, $profile);

/* Header */
$printer -> setJustification(Escpos::JUSTIFY_CENTER);
if(isset(self::$conf['logo']) && file_exists(self::$conf['logo'])) {
/* Include top image if set & available */
$logofile = self::$conf['logo'];
$ser = $logofile . ".ser";
if(file_exists($ser)) {
$img = unserialize(file_get_contents($ser));
} else {
$img = new EscposImage($logofile);
@file_put_contents($ser, serialize($img)); // Attempt to cache
}
$printer -> bitImage($img);
}
}
$printer -> feed();
$printer -> text("Password:\n $password\n");
$printer -> feed(2);

/* Footer */
$printer -> text(self::$conf['footer'] . "\n");
$printer -> feed();

/* Barcode */
if($barcode != "") {
$printer -> set_justification(escpos::JUSTIFY_CENTER);
$printer -> barcode($barcode, escpos::BARCODE_CODE39);
$printer -> setEmphasis(true);
$printer -> text(self::$conf['header'] . "\n");
$printer -> setEmphasis(false);
$printer -> feed();
$printer -> text("User Account Information\n");
$printer -> feed(2);
$printer -> setJustification(Escpos::JUSTIFY_LEFT);

/* User info */
$barcode = "";
$seen = array();
$printer -> text("User Account:\n " . $owner -> owner_firstname . " " . $owner -> owner_surname . "\n\n");
$printer -> text("Login name(s):\n");
foreach($owner -> list_Account as $acct) {
if(!isset($seen[$acct -> account_login])) {
$printer -> text(" " . $acct -> account_login . "\n");
$seen[$acct -> account_login] = true;
if(is_numeric($acct -> account_login) && ($barcode == "" || strlen($acct -> account_login) < strlen($barcode))) {
$barcode = $acct -> account_login;
}
}
}
$printer -> feed();
$printer -> text("Password:\n $password\n");
$printer -> feed(2);

/* Footer */
$printer -> text(self::$conf['footer'] . "\n");
$printer -> feed();
$printer -> text($barcode);
$printer -> feed(1);
$printer -> set_justification(escpos::JUSTIFY_LEFT);

/* Barcode */
if($barcode != "") {
$printer -> setJustification(Escpos::JUSTIFY_CENTER);
$printer -> barcode($barcode, Escpos::BARCODE_CODE39);
$printer -> feed();
$printer -> text($barcode);
$printer -> feed(1);
$printer -> setJustification(Escpos::JUSTIFY_LEFT);
}
$printer -> cut();
$printer -> close();
} catch(Exception $e) {
trigger_error($e -> getMessage()); // Should be logged some-place for troubleshooting.
return false;
}
$printer -> cut();

fclose($fp);
}
}
26 changes: 19 additions & 7 deletions lib/util/Cleanup_util/Cleanup_util.php
Expand Up @@ -6,7 +6,9 @@
*
*/
class Cleanup_util extends util {
private static $config;
private static $config;

private static $debug;

/**
* Initialise utility
Expand All @@ -16,7 +18,8 @@ public static function init() {
self::verifyEnabled();

Auth::loadClass("Ou_api");
Auth::loadClass("ActionQueue_api");
Auth::loadClass("ActionQueue_api");
self::$debug = Auth::isDebug();
}

/**
Expand Down Expand Up @@ -69,12 +72,20 @@ public static function admin() {
$data['message'] = "The queue has been emptied.";
break;
case 'eraseLocal':
self::eraseLocal();
$data['message'] = "All local entries have been erased.";
if(self::$debug) {
self::eraseLocal();
$data['message'] = "All local entries have been erased.";
} else {
$data['message'] = "This feature is disabled.";
}
break;
case 'dummyData':
self::dummyData();
$data['message'] = "Dummy data has been introduced.";
if(self::$debug) {
self::dummyData();
$data['message'] = "Dummy data has been introduced.";
} else {
$data['message'] = "This feature is disabled.";
}
break;
default:
throw new Exception("Unknown action: $action");
Expand All @@ -85,7 +96,8 @@ public static function admin() {
}

$data['service-enabled'] = Service_model::list_by_service_enabled('1');
$data['service-disabled'] = Service_model::list_by_service_enabled('0');
$data['service-disabled'] = Service_model::list_by_service_enabled('0');
$data['debug'] = self::$debug;
return $data;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/util/Cleanup_util/layout/main.inc
Expand Up @@ -158,7 +158,7 @@
queue, you can clear the queue with this button:</p>
<a class="btn" href="#" onClick="emptyAq();">Empty the ActionQueue</a>
</div>

<?php if($data['debug']) { ?>
<div class="alert alert-danger">
<h3>Danger zone</h3>
<h4>Erase local database</h4>
Expand All @@ -172,6 +172,7 @@
<a class="btn btn-danger" href="#" onClick="dummyData();">Add dummy
data</a>
</div>
<?php } ?>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/vendor/escpos-php
Submodule escpos-php updated 90 files
+10 −0 .gitignore
+628 −0 Escpos.php
+27 −0 LICENSE.md
+259 −67 README.md
+32 −0 composer.json
+975 −0 composer.lock
+9 −0 doc/Makefile
+2,352 −0 doc/escpos.conf
+0 −197 escpos.php
+0 −0 example/README.md
+32 −0 example/bit-image.php
+59 −0 example/character-encodings-with-images.php
+58 −0 example/character-encodings.php
+71 −0 example/character-tables.php
+177 −0 example/demo.php
+32 −0 example/graphics.php
+8 −0 example/interface/README.md
+21 −0 example/interface/ethernet.php
+33 −0 example/interface/linux-usb.php
+50 −0 example/interface/smb.php
+28 −0 example/interface/windows-lpt.php
+31 −0 example/interface/windows-usb.php
+53 −0 example/print-from-html.php
+71 −0 example/print-from-pdf.php
+81 −0 example/qr-code.php
+96 −0 example/receipt-with-logo.php
+35 −0 example/resources/character-encoding-test-strings.inc
+ example/resources/document.odt
+ example/resources/document.pdf
+ example/resources/document.z
+ example/resources/escpos-php-small.png
+ example/resources/escpos-php.png
+ example/resources/tux.png
+21 −0 example/specific/29-latvian-star-tup592.php
+36 −0 example/specific/32-german-tm-t20-ii-custom-command.php
+7 −0 example/specific/README.md
+56 −0 src/AbstractCapabilityProfile.php
+178 −0 src/CodePage.php
+99 −0 src/DefaultCapabilityProfile.php
+66 −0 src/DummyPrintConnector.php
+4 −0 src/EposTepCapabilityProfile.php
+405 −0 src/EscposImage.php
+304 −0 src/EscposPrintBuffer.php
+72 −0 src/FilePrintConnector.php
+98 −0 src/ImagePrintBuffer.php
+39 −0 src/NetworkPrintConnector.php
+75 −0 src/PrintBuffer.php
+50 −0 src/PrintConnector.php
+17 −0 src/SimpleCapabilityProfile.php
+82 −0 src/StarCapabilityProfile.php
+12 −0 src/StarCompatibilityProfile.php
+348 −0 src/WindowsPrintConnector.php
+ src/cache/Characters-DefaultCapabilityProfile.ser.gz
+ src/cache/Characters-SimpleCapabilityProfile.ser.gz
+ src/cache/Characters-StarCapabilityProfile.ser.gz
+0 −7 test.php
+26 −0 test/bootstrap.php
+112 −0 test/integration/ExampleTest.php
+ test/integration/resources/output/bit-image.bin
+ test/integration/resources/output/character-encodings.bin
+ test/integration/resources/output/character-tables.bin
+ test/integration/resources/output/demo.bin
+ test/integration/resources/output/graphics.bin
+1 −0 test/integration/resources/output/interface-ethernet.bin
+0 −0 test/integration/resources/output/interface-linux-usb.bin
+ test/integration/resources/output/print-from-pdf.bin.z
+ test/integration/resources/output/qr-code.bin
+ test/integration/resources/output/receipt-with-logo.bin
+16 −0 test/phpunit.xml
+69 −0 test/unit/AbstractCapabilityProfileTest.php
+235 −0 test/unit/EscposImageTest.php
+150 −0 test/unit/EscposPrintBufferTest.php
+494 −0 test/unit/EscposTest.php
+252 −0 test/unit/WindowsPrintConnectorTest.php
+ test/unit/resources/black_transparent.gif
+ test/unit/resources/black_transparent.png
+ test/unit/resources/black_white.bmp
+ test/unit/resources/black_white.gif
+ test/unit/resources/black_white.jpg
+ test/unit/resources/black_white.png
+ test/unit/resources/canvas_black.bmp
+ test/unit/resources/canvas_black.gif
+ test/unit/resources/canvas_black.jpg
+ test/unit/resources/canvas_black.png
+ test/unit/resources/canvas_white.bmp
+ test/unit/resources/canvas_white.gif
+ test/unit/resources/canvas_white.jpg
+ test/unit/resources/canvas_white.png
+19 −0 test/unit/resources/demo.php
+ test/unit/resources/doc.pdf
11 changes: 8 additions & 3 deletions maintenance/bin/authqueue.php
Expand Up @@ -6,6 +6,7 @@
try{
$pidfile = Auth::getConfig('pidfile');
$logfile = Auth::getConfig('logfile');
$isDebug = Auth::isDebug();
if(!$pf = fopen($pidfile, "w")) {
throw new Exception("Couldn't open PID file $pidfile. Check that it is write-able.");
}
Expand Down Expand Up @@ -46,9 +47,13 @@

try {
if(process($next)) {
try {
$next -> aq_complete = 1;
$next -> update();
try {
if($isDebug) {
$next -> aq_complete = 1;
$next -> update();
} else {
$next -> delete();
}
} catch(Exception $e) {
outp("\tProblem marking item as done; Was it cancelled while it was running?");
}
Expand Down
1 change: 0 additions & 1 deletion maintenance/schema/data/defaults.sql
Expand Up @@ -59,4 +59,3 @@ INSERT INTO `Service` (`service_id`, `service_name`, `service_enabled`, `service
INSERT INTO `ListServiceDomain` (`service_id`, `domain_id`, `sd_root`, `sd_secondary`) VALUES
('ldap1', 'default', '', 0);

INSERT INTO `auth_main`.`ListServiceDomain` (`service_id`, `domain_id`, `sd_root`, `sd_secondary`) VALUES ('ldap1', 'default', '', '0');
10 changes: 8 additions & 2 deletions site.example/config.php
Expand Up @@ -28,12 +28,18 @@
array(
'domain_id' => 'default',
'service_id' => 'ldap1'
)
),
// Leaves data in the database, enables the directory cleanup
// "Delete all local data" button. These are useful for initial
// setup, but should be disabled afterward.
'debug' => 'true'
),
'ReceiptPrinter' => array( // Receipt printer, or 0.0.0.0 for no printer
'ip' => '0.0.0.0',
'port' => '9100',
'header' => 'Example',
'footer' => 'Terms and conditions'
'footer' => 'Terms and conditions',
// Optional - printed at top of receipts if set
'logo' => dirname(__FILE__) . "/logo.png"
)
);
Binary file added site.example/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3012082

Please sign in to comment.