diff --git a/CVoipPanel/__init__.py b/CVoipPanel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/CVoipPanel/asgi.py b/CVoipPanel/asgi.py new file mode 100644 index 0000000..2536249 --- /dev/null +++ b/CVoipPanel/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for CVoipPanel project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CVoipPanel.settings') + +application = get_asgi_application() diff --git a/CVoipPanel/settings.py b/CVoipPanel/settings.py new file mode 100644 index 0000000..ca5cd56 --- /dev/null +++ b/CVoipPanel/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for CVoipPanel project. + +Generated by 'django-admin startproject' using Django 5.2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-blrkcfli^=1zwyost^hq_2%ol0igoc@wy8bkt2$hg#+st2$h_z' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'Dashboard', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + '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 = 'CVoipPanel.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'CVoipPanel.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'cvoipdb', + 'USER': 'admin', + 'PASSWORD': 'admin', + 'HOST': 'localhost', + 'PORT': '5432', + } +} + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/CVoipPanel/urls.py b/CVoipPanel/urls.py new file mode 100644 index 0000000..60ded86 --- /dev/null +++ b/CVoipPanel/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for CVoipPanel project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('Dashboard.urls')), +] diff --git a/CVoipPanel/wsgi.py b/CVoipPanel/wsgi.py new file mode 100644 index 0000000..f46a5b8 --- /dev/null +++ b/CVoipPanel/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for CVoipPanel project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CVoipPanel.settings') + +application = get_wsgi_application() diff --git a/Dashboard/__init__.py b/Dashboard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Dashboard/admin.py b/Dashboard/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/Dashboard/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Dashboard/apps.py b/Dashboard/apps.py new file mode 100644 index 0000000..99a3c0a --- /dev/null +++ b/Dashboard/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class DashboardConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'Dashboard' diff --git a/Dashboard/migrations/__init__.py b/Dashboard/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Dashboard/models.py b/Dashboard/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/Dashboard/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Dashboard/tests.py b/Dashboard/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/Dashboard/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Dashboard/urls.py b/Dashboard/urls.py new file mode 100644 index 0000000..4240031 --- /dev/null +++ b/Dashboard/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.login_view, name='login'), + path('dashboard/', views.dashboard, name='dashboard'), + path('add_user/', views.add_user, name='add_user'), + path('edit_user//', views.edit_user, name='edit_user'), + path('delete_user//', views.delete_user, name='delete_user'), + path('logout/', views.logout_view, name='logout'), +] \ No newline at end of file diff --git a/Dashboard/views.py b/Dashboard/views.py new file mode 100644 index 0000000..1931c75 --- /dev/null +++ b/Dashboard/views.py @@ -0,0 +1,67 @@ +from django.shortcuts import render, redirect, get_object_or_404 +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.models import User +from django.contrib.auth.decorators import login_required + +def login_view(request): + if request.method == 'POST': + username = request.POST['username'] + password = request.POST['password'] + user = authenticate(request, username=username, password=password) + + if user is not None and user.is_superuser: + login(request, user) + return redirect('dashboard') + else: + return render(request, 'Dashboard/login.html', {'error': 'Only superusers can log in.' if user is not None else 'Invalid credentials.'}) + return render(request, 'Dashboard/login.html') + +@login_required +def dashboard(request): + users = User.objects.all() + return render(request, 'Dashboard/dashboard.html', {'users': users}) + +@login_required +def add_user(request): + if request.method == 'POST': + username = request.POST['username'] + password = request.POST['password'] + confirm_password = request.POST['confirm_password'] + email = request.POST['email'] + + if password != confirm_password: + return render(request, 'Dashboard/add_user.html', { + 'error': 'Passwords do not match.' + }) + + User.objects.create_user(username=username, password=password, email=email) + return redirect('dashboard') + return render(request, 'Dashboard/add_user.html') + +@login_required +def edit_user(request, user_id): + user = get_object_or_404(User, id=user_id) + if request.method == 'POST': + user.username = request.POST['username'] + user.email = request.POST['email'] + password = request.POST['password'] + confirm_password = request.POST['confirm_password'] + if (password is not None or confirm_password is not None) and (password == confirm_password): + user.set_password(request.POST['password']) + elif (password is not None or confirm_password is not None) and (password != confirm_password): + return render(request, 'Dashboard/edit_user.html', { + 'error': 'Passwords do not match.' + }) + user.save() + return redirect('dashboard') + return render(request, 'Dashboard/edit_user.html', {'user': user}) + +@login_required +def delete_user(request, user_id): + user = get_object_or_404(User, id=user_id) + user.delete() + return redirect('dashboard') + +def logout_view(request): + logout(request) + return redirect('login') diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..52e7ed6 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CVoipPanel.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..75f68ab --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Django==5.2.2 +psycopg-binary==3.2.9 \ No newline at end of file diff --git a/templates/Dashboard/add_user.html b/templates/Dashboard/add_user.html new file mode 100644 index 0000000..f8e72b8 --- /dev/null +++ b/templates/Dashboard/add_user.html @@ -0,0 +1,35 @@ +{% extends "Dashboard/base.html" %} + +{% block content %} +

Add New User

+ +{% if error %} +
+ {{ error }} +
+{% endif %} + +
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + Cancel +
+
+{% endblock %} diff --git a/templates/Dashboard/base.html b/templates/Dashboard/base.html new file mode 100644 index 0000000..1ca7bdb --- /dev/null +++ b/templates/Dashboard/base.html @@ -0,0 +1,29 @@ + + + + + CVoip Panel + + + + + + + + +
+ {% block content %}{% endblock %} +
+ + + + diff --git a/templates/Dashboard/dashboard.html b/templates/Dashboard/dashboard.html new file mode 100644 index 0000000..28ea122 --- /dev/null +++ b/templates/Dashboard/dashboard.html @@ -0,0 +1,36 @@ +{% extends "Dashboard/base.html" %} + +{% block content %} +
+

All Users

+ Add User +
+ + + + + + + + + + + + + {% for user in users %} + + + + + + + + {% endfor %} + +
IDUsernameEmailIs SuperuserActions
{{ user.id }}{{ user.username }}{{ user.email }}{{ user.is_superuser }} + Edit + {% if not user.is_superuser %} + Delete + {% endif %} +
+{% endblock %} diff --git a/templates/Dashboard/edit_user.html b/templates/Dashboard/edit_user.html new file mode 100644 index 0000000..28d3efc --- /dev/null +++ b/templates/Dashboard/edit_user.html @@ -0,0 +1,35 @@ +{% extends "Dashboard/base.html" %} + +{% block content %} +

Edit User: {{ user.username }}

+ +{% if error %} +
+ {{ error }} +
+{% endif %} + +
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + Cancel +
+
+{% endblock %} diff --git a/templates/Dashboard/login.html b/templates/Dashboard/login.html new file mode 100644 index 0000000..e45f094 --- /dev/null +++ b/templates/Dashboard/login.html @@ -0,0 +1,24 @@ +{% extends "Dashboard/base.html" %} + +{% block content %} +
+
+

Login

+ + {% if error %} +
{{ error }}
+ {% endif %} + +
+ {% csrf_token %} +
+ +
+
+ +
+ +
+
+
+{% endblock %}