def get_config_file(filename, original_content):
    config_file = mktemp()

    try:
        c = Path.__getattr__(filename)
        if exists(c) and access(c, R_OK):
            config_file = c
        else:
            raise Exception()
    except:
        # Using temporary file
        cfile = open(config_file, "w")
        cfile.write(original_content)
        cfile.close()

    log.debug(">>> Get config file %s: %s" % (filename, config_file))
    return config_file
예제 #2
0
import httplib
import mimetypes
from urllib import quote, unquote, urlencode
from tempfile import mktemp

sys.path += [os.path.join(os.path.dirname(__file__), "..", "")]

from umitWeb.WebLogger import getLogger
from umitWeb.Security import Context
from umitWeb.ProfileParser import ProfileEditorParser, WizardParser

######################################
# Setting the umit home directory

from umitCore.Paths import Path
Path.set_umit_conf(
    os.path.join(os.path.split(__file__)[0], os.pardir, 'config', 'umit.conf'))
######################################


class HttpTestCase(unittest.TestCase):
    logger = getLogger("HttpTestCase")

    def setUp(self):
        self.server_url = "http://localhost:8059"
        self.info_url = "%s/test/server/info/" % self.server_url
        self.req_info = urllib2.Request(self.info_url)

    def get_cookie(self, headers, name):
        try:
            pattern = r".*%s=([^;]+)[;]{0,1}.*" % name
            return re.findall(pattern, headers['set-cookie'])[0]
예제 #3
0
import mimetypes
from urllib import quote, unquote, urlencode
from tempfile import mktemp

sys.path += [os.path.join(os.path.dirname(__file__), "..", "")]

from umitWeb.WebLogger import getLogger
from umitWeb.Security import Context
from umitWeb.ProfileParser import ProfileEditorParser, WizardParser


######################################
# Setting the umit home directory

from umitCore.Paths import Path
Path.set_umit_conf(os.path.join(os.path.split(__file__)[0], os.pardir,'config', 'umit.conf'))
######################################


class HttpTestCase(unittest.TestCase):
    logger = getLogger("HttpTestCase")
    
    def setUp(self):
        self.server_url = "http://localhost:8059"
        self.info_url = "%s/test/server/info/" % self.server_url
        self.req_info = urllib2.Request(self.info_url)
        
    def get_cookie(self, headers, name):
        try:
            pattern = r".*%s=([^;]+)[;]{0,1}.*" % name
            return re.findall(pattern, headers['set-cookie'])[0]
예제 #4
0
    def add_target(self, target):
        # to keep stack order;
        # if the target is on the list, we have to move it at the beginning
        if target in self.temp_list:
            self.temp_list.remove(target)

        self.temp_list.append(target)
        self.save()

    def clean_list(self):
        del self.temp_list
        self.temp_list = []
        self.save()

    def get_target_list(self):
        t = self.temp_list[:]
        t.reverse()
        return t

target_list = TargetList()

if __name__ == "__main__":
    import sys
    from os.path import split
    Path.set_umit_conf(split(sys.argv[0])[0])
    t = TargetList()
    print ">>> Getting empty list:", t.get_target_list()
    print ">>> Adding target 127.0.0.1:", t.add_target("127.0.0.3")
    print ">>> Getting target list:", t.get_target_list()
    del t
예제 #5
0
    def add_target(self, target):
        # to keep stack order;
        # if the target is on the list, we have to move it at the beginning
        if target in self.temp_list:
            self.temp_list.remove(target)

        self.temp_list.append(target)
        self.save()

    def clean_list(self):
        del self.temp_list
        self.temp_list = []
        self.save()

    def get_target_list(self):
        t = self.temp_list[:]
        t.reverse()
        return t


target_list = TargetList()

if __name__ == "__main__":
    import sys
    from os.path import split
    Path.set_umit_conf(split(sys.argv[0])[0])
    t = TargetList()
    print ">>> Getting empty list:", t.get_target_list()
    print ">>> Adding target 127.0.0.1:", t.add_target("127.0.0.3")
    print ">>> Getting target list:", t.get_target_list()
    del t
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import unittest

# Setting up Paths so UmitConf can be correctly loaded
from os.path import join
from umitCore.Paths import Path
Path.set_umit_conf([join("share", "umit", "config", "umit.conf")])

# Loading UmitConf files
from umitCore.TargetList import target_list


class TestTargetList(unittest.TestCase):
    def setUp(self):
        self.umit_conf = UmitConf()

    def tearDown(self):
        del self.umit_conf

    def testAddTarget(self):
        target_list.add_target("127.0.0.1")
예제 #7
0
 def set_umit_conf(self, base_dir):
     Paths.set_umit_conf(self, base_dir)
     Path.set_umit_conf(base_dir)
     if not exists(join(self.config_dir, "security.xml")) or not exists(join(self.config_dir, "umitweb.conf")):
         create_web_files(self.config_file, HOME)
예제 #8
0
 def set_umit_conf(self, base_dir):
     Paths.set_umit_conf(self, base_dir)
     Path.set_umit_conf(base_dir)
     if not exists(join(self.config_dir, "security.xml")) or \
        not exists(join(self.config_dir, "umitweb.conf")):
         create_web_files(self.config_file, HOME)