Outils pour utilisateurs

Outils du site


blog

Notes Postgres PL/PGSQL

Call function

Si aucun résultat n'est attendu Utiliser PERFORM à la place de SELECT\ Note : A la place de SELECT pensez à utiliser SELECT INTO Voir aussi EXECUTE.

CREATE OR REPLACE FUNCTION foo()
RETURNS void AS $$
BEGIN
  RAISE NOTICE 'Hello from void function';
END;
$$ LANGUAGE plpgsql;
 
-- direct call from SQL
SELECT foo();
 
-- in PLpgSQL
DO $$
BEGIN
  SELECT foo(); -- is not allowed
  PERFORM foo(); -- is ok
END;
$$;
SELECT ma_function();
 
SELECT * FROM ma_function();
 
DO $$ BEGIN
    PERFORM ma_function();
END $$;
Ne rien faire

Utiliser NULL

BEGIN
    y := x / 0;
EXCEPTION
    WHEN division_by_zero THEN
        NULL;  -- ignore the error
END;
cast conversion type - date
db1=> SELECT now();
              now
-------------------------------
 2019-12-11 15:54:57.984691+00
(1 row)

db1=> SELECT now()::timestamp;
            now
----------------------------
 2019-12-11 15:55:05.608026
(1 row)
DEBUG

Avec RAISE NOTICE

CREATE OR REPLACE FUNCTION plop() RETURNS INT AS $$
  DECLARE  
  query1 text;
  WN_RESULT INT;
  -- res RECORD;
  res table%rowtype;
  BEGIN 
     WN_RESULT := 1;
     BEGIN 
     FOR res IN
       SELECT * FROM table1 WHERE maintained=FALSE
     LOOP
		query1='UPDATE table SET nbcount=subquery.count,maintained=true FROM (SELECT COUNT(*) FROM ' 
		|| res.atable
		|| ') AS subquery WHERE atable=' 
		|| quote_literal(res.atable) ;
		RAISE NOTICE 'DEBUG: %', query1 ;
		EXECUTE query1 ;
     END LOOP;
    EXCEPTION
 
    WHEN OTHERS THEN
     RAISE WARNING 'plop() exception[%][%]', SQLSTATE, SQLERRM;
     WN_RESULT := -1;
      END;
     RETURN WN_RESULT;
  END;
  $$ LANGUAGE plpgsql;
 
 
SELECT plop();
2025/03/24 15:06

BounCA - Une WebUI pour gérer vos certificats SSL/TLS PKI

Voir : https://bounca.org

Voir également : EasyRSA

BounCA est une application Django pour gérer votre PKI

Notes installation via Docker

docker-compose.yml

diff --git a/docker-compose.yml b/docker-compose.yml
index 584d3c9..969d37d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -28,7 +28,10 @@ nginx:
 postgres:
   restart: always
   image: postgres:latest
+  environment:
+    POSTGRES_PASSWORD: postgres
   ports:
     - "5432:5432"

POSTGRES_PASSWORD doit être en adéquation avec le fichier .env

.env

# Add Environment Variables
 
SECRET_KEY=5(15ds+i2+%ik6z&!yer+ga9m=e%jcqiz_5wszg)r-z!2--b2d
DB_NAME=postgres
DB_USER=postgres
DB_PASS=postgres
DB_SERVICE=postgres

launch-bounca.sh

diff --git a/launch-bounca.sh b/launch-bounca.sh
index b993a28..3320b9e 100755
--- a/launch-bounca.sh
+++ b/launch-bounca.sh
@@ -1,11 +1,6 @@
 #!/bin/bash -e
 
-docker-machine create -d virtualbox bounca || true
-docker-machine stop bounca || true
-docker-machine start bounca || true
-eval $(docker-machine env bounca)
 docker-compose build
 docker-compose up -d
 docker-compose run bounca python3 /srv/www/bounca/manage.py migrate --noinput
 echo "Visit your BounCA installation:"
-docker-machine ip bounca

Création manuelle de la base (nécessaire ?)

docker exec -ti docker-compose-bounca_postgres_1 /bin/bash
su - postgres
createuser bounca
createdb --owner=bounca bounca --encoding=UTF8 --template=template0
psql -c 'alter user bounca with createdb' postgres

Création manuelle du schéma de la base (nécessaire ?)

docker-compose build
docker-compose up -d
 
#docker exec -ti docker-compose-bounca_bounca_1 /bin/bash
#python3 ./bounca/manage.py migrate
docker-compose run bounca python3 /srv/www/bounca/manage.py migrate --noinput

