Outils pour utilisateurs

Outils du site


blog

Info site

Whois

Headers HTTP/HTTPS

Headers
curl -I www.cible.com

En ligne : https://securityheaders.com

Google safebrowsing
Alexa

Mesures d’audience. Amazon

http://www.alexa.com/

TLS/SSL
2025/03/24 15:06

Notes imprimante sous GNU/Linux

Voir :

Voir aussi :

Si jamais CUPS n'est pas installé sur votre machine, installer les paquets cups et cups-client cups-bsd.

Pour une imprimante HP il faut le paquet hplip (CUPS a besoin de /usr/lib/cups/backend/hp)

Pour configurer une imprimante : http://localhost:631

Voir https://wiki.archlinux.fr/CUPS

lsmod | grep usblp

Il se peut que l'imprimante ne soit pas reconnue dans l'interface de Cups (imprimantes locales). Ceci est dû au fait que le noyau cré un composant qui se trouve dans /dev/usb/lp0. Une règles udev résout ce problème et permet de faire un lien symbolique /dev/lp0 → /dev/usb/lp0.

/var/log/cups/

Ajout imprimante en ligne de commande

Exemple imprimante Zebra (langage ZPL)

Install paquets

apt-get install cups #lprng
 
apt-get install cups-bsd
# ou
apt-get install lpr

Lister toutes les imprimantes connectées

lpinfo -v

L'imprimante connectées en USB apparait

network ipp
network http
network lpd
serial serial:/dev/ttyS0?baud=115200
serial serial:/dev/ttyS1?baud=115200
serial serial:/dev/ttyS2?baud=115200
serial serial:/dev/ttyS3?baud=115200
network ipps
network socket
network https
network ipp14
direct usb://Zebra%20Technologies/ZTC%20GK420d?serial=28J162400192
network smb

Ajout de l'imprimante

lpadmin -p GK420D -v usb://Zebra%20Technologies/ZTC%20GK420d?serial=28J162400192 -E

Ou

chown root:lp /etc/cups/ppd/GK420d.ppd
chmod 640 /etc/cups/ppd/GK420d.ppd
lpadmin -p GK420D -v usb://Zebra%20Technologies/ZTC%20GK420d?serial=28J162400192 -m /usr/share/cups/model/HP/DeskJet_882C-cdj880.ppd

Vérif

lpstat -p
printer GK420D is idle.  enabled since Thu 04 May 2017 04:32:45 PM CEST

Impression

lp -d GK420D -o raw plop.zpl

Vérifier que l'impression est terminée et OK (Show completed job)

lpstat -W completed
GK420D-1                root              3072   Thu 04 May 2017 04:39:38 PM CEST

Lister toutes les impressions des utilisateurs

lpstat -W all  -o
GK420D-2                unknown           3072   Thu 04 May 2017 04:55:46 PM CEST
GK420D-1                root              3072   Thu 04 May 2017 04:39:38 PM CEST

La conf est ici

/etc/cups/printers.conf

# Printer configuration file for CUPS v1.7.5
# Written by cupsd
# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING
<Printer GK420D>
UUID urn:uuid:180e7105-f553-341a-6d6d-a8acdc5a89f4
Info GK420D
DeviceURI usb://Zebra%20Technologies/ZTC%20GK420d?serial=28J162400192
State Idle
StateTime 1493908365
Type 4
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
</Printer>
Supprimer une imprimante

Lister les imprimantes

lpstat -p
printer GK420D is idle.  enabled since Tue 09 May 2017 01:12:32 PM CEST
printer GK420DD is idle.  enabled since Tue 09 May 2017 02:20:21 PM CEST

Effacement

lpadmin -x GK420DD

Réactiver l’imprimante

Source : http://superuser.com/questions/280396/how-to-resume-cups-printer-from-command-line

lpstat -p
printer DeskJet-3630-series is idle.  enabled since mar. 12 juil. 2016 21:21:34 CEST
        ready to print
cupsenable DeskJet-3630-series
lpc status
DeskJet-3630-series:
        printer is on device 'hp' speed -1
        queuing is enabled
        printing is enabled
        no entries
        daemon present

Effacer et annuler toutes les impressions

cancel -a $NOM_DE_L_IMPRIMANTE
 
# ou
 
cancel -a -x

Administration

