Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
package_entry = Package.query.filter_by(name=packagename).first()
if package_entry is not None:
if package_entry.type == 'zip' and package_entry.upload is not None:
SavedFile(package_entry.upload).delete()
package_entry.version += 1
package_entry.giturl = giturl
package_entry.upload = None
package_entry.limitation = None
package_entry.type = 'git'
db.session.commit()
ok, logmessages = docassemble.webapp.update.check_for_updates()
if ok:
trigger_update(except_for=hostname)
restart_wsgi()
flash(word("Install successful"), 'success')
else:
flash(word("Install not successful"), 'error')
flash('pip log: ' + str(logmessages), 'info')
# pip_log = tempfile.NamedTemporaryFile()
# commands = ['install', '--quiet', '--egg', '--src=' + tempfile.mkdtemp(), '--upgrade', '--log-file=' + pip_log.name, 'git+' + giturl + '.git#egg=' + packagename]
# returnval = pip.main(commands)
# if returnval > 0:
# with open(pip_log.name) as x: logfilecontents = x.read()
# flash("pip " + " ".join(commands) + "<pre>" + str(logfilecontents) + "</pre>", 'error')
return
<ul class="nav navbar-nav navbar-right">
"""
if show_login:
if current_user.is_anonymous:
#logmessage("is_anonymous is " + str(current_user.is_anonymous))
navbar += ' <li><a href="' + url_for('user.login', next=url_for('index')) + '">' + word('Sign in') + '</a></li>' + "\n"
else:
navbar += ' <li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#">' + current_user.email + '<b class="caret"></b></a><ul class="dropdown-menu">'
if current_user.has_role('admin', 'developer'):
navbar +='<li><a href="' + url_for('package_page') + '">' + word('Package Management') + '</a></li>'
navbar +='<li><a href="' + url_for('logs') + '">' + word('Logs') + '</a></li>'
navbar +='<li><a href="' + url_for('playground_page') + '">' + word('Playground') + '</a></li>'
if current_user.has_role('admin'):
navbar +='<li><a href="' + url_for('user_list') + '">' + word('User List') + '</a></li>'
navbar +='<li><a href="' + url_for('privilege_list') + '">' + word('Privileges List') + '</a></li>'
navbar +='<li><a href="' + url_for('config_page') + '">' + word('Configuration') + '</a></li>'
navbar += '<li><a href="' + url_for('user_profile_page') + '">' + word('Profile') + '</a></li><li><a href="' + url_for('user.logout') + '">' + word('Sign out') + '</a></li></ul></li>'
else:
navbar += ' <li><a href="' + url_for('exit') + '">' + word('Exit') + '</a></li>'
navbar += """\
</ul>
"""
return(navbar)
@app.route('/config', methods=['GET', 'POST'])
@login_required
@roles_required(['admin'])
def config_page():
form = ConfigForm(request.form, current_user)
if request.method == 'POST':
if form.submit.data and form.config_content.data:
if S3_ENABLED:
key = s3.get_key('config.yml')
key.set_contents_from_string(form.config_content.data)
with open(daconfig['config_file'], 'w') as fp:
fp.write(form.config_content.data)
flash(word('The configuration file was saved.'), 'success')
restart_wsgi()
elif form.cancel.data:
flash(word('Configuration not updated.'), 'info')
else:
flash(word('Configuration not updated. There was an error.'), 'error')
return redirect(url_for('index'))
with open(daconfig['config_file'], 'r') as fp:
content = fp.read()
return render_template('pages/config.html', extra_css=Markup('\n '), extra_js=Markup('\n \n \n '), form=form), 200
abort(404)
def process_attachment(self, target):
metadata = dict()
variable_name = str()
defs = list()
options = dict()
if type(target) is dict:
if 'language' in target:
options['language'] = target['language']
if 'filename' not in target:
target['filename'] = word("Document")
if 'name' not in target:
target['name'] = word("Document")
if 'description' not in target:
target['description'] = ''
if 'initial yaml' in target:
if type(target['initial yaml']) is not list:
target['initial yaml'] = [target['initial yaml']]
options['initial_yaml'] = list()
for yaml_file in target['initial yaml']:
if type(yaml_file) is not str:
raise DAError('An initial yaml file must be a string.' + self.idebug(target))
options['initial_yaml'].append(docassemble.base.util.package_template_filename(yaml_file, package=self.package))
if 'additional yaml' in target:
if type(target['additional yaml']) is not list:
target['additional yaml'] = [target['additional yaml']]
options['additional_yaml'] = list()
navbar += """\
<ul class="nav navbar-nav navbar-right">
"""
if show_login:
if current_user.is_anonymous:
#logmessage("is_anonymous is " + str(current_user.is_anonymous))
navbar += ' <li><a href="' + url_for('user.login', next=url_for('index')) + '">' + word('Sign in') + '</a></li>' + "\n"
else:
navbar += ' <li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#">' + current_user.email + '<b class="caret"></b></a><ul class="dropdown-menu">'
if current_user.has_role('admin', 'developer'):
navbar +='<li><a href="' + url_for('package_page') + '">' + word('Package Management') + '</a></li>'
navbar +='<li><a href="' + url_for('logs') + '">' + word('Logs') + '</a></li>'
navbar +='<li><a href="' + url_for('playground_page') + '">' + word('Playground') + '</a></li>'
if current_user.has_role('admin'):
navbar +='<li><a href="' + url_for('user_list') + '">' + word('User List') + '</a></li>'
navbar +='<li><a href="' + url_for('privilege_list') + '">' + word('Privileges List') + '</a></li>'
navbar +='<li><a href="' + url_for('config_page') + '">' + word('Configuration') + '</a></li>'
navbar += '<li><a href="' + url_for('user_profile_page') + '">' + word('Profile') + '</a></li><li><a href="' + url_for('user.logout') + '">' + word('Sign out') + '</a></li></ul></li>'
else:
navbar += ' <li><a href="' + url_for('exit') + '">' + word('Exit') + '</a></li>'
navbar += """\
</ul>
"""
return(navbar)
if (form.submit.data or form.run.data) and form.playground_content.data:
if form.original_playground_name.data and form.original_playground_name.data != the_file:
old_filename = os.path.join(playground.directory, form.original_playground_name.data)
if os.path.isfile(old_filename):
os.remove(old_filename)
files = sorted([f for f in os.listdir(playground.directory) if os.path.isfile(os.path.join(playground.directory, f))])
the_time = time.strftime('%H:%M:%S %Z', time.localtime())
with open(filename, 'w') as fp:
fp.write(form.playground_content.data)
if form.submit.data:
flash(word('The playground was saved at') + ' ' + the_time + '.', 'success')
else:
flash(word('The playground was saved at') + ' ' + the_time + '. ' + word('Running in other tab.'), 'info')
javascript = "\n window.open(" + repr(url_for('index', i='/playground/' + the_file)) + ", '_blank' );"
else:
flash(word('Playground not saved. There was an error.'), 'error')
content = ''
if the_file:
playground.finalize()
with open(filename, 'r') as fp:
form.original_playground_name.data = the_file
form.playground_name.data = the_file
content = fp.read()
#if not form.playground_content.data:
#form.playground_content.data = content
elif form.playground_content.data:
content = form.playground_content.data
return render_template('pages/playground.html', extra_css=Markup('\n '), extra_js=Markup('\n \n \n \n '), form=form, files=files, current_file=the_file, content=content), 200
@app.route('/config', methods=['GET', 'POST'])
@login_required
@roles_required(['admin'])
def config_page():
form = ConfigForm(request.form, current_user)
if request.method == 'POST':
if form.submit.data and form.config_content.data:
if S3_ENABLED:
key = s3.get_key('config.yml')
key.set_contents_from_string(form.config_content.data)
with open(daconfig['config_file'], 'w') as fp:
fp.write(form.config_content.data)
flash(word('The configuration file was saved.'), 'success')
restart_wsgi()
elif form.cancel.data:
flash(word('Configuration not updated.'), 'info')
else:
flash(word('Configuration not updated. There was an error.'), 'error')
return redirect(url_for('index'))
with open(daconfig['config_file'], 'r') as fp:
content = fp.read()
return render_template('pages/config.html', extra_css=Markup('\n '), extra_js=Markup('\n \n \n '), form=form), 200
abort(404)
recipients = list()
if request.method == 'POST':
for user in User.query.filter_by(active=True).all():
for role in user.roles:
if role.name == 'admin':
recipients.append(user.email)
url = request.base_url
url = re.sub(r'^(https?://[^/]+)/.*', r'\1', url)
body = "User " + str(current_user.email) + " (" + str(current_user.id) + ") has requested developer privileges.\n\n"
if form.reason.data:
body += "Reason given: " + str(form.reason.data) + "\n\n"
body += "Go to " + str(url) + url_for('edit_user_profile_page', id=current_user.id) + " to change the user's privileges."
from flask_mail import Message
msg = Message("Request for developer account from " + str(current_user.email), recipients=recipients, body=body)
if not len(recipients):
flash(word('No administrators could be found.'), 'error')
else:
try:
mail.send(msg)
flash(word('Your request was submitted.'), 'success')
except:
flash(word('We were unable to submit your request.'), 'error')
return redirect(url_for('index'))
return render_template('users/request_developer.html', form=form)
navbar += """\
<li><a aria-controls="source" aria-expanded="false" data-toggle="collapse" href="#source" id="sourcetoggle">""" + word('Source') + """</a></li>
"""
navbar += """\
<ul class="nav navbar-nav navbar-right">
"""
if show_login:
if current_user.is_anonymous:
#logmessage("is_anonymous is " + str(current_user.is_anonymous))
navbar += ' <li><a href="' + url_for('user.login', next=url_for('index')) + '">' + word('Sign in') + '</a></li>' + "\n"
else:
navbar += ' <li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#">' + current_user.email + '<b class="caret"></b></a><ul class="dropdown-menu">'
if current_user.has_role('admin', 'developer'):
navbar +='<li><a href="' + url_for('package_page') + '">' + word('Package Management') + '</a></li>'
navbar +='<li><a href="' + url_for('logs') + '">' + word('Logs') + '</a></li>'
navbar +='<li><a href="' + url_for('playground_page') + '">' + word('Playground') + '</a></li>'
if current_user.has_role('admin'):
navbar +='<li><a href="' + url_for('user_list') + '">' + word('User List') + '</a></li>'
navbar +='<li><a href="' + url_for('privilege_list') + '">' + word('Privileges List') + '</a></li>'
navbar +='<li><a href="' + url_for('config_page') + '">' + word('Configuration') + '</a></li>'
navbar += '<li><a href="' + url_for('user_profile_page') + '">' + word('Profile') + '</a></li><li><a href="' + url_for('user.logout') + '">' + word('Sign out') + '</a></li></ul></li>'
else:
navbar += ' <li><a href="' + url_for('exit') + '">' + word('Exit') + '</a></li>'
navbar += """\
</ul>
"""
return(navbar)