def upload_server_cert(self): dialog = UploadDialog( selector_label=tr("LDAP certificate"), filter=tr("Certificate file (*.crt *.pem *)") ) accepted = dialog.exec_() if accepted != QDialog.Accepted: return filename = dialog.filename if not filename: return with open(filename, 'rb') as fd: content = fd.read() content = encodeFileContent(content) self.mainwindow.addToInfoArea(tr('Uploading of a certificate file for the ldap server')) async = self.mainwindow.client.async() async.call("nuauth", "upload_ldap_server_cert", content, callback = self.success_upload, errback = self.error_upload )
def upload_file(self): dialog = RestoreConfirmDialog() accept = dialog.exec_() if not accept: return dialog = UploadDialog( selector_label=tr("Select an EdenWall archive"), filter=tr("EdenWall archive (*.tar.gz *)") ) accepted = dialog.exec_() if accepted != QDialog.Accepted: return filename = dialog.filename if not filename: return with open(filename, "rb") as fd: content = fd.read() content = encodeFileContent(content) self.mainwindow.addToInfoArea(tr("Uploading of an archive file to restore the appliance")) async = self.mainwindow.client.async() async.call("nurestore", "restore", content, callback=self.success_upload, errback=self.error_upload) self._start_splash(tr("Uploading EdenWall restoration archive..."))
def sendKeytab(self, filename): with open(filename, 'rb') as fd: content = fd.read() content = encodeFileContent(content) self.mainwindow.addToInfoArea(tr('Upload a keytab file')) async = self.mainwindow.client.async() async.call('nuauth', "upload_krb_keytab", content, callback = self.success_upload, errback = self.error_upload )
def service_getClientConfig(self, context): """ Return a string containing a configuration for a client. """ try: with open(self.CLIENT_CONF) as fd: return encodeFileContent(fd.read()) except IOError: raise OpenVpnError(OPENVPN_CLIENT_CONF_UNAVAILABLE, tr('The client configuration for VPN client is not available. ' 'Have you configured the VPN client service, ' 'then saved and applied the configuration?'))
def service_getDiagnosticFile(self, context): """ Return a diagnostic file, containing the result of various command """ process = createProcess(self, '/usr/share/ufwi_rpcd/scripts/diagnostic', stdout=subprocess.PIPE, stderr=subprocess.PIPE, locale=False) return_code, out, err = communicateProcess(self, process, DEFAULT_TIMEOUT) if return_code != 0: raise CreateDiagFailed(err) tmp_dir = out[0].strip() with open(tmp_dir + "/diagnostic.tar.gz") as fd: result = encodeFileContent(fd.read()) try: rmtree(tmp_dir) except Exception, err: self.error( 'Could not delete temporary diagnostic directory (%s).', err)
def chooseAndSendFile(self): filename = unicode( QFileDialog.getOpenFileName(self.mainwindow, translate('MainWindow', 'Select the EdenWall activation key file to upload'))) if not filename: return basefilename = basename(filename) with open(filename, 'rb') as fd: content = fd.read() try: minimalmode = self.client.call('acl', 'getMinimalMode') if self.client.call('license', 'sendLicense', encodeFileContent(content)): self.mainwindow.addToInfoArea(translate('MainWindow', "Uploaded activation key file") + " `%s'." % basefilename) try: need_ufwi_rpcd_restart = self.client.call( "license", "needNucentralRestart") except Exception: need_ufwi_rpcd_restart = False if need_ufwi_rpcd_restart: self.mainwindow.addToInfoArea( tr("You need to restart the configuration " "service and EAS to use the protocol analysis " "configuration service")) if need_ufwi_rpcd_restart or ( minimalmode and not self.client.call('acl', 'getMinimalMode')): self.pleaseRestartEASDialog(need_ufwi_rpcd_restart) else: self.mainwindow.addToInfoArea(translate('MainWindow', "No new activation key for this appliance in this file.")) except RpcdError, err: self.mainwindow.addToInfoArea(translate('MainWindow', "Error while uploading activation key file") + " `%s': %s" % (basefilename, exceptionAsUnicode(err)), category=COLOR_CRITICAL)
def choose_and_upload(self): # Get filename open_caption = tr("Select a CA certificate to upload") filename = unicode( QFileDialog.getOpenFileName(self, open_caption,)) if not filename: return # Check file size (<= 5 MB). if os.path.getsize(filename) > 5 * 1024 * 1024: error_message = tr( "Error: The file you are trying to upload is larger than " "5 MB. Are you sure it is a CA certificate?") self.main_widget.main_window.addToInfoArea(error_message, category=COLOR_ERROR) return False # Read content and encode it to base64 with open(filename, 'rb') as fd: content = fd.read() content_base64 = encodeFileContent(content) content = None self.conf.ca_cert = content_base64 return True
for filename in glob(path_join(directory, "*.xml")): name = basename(filename) name = name[:-4] timestamp = stat(filename).st_mtime timestamp = datetime.fromtimestamp(timestamp) yield (name, unicode(timestamp)) def rulesetDownload(filetype, name): filename = rulesetFilename(filetype, name) try: with open(filename, "rb") as fp: content = fp.read() except IOError, err: raise RulesetError(tr('Unable to open "%s" (%s): %s!'), basename(filename), filetype, exceptionAsUnicode(err)) return encodeFileContent(content) 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)