本文整理汇总了Python中nginx.dumpf函数的典型用法代码示例。如果您正苦于以下问题:Python dumpf函数的具体用法?Python dumpf怎么用?Python dumpf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumpf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ssl_disable
def ssl_disable(self, data):
name, stype = data.name, data.stype
port = '80'
s = None
c = nginx.loadf('/etc/nginx/sites-available/'+name)
if len(c.servers) > 1:
for x in c.servers:
if not 'ssl' in x.filter('Key', 'listen')[0].value \
and x.filter('key', 'return'):
c.remove(x)
break
s = c.servers[0]
l = s.filter('Key', 'listen')[0]
if l.value == '443 ssl':
l.value = '80'
port = '80'
else:
l.value = l.value.rstrip(' ssl')
port = l.value
s.remove(*[x for x in s.filter('Key') if x.name.startswith('ssl_')])
c.filter('Comment')[0].comment = 'GENESIS %s http://%s:%s' \
% (stype, data.addr, port)
nginx.dumpf(c, '/etc/nginx/sites-available/'+name)
apis.webapps(self.app).get_interface(stype).ssl_disable(
os.path.join('/srv/http/webapps', name))
示例2: nginx_edit
def nginx_edit(self, oldsite, site):
# Update the nginx serverblock
c = nginx.loadf(os.path.join('/etc/nginx/sites-available', oldsite.name))
s = c.servers[0]
if oldsite.ssl and oldsite.port == '443':
for x in c.servers:
if x.filter('Key', 'listen')[0].value == '443 ssl':
s = x
if site.port != '443':
for x in c.servers:
if not 'ssl' in x.filter('Key', 'listen')[0].value \
and x.filter('key', 'return'):
c.remove(x)
elif site.port == '443':
c.add(nginx.Server(
nginx.Key('listen', '80'),
nginx.Key('server_name', site.addr),
nginx.Key('return', '301 https://%s$request_uri'%site.addr)
))
s.filter('Key', 'listen')[0].value = site.port+' ssl' if site.ssl else site.port
s.filter('Key', 'server_name')[0].value = site.addr
s.filter('Key', 'root')[0].value = site.path
s.filter('Key', 'index')[0].value = 'index.php' if site.php else 'index.html'
nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', oldsite.name))
# If the name was changed, rename the folder and files
if site.name != oldsite.name:
if os.path.exists(os.path.join('/srv/http/webapps', site.name)):
shutil.rmtree(os.path.join('/srv/http/webapps', site.name))
shutil.move(os.path.join('/srv/http/webapps', oldsite.name),
os.path.join('/srv/http/webapps', site.name))
shutil.move(os.path.join('/etc/nginx/sites-available', oldsite.name),
os.path.join('/etc/nginx/sites-available', site.name))
self.nginx_disable(oldsite, reload=False)
self.nginx_enable(site)
self.nginx_reload()
示例3: ssl_disable
def ssl_disable(self, data):
name, stype = data.name, data.stype
port = '80'
s = None
c = nginx.loadf('/etc/nginx/sites-available/'+name)
if len(c.servers) > 1:
for x in c.servers:
if not 'ssl' in x.filter('Key', 'listen')[0].value \
and x.filter('key', 'return'):
c.remove(x)
break
s = c.servers[0]
l = s.filter('Key', 'listen')[0]
if l.value == '443 ssl':
l.value = '80'
port = '80'
else:
l.value = l.value.rstrip(' ssl')
port = l.value
s.remove(*[x for x in s.filter('Key') if x.name.startswith('ssl_')])
g = ConfigParser.SafeConfigParser()
g.read(os.path.join('/etc/nginx/sites-available', '.'+name+'.ginf'))
g.set('website', 'ssl', '')
g.write(open(os.path.join('/etc/nginx/sites-available', '.'+name+'.ginf'), 'w'))
nginx.dumpf(c, '/etc/nginx/sites-available/'+name)
apis.webapps(self.app).get_interface(stype).ssl_disable(
os.path.join('/srv/http/webapps', name))
示例4: ssl_enable
def ssl_enable(self, data, cpath, kpath):
name, stype = data.name, data.stype
port = '443'
c = nginx.loadf('/etc/nginx/sites-available/'+name)
l = c.servers[0].filter('Key', 'listen')[0]
if l.value == '80':
l.value = '443 ssl'
port = '443'
else:
port = l.value.split(' ssl')[0]
l.value = l.value.split(' ssl')[0] + ' ssl'
if c.servers[0].filter('Key', 'ssl_certificate'):
c.servers[0].remove(c.servers[0].filter('Key', 'ssl_certificate'))
if c.servers[0].filter('Key', 'ssl_certificate_key'):
c.servers[0].remove(c.servers[0].filter('Key', 'ssl_certificate_key'))
if c.servers[0].filter('Key', 'ssl_protocols'):
c.servers[0].remove(c.servers[0].filter('Key', 'ssl_protocols'))
if c.servers[0].filter('Key', 'ssl_ciphers'):
c.servers[0].remove(c.servers[0].filter('Key', 'ssl_ciphers'))
c.servers[0].add(
nginx.Key('ssl_certificate', cpath),
nginx.Key('ssl_certificate_key', kpath),
nginx.Key('ssl_protocols', 'SSLv3 TLSv1 TLSv1.1 TLSv1.2'),
nginx.Key('ssl_ciphers', 'HIGH:!aNULL:!MD5')
)
c.filter('Comment')[0].comment = 'GENESIS %s https://%s:%s' \
% (stype, data.addr, port)
nginx.dumpf(c, '/etc/nginx/sites-available/'+name)
apis.webapps(self.app).get_interface(stype).ssl_enable(
os.path.join('/srv/http/webapps', name), cpath, kpath)
self.nginx_reload()
示例5: ssl_disable
def ssl_disable(self):
n = nginx.loadf('/etc/nginx/sites-available/%s' % self.name)
for x in n.servers:
if x.filter('Location', '/'):
x.remove(x.filter('Location', '/')[0])
x.add(self.addtoblock[0])
nginx.dumpf(n, '/etc/nginx/sites-available/%s' % self.name)
示例6: nginx_add
def nginx_add(self, site, add):
if site.path == '':
site.path = os.path.join('/srv/http/webapps/', site.name)
c = nginx.Conf()
s = nginx.Server(
nginx.Key('listen', site.port),
nginx.Key('server_name', site.addr),
nginx.Key('root', site.path),
nginx.Key('index', 'index.'+('php' if site.php else 'html'))
)
if add:
s.add(*[x for x in add])
c.add(s)
nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', site.name))
# Write configuration file with info Genesis needs to know the site
f = open(os.path.join('/etc/nginx/sites-available', '.'+site.name+'.ginf'), 'w')
c = ConfigParser.SafeConfigParser()
c.add_section('website')
c.set('website', 'name', site.name)
c.set('website', 'stype', site.stype)
c.set('website', 'ssl', '')
c.set('website', 'version', site.version if site.version else 'None')
c.set('website', 'dbengine', site.dbengine if site.dbengine else '')
c.set('website', 'dbname', site.dbname if site.dbname else '')
c.set('website', 'dbuser', site.dbuser if site.dbuser else '')
c.write(f)
f.close()
示例7: post_install
def post_install(self, name, path, vars, dbinfo={}):
# Write a basic index file showing that we are here
if vars.getvalue('php', '0') == '1':
php = True
path = os.path.join(path, 'htdocs')
os.mkdir(path)
c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
for x in c.servers:
if x.filter('Key', 'root'):
x.filter('Key', 'root')[0].value = path
nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
else:
php = False
if php:
phpctl = apis.langassist(self.app).get_interface('PHP')
phpctl.enable_mod('xcache')
if php and dbinfo and dbinfo['engine'] == 'MariaDB':
phpctl.enable_mod('mysql')
f = open(os.path.join(path, 'index.'+('php' if php is True else 'html')), 'w')
f.write(
'<html>\n'
'<body>\n'
'<h1>Genesis - Custom Site</h1>\n'
'<p>Your site is online and available at '+path+'</p>\n'
'<p>Feel free to paste your site files here</p>\n'
'</body>\n'
'</html>\n'
)
f.close()
# Give access to httpd
shell('chown -R http:http '+path)
示例8: edit
def edit(self, newname=""):
site_dir = config.get("websites", "site_dir")
block = nginx.loadf(os.path.join("/etc/nginx/sites-available", self.id))
# If SSL is enabled and the port is changing to 443, create the port 80 redirect
server = block.servers[0]
if self.cert and self.port == 443:
for x in block.servers:
if x.filter("Key", "listen")[0].value == "443 ssl":
server = x
if self.port != 443:
for x in block.servers:
if not "ssl" in x.filter("Key", "listen")[0].value \
and x.filter("key", "return"):
block.remove(x)
elif self.port == 443:
block.add(nginx.Server(
nginx.Key("listen", "80"),
nginx.Key("server_name", self.addr),
nginx.Key("return", "301 https://%s$request_uri"%self.addr)
))
# If the name was changed...
if newname and self.id != newname:
# rename the folder and files...
if self.path.endswith("_site"):
self.path = os.path.join(site_dir, newname, "_site")
elif self.path.endswith("htdocs"):
self.path = os.path.join(site_dir, newname, "htdocs")
else:
self.path = os.path.join(site_dir, newname)
self.path = self.path.encode("utf-8")
if os.path.exists(self.path):
shutil.rmtree(self.path)
self.nginx_disable(reload=False)
shutil.move(os.path.join(site_dir, self.id), self.path)
os.unlink(os.path.join("/etc/nginx/sites-available", self.id))
signals.emit("websites", "site_removed", self)
self.id = newname
# then update the site's arkOS metadata file with the new name
meta = ConfigParser.SafeConfigParser()
meta.read(os.path.join(self.path, ".arkos"))
meta.set("website", "id", self.id)
with open(os.path.join(self.path, ".arkos"), "w") as f:
meta.write(f)
self.nginx_enable(reload=False)
# Pass any necessary updates to the nginx serverblock and save
server.filter("Key", "listen")[0].value = str(self.port)+" ssl" if self.cert else str(self.port)
server.filter("Key", "server_name")[0].value = self.addr
server.filter("Key", "root")[0].value = self.path
server.filter("Key", "index")[0].value = "index.php" if hasattr(self, "php") and self.php else "index.html"
nginx.dumpf(block, os.path.join("/etc/nginx/sites-available", self.id))
# Call the site's edited hook, if it has one, then reload nginx
signals.emit("websites", "site_loaded", self)
if hasattr(self, "site_edited"):
self.site_edited()
nginx_reload()
示例9: ssl_disable
def ssl_disable(self):
block = nginx.loadf(os.path.join("/etc/nginx/sites-available/", self.id))
# If there's an 80-to-443 redirect block, get rid of it
if len(block.servers) > 1:
for x in block.servers:
if not "ssl" in x.filter("Key", "listen")[0].value \
and x.filter("key", "return"):
block.remove(x)
break
# Remove all SSL directives and save
server = block.servers[0]
listen = server.filter("Key", "listen")[0]
if listen.value == "443 ssl":
listen.value = "80"
else:
listen.value = listen.value.rstrip(" ssl")
server.remove(*[x for x in server.filter("Key") if x.name.startswith("ssl_")])
nginx.dumpf(block, os.path.join("/etc/nginx/sites-available/", self.id))
meta = ConfigParser.SafeConfigParser()
meta.read(os.path.join(self.path, ".arkos"))
meta.set("website", "ssl", "None")
with open(os.path.join(self.path, ".arkos"), "w") as f:
meta.write(f)
# Call the website type's SSL disable hook
self.disable_ssl()
示例10: install
def install(self, extra_vars={}, enable=True, message=None):
# Set metadata values
site_dir = config.get("websites", "site_dir")
self.path = self.path.encode("utf-8") or os.path.join(site_dir, self.id).encode("utf-8")
try:
os.makedirs(self.path)
except:
pass
# If extra data is passed in, set up the serverblock accordingly
if extra_vars:
if not extra_vars.get("type") or not extra_vars.get("pass"):
raise Exception("Must enter ReverseProxy type and location to pass to")
elif extra_vars.get("type") in ["fastcgi", "uwsgi"]:
self.block = [nginx.Location(extra_vars.get("lregex", "/"),
nginx.Key("%s_pass"%extra_vars.get("type"),
"%s"%extra_vars.get("pass")),
nginx.Key("include", "%s_params"%extra_vars.get("type"))
)]
else:
self.block = [nginx.Location(extra_vars.get("lregex", "/"),
nginx.Key("proxy_pass", "%s"%extra_vars.get("pass")),
nginx.Key("proxy_redirect", "off"),
nginx.Key("proxy_buffering", "off"),
nginx.Key("proxy_set_header", "Host $host")
)]
if extra_vars.get("xrip"):
self.block[0].add(nginx.Key("proxy_set_header", "X-Real-IP $remote_addr"))
if extra_vars.get("xff") == "1":
self.block[0].add(nginx.Key("proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for"))
# Create the nginx serverblock and arkOS metadata files
block = nginx.Conf()
server = nginx.Server(
nginx.Key("listen", self.port),
nginx.Key("server_name", self.addr),
nginx.Key("root", self.base_path or self.path),
)
server.add(*[x for x in self.block])
block.add(server)
nginx.dumpf(block, os.path.join("/etc/nginx/sites-available", self.id))
meta = ConfigParser.SafeConfigParser()
meta.add_section("website")
meta.set("website", "id", self.id)
meta.set("website", "name", self.name)
meta.set("website", "type", "ReverseProxy")
meta.set("website", "extra", self.type)
meta.set("website", "version", "None")
meta.set("website", "ssl", self.cert.id if hasattr(self, "cert") and self.cert else "None")
with open(os.path.join(self.path, ".arkos"), "w") as f:
meta.write(f)
# Track port and reload daemon
self.meta = None
self.installed = True
storage.sites.add("sites", self)
signals.emit("websites", "site_installed", self)
self.nginx_enable()
示例11: post_install
def post_install(self, name, path, vars):
# Make sure the webapps config points to the _site directory and generate it.
c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
c.servers[0].filter('Key', 'root')[0].value = os.path.join(path, '_site')
nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
shell('jekyll build --source '+path+' --destination '+os.path.join(path, '_site'))
# Return an explicatory message.
return 'Jekyll has been setup, with a sample site at '+path+'. Modify these files as you like. To learn how to use Jekyll, visit http://jekyllrb.com/docs/usage. After making changes, click the Configure button next to the site, then "Regenerate Site" to bring your changes live.'
示例12: ssl_disable
def ssl_disable(self, path):
name = os.path.basename(path)
n = nginx.loadf('/etc/nginx/sites-available/%s'%name)
for x in n.servers:
if x.filter('Location', '/'):
x.remove(x.filter('Location', '/')[0])
x.add(self.addtoblock[0])
nginx.dumpf(n, '/etc/nginx/sites-available/%s'%name)
s = self.app.get_backend(apis.services.IServiceManager)
示例13: enable_ssl
def enable_ssl(self, cfile, kfile):
n = nginx.loadf('/etc/nginx/sites-available/%s'%self.id)
for x in n.servers:
if x.filter('Location', '/'):
x.remove(x.filter('Location', '/')[0])
self.addtoblock[0].add(
nginx.Key('proxy_set_header', 'X-Forwarded-For $proxy_add_x_forwarded_for'),
nginx.Key('proxy_set_header', 'X-Forwarded-Proto $scheme'),
)
x.add(self.addtoblock[0])
nginx.dumpf(n, '/etc/nginx/sites-available/%s'%self.id)
示例14: ssl_enable
def ssl_enable(self):
# Get server-preferred ciphers
if config.get("certificates", "ciphers"):
ciphers = config.get("certificates", "ciphers")
else:
config.set("certificates", "ciphers", ciphers)
config.save()
block = nginx.loadf(os.path.join("/etc/nginx/sites-available/", self.id))
# If the site is on port 80, setup an HTTP redirect to new port 443
server = block.servers[0]
listen = server.filter("Key", "listen")[0]
if listen.value == "80":
listen.value = "443 ssl"
block.add(nginx.Server(
nginx.Key("listen", "80"),
nginx.Key("server_name", self.addr),
nginx.Key("return", "301 https://%s$request_uri" % self.addr)
))
for x in block.servers:
if x.filter("Key", "listen")[0].value == "443 ssl":
server = x
break
else:
listen.value = listen.value.split(" ssl")[0] + " ssl"
# Clean up any pre-existing SSL directives that no longer apply
for x in server.all():
if type(x) == nginx.Key and x.name.startswith("ssl_"):
server.remove(x)
# Add the necessary SSL directives to the serverblock and save
server.add(
nginx.Key("ssl_certificate", self.cert.cert_path),
nginx.Key("ssl_certificate_key", self.cert.key_path),
nginx.Key("ssl_protocols", "TLSv1 TLSv1.1 TLSv1.2"),
nginx.Key("ssl_ciphers", ciphers),
nginx.Key("ssl_session_timeout", "5m"),
nginx.Key("ssl_prefer_server_ciphers", "on"),
nginx.Key("ssl_dhparam", "/etc/arkos/ssl/dh_params.pem"),
nginx.Key("ssl_session_cache", "shared:SSL:50m"),
)
nginx.dumpf(block, os.path.join("/etc/nginx/sites-available/", self.id))
# Set the certificate name in the metadata file
meta = ConfigParser.SafeConfigParser()
meta.read(os.path.join(self.path, ".arkos"))
meta.set("website", "ssl", self.cert.id)
with open(os.path.join(self.path, ".arkos"), "w") as f:
meta.write(f)
# Call the website type's SSL enable hook
self.enable_ssl(self.cert.cert_path, self.cert.key_path)
示例15: post_install
def post_install(self, name, path, vars):
# Write a basic index file showing that we are here
if vars.getvalue('php', '0') == '1':
php = True
path = os.path.join(path, 'htdocs')
os.mkdir(path)
c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
for x in c.servers:
if x.filter('Key', 'root'):
x.filter('Key', 'root')[0].value = path
nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
else:
php = False
# Create a database if the user wants one
if php:
phpctl = apis.langassist(self.app).get_interface('PHP')
if vars.getvalue('ws-dbsel', 'None') != 'None':
dbtype = vars.getvalue('ws-dbsel', '')
dbname = vars.getvalue('ws-dbname', '')
passwd = vars.getvalue('ws-dbpass', '')
dbase = apis.databases(self.app).get_interface(dbtype)
if hasattr(dbase, 'connect'):
conn = apis.databases(self.app).get_dbconn(dbtype)
dbase.add(dbname, conn)
dbase.usermod(dbname, 'add', passwd, conn)
dbase.chperm(dbname, dbname, 'grant', conn)
else:
dbase.add(dbname)
dbase.usermod(dbname, 'add', passwd)
dbase.chperm(dbname, dbname, 'grant')
if php:
phpctl.enable_mod('mysql')
f = open(os.path.join(path, 'index.'+('php' if php is True else 'html')), 'w')
f.write(
'<html>\n'
'<body>\n'
'<h1>Genesis - Custom Site</h1>\n'
'<p>Your site is online and available at '+path+'</p>\n'
'<p>Feel free to paste your site files here</p>\n'
'</body>\n'
'</html>\n'
)
f.close()
# Give access to httpd
shell('chown -R http:http '+path)
# Enable xcache if PHP is set
if php:
phpctl.enable_mod('xcache')