made it so that helpers are dynamically defined.
[matthijs/upstream/backupninja.git] / handlers / ldap.helper
1 HELPERS="$HELPERS ldap:ldap_database_backup"
2
3 ldap_create_file() {
4 while true; do
5       checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
6          "slapcat" "export ldif using slapcat" on \
7          "ldapsearch" "export ldif using ldapsearch" off \
8          "compress" "compress the ldif output files" on
9       status=$?
10       compress="compress = off"
11       method="method = <unset>"
12       restart="restart = no"
13       binddn=""
14       passwordfile=""
15       [ $status = 1 ] && return;
16       result="$REPLY"
17       for opt in $result; do
18          case $opt in
19            '"compress"') compress="compress = on";;
20            '"slapcat"')
21               method="method = slapcat"
22               [ "$_RESTART" == "yes" ] && restart="restart = yes"
23               ;;
24            '"ldapsearch"')
25               method="method = ldapsearch"
26               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable."
27               [ $? = 1 ] && return
28               passwordfile="passwordfile = $REPLY"
29               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
30               [ $? = 1 ] && return
31               binddn="binddn = $REPLY"
32               require_packages ldap-utils
33               ;;
34          esac
35       done
36       get_next_filename $configdirectory/30.ldap
37       cat > $next_filename <<EOF
38 $method
39 $compress
40 $restart
41 $binddn
42 $passwordfile
43 # backupdir = /var/backups/ldap
44 # conf = /etc/ldap/slapd.conf
45 # databases = all
46 EOF
47      chmod 000 $next_filename
48      return
49 done
50 }
51
52 ldap_wizard() {
53    bdb=no
54    ldbm=no
55    for backend in `grep -e "^backend" /etc/ldap/slapd.conf | awk '{print $2}'`; do
56       if [ "$backend" == "bdb" -a "$bdb" == "no" ]; then
57          bdb=yes
58       elif [ "$backend" == "ldbm" -a "$ldbm" == "no" ]; then
59          ldbm=yes
60       fi
61    done    
62
63    if [ "$bdb" == "yes" -a "$ldbm" == "no" ]; then
64      msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to BDB. If this is not the case, exit this wizard! From this point on, we will assume BDB backend, which might have disasterious consequences if this is incorrect."
65      _RESTART=no
66      ldap_create_file
67    elif [ "$ldbm" == "yes" ]; then
68      msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)." 
69      _RESTART=yes
70      ldap_create_file
71    else
72      msgBox "ldap action wizard" "I couldn't find any backends in your slapd.conf. Bailing out." 
73      return
74    fi
75 }
76