Repository navigation
Python Src
Contains python scripts for the app.
src/admin.py
Handles admin related page requests and tasks.
| Function | Description |
|---|---|
| class | Defines admin page view (list and detail), layout and field grouping. Seehere. |
| apache(), aws(), ga(), git() | Handles page requests of /admin/apache/, /admin/aws/, /admin/ga/, /admin/git/. |
| apache_stat(), aws_stat(), ga_stat(), git_stat() | Retrieves analytics data through *_stats() in src/console.py. |
| get_sys(), get_ver(), get_backup() | Accesses cache/stat_sys.json, cache/stat_ver.json and cache/stat_backup.json for versions and backup status (capacity, sizes, etc.) text. Neither TXT files are accessible through url. |
| get_arch() | Accesses config/flow_chart.svg for admin only. |
| backup_form() | Get backup related status from cron jobs. |
| backup_now(), upload_now() | Kicks off call_command() for management commands of either backup or gdrive. |
| sys_stat() | Kicks off call_command() for management command of versions with flag 1 to override IS_VERSION in config/bot.conf. |
| ssl_dash() | Returns status of SSL Certificate). |
| backup() | Handles page requests of /admin/backup/ page. Also takes POST request to set configurations. |
| export() | Handles page request of /admin/export/. Also takes POST request to execute publication export to file. |
| dir(), man(), ref(), doc() | Handles page requests of /admin/dir/, /admin/man/, /admin/ref/ and /admin/doc/ for django-filemanager and documentation pages. |
src/console.py
Handles admin analytics console/dashboard data requests and error emails.
| Function | Description |
|---|---|
| send_notify_emails() | Uses smtp email to send messages to admin about error reports. |
| get_backup_stat() | Reads sizes of folders in data/ and sizes of files in backup/, and a list of TGZ files stored in Google Drive. Text information is saved to cache/stat_backup.json. |
| refresh_settings() | Reloads config/*.conf files into current running environment. It writes to settings._wrapped to overwrite current Django app setting. |
| get_sys_crontab(), set_sys_crontab() | GET/SET cron jobs. GET reads from system crontab -l instead of config/cron.conf to reflect the current setting. |
| get_backup_form(), set_backup_form() | GET/SET backup settings. GET reads from system get_sys_crontab(); SET writes to config/cron.conf. |
| restyle_apache() | Parses Apache status page (/server-status/) into a JSON object. Uses urllib2 for credential supply to /server-status/. |
| aws_stats() | Handles /admin/aws/ data query. Uses gviz-api.py and boto. Calls aws_result() through aws_call() for data formatting. qs=init returns JSON, while others return Google Visualization ToJSONResponse() object. Query format: |
qs : Query string; accepts init (table of basic specs on top of page), latency, request, 23xx (HTTP response 2xx and 3xx combined), 45xx (HTTP response 4xx and 5xx combined), host, status, cpu, credit, and volbytes. |
|
sp : Period; accepts 7d (7 days) or 48h (48 hours). |
|
tqx : Required by Google Visualization API. It should has the value like reqId:%d. |
|
| ga_stats() | Handles /admin/ga/ data query. Uses gviz-api.py. Uses requests instead of Google Analytics OAuth API for simplicity. qs=init returns JSON, while others return Google Visualization ToJSONResponse() object. Makes 3 attempts if connection fails. Query format: |
qs : Query string; accepts init (table of number ratings), chart (session plots), pie (categorical pie plots), and geo (world map of visitors). |
|
sp : Period or type; qs=chart accepts 24h, 7d, 1m (1 month), or 3m (3 months), while qs=pie accepts session, user, browser, or pageview. |
|
tqx : Same as in aws_stats(). |
|
git_stats() |
Handles /admin/git/ data query. Uses gviz-api.py and PyGithub. qs=init returns JSON, while others return Google Visualization ToJSONResponse() object. Makes 3 attempts if connection fails. Query format: |
qs : Query string; accepts init (table of contributors data), num (repository statistics, e.g. number of branches), c (commits calendar), ad (addition/deletion timeline), and au (author contribution pie plot). |
|
tqx : Same as in aws_stats(). |
|
| dash_ssl() | Uses openssl to retrieve server SSL Certificate expiration date. |
src/env.py
Handles *.conf files and HTML template path.
| Function | Description |
|---|---|
SYS_PATH |
Collection of HTML template path and data folder path. |
| reload_conf() | Loads config/*.conf files and save as runtime environment variables for the Django app. |
| error400(), error401(), error403(), error404(), error500(), error503() | Handlers for custom HTTP error response pages. Use ?status=false to suppress the HTTP error code (returns 200 instead). |
src/helper.py
Collection of helper functions for src/wrapper_?d.py.
| Function | Description |
|---|---|
| prm_1d, prm_2d, prm_3d |
primerize constructor instances. They are constructed once and shared by src/wrapper_?d.py. |
| is_valid_name(), is_valid_email(), is_t7_present() | Test functions for inputs. |
| random_job_id() | Generates random JOB_ID as 16-digit hexadecimal string. It prevents collision by querying all previous JOB_ID on record. |
| create_res_html(), create_wait_html(), create_err_html() | Writes to HTML result files in data/. create_res_html() is called by the other 2 for file handling. |
src/models.py
Handles MySQL database table schema and in-page form models.
| Function | Description |
|---|---|
models.Model |
Database table schema. See here; contains Design1D, Design2D, Design3D, JobIDs, JobGroups, HistoryItem, and SourceDownloader. |
forms.Form |
Front-end in-page forms. See here. |
Admin site : BackupForm. |
|
Group site : Design1DForm , Design2DForm , Design3DForm , and DownloadForm . |
|
Login : LoginForm, PasswordForm. |
|
| debug_flag(), ga_tracker() | Global context processors to convey DEBUG flag and Google Analytics tracker ID. |
src/settings.py
Handles basic app settings (defined by Django). See here.** Loading order is to avoid import loop.**
-
X_FRAME_OPTIONSis not set toDENYdue to /admin/dir/ uses<iframe>of /admin/browse/.
src/urls.py
Handles url routing (defined by Django). Uses AdminSitePlus to override Admin. See django-adminplus here.
- Routes /site_media/ to
media/, and /site_data/ todata/; to prevent direct access to files from path. - Redirect old and synonym urls to current ones with 301. Exposes custom error handler pages, as well as
robots.txtas /robots.txt. - Based on
IS_MAINTENANCEinconfig/t47_dev.py, the server can run in either normal mode or downtime mode. In downtime mode, all requests are responded with HTTP code 503.
src/user.py
Handles responses for user-related activity. Each handler is routed from src/urls.py, and takes PATH.HTML_PATH to locate HTML templates
| Function | Description |
|---|---|
| user_login(), user_password(), user_logout() | Pages related to account. Only used in test server due to WebAuth. In production, the only user in system is daslab. |
| browse() | django-filemanger view handler, channeled as <iframe> on /admin/dir/. |
src/views.py
Handles responses for non-admin pages. Each handler is routed from src/urls.py, and mostly takes PATH.HTML_PATH to locate HTML templates
| Function | Description |
|---|---|
| ping_test() | Returns an empty 200 response. Used by AWS ELB Health Check. |
| test() | Test handler for test server. Not accessible in production. |
| get_admin(), get_user() | Used by 403 error page only (/error/403/). |
| get_js() | Used by media/js/admin/load.js. Reads cache/stat_ver.json and returns core JS vendor library versions. The versions information is used to load libraries from CDN. |
| get_ver() | Used by / and /docs/ to retrieve current running version primerize. |
src/wsgi.py
Handles uwsgi connections. Do not change, unless syntax changes in newer Django releases. Called by Apache mod_wsgi dispatcher.
New Admin Setup
Admin Responsibility
Server Environment
Overview
Linux
Python