Ajouter l'utilisateur dans les groupes lp, lpadmin et sys ?

gpasswd -a jean lp
gpasswd -a jean lpadmin

Supervision SNMP

snmpget -c public -v 1 192.168.1.250 hrPrinterDetectedErrorState.1 

Autres

Voir /etc/printcap

smb.conf

[global]
print command = lpr -r -h -P%p %s

Try adding the 'sf' option to the printer definition in /etc/printcap The 'sf' stands for 'suppress form feeds'.

Config client CUPS

cat > /etc/cups/client.conf << EOF
ServerName 192.168.1.1
EOF

Diag

Pb https://forum.linuxchallans.org/topic/262/impression-vide-de-l-attestation-de-d%C3%A9placement-d%C3%A9rogatoire

Voir

$ lp attestation-deplacement-fr.pdf 
lp: Error - ~/.cups/lpoptions file names default destination that does not exist.

$ lpstat -p -d
printer HP_DeskJet_3630_series is idle.  enabled since mer. 06 mai 2020 19:34:55 CEST                                                                                  
no system default destination

~/.cups/lpoptions

#Default DeskJet-3630-series
Default HP_DeskJet_3630_series 

Ou

lpoptions -d HP_DeskJet_3630_series
echo "Hello, world." | lp
sudo cupsctl --debug-logging
#sudo cupsctl --no-debug-logging

Voir /var/log/cups/error_log

service cups restart
journalctl -u cups.service -f

HTTP_STATE_WAITING Closing for error 32 (Broken pipe) A tester https://forum.manjaro.org/t/printer-doesnt-work-closing-for-error-32-broken-pipe/40678

cat attestation-deplacement-fr.pdf | /usr/lib/cups/filter/pdftopdf 1 1 1 1 '' >out.pdf
DEBUG: pdftopdf: No PPD file specified, could not determine whether to log pages or not, so turned off page logging.
DEBUG: PDF form flattening command line: pdftocairo -pdf - /tmp/032cf5ea697ad
WARNING: temp file: file is damaged
WARNING: temp file (object 6 0, offset 85): expected n n obj
WARNING: temp file: Attempting to reconstruct cross-reference table
WARNING: temp file: object 6 0 not found in file after regenerating cross reference table
pdftocairo -pdf original.pdf out.pdf

Hp

Installer / Reinstaller une imprimante HP

hp-setup -i

hp-check est fait pour RedHat. Pas très efficace.

Pb

Err invalid deviceid ret=-9: Resource temporarily unavailable

Suite à passage de Debian 9 à Debian 10

-- Boot b860f46144c6442c86d06b19bc47ea20 --                                                                                                                             
janv. 21 22:38:57 portable hpfax[131730]: [131730]: error: Failed to create /var/spool/cups/tmp/.hplip                                                                  
janv. 21 22:40:32 portable hp[136572]: io/hpmud/musb.c 770: invalid deviceid ret=-9: Resource temporarily unavailable

déc. 28 18:20:35 portable hp[71827]: io/hpmud/musb.c 770: invalid deviceid ret=-9: Resource temporarily unavailable
déc. 28 18:20:35 portable hp[71827]: io/hpmud/musb.c 561: released ff/4/1 interface
déc. 28 18:20:35 portable hp[71827]: prnt/backend/hp.c 825: INFO: open device failed stat=12: hp:/usb/DeskJet_3630_series?serial=CN5CS2H5YV067P; will retry in 30 secon>
déc. 28 18:21:05 portable hp[71827]: io/hpmud/musb.c 427: Found interface conf=0, iface=1, altset=0, index=1                                                   
Solution

Pas très clair, à vérif

apt-get purge ipp-usb
apt-get install cups
 
apt-get reinstall hplip hplip-data
 
hp-setup -i
2025/03/24 15:06

Voir document

  • import_vm_vdi_qcow2.odt FIXME

Import VM (VDI QCOW2)

VDI vers RAW

$ VBoxManage clonehd --format RAW /home/jibe/tmp/wheezy1.vdi /home/jibe/tmp/wheezy1.img

VBoxManage: error: Cannot register the hard disk '/home/jibe/tmp/wheezy1.vdi' {16d89855-060b-4abf-a154-32b869784a26} because a hard disk '/home/jibe/VirtualBox VMs/wheezy1/wheezy1.vdi' with UUID {16d89855-060b-4abf-a154-32b869784a26} already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp

