github.com/larkox/mattermost-server@v5.11.1+incompatible/scripts/ldap-check.sh (about)

     1  #!/bin/bash
     2  
     3  jq_cmd=jq
     4  [[ $(type -P "$jq_cmd") ]] || { 
     5  	echo "'$jq_cmd' command line JSON processor not found";
     6  	echo "Please install on linux with 'sudo apt-get install jq'"
     7  	echo "Please install on mac with 'brew install jq'"
     8  	exit 1; 
     9  }
    10  
    11  ldapsearch_cmd=ldapsearch
    12  [[ $(type -P "$ldapsearch_cmd") ]] || { 
    13  	echo "'$ldapsearch_cmd' shell accessible interface to ldap not found";
    14  	echo "Please install on linux with 'sudo apt-get install ldap-utils'"
    15  	exit 1; 
    16  }
    17  
    18  if [[ -z ${1} ]]; then
    19  	echo "We could not find a username";
    20  	echo "usage: ./ldap-check.sh [username]"
    21  	echo "example: ./ldap-check.sh john"
    22  	exit 1;
    23  fi
    24  
    25  echo "Looking for config.json"
    26  
    27  config_file=
    28  if [[ -e "./config.json" ]]; then
    29  	config_file="./config.json"
    30  	echo "Found config at $config_file";
    31  fi
    32  
    33  if [[ -z ${config_file} && -e "./config/config.json" ]]; then
    34  	config_file="./config/config.json"
    35  	echo "Found config at $config_file";
    36  fi
    37  
    38  if [[ -z ${config_file} && -e "../config/config.json" ]]; then
    39  	config_file="../config/config.json"
    40  	echo "Found config at $config_file";
    41  fi
    42  
    43  if [[ -z ${config_file} ]]; then
    44  	echo "We could not find config.json";
    45  	exit 1;
    46  fi
    47  
    48  LdapServer=`cat $config_file | jq -r .LdapSettings.LdapServer`
    49  LdapPort=`cat $config_file | jq -r .LdapSettings.LdapPort`
    50  BindUsername=`cat $config_file | jq -r .LdapSettings.BindUsername`
    51  BindPassword=`cat $config_file | jq -r .LdapSettings.BindPassword`
    52  BaseDN=`cat $config_file | jq -r .LdapSettings.BaseDN`
    53  UserFilter=`cat $config_file | jq -r .LdapSettings.UserFilter`
    54  EmailAttribute=`cat $config_file | jq -r .LdapSettings.EmailAttribute`
    55  UsernameAttribute=`cat $config_file | jq -r .LdapSettings.UsernameAttribute`
    56  IdAttribute=`cat $config_file | jq -r .LdapSettings.IdAttribute`
    57  
    58  if [[ -z ${UserFilter} ]]; then
    59  	UserFilter="($IdAttribute=$1)"
    60  else
    61  	UserFilter="(&($IdAttribute=$1)$UserFilter)"
    62  fi
    63  
    64  cmd_to_run="$ldapsearch_cmd -LLL -x -h $LdapServer -p $LdapPort -D \"$BindUsername\" -w \"$BindPassword\" -b \"$BaseDN\" \"$UserFilter\" $IdAttribute $UsernameAttribute $EmailAttribute"
    65  echo $cmd_to_run
    66  echo "-------------------------"
    67  eval $cmd_to_run