Skip to content

Commit 1f962c5

Browse files
committed
first commit
Signed-off-by: Choonho Son <[email protected]>
0 parents  commit 1f962c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3452
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PyEngine

bin/create_root.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Root ID
5+
ROOT_USER = 'admin'
6+
7+
import os, sys
8+
import django
9+
10+
path = os.path.abspath(__file__ + '/../..')
11+
if path not in sys.path:
12+
sys.path.append(path)
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyengine.settings")
15+
django.setup()
16+
17+
from django.contrib.auth.hashers import make_password
18+
from pyengine.lib.locator import Locator
19+
from pyengine.lib import config
20+
21+
GLOBAL_CONF = config.getGlobalConfig()
22+
23+
locator = Locator()
24+
user_dao = locator.getDAO('user')
25+
26+
def deleteRootUser():
27+
users = user_dao.getVOfromKey(user_id=ROOT_USER)
28+
users.delete()
29+
30+
def createRootUser(password):
31+
dic = {}
32+
dic['user_id'] = ROOT_USER
33+
dic['password'] = make_password(password)
34+
dic['language'] = GLOBAL_CONF['DEFAULT_LANGUAGE']
35+
dic['timezone'] = GLOBAL_CONF['DEFAULT_TIMEZONE']
36+
37+
user_dao.insert(dic)
38+
39+
if __name__ == '__main__':
40+
if len(sys.argv) != 2:
41+
print
42+
print "Usage: ./create_root.py <password>"
43+
print
44+
exit(1)
45+
else:
46+
password = sys.argv[1]
47+
48+
deleteRootUser()
49+
50+
createRootUser(password)
51+
52+
print
53+
print "Success : Create a '%s' user" %(ROOT_USER)
54+
print
55+
exit(0)

bin/generate_rsa.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import rsa
5+
import os, sys
6+
7+
path = os.path.abspath(__file__ + '/../..')
8+
if path not in sys.path:
9+
sys.path.append(path)
10+
11+
from identity import settings
12+
13+
def createKey():
14+
(pubkey, prikey) = rsa.newkeys(1024)
15+
16+
f = open(settings.PUB_KEY_PATH,'w')
17+
pubkey_str = rsa.PublicKey.save_pkcs1(pubkey)
18+
f.write(pubkey_str)
19+
f.close()
20+
21+
f = open(settings.PRI_KEY_PATH,'w')
22+
prikey_str = rsa.PrivateKey.save_pkcs1(prikey)
23+
f.write(prikey_str)
24+
f.close()
25+
26+
27+
if __name__ == '__main__':
28+
createKey()

bin/load_rsa.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import rsa
5+
import os, sys
6+
7+
path = os.path.abspath(__file__ + '/../..')
8+
if path not in sys.path:
9+
sys.path.append(path)
10+
11+
from identity import settings
12+
13+
def loadKey():
14+
f = open(settings.PUB_KEY_PATH, 'r')
15+
pubkey_str = f.read()
16+
f.close()
17+
18+
pubkey = rsa.PublicKey.load_pkcs1(pubkey_str)
19+
print pubkey
20+
21+
f = open(settings.PRI_KEY_PATH, 'r')
22+
prikey_str = f.read()
23+
f.close()
24+
25+
prikey = rsa.PrivateKey.load_pkcs1(prikey_str)
26+
print prikey
27+
28+
29+
if __name__ == '__main__':
30+
loadKey()