Cette erreur disparaît en root

$ time VBoxManage clonehd --format RAW /home/jibe/tmp/wheezy1.vdi /home/jibe/tmp/wheezy1.img

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'RAW'. UUID: 8e3b2b88-31d2-4e60-8792-f42d4e7e107e

real	2m59.942s
user	0m1.272s
sys	0m1.084s

Le format RAW de gérant pas le <lang en>Copy-On-Write</lang> l'image générée sera de la taille maximal (Taille virtuelle)

$ ls -lh ~/tmp/wheezy1.*
-rw------- 1 root root 8,0G avril  1 11:38 /home/jibe/tmp/wheezy1.img
-rw------- 1 jibe jibe 1,6G mars   7 14:54 /home/jibe/tmp/wheezy1.vdi

Conversion RAW vers QCOW2

$ time qemu-img convert -f raw ~/tmp/wheezy1.img -O qcow2 wheezy1.qcow2
real	2m17.464s
user	0m5.684s
sys	0m26.528s

La taille de l'image disque redevient celle de l'espace vraiment consommé:

$ ls -lh wheezy1.qcow2
-rw-r--r-- 1 jibe jibe 1,5G avril  1 12:06 wheezy1.qcow2

Conversion OVA / OVF

Un OVA est une archive TAR

tar xvf plop.ova

Lister les formats pris en charge

qemu-img -h |tail -n1

Conversion du VMDK en QCOW2

qemu-img convert -O qcow2 plop-disk1.vmdk plop.qcow2

info sur l'image

qemu-img  info --output json plop.qcow2

Création d'un VMDK

wget https://download.fedoraproject.org/pub/fedora/linux/releases/31/Cloud/x86_64/images/Fedora-Cloud-Base-31-1.9.x86_64.raw.xz
xz --decompress Fedora-Cloud-Base-31-1.9.x86_64.raw.xz
qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized Fedora-Cloud-Base-31-1.9.x86_64.raw Fedora-31.vmdk
printf '\x03' | dd conv=notrunc of=Fedora-31.vmdk bs=1 seek=$((0x4))

Conversion VMDK vers VMDK (VMDK2VMDK)

Par exemple suite à

openstack image save plop --file plop.vmdk

Conversion VMDK vers VMDK

qemu-img convert -O vmdk plop.vmdk plop2.vmdk

Resize VDI

VBoxManage.exe modifyhd D:\VMs\plop\plop.vdi --resize 40000
2025/03/24 15:06

Ansible inventory script - inventaire dynamique 1

Voir :

Voir aussi :

In Ansible 2.10 and later, inventory scripts moved to their associated collections. Many are now in the ansible-community/contrib-scripts repository. We recommend you use Inventory plugins instead.

Source : https://docs.ansible.com/ansible/latest/inventory_guide/intro_dynamic_inventory.html#intro-dynamic-inventory

Nous allons coder un inventory script en bash en mode “hello world”

Voici le script bash avec des données codés en dures dedans, c'est moche mais c'est juste pour un PoC.

inv.sh

#! /bin/bash
 
set -euo pipefail
IFS=$' \t\n'
export LANG=C
SCRIPT_NAME="$(basename "$0")"
 
trap 'rm -f "$TMP_INV_INI"' EXIT
 
TMP_INV_INI="$(mktemp --suffix=_"${SCRIPT_NAME%%.*}".ini)"
 
mk_ini_tmp_inv() {
cat <<-EOF >"$TMP_INV_INI"
[all:vars]
os = linux
 
[web]
srv-web1 web=1
srv-web2 web=2
 
[db]
srv-db1 db=1
srv-db2 db=2
 
[plop]
test-ansible
EOF
}
 
arg_list() {
        mk_ini_tmp_inv
        ansible-inventory -i "$TMP_INV_INI" --list
}
 
arg_host() {
        mk_ini_tmp_inv
        ansible-inventory -i "$TMP_INV_INI" --host "$1"
}
 
usage() {
        ansible-doc -t inventory script
}
 
