Merge branch 'extensions'

* extensions:
  Changes to support extensions.
  Extension: a good source of porn links
  Data source update.
  First code alterations for extensions.
  FIrst extension: hosts file for porn sites
This commit is contained in:
Steven Black
2016-02-22 19:21:00 -05:00
3 changed files with 5865 additions and 4 deletions
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/pornography-hosts
+18 -4
View File
@@ -76,9 +76,11 @@ def listdir_nohidden(path):
# Project Settings
BASEDIR_PATH = os.path.dirname(os.path.realpath(__file__))
DATA_PATH = os.path.join(BASEDIR_PATH, 'data')
EXTENSIONS_PATH = os.path.join(BASEDIR_PATH, 'extensions')
DATA_FILENAMES = 'hosts'
UPDATE_URL_FILENAME = 'update.info'
SOURCES = listdir_nohidden(DATA_PATH)
EXTENSIONS = listdir_nohidden(EXTENSIONS_PATH)
README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md')
README_FILE = os.path.join(BASEDIR_PATH, 'readme.md')
WHITELIST_FILE = os.path.join(BASEDIR_PATH, 'whitelist')
@@ -94,18 +96,25 @@ exclusionRegexs = []
numberOfRules = 0
auto = False
targetIP = "0.0.0.0"
extensions = []
def main():
parser = argparse.ArgumentParser(description="Creates an amalgamated hosts file from hosts stored in data subfolders.")
parser.add_argument("--auto", "-a", dest="auto", default=False, action='store_true', help="Run without prompting.")
parser.add_argument("--ip", "-i", dest="targetIP", default="0.0.0.0", help="Target IP address. Default is 0.0.0.0")
parser.add_argument("--ip", "-i", dest="targetIP", default="0.0.0.0", help="Target IP address. Default is 0.0.0.0.")
parser.add_argument("--extensions", "-e", dest="extensions", default=[], nargs='*', help="Host extensions to include in the final hosts file.")
args = parser.parse_args()
global auto, targetIP
global auto, targetIP, extensions
auto = args.auto
targetIP = args.targetIP
# All our extensions folders...
extensions = [os.path.basename(item) for item in listdir_nohidden(EXTENSIONS_PATH)]
# ... intersected with the extensions passed-in as arguments
extensions = list(set(args.extensions).intersection(extensions))
promptForUpdate()
promptForExclusions()
mergeFile = createInitialFile()
@@ -194,7 +203,8 @@ def matchesExclusions(strippedRule):
# Update Logic
def updateAllSources():
for source in SOURCES:
allsources = list(set(SOURCES) | set(EXTENSIONS))
for source in allsources:
updateURL = getUpdateURLFromFile(source)
if updateURL is None:
continue
@@ -211,7 +221,6 @@ def updateAllSources():
except:
print ("Skipping.")
def getUpdateURLFromFile(source):
pathToUpdateFile = os.path.join(DATA_PATH, source, UPDATE_URL_FILENAME)
if os.path.exists(pathToUpdateFile):
@@ -233,6 +242,11 @@ def createInitialFile():
#Done in a cross-python way
writeData(mergeFile, curFile.read())
for source in extensions:
curFile = open(os.path.join(EXTENSIONS_PATH, source, DATA_FILENAMES), 'r')
#Done in a cross-python way
writeData(mergeFile, curFile.read())
return mergeFile
def removeDupsAndExcl(mergeFile):