Beispiel #1
0
	def email_user(self, key=None, password=None, origin=None):
		"""Email the user a key (to reset her password) OR a password (if the
		user followed a link with the key in it). The origin shows where the request
		came from (string)"""
		from submin.template.shortcuts import evaluate
		from submin.email import sendmail
		
		if key and password:
			raise ValueError('Ambiguous input: both key and password are set')

		templatevars = {
			'from': options.value('smtp_from', 'root@localhost'),
			'to': self.email,
			'username': self.name,
			'key': key,
			'password': password,
			'http_vhost': options.http_vhost(),
			'base_url': options.url_path("base_url_submin"),
			'origin': origin,
		}
		if key:
			template = 'email/prepare_reset.txt'
		else:
			template = 'email/reset_password.txt'
		
		message = evaluate(template, templatevars)
		sendmail(templatevars['from'], templatevars['to'], message)
Beispiel #2
0
    def email_user(self, key=None, password=None, origin=None):
        """Email the user a key (to reset her password) OR a password (if the
		user followed a link with the key in it). The origin shows where the request
		came from (string)"""
        from submin.template.shortcuts import evaluate
        from submin.email import sendmail

        if key and password:
            raise ValueError('Ambiguous input: both key and password are set')

        templatevars = {
            'from': options.value('smtp_from', 'root@localhost'),
            'to': self.email,
            'username': self.name,
            'key': key,
            'password': password,
            'http_vhost': options.http_vhost(),
            'base_url': options.url_path("base_url_submin"),
            'origin': origin,
        }
        if key:
            template = 'email/prepare_reset.txt'
        else:
            template = 'email/reset_password.txt'

        message = evaluate(template, templatevars)
        sendmail(templatevars['from'], templatevars['to'], message)
Beispiel #3
0
def setCommitEmailHook(reponame, enable):
    prepare(reponame)

    reposdir = repository.directory('git', reponame)
    hook_dir = reposdir + 'hooks' + 'post-receive.d'
    mkdirs(hook_dir)
    hook_dest = hook_dir + '001-commit-email.hook'

    if enable:
        variables = {
            'submin_lib_dir': options.lib_path(),
            'base_url': options.url_path('base_url_submin'),
            'http_vhost': options.http_vhost(),
            'hook_version': HOOK_VERSIONS['commit-email'],
        }
        hook = evaluate('plugins/vcs/git/post-receive', variables)
        try:
            os.unlink(hook_dest)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise

        try:
            with file(hook_dest, 'w') as f:
                f.write(hook)

            os.chmod(hook_dest, 0o755)
        except OSError as e:
            raise repository.PermissionError("Enabling hook failed: %s" %
                                             (str(e), ))
        try:
            cfg = repository.directory('git', reponame) + 'config'
            email = options.value(
                'commit_email_from',
                'Please configure commit_email_from <*****@*****.**>')

            set_git_config(cfg, 'multimailhook.emailmaxlines', '2000')
            prefix = '[%s]' % reponame
            set_git_config(cfg, 'multimailhook.emailprefix', prefix)
            set_git_config(cfg, 'multimailhook.envelopesender', email)
        except SetGitConfigError as e:
            raise repository.PermissionError(
                "Enabling hook succeeded, but configuring it failed: %s" %
                (str(e)))
    else:
        try:
            os.unlink(hook_dest)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise repository.PermissionError("Removing hook failed: %s" %
                                                 (str(e), ))
Beispiel #4
0
def setCommitEmailHook(reponame, enable):
	prepare(reponame)

	reposdir = repository.directory('git', reponame)
	hook_dir = reposdir + 'hooks' + 'post-receive.d'
	mkdirs(hook_dir)
	hook_dest = hook_dir + '001-commit-email.hook'

	if enable:
		variables = {
			'submin_lib_dir': options.lib_path(),
			'base_url': options.url_path('base_url_submin'),
			'http_vhost': options.http_vhost(),
			'hook_version': HOOK_VERSIONS['commit-email'],
		}
		hook = evaluate('plugins/vcs/git/post-receive', variables)
		try:
			os.unlink(hook_dest)
		except OSError as e:
			if e.errno != errno.ENOENT:
				raise

		try:
			with file(hook_dest, 'w') as f:
				f.write(hook)

			os.chmod(hook_dest, 0o755)
		except OSError as e:
			raise repository.PermissionError(
				"Enabling hook failed: %s" % (str(e),))
		try:
			cfg = repository.directory('git', reponame) + 'config'
			email = options.value('commit_email_from',
				'Please configure commit_email_from <*****@*****.**>')

			set_git_config(cfg, 'multimailhook.emailmaxlines', '2000')
			prefix = '[%s]' % reponame
			set_git_config(cfg, 'multimailhook.emailprefix', prefix)
			set_git_config(cfg, 'multimailhook.envelopesender', email)
		except SetGitConfigError as e:
			raise repository.PermissionError(
				"Enabling hook succeeded, but configuring it failed: %s" %
				(str(e)))
	else:
		try:
			os.unlink(hook_dest)
		except OSError as e:
			if e.errno != errno.ENOENT:
				raise repository.PermissionError(
					"Removing hook failed: %s" % (str(e),))