while [ "${1-}" != "" ]; do
    case $1 in
        --list )                        shift
                                        arg_list
                                ;;
        --host )                        shift
                                        arg_host "$1"
                                ;;
        -h | --help )                   usage
                                        exit 0
                                ;;
        --)                             # End of all options
                                        shift
                                        break
                                ;;
        -*)                             echo "SCRIPT_NAME: invalid option" >&2
                                        echo "Try '$SCRIPT_NAME --help' for more information." >&2
                                        exit 1
                                ;;
        *)
                                        usage
                                ;;
    esac
    shift
done

Rendons le script exécutable

chmod +x inv.sh

Nous testons la sortie de notre script bash

./inv.sh --list
{
    "_meta": {
        "hostvars": {
            "srv-db1": {
                "db": 1,
                "os": "linux"
            },
            "srv-db2": {
                "db": 2,
                "os": "linux"
            },
            "srv-web1": {
                "os": "linux",
                "web": 1
            },
            "srv-web2": {
                "os": "linux",
                "web": 2
            },
            "test-ansible": {
                "os": "linux"
            }
        }
    },
    "all": {
        "children": [
            "db",
            "plop",
            "ungrouped",
            "web"
        ]
    },
    "db": {
        "hosts": [
            "srv-db1",
            "srv-db2"
        ]
    },
    "plop": {
        "hosts": [
            "test-ansible"
        ]
    },
    "web": {
        "hosts": [
            "srv-web1",
            "srv-web2"
        ]
    }
}

Nous testons de nouveau la sortie de notre script mais pour un host spécifique cette fois

./inv.sh --host srv-web1
{
    "os": "linux",
    "web": 1
}

A présent testons avec Ansible :

$ ansible -i inv.sh -m ping plop
[WARNING]:  * Failed to parse /home/jean/tmp/inv.sh with script plugin: Inventory script (/home/jean/tmp/inv.sh) had an execution error:
[WARNING]:  * Failed to parse /home/jean/tmp/inv.sh with ini plugin: /home/jean/tmp/inv.sh:3: Expected key=value host variable assignment, got: -euo
[WARNING]: Unable to parse /home/jean/tmp/inv.sh as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: plop

Ça ne marche pas. Ansible s'attend à trouver un inventaire au format ini et à la place il a du bash.

Les inventory script doivent être en Python. J'ai essayé de renommer ce script inv.sh en inv.py mais ça ne marche pas.

Nous allons coder un wrapper Python qui lance notre script bash.

inv.py

#! /usr/bin/env python3
 
import os
import argparse
 
parser = argparse.ArgumentParser()
parser.add_argument('--list', action='store_true')
parser.add_argument('--host')
 
args = parser.parse_args()
 
if args.list:
    os.system('bash ./inv.sh --list')
elif args.host:
    os.system(f'bash ./inv.sh --host {args.host}')

Rendons ce script Python exécutable

chmod +x inv.py

Et ça marche :

$ ansible -i inv.py -m ping plop
test-ansible | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

Autres

Voir

Enabled Variable

Retrieve the enabled state from the given dict of host variables. The enabled variable may be specified using dot notation, e.g: 'foo.bar'
2025/03/24 15:06

IMAP dossier partage

Brouillon

Dossier IMAP partagé

Voir :

/etc/dovecot/conf.d/10-mail.conf

mail_plugins = acl

Ajouter imap_acl à la fin de la ligne

/etc/dovecot/conf.d/20-imap.conf

mail_plugins = $mail_plugins imap_acl

Décommenter

/etc/dovecot/conf.d/90-acl.conf

plugin {
  acl = vfile:/etc/dovecot/global-acls:cache_secs=300
}
 
# To let users LIST mailboxes shared by other users, Dovecot needs a
# shared mailbox dictionary. For example:
plugin {
  acl_shared_dict = file:/var/lib/dovecot/shared-mailboxes
}
service dovecot restart

/etc/letsencrypt/cli.ini

# Source : https://gist.github.com/mrothNET/cb6f313e9cbe896f3e0fdec80ad2f3fa
 
# Manage Firewall
#pre-hook = ufw allow http
#post-hook = ufw deny http
 
# Restart Postfix & Dovecot
renew-hook = systemctl restart dovecot.service postfix.service

Astuce : Si rlwrap installé, préfixer votre commande par rlwrap. Il sera plus aissé de rapeller les commandes via fleche du haut

#rlwrap nc localhost 143
#telnet localhost 143
nc localhost 143

rli pour read ®, lookup (l) et insert (i)

. login user P@ssw0rd
. SETACL Sent paul rli
2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki