1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
"""
Django settings for sbhs_server project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
import sys #srikant
import socket,json
import sbhs_server.credentials as credentials
hostname = socket.gethostname()
is_production = True
hostname == "vlabs-sbhs"
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = credentials.PROJECT_SECRET_KEY
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = not is_production
TEMPLATE_DEBUG = not is_production
#IPs allowed to host the server
ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
"192.168.43.208",
"192.168.43.144",
"10.42.0.1",
"vlabs.iitb.ac.in",
]
if is_production:
ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
"vlabs.iitb.ac.in",
"vlabs.iitb.ac.in.",
"10.102.152.16",
]
# Application definition
"""
Installed apps
"""
INSTALLED_APPS = (
#'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#'south',
'undelete',
#'yaksh',
'taggit',
#'corsheaders',
'account',
'myadmin',
'experiment',
'pages',
'password',
'slot',
'sbhs_server.tables',
'webcam',
'maintenance',
'django_extensions',
)
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
#'corsheaders.middleware.CorsMiddleware',
)
ROOT_URLCONF = 'sbhs_server.urls'
WSGI_APPLICATION = 'sbhs_server.wsgi.application'
#CORS_ORIGIN_ALLOW_ALL=True
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
if is_production:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': credentials.DB_NAME,
'USER': credentials.DB_USER,
'PASSWORD': credentials.DB_PASS,
'HOST': credentials.DB_HOST,
'PORT': credentials.DB_PORT,
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'sbhs.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = False
AUTH_USER_MODEL = 'tables.Account'
LOGIN_URL = '/sbhs/enter'
LOGOUT_URL = '/sbhs/logout'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True # Browser-length session
CSRF_COOKIE_NAME = "pfesgbxra"
SESSION_COOKIE_NAME = "frffvbaVq"
EMAIL_HOST = 'smtp-auth.iitb.ac.in'
EMAIL_PORT = 25
EMAIL_HOST_USER = credentials.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = credentials.EMAIL_HOST_PASSWORD
ADMIN_EMAIL=credentials.ADMIN_EMAIL
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
if is_production:
BASE_URL = "http://vlabs.iitb.ac.in/sbhs/"
FORCE_SCRIPT_NAME = "/sbhs"
USE_X_FORWARDED_HOST = True
else:
BASE_URL = "http://127.0.0.1/"
SBHSCLIENT_STATIC_DIR = os.path.join(BASE_DIR, "client_static")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
os.path.join(SBHSCLIENT_STATIC_DIR, "zipped"),
)
if is_production:
STATIC_ROOT = os.path.join(BASE_DIR, "production_static_files")
STATIC_URL = 'http://vlabs.iitb.ac.in/sbhs/static/'
else:
STATIC_URL = '/static/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
import warnings
warnings.filterwarnings(
'ignore', r"DateTimeField .* received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
if not is_production:
import logging
l = logging.getLogger('django.db')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db': {
'level': 'DEBUG',
'handlers': ['console'],
},
}
}
else:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'log/django_error.log'),
}
},
'loggers': {
'django.request': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
}
}
}
EXPERIMENT_LOGS_DIR = os.path.join(BASE_DIR, 'experiments')
WEBCAM_DIR = os.path.join(STATIC_ROOT, 'img/webcam/') if is_production else os.path.join(BASE_DIR, 'static/img/webcam/')
WEBCAM_STATIC_DIR = 'img/webcam/'
if not is_production:
SBHS_ADMINS = (
('Rupak Rokade' , '+91-9960447251' , 'rupakrokade@gmail.com'),
('Akash Chavan' , '+91-8007895970' , 'meakashchavan@gmail.com')
)
else:
from sbhs_server.sbhs_admin_config import SBHS_ADMINS
SBHS_GLOBAL_LOG_DIR = os.path.join(BASE_DIR, 'log')
with open(os.path.join(BASE_DIR, "sbhs_server/pi-ip.json"),'r') as fh:
json_data = fh.read()
pi_ip_map = json.loads(json_data)
online_mids = list(pi_ip_map.keys())
print "No of machines online : ", len(online_mids)
import sys
print >>sys.stderr, online_mids[:]
|