How to print in duplex mode with smblient? - printing

Because I don't want to give any information about a corporate printer to CUPS, because I suspect it trying to access it even when I'm not on the corporate network, I use the following "script" to print documents on a corporate printer managed by a Windows print server:
smbclient "//printserv.acme.corp/BUILDING0PRINTER1" "password" -c "print /tmp/my.pdf" -U "username" -W "Domain"
The printer is some HP MFP and can very well print duplex. My command, however, does not print duplex.
My question is: How to print a PDF in duplex mode (such that both sides of the paper sheet are used, aka flip on long edge)?
I don't mind extending my "script" by prepending some weird PCL or Postscript commands, but I don't want CUPS to be searching for the printer (and potentially send my password into the ether).

I found that pdftops provides a -duplex switch.
So I scripted the following:
pdftops -paper A4 -duplex "$1" "${1}.ps"
smbclient "//printserv.acme.corp/BUILDING0PRINTER1" "password" -c "print \"${1}.ps\"" -U "username" -W "Domain"

Related

CUPS Printer added using command prompt is not working with authentication

I have a CUPS server setup in Linux.I want to add this printer to my windows programmatically. Manually I am able to add.By searching various forums I found the following command:
rundll32 printui.dll,PrintUIEntry /if /b "TestPrinter_With_Auth" /f %windir%\inf\ntprint.inf /r "https://username:pasword#ipp.devCups.com/printers/Printer" /m "HP Color LaserJet 2500 PCL6 Class Driver"
I could install Printer using this command. But I couldn't Print to CUPS as it is not recognizing the credentials. I get access denied.
Any suggestion to achieve this programmatically.
Thanks in Advance
Matt

How to configure user and password for neo4j cluster without REST API

The version I use is neo4j-enterprise-2.2.0-M02
My question is :
How can I configure a user (like add a new user, change the password ,etc) in backend or browser, instead of REST API? Can I do it via neo4j-shell? imagine that I am a DBA, it is not very convenient to do this by REST API.
Any help will be greatly appreciated!
You can use the browser instead of the API. Just go to http://localhost:7474 (or whatever IP to which the web console is bound) and you will be prompted to change the password. Once authenticated, use the command :server change-password to change the password again.
It is not yet possible to create multiple user accounts within the system.
You can use the command :help server to see available authentication commands.
Although still utilizing the REST API, I'll throw the cURL option out there to anyone who doesn't have access to a web browser (AWS instance, for example):
$ curl -H "Content-Type: application/json" -X POST -d '{"password":"WHATEVER THE PASSWORD IS"}' -u neo4j:neo4j http://localhost:7474/user/neo4j/password
Another option is to modify the auth file directly and restart neo. Doing this, you can even change the username!
Run
find / -name dbms
For me this gave one hit:
/var/lib/neo4j/data/dbms/auth
Save this code as build_auth_string.sh:
#!/bin/bash
DEFAULT_IFS="$IFS"
SALT_LEN=32
# either read from stdin or use the argument
if [ -z "$1" ]; then
read INPUT
else
INPUT="$1"
fi
if [ -z "$INPUT" ]; then
echo "correct format <uname:pass>"
exit
fi
IFS=':'
read -a UNAME_PASS <<< "$INPUT"
UNAME="${UNAME_PASS[0]}"
PASS="${UNAME_PASS[1]}"
# representing the password in hex format like \xAB\x0C etc
# HEX_PASS=$(echo -n $PASS | xxd -p | awk '{print toupper($1);}' | sed -r 's/(.{2})/\\x\1/g')
HEX_PASS=$(echo -n $PASS | hexdump -v -e '"\\\x" 1/1 "%02X"')
# echo $HEX_PASS
# create the salt and store it in hex format
SALT=$(cat /dev/urandom | tr -dc 'a-f0-9' | fold -w $SALT_LEN | head -n 1)
# SALT="28FD26AD92D6D2D8820E969F3F3732B4"
HEX_SALT=$(echo -n $SALT | sed -r 's/(.{2})/\\x\1/g')
# calculate the sha256 sum of the salt and password value
# need to split the output because the output ends with a hyphen
IFS=' '
read -a PASSWORD_HASH_ARRAY <<< $(printf $HEX_SALT$HEX_PASS | sha256sum)
PASSWORD_HASH="${PASSWORD_HASH_ARRAY[0]}"
# echo "$UNAME;$PASS;$SALT"
# echo "$PASSWORD_HASH"
# and print out the auth string
COMBINED=$(echo -n "$PASSWORD_HASH,$SALT" | awk '{print toupper($1);}')
echo "$UNAME:SHA-256,$COMBINED:"
IFS="$DEFAULT_IFS"
The code for the above came from https://github.com/artsince/docker-neo4j-auth/blob/master/build_auth_string.sh - im posting it here just encase..
And then just run the above script like
build_auth_string.sh myUsername:myP#ssw0rd
Copy/paste that into your auth file replacing whatever was there before, and restart neo4j :)
A fresh install of Neo4j 2.2.x has a user 'neo4j', with an initial password 'neo4j'. You are required to change the password before you can do anything.
It's easy to do this from the command line, by calling httpie to interact with the REST API. For example, to set a new password of 'foobar', run this command:
http -a neo4j:neo4j POST http://localhost:7474/user/neo4j/password password=foobar
If you want to reset the password and you dont know the old password :
then for Windows user
go to this path:
C:\Users\xyz\Documents\Neo4j\default.graphdb\dbms
and delete that auth file.
Restart the neo4j they will again ask to set the username and password!!
by default
username:neo4j
password:neo4j
Currently it's not possible to configure authorization using neo4j-shell. As you've mentioned the REST API is the way to go. Using a convenient REST client this is very easy.
My tools of choice is either postman (a plugin for chrome browser) or httpie for the command line. E.g. with httpie changing the password for a user is as simple as:
http localhost:7474/user/neo4j/password password=neo4j new_password=mypass
Be aware that password (and other authorization settings) are not automatically distributed in a cluster, see the manual how to copy over settings between instances.
For Mac users, version 2.3.1 of Neo4J, best way to reset credentials is to remove the file with credential information and start the service again.
Steps to follow
Find where the file that contains credentials is located from the browser console (localhost:7474). Go to Star (Favourites)->System->Server configuration
Search for dbms.security.auth_store.location property to see where it points to. In my case it was /Users/felipe/Documents/Neo4j/default.graphdb/./dbms/auth
Delete that file.
Start the service again and go to the console again (localhost:7474).
By default you will be asked to set the password for the user neo4j.
I hope it helps.
To elaborate on felipe's response (since I do not have enough rep points to comment):
I stopped the server, I deleted the auth files in BOTH:
DBROOT\data\auth
DBROOT\dbms\auth
Restarted the server, and connected to it via the localhost:7474, used the default username/password (neo4j/neo4j) and then it prompted me for a new password.
On Neo4j 4.0+, you can run:
$ cypher-shell
If it's the first time you connect, you can enter neo4j as user and password and you will be prompted to set a new password.
If you want to change the password afterwards, you can write in the Cypher shell:
:server change-password

make an lp script into functioning printer

I'm trying to print to separate printers simultaneously in Ubuntu 14.04
From all of my reading the best option I've seen is to write a script
that sends an lp command to the separate printers.
This is the script I've written so far
!/bin/bash
lp -d printer "$#"
lp -d printer2 "$#"
where printer and printer 2 are the actual printers installed on the system
This script works from a terminal, however I would like to be able to send print jobs directly to a "printer" that is actually the script I've written.
How can I make this lp script into a "printer"
Ok I didn't find a way to do this the way I originally intended, however it is possible with tea4CUPS
great cups backend tool with an easy config file
http://www.pykota.com/software/tea4cups/download
The install instructions are on the download page.
As for printing to multiple printers, add this command in the config file for every printer you wish to print to.
prehook_firstprinter: /usr/bin/lp -d Name of Printer -o raw $TEADATAFILE
Here are the simplest instructions I could write
1. download the tea4cups.gz
Extract it to the home folder, rename it to tea4cups
Open a terminal and run these commands
sudo cp /home/manifester/tea4cups/tea4cups.conf /etc/cups
sudo cp /home/manifester/tea4cups/tea4cups /usr/lib/cups/backend/
sudo chmod 700 /usr/lib/cups/backend/tea4cups
Run this command
sudo gedit /etc/cups/tea4cups.conf
Paste this in the bottom of the document
prehook_firstprinter: /usr/bin/lp -d Name of Printer yes the literal name in the printer window -o raw $TEADATAFILE
you will need a new line for every printer you have, so if you want to print to 3 printers you will need three of the above line each having the name of the printer it will be talking to.
save and close everything
open a terminal and run
sudo service cups restart
open a web browser and go to the browser cups controller
http://localhost:631/admin
go to Add Printer
you should see a printer named "tea4CUPSnothing"
If you don't see it go back and press "Find Printers"
it should be there
Change the info of the printer to "Print all" for all type fields"
Press Continue
The generic printer driver works because the printer doesn't actually exist.
Press Continue
Set Defaults
you should be done, go to your printer window on ubuntu and do a test print.

