def readTablesFromDBManifests(con): progress.do("gathering schema information from manifests (from database)") cur = con.cursor() cur.execute("""SELECT sc.name, data FROM package_body p JOIN components c ON (c.pkg_id = p.pkg_id) JOIN sc_instances si ON (si.component_id = c.component_id) JOIN service_classes sc ON (sc.sc_id = si.sc_id) WHERE sc.name NOT IN ('pleskd', 'vzpemagent')""") manifest_tables = dict() for row in cur.fetchall(): data = row[1] data = str(data) xml_text = uManifestParser.unsign_package(cStringIO.StringIO(data)) for table in uPDLDBSchema.getSchemaFromString(xml_text): manifest_tables[table.name] = table # Add tables from ejb's reduced descriptor try: earFiles = [] dummy, _mn_plesk_root = uPEM.getMNInfo() from u import bootstrap for root, subFolders, files in os.walk( bootstrap.getJBossDir(_mn_plesk_root) + '/standalone/data/content/'): for file in files: earFiles.append(os.path.join(root, file)) wDir = tempfile.mkdtemp() for earFile in earFiles: progress.do("unzip ear file " + earFile + " to " + wDir) unzipFile(earFile, wDir) progress.done() jarFiles = [f for f in os.listdir(wDir) if f.endswith(".jar")] for jarFile in jarFiles: wDirJar = tempfile.mkdtemp() progress.do("unzip jar file " + jarFile + " to " + wDirJar) unzipFile(os.path.join(wDir, jarFile), wDirJar) progress.done() rdFilePath = os.path.join(wDirJar, 'rd.xml') if not os.path.isfile(rdFilePath): continue rdFile = open(rdFilePath, 'r') rdContent = rdFile.read() rdFile.close() for table in uPDLDBSchema.getSchemaFromString(rdContent): manifest_tables[table.name] = table shutil.rmtree(wDirJar) shutil.rmtree(wDir) except Exception, e: uUtil.logLastException() pass
def _deployBaseExesFiles(files): _, plesk_root = uPEM.getMNInfo() dst_path = os.path.join(plesk_root, Const.getCoreExesDir()) if not os.path.exists(dst_path): uLogging.debug('Create directory: %s' % dst_path) os.makedirs(dst_path) for src_file_path in files: file_name = os.path.basename(src_file_path) dst_file_path = os.path.join(dst_path, file_name) uLogging.debug('Copying %s to %s' % (src_file_path, dst_file_path)) shutil.copy2(src_file_path, dst_file_path)
def ppm_ctl_cmd(): global _mn_plesk_root, _ppm_ctl_cmd if _ppm_ctl_cmd is None: if _mn_plesk_root is None: dummy, _mn_plesk_root = uPEM.getMNInfo() _ppm_ctl_cmd = [ os.path.join(_mn_plesk_root, 'bin', 'ppm_ctl'), '-b', '-q', '-f', os.path.join(_mn_plesk_root, 'etc', 'pleskd.props') ] return _ppm_ctl_cmd
def _getCumulativeAgents(agents_dir): _, plesk_root = uPEM.getMNInfo() agents_path = os.path.join(plesk_root, agents_dir) if os.path.exists(agents_path): uLogging.debug('Reading cumulative agents from: %s' % agents_path) return getBuildFromFS(agents_path, os.path.basename(os.path.realpath(agents_path)), None, False, False, None, corerpms_dir_pattern) else: uLogging.warn('No directory with cumulative agents: %s' % agents_path) return None
def find_newer_sc_pkg_id(con, pkg_id, pkg_name, pkg_version): cur = con.cursor() for platform in uPEM.getPlatformLine(con, uPEM.getMNInfo()[0]): uLogging.debug("Searching latest {pkg_name} package for platform {platform}".format(pkg_name=pkg_name, platform=platform)) cur.execute(""" SELECT p.pkg_id, p.version FROM packages p JOIN packages p2 ON (p.name = p2.name AND p.ctype = p2.ctype) WHERE p2.pkg_id = %s AND p.platform_id = %s """, pkg_id, platform.platform_id) rows = cur.fetchall() if not rows: continue new_package = max(rows, key=lambda x: LooseVersion(x[1])) if LooseVersion(new_package[1]) > LooseVersion(pkg_version): uLogging.debug("Higher version package found: " "%s (platform = %s, pkg_id = %d)", pkg_name, platform, new_package[0]) return new_package[0] return None
def generate_self_signed_certificate(subj): openssl_conf = """ # # OpenSSL configuration file. # # Establish working directory. dir = . [ ca ] default_ca = CA_default [ CA_default ] serial = $dir/serial database = $dir/certindex.txt new_certs_dir = $dir/certs certificate = $dir/cacert.pem private_key = $dir/private/cakey.pem default_days = 36500 default_md = sha256 preserve = no email_in_dn = no nameopt = default_ca certopt = default_ca policy = policy_match [ policy_match ] countryName = match stateOrProvinceName = match organizationName = match organizationalUnitName = optional commonName = supplied emailAddress = optional [ req ] default_bits = 2048 # Size of keys default_keyfile = key.pem # name of generated keys default_md = sha256 # message digest algorithm string_mask = nombstr # permitted characters distinguished_name = req_distinguished_name req_extensions = v3_req [ req_distinguished_name ] # Variable name Prompt string #------------------------- ---------------------------------- 0.organizationName = Organization Name (company) organizationalUnitName = Organizational Unit Name (department, division) emailAddress = Email Address emailAddress_max = 40 localityName = Locality Name (city, district) stateOrProvinceName = State or Province Name (full name) countryName = Country Name (2 letter code) countryName_min = 2 countryName_max = 2 commonName = Common Name (hostname, IP, or your name) commonName_max = 64 [ v3_ca ] basicConstraints = CA:TRUE subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer:always [ v3_req ] basicConstraints = CA:FALSE subjectKeyIdentifier = hash """ platform, root = uPEM.getMNInfo() privkey_path = os.path.join(root, 'priv_key.pem') cert_path = os.path.join(root, 'cert.pem') ssl_conf_path = os.path.join(root, 'pem_openssl.cnf') uLogging.debug("creating SSL config file at '%s'" % ssl_conf_path) ssl_cnf_file = open(ssl_conf_path, 'w+') ssl_cnf_file.write(openssl_conf) ssl_cnf_file.close() openssl_binary = _get_openssl_binary() out_text, err_text, status = uUtil.readCmdExt([ openssl_binary, "req", "-new", "-x509", "-newkey", "rsa:2048", "-keyout", privkey_path, "-out", cert_path, "-days", "36500", "-subj", subj, "-nodes", "-config", ssl_conf_path ], env=os.environ.copy()) uLogging.debug("openssl exited with status: %s", status) uLogging.debug("openssl executed with result:\nstderr:\n%s\nstdout:\n%s\n", err_text, out_text) # Read created private key privkey_file = open(privkey_path, 'r') b64privkey = privkey_file.read() privkey_file.close() # Read created certificate cert_file = open(cert_path, 'r') b64cert = cert_file.read() cert_file.close() # cleanup os.remove(privkey_path) os.remove(cert_path) os.remove(ssl_conf_path) return b64privkey, b64cert