Skip to content

Commit ea115b8

Browse files
committed
install script
1 parent 5293711 commit ea115b8

File tree

8 files changed

+86
-13
lines changed

8 files changed

+86
-13
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ jobs:
2323
cp src/config.yml .debpkg/var/lib/sesame-daemon/backends-modules/ad
2424
cp README.md .debpkg/var/lib/sesame-daemon/backends-modules/ad
2525
cp install.sh .debpkg/var/lib/sesame-daemon/backends-modules/ad
26-
cp requirements.txt .debpkg/var/lib/sesame-daemon/backends-modules/ad
26+
cp copy_ssh_key.py .debpkg/var/lib/sesame-daemon/backends-modules/ad
2727
chmod 700 .debpkg/var/lib/sesame-daemon/backends-modules/ad/install.sh
28+
chmod 700 .debpkg/var/lib/sesame-daemon/backends-modules/ad/copy_ssh_key.py
29+
cp requirements.txt .debpkg/var/lib/sesame-daemon/backends-modules/ad
2830
- uses: jiro4989/build-deb-action@v3
2931
with:
3032
package: sesame-backend-ad
3133
package_root: .debpkg
3234
maintainer: Libertech
3335
version: ${{ github.ref }} # refs/tags/v*.*.*
3436
arch: 'amd64'
35-
depends: 'python3, python3-jinja2, python3-paramiko, sesame-daemon'
37+
depends: 'python3, python3-jinja2, python3-paramiko, sesame-daemon, openssh-client'
3638
desc: 'AD backend for sesame-daemon'
3739
homepage: 'https://github.com/Libertech-FR/sesame-backend-ad'
3840
- uses: svenstaro/upload-release-action@v2

copy_ssh_key.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr//bin/python3 -u
2+
import paramiko
3+
import argparse
4+
parser = argparse.ArgumentParser(
5+
prog='ProgramName',
6+
description='What the program does',
7+
epilog='Text at the bottom of help')
8+
parser.add_argument('-s', '--server')
9+
parser.add_argument('-u', '--user') # option that takes a value
10+
parser.add_argument('-p', '--password')
11+
parser.add_argument('-k', '--keyfile')
12+
args = parser.parse_args()
13+
14+
client = paramiko.SSHClient()
15+
policy = paramiko.AutoAddPolicy()
16+
client.set_missing_host_key_policy(policy)
17+
try:
18+
client.connect(hostname=args.server, username=args.user, password=args.password)
19+
sshfile = client.open_sftp()
20+
with open(args.keyfile) as f: new_key = f.read()
21+
## ouverture sur windows du authorized_Keys
22+
with sshfile.open(".ssh/authorized_keys", mode="a") as message:
23+
message.write(new_key)
24+
message.close()
25+
del client
26+
except paramiko.ssh_exception.SSHException as e:
27+
e_dict = e.args[0]
28+
print("Erreur d'authentification")
29+
exit(1)
30+

