kidpressingbuttons Posted March 27, 2014 Posted March 27, 2014 Hello All, We are currently looking into implementing Papercut in our school, it has already been set up and is ready to go!! However we want to be able to add a daily generated password for the morning and afternoon which the staff and students would have to enter to be able to print, have had a look into this but just wanted to know if anyone else has had any experience with this?
MicrodigitUK Posted March 27, 2014 Posted March 27, 2014 Yes, you can do this with department pin codes that reset twice a day. I have a script somewhere for my student shard acounts that dose that. I'll see if I can dig it out. 1
kidpressingbuttons Posted March 27, 2014 Author Posted March 27, 2014 That would be extremely helpful thank you!
ICTonto Posted March 27, 2014 Posted March 27, 2014 You can create a shared account with a PIN code if that is what you are asking?
kidpressingbuttons Posted March 28, 2014 Author Posted March 28, 2014 Mostly along the lines that MicroDigitUK was saying. But I'm open to any other suggestions if you have any?
ICTonto Posted March 28, 2014 Posted March 28, 2014 MicroDigitUK is spot on, there is a scripting recipe for this called "Require Approval Code", however i don't know how to cycle through PIN codes automatically, might be worth asking papercut support they are very helpful.
Big_Ted Posted March 28, 2014 Posted March 28, 2014 Sounds like something that would require some upkeep. people asking for passwords and then new passwords being created. If you are going to tell them the password anyway what is the point of ever changing it In my experience you would be better off using 1 of the many other features in papercut to keep an eye and restrict printing.
MicrodigitUK Posted March 28, 2014 Posted March 28, 2014 OK, this script is to reset shared accounts. All of the shared account names must start with "STUDENT" or the script will ignore them. e.g. I have student shared accounts called "STUDENT Art", "STUDENT D and T" and "STUDENT ICT" ... This BAT/CMD script is then just scheduled to run at the times you wish to reset the pin codes for the shared accounts. You, will need to set the SERVER_COMMAND to the correct path. This must be the shortened abbreviation old DOS style path e.g. "c:\Progra~1" and not "C:\Program Files". Had issues running the script with full path. @echo off setlocal EnableDelayedExpansion ::set SERVER_COMMAND="%~d0%~p0..\..\..\bin\win\server-command.exe" ::set SERVER_COMMAND="C:\Program Files\PaperCut NG\server\bin\win\server-command.exe" set SERVER_COMMAND=c:\Progra~1\PaperC~1\server\bin\win\server-command.exe set ACTION="set-shared-account-property" set /a number=0 FOR /f "delims=" %%A in ('%SERVER_COMMAND% list-shared-accounts') DO ( IF /i %number% LSS 1234 ( Call :_RandomNumber ) call :studentcheck "%%A" set /a number=0 ) :studentcheck set str=%1 :: remove ampasand from string to prevent errors after removing quotes set str=%str:&=% :: Remove quotes from string set str=%str:~1,-1% :: Trim string to the first 7 chars set str=%str:~0,7% :: if the string is student it is a student account IF /I "%str%"=="STUDENT" ( FOR /f "tokens=1 delims=" %%B in ('%SERVER_COMMAND% get-shared-account-property %1 disabled') DO ( :: see if the acount is disabled and skip if it is IF /I "%%B"=="true" ( GOTO :eof ) ELSE ( ::Set the random pin number %SERVER_COMMAND% %ACTION% %1 "pin" %number% ) ) ) GOTO :eof :_RandomNumber :_setmax set /a max=%random% if %max% LSS 8000 GOTO _setmax :_setmaxrand set /a maxrand=%random% if %maxrand% LSS 10000 GOTO _setmaxrand set /a min=%random%%%7999 set /a range=%max%-%min% set /a minrand=%random%%%9999 set /a rangerand=%maxrand%-%minrand% set /a rand=%random%%%3 set /a number=(((%random% - %minrand%) * %range%) / ((%rangerand% + %min%) ^^ %rand%)) if %number% LSS 9999 Call :_RandomNumber GOTO :EOF :_End 1
MicrodigitUK Posted March 28, 2014 Posted March 28, 2014 Part 2: Ok once you have all of your student shared account codes reset you will need to easily view them. This script will output all of the "STUDENT" shared accounts to a JASON formatted file. This can then be read by a web based application and displayed on a staff intranet or VLE page. The script also uses "Iconv" to convert character encoding as most systems read JASON in UTF-8 format. Iconv can be downloaded from: http://gnuwin32.sourceforge.net/downlinks/libiconv-bin-zip.php SERVER_COMMAND, JSONFILEPATH and JSONTEMPFILE should be changed to meet the setup of your server. @echo off set JSONFILEPATH="C:\Program Files\PaperCut NG\server\custom\web\StudentPins.json" set JSONTEMPFILE="C:\Program Files\PaperCut NG\server\custom\web\TempStudentPins.json" if exist %JSONTEMPFILE% (del %JSONTEMPFILE%) ::set SERVER_COMMAND="C:\Program Files\PaperCut MF\server\bin\win\server-command.exe" set SERVER_COMMAND=c:\Progra~1\PaperC~1\server\bin\win\server-command.exe setlocal EnableDelayedExpansion echo { > %JSONTEMPFILE% echo "data": >> %JSONTEMPFILE% echo [ >> %JSONTEMPFILE% SET /A COUNT=0 FOR /f "delims=" %%A in ('%SERVER_COMMAND% list-shared-accounts') DO (call :studentcheck "%%A") echo %last% echo ]} >> %JSONTEMPFILE% ::move /Y %JSONTEMPFILE% %JSONFILEPATH% iconv -f ISO-8859-1 -t UTF-8 %JSONTEMPFILE% > %JSONFILEPATH% if exist %JSONTEMPFILE% (del %JSONTEMPFILE%) :studentcheck set str=%1 :: remove ampasand from string to prevent errors after removing quotes set str=%str:&=% :: Remove quotes from string set str=%str:~1,-1% :: Trim string to the first 7 chars set str=%str:~0,7% :: if the string is student it is a student account IF /I "%str%"=="STUDENT" ( FOR /f "tokens=1 delims=" %%B in ('%SERVER_COMMAND% get-shared-account-property %1 disabled') DO ( :: see if the acount is disabled and skip if it is IF /I "%%B"=="true" ( GOTO :eof ) ELSE ( FOR /f "tokens=1 delims=" %%C in ('%SERVER_COMMAND% get-shared-account-property %1 notes') DO ( IF /I "%%C"=="Hidden" ( GOTO :eof ) ELSE ( call :studentcheck2 %1 "%%C" GOTO :eof ) ) call :studentcheck2 %1 "" ) ) ) GOTO :eof :studentcheck2 FOR /f "tokens=1 delims=" %%D in ('%SERVER_COMMAND% get-shared-account-property %1 pin') DO ( FOR /f "tokens=1 delims=" %%E in ('%SERVER_COMMAND% get-shared-account-property %1 balance') DO ( FOR /f "tokens=1 delims=" %%F in ('%SERVER_COMMAND% get-shared-account-property %1 restricted') DO ( IF "!COUNT!"=="0" ( echo {"Account": %1, "Pin": "%%D", "Balance": "%%E", "Restricted": "%%F", "Notes": %2} >> %JSONTEMPFILE% ) ELSE ( echo ,{"Account": %1, "Pin": "%%D", "Balance": "%%E", "Restricted": "%%F", "Notes": %2} >> %JSONTEMPFILE% ) SET /A COUNT+=1 ) ) ) GOTO :eof :_End 1
MicrodigitUK Posted March 28, 2014 Posted March 28, 2014 Part 3: The web app to display the information from your JASON file on your VLE or intranet to the staff to distribute the shared account codes. I have published 2 options but you could re-produce this in ASP.net, SharePoint, or as a Moodle block. My 2 options given are as simple PHP page and a Frog3 widget. PHP version (just change "$JSONfile" to point to your JSON file): "http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"> Papercut Student Printing Pins <br /> body {background:white; font-family:arial; font-size:10pt; color:#333333;}<br /> div.row {cursor:pointer}<br /> div.el {float:left; width:200px;}<br /> .restr {color:#FE9621; font-weight:bold}<br /> tr.oddrow {background:#EAECEC; }<br /> tr.oddrow2 {background:#fed671; }<br /> tr.evenrow {}<br /> tr :hover {background:#d1e7f0}<br /> span.pinno {font-size:1.2em; background:yellow; padding:1px 3px}<br /> <br /> td.col1 {padding:2px 20px 0 5px; cursor:pointer}<br /> .col2 {padding:5px 0 0 15px}<br /> <br /> table.pcut {border-collapse:collapse; border:0; padding:0; width:100%}<br /> table.pcut td {vertical-align:middle; text-align:left; font-size:1em; border:1px solid #D4D8D8; border-width:1px 0; padding:2px 0 2px 10px}<br /> div.spacerbox {clear:both; height:2500px; width:100%;}<br /> <br /> div.moduleHeader {display: none;}<br /> div.moduleFooter {display: none;}<br /> <br /> //<![CDATA[<br /> <br /> onload=function(){<br /> if (document.getElementsByClassName == undefined){<br /> document.getElementsByClassName = function(className){<br /> var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");<br /> var allElements = document.getElementsByTagName("*");<br /> var results = [];<br /> <br /> var element;<br /> for (var i = 0; (element = allElements[i]) != null; i++){<br /> var elementClass = element.className;<br /> if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass)){<br /> results.push(element);<br /> }<br /> }<br /> <br /> return results;<br /> }<br /> }<br /> }<br /> <br /> change = function(what) {<br /> var e=document.getElementById(what);<br /> if(e.style.display == 'block'){<br /> e.style.display = 'none';<br /> }<br /> else{<br /> e.style.display = 'block';<br /> }<br /> var arr = document.getElementsByClassName("col2");<br /> for (i = 0; i < arr.length; i++) {<br /> if (arr[i].id != what) {<br /> arr[i].style.display = 'none';<br /> }<br /> }<br /> }<br /> //]]><br /> $JSONfile = "http://papercutserver:9191/custom/StudentPins.json"; //populate array with mounths $month_name[0]="January"; $month_name[1]="February"; $month_name[2]="March"; $month_name[3]="April"; $month_name[4]="May"; $month_name[5]="June"; $month_name[6]="July"; $month_name[7]="August"; $month_name[8]="September"; $month_name[9]="October"; $month_name[10]="November"; $month_name[11]="December"; function http_file_exists($url, $followRedirects = true) { $url_parsed = parse_url($url); extract($url_parsed); if (!@$scheme) $url_parsed = parse_url('http://'.$url); extract($url_parsed); if(!@$port) $port = 80; if(!@$path) $path = '/'; if(@$query) $path .= '?'.$query; $out = "HEAD $path HTTP/1.0\r\n"; $out .= "Host: $host\r\n"; $out .= "Connection: Close\r\n\r\n"; if(!$fp = @fsockopen($host, $port, $es, $en, 5)){ return false; } fwrite($fp, $out); while (!feof($fp)) { $s = fgets($fp, 128); if(($followRedirects) && (preg_match('/^Location:/i', $s) != false)){ fclose($fp); return http_file_exists(trim(preg_replace("/Location:/i", "", $s))); } if(preg_match('/^HTTP(.*?)200/i', $s)){ fclose($fp); return true; } } fclose($fp); return false; } // try up to 5 times to read the JSON file from $JSONfile for ($x=0; $x<=5; $x++){ //read the JSON file from Papercut server if (http_file_exists($JSONfile)) { $handle = fopen($JSONfile, "rb"); while ( !feof($handle) ) { $myJSONObject = fread($handle, 8192); } fclose($handle); } //decode jeason into array $pcutjson = json_decode($myJSONObject, true); if (!empty($pcutjson)) { //brack out of th for loop if JSON was returned $x=5; } } //check if ther was jason data returned from the file if (empty($pcutjson)) { echo(' Sorry, there are no published printer pins. Please let ICT Support know so we can fix it!'); } else { /////pins found $pcutitems = count($pcutjson['data']); $inner = "</pre><table class="pcut">"; for ($j=0;$j<$pcutitems;$j++) { $balance = round($pcutjson['data'][$j]['Balance']*-100); // 123.45 67.8 .09 0 .1 if (strlen((string)$balance) == 2) { $bal = "0.".substr((string)$balance,(strlen((string)$balance)-2),strlen((string)$balance)); } elseif (strlen((string)$balance) == 1) { $bal = "0.0".substr((string)$balance,(strlen((string)$balance)-2),strlen((string)$balance)); } else { $bal = substr((string)$balance,0,strlen((string)$balance)-2) .".". substr((string)$balance,strlen((string)$balance)-2,strlen((string)$balance)); // 123.45 67.80 .9 .0 .10 } /////classify even table rows so they can be styled if ($j%2) { /////check whether papercut account is restricted, if so highlight text to differentiate if ($pcutjson['data'][$j]['Restricted']=="true") { $inner = $inner."".$pcutjson['data'][$j]['Account']."Pin: ".$pcutjson['data'][$j]['Pin']." ".$month_name[date('m')-1]." balance: £ ".$bal." Notes: ".$pcutjson['data'][$j]['Notes'].""; } else { $inner = $inner."".$pcutjson['data'][$j]['Account']."Pin: ".$pcutjson['data'][$j]['Pin']." ".$month_name[date('m')-1]." balance: £ ".$bal.""; } } else { /////check whether papercut account is restricted, if so highlight text to differentiate if ($pcutjson['data'][$j]['Restricted']=="true") { $inner = $inner."".$pcutjson['data'][$j]['Account']."Pin: ".$pcutjson['data'][$j]['Pin']." ".$month_name[date('m')-1]." balance: £ ".$bal." Notes: ".$pcutjson['data'][$j]['Notes'].""; } else { $inner = $inner."".$pcutjson['data'][$j]['Account']."Pin: ".$pcutjson['data'][$j]['Pin']." ".$month_name[date('m')-1]." balance: £ ".$bal.""; } } } $inner = $inner."</table>";<br> echo($inner);<br> }<br><br> ?><br> <b 1
MicrodigitUK Posted March 28, 2014 Posted March 28, 2014 Frog3 UWA Widget version: "http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"> xmlns:widget="http://www.netvibes.com/ns/" xmlns:frog="http://fdp.frogtrade.com/ns/"> Papercut Student Pins FDP v4 <br /> //<![CDATA[<br /> // http://printserver.local:9191/server/custom/web/StudentPins.json<br /> var uid = UWA.Environment.user.id;<br /> var mybaseobj = {};<br /> var servuri = widget.getValue('servuri');<br /> var servport = widget.getValue('servport');<br /> var jsonfile = widget.getValue('jsonfile');<br /> var pcutitems = 0;<br /> <br /> var thismonth=new Date();<br /> var month_name=new Array(12);<br /> month_name[0]="January"<br /> month_name[1]="February"<br /> month_name[2]="March"<br /> month_name[3]="April"<br /> month_name[4]="May"<br /> month_name[5]="June"<br /> month_name[6]="July"<br /> month_name[7]="August"<br /> month_name[8]="September"<br /> month_name[9]="October"<br /> month_name[10]="November"<br /> month_name[11]="December"<br /> <br /> change = function(what) {<br /> UWA.extendElement(widget.body.getElementsByClassName(what)[0]).toggle();<br /> for (var k=0;k<pcutitems;k++) {<br /> var h = UWA.extendElement(widget.body.getElementsByClassName("id"+k)[0]);<br /> if ("id"+k != what) {<br /> h.hide();<br /> }<br /> }<br /> }<br /> <br /> widget.environment.handleLinks = function(){};<br /> widget.onLoad = function(){<br /> //alert("onload pcutitems="+pcutitems);<br /> UWA.Data.getJson(servuri+":"+servport+"/custom/"+jsonfile,mybaseobj.process);<br /> var c = widget.createElement('div');<br /> c.addClassName('spacerbox');<br /> widget.addBody(c);<br /> }<br /> <br /> mybaseobj.process = function(pcuttext) {<br /> var pcutjson = eval("("+pcuttext+")");<br /> if (!pcutjson.data) {<br /> widget.setBody('<p style="color:red">Sorry, there are no published printer pins. Please let ICT Support know so we can fix it!');<br /> }<br /> else {<br /> /////pins found<br /> pcutitems = pcutjson.data.length;<br /> <br /> var parray = new Array(pcutjson.data.length);<br /> for (var i=0;i<pcutjson.data.length;i++) {<br /> parray[i] = new Array(6);<br /> parray[i][0] = "id"+i;<br /> parray[i][1] = pcutjson.data[i].Account;<br /> parray[i][2] = pcutjson.data[i].Pin;<br /> parray[i][3] = pcutjson.data[i].Balance;<br /> parray[i][4] = pcutjson.data[i].Restricted;<br /> parray[i][5] = pcutjson.data[i].Notes;<br /> }<br /> <br /> var pinstable = widget.createElement('div');<br /> var inner = "<table class='pcut'>";<br /> for (var j=0;j<parray.length;j++) {<br /> /////65533 is the ASCII character code for £ symbol, 163 is UTF8<br /> /////strip the notes to include on amount<br /> /*var searchar = String.fromCharCode(163);<br /> var startchar = parray[j][5].search(searchar)+1;<br /> var endchar = parray[j][5].length;<br /> var restricttext = parray[j][5].substring(startchar,endchar);*/<br /> var balance = Math.round(parray[j][3]*-100); // 123.45 67.8 .09 0 .1<br /> var num = parseInt(balance).toString(); // 12345 6780 9 0 10<br /> if (num.length == 2) {<br /> var bal = "0."+num.substring(num.length-2,num.length);<br /> }<br /> else if (num.length == 1) {<br /> var bal = "0.0"+num.substring(num.length-2,num.length);<br /> }<br /> else {<br /> var bal = num.substring(0,num.length-2) +"."+ num.substring(num.length-2,num.length); // 123.45 67.80 .9 .0 .10<br /> }<br /> <br /> /////classify even table rows so they can be styled<br /> if (j%2) {<br /> /////check whether papercut account is restricted, if so highlight text to differentiate<br /> if (parray[j][4]=="true") {<br /> inner += "<tr class='evenrow'><td class='col1' onClick='change(\""+parray[j][0]+"\")'><span class='restr'>"+parray[j][1]+"<div class='col2 "+parray[j][0]+"' style='display: none;'><b>Pin: <span class='pinno'>"+parray[j][2]+" <b>"+month_name[thismonth.getMonth()]+" balance: £ "+bal+"<br /><b class='restr'>Notes: "+parray[j][5]+"";<br /> }<br /> else {<br /> inner += "<tr class='evenrow'><td class='col1' onClick='change(\""+parray[j][0]+"\")'>"+parray[j][1]+"<div class='col2 "+parray[j][0]+"' style='display: none;'><b>Pin: <span class='pinno'>"+parray[j][2]+" <b>"+month_name[thismonth.getMonth()]+" balance: £ "+bal+"";<br /> }<br /> }<br /> else {<br /> /////check whether papercut account is restricted, if so highlight text to differentiate<br /> if (parray[j][4]=="true") {<br /> /////find ASCII or UTF8 character code for the evasive £ symbol (depending on json encoding)<br /> //alert("char 22 = "+parray[j][5].charAt(22)+" in ASCII/UTF8 = "+parray[j][5].charCodeAt(22)+" so restrict: "+restricttext);<br /> inner += "<tr class='oddrow'><td class='col1' onClick='change(\""+parray[j][0]+"\")'><span class='restr'>"+parray[j][1]+"<div class='col2 "+parray[j][0]+"' style='display: none;'><b>Pin: <span class='pinno'>"+parray[j][2]+" <b>"+month_name[thismonth.getMonth()]+" balance: £ "+bal+"<br /><b class='restr'>Notes: "+parray[j][5]+"";<br /> }<br /> else {<br /> inner += "<tr class='oddrow'><td class='col1' onClick='change(\""+parray[j][0]+"\")'>"+parray[j][1]+"<div class='col2 "+parray[j][0]+"' style='display: none;'><b>Pin: <span class='pinno'>"+parray[j][2]+" <b>"+month_name[thismonth.getMonth()]+" balance: £ "+bal+"";<br /> }<br /> }<br /> }<br /> inner += "";<br /> pinstable.setHTML(inner);<br /> widget.setBody(pinstable);<br /> }<br /> } <br /> //]]><br /> <br /> body {background:white; font-family:arial; font-size:10pt; color:#333333;}<br /> div.row {cursor:pointer}<br /> div.el {float:left; width:200px;}<br /> .restr {color:#FE9621; font-weight:bold}<br /> tr.oddrow {background:#EAECEC; }<br /> tr.oddrow2 {background:#fed671; }<br /> tr.evenrow {}<br /> tr :hover {background:#d1e7f0}<br /> span.pinno {font-size:1.2em; background:yellow; padding:1px 3px}<br /> <br /> td.col1 {padding:2px 20px 0 5px; cursor:pointer}<br /> .col2 {padding:5px 0 0 15px}<br /> <br /> table.pcut {border-collapse:collapse; border:0; padding:0; width:100%}<br /> table.pcut td {vertical-align:middle; text-align:left; font-size:1em; border:1px solid #D4D8D8; border-width:1px 0; padding:2px 0 2px 10px}<br /> div.spacerbox {clear:both; height:2500px; width:100%;}<br /> Retrieving pins...
MicrodigitUK Posted March 28, 2014 Posted March 28, 2014 @kidpressingbuttons a bit of background into how we use shard accounts and scripts in my school. We use the PaperCut with shared accounts and don’t give anyone credit on their personal accounts. We use the shared accounts as department accounts, similar to how most schools do on their photocopiers. Each department has a pin code and they enter that code in the popup window to release there prints. Also for students/pupils printing each department has a second student pin code. The only difference being that the student codes change twice a day. (Done with a simple script and scheduled task) This is to stop students memorizing pin codes and printing to the incorrect department. All department pin codes are published on intranet/VLE for staff access only, Staff then only give out the code to classes when they want students/pupils to print. At the end of each month the total of Staff and Student shared accounts are charged back to the departments covering toner and paper. (Departments are allocated in budgets enough funds to cover their printing charges.)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now