def email( fromaddr, toaddr, subject, msg, smtp_pass = None ): if smtp_pass == None and config.has_option('mailer', 'password'): smtp_pass = config.get('mailer', 'password') if smtp_pass == None: smtp_pass = get_pass() msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (fromaddr, toaddr, subject, msg) server = smtplib.SMTP(config.get('mailer', 'smtpserver'), timeout = 5) server.ehlo() server.starttls() server.ehlo() server.login(config.get('mailer', 'username'), smtp_pass) print("Emailing...", end=' ') r = server.sendmail(fromaddr, toaddr, msg) if len(r): print(" FAILED.") else: print(" OK.") try: server.quit() except smtplib.sslerror: pass
def main(): print 'pwserverd starting' # Parse the arguments parser = OptionParser() parser.add_option("-c", "--config", dest="config_file", default="/etc/pwserverd.cfg", help="use the specified configuration file") (options, args) = parser.parse_args() # Read the configuration file config.read([options.config_file]) # Set things up factory = PasswordProtocolFactory() listeners = [l.strip() for l in config.get('main', 'listeners').split(',')] for listener in listeners: ltype = config.get(listener, 'type').strip().upper() if ltype == 'TCP': port = config.getint(listener, 'port') interface = '127.0.0.1' if config.has_option(listener, 'interface'): interface = config.get(listener, 'interface') print 'listening on interface %s port %s' % (interface, port) reactor.listenTCP(port, factory, interface=interface) elif ltype == 'UNIX': mode = 0644 if config.has_option(listener, 'mode'): mode = int(config.get(listener, 'mode'), 0) socket = config.get(listener, 'socket') wantpid = True if config.has_option(listener, 'wantPID'): wantpid = config.getboolean(listener, 'wantPID') print 'listening on socket %s' % socket reactor.listenUNIX(socket, factory, mode=mode, wantPID=wantpid) else: print 'unknown listener type %s for listener %s' % (ltype, listener) reactor.run()
def completion_set(self, the_input): """Completion for /set""" args = common.shell_split(the_input.text) n = the_input.get_argument_position(quoted=True) if n >= len(args): args.append('') if n == 1: if '|' in args[1]: plugin_name, section = args[1].split('|')[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = [ '%s|%s' % (plugin_name, section) for section in plugin.config.sections() ] else: end_list = set(config.options('Poezio')) end_list.update(config.default.get('Poezio', {})) end_list = list(end_list) end_list.sort() elif n == 2: if '|' in args[1]: plugin_name, section = args[1].split('|')[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([''], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = set(plugin.config.options(section or plugin_name)) if plugin.config.default: end_list.update( plugin.config.default.get(section or plugin_name, {})) end_list = list(end_list) end_list.sort() elif not config.has_option('Poezio', args[1]): if config.has_section(args[1]): end_list = config.options(args[1]) end_list.append('') else: end_list = [] else: end_list = [str(config.get(args[1], '')), ''] elif n == 3: if '|' in args[1]: plugin_name, section = args[1].split('|')[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([''], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = [ str(plugin.config.get(args[2], '', section or plugin_name)), '' ] else: if not config.has_section(args[1]): end_list = [''] else: end_list = [str(config.get(args[2], '', args[1])), ''] else: return return the_input.new_completion(end_list, n, quotify=True)
def setExternalPhoneAddress(): if config.has_option(consts.SECTION, consts.EXTPHONEADDR): extphoneadr = config.get(consts.SECTION, consts.EXTPHONEADDR) if len(extphoneadr.strip()): return try: extphoneadr = get_ip_address("eth0") except: raise ZsiposCfgException("ip address eth0 not found") config.set(consts.SECTION, consts.EXTPHONEADDR, extphoneadr)
def static_url_for(filename): from flask import url_for, request from config import config import urllib url_base = request.environ.get('wsgiorg.routing_args', ([], {}))[1].get('static_url_base') if not url_base and config.has_option('general', 'static_url_base'): url_base = config.get('general', 'static_url_base') if url_base: return url_base.rstrip('/') + '/' + urllib.quote(filename) else: return url_for('static', filename=filename)
def setExternalGateway(): if config.has_option(consts.SECTION, consts.EXTGATEWAY): return try: gateway = get_default_gateway_linux() except: raise ZsiposCfgException("dhcp gateway not found") if not gateway: raise ZsiposCfgException("external gateway not found") log.info("gateway " + gateway) config.set(consts.SECTION, consts.EXTGATEWAY, gateway)
def completion_set(self, the_input): """Completion for /set""" args = common.shell_split(the_input.text) n = the_input.get_argument_position(quoted=True) if n >= len(args): args.append("") if n == 1: if "|" in args[1]: plugin_name, section = args[1].split("|")[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = ["%s|%s" % (plugin_name, section) for section in plugin.config.sections()] else: end_list = set(config.options("Poezio")) end_list.update(config.default.get("Poezio", {})) end_list = list(end_list) end_list.sort() elif n == 2: if "|" in args[1]: plugin_name, section = args[1].split("|")[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([""], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = set(plugin.config.options(section or plugin_name)) if plugin.config.default: end_list.update(plugin.config.default.get(section or plugin_name, {})) end_list = list(end_list) end_list.sort() elif not config.has_option("Poezio", args[1]): if config.has_section(args[1]): end_list = config.options(args[1]) end_list.append("") else: end_list = [] else: end_list = [str(config.get(args[1], "")), ""] elif n == 3: if "|" in args[1]: plugin_name, section = args[1].split("|")[:2] if not plugin_name in self.plugin_manager.plugins: return the_input.new_completion([""], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = [str(plugin.config.get(args[2], "", section or plugin_name)), ""] else: if not config.has_section(args[1]): end_list = [""] else: end_list = [str(config.get(args[2], "", args[1])), ""] else: return return the_input.new_completion(end_list, n, quotify=True)
def __init__(self): if config.has_option(consts.SECTION, consts.EXTPHONEADDR): self.extphoneaddr = config.get(consts.SECTION, consts.EXTPHONEADDR).strip() if config.has_option(consts.SECTION, consts.LOCPROXYADDR): self.locproxyaddr = config.get(consts.SECTION, consts.LOCPROXYADDR).strip() self.extProxyURL = parseURL("sip:" + config.get(consts.SECTION, consts.EXTPROXYADDR) + ":" + config.get(consts.SECTION, consts.EXTPROXYPORT)) log.info("original proxy address: %s", self.extProxyURL.toString()) self.phoneInfoValid = False self.locPhoneURL = parseAddress(UNKNOWNADDR)[1] self.extProto = SipProtocol(self.extMessageReceived) self.locProto = SipProtocol(self.locMessageReceived) self.myAddr = parseAddress(UNKNOWNADDR) self.locContact = UNKNOWNADDR self.extContact = UNKNOWNADDR self.callmap = { } self.branchmap = { } self.seq2branch = [ { }, { } ] self.dolog = [ config.getboolean(consts.SECTION, consts.LOGLOC), config.getboolean(consts.SECTION, consts.LOGEXT) ] self.logfull = config.getboolean(consts.SECTION, consts.LOGFULLMESSAGE) self.eventsink = None if self.extphoneaddr and len(self.extphoneaddr): self.extStartListening(self.extphoneaddr) if self.locproxyaddr and len(self.locproxyaddr): self.locStartListening(self.locproxyaddr)
import subprocess import shlex def current_time(): ## get microsecond return time.time() * 1000 if __name__ == "__main__": logger.info("Dns Benchmark server starts") ## fetch ip list ip_list = [] if config.has_option("basic", "ip_list_filename"): ip_list_filename = config.get("basic", "ip_list_filename") with open(ip_list_filename, 'r') as ip_list_file: ips = ip_list_file.readlines() for ip in ips: ip_list.append(ip) else: ip_list = ['127.0.0.1'] ## fetch configs ip = config.get("server", "ip") if config.has_option("server", "ip") else "127.0.0.1" port = config.getint("server", "port") if config.has_option("server", "port") else 50000 authkey = config.get("server", "authkey") if config.has_option("server", "authkey") else "secret" address = (ip, port)
from twisted.python import log from twisted.web.client import getPage from twisted.web.error import Error import urllib, urlparse from zope.interface import implements auth_protocol = config.get('drupalSSHGitServer', 'authServiceProtocol') if auth_protocol == "drush": # Load drush settings from drupaldaemons.cnf drush_webroot = config.get('drush-settings', 'webroot') drush_path = config.get('drush-settings', 'drushPath') elif auth_protocol == "http": # Load http settings http_service_url = config.get('http-settings', 'serviceUrl') http_headers = {} if config.has_option('http-settings', 'hostHeader'): http_host_header = config.get('http-settings', 'hostHeader') http_headers["Host"] = http_host_header if config.has_option('http-settings', 'httpAuth'): http_auth = b64encode(config.get('http-settings', 'httpAuth')) http_headers["Authorization"] = "Basic " + http_auth else: raise Exception("No valid authServiceProtocol specified.") class DrushError(ConchError): pass class HTTPError(ConchError): pass class DrushProcessProtocol(ProcessProtocol):
from twisted.python import log from twisted.web.client import getPage from twisted.web.error import Error import urllib, urlparse from zope.interface import implements auth_protocol = config.get('drupalSSHGitServer', 'authServiceProtocol') if auth_protocol == "drush": # Load drush settings from drupaldaemons.cnf drush_webroot = config.get('drush-settings', 'webroot') drush_path = config.get('drush-settings', 'drushPath') elif auth_protocol == "http": # Load http settings http_service_url = config.get('http-settings', 'serviceUrl') http_headers = {} if config.has_option('http-settings', 'hostHeader'): http_host_header = config.get('http-settings', 'hostHeader') http_headers["Host"] = http_host_header if config.has_option('http-settings', 'httpAuth'): http_auth = b64encode(config.get('http-settings', 'httpAuth')) http_headers["Authorization"] = "Basic " + http_auth else: raise Exception("No valid authServiceProtocol specified.") class DrushError(ConchError): pass class HTTPError(ConchError): pass