created ninjahelper
[matthijs/upstream/backupninja.git] / handlers / ldap.helper
1
2 ldap_create_file() {
3 while true; do
4       checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
5          "slapcat" "export ldif using slapcat" on \
6          "ldapsearch" "export ldif using ldapsearch" off \
7          "compress" "compress the ldif output files" on
8       status=$?
9       compress="compress = off"
10       method="method = <unset>"
11       restart="restart = no"
12       binddn=""
13       passwordfile=""
14       [ $status = 1 ] && return;
15       result="$REPLY"
16       for opt in $result; do
17          case $opt in
18            '"compress"') compress="compress = on";;
19            '"slapcat"')
20               method="method = slapcat"
21               [ "$_RESTART" == "yes" ] && restart="restart = yes"
22               ;;
23            '"ldapsearch"')
24               method="method = ldapsearch"
25               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."
26               [ $? = 1 ] && return
27               passwordfile="passwordfile = $REPLY"
28               inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
29               [ $? = 1 ] && return
30               binddn="binddn = $REPLY"
31               require_packages ldap-utils
32               ;;
33          esac
34       done
35       get_next_filename $configdirectory/30.ldap
36       cat > $next_filename <<EOF
37 $method
38 $compress
39 $restart
40 $binddn
41 $passwordfile
42 # backupdir = /var/backups/ldap
43 # conf = /etc/ldap/slapd.conf
44 # databases = all
45 EOF
46      chmod 000 $next_filename
47      return
48 done
49 }
50
51 ldap_wizard() {
52    bdb=no
53    ldbm=no
54    for backend in `grep -e "^backend" /etc/ldap/slapd.conf | awk '{print $2}'`; do
55       if [ "$backend" == "bdb" -a "$bdb" == "no" ]; then
56          bdb=yes
57       elif [ "$backend" == "ldbm" -a "$ldbm" == "no" ]; then
58          ldbm=yes
59       fi
60    done    
61
62    if [ "$bdb" == "yes" -a "$ldbm" == "no" ]; then
63      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."
64      _RESTART=no
65      ldap_create_file
66    elif [ "$ldbm" == "yes" ]; then
67      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)." 
68      _RESTART=yes
69      ldap_create_file
70    else
71      msgBox "ldap action wizard" "I couldn't find any backends in your slapd.conf. Bailing out." 
72      return
73    fi
74 }
75