new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / var / ossec / agentless / register_host.sh
1 #!/bin/sh
2
3 # Agentless monitoring
4 #
5 # Copyright (C) 2009 Trend Micro Inc.
6 # All rights reserved.
7 #
8 # This program is a free software; you can redistribute it
9 # and/or modify it under the terms of the GNU General Public
10 # License (version 2) as published by the FSF - Free Software
11 # Foundation.
12
13 MYNAME="register_host.sh"
14 MYPASS=".passlist"
15
16 # Check the location
17 ls -la $MYNAME > /dev/null 2>&1
18 if [ ! $? = 0 ]; then
19     LOCALDIR=`dirname $0`;
20     cd ${LOCALDIR}
21
22     ls -la $MYNAME > /dev/null 2>&1
23     if [ ! $? = 0 ]; then
24         echo "ERROR: You must run this script from the same directory."
25         exit 1;
26     fi
27 fi
28
29 # Arguments
30 if [ "x$1" = "x" -o "x$1" = "xhelp" -o "x$1" = "x-h" ]; then
31     echo "$0 options:"
32     echo "        add <user@host> [<passwd>] (<additional_pass>)"
33     echo "        list (passwords)"
34     exit 0;
35 fi
36
37 if [ "x$1" = "xlist" ]; then
38     echo "*Available hosts: "
39     if [ "x$2" = "xpasswords" ]; then
40         cat $MYPASS | sort | uniq;
41     else
42         cat $MYPASS | cut -d "|" -f 1 | sort | uniq;
43     fi
44     exit 0;
45
46 elif [ "x$1" = "xadd" ]; then
47     if [ "x$2" = "x" ]; then
48         echo "ERROR: Missing hostname name.";
49         echo "ex: $0 add <user@host> [<passwd>] (<additional_pass>)";
50         exit 1;
51     fi
52
53     grep "$2|" $MYPASS > /dev/null 2>&1
54     if [ $? = 0 ]; then
55         echo "ERROR: Host '$2' already added.";
56         exit 1;
57     fi
58
59     # Check if the password was supplied
60     if [ "x$3" = "x" ]; then
61         echo "Please provide password for host $2."
62         echo -n "Password: ";
63         stty -echo
64         read INPASS
65         stty echo
66
67         echo "Please provide additional password for host $2 (<enter> for empty)."
68         echo -n "Password: ";
69         stty -echo
70         read ADDPASS
71         stty echo
72     else
73         INPASS=$3
74         ADDPASS=$4
75     fi
76
77     echo "$2|$INPASS|$ADDPASS" >> $MYPASS;
78     if [ ! $? = 0 ]; then
79         echo "ERROR: Unable to creating entry (echo failed)."
80         exit 1;
81     fi
82     chmod 744 $MYPASS
83     echo "*Host $2 added."
84
85 else
86     echo "ERROR: Invalid argument.";
87     exit 1;
88
89 fi
90