diff --git a/main/__init__.py b/example/example/__init__.py similarity index 100% rename from main/__init__.py rename to example/example/__init__.py diff --git a/example/example/settings.py b/example/example/settings.py new file mode 100644 index 0000000..de5a709 --- /dev/null +++ b/example/example/settings.py @@ -0,0 +1,135 @@ +""" +Django settings for pydash 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/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +# SITE_ID = 1 + +# 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 = '1)$crmowu-23tz@i2-d=7tb3t+1u&(pm!lnjyuarki^72h!3af' +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +TEMPLATE_DEBUG = True + +ADMINS = ( +) + +MANAGERS = ADMINS + + +ALLOWED_HOSTS = ['*'] + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + # Add pydash here + 'pydash' +) + +MIDDLEWARE_CLASSES = ( + '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', +) + +ROOT_URLCONF = 'example.urls' + +WSGI_APPLICATION = 'example.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.6/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') + } +} + +# Internationalization +# https://docs.djangoproject.com/en/1.6/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + # 'django.template.loaders.eggs.Loader', +) + +TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.6/howto/static-files/ + +STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static') +STATIC_URL = '/static/' + +STATICFILES_DIRS = ( +) + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + #'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'filters': ['require_debug_false'], + 'class': 'django.utils.log.AdminEmailHandler' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + } +} + +try: + from local_settings import * +except ImportError: + pass diff --git a/example/example/urls.py b/example/example/urls.py new file mode 100644 index 0000000..a808d4b --- /dev/null +++ b/example/example/urls.py @@ -0,0 +1,4 @@ +from django.conf.urls import patterns, include, url + +urlpatterns = patterns('', + url(r'^pydash/', include('pydash.urls'))) diff --git a/pydash/wsgi.py b/example/example/wsgi.py similarity index 74% rename from pydash/wsgi.py rename to example/example/wsgi.py index accaf0c..2cc360a 100644 --- a/pydash/wsgi.py +++ b/example/example/wsgi.py @@ -1,5 +1,5 @@ """ -WSGI config for pydash project. +WSGI config for example project. It exposes the WSGI callable as a module-level variable named ``application``. @@ -8,7 +8,7 @@ https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ """ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pydash.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() diff --git a/manage.py b/example/manage.py old mode 100755 new mode 100644 similarity index 71% rename from manage.py rename to example/manage.py index 889180b..2605e37 --- a/manage.py +++ b/example/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pydash.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") from django.core.management import execute_from_command_line diff --git a/example/pydash b/example/pydash new file mode 120000 index 0000000..37111fb --- /dev/null +++ b/example/pydash @@ -0,0 +1 @@ +../pydash \ No newline at end of file diff --git a/main/views.py b/pydash/services.py old mode 100755 new mode 100644 similarity index 65% rename from main/views.py rename to pydash/services.py index 0d8150f..8eb1c2d --- a/main/views.py +++ b/pydash/services.py @@ -1,52 +1,8 @@ -# The MIT License (MIT) -# -# Copyright (c) 2014 Florian Neagu - michaelneagu@gmail.com - https://github.com/k3oni/ -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -import platform import os +import platform import multiprocessing from datetime import timedelta -from django.contrib.auth.decorators import login_required -from django.shortcuts import render_to_response -from django.http import HttpResponseRedirect -from django.template import RequestContext - -from pydash.settings import TIME_JS_REFRESH, TIME_JS_REFRESH_LONG, TIME_JS_REFRESH_NET, VERSION - -time_refresh = TIME_JS_REFRESH -time_refresh_long = TIME_JS_REFRESH_LONG -time_refresh_net = TIME_JS_REFRESH_NET -version = VERSION - - -@login_required(login_url='/login/') -def index(request): - """ - - Index page. - - """ - return HttpResponseRedirect('/main') - def chunks(get, n): return [get[i:i + n] for i in range(0, len(get), n)] @@ -80,7 +36,8 @@ def get_ipaddress(): del iface[0] for i in iface: - pipe = os.popen("ip addr show " + i + "| awk '{if ($2 == \"forever\"){!$2} else {print $2}}'") + pipe = os.popen( + "ip addr show " + i + "| awk '{if ($2 == \"forever\"){!$2} else {print $2}}'") data1 = pipe.read().strip().split('\n') pipe.close() if len(data1) == 2: @@ -149,12 +106,14 @@ def get_traffic(request): Get the traffic for the specified interface """ try: - pipe = os.popen("cat /proc/net/dev |" + "grep " + request + "| awk '{print $1, $9}'") + pipe = os.popen( + "cat /proc/net/dev |" + "grep " + request + "| awk '{print $1, $9}'") data = pipe.read().strip().split(':', 1)[-1] pipe.close() if not data[0].isdigit(): - pipe = os.popen("cat /proc/net/dev |" + "grep " + request + "| awk '{print $2, $10}'") + pipe = os.popen( + "cat /proc/net/dev |" + "grep " + request + "| awk '{print $2, $10}'") data = pipe.read().strip().split(':', 1)[-1] pipe.close() @@ -197,7 +156,8 @@ def get_disk(): Get disk usage """ try: - pipe = os.popen("df -Ph | " + "grep -v Filesystem | " + "awk '{print $1, $2, $3, $4, $5, $6}'") + pipe = os.popen( + "df -Ph | " + "grep -v Filesystem | " + "awk '{print $1, $2, $3, $4, $5, $6}'") data = pipe.read().strip().split('\n') pipe.close() @@ -214,21 +174,24 @@ def get_disk_rw(): Get the disk reads and writes """ try: - pipe = os.popen("cat /proc/partitions | grep -v 'major' | awk '{print $4}'") + pipe = os.popen( + "cat /proc/partitions | grep -v 'major' | awk '{print $4}'") data = pipe.read().strip().split('\n') pipe.close() rws = [] for i in data: if i.isalpha(): - pipe = os.popen("cat /proc/diskstats | grep -w '" + i + "'|awk '{print $4, $8}'") + pipe = os.popen( + "cat /proc/diskstats | grep -w '" + i + "'|awk '{print $4, $8}'") rw = pipe.read().strip().split() pipe.close() rws.append([i, rw[0], rw[1]]) if not rws: - pipe = os.popen("cat /proc/diskstats | grep -w '" + data[0] + "'|awk '{print $4, $8}'") + pipe = os.popen( + "cat /proc/diskstats | grep -w '" + data[0] + "'|awk '{print $4, $8}'") rw = pipe.read().strip().split() pipe.close() @@ -247,7 +210,8 @@ def get_mem(): Get memory usage """ try: - pipe = os.popen("free -tmo | " + "grep 'Mem' | " + "awk '{print $2,$4}'") + pipe = os.popen( + "free -tmo | " + "grep 'Mem' | " + "awk '{print $2,$4}'") data = pipe.read().strip().split() pipe.close() @@ -289,7 +253,8 @@ def get_cpu_usage(): total_free = ((100 * int(get_cpus()['cpus'])) - float(total_usage)) - cpu_used = {'free': total_free, 'used': float(total_usage), 'all': usage} + cpu_used = {'free': total_free, 'used': + float(total_usage), 'all': usage} data = cpu_used @@ -328,11 +293,3 @@ def get_netstat(): data = str(err) return data - - -@login_required(login_url='/login/') -def getall(request): - return render_to_response('main.html', {'time_refresh': time_refresh, - 'time_refresh_long': time_refresh_long, - 'time_refresh_net': time_refresh_net, - 'version': version}, context_instance=RequestContext(request)) diff --git a/pydash/settings.py b/pydash/settings.py index ea5095a..976fba9 100644 --- a/pydash/settings.py +++ b/pydash/settings.py @@ -1,143 +1,8 @@ -""" -Django settings for pydash 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/ -""" - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -import os - -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) - -# SITE_ID = 1 - -# 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 = '1)$crmowu-23tz@i2-d=7tb3t+1u&(pm!lnjyuarki^72h!3af' -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False - -TEMPLATE_DEBUG = False - -ADMINS = ( -) - -MANAGERS = ADMINS - -#All refresh values are in miliseconds, 1 second = 1000 miliseconds -#Adjust accordingly as you wish -TIME_JS_REFRESH = 30000 -TIME_JS_REFRESH_LONG = 120000 -TIME_JS_REFRESH_NET = 2000 - -VERSION = "1.4.4" - -ALLOWED_HOSTS = ['*'] - - -# Application definition - -INSTALLED_APPS = ( - #'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - #'django.contrib.sites', - 'django.contrib.staticfiles', -) - -MIDDLEWARE_CLASSES = ( - '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', -) - -ROOT_URLCONF = 'pydash.urls' - -WSGI_APPLICATION = 'pydash.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.6/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3') - } -} - -# Internationalization -# https://docs.djangoproject.com/en/1.6/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - # 'django.template.loaders.eggs.Loader', -) - -TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.6/howto/static-files/ - -STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static') -STATIC_URL = '/static/' - -STATICFILES_DIRS = ( -) - -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - #'django.contrib.staticfiles.finders.DefaultStorageFinder', -) - -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - } - }, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} - -try: - from local_settings import * -except ImportError: - pass +from django.conf import settings + +# All of the refresh values are in miliseconds, 1 second = 1000 miliseconds +# Adjust accordingly as you wish, preferably in your application's settings.py. +TIME_JS_REFRESH = getattr(settings, 'TIME_JS_REFRESH', 30000) +TIME_JS_REFRESH_LONG = getattr(settings, 'TIME_JS_REFRESH_LONG', 120000) +TIME_JS_REFRESH_NET = getattr(settings, 'TIME_JS_REFRESH_NET', 2000) +_VERSION = '1.4.4' diff --git a/static/css/bootstrap-responsive.min.css b/pydash/static/css/bootstrap-responsive.min.css similarity index 100% rename from static/css/bootstrap-responsive.min.css rename to pydash/static/css/bootstrap-responsive.min.css diff --git a/static/css/bootstrap.min.css b/pydash/static/css/bootstrap.min.css similarity index 100% rename from static/css/bootstrap.min.css rename to pydash/static/css/bootstrap.min.css diff --git a/static/css/dashboard.css b/pydash/static/css/dashboard.css similarity index 100% rename from static/css/dashboard.css rename to pydash/static/css/dashboard.css diff --git a/static/css/font-awesome.css b/pydash/static/css/font-awesome.css similarity index 100% rename from static/css/font-awesome.css rename to pydash/static/css/font-awesome.css diff --git a/static/css/fonts.css b/pydash/static/css/fonts.css similarity index 100% rename from static/css/fonts.css rename to pydash/static/css/fonts.css diff --git a/static/css/signin.css b/pydash/static/css/signin.css similarity index 100% rename from static/css/signin.css rename to pydash/static/css/signin.css diff --git a/static/css/style.css b/pydash/static/css/style.css similarity index 100% rename from static/css/style.css rename to pydash/static/css/style.css diff --git a/static/fonts/MTP_ySUJH_bn48VBG8sNSnhCUOGz7vYGh680lGh-uXM.woff b/pydash/static/fonts/MTP_ySUJH_bn48VBG8sNSnhCUOGz7vYGh680lGh-uXM.woff similarity index 100% rename from static/fonts/MTP_ySUJH_bn48VBG8sNSnhCUOGz7vYGh680lGh-uXM.woff rename to pydash/static/fonts/MTP_ySUJH_bn48VBG8sNSnhCUOGz7vYGh680lGh-uXM.woff diff --git a/static/fonts/MTP_ySUJH_bn48VBG8sNSonF5uFdDttMLvmWuJdhhgs.ttf b/pydash/static/fonts/MTP_ySUJH_bn48VBG8sNSonF5uFdDttMLvmWuJdhhgs.ttf similarity index 100% rename from static/fonts/MTP_ySUJH_bn48VBG8sNSonF5uFdDttMLvmWuJdhhgs.ttf rename to pydash/static/fonts/MTP_ySUJH_bn48VBG8sNSonF5uFdDttMLvmWuJdhhgs.ttf diff --git a/static/fonts/PRmiXeptR36kaC0GEAetxi8cqLH4MEiSE0ROcU-qHOA.ttf b/pydash/static/fonts/PRmiXeptR36kaC0GEAetxi8cqLH4MEiSE0ROcU-qHOA.ttf similarity index 100% rename from static/fonts/PRmiXeptR36kaC0GEAetxi8cqLH4MEiSE0ROcU-qHOA.ttf rename to pydash/static/fonts/PRmiXeptR36kaC0GEAetxi8cqLH4MEiSE0ROcU-qHOA.ttf diff --git a/static/fonts/PRmiXeptR36kaC0GEAetxn5HxGBcBvicCpTp6spHfNo.woff b/pydash/static/fonts/PRmiXeptR36kaC0GEAetxn5HxGBcBvicCpTp6spHfNo.woff similarity index 100% rename from static/fonts/PRmiXeptR36kaC0GEAetxn5HxGBcBvicCpTp6spHfNo.woff rename to pydash/static/fonts/PRmiXeptR36kaC0GEAetxn5HxGBcBvicCpTp6spHfNo.woff diff --git a/static/fonts/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff b/pydash/static/fonts/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff similarity index 100% rename from static/fonts/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff rename to pydash/static/fonts/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff diff --git a/static/fonts/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf b/pydash/static/fonts/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf similarity index 100% rename from static/fonts/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf rename to pydash/static/fonts/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf diff --git a/static/fonts/fontawesome-webfont.eot b/pydash/static/fonts/fontawesome-webfont.eot similarity index 100% rename from static/fonts/fontawesome-webfont.eot rename to pydash/static/fonts/fontawesome-webfont.eot diff --git a/static/fonts/fontawesome-webfont.svg b/pydash/static/fonts/fontawesome-webfont.svg similarity index 100% rename from static/fonts/fontawesome-webfont.svg rename to pydash/static/fonts/fontawesome-webfont.svg diff --git a/static/fonts/fontawesome-webfont.ttf b/pydash/static/fonts/fontawesome-webfont.ttf similarity index 100% rename from static/fonts/fontawesome-webfont.ttf rename to pydash/static/fonts/fontawesome-webfont.ttf diff --git a/static/fonts/fontawesome-webfont.woff b/pydash/static/fonts/fontawesome-webfont.woff similarity index 100% rename from static/fonts/fontawesome-webfont.woff rename to pydash/static/fonts/fontawesome-webfont.woff diff --git a/static/fonts/glyphicons-halflings-regular.eot b/pydash/static/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from static/fonts/glyphicons-halflings-regular.eot rename to pydash/static/fonts/glyphicons-halflings-regular.eot diff --git a/static/fonts/glyphicons-halflings-regular.svg b/pydash/static/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from static/fonts/glyphicons-halflings-regular.svg rename to pydash/static/fonts/glyphicons-halflings-regular.svg diff --git a/static/fonts/glyphicons-halflings-regular.ttf b/pydash/static/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from static/fonts/glyphicons-halflings-regular.ttf rename to pydash/static/fonts/glyphicons-halflings-regular.ttf diff --git a/static/fonts/glyphicons-halflings-regular.woff b/pydash/static/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from static/fonts/glyphicons-halflings-regular.woff rename to pydash/static/fonts/glyphicons-halflings-regular.woff diff --git a/static/fonts/xjAJXh38I15wypJXxuGMBobN6UDyHWBl620a-IRfuBk.woff b/pydash/static/fonts/xjAJXh38I15wypJXxuGMBobN6UDyHWBl620a-IRfuBk.woff similarity index 100% rename from static/fonts/xjAJXh38I15wypJXxuGMBobN6UDyHWBl620a-IRfuBk.woff rename to pydash/static/fonts/xjAJXh38I15wypJXxuGMBobN6UDyHWBl620a-IRfuBk.woff diff --git a/static/fonts/xjAJXh38I15wypJXxuGMBp0EAVxt0G0biEntp43Qt6E.ttf b/pydash/static/fonts/xjAJXh38I15wypJXxuGMBp0EAVxt0G0biEntp43Qt6E.ttf similarity index 100% rename from static/fonts/xjAJXh38I15wypJXxuGMBp0EAVxt0G0biEntp43Qt6E.ttf rename to pydash/static/fonts/xjAJXh38I15wypJXxuGMBp0EAVxt0G0biEntp43Qt6E.ttf diff --git a/static/img/asc.gif b/pydash/static/img/asc.gif similarity index 100% rename from static/img/asc.gif rename to pydash/static/img/asc.gif diff --git a/static/img/bg.gif b/pydash/static/img/bg.gif similarity index 100% rename from static/img/bg.gif rename to pydash/static/img/bg.gif diff --git a/static/img/desc.gif b/pydash/static/img/desc.gif similarity index 100% rename from static/img/desc.gif rename to pydash/static/img/desc.gif diff --git a/static/img/favicon.ico b/pydash/static/img/favicon.ico similarity index 100% rename from static/img/favicon.ico rename to pydash/static/img/favicon.ico diff --git a/static/img/icons-sa7c41345d9.png b/pydash/static/img/icons-sa7c41345d9.png similarity index 100% rename from static/img/icons-sa7c41345d9.png rename to pydash/static/img/icons-sa7c41345d9.png diff --git a/static/js/Chart.min.js b/pydash/static/js/Chart.min.js similarity index 100% rename from static/js/Chart.min.js rename to pydash/static/js/Chart.min.js diff --git a/static/js/base.js b/pydash/static/js/base.js similarity index 100% rename from static/js/base.js rename to pydash/static/js/base.js diff --git a/static/js/bootstrap-multiselect.js b/pydash/static/js/bootstrap-multiselect.js similarity index 100% rename from static/js/bootstrap-multiselect.js rename to pydash/static/js/bootstrap-multiselect.js diff --git a/static/js/bootstrap.js b/pydash/static/js/bootstrap.js similarity index 100% rename from static/js/bootstrap.js rename to pydash/static/js/bootstrap.js diff --git a/static/js/bootstrap.min.js b/pydash/static/js/bootstrap.min.js similarity index 100% rename from static/js/bootstrap.min.js rename to pydash/static/js/bootstrap.min.js diff --git a/static/js/dashboard.js b/pydash/static/js/dashboard.js similarity index 91% rename from static/js/dashboard.js rename to pydash/static/js/dashboard.js index e7548f2..8ffd682 100644 --- a/static/js/dashboard.js +++ b/pydash/static/js/dashboard.js @@ -100,31 +100,31 @@ function get_os_data(url, element) { var dashboard = {}; dashboard.getUptime = function () { - get_os_data('/info/uptime/', "#get-uptime"); + get_os_data(pydashUrls['uptime'], "#get-uptime"); }; dashboard.getOSname = function () { - get_os_data('/info/platform/osname/', "#get-osname"); + get_os_data( pydashUrls['platform'] + 'osname/', "#get-osname"); }; dashboard.getHostname = function () { - get_os_data('/info/platform/hostname/', "#get-hostname"); + get_os_data( pydashUrls['platform'] + 'hostname/', "#get-hostname"); }; dashboard.getKernel = function () { - get_os_data('/info/platform/kernel/', "#get-kernel"); + get_os_data( pydashUrls['platform'] + 'kernel/', "#get-kernel"); }; dashboard.getCPUcount = function () { - get_os_data('/info/getcpus/count/', "#get-cpucount"); + get_os_data( pydashUrls['getcpus'] + 'count/', "#get-cpucount"); }; dashboard.getCPUtype = function () { - get_os_data('/info/getcpus/type/', "#get-cputype"); + get_os_data( pydashUrls['getcpus'] + 'type/', "#get-cputype"); }; dashboard.getDisk = function () { - $.getJSON('/info/getdisk/', function (data) { + $.getJSON( pydashUrls['getdisk'], function (data) { destroy_dataTable("get_disk"); var $filterPs = $("#filter-ps"); $filterPs.val("").off("keyup"); @@ -151,7 +151,7 @@ dashboard.getDisk = function () { }; dashboard.getUsers = function () { - $.getJSON('/info/getusers/', function (data) { + $.getJSON( pydashUrls['getusers'], function (data) { destroy_dataTable("get_users"); var $filterPs = $("#filter-ps"); $filterPs.val("").off("keyup"); @@ -179,7 +179,7 @@ dashboard.getUsers = function () { }; dashboard.getNetstat = function () { - $.getJSON('/info/getnetstat/', function (data) { + $.getJSON( pydashUrls['getnetstat'], function (data) { destroy_dataTable("get_netstat"); var $filterPs = $("#filter-ps"); $filterPs.val("").off("keyup"); @@ -205,7 +205,7 @@ dashboard.getNetstat = function () { }; dashboard.getProc = function () { - $.getJSON('/info/proc/', function (data) { + $.getJSON( pydashUrls['getproc'], function (data) { destroy_dataTable("get_proc"); var $filterPs = $("#filter-ps"); $filterPs.val("").off("keyup"); @@ -238,7 +238,7 @@ dashboard.getProc = function () { }; dashboard.getIps = function () { - $.getJSON('/info/getips/', function (data) { + $.getJSON( pydashUrls['getips'], function (data) { destroy_dataTable("get_ips"); var $filterPs = $("#filter-ps"); $filterPs.val("").off("keyup"); diff --git a/static/js/excanvas.js b/pydash/static/js/excanvas.js similarity index 100% rename from static/js/excanvas.js rename to pydash/static/js/excanvas.js diff --git a/static/js/jquery.dataTables.min.js b/pydash/static/js/jquery.dataTables.min.js similarity index 100% rename from static/js/jquery.dataTables.min.js rename to pydash/static/js/jquery.dataTables.min.js diff --git a/static/js/jquery.js b/pydash/static/js/jquery.js similarity index 100% rename from static/js/jquery.js rename to pydash/static/js/jquery.js diff --git a/templates/base_auth.html b/pydash/templates/base_auth.html similarity index 100% rename from templates/base_auth.html rename to pydash/templates/base_auth.html diff --git a/templates/login.html b/pydash/templates/login.html similarity index 90% rename from templates/login.html rename to pydash/templates/login.html index 453ebd3..738207e 100644 --- a/templates/login.html +++ b/pydash/templates/login.html @@ -13,7 +13,7 @@

{% trans "Sign In" %}

-
+
{% endblock %} diff --git a/templates/logout.html b/pydash/templates/logout.html similarity index 100% rename from templates/logout.html rename to pydash/templates/logout.html diff --git a/templates/main.html b/pydash/templates/main.html similarity index 94% rename from templates/main.html rename to pydash/templates/main.html index 89797ca..be893cb 100644 --- a/templates/main.html +++ b/pydash/templates/main.html @@ -14,9 +14,18 @@ {% block style %}{% endblock %} + + +
-
+
{% block content %} - +
- +
@@ -83,7 +92,7 @@
- +
@@ -104,7 +113,7 @@
- +
@@ -122,12 +131,12 @@
- +
- +
- +
@@ -164,8 +173,8 @@
- - + +
@@ -184,7 +193,7 @@
- +
@@ -201,12 +210,12 @@ {% trans "Out" %}
- +
- +
@@ -293,23 +302,23 @@
-
- +
+ - + {% endblock %} @@ -328,7 +337,7 @@ var mem_ctx = $("#memoryChart").get(0).getContext("2d"); var memChart = new Chart(mem_ctx); function memory_usage(){ - $.getJSON('/info/memory/', function(data) { + $.getJSON(pydashUrls['memusage'], function(data) { var options = { animation : false, pointDotRadius : 2, @@ -341,7 +350,7 @@ var mem_ctx = $("#memoryChart").get(0).getContext("2d"); var cpu_ctx = $("#cpuuChart").get(0).getContext("2d"); var cpuChart = new Chart(cpu_ctx); function cpuu_usage(){ - $.getJSON('/info/cpuusage/', function(data) { + $.getJSON(pydashUrls['cpuusage'], function(data) { var options = { percentageInnerCutout : 50, segmentStrokeWidth : 0 @@ -353,7 +362,7 @@ var cpu_ctx = $("#cpuuChart").get(0).getContext("2d"); var trf_ctx = $("#trfChart").get(0).getContext("2d"); var trfChart = new Chart(trf_ctx); function traffic_usage(){ - $.getJSON('/info/gettraffic/', function(data) { + $.getJSON(pydashUrls['gettraffic'], function(data) { var options = { animation : false, pointDotRadius : 2, @@ -362,11 +371,11 @@ var trf_ctx = $("#trfChart").get(0).getContext("2d"); trfChart.Line(data, options); }); } - + var dsk_ctx = $("#dskChart").get(0).getContext("2d"); var dskChart = new Chart(dsk_ctx); function disk_io(){ - $.getJSON('/info/getdiskio/', function(data) { + $.getJSON(pydashUrls['getdiskio'], function(data) { var options = { animation : false, pointDotRadius : 2, @@ -379,7 +388,7 @@ var dsk_ctx = $("#dskChart").get(0).getContext("2d"); var load_ctx = $("#loadChart").get(0).getContext("2d"); var loadChart = new Chart(load_ctx); function load_average(){ - $.getJSON('/info/loadaverage/', function(data) { + $.getJSON(pydashUrls['getdiskio'], function(data) { var options = { animation : false, pointDotRadius : 2, diff --git a/pydash/urls.py b/pydash/urls.py index 7597e6d..9055c5d 100644 --- a/pydash/urls.py +++ b/pydash/urls.py @@ -1,35 +1,21 @@ from django.conf.urls import patterns, url -from django.conf import settings - -# from django.contrib import admin -# admin.autodiscover() urlpatterns = patterns('', - # Examples: - # url(r'^$', 'pydash.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - - # url(r'^admin/', include(admin.site.urls)), - url(r'^$', 'main.views.index', name='index'), - url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, + url(r'^$', 'pydash.views.index', name='index'), + url(r'login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'), - url(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}, + url(r'logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}, name='logout'), - url(r'^main/$', 'main.views.getall', name='main'), - url(r'^info/uptime/$', 'usage.views.uptime', name='uptime'), - url(r'^info/memory/$', 'usage.views.memusage', name='memusage'), - url(r'^info/cpuusage/$', 'usage.views.cpuusage', name='cpuusage'), - url(r'^info/getdisk/$', 'usage.views.getdisk', name='getdisk'), - url(r'^info/getusers/$', 'usage.views.getusers', name='getusers'), - url(r'^info/getips/$', 'usage.views.getips', name='getips'), - url(r'^info/gettraffic/$', 'usage.views.gettraffic', name='gettraffic'), - url(r'^info/proc/$', 'usage.views.getproc', name='getproc'), - url(r'^info/getdiskio/$', 'usage.views.getdiskio', name='getdiskio'), - url(r'^info/loadaverage/$', 'usage.views.loadaverage', name='loadaverage'), - url(r'^info/platform/([\w\-\.]+)/$', 'usage.views.platform', name='platform'), - url(r'^info/getcpus/([\w\-\.]+)/$', 'usage.views.getcpus', name='getcpus'), - url(r'^info/getnetstat/$', 'usage.views.getnetstat', name='getnetstat')) - -urlpatterns += patterns('', - (r'^static/(?P.*)$', 'django.views.static.serve', - {'document_root': settings.STATIC_ROOT})) + url(r'info/uptime/$', 'pydash.views.uptime', name='uptime'), + url(r'info/memory/$', 'pydash.views.memusage', name='memusage'), + url(r'info/cpuusage/$', 'pydash.views.cpuusage', name='cpuusage'), + url(r'info/getdisk/$', 'pydash.views.getdisk', name='getdisk'), + url(r'info/getusers/$', 'pydash.views.getusers', name='getusers'), + url(r'info/getips/$', 'pydash.views.getips', name='getips'), + url(r'info/gettraffic/$', 'pydash.views.gettraffic', name='gettraffic'), + url(r'info/proc/$', 'pydash.views.getproc', name='getproc'), + url(r'info/getdiskio/$', 'pydash.views.getdiskio', name='getdiskio'), + url(r'info/loadaverage/$', 'pydash.views.loadaverage', name='loadaverage'), + url(r'info/platform/([\w\-\.]+)/$', 'pydash.views.platform', name='platform'), + url(r'info/getcpus/([\w\-\.]+)/$', 'pydash.views.getcpus', name='getcpus'), + url(r'info/getnetstat/$', 'pydash.views.getnetstat', name='getnetstat')) diff --git a/usage/views.py b/pydash/views.py similarity index 82% rename from usage/views.py rename to pydash/views.py index 77e1554..7f6400a 100755 --- a/usage/views.py +++ b/pydash/views.py @@ -19,27 +19,60 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. - import json +from django.contrib.auth.decorators import login_required +from django.shortcuts import render_to_response +from django.core.urlresolvers import reverse, reverse_lazy from django.http import HttpResponse +from django.template import RequestContext + +from settings import (TIME_JS_REFRESH, TIME_JS_REFRESH_LONG, + TIME_JS_REFRESH_NET, _VERSION) +import services +import urls + + +def get_pydash_urls(): + results = dict() + for url_pattern in urls.urlpatterns: + name = url_pattern.name + try: + # Works for non regex patterns + results[name] = reverse(name) + except Exception: + # Get relative url prefix of regex patterns + + # Hacky solution but it works. + # E.g. reverse('platform', args=[0])[:-2] -> /info/platform/ + # reverse('getcpus', args[0])[:-2] -> /info/getcpus/ + results[name] = reverse(name, args=[0])[:-2] + return results -from main.views import * -from pydash.settings import TIME_JS_REFRESH, TIME_JS_REFRESH_LONG, TIME_JS_REFRESH_NET +@login_required(login_url=reverse_lazy('login')) +def index(request): + """ -time_refresh = TIME_JS_REFRESH -time_refresh_long = TIME_JS_REFRESH_LONG -time_refresh_net = TIME_JS_REFRESH_NET + Index page. + + """ + pydash_urls = get_pydash_urls() + return render_to_response('main.html', {'time_refresh': TIME_JS_REFRESH, + 'time_refresh_long': TIME_JS_REFRESH_LONG, + 'time_refresh_net': TIME_JS_REFRESH_NET, + 'version': _VERSION, + 'pydashUrls': pydash_urls}, + context_instance=RequestContext(request)) -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getnetstat(request): """ Return netstat output """ try: - net_stat = get_netstat() + net_stat = services.get_netstat() except Exception: net_stat = None @@ -50,12 +83,12 @@ def getnetstat(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def platform(request, name): """ Return the hostname """ - getplatform = get_platform() + getplatform = services.get_platform() hostname = getplatform['hostname'] osname = getplatform['osname'] kernel = getplatform['kernel'] @@ -87,12 +120,12 @@ def platform(request, name): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getcpus(request, name): """ Return the CPU number and type/model """ - cpus = get_cpus() + cpus = services.get_cpus() cputype = cpus['type'] cpucount = cpus['cpus'] data = {} @@ -116,13 +149,13 @@ def getcpus(request, name): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def uptime(request): """ Return uptime """ try: - up_time = get_uptime() + up_time = services.get_uptime() except Exception: up_time = None @@ -133,13 +166,13 @@ def uptime(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getdisk(request): """ Return the disk usage """ try: - diskusage = get_disk() + diskusage = services.get_disk() except Exception: diskusage = None @@ -150,13 +183,13 @@ def getdisk(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getips(request): """ Return the IPs and interfaces """ try: - get_ips = get_ipaddress() + get_ips = services.get_ipaddress() except Exception: get_ips = None @@ -167,13 +200,13 @@ def getips(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getusers(request): """ Return online users """ try: - online_users = get_users() + online_users = services.get_users() except Exception: online_users = None @@ -184,13 +217,13 @@ def getusers(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getproc(request): """ Return the running processes """ try: - processes = get_cpu_usage() + processes = services.get_cpu_usage() processes = processes['all'] except Exception: processes = None @@ -202,13 +235,13 @@ def getproc(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def cpuusage(request): """ Return CPU Usage in % """ try: - cpu_usage = get_cpu_usage() + cpu_usage = services.get_cpu_usage() except Exception: cpu_usage = 0 @@ -231,7 +264,7 @@ def cpuusage(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def memusage(request): """ Return Memory Usage in % and numeric @@ -240,7 +273,7 @@ def memusage(request): datasets_used = [] try: - mem_usage = get_mem() + mem_usage = services.get_mem() except Exception: mem_usage = 0 @@ -314,7 +347,7 @@ def memusage(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def loadaverage(request): """ Return Load Average numeric @@ -322,7 +355,7 @@ def loadaverage(request): datasets = [] try: - load_average = get_load() + load_average = services.get_load() except Exception: load_average = 0 @@ -374,7 +407,7 @@ def loadaverage(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def gettraffic(request): """ Return the traffic for the interface @@ -386,10 +419,10 @@ def gettraffic(request): label = "KBps" try: - intf = get_ipaddress() + intf = services.get_ipaddress() intf = intf['interface'][0] - traffic = get_traffic(intf) + traffic = services.get_traffic(intf) except Exception: traffic = 0 @@ -442,8 +475,10 @@ def gettraffic(request): datasets_out_o.append(float(traffic['traffic_out'])) del datasets_out_o[0] - dataset_in = (float(((datasets_in_i[1] - datasets_in_i[0]) / 1024) / (time_refresh_net / 1000))) - dataset_out = (float(((datasets_out_o[1] - datasets_out_o[0]) / 1024) / (time_refresh_net / 1000))) + dataset_in = ( + float(((datasets_in_i[1] - datasets_in_i[0]) / 1024) / (TIME_JS_REFRESH_NET / 1000))) + dataset_out = ( + float(((datasets_out_o[1] - datasets_out_o[0]) / 1024) / (TIME_JS_REFRESH_NET / 1000))) if dataset_in > 1024 or dataset_out > 1024: dataset_in = (float(dataset_in / 1024)) @@ -497,7 +532,7 @@ def gettraffic(request): return response -@login_required(login_url='/login/') +@login_required(login_url=reverse_lazy('login')) def getdiskio(request): """ Return the reads and writes for the drive @@ -508,7 +543,7 @@ def getdiskio(request): datasets_out_o = [] try: - diskrw = get_disk_rw() + diskrw = services.get_disk_rw() diskrw = diskrw[0] except Exception: diskrw = 0 @@ -562,8 +597,10 @@ def getdiskio(request): datasets_out_o.append(int(diskrw[2])) del datasets_out_o[0] - dataset_in = (int((datasets_in_i[1] - datasets_in_i[0]) / (time_refresh_net / 1000))) - dataset_out = (int((datasets_out_o[1] - datasets_out_o[0]) / (time_refresh_net / 1000))) + dataset_in = ( + int((datasets_in_i[1] - datasets_in_i[0]) / (TIME_JS_REFRESH_NET / 1000))) + dataset_out = ( + int((datasets_out_o[1] - datasets_out_o[0]) / (TIME_JS_REFRESH_NET / 1000))) if len(datasets_in) <= 9: datasets_in.append(dataset_in) diff --git a/usage/__init__.py b/usage/__init__.py deleted file mode 100644 index e69de29..0000000