From 30120827437775b868a4391d5c8d1dc226fa117e Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Sat, 23 May 2015 23:45:12 +1000 Subject: [PATCH] add option to disable debugging features for production installs, enhance receipt printing --- README.md | 44 +--------- lib/Auth.php | 10 ++- lib/misc/ReceiptPrinter.php | 108 ++++++++++++++----------- lib/util/Cleanup_util/Cleanup_util.php | 26 ++++-- lib/util/Cleanup_util/layout/main.inc | 3 +- lib/vendor/escpos-php | 2 +- maintenance/bin/authqueue.php | 11 ++- maintenance/schema/data/defaults.sql | 1 - site.example/config.php | 10 ++- site.example/logo.png | Bin 0 -> 3292 bytes 10 files changed, 110 insertions(+), 105 deletions(-) create mode 100644 site.example/logo.png diff --git a/README.md b/README.md index 95a3165..e1f57dc 100644 --- a/README.md +++ b/README.md @@ -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. - - 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. diff --git a/lib/Auth.php b/lib/Auth.php index 1cb4e75..20c9894 100644 --- a/lib/Auth.php +++ b/lib/Auth.php @@ -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; + } } \ No newline at end of file diff --git a/lib/misc/ReceiptPrinter.php b/lib/misc/ReceiptPrinter.php index c5c67b0..85433d6 100644 --- a/lib/misc/ReceiptPrinter.php +++ b/lib/misc/ReceiptPrinter.php @@ -4,7 +4,7 @@ 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__); } @@ -12,55 +12,69 @@ 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); } } diff --git a/lib/util/Cleanup_util/Cleanup_util.php b/lib/util/Cleanup_util/Cleanup_util.php index 5b4dc44..4b064bc 100644 --- a/lib/util/Cleanup_util/Cleanup_util.php +++ b/lib/util/Cleanup_util/Cleanup_util.php @@ -6,7 +6,9 @@ * */ class Cleanup_util extends util { - private static $config; + private static $config; + + private static $debug; /** * Initialise utility @@ -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(); } /** @@ -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"); @@ -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; } diff --git a/lib/util/Cleanup_util/layout/main.inc b/lib/util/Cleanup_util/layout/main.inc index 476b094..f02115c 100644 --- a/lib/util/Cleanup_util/layout/main.inc +++ b/lib/util/Cleanup_util/layout/main.inc @@ -158,7 +158,7 @@ queue, you can clear the queue with this button:

Empty the ActionQueue - +

Danger zone

Erase local database

@@ -172,6 +172,7 @@ Add dummy data
+ diff --git a/lib/vendor/escpos-php b/lib/vendor/escpos-php index 4257a17..5bbc8c9 160000 --- a/lib/vendor/escpos-php +++ b/lib/vendor/escpos-php @@ -1 +1 @@ -Subproject commit 4257a17fb39810a627548f0668001ed9d6672123 +Subproject commit 5bbc8c966632d826c33a8f64fb8e0233c125e556 diff --git a/maintenance/bin/authqueue.php b/maintenance/bin/authqueue.php index e63d858..efcfb50 100755 --- a/maintenance/bin/authqueue.php +++ b/maintenance/bin/authqueue.php @@ -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."); } @@ -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?"); } diff --git a/maintenance/schema/data/defaults.sql b/maintenance/schema/data/defaults.sql index cbca4d6..0266200 100644 --- a/maintenance/schema/data/defaults.sql +++ b/maintenance/schema/data/defaults.sql @@ -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'); diff --git a/site.example/config.php b/site.example/config.php index f302e42..b131a92 100644 --- a/site.example/config.php +++ b/site.example/config.php @@ -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" ) ); diff --git a/site.example/logo.png b/site.example/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..47bbc99cd7f76d6e67ed6855453a0266e136a67d GIT binary patch literal 3292 zcmbVP_dDB*7yh6&v70KYw3phewMVVmo1&`rtb|&jQ9?_qHEWC2)~u*4c4CxkRn-=n zxK^!1ORZdd-GAZxoaemfJn#A8eSbO6b55eAxdAKFbtV7+Sd9$ztO0=P{$+2-KzE7A zCdrV?Lg#K`pa)$17bRU48J7%WkfGz{gqiEVqyq8_u3eJ!p+;u<^aNTkE4M)4KckbE z6mO`$L#S>b1mXn^1$2YG+(NxPZ^HaSeQz2VnOWM$g1`X4qGzP1Z5y$$TL`bSvlAH9 z%6TjNi_?-ZnftqEl&4?!7`Xf&yq;8^yp_kE)r_U8zp+{VyGI$Rre;m0dUAt%9Qm;y z+~0U)$cXFFYDeAjM+Cjsnjw$!A38rRZaz|>s7n*ZM~jjgZ@_E*IAObH0?(qi@f)GMO7qzw=m8}MQH9%7?y#>$1DM9> zDE3@>Nt)~xkfb-27VTlvdCJ-`4vwWsO8Ps7o%HSF0uK=!yB~l)f7;;SkH6JYcN{#> zvX(Wii%>(vAA&Bfd2E6&(~*a{ZC?}ZiRGiAL#L7Yz+yM;ewHC>$4nc z8I!Lu6U9Ijciwq{NKRk-9h?m(_5yc)R^E?wArEyxJbgxuR-HKWYF$d4VRlu3J*wvJ z5QKaCf$ekiD&?#F1OtCAD(ef;l}?h4W2lZWvFeO&i^@hk=V zVfh-G0X9Z zS1jtvL#y^R*?>XIoy0TbVXS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