From b9d2b32b0df402420b16ff908055fe33e4b2c5bf Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 9 Dec 2013 13:03:53 +0100 Subject: [PATCH 01/16] =?utf8?q?[pass]=20Pour=20afficher/=C3=A9diter=20mon?= =?utf8?q?=20fichier=20de=20mots=20de=20passe?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- pass/pass-edit.sh | 34 ++++++++++++++++++++++++++++++++++ pass/pass-show.sh | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 pass/pass-edit.sh create mode 100755 pass/pass-show.sh diff --git a/pass/pass-edit.sh b/pass/pass-edit.sh new file mode 100755 index 0000000..4b5a054 --- /dev/null +++ b/pass/pass-edit.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Script pour décrypter/crypter le fichier de passwords avec GPG +# plutôt qu'avec python qui est plus que poussif. + +cd ~/.pass + +FILE="pss" + +# On décrypte +gpg --decrypt-files ${FILE}.gpg + +# On édite le fichier +nano ${FILE} + +echo -n "Save ? (o/N)" +read -r ans +if [[ ${ans} = "o" ]] +then + echo "Backuping ${FILE}.gpg into ${FILE}.gpg.bkp1" + cp ${FILE}.gpg ${FILE}.gpg.bkp1 + echo "Removing previous ${FILE}.gpg file" + rm -f ${FILE}.gpg + echo "Encrypting new ${FILE}.gpg" + gpg --batch -r A94025B0 --encrypt-files ${FILE} + echo "Pense à copier ${FILE}.gpg.bkp1 en ${FILE}.gpg.bkp2" +else + echo "Nothing saved." +fi + + +# On shred le fichier non encrypté +echo "Deleting not encrypted ${FILE}" +shred -n 10 -u ${FILE} diff --git a/pass/pass-show.sh b/pass/pass-show.sh new file mode 100755 index 0000000..c98a213 --- /dev/null +++ b/pass/pass-show.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Script pour décrypter/crypter le fichier de passwords avec GPG +# plutôt qu'avec python qui est plus que poussif. + +cd ~/.pass + +FILE="pss" + +# On décrypte +gpg --decrypt-files ${FILE}.gpg + +# On montre le fichier +cat ${FILE} +clear + +# On shred le fichier non encrypté +shred -n 10 -u ${FILE} -- 2.39.2 From 4c872eff8d421dd9ec659ab03470fe39e28ed5e3 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 9 Dec 2013 17:37:53 +0100 Subject: [PATCH 02/16] [update_my*] + becue --- update_myconfig.sh | 2 +- update_myscripts.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/update_myconfig.sh b/update_myconfig.sh index 7da0fc1..ca2778b 100755 --- a/update_myconfig.sh +++ b/update_myconfig.sh @@ -11,7 +11,7 @@ echo "${color}sur eva:${endcolor}" cd ~/.myconfig git pull -for i in cerebro cabal info22 bde bde2 bde3 videobde pimeys baldrick quigon hexagon zamok ovh rezosup +for i in cerebro cabal info22 bde bde2 bde3 videobde pimeys becue baldrick quigon hexagon zamok ovh rezosup do echo "${color}sur $i:${endcolor}" ssh $i 'cd .myconfig; git pull' diff --git a/update_myscripts.sh b/update_myscripts.sh index 4b207cf..c270409 100755 --- a/update_myscripts.sh +++ b/update_myscripts.sh @@ -6,7 +6,7 @@ color='' endcolor='' -for i in eva zamok cerebro cabal bde pimeys +for i in eva zamok cerebro cabal bde pimeys becue do echo "${color}sur $i:${endcolor}" ssh $i 'cd scripts; git pull' -- 2.39.2 From 1781bba87c7610c3d302fabcd9767586905b9514 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 9 Dec 2013 19:07:14 +0100 Subject: [PATCH 03/16] [install_always] +rlwrap --- install_always.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_always.sh b/install_always.sh index e2dff1e..45d94c4 100755 --- a/install_always.sh +++ b/install_always.sh @@ -3,6 +3,6 @@ # À installer sur toute nouvelle macine base="vim htop iotop iftop ipython moreutils screen git molly-guard vlock make" -cool="ack-grep colordiff nmap automake" +cool="ack-grep colordiff nmap automake rlwrap" apt-get install ${packages} ${cool} -- 2.39.2 From 9d7b2db5754f0f7d292f683d2e5e3a5c693f7db4 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2013 02:24:24 +0100 Subject: [PATCH 04/16] [bde/supprimer] On peut supprimer une liste d'id et pas seulement un intervalle --- bde/supprimer_quelquun.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bde/supprimer_quelquun.py b/bde/supprimer_quelquun.py index 0123f06..5564278 100755 --- a/bde/supprimer_quelquun.py +++ b/bde/supprimer_quelquun.py @@ -13,16 +13,22 @@ class NonZeroError(ValueError): def __init__(self): super(NonZeroError, self).__init__("Solde du compte non-nul") +def liste_to_sql(l): + """Renvoie la liste d'entiers en chaîne sql utilisable""" + assert all([type(i) == int for i in l]) + return "(" + ",".join([str(i) for i in l]) + ")" + def getcursor(): """Ouvre une connexion à la base de données.""" con = psycopg2.connect(database="bde") cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor) return con, cur -def get_comptes(debut, fin): - """Récupère les comptes entre début et fin.""" +def get_comptes(liste): + """Récupère les comptes entre début et fin. + Attention au contenu de liste, quand même.""" con, cur = getcursor() - cur.execute("SELECT * FROM adherents WHERE numcbde>=%s AND numcbde<=%s ORDER BY numcbde;", (debut,fin)) + cur.execute("SELECT * FROM adherents WHERE numcbde in %s ORDER BY numcbde;" % liste_to_sql(liste)) l = cur.fetchall() return l @@ -33,9 +39,9 @@ def check_impossibles(l): print "Je supprimerai pas quelqu'un dont le solde n'est pas nul : %s" % (",".join([str(adh["numcbde"]) for adh in paspossibles])) raise NonZeroError -def supprime(debut, fin): - """Supprime les comptes de numcbde entre ``debut`` et ``fin`` (compris).""" - l = get_comptes(debut, fin) +def supprime(liste): + """Supprime les comptes dont le numcbde est dans ``liste``.""" + l = get_comptes(liste) check_impossibles(l) con, cur = getcursor() cur.execute("""UPDATE adherents @@ -43,8 +49,8 @@ def supprime(debut, fin): passwd='!', section='', adresse='', email='nobody@crans.org', droits=0, surdroits=0, supreme='f', bloque='t', fonction='', mail_info=0, club='f', telephone='', theme='UNI', pbsante='', - normalien='t', numsecu='' WHERE numcbde>=%s AND numcbde<=%s; - """ % (debut, fin)) + normalien='t', numsecu='' WHERE numcbde in %s; + """ % (liste_to_sql(liste))) cur.execute("COMMIT;") def interactive(): @@ -59,7 +65,7 @@ def interactive(): else: fin = int(fin) - l = get_comptes(debut, fin) + l = get_comptes(range(debut, fin+1)) print spp(l, ["numcbde", "nom", "prenom", "pseudo", "solde"]) ans=raw_input("""Êtes-vous sûr de vouloir les "supprimer" ? """) -- 2.39.2 From 0b8e2a8de7eaac24c5720fe48a0414f1112ce897 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2013 02:47:51 +0100 Subject: [PATCH 05/16] [bde/supprimer] On distingue la partie input de la partie confirmation. --- bde/supprimer_quelquun.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bde/supprimer_quelquun.py b/bde/supprimer_quelquun.py index 5564278..74c3a81 100755 --- a/bde/supprimer_quelquun.py +++ b/bde/supprimer_quelquun.py @@ -53,8 +53,8 @@ def supprime(liste): """ % (liste_to_sql(liste))) cur.execute("COMMIT;") -def interactive(): - """Exécute le script de manière interactive.""" +def interactive_begin(): + """Détermine la liste des comptes à supprimer de manière interactive.""" print "Attention, je ne supprime rien, je ne fais que transformer en Erreur,Erreur..." debut = raw_input("Premier id : ") @@ -65,7 +65,11 @@ def interactive(): else: fin = int(fin) - l = get_comptes(range(debut, fin+1)) + return range(debut, fin+1) + +def interactive_delete(liste): + """Supprime les comptes de manière interactive.""" + l = get_comptes(liste) print spp(l, ["numcbde", "nom", "prenom", "pseudo", "solde"]) ans=raw_input("""Êtes-vous sûr de vouloir les "supprimer" ? """) @@ -79,4 +83,4 @@ def interactive(): print "Nothing Done" if __name__ == "__main__": - interactive() + interactive_delete(interactive_begin()) -- 2.39.2 From 3c2fa7b040ac5ada236d3b8d565474f58c1e7a27 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 12 Dec 2013 11:14:35 +0100 Subject: [PATCH 06/16] =?utf8?q?[gitignore]=20D=C3=A9p=C3=B4t=20newsstorer?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 77f5cd4..7d45feb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ chopes/ dtc/ irc/ +newsstorer/ python-myirclib/ snake/ sudoku/ -- 2.39.2 From 66722ac5b0bc032dbbaef64d58920d3af64b5603 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 12 Dec 2013 11:15:37 +0100 Subject: [PATCH 07/16] =?utf8?q?[update=5Fmy*]=20=C3=87a=20y=20est,=20pime?= =?utf8?q?ys=20est=20migr=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- update_myconfig.sh | 2 +- update_myscripts.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/update_myconfig.sh b/update_myconfig.sh index ca2778b..7da0fc1 100755 --- a/update_myconfig.sh +++ b/update_myconfig.sh @@ -11,7 +11,7 @@ echo "${color}sur eva:${endcolor}" cd ~/.myconfig git pull -for i in cerebro cabal info22 bde bde2 bde3 videobde pimeys becue baldrick quigon hexagon zamok ovh rezosup +for i in cerebro cabal info22 bde bde2 bde3 videobde pimeys baldrick quigon hexagon zamok ovh rezosup do echo "${color}sur $i:${endcolor}" ssh $i 'cd .myconfig; git pull' diff --git a/update_myscripts.sh b/update_myscripts.sh index c270409..4b207cf 100755 --- a/update_myscripts.sh +++ b/update_myscripts.sh @@ -6,7 +6,7 @@ color='' endcolor='' -for i in eva zamok cerebro cabal bde pimeys becue +for i in eva zamok cerebro cabal bde pimeys do echo "${color}sur $i:${endcolor}" ssh $i 'cd scripts; git pull' -- 2.39.2 From 8e6221db8bf74c533d0d7ef61828400de740c703 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 17 Dec 2013 02:03:10 +0100 Subject: [PATCH 08/16] [bde] Shortcut pour afficher les activites. --- bde/activites.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 bde/activites.sh diff --git a/bde/activites.sh b/bde/activites.sh new file mode 100755 index 0000000..2d3efd0 --- /dev/null +++ b/bde/activites.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Pour avoir rapidement la liste des activités + +export LESS="-S" + +for i in $@ +do + if [ $i = "--pot" ] + then pot=1; + fi; +done + +if [ "${pot}" = "1" ] +then + WHERE="WHERE titre ILIKE '%pot%' " +fi + +psql bde -c "SELECT * FROM activites ${WHERE}ORDER BY debut DESC;" -- 2.39.2 From bd7e8ad7b16eee5f8b73cce410c5c2e6d23fdf6b Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 23 Jan 2014 19:10:08 +0100 Subject: [PATCH 09/16] Moron --- bde/supprimer_quelquun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bde/supprimer_quelquun.py b/bde/supprimer_quelquun.py index 74c3a81..b28d711 100755 --- a/bde/supprimer_quelquun.py +++ b/bde/supprimer_quelquun.py @@ -75,7 +75,7 @@ def interactive_delete(liste): ans=raw_input("""Êtes-vous sûr de vouloir les "supprimer" ? """) if ans in ["oui","o","O","OUI","Y","y","YES","yes"]: try: - supprime(debut, fin) + supprime(liste) except NonZeroError: exit(1) print "Et bim !" -- 2.39.2 From 850c2ba028605fbd9e3faab6b092c62af879ee6b Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sat, 25 Jan 2014 20:18:08 +0100 Subject: [PATCH 10/16] =?utf8?q?[install=5Falways]=20modif=20faite=20?= =?utf8?q?=C3=A0=20moiti=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- install_always.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_always.sh b/install_always.sh index 45d94c4..a290175 100755 --- a/install_always.sh +++ b/install_always.sh @@ -5,4 +5,4 @@ base="vim htop iotop iftop ipython moreutils screen git molly-guard vlock make" cool="ack-grep colordiff nmap automake rlwrap" -apt-get install ${packages} ${cool} +apt-get install ${base} ${cool} -- 2.39.2 From 01914e99d2c6dfffe01c5f3c6cc5c3fdf145187e Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sun, 26 Jan 2014 01:24:07 +0100 Subject: [PATCH 11/16] Pour transformer un mail en pgp/mime en un PGP SIGNED MESSAGE --- clearmime.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 clearmime.py diff --git a/clearmime.py b/clearmime.py new file mode 100755 index 0000000..d53c7d5 --- /dev/null +++ b/clearmime.py @@ -0,0 +1,69 @@ +#!/usr/bin/python + +# Copyright 2008 Lenny Domnitser +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__all__ = 'clarify', +__author__ = 'Lenny Domnitser' +__version__ = '0.1' + +import email +import re + +TEMPLATE = '''-----BEGIN PGP SIGNED MESSAGE----- +Hash: %(hashname)s +NotDashEscaped: You need GnuPG to verify this message + +%(text)s%(sig)s''' + + +def _clarify(message, messagetext): + if message.get_content_type() == 'multipart/signed': + if message.get_param('protocol') == 'application/pgp-signature': + hashname = message.get_param('micalg').upper() + assert hashname.startswith('PGP-') + hashname = hashname.replace('PGP-', '', 1) + textmess, sigmess = message.get_payload() + assert sigmess.get_content_type() == 'application/pgp-signature' + #text = textmess.as_string() - not byte-for-byte accurate + text = messagetext.split('\n--%s\n' % message.get_boundary(), 2)[1] + sig = sigmess.get_payload() + assert isinstance(sig, str) + # Setting content-type to application/octet instead of text/plain + # to maintain CRLF endings. Using replace_header instead of + # set_type because replace_header clears parameters. + message.replace_header('Content-Type', 'application/octet') + clearsign = TEMPLATE % locals() + clearsign = clearsign.replace( + '\r\n', '\n').replace('\r', '\n').replace('\n', '\r\n') + message.set_payload(clearsign) + elif message.is_multipart(): + for message in message.get_payload(): + _clarify(message, messagetext) + + +def clarify(messagetext): + '''given a string containing a MIME message, returns a string + where PGP/MIME messages are replaced with clearsigned messages.''' + + message = email.message_from_string(messagetext) + _clarify(message, messagetext) + return message.as_string() + + +if __name__ == '__main__': + import sys + sys.stdout.write(clarify(sys.stdin.read())) + -- 2.39.2 From ffc93be868e1b0caa822982186fb8a42fb0ec208 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sun, 26 Jan 2014 06:35:44 +0100 Subject: [PATCH 12/16] [install_always] Pour naviguer dans l'utilisation du disque. Merci olasd. --- install_always.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_always.sh b/install_always.sh index a290175..a50a58b 100755 --- a/install_always.sh +++ b/install_always.sh @@ -3,6 +3,6 @@ # À installer sur toute nouvelle macine base="vim htop iotop iftop ipython moreutils screen git molly-guard vlock make" -cool="ack-grep colordiff nmap automake rlwrap" +cool="ack-grep colordiff nmap automake rlwrap ncdu" apt-get install ${base} ${cool} -- 2.39.2 From 4d027200601333fcd20d5d1361b13478ab539852 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Tue, 28 Jan 2014 22:46:55 +0100 Subject: [PATCH 13/16] [-mkhome] Il existe dans /usr/scripts/respbats --- mkhome.sh | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100755 mkhome.sh diff --git a/mkhome.sh b/mkhome.sh deleted file mode 100755 index 21a135e..0000000 --- a/mkhome.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Pour fabriquer le home d'un utilisateur - -for user in $@ -do - echo $user ? - read - mkdir -v -p /home/$user/Mail - chown -v -R $user:users /home/$user/ - chmod -v 700 /home/$user/Mail - mkdir -v -p /home/mail/$user/ - chown -v $user:mail /home/mail/$user/ -done -- 2.39.2 From dd989221c4c3a956952910ac0d58f055006ed0df Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Wed, 29 Jan 2014 01:27:52 +0100 Subject: [PATCH 14/16] [persoit] pastebinit, sur la page perso MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1ère version, pas bien folichonne --- persoit.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 persoit.sh diff --git a/persoit.sh b/persoit.sh new file mode 100755 index 0000000..b5ccebb --- /dev/null +++ b/persoit.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Équivalent de pastebinit, mais pour le mettre sur la page perso + +# Foire sur les fichiers avec espace + +# TODO : +# * échapper les espaces (escaped=${1// /\\ }) +# * ne pas envoyer si y'a déjà un truc du même nom, sauf -f +# * à mon avis il va falloir passer en python + + +USER=legallic + +scp $1 zamok:www/$1 + +echo https://perso.crans.org/$USER/$1 -- 2.39.2 From ec403e1b12920634bae283393704e4df9832bbef Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Wed, 29 Jan 2014 01:29:24 +0100 Subject: [PATCH 15/16] [persoit] Maintenant je peux faire persoit HowTo/unicode --- persoit.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/persoit.sh b/persoit.sh index b5ccebb..aa267e1 100755 --- a/persoit.sh +++ b/persoit.sh @@ -12,6 +12,8 @@ USER=legallic -scp $1 zamok:www/$1 +filename=`basename $1` -echo https://perso.crans.org/$USER/$1 +scp $1 zamok:www/${filename} + +echo https://perso.crans.org/$USER/${filename} -- 2.39.2 From 14588d148b4c6ae09ef6b84ae90364244575105a Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 31 Jan 2014 16:25:38 +0100 Subject: [PATCH 16/16] =?utf8?q?[bde/virements]=20=C3=A9galit=C3=A9=20de?= =?utf8?q?=20flottant=20:=20you're=20screwed?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bde/virements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bde/virements.py b/bde/virements.py index f14f08b..030fca6 100755 --- a/bde/virements.py +++ b/bde/virements.py @@ -129,7 +129,7 @@ def virements(): print "Total : %s" % total print "\nPayeurs :\n" + " ".join(["%s (%s)" % (i[1]["pseudo"], i[0]) for i in destinataires]) print "Total : %s" % total_pay + "\n" - if total != total_pay: + if abs(total-total_pay) >= 0.01: print "Les totaux des participations et des paiements ne concordent pas !\nAbort." exit(1) -- 2.39.2