コード例 #1
0
    def _setSSLConfigFiles(self, config):
        if not config['disable_crl'] and not config['crl']:
            ## Check a crl has previously been uploaded:
            try:
                with open(self.CRL_PATH, 'r') as fp:
                    fp.read()
            except IOError:
                raise RpcdError(tr("No CRL has previously been uploaded. CRL check cannot be enabled."))

        tmp_file = {}
        tmp_ssl_config = SSLConfig()
        tmp_ssl_options = {}

        self.warning('Validate uploaded certificate')

        umask(0177)
        for key in self.CERT_ATTR_TO_PATH.keys():
            if not config[key]:
                continue
            content = decodeFileContent(config[key])

            tmp_file[key] = NamedTemporaryFile("wb")
            tmp_file[key].write(content)
            tmp_file[key].flush()
            tmp_ssl_options[key] = tmp_file[key].name

        tmp_ssl_config.setConfig(**tmp_ssl_options)

        # Check key and cert if one of the 2 was provided
        tmp_ssl_config.send_cert = False
        if 'cert' in config and config['cert']:
            tmp_ssl_config.send_cert = True
        if 'key' in config and config['key']:
            tmp_ssl_config.send_cert = True

        # Check ca and crl if one of the 2 was provided
        if 'ca' in config and config['ca']:
            tmp_ssl_config.check = True
        if 'crl' in config and config['crl']:
            tmp_ssl_config.check = True

        validation = tmp_ssl_config.validate()

        for key in self.CERT_ATTR_TO_PATH.keys():
            if key in tmp_file:
                tmp_file[key].close()

        if validation is not None:
            raise RpcdError(validation)

        self.warning('Write the uploaded certificate')
        # FIXME: use a transaction to write PEM files
        for key in self.CERT_ATTR_TO_PATH.keys():
            if not config[key]:
                continue
            with open(self.CERT_ATTR_TO_PATH[key], 'w') as fp:
                fp.write(decodeFileContent(config[key]))
コード例 #2
0
ファイル: ruleset_list.py プロジェクト: maximerobin/Ufwi
def rulesetUpload(component, logger, filetype, input_filename, content, netcfg):

    # Extract ruleset name from the input filename
    name = basename(input_filename)
    if not name.lower().endswith(".xml"):
        raise RulesetError('File extension is not ".xml"!')
    name = name[:-4]

    # Ensure that the ruleset doesn't exist on disk
    rulesetFilename(filetype, name, check_existing=True)

    # Decode the content
    content = decodeFileContent(content)

    # Open the ruleset the check the consistency
    ruleset = Ruleset(component, logger, netcfg, read_only=True)
    ruleset.load(logger, filetype, name, content=content)
    if component.core.getMultisiteType() == MULTISITE_SLAVE:
        if exists(MULTISITE_TEMPLATE_FILENAME):
            template = MULTISITE_TEMPLATE_NAME
        else:
            template = None
        replaceTemplate(logger, ruleset, template)

    # Write the ruleset
    try:
        ruleset.save()
    except IOError, err:
        raise RulesetError(
            tr("Unable to write into the file %s (%s): %s!"),
            basename(ruleset.filename),
            ruleset.filetype,
            exceptionAsUnicode(err),
        )
コード例 #3
0
ファイル: license.py プロジェクト: maximerobin/Ufwi
 def service_sendLicense(self, context, encoded_bin):
     decoded_content = decodeFileContent(encoded_bin)
     found_license_for_me = False
     for license_text in self._iter_licenses(decoded_content):
         if self._handle_single_license(context, license_text):
             found_license_for_me = True
     self.check_validity()
     return found_license_for_me
コード例 #4
0
    def success_download(self, value):
        self._stop_splash()
        encoded, components = value
        self.mainwindow.addToInfoArea(tr("Downloaded EdenWall configuration"))

        extension = "*.tar.gz"
        archive_description = tr("Edenwall archive file")
        filter = "%s (%s)" % (archive_description, extension)

        date = datetime.now().strftime("%c")
        date = toUnicode(date)
        date = date.replace(".", "")
        date = date.replace(" ", "_")
        date = date.replace(":", "-")

        host = self.mainwindow.client.host
        host = host.replace(".", "_")
        host = host.replace(":", "-")
        suggestion = u"edenwall-config-%s-%s.tar.gz" % (host, date)

        filename = QFileDialog.getSaveFileName(
            self, tr("Choose a filename to save under"), join(SaveRestoreWidget.last_save_position, suggestion), filter
        )

        filename = unicode(filename)

        if not filename:
            self.mainwindow.addToInfoArea(tr("EdenWall configuration save cancelled"))
            return

        SaveRestoreWidget.last_save_position = split(filename)[0]

        try:
            with open(filename, "wb") as fd:
                fd.write(decodeFileContent(encoded))
        except IOError, err:
            message_vars = (tr("An error occured while saving EdenWall configuration:"), toUnicode(strerror(err.errno)))

            text_message = "%s\n%s" % message_vars
            self.mainwindow.addToInfoArea(text_message, category=COLOR_ERROR)

            html_message = "<span>%s<br/><b>%s</b></span>" % message_vars
            QMessageBox.critical(self, tr("Save error"), html_message)
            return
コード例 #5
0
ファイル: roadwarrior.py プロジェクト: maximerobin/Ufwi
 def successDiag(self, file_, filename, desc):
     with open(filename, 'wb') as fd:
         fd.write(decodeFileContent(file_))
     self.mainwindow.addToInfoArea(tr("%s saved in '%s'.") % (desc,
                                                              filename))