Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        
        context = super(ViewSafetySystemInfo, self).get_context_data(**kwargs)

        v = Version()

        info = {
            'product_name'      : 'Web Safety for Squid Proxy',
            'installed_version' : v.installed,
            'latest_version'    : v.latest,
            'need_to_upgrade'   : v.need_to_upgrade(),        # 0 - no_need_to_upgrade, 1 - may_upgrade, 2 - should_upgrade, 3 - must_upgrade
            'whats_new'         : v.whats_new
        };
        context['info'] = info

        # add hardcoded settings
        context['WEBSAFETY_ETC_DIR']      = Paths.etc_dir()
        context['WEBSAFETY_ETC_DIR_SIZE'] = long(FolderInfo(Paths.etc_dir()).get_size()) 
        context['WEBSAFETY_VAR_DIR']      = Paths.var_dir()
        context['WEBSAFETY_VAR_DIR_SIZE'] = long(FolderInfo(Paths.var_dir()).get_size())
        context['WEBSAFETY_BIN_DIR']      = Paths.bin_dir()
        context['WEBSAFETY_BIN_DIR_SIZE'] = long(FolderInfo(Paths.bin_dir()).get_size())
        context['WEBSAFETY_VERSION']      = Build.version()
        context['WEBSAFETY_ARCH']         = Distrib.arch()
        context['WEBSAFETY_DISTRIB']      = Distrib.name()
        context['WEBSAFETY_SYSTEM']       = System.name()
        
        return context
Ejemplo n.º 2
0
    def generate_linux(self, devices, manual):

        # debug check
        assert (System.WS_LINUX == System.name())

        # what distrib we have
        distrib = Distrib.name()

        # we only generate network settings for debian/ubuntu for now
        if distrib in [Distrib.WS_DEBIAN9, Distrib.WS_UBUNTU16]:
            return self.generate_linux_debian(devices, manual)

        raise Exception(
            "NetworkGenerateView::generate_linux - generator is not implemented for distrib: '%s'"
            % Distrib.name())
Ejemplo n.º 3
0
    def generate(self, contents):

        # debug check
        assert (len(contents) > 0)

        # first generate a temporary file in /opt/websafety/etc/node folder (it will be removed after close automatically)
        prefix = "etc_network_interfaces."
        folder = os.path.join(Paths.etc_dir(), "node")

        # write to temp file
        with tempfile.NamedTemporaryFile(prefix=prefix,
                                         dir=folder,
                                         delete=True) as temp:

            temp.write(contents)
            temp.flush()

            # call the sudoing binary
            exe = os.path.join(Paths.bin_dir(), "network_debian.py")
            arg1 = "--file=%s" % temp.name
            arg2 = "--system=%s" % System.name()
            arg3 = "--distrib=%s" % Distrib.name()
            args = [exe, arg1, arg2, arg3]

            # and run it
            (exit_code, stdout, stderr) = CommandElevated().run(args)
            if exit_code != 0:
                raise Exception(
                    "Cannot generate network settings. Error: %d, STDOUT: %s, STDERR: %s"
                    % (exit_code, stdout, stderr))
def is_pfsense(request):

    is_pfsense = False
    if Distrib.WS_PFSENSE == Distrib.name():
        is_pfsense = True

    return {'is_pfsense': is_pfsense}
Ejemplo n.º 5
0
    def configured_tz_linux(self):

        # debug check
        assert(System.name() == System.WS_LINUX)

        # assume default
        value = self.default

        # see if this is centos style
        if Distrib.WS_CENTOS7 == Distrib.name():

            etc_localtime = "/etc/localtime"
            usr_zoneinfo  = "/usr/share/zoneinfo/"

            # see if local time is a link or not
            if os.path.islink(etc_localtime):

                value = os.path.realpath(etc_localtime)
                if value.startswith(usr_zoneinfo):
                    value = value[len(usr_zoneinfo):]

        else:

            # ok this is debian style then
            with open('/etc/timezone') as fin:
                value = fin.read()                
                value = value.strip()

        # return nicely
        return value
Ejemplo n.º 6
0
    def set(self, value):

        assert(len(value) > 0)

        # check the provided timezone indeed exists in the pytz
        if value not in pytz.all_timezones:
            raise Exception("Wrong timezone %s (not found pytz.all_timezones)" % value)

        # save the new timezone into the system
        exe  = os.path.join(Paths.bin_dir(), "timezone.py")
        arg1 = "--timezone=%s" % value
        arg2 = "--system=%s" % System.name()
        arg3 = "--distrib=%s" % Distrib.name()
        args = [exe, arg1, arg2, arg3]

        (ret, stdout, stderr) = CommandElevated().run(args)

        # the system zone is set if return value is 0
        if ret == 0:

            # also generate the timezone.setting file
            tz_file = os.path.join(Paths.var_dir(), "console", "console", "timezone.setting")
            with open(tz_file,"w") as fout:
                fout.write(value)

        # and return
        return (ret, stdout, stderr)
Ejemplo n.º 7
0
    def runas_user():

        if System.WS_WINDOWS == System.name():
            return "unknown"

        if System.WS_FREEBSD == System.name():
            return "squid"

        assert (System.WS_LINUX == System.name())

        if Distrib.WS_CENTOS7 == Distrib.name():
            return "squid"

        if Distrib.name() in [Distrib.WS_DEBIAN9, Distrib.WS_UBUNTU16]:
            return "proxy"

        raise Exception("Unknown distrib '%s' in BinarySquid.runas_user" %
                        Distrib.name())
Ejemplo n.º 8
0
    def can_manage_network(self):

        # for debug
        if System.WS_WINDOWS == System.name():
            return True

        if System.WS_LINUX == System.name():
            if Distrib.name() in [Distrib.WS_DEBIAN9, Distrib.WS_UBUNTU16]:
                return True

        return False
Ejemplo n.º 9
0
    def set(self, value):

        assert (len(value) > 0)

        exe = os.path.join(Paths.bin_dir(), "hostname.py")
        arg1 = "--hostname=%s" % value
        arg2 = "--system=%s" % System.name()
        arg3 = "--distrib=%s" % Distrib.name()
        args = [exe, arg1, arg2, arg3]

        return CommandElevated().run(args)
Ejemplo n.º 10
0
    def __init__(self):

        downloader = FileDownloader(Build.version(), Distrib.arch())
        self.installed = Build.version()

        try:
            content = downloader.download_file(
                "https://defs.diladele.com/websafety/version/%s/" %
                Distrib.name())
            data = json.loads(content)

            self.latest = data['current']
            self.whats_new = data['whats_new_txt']
            self.whats_new_html = data['whats_new_html']
            self.whats_new_md = data['whats_new_md']

        except Exception as e:

            self.latest = "!ERROR OCCURRED! %s" % str(e)
            self.whats_new = str(e)
            self.whats_new_html = str(e)
            self.whats_new_md = str(e)
Ejemplo n.º 11
0
    def get_path(self):

        # windows (for debug only)
        if System.WS_WINDOWS == System.name():
            return r"m:\websafety_extra\src.test\res\squid.conf"

        # freebsd
        if System.WS_FREEBSD == System.name():
            return "/usr/local/etc/squid/squid.conf"

        # debug check
        assert (System.WS_LINUX == System.name())

        # centos and redhat
        if Distrib.WS_CENTOS7 == Distrib.name():
            return "/etc/squid/squid.conf"

        # by default - debian and ubuntu
        return "/etc/squid/squid.conf"