def populate_conf_directory(): cork = Cork("example_conf", initialize=True) cork._store.roles["admin"] = 100 cork._store.roles["editor"] = 60 cork._store.roles["user"] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = "******" cork._store.users[username] = { "role": "admin", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } username = password = "" cork._store.users[username] = { "role": "user", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } cork._store.save_users()
def populate_conf_directory(): cork = Cork('example_conf', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['editor'] = 60 cork._store.roles['user'] = 50 cork._store._savejson('roles', cork._store.roles) tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store._save_users()
def populate_conf_directory(adminpass): print("Setting screenly admin pw to "+str(adminpass)) if not os.path.exists("/home/pi/screenly.auth"): os.mkdir("/home/pi/screenly.auth") cork = Cork('/home/pi/screenly.auth', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['editor'] = 60 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = '******' password=adminpass cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '******' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users()
def populate_conf_directory(): cork = Cork('users', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['editor'] = 60 cork._store.roles['user'] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@gmail.com', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '******' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@usaid.gov', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users()
def populate_conf_directory(): cork = Cork('cork_conf', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['user'] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '******' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users()
def run(*args): #cork (app auth) client = pymongo.MongoClient(app_settings.DATABASE_URI) db = client[app_settings.DATABASE_CORK] db.authenticate(app_settings.DATABASE_USERNAME, app_settings.DATABASE_PASSWORD, app_settings.DATABASE_MAIN) existing = db.users.find_one({"login": "******"}) if existing: return mb = MongoDBBackend(db_name=app_settings.DATABASE_CORK, username=app_settings.DATABASE_USERNAME, password=app_settings.DATABASE_PASSWORD, authdb=app_settings.DATABASE_MAIN, initialize=True) cork = Cork(backend=mb, preferred_hashing_algorithm='scrypt') admin_hash = cork._hash("admin", app_settings.ADMIN_PASSWORD) mb.users._coll.insert({ "login": "******", "email_addr": "*****@*****.**", "desc": "admin user", "role": "admin", "hash": admin_hash, "creation_date": "2012-10-28 20:50:26.286723" }) mb.roles._coll.insert({'role': 'admin', 'val': 100}) #mb.roles._coll.insert({'role': 'editor', 'val': 60}) mb.roles._coll.insert({'role': 'user', 'val': 50})
def populate_conf_directory(out_dir, non_interactive): cork = Cork(out_dir, initialize=True) cork._store.roles['admin'] = 101 cork._store.roles['portal'] = 100 cork._store.roles['experimenter'] = 60 cork._store.save_roles() tstamp = str(datetime.utcnow()) stop = False while not stop: if non_interactive: choice = 'y' stop = True else: choice = input('do you want to add one user? [Y/n]') if choice.lower() == 'y' or choice.lower() == 'yes' or not choice: username, password, role = get_username_and_password( non_interactive) user_cork = { 'role': role, 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.users[username] = user_cork print("Cork user is: %s, password is %s" % (username, password)) else: stop = True cork._store.save_users()
def populate_conf_directory(self, auth_dir): """ Creation of basic auth files. """ logger.info("Creating new authentication files, check STDOUT for the generated admin password.") cork = Cork(auth_dir, initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['access_all'] = 70 cork._store.roles['access_normalized'] = 60 cork._store.roles['public'] = 10 cork._store.save_roles() tstamp = str(datetime.utcnow()) #default admin combo: admin/admin username = '******' password = str(uuid.uuid4()) cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': 'Default administrative account', 'creation_date': tstamp } cork._store.save_users() #for security reasons we fdo not want this in the log files. print "A 'admin' account has been created with the password '{0}'".format(password) return cork
def setup_dir(testdir): """Setup test directory with valid JSON files""" #dummy users for testing users = { 'admin': { 'role': 'admin' }, 'a_all': { 'role': 'access_all' }, 'a_norm': { 'role': 'access_normalized' }, 'public': { 'role': 'public' } } #set hash for all users for k, v in users.items(): v['hash'] = Cork._hash(k, 'password') with open("%s/users.json" % testdir, 'w') as f: f.write(json.dumps(users)) with open("%s/roles.json" % testdir, 'w') as f: f.write( """{"admin": 100, "access_all": 70, "access_normalized": 60,"public": 10}""" ) with open("%s/register.json" % testdir, 'w') as f: f.write("""{}""")
def change_pass(pwd): sqlalchemy_backend = Cork(backend=SqlAlchemyBackend(config.db_url)) metadata = MetaData() engine = create_engine(config.db_url) metadata.bind = engine users = Table("users", metadata, extend_existing=True, autoload=True, autoload_with=engine) users.update().where(users.c.username == "transito").values( hash=sqlalchemy_backend._hash("transito", pwd)).execute()
def populate_conf_directory(self): """Populate a directory with valid configuration files, to be run just once The files are not modified by each test """ self._tmpdir = os.path.join(self._tmproot, "cork_functional_test_source") # only do this once, as advertised if os.path.exists(self._tmpdir): return os.mkdir(self._tmpdir) os.mkdir(self._tmpdir + "/example_conf") cork = Cork(os.path.join(self._tmpdir, "example_conf"), initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['editor'] = 60 cork._store.roles['user'] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users()
def populate_conf_directory(self): """Populate a directory with valid configuration files, to be run just once The files are not modified by each test """ self._tmpdir = os.path.join(self._tmproot, "cork_functional_test_source") # only do this once, as advertised if os.path.exists(self._tmpdir): return os.mkdir(self._tmpdir) os.mkdir(self._tmpdir + "/example_conf") cork = Cork(os.path.join(self._tmpdir, "example_conf"), initialize=True) cork._store.roles["admin"] = 100 cork._store.roles["editor"] = 60 cork._store.roles["user"] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = "******" cork._store.users[username] = { "role": "admin", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } username = password = "" cork._store.users[username] = { "role": "user", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } cork._store.save_users()
def add_user(Base, session): Users = Base.classes.users sqlalchemy_backend = Cork(backend=SqlAlchemyBackend(config.db_url)) session.add( Users(username="******", role="admin", hash=sqlalchemy_backend._hash("transito", "transito"), email_addr="*****@*****.**", desc="operario", creation_date=str(datetime.now()), last_login=str(datetime.now()))) session.commit() session.close()
def populate_conf_directory(): """Populate a directory with valid configuration files, to be run just once The files are not modified by each test """ global tmpdir tmpdir = "%s/cork_functional_test_source" % tmproot # only do this once, as advertised if os.path.exists(tmpdir): return os.mkdir(tmpdir) os.mkdir(tmpdir + "/example_conf") cork = Cork(tmpdir + "/example_conf", initialize=True) cork._store.roles["admin"] = 100 cork._store.roles["editor"] = 60 cork._store.roles["user"] = 50 cork._store._savejson("roles", cork._store.roles) tstamp = str(datetime.utcnow()) username = password = "******" cork._store.users[username] = { "role": "admin", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } username = password = "" cork._store.users[username] = { "role": "user", "hash": cork._hash(username, password), "email_addr": username + "@localhost.local", "desc": username + " test user", "creation_date": tstamp, } cork._store._save_users()
def populate_conf_directory(): """Populate a directory with valid configuration files, to be run just once The files are not modified by each test """ global tmpdir tmpdir = "%s/cork_functional_test_source" % tmproot # only do this once, as advertised if os.path.exists(tmpdir): return os.mkdir(tmpdir) os.mkdir(tmpdir + "/example_conf") cork = Cork(tmpdir + "/example_conf", initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['editor'] = 60 cork._store.roles['user'] = 50 cork._store._savejson('roles', cork._store.roles) tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } username = password = '' cork._store.users[username] = { 'role': 'user', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store._save_users()
def __initialize_cork_user(username, role, password): cork = Cork(directory=get_config("api", "cork-files-path", "/etc/softfire/users"), initialize=False) user_cork = { 'role': role, 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) } cork._store.users[username] = user_cork cork._store.save_users() logger.debug('Created cork user {} with role {}.'.format(username, role))
def add_user(Base, session): Users = Base.classes.users sqlalchemy_backend = Cork(backend=SqlAlchemyBackend(config.db_url)) session.add( Users( username="******", role="admin", hash=sqlalchemy_backend._hash("transito", "transito"), email_addr="*****@*****.**", desc="operario", creation_date=str(datetime.now()), last_login=str(datetime.now()), ) ) session.commit() session.close()
def populate_conf_directory(): cork = Cork('conf', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['user'] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users() print("Login with the username '{}' and the password '{}'. Then go to /admin, add a new admin, and delete this one.".format(username, password))
def create_test_databases(*args): create_databases_with_auth(app_settings.DATABASE_CORK) create_databases_with_auth(app_settings.DATABASE_MAIN) mb = MongoDBBackend(db_name=app_settings.DATABASE_CORK, username=app_settings.DATABASE_USERNAME, password=app_settings.DATABASE_PASSWORD, authdb=app_settings.DATABASE_MAIN, initialize=True) cork = Cork(backend=mb, preferred_hashing_algorithm='scrypt') testuser_hash = cork._hash("testuser", "testuser") mb.users._coll.insert({ "login": "******", "email_addr": "*****@*****.**", "desc": "test user", "role": "user", "hash": testuser_hash, "creation_date": "2012-10-28 20:50:26.286723" })
def create_test_users(): """Run from the 'src' folder""" cork = Cork('config', initialize=True) cork._store.roles['admin'] = 100 cork._store.roles['edit'] = 50 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = '******' password = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } cork._store.save_users()
def populate_conf_directory(): cork = Cork('.', initialize=True) cork._store.roles['admin'] = 100 cork._store._savejson('roles', cork._store.roles) tstamp = str(datetime.utcnow()) username = "" while not username: username = raw_input("Enter admin username: "******"" while not password: password = raw_input("Enter admin password: ") cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'creation_date': tstamp } cork._store._save_users()
def setup_dir(testdir): """Setup test directory with valid JSON files""" # dummy users for testing users = { "admin": {"role": "admin"}, "a_all": {"role": "access_all"}, "a_norm": {"role": "access_normalized"}, "public": {"role": "public"}, } # set hash for all users for k, v in users.items(): v["hash"] = Cork._hash(k, "password") with open("%s/users.json" % testdir, "w") as f: f.write(json.dumps(users)) with open("%s/roles.json" % testdir, "w") as f: f.write("""{"admin": 100, "access_all": 70, "access_normalized": 60,"public": 10}""") with open("%s/register.json" % testdir, "w") as f: f.write("""{}""")
def main(): global aaa global app global content_path setproctitle("shoebill") args = parse_args() site_path = os.path.abspath(args.directory) content_path = os.path.join(site_path, "content") check_site_dir(site_path, content_path) print("Starting Shoebill...") setup_git_repo(site_path) if not args.no_auth: # Setup authentication if not aaa_available: print( """Error: the Beaker and/or Cork libraries are missing. \ \nPlease install them or disable authentication using --no-auth""" ) sys.exit(1) auth_dir = os.path.join(site_path, ".shoebill_auth") if not os.path.isdir(auth_dir): print("Creating authentication data") os.mkdir(auth_dir) token = gen_random_token(21) with open(os.path.join(auth_dir, "token"), "w") as f: f.write(token) aaa = Cork(auth_dir, initialize=True, preferred_hashing_algorithm="scrypt") aaa._store.roles["admin"] = 100 aaa._store.roles["editor"] = 50 aaa._store.save_roles() tstamp = str(datetime.utcnow()) admin_password = gen_random_token(6) aaa._store.users["admin"] = { "role": "admin", "hash": aaa._hash("admin", admin_password), "email_addr": "", "desc": "admin", "creation_date": tstamp, "_accessed_time": tstamp, "last_login": tstamp, } aaa._store.save_users() print("\n", "*" * 32, "\n") print("Initialized user 'admin' with password '%s'" % admin_password) print("\n", "*" * 32, "\n") else: aaa = Cork(auth_dir, preferred_hashing_algorithm="scrypt") if aaa: # Sessions are enabled only if authentication is enabled with open(os.path.join(auth_dir, "token")) as f: session_encrypt_key = f.read() session_opts = { "session.cookie_expires": True, "session.encrypt_key": session_encrypt_key, "session.httponly": True, "session.timeout": 3600 * 24, # 1 day "session.type": "cookie", "session.validate_key": True, } wrapped_app = SessionMiddleware(app, session_opts) bottle.run( wrapped_app, host=args.host, port=args.port, debug=args.debug, reloader=args.debug, server="auto", ) else: bottle.run( app, host=args.host, port=args.port, debug=args.debug, reloader=args.debug, server="auto", )
from datetime import datetime from cork import Cork from pathlib import Path password = '******' confdir = Path('./authconf') if not confdir.exists(): confdir.mkdir() cork = Cork('authconf', initialize=True) cork._store.roles['admin'] = 100 cork._store.save_roles() tstamp = str(datetime.utcnow()) username = '******' cork._store.users[username] = { 'role': 'admin', 'hash': cork._hash(username, password), 'email_addr': f'{username}@localhost.local', 'desc': '', 'creation_date': tstamp } cork._store.save_users()
from cork import Cork from datetime import datetime aaa = Cork('auth') username = '******' password = '******' tstamp = str(datetime.utcnow()) aaa._store.users[username] = { 'role': 'admin', 'hash': aaa._hash(username, password), 'email_addr': username + '@localhost.local', 'desc': username + ' test user', 'creation_date': tstamp } aaa._store.save_users()
import sys import os from datetime import datetime from cork import Cork try: os.mkdir("authconf") except OSError: pass cork = Cork("authconf", initialize=True) cork._store.roles["user"] = 50 cork._store.save_roles() username = sys.argv[1] password = sys.argv[2] cork._store.users[username] = { "role": "user", "hash": cork._hash(username, password), "email_addr": "", "desc": "", "creation_date": str(datetime.utcnow()), } cork._store.save_users() print "Generated directory %s%sauthconf" % (os.getcwd(), os.sep)
def main(): global aaa global app global content_path setproctitle('shoebill') args = parse_args() site_path = os.path.abspath(args.directory) content_path = os.path.join(site_path, 'content') check_site_dir(site_path, content_path) print "Starting Shoebill..." setup_git_repo(site_path) if not args.no_auth: # Setup authentication if not aaa_available: print """Error: the Beaker and/or Cork libraries are missing. \ \nPlease install them or disable authentication using --no-auth""" sys.exit(1) auth_dir = os.path.join(site_path, '.shoebill_auth') if not os.path.isdir(auth_dir): print "Creating authentication data" os.mkdir(auth_dir) token = gen_random_token(21) with open(os.path.join(auth_dir, 'token'), 'w') as f: f.write(token) aaa = Cork(auth_dir, initialize=True) aaa._store.roles['admin'] = 100 aaa._store.roles['editor'] = 50 aaa._store.save_roles() tstamp = str(datetime.utcnow()) admin_password = gen_random_token(6) aaa._store.users['admin'] = { 'role': 'admin', 'hash': aaa._hash('admin', admin_password), 'email_addr': '', 'desc': 'admin', 'creation_date': tstamp, '_accessed_time': tstamp, 'last_login': tstamp } aaa._store.save_users() print "\n", "*" * 32, "\n" print "Initialized user 'admin' with password '%s'" % admin_password print "\n", "*" * 32, "\n" else: aaa = Cork(auth_dir) if aaa: # Sessions are enabled only if authentication is enabled with open(os.path.join(auth_dir, 'token')) as f: session_encrypt_key = f.read() session_opts = { 'session.cookie_expires': True, 'session.encrypt_key': session_encrypt_key, 'session.httponly': True, 'session.timeout': 3600 * 24, # 1 day 'session.type': 'cookie', 'session.validate_key': True, } wrapped_app = SessionMiddleware(app, session_opts) bottle.run(wrapped_app, host=args.host, port=args.port, debug=args.debug, reloader=args.debug, server='auto') else: bottle.run(app, host=args.host, port=args.port, debug=args.debug, reloader=args.debug, server='auto')