From 9c331108798c5c1e91c9840ea314e7ae5785640e Mon Sep 17 00:00:00 2001 From: Vyacheslav Anzhiganov Date: Sun, 3 Apr 2016 19:10:18 +0300 Subject: [PATCH] prepare to pypi packaging --- .../controllers/administrators/__init__.py | 5 +- SWSCloudCore/controllers/billing/__init__.py | 35 +- .../controllers/containers/__init__.py | 4 +- .../controllers/datacenters/__init__.py | 2 + SWSCloudCore/controllers/ips/__init__.py | 2 +- SWSCloudCore/controllers/teams/__init__.py | 2 +- SWSCloudCore/controllers/users/__init__.py | 26 +- SWSCloudCore/models.py | 60 +- .../administrator/html/blank-page.html | 233 ------- .../html/bootstrap-elements.html | 584 ------------------ .../administrator/html/bootstrap-grid.html | 494 --------------- .../templates/administrator/html/charts.html | 406 ------------ .../templates/administrator/html/forms.html | 444 ------------- .../administrator/html/index-rtl.html | 493 --------------- .../templates/administrator/html/index.html | 489 --------------- .../templates/administrator/html/tables.html | 542 ---------------- .../templates/default/cdn/create.html | 35 -- SWSCloudCore/templates/default/cdn/index.html | 48 -- SWSCloudCore/views/account/__init__.py | 281 +++++---- SWSCloudCore/views/account/decorators.py | 0 SWSCloudCore/views/administrator/__init__.py | 73 ++- SWSCloudCore/views/containers/__init__.py | 189 +++--- TODO | 2 + setup.py | 54 +- 24 files changed, 415 insertions(+), 4088 deletions(-) delete mode 100644 SWSCloudCore/templates/administrator/html/blank-page.html delete mode 100644 SWSCloudCore/templates/administrator/html/bootstrap-elements.html delete mode 100644 SWSCloudCore/templates/administrator/html/bootstrap-grid.html delete mode 100644 SWSCloudCore/templates/administrator/html/charts.html delete mode 100644 SWSCloudCore/templates/administrator/html/forms.html delete mode 100644 SWSCloudCore/templates/administrator/html/index-rtl.html delete mode 100644 SWSCloudCore/templates/administrator/html/index.html delete mode 100644 SWSCloudCore/templates/administrator/html/tables.html delete mode 100644 SWSCloudCore/templates/default/cdn/create.html delete mode 100644 SWSCloudCore/templates/default/cdn/index.html create mode 100644 SWSCloudCore/views/account/decorators.py create mode 100644 TODO diff --git a/SWSCloudCore/controllers/administrators/__init__.py b/SWSCloudCore/controllers/administrators/__init__.py index 58531ab..7b5a1d4 100644 --- a/SWSCloudCore/controllers/administrators/__init__.py +++ b/SWSCloudCore/controllers/administrators/__init__.py @@ -17,12 +17,11 @@ class ControllerAdministrators: :param status: :return: """ - result = models.Admins.select().\ - where( + result = models.Admins.select().where( models.Admins.email == email, models.Admins.password == md5(password).hexdigest(), models.Admins.status == status - ).count() + ).count() if result == 0: return False diff --git a/SWSCloudCore/controllers/billing/__init__.py b/SWSCloudCore/controllers/billing/__init__.py index 39f3908..c2312fb 100644 --- a/SWSCloudCore/controllers/billing/__init__.py +++ b/SWSCloudCore/controllers/billing/__init__.py @@ -4,21 +4,50 @@ from SWSCloudCore import models class ControllerBilling: + """ + Класс работы с деньгами + """ def get(self, user_id): - return models.UsersBalance.select( + """ + Выбираем состояние баланса выбранного пользователя + """ + x = models.UsersBalance.select( models.UsersBalance.balance ).where( models.UsersBalance.user == user_id - )[0].balance + ).get() + return x.balance def update(self, user_id): + """ + Обновление баланса + """ return None def exists(self, user_id): - if models.UsersBalance.select().where(models.UsersBalance.user == user_id).count() == 0: + """ + Проверяет наличие записи в таблице балансов + """ + cnt = models.UsersBalance.select().where( + models.UsersBalance.user == user_id + ).count() + if cnt == 0: return False return True def create(self, user_id, balance=0): + """ + Создание записи в таблице + """ models.UsersBalance.create(user=user_id, balance=balance) return True + + def transactions_get(self, user_id): + transactions = dict() + transactions['total'] = models.UsersBalanceTransactions.select().where( + models.UsersBalanceTransactions.user == user_id + ).count() + transactions['items'] = models.UsersBalanceTransactions.select().where( + models.UsersBalanceTransactions.user == user_id + ) + return transactions diff --git a/SWSCloudCore/controllers/containers/__init__.py b/SWSCloudCore/controllers/containers/__init__.py index ebd6213..437838e 100644 --- a/SWSCloudCore/controllers/containers/__init__.py +++ b/SWSCloudCore/controllers/containers/__init__.py @@ -22,7 +22,7 @@ class ControllerContainers: status=status ) except Exception as e: - # todo: write to log + # TODO: write to log print e return False return True @@ -65,7 +65,7 @@ class ControllerContainers: return models.Containers.select().where( models.Containers.user == self.user_id, models.Containers.id == container_id - ).limit(1)[0] + ).get() def set_status(self, rule_id, status=0): # Устанавливаем статус в самом правиле diff --git a/SWSCloudCore/controllers/datacenters/__init__.py b/SWSCloudCore/controllers/datacenters/__init__.py index 9cd8fc9..5a2e21e 100644 --- a/SWSCloudCore/controllers/datacenters/__init__.py +++ b/SWSCloudCore/controllers/datacenters/__init__.py @@ -1,3 +1,5 @@ +# coding: utf-8 + from SWSCloudCore import models diff --git a/SWSCloudCore/controllers/ips/__init__.py b/SWSCloudCore/controllers/ips/__init__.py index 067db6b..6e80ec4 100644 --- a/SWSCloudCore/controllers/ips/__init__.py +++ b/SWSCloudCore/controllers/ips/__init__.py @@ -11,7 +11,7 @@ class ControllerIps: # select IP return models.Ips.select().where( models.Ips.datacenter == datacenter_id and models.Ips.status == 0 - )[0] + ).get() def setbusy(self, ip_id): # mark ip as busy (taken) diff --git a/SWSCloudCore/controllers/teams/__init__.py b/SWSCloudCore/controllers/teams/__init__.py index 5500241..1ed28aa 100644 --- a/SWSCloudCore/controllers/teams/__init__.py +++ b/SWSCloudCore/controllers/teams/__init__.py @@ -18,4 +18,4 @@ class ControllerTeam: return None def members_get(self, team_id): - return None \ No newline at end of file + return None diff --git a/SWSCloudCore/controllers/users/__init__.py b/SWSCloudCore/controllers/users/__init__.py index 8ee5f9c..a601cb0 100644 --- a/SWSCloudCore/controllers/users/__init__.py +++ b/SWSCloudCore/controllers/users/__init__.py @@ -21,18 +21,25 @@ class ControllerUsers: def user_id_by_email(self, email): return models.Users.get(models.Users.email == email).id + def get_id_by_email(self, email): + return models.Users.get(models.Users.email == email).id + def user_exists_by_email(self, email): - if models.Users.select().where(models.Users.email == email).count() == 0: + cnt = models.Users.select().where(models.Users.email == email).count() + if cnt == 0: return False return True def get(self): - return models.Users.select().where(models.Users.id == self.user_id).limit(1)[0] + return models.Users.select().where(models.Users.id == self.user_id).get() def update(self, user_id, **kwargs): if 'password' in kwargs: - x = models.Users.update(password=md5(kwargs['password']).hexdigest()).where( - models.Users.id == user_id) + x = models.Users.update( + password=md5(kwargs['password']).hexdigest() + ).where( + models.Users.id == user_id + ) x.execute() return True @@ -63,12 +70,11 @@ class ControllerUsers: :return: """ password_hash = md5(password).hexdigest() - result = models.Users.select().\ - where( + result = models.Users.select().where( models.Users.email == email, models.Users.password == password_hash, models.Users.status == status - ).count() + ).count() if result == 0: return False return True @@ -82,7 +88,7 @@ class ControllerUsers: """ password_hash = md5(password).hexdigest() user_id = uuid.uuid4() - # todo: add date registration and update of date - =datetime.datetime.now() + # TODO: add date registration and update of date - =datetime.datetime.now() user = models.Users.create(id=user_id, email=email, password=password_hash, status=1) if user.id: return True @@ -95,10 +101,6 @@ class ControllerUsers: u.save() return True - def get_id_by_email(self, email): - user = models.Users.select(models.Users.id).where(models.Users.email == email).limit(1) - return user[0].id - class ControllerUsersRecoveryCodes(): def create(self, user_id, code): diff --git a/SWSCloudCore/models.py b/SWSCloudCore/models.py index 3d92b03..21ed565 100644 --- a/SWSCloudCore/models.py +++ b/SWSCloudCore/models.py @@ -26,6 +26,9 @@ class PgSQLModel(Model): class DataCenters(PgSQLModel): + """ + Модель датацентров + """ id = UUIDField(unique=True, primary_key=True, null=False) code = CharField(unique=True) name = CharField(unique=True) @@ -36,7 +39,7 @@ class DataCenters(PgSQLModel): class Servers(PgSQLModel): id = UUIDField(unique=True, primary_key=True) - datacenter = ForeignKeyField(DataCenters, related_name='dcsservers') + datacenter = ForeignKeyField(DataCenters) secret = CharField() created = DateTimeField(default=datetime.datetime.now()) status = IntegerField() @@ -57,8 +60,7 @@ class Ips(PgSQLModel): ipv6 = CharField() ipv4_gateway = CharField() ipv6_gateway = CharField() - # 0 - free - # 1 - used + # 0: free, 1: used status = IntegerField() @@ -66,17 +68,18 @@ class Users(PgSQLModel): id = UUIDField(primary_key=True, unique=True) email = CharField(unique=True, null=False) password = CharField() + created = DateTimeField(default=datetime.datetime.now) status = IntegerField() class UsersRecoveryCodes(PgSQLModel): - user = ForeignKeyField(Users, related_name='usersrecoverycodes') + user = ForeignKeyField(Users) recovery_code = CharField(null=False) created = DateTimeField(default=datetime.datetime.now) class UsersSecrets(PgSQLModel): - user = ForeignKeyField(Users, related_name='userssecrets') + user = ForeignKeyField(Users) # 4f235008-a9bd-11e5-a24e-28d244e159e9 secret = CharField(unique=True, null=False) # 1.1.1.1,1.2.3.4 @@ -87,24 +90,29 @@ class UsersSecrets(PgSQLModel): class UsersDetails(PgSQLModel): - user = ForeignKeyField(Users, related_name='usersdetails') - fname = CharField(null=True) - lname = CharField(null=True) - address = CharField(null=True) - city = CharField(null=True) - country = CharField(null=True) - state = CharField(null=True) - zipcode = IntegerField(null=True) + user = ForeignKeyField(Users) + fname = CharField(null=True, default='') + lname = CharField(null=True, default='') + address = CharField(null=True, default='') + city = CharField(null=True, default='') + country = CharField(null=True, default='') + state = CharField(null=True, default='') + zipcode = IntegerField(null=True, default='') class UsersBalance(PgSQLModel): - user = ForeignKeyField(Users, related_name='usersbalance') + """ + Текущий баланс пользователей + """ + user = ForeignKeyField(Users) balance = FloatField(default=0, null=False) class UsersBalanceTransactions(PgSQLModel): - id = IntegerField(primary_key=True, null=False, sequence='nextval') - user = ForeignKeyField(Users, related_name='usersbalancetransaction') + """ + Транзакции + """ + user = ForeignKeyField(Users) amount = FloatField(default=0, null=False) created = DateTimeField(default=datetime.datetime.now) notified = IntegerField(null=False, default=0) @@ -117,6 +125,10 @@ class UsersBalanceTransactions(PgSQLModel): class SSHKeys(PgSQLModel): user = ForeignKeyField(Users) sshkey = TextField(null=True) + # с какого ip был добавлен ключ + remote = TextField(null=True) + # когда был добавлен ключ + created = DateTimeField(default=datetime.datetime.now) class Containers(PgSQLModel): @@ -126,12 +138,7 @@ class Containers(PgSQLModel): user = ForeignKeyField(Users) ipv4 = CharField() ipv6 = CharField() - # 0 - # 1 - # 2 - # 3 - # 4 - # 5 + # 0: inactive, 1: active, 2: ..., 3: ..., 4: ..., 5: ... status = IntegerField() @@ -159,9 +166,9 @@ class ContainersStatisticsState(PgSQLModel): class Tasks(PgSQLModel): id = UUIDField(primary_key=True, unique=True) - datacenter = ForeignKeyField(DataCenters, related_name='dcstasks') - server = ForeignKeyField(Servers, related_name='serverstasks') - user = ForeignKeyField(Users, related_name='userstasks') + datacenter = ForeignKeyField(DataCenters) + server = ForeignKeyField(Servers) + user = ForeignKeyField(Users) created = DateTimeField(default=datetime.datetime.now) task = CharField(null=False) # 0 - new @@ -172,6 +179,9 @@ class Tasks(PgSQLModel): class Settings(PgSQLModel): + """ + Модель настроек + """ key = TextField(unique=True, null=False) val = TextField(null=True) diff --git a/SWSCloudCore/templates/administrator/html/blank-page.html b/SWSCloudCore/templates/administrator/html/blank-page.html deleted file mode 100644 index 3aa3f5c..0000000 --- a/SWSCloudCore/templates/administrator/html/blank-page.html +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Blank Page - Subheading -

- -
-
- - -
- - -
- - -
- - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/bootstrap-elements.html b/SWSCloudCore/templates/administrator/html/bootstrap-elements.html deleted file mode 100644 index d5e9951..0000000 --- a/SWSCloudCore/templates/administrator/html/bootstrap-elements.html +++ /dev/null @@ -1,584 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Bootstrap Elements -

- -
-
- - - -
-

Hello, world!

-

This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.

-

Learn more » -

-
- - -

- - - - - - - -

-

- - - - - - - -

-

- - - - - - - -

-

- - - - - - - -

- - - - - - - - - - - - - - -
- Well done! You successfully read this important alert message. -
-
- Heads up! This alert needs your attention, but it's not super important. -
-
- Warning! Best check yo self, you're not looking too good. -
-
- Oh snap! Change a few things up and try submitting again. -
- - -
-
60% Complete -
-
-
-
40% Complete (success) -
-
-
-
20% Complete -
-
-
-
60% Complete (warning) -
-
-
-
80% Complete (danger) -
-
-
-
35% Complete (success) -
-
20% Complete (warning) -
-
10% Complete (danger) -
-
- - - - - -
-
-
-
-

Panel title

-
-
- Panel content -
-
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
-
-
-

Panel title

-
-
- Panel content -
-
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
-
-
-

Panel title

-
-
- Panel content -
-
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
-
-
-

Panel title

-
-
- Panel content -
-
-
- -
- - -
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed diam eget risus varius blandit sit amet non magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Cras mattis consectetur purus sit amet fermentum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Aenean lacinia bibendum nulla sed consectetur.

-
- -
- - -
- - -
- - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/bootstrap-grid.html b/SWSCloudCore/templates/administrator/html/bootstrap-grid.html deleted file mode 100644 index 4c6d737..0000000 --- a/SWSCloudCore/templates/administrator/html/bootstrap-grid.html +++ /dev/null @@ -1,494 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Bootstrap Grid -

- -
-
- - -
-
-
-
- .col-lg-12 -
-
-
-
- - -
-
-
-
- .col-lg-6 -
-
-
-
-
-
- .col-lg-6 -
-
-
-
- - -
-
-
-
- .col-lg-4 -
-
-
-
-
-
- .col-lg-4 -
-
-
-
-
-
- .col-lg-4 -
-
-
-
- - -
-
-
-
- .col-lg-3 -
-
-
-
-
-
- .col-lg-3 -
-
-
-
-
-
- .col-lg-3 -
-
-
-
-
-
- .col-lg-3 -
-
-
-
- - -
-
-
-
- .col-lg-2 -
-
-
-
-
-
- .col-lg-2 -
-
-
-
-
-
- .col-lg-2 -
-
-
-
-
-
- .col-lg-2 -
-
-
-
-
-
- .col-lg-2 -
-
-
-
-
-
- .col-lg-2 -
-
-
-
- - -
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
-
-
- .col-lg-1 -
-
-
-
- - -
-
-
-
- .col-lg-8 -
-
-
-
-
-
- .col-lg-4 -
-
-
-
- - -
-
-
-
- .col-lg-3 -
-
-
-
-
-
- .col-lg-6 -
-
-
-
-
-
- .col-lg-3 -
-
-
-
- - -
- - -
- - -
- - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/charts.html b/SWSCloudCore/templates/administrator/html/charts.html deleted file mode 100644 index 4354bf8..0000000 --- a/SWSCloudCore/templates/administrator/html/charts.html +++ /dev/null @@ -1,406 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Charts -

- -
-
- - - -
-
- -

Flot is a pure JavaScript plotting library for jQuery, with a focus on simple usage, attractive looks and interactive features. For full usage instructions and documentation for Flot Charts, visit http://www.flotcharts.org/.

-
-
- - -
-
-
-
-

Line Graph Example with Tooltips

-
-
-
-
-
-
-
-
-
- - -
-
-
-
-

Pie Chart Example with Tooltips

-
-
-
-
-
- -
-
-
-
-
-
-

Multiple Axes Line Graph Example with Tooltips and Raw Data

-
-
-
-
-
- -
-
-
-
- - -
-
-
-
-

Moving Line Chart

-
-
-
-
-
- -
-
-
-
-
-
-

Bar Graph with Tooltips

-
-
-
-
-
- -
-
-
-
- - - -
-
- -

Morris.js is a very simple API for drawing line, bar, area and donut charts. For full usage instructions and documentation for Morris.js charts, visit http://morrisjs.github.io/morris.js/.

-
-
- - -
-
-
-
-

Area Line Graph Example with Tooltips

-
-
-
-
-
-
-
- - -
-
-
-
-

Donut Chart Example

-
-
-
- -
-
-
-
-
-
-

Line Graph Example with Tooltips

-
-
-
- -
-
-
-
-
-
-

Bar Graph Example

-
-
-
- -
-
-
-
- - -
- - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/forms.html b/SWSCloudCore/templates/administrator/html/forms.html deleted file mode 100644 index c7d99e0..0000000 --- a/SWSCloudCore/templates/administrator/html/forms.html +++ /dev/null @@ -1,444 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Forms -

- -
-
- - -
-
- -
- -
- - -

Example block-level help text here.

-
- -
- - -
- -
- -

email@example.com

-
- -
- - -
- -
- - -
- -
- -
- -
-
- -
-
- -
-
- -
- - - - -
- -
- -
- -
-
- -
-
- -
-
- -
- - - - -
- -
- - -
- -
- - -
- - - - -
- -
-
-

Disabled Form States

- -
- -
- -
- - -
- -
- - -
- -
- -
- - - -
- -
- -

Form Validation

- -
- -
- - -
- -
- - -
- -
- - -
- -
- -

Input Groups

- -
- -
- @ - -
- -
- - .00 -
- -
- - -
- -
- $ - - .00 -
- -
- - -
- -
- -

For complete documentation, please visit Bootstrap's Form Documentation.

- -
-
- - -
- - -
- - -
- - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/index-rtl.html b/SWSCloudCore/templates/administrator/html/index-rtl.html deleted file mode 100644 index 2cb9e03..0000000 --- a/SWSCloudCore/templates/administrator/html/index-rtl.html +++ /dev/null @@ -1,493 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Dashboard Statistics Overview -

- -
-
- - -
-
-
- - Like SB Admin? Try out SB Admin 2 for additional features! -
-
-
- - -
-
-
-
-
-
- -
-
-
26
-
New Comments!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
12
-
New Tasks!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
124
-
New Orders!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
13
-
Support Tickets!
-
-
-
- - - -
-
-
- - -
-
-
-
-

Area Chart

-
-
-
-
-
-
-
- - -
-
-
-
-

Donut Chart

-
-
-
- -
-
-
- -
-
-
-

Transactions Panel

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Order #Order DateOrder TimeAmount (USD)
332610/21/20133:29 PM$321.33
332510/21/20133:20 PM$234.34
332410/21/20133:03 PM$724.17
332310/21/20133:00 PM$23.71
332210/21/20132:49 PM$8345.23
332110/21/20132:23 PM$245.12
332010/21/20132:15 PM$5663.54
331910/21/20132:13 PM$943.45
-
- -
-
-
-
- - -
- - -
- - -
- - - - - - - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/index.html b/SWSCloudCore/templates/administrator/html/index.html deleted file mode 100644 index 22a864d..0000000 --- a/SWSCloudCore/templates/administrator/html/index.html +++ /dev/null @@ -1,489 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Dashboard Statistics Overview -

- -
-
- - -
-
-
- - Like SB Admin? Try out SB Admin 2 for additional features! -
-
-
- - -
-
-
-
-
-
- -
-
-
26
-
New Comments!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
12
-
New Tasks!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
124
-
New Orders!
-
-
-
- - - -
-
-
-
-
-
-
- -
-
-
13
-
Support Tickets!
-
-
-
- - - -
-
-
- - -
-
-
-
-

Area Chart

-
-
-
-
-
-
-
- - -
-
-
-
-

Donut Chart

-
-
-
- -
-
-
- -
-
-
-

Transactions Panel

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Order #Order DateOrder TimeAmount (USD)
332610/21/20133:29 PM$321.33
332510/21/20133:20 PM$234.34
332410/21/20133:03 PM$724.17
332310/21/20133:00 PM$23.71
332210/21/20132:49 PM$8345.23
332110/21/20132:23 PM$245.12
332010/21/20132:15 PM$5663.54
331910/21/20132:13 PM$943.45
-
- -
-
-
-
- - -
- - -
- - -
- - - - - - - - - - - - - - - - diff --git a/SWSCloudCore/templates/administrator/html/tables.html b/SWSCloudCore/templates/administrator/html/tables.html deleted file mode 100644 index 6ea715c..0000000 --- a/SWSCloudCore/templates/administrator/html/tables.html +++ /dev/null @@ -1,542 +0,0 @@ - - - - - - - - - - - - SB Admin - Bootstrap Admin Template - - - - - - - - - - - - - - - - - - -
- - - - -
- -
- - -
-
-

- Tables -

- -
-
- - -
-
-

Bordered Table

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PageVisits% New VisitsRevenue
/index.html126532.3%$321.33
/about.html26133.3%$234.12
/sales.html66521.3%$16.34
/blog.html951689.3%$1644.43
/404.html2334.3%$23.52
/services.html42160.3%$724.32
/blog/post.html123393.2%$126.34
-
-
-
-

Bordered with Striped Rows

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PageVisits% New VisitsRevenue
/index.html126532.3%$321.33
/about.html26133.3%$234.12
/sales.html66521.3%$16.34
/blog.html951689.3%$1644.43
/404.html2334.3%$23.52
/services.html42160.3%$724.32
/blog/post.html123393.2%$126.34
-
-
-
- - -
-
-

Basic Table

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PageVisits% New VisitsRevenue
/index.html126532.3%$321.33
/about.html26133.3%$234.12
/sales.html66521.3%$16.34
/blog.html951689.3%$1644.43
/404.html2334.3%$23.52
/services.html42160.3%$724.32
/blog/post.html123393.2%$126.34
-
-
-
-

Striped Rows

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PageVisits% New VisitsRevenue
/index.html126532.3%$321.33
/about.html26133.3%$234.12
/sales.html66521.3%$16.34
/blog.html951689.3%$1644.43
/404.html2334.3%$23.52
/services.html42160.3%$724.32
/blog/post.html123393.2%$126.34
-
-
-
- - -
-
-

Contextual Classes

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PageVisits% New VisitsRevenue
/index.html126532.3%$321.33
/about.html26133.3%$234.12
/sales.html66521.3%$16.34
/blog.html951689.3%$1644.43
/404.html2334.3%$23.52
/services.html42160.3%$724.32
/blog/post.html123393.2%$126.34
-
-
-
-

Bootstrap Docs

-

For complete documentation, please visit Bootstrap's Tables Documentation.

-
-
- - -
- - -
- - -
- - - - - - - - - - - diff --git a/SWSCloudCore/templates/default/cdn/create.html b/SWSCloudCore/templates/default/cdn/create.html deleted file mode 100644 index 8e78dda..0000000 --- a/SWSCloudCore/templates/default/cdn/create.html +++ /dev/null @@ -1,35 +0,0 @@ -{% extends "default/_layout.html" %} - -{% block title %}Новая зона{% endblock %} - -{% block content %} -
-
-

Новая зона

-
-
-
-
- {% if g.errors['total'] > 0 %} -
-
    - {% for error in g.errors['items'] %} -
  • {{ error }}
  • - {% endfor %} -
-
- {% endif %} -
-
-
- - -
-
- -
-
-
-
-
-{% endblock %} diff --git a/SWSCloudCore/templates/default/cdn/index.html b/SWSCloudCore/templates/default/cdn/index.html deleted file mode 100644 index 2864f0e..0000000 --- a/SWSCloudCore/templates/default/cdn/index.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends "default/_layout.html" %} - -{% block title %}CDN{% endblock %} - -{% block content %} -
-
-

Список +

-
-
-
-
- - - - - - {##} - - - - - - - - {% if zones|length == 0 %} - - - - {% else %} - {% for zone in zones %} - - - - - - - - {% endfor %} - {% endif %} - -
IDИмяТипURL зоныURL источникаДействие
Нет ни одного контейнера. Добавить.
{{ zone['id'] }}{{ zone['name'] }}{{ zone['name'] }}.procdn.ru{{ zone['originurl'] }} - Настройки -
-
-
-{% endblock %} diff --git a/SWSCloudCore/views/account/__init__.py b/SWSCloudCore/views/account/__init__.py index 9dedce9..d301b0b 100644 --- a/SWSCloudCore/views/account/__init__.py +++ b/SWSCloudCore/views/account/__init__.py @@ -1,6 +1,8 @@ # coding: utf-8 -from flask import Blueprint, g, render_template, session, redirect, url_for, request +import validators +from flask import Blueprint, g, render_template, session, redirect, url_for +from flask import request, flash from sshpubkeys import SSHKey from SWSCloudCore.controllers.billing import ControllerBilling from SWSCloudCore.controllers.common import ControllerMessagesEmail @@ -25,58 +27,57 @@ def index(): return redirect(url_for("account.logout")) cud = ControllerUsersDetails(session['user_id']) - user = cud.details_get() # проверяем, есть ли запись в таблице usersdetails, чтобы небыло ошибок if not cud.details_exists(): # если нет, то делаем запись в таблицу, чтобы небыло ошибок cud.details_create() - # извлекаем из базы детали пользователя - user_details = cud.details_get() - return render_template( 'default/id/index.html', - user=user, - user_details=user_details + user=cud.details_get(), + user_details=cud.details_get() ) -@viewAccount.route('/edit', methods=['GET', 'POST']) +@viewAccount.route('/edit.html', methods=['GET', 'POST']) def edit(): + cu = ControllerUsers() # check session - if not ControllerUsers().check_session(): + if not cu.check_session(): return redirect(url_for("account.logout")) # auth user - if not ControllerUsers().auth(session['email'], session['password']): + if not cu.auth(session['email'], session['password']): return redirect(url_for("account.logout")) cud = ControllerUsersDetails(session['user_id']) - user = cud.details_get() + # Проверяем есть ли детали пользователя. if not cud.details_exists(): + # Если нет, то создаём cud.details_create() if request.method == "POST": if not request.form['zipcode'].isdigit(): - g.errors['items'].append(u'Индекс должен содержать только цифры') - g.errors['total'] += 1 - - if g.errors['total'] == 0: - cud.details_update( - fname=request.form['fname'], - lname=request.form['lname'], - address=request.form['address'], - city=request.form['city'], - country=request.form['country'], - state=request.form['state'], - zipcode=request.form['zipcode'] - ) + flash(u'Индекс должен содержать только цифры') return redirect(url_for('account.edit')) - # get user details - user_details = cud.details_get() - return render_template('default/id/edit.html', user=user, user_details=user_details) + cud.details_update( + fname=request.form['fname'], + lname=request.form['lname'], + address=request.form['address'], + city=request.form['city'], + country=request.form['country'], + state=request.form['state'], + zipcode=request.form['zipcode'] + ) + return redirect(url_for('account.edit')) + + return render_template( + 'default/id/edit.html', + user=cud.details_get(), + user_details=cud.details_get() + ) @viewAccount.route('/settings', methods=['GET', 'POST']) @@ -87,10 +88,11 @@ def settings(): # auth user if not ControllerUsers().auth(session['email'], session['password']): return redirect(url_for("account.logout")) - # get user data - user = ControllerUsers(session['user_id']).get() - return render_template('default/id/index.html', user_details=user) + return render_template( + 'default/id/index.html', + user_details=ControllerUsers(session['user_id']).get() + ) @viewAccount.route('/billing', methods=['GET', 'POST']) @@ -103,109 +105,113 @@ def billing(): return redirect(url_for("account.logout")) user_id = session['user_id'] + cub = ControllerBilling() - if models.UsersBalance.select().where(models.UsersBalance.user == user_id).count() == 0: - models.UsersBalance.create(user=user_id, balance=10) - user_balance = models.UsersBalance.select().where(models.UsersBalance.user == user_id).limit(1)[0].balance + if not cub.exists(user_id): + cub.create(user=user_id, balance=0) - user_details = models.Users.select().where(models.Users.id == session['user_id']).limit(1)[0] - - # выгрузка истории платежей - history = dict() - history['total'] = models.UsersBalanceTransactions.select().\ - where(models.UsersBalanceTransactions.user == user_id).count() - history['items'] = models.UsersBalanceTransactions.select().\ - where(models.UsersBalanceTransactions.user == user_id) + # TODO: move to function + user_details = models.Users.select().where( + models.Users.id == session['user_id'] + ).get() return render_template( 'default/id/balance.html', user_details=user_details, - user_balance=user_balance, - history=history + user_balance=cub.get(user_id), + history=cub.transactions_get(user_id) ) -@viewAccount.route('/registration', methods=['GET', 'POST']) +@viewAccount.route('/registration.html', methods=['GET', 'POST']) def registration(): - # check session - if ControllerUsers().check_session(): + cu = ControllerUsers() + # Проверяем сессию, если все данные на месте, + # то перенаправляем пользователя на страницу со списком контейнеров + if cu.check_session(): return redirect(url_for("containers.index")) if request.method == 'POST': - check_password = False - if request.form['password'] == request.form['password2']: - check_password = True + email = request.form['email'] + password = request.form['password'] + password2 = request.form['password2'] - if not special_match(request.form['email'], r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$")\ - or len(request.form['password']) < 5\ - or not check_password: - g.errors['items'].append('Invalid registration data.') - g.errors['total'] += 1 + # Проверка введён ли проверочный пароль одинаково + if password != password2: + flash(u'Пароли не совпадают', 'error') - if g.errors['total'] == 0: - # count user with email and password - if models.Users.select().where(models.Users.email == request.form['email']).count(): - g.errors['items'].append('Invalid registration. User already exists.') - g.errors['total'] += 1 - else: - if ControllerUsers().registration(request.form['email'], request.form['password']): - user_id = ControllerUsers().get_id_by_email(request.form['email']) + # Проверяем правильность адреса е-почты и + if not validators.email(email): + flash(u'Неправильный адрес електронной почты', 'error') + return redirect(url_for('account.registration')) - ControllerUsersDetails(user_id).details_create() - ControllerBilling().create(user_id, g.settings['bonus']) - # ControllerU - # send mail message with recovery code - message = u""" - Е-почта: %s - Пароль: %s - """ % (request.form['email'], request.form['password']) - subject = u'GoCloud.ru: Успешная регистрация' - lead = u""" - Поздравляем с успешной зарегистрацией. - """ - callout = u""" - Для входа в личный кабинет воспользуйтесь - страницей авторизации. - """ + # Проверяем зарегистрирован ли указанный адрес електронной почты + if cu.user_exists_by_email(email): + flash(u'Польщователь с указанным адресом уже зарегистрирован') + return redirect(url_for('account.registration')) - email = ControllerMessagesEmail() - email.send(title=subject, to=request.form['email'], lead=lead, message=message, callout=callout) + # Регистрируем пользователя в системе + if ControllerUsers().registration(email, password): + user_id = ControllerUsers().get_id_by_email(email) - # redirect to login page - return redirect(url_for('account.login')) - else: - g.errors['items'].append('Invalid registration. Try again.') - g.errors['total'] += 1 + ControllerUsersDetails(user_id).details_create() + ControllerBilling().create(user_id, g.settings['bonus']) + # ControllerU + # send mail message with recovery code + message = u""" + Е-почта: %s + Пароль: %s + """ % (request.form['email'], request.form['password']) + subject = u'GoCloud.ru: Успешная регистрация' + lead = u""" + Поздравляем с успешной зарегистрацией. + """ + callout = u""" + Для входа в личный кабинет воспользуйтесь + страницей авторизации. + """ + + email = ControllerMessagesEmail() + email.send(title=subject, to=request.form['email'], lead=lead, message=message, callout=callout) + + # redirect to login page + flash(u'Учетная запись успешно зарегистрирована.', 'success') + return redirect(url_for('account.login')) + else: + flash('Ошибка при регистрации, попробуйте снова', 'error') + return redirect(url_for('account.registration')) return render_template('default/id/registration.html') -@viewAccount.route('/login', methods=['GET', 'POST']) +@viewAccount.route('/login.html', methods=['GET', 'POST']) def login(): + cu = ControllerUsers() if request.method == 'POST': - # validation entered data - if not special_match(request.form['email'], r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$")\ - or len(request.form['password']) < 5: - g.errors['items'].append('Invalid registration data.') - g.errors['total'] += 1 + email = request.form['email'] + password = request.form['password'] - if g.errors['total'] == 0: - # try auth only active users (with status code 1) - if ControllerUsers().auth(request.form['email'], request.form['password'], 1): - # get user_id - user_id = ControllerUsers().get_id_by_email(request.form['email']) - # save user data to session - session['user_id'] = user_id - session['email'] = request.form['email'] - session['password'] = request.form['password'] - # redirect to rules list - return redirect(url_for('containers.index')) - else: - g.errors['items'].append('Invalid login. Please try again.') - g.errors['total'] += 1 + # validation entered data + if not requests.email(email): + flash(u'Неправильный адрес електронной почты', 'error') + return redirect(url_for('account.login')) + + # try auth only active users (with status code 1) + if cu.auth(email, password, 1): + # get user_id + user_id = cu.get_id_by_email(email) + # save user data to session + session['user_id'] = user_id + session['email'] = email + session['password'] = password + # redirect to rules list + return redirect(url_for('containers.index')) + else: + flash(u'Не авторизованы', 'error') + return redirect(url_for('account.login')) return render_template("default/id/login.html") -@viewAccount.route('/logout') +@viewAccount.route('/logout.html') def logout(): session.pop('user_id', None) session.pop('email', None) @@ -213,44 +219,53 @@ def logout(): return redirect(url_for('account.login')) -@viewAccount.route("/password_reset", methods=['GET', 'POST']) +@viewAccount.route("/password_reset.html", methods=['GET', 'POST']) def password_reset(): if request.method == "POST": + cu = ControllerUsers() + curc = ControllerUsersRecoveryCodes() + email = request.form['email'] + + if not validators.email(email): + flash(u'Произошла ошибка. Введите корректный адрес е.почты.') + return redirect(url_for('account.password_reset')) + # check exists email - if ControllerUsers().user_exists_by_email(request.form['email']): - # get user_id by email - user_id = str(ControllerUsers().user_id_by_email(request.form['email'])) + if not cu.user_exists_by_email(email): + flash(u'Произошла ошибка. Введите корректный адрес е.почты.') + return redirect(url_for('account.password_reset')) - # create recovery code - recovery_code = ControllerUsersRecoveryCodes().code_generate() + # get user_id by email + user_id = str(cu.user_id_by_email(email)) - # remove old recovery codes for user - ControllerUsersRecoveryCodes().delete(user_id) - # write new recovery code to database - ControllerUsersRecoveryCodes().create(user_id, recovery_code) + # create recovery code + recovery_code = curc.code_generate() - # send mail message with recovery code - subject = u'GoCloud.ru: Код восстановления доступа' - message = u'Код восстановления: %s' % recovery_code - lead = u""" - Данный код необходимо ввести на странице подтверждения - сброса пароля. - """ - callout = u'Если вы не хотите сбрасывать пароль, то просто проигнорируйте (или удалите) данное письмо.' - # controllers.Mail().send(request.form['email'], subject, message) + # remove old recovery codes for user + curc.delete(user_id) + # write new recovery code to database + curc.create(user_id, recovery_code) - email = ControllerMessagesEmail() - email.send(title=subject, to=request.form['email'], lead=lead, message=message, callout=callout) + # send mail message with recovery code + subject = u'GoCloud.ru: Код восстановления доступа' + message = u'Код восстановления: %s' % recovery_code + lead = u""" + Данный код необходимо ввести на странице подтверждения + сброса пароля. + """ + callout = u'Если вы не хотите сбрасывать пароль, то просто проигнорируйте (или удалите) данное письмо.' + # controllers.Mail().send(request.form['email'], subject, message) - # redirect to step 2 - return redirect(url_for('account.password_reset_step2')) - else: - g.errors['items'].append(u'Произошла ошибка. Введите корректный адрес е.почты.') - g.errors['total'] += 1 + email = ControllerMessagesEmail() + email.send(title=subject, to=request.form['email'], lead=lead, message=message, callout=callout) + + # redirect to step 2 + flash(u'На указанный адрес был отправлен код подтверждения', 'info') + return redirect(url_for('account.password_reset_step2')) return render_template('default/id/password_reset_step1.html') -@viewAccount.route("/password_reset_step2", methods=['GET', 'POST']) +@viewAccount.route("/password_reset_step2.html", methods=['GET', 'POST']) def password_reset_step2(): if request.method == "POST": # check exists email diff --git a/SWSCloudCore/views/account/decorators.py b/SWSCloudCore/views/account/decorators.py new file mode 100644 index 0000000..e69de29 diff --git a/SWSCloudCore/views/administrator/__init__.py b/SWSCloudCore/views/administrator/__init__.py index 307acb3..c710e1d 100644 --- a/SWSCloudCore/views/administrator/__init__.py +++ b/SWSCloudCore/views/administrator/__init__.py @@ -1,15 +1,8 @@ # coding: utf-8 from uuid import uuid4 +import validators -from SWSCloudCore.controllers.administrators import ControllerAdministrators -from SWSCloudCore.controllers.billing import ControllerBilling -from SWSCloudCore.controllers.common import ControllerMessagesEmail -from SWSCloudCore.controllers.common import special_match -from SWSCloudCore.controllers.containers.manage import ControllerManageContainers -from SWSCloudCore.controllers.datacenters.manage import ControllerManageDatacenters -from SWSCloudCore.controllers.ips.manage import ControllerManageIPs -from SWSCloudCore.controllers.servers.manage import ControllerManageServer from flask import Blueprint from flask import g from flask import jsonify @@ -19,10 +12,17 @@ from flask import request from flask import session from flask import url_for -from SWSCloudCore import models +from SWSCloudCore.controllers.administrators import ControllerAdministrators +from SWSCloudCore.controllers.billing import ControllerBilling +from SWSCloudCore.controllers.common import ControllerMessagesEmail +from SWSCloudCore.controllers.containers.manage import ControllerManageContainers +from SWSCloudCore.controllers.datacenters.manage import ControllerManageDatacenters +from SWSCloudCore.controllers.ips.manage import ControllerManageIPs +from SWSCloudCore.controllers.servers.manage import ControllerManageServer from SWSCloudCore.controllers.users.manage import ControllerManageUsers from SWSCloudCore.controllers.users.manage import ControllerManageUsersBalance from SWSCloudCore.controllers.users.manage import ControllerManageUsersDetails +from SWSCloudCore import models viewAdministrator = Blueprint('administrator', __name__, url_prefix='/administrator') @@ -34,27 +34,25 @@ def login(): admin_password = request.form['password'].encode('utf-8') # validation entered data - if not special_match(admin_email, r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$")\ - or len(admin_password) < 5: - g.errors['items'].append('Invalid registration data.') - g.errors['total'] += 1 - # если ошибок нет, то продолжаем обработку - if g.errors['total'] == 0: - # try auth only active users (with status code 1) - if ControllerAdministrators().auth(admin_email, admin_password, 1): - # get user_id - user_id = ControllerAdministrators().get_id_by_email(admin_email) + if not validators.email(admin_email): + flash('Invalid registration data') + return redirect(url_for('administrator.login')) - # save user data to session - session['admin_id'] = str(user_id) - session['admin_email'] = admin_email - session['admin_password'] = admin_password + # try auth only active users (with status code 1) + if ControllerAdministrators().auth(admin_email, admin_password, 1): + # get user_id + user_id = ControllerAdministrators().get_id_by_email(admin_email) - # redirect to rules list - return redirect(url_for('administrator.dashboard')) - else: - g.errors['items'].append('Invalid login. Please try again.') - g.errors['total'] += 1 + # save user data to session + session['admin_id'] = str(user_id) + session['admin_email'] = admin_email + session['admin_password'] = admin_password + + # redirect to rules list + return redirect(url_for('administrator.dashboard')) + else: + flah('Invalid login. Please try again.') + return redirect('administrator.login') return render_template('administrator/login.html') @@ -83,7 +81,10 @@ def dashboard(): 'payments': models.UsersBalanceTransactions.select().count(), } # - return render_template('administrator/dashboard.html', stats=stats) + return render_template( + 'administrator/dashboard.html', + stats=stats + ) @viewAdministrator.route('/users/') @@ -151,7 +152,10 @@ def payments(): 'total': models.UsersBalanceTransactions.select().count(), 'items': models.UsersBalanceTransactions.select() } - return render_template('administrator/payments.html', payments=payments_items) + return render_template( + 'administrator/payments.html', + payments=payments_items + ) @viewAdministrator.route('/datacenters') @@ -210,13 +214,13 @@ def datacenters_edit(dc_id): # POST if request.method == "POST": # todo: ... update record for datacenter - return url_for('administrator.datacenters_edit', dc_id=dc_id) + return redirect(url_for('administrator.datacenters_edit', dc_id=dc_id)) - datacenter = ControllerManageDatacenters().item_get(dc_id) + cmd = ControllerManageDatacenters() return render_template( 'administrator/datacenters_edit.html', - datacenter=datacenter + datacenter=cmd.item_get(dc_id) ) @@ -229,9 +233,10 @@ def servers_index(): if not ControllerAdministrators().auth(session['admin_email'], session['admin_password']): return redirect(url_for("administrator.logout")) # + cms = ControllerManageServer() return render_template( 'administrator/servers/index.html', - servers=ControllerManageServer().items_get() + servers=cms.items_get() ) diff --git a/SWSCloudCore/views/containers/__init__.py b/SWSCloudCore/views/containers/__init__.py index c39a8c6..dfaeed4 100644 --- a/SWSCloudCore/views/containers/__init__.py +++ b/SWSCloudCore/views/containers/__init__.py @@ -1,7 +1,8 @@ # coding: utf-8 import uuid -from flask import Blueprint, g, redirect, render_template, request, session, url_for +from flask import Blueprint, g, redirect, render_template, request, session +from flask import url_for from SWSCloudCore.controllers.billing import ControllerBilling from SWSCloudCore.controllers.common import ControllerCommon @@ -49,94 +50,93 @@ def create(): if request.method == "POST": # check user money if user_balance <= 0: - g.errors['total'] += 1 - g.errors['items'].append(u'No money') + flash(u'Недостаточно средств на аккаунте') + return redirect(url_for('containers.create')) - if g.errors['total'] == 0: - # select server from selected region with available ip-addresses - # select IP - select_ip = ControllerIps().getfree(request.form['datacenter']) - # mark ip as busy (taken) - ControllerIps().setbusy(select_ip.id) - # generate password for container user - password = ControllerCommon().generate_password(size=14) + # select server from selected region with available ip-addresses + # select IP + select_ip = ControllerIps().getfree(request.form['datacenter']) + # mark ip as busy (taken) + ControllerIps().setbusy(select_ip.id) + # generate password for container user + password = ControllerCommon().generate_password(size=14) - new_container = { - 'container_id': str(uuid.uuid4()), - 'datacenter_id': str(select_ip.datacenter.id), - 'server_id': str(select_ip.server.id), - 'ipv4': select_ip.ipv4, - 'ipv6': select_ip.ipv6, - 'ipv4_gateway': select_ip.ipv4_gateway, - 'ipv6_gateway': select_ip.ipv6_gateway, - 'username': 'ubuntu', - 'password': password, - 'ssh_key': None, - } + new_container = { + 'container_id': str(uuid.uuid4()), + 'datacenter_id': str(select_ip.datacenter.id), + 'server_id': str(select_ip.server.id), + 'ipv4': select_ip.ipv4, + 'ipv6': select_ip.ipv6, + 'ipv4_gateway': select_ip.ipv4_gateway, + 'ipv6_gateway': select_ip.ipv6_gateway, + 'username': 'ubuntu', + 'password': password, + 'ssh_key': None, + } - # sshkey - if user_ssh.check(): - new_container['ssh_key'] = user_ssh.get() + # sshkey + if user_ssh.check(): + new_container['ssh_key'] = user_ssh.get() - # create container record in database - # status 4: creation - status = 4 - container_create = ControllerContainers(session['user_id']).create( - new_container['container_id'], + # create container record in database + # status 4: creation + status = 4 + container_create = ControllerContainers(session['user_id']).create( + new_container['container_id'], + new_container['datacenter_id'], + new_container['server_id'], + new_container['ipv4'], + new_container['ipv6'], + status + ) + # create default state data + ControllerContainersStatisticsState().set(new_container['container_id'], dict()) + if container_create: + # create task for create new container + ControllerTasks(session['user_id']).create( new_container['datacenter_id'], new_container['server_id'], - new_container['ipv4'], - new_container['ipv6'], - status + 'container_create', + 0, + container_id=new_container['container_id'], + ipv4=new_container['ipv4'], + ipv6=new_container['ipv6'], + ipv4_gateway=new_container['ipv4_gateway'], + ipv6_gateway=new_container['ipv6_gateway'], + username=new_container['username'], + password=new_container['password'], + ssh_key=new_container['ssh_key'] ) - # create default state data - ControllerContainersStatisticsState().set(new_container['container_id'], dict()) - if container_create: - # create task for create new container - ControllerTasks(session['user_id']).create( - new_container['datacenter_id'], - new_container['server_id'], - 'container_create', - 0, - container_id=new_container['container_id'], - ipv4=new_container['ipv4'], - ipv6=new_container['ipv6'], - ipv4_gateway=new_container['ipv4_gateway'], - ipv6_gateway=new_container['ipv6_gateway'], - username=new_container['username'], - password=new_container['password'], - ssh_key=new_container['ssh_key'] - ) - # send mail message with recovery code - message_parts = [] + # send mail message with recovery code + message_parts = [] - if new_container['ipv4']: - message_parts.append(u"IPv4: %s" % new_container['ipv4']) - if new_container['ipv6']: - message_parts.append(u"IPv6: %s" % new_container['ipv6']) - message_parts.append(u"Пользователь: %s" % new_container['username']) - message_parts.append(u"Пароль: %s" % new_container['password']) - if new_container['ssh_key']: - message_parts.append(u"SSH ключ: добавлен") + if new_container['ipv4']: + message_parts.append(u"IPv4: %s" % new_container['ipv4']) + if new_container['ipv6']: + message_parts.append(u"IPv6: %s" % new_container['ipv6']) + message_parts.append(u"Пользователь: %s" % new_container['username']) + message_parts.append(u"Пароль: %s" % new_container['password']) + if new_container['ssh_key']: + message_parts.append(u"SSH ключ: добавлен") - message = '
\n'.join(message_parts) - subject = u'GoCloud.ru: Новый контейнер' - lead = u"""Поздравляем с новым контейнером.""" - callout = u""" - Для входа в личный кабинет воспользуйтесь - страницей авторизации. - """ + message = '
\n'.join(message_parts) + subject = u'GoCloud.ru: Новый контейнер' + lead = u"""Поздравляем с новым контейнером.""" + callout = u""" + Для входа в личный кабинет воспользуйтесь + страницей авторизации. + """ - user_data = ControllerUsers(session['user_id']).get() + user_data = ControllerUsers(session['user_id']).get() - email = ControllerMessagesEmail() - email.send(title=subject, to=user_data.email, lead=lead, message=message, callout=callout) + email = ControllerMessagesEmail() + email.send(title=subject, to=user_data.email, lead=lead, message=message, callout=callout) - return redirect(url_for('containers.index')) - else: - # mark ip as free - ControllerIps().setfree(select_ip.id) + return redirect(url_for('containers.index')) + else: + # mark ip as free + ControllerIps().setfree(select_ip.id) # Get datacenters list datacenters = ControllerDataCenters().get() # @@ -146,7 +146,7 @@ def create(): ) -@viewContainers.route('/delete/', methods=['GET', 'POST']) +@viewContainers.route('/delete/.html', methods=['GET', 'POST']) def delete(container_id): # check session if not ControllerUsers().check_session(): @@ -176,6 +176,7 @@ def delete(container_id): ) # TODO: send email container was deleted about # Редиректим на страницу со всеми правилами + flash(u'Контейнер был удалён') return redirect(url_for('containers.index')) return render_template( 'default/containers/delete.html', @@ -217,28 +218,30 @@ def settings(container_id): return redirect(url_for('containers.settings', container_id=container_id)) if request.form['status'] == 'active': - balance = models.UsersBalance.select(models.UsersBalance.balance) \ - .where(models.UsersBalance.user == session['user_id'])[0].balance + balance = ControllerBilling().get(session['user_id']) if balance <= 0: - g.errors['items'].append(u'Недостаточно средств на балансе.') - g.errors['total'] += 1 - else: - containers.set_status(container_id, 2) - # Создание задания - ControllerTasks(session['user_id']).create( - container_details.datacenter.id, - container_details.server.id, - 'container_start', - 0, - container_id=container_details.id - ) + flash(u'Недостаточно средств на балансе.') return redirect(url_for('containers.settings', container_id=container_id)) - return render_template('default/containers/settings.html', container=container_details) + containers.set_status(container_id, 2) + # Создание задания + ControllerTasks(session['user_id']).create( + container_details.datacenter.id, + container_details.server.id, + 'container_start', + 0, + container_id=container_details.id + ) + return redirect(url_for('containers.settings', container_id=container_id)) + + return render_template( + 'default/containers/settings.html', + container=container_details + ) -@viewContainers.route('/stats/') +@viewContainers.route('/stats/.html') def stats(container_id): # check session if not ControllerUsers().check_session(): diff --git a/TODO b/TODO new file mode 100644 index 0000000..d77f2a0 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +[ ] Сделать вывод ошибок через flash +[ ] Избавиться от лишних методов в common diff --git a/setup.py b/setup.py index 8ac4062..67bcb92 100644 --- a/setup.py +++ b/setup.py @@ -51,28 +51,52 @@ setup( 'static/js/vendor/*.js', # 'templates/*.html', - 'templates/account/*.html', 'templates/administrator/*.html', - 'templates/administrator/payments/*.html', - 'templates/administrator/plans/*.html', + 'templates/administrator/containers/*.html', + 'templates/administrator/datacenters/*.html', + 'templates/administrator/ips/*.html', + 'templates/administrator/servers/*.html', 'templates/administrator/settings/*.html', + 'templates/administrator/settings/messages/*.html', 'templates/administrator/users/*.html', - 'templates/administrator/zones/*.html', - 'templates/billing/*.html', - 'templates/mail/default/*.html', - 'templates/mail/default/*.css', - 'templates/payment/robokassa/*.html', - 'templates/records/*.html', - 'templates/support/*.html', - 'templates/zones/*.html', + # 'templates/administrator/payments/*.html', + 'templates/administrator/wiki/*.html', + 'templates/administrator/wiki/article/*.html', + 'templates/administrator/wiki/category/*.html', + 'templates/default/*.html', + 'templates/default/containers/*.html', + 'templates/default/documents/*.html', + 'templates/default/homepage/*.html', + 'templates/default/id/*.html', + 'templates/default/kb/*.html', + 'templates/default/payment/*.html', + 'templates/default/support/*.html', + 'templates/default/tasks/*.html', + 'templates/email/simple/*.html', + 'templates/errors/*.html', ] }, scripts=[ - 'swscloud-db-init.py', - 'swscloud-runserver.py', + 'exec/swscloud-db-init.py', + 'exec/swscloud-settings-init.py', + 'exec/swscloud-runserver.py', + # accounts + 'exec/swscloud-admin-add.py', + # TODO: make it + # 'exec/swscloud-admin-delete.py', + 'exec/swscloud-admin-ls.py', + 'exec/swscloud-admin-passwd.py', + # datacenters + 'exec/swscloud-dc-add.py', + 'exec/swscloud-dc-ls.py', + # servers + 'exec/swscloud-server-add.py', + 'exec/swscloud-server-ls.py', ], install_requires=[ 'Flask==0.10.1', + 'Flask-Markdown==0.3', + 'Flask-Babel==0.9' 'flask-peewee==0.6.7', 'Jinja2==2.8', 'peewee==2.8.0', @@ -81,5 +105,9 @@ setup( 'configparser', 'uwsgi==2.0.12', 'flask_httpauth', + 'requests==2.7.0', + 'uWSGI==2.0.11.1', + 'wsgiref==0.1.2', + 'sshpubkeys' ] )