A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.
1 #!/usr/bin/perl 2 3 # Identify the distro, accounting for slackware. 4 if (-e "/etc/slackware-version") 5 { open(ISSFILE,"/etc/slackware-version"); } 6 else 7 { open(ISSFILE,"/etc/issue") || die "Tried to open /etc/issue to guess your system type, but failed"; } 8 9 my $aline=<ISSFILE>; 10 11 close ISSFILE; 12 13 my $pattype=""; 14 my $inittype=""; 15 my $confpath=""; 16 my $exepath=""; 17 my $initname=""; 18 my $logconf=""; 19 20 if( $aline =~ /Red Hat Enterprise Linux ES release 4/ ) 21 { 22 printf "System type: RH Enterprise\n"; 23 $pattype="rhFC30"; 24 $inittype="$pattype"; 25 $confpath="/etc/"; 26 $exepath="/usr/sbin/"; 27 $initname="sshd"; 28 $logconf="/etc/log.d/conf/services/"; 29 $logserv="/etc/log.d/scripts/services/"; 30 } elsif ( $aline =~ /Fedora Core release 2 / ) { 31 printf "System type: Fedora Core 2, post RH9.0, but not FC3 or FC4\n"; 32 $pattype="rh7390"; 33 $inittype="$pattype"; 34 $confpath="/etc/"; 35 $exepath="/usr/sbin/"; 36 $initname="sshd"; 37 $logconf="/etc/log.d/conf/services/"; 38 $logserv="/etc/log.d/scripts/services/"; 39 } elsif ( $aline =~ /Fedora Core release 4 / ) { 40 printf "System type: Fedora Core 4\n"; 41 $pattype="rhFC30"; 42 $inittype="rhFC40"; 43 $confpath="/etc/"; 44 $exepath="/usr/sbin/"; 45 $initname="sshd"; 46 $logconf="/etc/logwatch/conf/"; 47 $logserv="/etc/logwatch/scripts/"; 48 } elsif( $aline =~ /Fedora/ ) { 49 printf "System type: Fedora, post RH9.0 and post Fedora Core 2\n"; 50 $pattype="rhFC30"; 51 $inittype="$pattype"; 52 $confpath="/etc/"; 53 $exepath="/usr/sbin/"; 54 $initname="sshd"; 55 $logconf="/etc/log.d/conf/services/"; 56 $logserv="/etc/log.d/scripts/services/"; 57 } elsif ( $aline =~ /Red Hat/ ) { 58 printf "System type: RedHat, pre Fedora\n"; 59 $pattype="rh7390"; 60 $inittype="$pattype"; 61 $confpath="/etc/"; 62 $exepath="/usr/sbin/"; 63 $initname="sshd"; 64 $logconf="/etc/log.d/conf/services/"; 65 $logserv="/etc/log.d/scripts/services/"; 66 } elsif ( $aline =~ /Ubuntu/ ) { 67 printf "System type: Ubuntu system\n"; 68 $pattype=""; 69 $inittype="ub80"; 70 $confpath="/etc/"; 71 $exepath="/usr/local/sbin/"; 72 $initname="ssh"; 73 $logconf="/etc/log.d/conf/services/"; 74 $logserv="/usr/share/logwatch/scripts/services/"; 75 } elsif ( $aline =~ /Debian/ ) { 76 printf "System type: Debian system\n"; 77 $pattype="deb31"; 78 $inittype="$pattype"; 79 $confpath="/etc/"; 80 $exepath="/usr/local/sbin/"; 81 $initname="ssh"; 82 $logconf="/etc/log.d/conf/services/"; 83 $logserv="/usr/share/logwatch/scripts/services/"; 84 } elsif ( $aline =~ / SUSE / ) { 85 printf "System type: SUSE system\n"; 86 $pattype="su10rc1"; 87 $inittype="$pattype"; 88 $confpath="/etc/"; 89 $exepath="/usr/local/sbin/"; 90 $initname="sshd"; 91 $logconf="/etc/log.d/conf/services/"; 92 $logserv="/usr/share/logwatch/scripts/services/"; 93 } elsif ( $aline =~ /entoo / ) { 94 printf "System type: Gentoo system\n"; 95 $pattype="su10rc1"; 96 $inittype="$pattype"; 97 $confpath="/etc/"; 98 $exepath="/usr/sbin/"; 99 $initname="sshd"; 100 $logconf="/etc/log.d/conf/services/"; 101 $logserv="/usr/share/logwatch/scripts/services/"; 102 } elsif ( $aline =~ /CentOS 5\./ ) { 103 printf "System type: CentOS 5.x\n"; 104 $pattype="co55"; 105 $inittype="$pattype"; 106 $confpath="/etc/"; 107 $exepath="/usr/sbin/"; 108 $initname="sshd"; 109 $logconf="/etc/log.d/conf/services/"; 110 $logserv="/etc/log.d/scripts/services/"; 111 } elsif ( $aline =~ /CentOS 3\./ ) { 112 printf "System type: CentOS 3.x\n"; 113 $pattype="rhFC30"; 114 $inittype="$pattype"; 115 $confpath="/etc/"; 116 $exepath="/usr/sbin/"; 117 $initname="sshd"; 118 $logconf="/etc/log.d/conf/services/"; 119 $logserv="/etc/log.d/scripts/services/"; 120 } elsif ( $aline =~ /CentOS / ) { 121 printf "System type: CentOS 4.x\n"; 122 $pattype="rh7390"; 123 $inittype="$pattype"; 124 $confpath="/etc/"; 125 $exepath="/usr/sbin/"; 126 $initname="sshd"; 127 $logconf="/etc/log.d/conf/services/"; 128 $logserv="/etc/log.d/scripts/services/"; 129 } elsif ($aline =~ /Slackware/) { 130 printf "System type: Slackware Linux\n"; 131 $pattype = "su10rc1"; 132 $inittype = "slackware"; 133 $confpath = "/etc"; 134 $exepath = "/usr/sbin"; 135 $initname = "sshd"; 136 $logconf="/etc/log.d/conf/services"; 137 $logserv="/etc/log.d/scripts/services"; 138 } else { 139 printf "System type does not appear to be Fedora, RedHat pre Fedora, Debian, \n"; 140 printf "CentOS, SUSE, RH Enterprise, Gentoo or Slackware. So, you will have to install manually \n"; 141 printf "(see INSTALL) and send me some hints on how to identify your system.\n"; 142 exit 1; 143 } 144 145 146 printf "configuration path: $confpath.\n"; 147 printf "exepath: $exepath.\n"; 148 if( -f "$confpath/sshdfilterrc" ) { 149 printf "Not installing configuration file, already exists.\n"; 150 } else { 151 printf "Installing configuration file sshdfilterrc.\n"; 152 system("cat etc/sshdfilterrc | sed \"s|logsource='STDIN'|logsource=\\\'/var/run/sshd.fifo\\\'|\" > /etc/sshdfilterrc"); 153 system("chmod 644 /etc/sshdfilterrc"); 154 } 155 156 printf "Setting up fifo /var/run/sshd.fifo, and changing /etc/syslog.conf. You will need to restart syslog yourself."; 157 system("mkfifo /var/run/sshd.fifo"); 158 system("chmod 600 /var/run/sshd.fifo"); 159 if( ! -f "/etc/syslog.orig" ) { 160 system("cp -p /etc/syslog.conf /etc/syslog.orig"); 161 } 162 system("grep -q \"^authpriv.*/var/run/sshd.fifo\" /etc/syslog.conf || (awk < /etc/syslog.conf '{printf \"%s\\n\",\$0;} /authpriv/ {if(n<1)printf \"authpriv.* |/var/run/sshd.fifo\\n\"; n++; }' > /etc/syslog.txt && mv /etc/syslog.txt /etc/syslog.conf && chmod --reference=/etc/syslog.orig /etc/syslog.conf)"); 163 164 printf "Installing man pages to /usr/share/man/man{1,5}\n"; 165 system("install -m 644 man/sshdfilter.1 /usr/share/man/man1/"); 166 system("install -m 644 man/sshdfilterrc.5 /usr/share/man/man5/"); 167 168 printf "Installing sshdfilter script.\n"; 169 system("install -m 744 source/sshdfilter.pl $exepath/sshdfilter"); 170 171 if ($inittype eq "slackware") { 172 printf "**Not** setting up sshdfilter to start automatically, you will need to do that yourself!\n"; 173 } else { 174 printf "Installing startup script in /etc/init.d/ and adding symlinks.\n"; 175 system("install -m 744 etc/init.d/sshdfilter /etc/init.d/sshdfilter"); 176 for($i=2;$i<=5;$i++) 177 { 178 if (! -l "/etc/rc$i.d/S46sshdfilter") { 179 system("( cd /etc/rc$i.d ; ln -s ../init.d/sshdfilter S46sshdfilter )"); 180 } 181 } 182 } 183 184 #if ( -d "$logconf" ) { 185 # printf "LogWatch directory found, installing LogWatch scripts.\n"; 186 # system("install -m 644 etc/log.d/conf/services/sshdfilt.conf $logconf/"); 187 # system("install -m 644 etc/log.d/scripts/services/sshdfilt $logserv/"); 188 # printf "Modifying $logconf/secure.conf.\n"; 189 # if( ! -f "$logconf/secure.conf.orig" ) { 190 # system("cp $logconf/secure.conf $logconf/secure.conf.orig"); 191 # } 192 # system("sed \"s/ sshdfilt//g;s/ sshd/ sshd sshdfilt/g;\" < $logconf/secure.conf > /tmp/sshdfilt.inst"); 193 # system("install -m 644 /tmp/sshdfilt.inst $logconf/secure.conf"); 194 #} 195 196 printf "Assuming that all worked, read INSTALL for the final steps.\n"; 197 printf "If not, you will have to install manually by reading INSTALL in full,\n"; 198 printf "this script followed route 2, standalone installation.\n"; 199 200