Beispiel #5
0
    def subcmd_hook(self, argv):
        """This is hidden from help because it is not meant to be run, except
		from commit/receive hooks
		"""
        from submin.path.path import Path
        from submin.models import hookjobs
        from submin.models import options
        from submin.subminadmin import trac
        #import urllib2
        from urllib import request, error

        if argv[0] != 'queue' or len(argv) != 4:
            print('Unknown command')
            return

        vcs_type, repository, hooktype = argv[1:]
        content = ''.join(sys.stdin.readlines())
        print('Notifying Trac of changes...')
        if hooktype == 'trac-sync' and 'refs/tags' in content:
            print('Skipping tag (no sync needed)')
            return

        hookjobs.queue(vcs_type, repository, hooktype, content)

        baseurl = Path(options.http_vhost() +
                       options.url_path('base_url_submin'))
        joburl = str(baseurl + 'hooks' + hooktype + vcs_type + repository)

        try:
            response = urllib2.urlopen(joburl)
        except urllib2.HTTPError as e:
            print('Job queued, but could not sync to "%s", HTTP error %u' % (
                joburl,
                e.code,
            ))
        except urllib2.URLError as e:
            print('Job queued, but URL invalid %s: %s' % (joburl, str(e)))
        else:
            xml = response.read()
            if 'success="True"' not in xml:
                print('Failed to sync:\n%s' % xml)
            # TODO: don't process XML with regexps...
            messages = re.sub('.*<errormsgs>(.*)</errormsgs>.*',
                              '\\1',
                              xml,
                              flags=re.DOTALL)
            messages = re.sub('<msg>(.*)</msg>', '\\1\n', messages)
            if "" != messages:
                print('WARNING: Synced, but got some messages:\n%s' % messages)
Beispiel #6
0
	def subcmd_hook(self, argv):
		"""This is hidden from help because it is not meant to be run, except
		from commit/receive hooks
		"""
		from submin.path.path import Path
		from submin.models import hookjobs
		from submin.models import options
		from submin.subminadmin import trac
		import urllib2

		if argv[0] != 'queue' or len(argv) != 4:
			print 'Unknown command'
			return

		vcs_type, repository, hooktype = argv[1:]
		content = ''.join(sys.stdin.readlines())
		print 'Notifying Trac of changes...'
		if hooktype == 'trac-sync' and 'refs/tags' in content:
			print('Skipping tag (no sync needed)')
			return

		hookjobs.queue(vcs_type, repository, hooktype, content)

		baseurl = Path(options.http_vhost()
					+ options.url_path('base_url_submin'))
		joburl = str(baseurl + 'hooks' + hooktype + vcs_type + repository)

		try:
			response = urllib2.urlopen(joburl)
		except urllib2.HTTPError as e:
			print('Job queued, but could not sync to "%s", HTTP error %u' %
				(joburl, e.code, ))
		except urllib2.URLError as e:
			print('Job queued, but URL invalid %s: %s' %
				(joburl, str(e)))
		else:
			xml = response.read()
			if 'success="True"' not in xml:
				print('Failed to sync:\n%s' % xml)
			# TODO: don't process XML with regexps...
			messages = re.sub('.*<errormsgs>(.*)</errormsgs>.*', '\\1', xml, flags=re.DOTALL)
			messages = re.sub('<msg>(.*)</msg>', '\\1\n', messages)
			if "" != messages:
				print('WARNING: Synced, but got some messages:\n%s' % messages)
Beispiel #7
0
def have_trac_sync_access():
	baseurl = Path(options.http_vhost() + options.url_path('base_url_submin'))
	# because we don't specify a full path, this will never succeed, but
	# it will set the 'inacl' attribute to True/False
	joburl = str(baseurl + 'hooks' + 'trac-sync')

	try:
		response = urllib2.urlopen(joburl, timeout=2)
	except urllib2.HTTPError as e:
		raise SyncError('HTTP error: %s' % str(e))
	except urllib2.URLError as e:
		raise SyncError('URL invalid %u: %s' % (e.reason[0], e.reason[1]))
	except socket.timeout as e:
		raise SyncError('Timeout: are we running a single-threaded server?')

	root = ET.fromstring(response.read())
	command = root.find('./command')
	if command is None:
		raise SyncError(root)

	if 'inacl' not in command.attrib or command.attrib['inacl'].lower() == 'false':
		msgnodes = root.findall('./command/errormsgs/msg')
		raise SyncError('\n'.join([x.text for x in msgnodes]))
Beispiel #8
0
def have_trac_sync_access():
    baseurl = Path(options.http_vhost() + options.url_path('base_url_submin'))
    # because we don't specify a full path, this will never succeed, but
    # it will set the 'inacl' attribute to True/False
    joburl = str(baseurl + 'hooks' + 'trac-sync')

    try:
        response = urllib2.urlopen(joburl, timeout=2)
    except urllib2.HTTPError as e:
        raise SyncError('HTTP error: %s' % str(e))
    except urllib2.URLError as e:
        raise SyncError('URL invalid %u: %s' % (e.reason[0], e.reason[1]))
    except socket.timeout as e:
        raise SyncError('Timeout: are we running a single-threaded server?')

    root = ET.fromstring(response.read())
    command = root.find('./command')
    if command is None:
        raise SyncError(root)

    if 'inacl' not in command.attrib or command.attrib['inacl'].lower(
    ) == 'false':
        msgnodes = root.findall('./command/errormsgs/msg')
        raise SyncError('\n'.join([x.text for x in msgnodes]))
Beispiel #9
0
	def _set_footer():
		git_multimail.FOOTER_TEMPLATE = FOOTER_TEMPLATE.format(
			http_vhost=options.http_vhost(),
			base_url=options.url_path("base_url_submin"),
		)
		git_multimail.REVISION_FOOTER_TEMPLATE = git_multimail.FOOTER_TEMPLATE