Le site est accessible par défaut http://127.0.0.1
Vous devez créer un compte via cette même interface graphique en cliquant sur Click here to register

FIXME

2025/03/24 15:06

Notes Postfix

Voir http://linuxserverworld.com/how-to-flush-and-delete-postfix-mail-queue-and-its-various-operations/

Mettre en place une limite sur le nombre de mails envoyés par IP sur Postfix

Source : http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html

Voir la file d'attente

mailq

Vérif syntax

postfix check

Sortir les mails de la file attentes (essaye de les ré-envoyer)

postfix flush

Effacer tous les courriels de la file d'attente

postsuper -d ALL

Effacer tous les mails de la “deferred queue”

postsuper -d ALL deferred

Source : http://www.cyberciti.biz/tips/howto-postfix-flush-mail-queue.html

postfix-delete.pl

#!/usr/bin/perl
 
$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";
 
@data = qx</usr/sbin/postqueue -p>;
for (@data) {
  if (/^(\w+)(\*|\!)?\s/) {
     $queue_id = $1;
  }
  if($queue_id) {
    if (/$REGEXP/i) {
      $Q{$queue_id} = 1;
      $queue_id = "";
    }
  }
}
 
#open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
 
foreach (keys %Q) {
  print POSTSUPER "$_\n";
};
close(POSTSUPER);

Efface de la file d'attente tous les message provenant ou en destination du domain fackspamdomain.com

./postfix-delete.pl fackspamdomain.com

Efface tous les courriel contenant le mot “xyz”

./postfix-delete.pl xyz

http://www.system-linux.eu/index.php?post/2009/01/27/Traitement-de-Queue-mail-Postfix

Supprimer un message de la file d'attente

postsuper -d E795D42A16

Mettre un messages en attente (hold) :

postsuper -h E795D42A16

Remettre en file d'attente un message :

postsuper -r E795D42A16

Afficher le contenu d'un message :

postcat -q E795D42A16

Pour forcer l'envoie de messages spécifique à un domaine non présent dans les paramètres relay_domains de la configuration Postfix :

Ajouter cette ligne dans le fichier main.cf :

main.cf

fast_flush_domains = $relay_domains mondomain.fr

Puis :

postqueue -s mondomain.fr

Autre

Exemple de config

/etc/aliases

plop: plop@localhost.acme.fr
postalias /etc/aliases

/etc/postfix/main.cf

myorigin = localhost.acme.fr
mydestination = $myhostname, localhost.$mydomain, localhost, $myorigin,
transport_maps = hash:/etc/postfix/transport

mydomain = acme.fr
myhostname = myhostname
relayhost = 192.168.6.28
default_transport = smtp
relay_transport = smtp
#inet_interfaces = localhost
inet_interfaces = loopback-only
inet_protocols = ipv4
systemctl reload postfix

/etc/postfix/transport

laposte.fr :
acme.fr :
localhost.acme.fr local:
* error: domaine non autorise
postmap /etc/postfix/transport
/usr/sbin/postdrop -r

Conf sur Debian

Serveur de référence

apt-get install debconf-utils
debconf-get-selections  |grep -e '^postfix

Nouveau serveur

LANG=C dpkg-reconfigure postfix

Serveur de référence

postconf -n

Nouveau serveur

# Exemple
postconf -e relayhost=
postconf -e myorigin=/etc/mailname

FQDN ici /etc/mailname

Pb

Pb FQDN

Erreur :

  • Helo command rejected: need fully-qualified hostname;
  • Sender address rejected: Domain not found (in reply to RCPT TO command))

/var/log/mail

Helo command rejected: need fully-qualified hostname;

/etc/mailname

smtp.acme.fr
postconf -e myhostname=smtp.belaris.fr
postfix check
service postfix reload

Test Question

What is the function of this Postfix configuration ?

relayhost = 
relay_transport = relay
relay_domains = static:ALL
smtpd_end_of_data_restrictions = check_client_access static:discard
2025/03/24 15:06

Notes post-mortem

sudo mactime -d /mnt -R -g /mnt/etc/group -p 
 /mnt/etc/passwd 1/2/1970 > timeline.txt
2025/03/24 15:06

Notes portmap rpcbind rpc

Voir

  • portreserve
  • NFS v3
  • NIS
  • rup
  • TCP Wrappers
  • xinetd

Autres

Debug
rpcdebug -m nfsd -s all
rpcdebug -m rpc -s all

/etc/sysconfig/nfs

RPCMOUNTDOPTS="-d all"
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