docs/INSTALL.md

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Pyengine
2+
3+
## Intall OpenVPN package(Recommended)
4+
5+
You can install OpenVPN automatically, using jeju -m openvpn.md
6+
7+
## Prerequisite
8+
9+
Keyword | Value | Description
10+
---- | ---- | ----
11+
PROJECT | pyengine-openvpn | Project name
12+
13+
# Installation
14+
15+
## Install libraries
16+
17+
Pyengine is based on apache and python django framework
18+
19+
~~~bash
20+
apt-get update
21+
export DEBIAN_FRONTEND=noninteractive
22+
apt-get install -y git python-dev python-pip mariadb-server apache2 libapache2-mod-wsgi python-mysqldb libyaml-cpp-dev libyaml-dev
23+
~~~
24+
25+
## Install PIP libraries for django
26+
27+
~~~bash
28+
pip install django
29+
pip install django-log-request-id
30+
pip install dicttoxml
31+
pip install xmltodict
32+
pip install routes
33+
pip install rsa
34+
pip install pytz
35+
pip install pyyaml
36+
pip install django-cors-headers
37+
~~~
38+
39+
## Download source
40+
41+
Download pyengine source
42+
43+
~~~bash
44+
cd /opt/
45+
git clone https://github.com/pyengine/pyengine.git ${PROJECT}
46+
~~~
47+
48+
## Update python module path environment
49+
50+
edit /usr/local/lib/python2.7/site-packages/pyengine.pth
51+
52+
~~~text
53+
/opt/${PROJECT}
54+
~~~
55+
56+
# Update Configuration
57+
58+
## Update Apache configuration
59+
60+
edit /etc/apache2/sites-available/pyengine.conf
61+
62+
~~~text
63+
<VirtualHost *:80>
64+
Alias /dashboard /opt/${PROJECT}/dashboard
65+
<Directory /opt/${PROJECT}/dashboard>
66+
Require all granted
67+
</Directory>
68+
69+
Alias /static /opt/${PROJECT}/static
70+
<Directory /opt/${PROJECT}/static>
71+
Require all granted
72+
</Directory>
73+
74+
WSGIScriptAlias / /opt/${PROJECT}/pyengine/wsgi.py
75+
WSGIPassAuthorization On
76+
77+
<Directory /opt/${PROJECT}/pyengine>
78+
<Files wsgi.py>
79+
Require all granted
80+
</Files>
81+
</Directory>
82+
83+
AddDefaultCharset UTF-8
84+
</VirtualHost>
85+
~~~
86+
87+
Enable the pyengine
88+
89+
~~~bash
90+
a2dissite default
91+
a2ensite pyengine
92+
~~~
93+
94+
# Create Database
95+
96+
Create pyengine database
97+
98+
~~~expect
99+
spawn mysql -u root -e "create database pyengine character set utf8 collate utf8_general_ci"
100+
expect "Enter password: "
101+
send "\n";
102+
interact
103+
~~~
104+
105+
## Update global.conf
106+
107+
edit /var/pyengine-openvpn/pyengine/conf/global.conf
108+
109+
~~~text
110+
GLOBAL:
111+
# Auth Settings
112+
# API Auth Type : noauth | xauth
113+
AUTH_TYPE: xauth
114+
AUTH_HOST: localhost
115+
AUTH_URL: '/api/v1/token/auth'
116+
117+
NO_AUTH_MODULES:
118+
- token
119+
120+
SYSTEM_KEY: 816801afffe508cf99cb
121+
SYSTEM_AUTH_MODULES:
122+
- system
123+
124+
# Default Settings
125+
DEFAULT_LANGUAGE: ko
126+
DEFAULT_TIMEZONE: Asia/Seoul
127+
DEFAULT_JOB_TIMEOUT: 1800
128+
TOKEN_EXPIRE_TIME: 86400
129+
DATETIME_FIELDS:
130+
- created
131+
- last_update
132+
- finished
133+
- deleted
134+
SERVER_ADDRESS: ${IP}
135+
~~~
136+
137+
## Update django DB
138+
139+
~~~bash
140+
mkdir /var/log/pyengine
141+
chown -R www-data:www-data /var/log/pyengine
142+
143+
cd /opt/${PROJECT}
144+
python manage.py makemigrations
145+
python manage.py migrate
146+
~~~
147+
148+
## Update OpenVPN script
149+
150+
edit /etc/openvpn/easy-rsa/pyengine-build.key.sh
151+
152+
~~~text
153+
#! /bin/bash
154+
155+
cd /etc/openvpn/easy-rsa
156+
source ./vars
157+
158+
export KEY_EMAIL=$2
159+
export KEY_OU=$3
160+
161+
./build-key --batch $1
162+
~~~
163+
164+
update permission
165+
166+
~~~bash
167+
chmod 755 /etc/openvpn/easy-rsa/pyengine-build-key.sh
168+
echo "www-data ALL=(/etc/openvpn/easy-rsa/pyengine-build-key.sh) NOPASSWD: ALL" > /etc/sudoers
169+
~~~
170+
171+
## Update static directory for key save
172+
173+
~~~bash
174+
mkdir /opt/${REPO}/static/keys
175+
chown -R www-data:www-data /opt/${REPO}/static/keys
176+
# Restart Apache
177+
178+
~~~bash
179+
service apache2 restart
180+
~~~
181+
182+

0 commit comments

Comments
 (0)