getDocRoot changes

This commit is contained in:
Miroslav Stampar 2010-01-05 11:30:33 +00:00
parent bb61010a45
commit 71547a3496
2 changed files with 25 additions and 12 deletions

View File

@ -30,6 +30,8 @@ import string
import sys import sys
import time import time
import urlparse import urlparse
import ntpath
import posixpath
from lib.contrib import magic from lib.contrib import magic
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
@ -215,7 +217,7 @@ def getHtmlErrorFp():
def getDocRoot(): def getDocRoot():
docRoot = None docRoot = None
pagePath = os.path.dirname(conf.path) pagePath = directoryPath(conf.path)
if kb.os == "Windows": if kb.os == "Windows":
defaultDocRoot = "C:/Inetpub/wwwroot/" defaultDocRoot = "C:/Inetpub/wwwroot/"
@ -224,14 +226,13 @@ def getDocRoot():
if kb.absFilePaths: if kb.absFilePaths:
for absFilePath in kb.absFilePaths: for absFilePath in kb.absFilePaths:
absFilePath = normalizePath(absFilePath)
absFilePathWin = None absFilePathWin = None
if re.search("[A-Za-z]:(\\[\w.\\]*)?", absFilePath): if re.match("[A-Za-z]:(\\[\w.\\]*)?", absFilePath):
absFilePathWin = absFilePath absFilePathWin = absFilePath
absFilePath = absFilePath[2:].replace("\\", "/") absFilePath = absFilePath[2:].replace("\\", "/")
absFilePath = os.path.normpath(absFilePath)
if pagePath in absFilePath: if pagePath in absFilePath:
index = absFilePath.index(pagePath) index = absFilePath.index(pagePath)
docRoot = absFilePath[:index] docRoot = absFilePath[:index]
@ -832,3 +833,19 @@ def sanitizeCookie(cookieStr, warn=False):
return result return result
else: else:
return None return None
def directoryPath(path):
retVal = None
if path.find('/') != -1:
retVal = posixpath.dirname(path)
else:
retVal = ntpath.dirname(path)
return retVal
def normalizePath(path):
retVal = None
if path.find('/') != -1:
retVal = posixpath.normpath(path)
else:
retVal = ntpath.normpath(path)
return retVal

View File

@ -27,11 +27,10 @@ import os
import re import re
import StringIO import StringIO
import zlib import zlib
import ntpath
import posixpath
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
from lib.core.common import directoryPath
from lib.parse.headers import headersParser from lib.parse.headers import headersParser
from lib.parse.html import htmlParser from lib.parse.html import htmlParser
@ -76,13 +75,10 @@ def parseResponse(page, headers):
reobj = re.compile(absFilePathRegExp) reobj = re.compile(absFilePathRegExp)
for match in reobj.finditer(page): for match in reobj.finditer(page):
absFilePath = match.group("result") absFilePath = match.group("result").strip()
if absFilePath not in kb.absFilePaths: if absFilePath not in kb.absFilePaths:
if absFilePath.find('/') != -1: dirname = directoryPath(absFilePath)
dirname = posixpath.dirname(absFilePath)
else:
dirname = ntpath.dirname(absFilePath)
kb.absFilePaths.add(dirname) kb.absFilePaths.add(dirname)
def decodePage(page, encoding): def decodePage(page, encoding):