From 8e24ffd81a9ae5e1e995d85efd7b05cdf535120c Mon Sep 17 00:00:00 2001 From: vanzhiganov Date: Thu, 26 Nov 2015 23:49:41 +0300 Subject: [PATCH] up --- .gitignore | 61 ++++++++++++++++++++++++++++++++++++++++++++ app.py | 6 +++++ cli-admin-add.py | 23 +++++++++++++++++ cli-admin-ls.py | 20 +++++++++++++++ cli-admin-passwd.py | 29 +++++++++++++++++++++ cli-database-init.py | 17 ++++++++++++ cli-settings-init.py | 45 ++++++++++++++++++++++++++++++++ requirements.txt | 6 +++++ settings.origin.ini | 10 ++++++++ 9 files changed, 217 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 cli-admin-add.py create mode 100644 cli-admin-ls.py create mode 100644 cli-admin-passwd.py create mode 100644 cli-database-init.py create mode 100644 cli-settings-init.py create mode 100644 requirements.txt create mode 100644 settings.origin.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f34049a --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +settings.ini +.idea/ + +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/app.py b/app.py new file mode 100644 index 0000000..34dcd7f --- /dev/null +++ b/app.py @@ -0,0 +1,6 @@ +# coding: utf-8 + +from app import app + +if __name__ == '__main__': + app.run() diff --git a/cli-admin-add.py b/cli-admin-add.py new file mode 100644 index 0000000..2ec6632 --- /dev/null +++ b/cli-admin-add.py @@ -0,0 +1,23 @@ +import argparse +from uuid import uuid4 +from hashlib import md5 +from app import models + +__author__ = 'vanzhiganov' + + +parser = argparse.ArgumentParser(description='') +parser.add_argument('--email', dest="email") +parser.add_argument('--password', dest="password") + +args = parser.parse_args() + +admin_id = uuid4() +# todo: validate admin email +admin_email = args.email +admin_password = md5(args.password).hexdigest() + +if models.Admins.select().where(models.Admins.email == args.email).count() == 0: + models.Admins.create(id=admin_id, email=admin_email, password=admin_password, status=1) +else: + print "Admin account with email '%s' already exists." % admin_email diff --git a/cli-admin-ls.py b/cli-admin-ls.py new file mode 100644 index 0000000..a935d2c --- /dev/null +++ b/cli-admin-ls.py @@ -0,0 +1,20 @@ +# coding: utf-8 + +from app import models + +__author__ = 'vanzhiganov' + + +admins_total = models.Admins.select().count() +admins_items = models.Admins.select() + +print "Total admins: %i" % admins_total + +if admins_total == 0: + print '' +else: + print 'List:' + for item in admins_items: + print '%s\t%s\t%s' % (item.id, item.email, item.status) +print '---' +print 'For create a new admin account use command "procdn-admin-add --email --password "' diff --git a/cli-admin-passwd.py b/cli-admin-passwd.py new file mode 100644 index 0000000..9fdcf0a --- /dev/null +++ b/cli-admin-passwd.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import argparse +from uuid import uuid4 +from hashlib import md5 +from app import models + +__author__ = 'vanzhiganov' + + +parser = argparse.ArgumentParser(description='') +parser.add_argument('--email', dest="email") +parser.add_argument('--password', dest="password") + +args = parser.parse_args() + +admin_id = uuid4() +# todo: validate admin email +admin_email = args.email +admin_password = md5(args.password).hexdigest() + +if models.Admins.select().where(models.Admins.email == args.email).count() == 0: + print "Admin account with email '%s' not exists." % admin_email + print '---' + print 'For create a new admin account use command "procdn-admin-add --email --password "' +else: + query = models.Admins.update(password=admin_password).where(models.Admins.email == admin_email) + query.execute() + print 'Password updated.' diff --git a/cli-database-init.py b/cli-database-init.py new file mode 100644 index 0000000..8dc6e57 --- /dev/null +++ b/cli-database-init.py @@ -0,0 +1,17 @@ +from app import models + +models.database.create_tables({ + models.Admins, + models.DataCenters, + models.Servers, + models.ServersSettings, + models.Ips, + models.Settings, + models.Users, + models.UsersBalance, + models.UsersBalanceTransactions, + models.UsersDetails, + models.UsersRecoveryCodes, + models.UsersSecrets, + models.Containers +}, safe=True) diff --git a/cli-settings-init.py b/cli-settings-init.py new file mode 100644 index 0000000..c407b3f --- /dev/null +++ b/cli-settings-init.py @@ -0,0 +1,45 @@ +import argparse +from uuid import uuid4 +from hashlib import md5 +from app import models + +__author__ = 'vanzhiganov' + + +def create_key(key, val=''): + if models.Settings.select().where(models.Settings.key == key).count() == 0: + models.Settings.create(key=key, val=val) + else: + print 'key %s already exists' % key + + +create_key('bonus', '300') +create_key('PAY_ROBOKASSA_LOGING', '') +create_key('PAY_ROBOKASSA_PASSWORD1', '') +create_key('PAY_ROBOKASSA_PASSWORD2', '') +create_key('PAY_ROBOKASSA_ENABLED', '') +create_key('SMTP_PORT', '') +create_key('SMTP_USERNAME', '') +create_key('SMTP_PASSWORD', '') +create_key('SMTP_TIMEOUT', '') +create_key('SMTP_FROM', '') +create_key('SMTP_SENDER', '') +create_key('SMTP_SSL', '1') +create_key('SMTP_SERVER', 'smtp.yandex.ru') +create_key('CLOUDNS_EMAIL', '') +create_key('CLOUDNS_SECRET', '') +create_key('CLOUDNS_DOMAIN', '') +create_key('CLOUDNS_HOST_BALANCE', 'servers.gocloud.ru.') +create_key('CLOUDNS_HOST_BALANCE', 'lb.gocloud.ru') +create_key('footer_code', '') + +create_key("mail.template_name", "simple") +create_key('mail.logotype', "https://procdn.ru/static/images/logo/procdn-logo-48.png") +create_key("mail.company_name", "ProCDN.ru") + +create_key("contacts.email", "support@procdn.ru") +create_key("contacts.phone", "+7 499 7020 236") + +create_key("social.googleplus", "http://plus.google.com/#efef") +create_key("social.facebook", "") +create_key("social.twitter", "") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7823218 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Flask==0.10.1 +psycopg2==2.6.1 +requests==2.7.0 +uWSGI==2.0.11.1 +wsgiref==0.1.2 +validators diff --git a/settings.origin.ini b/settings.origin.ini new file mode 100644 index 0000000..bda31a7 --- /dev/null +++ b/settings.origin.ini @@ -0,0 +1,10 @@ +[Database] +host = localhost +user = postgres +password = postgres +port = 5432 +name = gocloud + +[Application] +DEBUG = true +secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'