Reading netstat Output to Install Printer

Long story behind it, but here's what I'm trying to do:
I am working on a remote virtual machine implementation, where depending on the client device's location, the appropriate network printer will be installed via batch file (no VBS or PowerShell).
So, my idea is this:
Run netstat -an -p tcp to find the line containing port 49404.
Filter that output to grab the second IP address that will be
returned
Replace last octet of that IP with "250" (the printer IP
for each network)
Run nslookup on newly calculated IP to obtain
the name of that printer
Install printer by name.
Here's what I do have so far, pieced together from older posts around the web (I haven't gotten to steps 4 or 5 yet):
#echo off
netstat -p tcp -an | FIND "49404" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~9%
set "ip=%IP%"
for /f "tokens=1-4 delims=. " %%a in ("%ip%") do (
set octetA=%%a
set octetB=%%b
set octetC=%%c
set octetD=232
)
I'm sure there are cleaner or more efficient ways to perform this task, so I'm hoping you all can point me in the right direction. Thanks!

Script to add network printer to all users x64 bit print server

I use to use this script for Windows XP but since we're doing the switchover to 7 I tried to use it on the new images. It seems like it tries but it doesn't work. I have created a 64bit print server and these machines are 64bit which is the only difference. I read up on this and saw there was a GPO that needed to be set to allow this to work. Which was - Computer Configuration > Administrative Templates > Printers > Allow Print Spooler to accept client connections.
I have tried everything and can't get this to work, it doesn't give me an error or anything. It gives me the prompts for PC name and Printer name, then says 'Adding printer' from the echo command, and just sits there. I can run the command by itself and it doesn't work either....... Please help!
The main thing is that the printer needs to be added from a print server and to the computer for all users as their default.
#echo off
echo PC Name
set /p PC=
echo Printer Name
set /p PRINTER=
ECHO Adding Printer...
\\ghostserver\installs\pstools\psexec \\%PC% -n 3 cmd /c rundll32
printui.dll,PrintUIEntry /y /ga /c\\%PC% /n\\PRINTSERVER\%PRINTER%
ECHO Restarting Print Spooler...
start /wait sc \\%PC% stop spooler
start /wait sc \\%PC% start spooler
Do you want to install or map the printer from the network ?
First thing to try : map the printer manually on a 7 x64 client. If it fails, your problem is not the batch.
Also try the simple rundll32 printui.dll PrintUIEntry /in n\\PRINTSERVER\%PRINTER% with a non-admin non-elevated account on the client to validate the print server configuration.
Is the "Disallow installation of printer using kernel-mode drivers" GPO disabled ? (Have to be)
Check the firewall settings, UAC/elevation configuration, admin access. Run a gpupdate /force and restart the client.
Check the event log on both the client and print server for any errors.
With an admin account (both print server and client), try to push the installation from the print server.
Have you tried to force adding the provider ? /j "LanMan Print Services"
If you have 2008 servers or DCs, you can use Print Management or Group Policy Preferences to deploy printers (easier than bat+psexec+printui.dll).
If you really want to do it via login script, there are also a bunch of tools in Vista/7/8 for print management in %WINDIR%\System32\Printing_Admin_Scripts, like this one.
Side note : start /wait is inefficient since sc.exe doesn't wait any response of the service. So, if you stop and start without a pause, chances are the service will not be stopped before the restart and skip the second order. You have to simulate a pause (ping 127.0.0.1 -n 5 >nul 2>&1) between stop & start or use a safer script to check the state of the service.
Thank you so much! That fixed it.
Here's my add script:
#echo off
echo PC Name
set /p PC=
echo Printer Name
set /p PRINTER=
echo Adding Printer...
\\servername\installs\pstools\psexec -s -i -accepteula \\%pc% rundll32 printui.dll PrintUIEntry /in /y /ga /n\\PRINTSERVER\%PRINTER%
echo Restarting Print Spooler...
start sc \\%pc% stop spooler
pause
start sc \\%pc% start spooler
pause
Here's my remove script:
#echo off
echo PC Name
set /p PC=
echo Printer Name
set /p PRINTER=
echo Adding Printer...
\\servername\installs\pstools\psexec -s -i -accepteula \\%pc% rundll32 printui.dll PrintUIEntry /gd /n\\PRINTSERVER\%PRINTER%
echo Restarting Print Spooler...
start sc \\%pc% stop spooler
pause
start sc \\%pc% start spooler
pause

Resources