File: dh_reenable

package info (click to toggle)
denyhosts 2.6-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 464 kB
  • ctags: 420
  • sloc: python: 2,159; sh: 356; makefile: 19
file content (84 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# This program help sysadmin to reenable a hosts blocked by denyhosts.
#
# dh_reenable (c) 2008 Marco Bertorello <marco@bertorello.ns0.it> and is
# free software. You can use, modify and redistribute it under terms of
# GNU General Public License version 2 or later, as you whish, as published by
# Free Software Foundation.
#
# You can get a full copy of license here:
#
# http://www.gnu.org/licenses/gpl-2.0.txt
#
# and
#
# http://www.gnu.org/licenses/gpl-3.0.txt


import os
import sys
import fileinput

# file definition:

HOSTSFILE='/var/lib/denyhosts/hosts'
HOSTRESTFILE='/var/lib/denyhosts/hosts-restricted'
HOSTROOTFILE='/var/lib/denyhosts/hosts-root'
HOSTVALIDFILE='/var/lib/denyhosts/hosts-valid'
HOSTSDENY='/etc/hosts.deny'
#TEST='/etc/hosts.deny.tmp'


def usage():
	 print "Usage:"
         print sys.argv[0]+"     --help: Show this help"
         print sys.argv[0]+"       <IP>: check if the ip address was denied and reenable it"
         print sys.argv[0]+" <HOSTNAME>: check if the hostname was denied and reenable it"

try:
	host=sys.argv[1]
except:
	print sys.argv[0]+" need a hostname or a ip address input. See --help."
	sys.exit(1)

if host == "--help":
        usage()
        sys.exit(1)

def search(file_txt,host):
	for lines in fileinput.FileInput(file_txt, inplace=1): 	
	 	lines = lines.strip()
	 	if lines.find(host) != -1: 
			continue
		else:
	 		print lines


try:
	search(HOSTSFILE,host)
except:
	print "Problem parsing file "+HOSTSFILE
	sys.exit(1)
try:
	search(HOSTRESTFILE,host)
except:
	print "Problem parsing file "+HOSTRESTFILE
	sys.exit(1)
try:
	search(HOSTROOTFILE,host)
except:
        print "Problem parsing file "+HOSTROOTFILE
	sys.exit(1)
try:
	search(HOSTVALIDFILE,host)
except:
        print "Problem parsing file "+HOSTVALIDFILE
	sys.exit(1)
try:
	search(HOSTSDENY,host)
except:
        print "Problem parsing file "+HOSTSDENY
	sys.exit(1)

print "Done!"
print "Please restart denyhosts"