install.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
echo "Deploiment du module LDAP"
2+
echo "Deploiment du module AD"
33
echo "La position determinera l'ordre d'execution des backends (comme dans init.d)"
44
read -p "Numero de demarrage du module (2 positions):" NUM
55
echo "installation dans backends/${NUM}openldap"
@@ -22,13 +22,16 @@ PWD=`pwd`
2222
cp ./lib/__init__.py $INSTALL/lib
2323
ln -s $PWD/lib/backend_utils.py $INSTALL/lib/backend_utils.py
2424
ln -s $PWD/lib/ad_utils.py $INSTALL/lib/ad_utils.py
25+
mkdir $INSTALL/ps1_templates
26+
cp ./ps1_templates/* $INSTALL/ps1_templates
2527
cp config.yml $INSTALL
2628

2729
echo "Le backend a été installé dans $INSTALL"
2830
echo "Configuration"
29-
read -p "Url du serveur AD : " HOST
30-
read -p "Utilisateur (doit avoir les droits d'ecriture) : " DN
31-
read -p "Mot de passe : " PASSWORD
31+
read -p "Adresse du serveur AD primaire : " HOST
32+
read -p "Utilisateur (doit avoir les droits d'administration) : " USER
33+
read -s -p "Mot de passe : " PASSWORD
34+
echo ""
3235
read -p "Base ldap AD : " BASE
3336
read -p "Domaine pour UserPrincipalName : " DOMAIN
3437
echo "Génération du fichier de configuration"
@@ -40,6 +43,16 @@ echo "base=${BASE}" >> ${CONFFILE}
4043
echo "domain=${DOMAIN}" >> ${CONFFILE}
4144
echo "backendFor=adm,etd,esn" >> ${CONFFILE}
4245
chmod 600 ${CONFFILE}
46+
echo "Generation d'une clé ssh"
47+
mkdir $INSTALL/.ssh
48+
ssh-keygen -t ed25519 -f ${INSTALL}/.ssh/id_ed25519 -N ''
49+
./copy_ssh_key.py --server=${HOST} --user=${USER} --password="${PASSWORD}" --keyfile=${INSTALL}/.ssh/id_ed25519.pub
50+
OK=$?
51+
if [ $OK -ne 0 ];then
52+
echo "Impossible de copier la clé sur le serveur windows. Verifier que l'utilisateur a les droits d'administration"
53+
echo "Installation avortée"
54+
exit 1
55+
fi
4356
systemctl restart sesame-daemon
4457
echo "Vous pouvez completer le fichier de configuration avec les parametres optionnels (voir README.md)"
4558
echo "Merci "

src/bin/changepwd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
sys.path.insert(0, '../lib')
2+
sys.path.append('../lib')
33
import ad_utils as ad
44
import backend_utils as u
55

src/bin/ping.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
2-
sys.path.insert(0, '../lib')
2+
sys.path.append('../lib')
33
import ad_utils as ad
44
import backend_utils as u
55

6-
entity=u.readjsoninput()
76
config=u.read_config('../etc/config.conf')
87
ad.set_config(config)
9-
## test connection
8+
## test connection
9+
ad.test_conn()

src/bin/resetpwd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
sys.path.insert(0, '../lib')
2+
sys.path.append('../lib')
33
import ad_utils as ad
44
import backend_utils as u
55

src/bin/upsertidentity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
sys.path.insert(0, '../lib')
2+
sys.path.append('../lib')
33
import ad_utils as ad
44
import backend_utils as u
55

src/lib/ad_utils.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os.path
2+
import sys
3+
sys.path.append('.')
24
import paramiko
35
from jinja2 import FileSystemLoader
4-
import src.lib.backend_utils as u
6+
import backend_utils as u
57
import jinja2
68

79
__DEBUG__=0
@@ -32,7 +34,11 @@ def exec_cmd(command):
3234
return content
3335

3436
def compose_dn(entity):
37+
3538
rdnValue=u.find_key(entity,'cn')
39+
x=type(rdnValue)
40+
if rdnValue is None:
41+
rdnValue='test'
3642
branchAttr=u.config('branchAttr','')
3743
branch = ''
3844
if branchAttr != '':
@@ -56,6 +62,28 @@ def dn_superior(dn):
5662
return ','.join(tab)
5763

5864

65+
def test_conn():
66+
environment = jinja2.Environment(loader=FileSystemLoader("../ps1_templates/"))
67+
template = environment.get_template('ping.template')
68+
content=template.render({})
69+
scriptName='ping.ps1'
70+
client = open_ssh_conn()
71+
sshfile = client.open_sftp()
72+
with sshfile.open(scriptName, mode="w") as message:
73+
message.write(content)
74+
##execution du script
75+
chan = client.get_transport().open_session()
76+
chan.exec_command('powershell -ExecutionPolicy Bypass -NonInteractive -File ping.ps1')
77+
exitCode = chan.recv_exit_status()
78+
content = chan.recv(4096).decode('utf-8')
79+
del client
80+
if exitCode == 0:
81+
print(u.returncode(0, content.rstrip("\n")))
82+
exit(0)
83+
else:
84+
print(u.returncode(1, content.rstrip("\n")))
85+
exit(1)
86+
5987
def gen_script_from_template(entity,template):
6088
data={
6189
'domain' :u.config('domain'),

0 commit comments

Comments
 (0)