cvoip-init
This commit is contained in:
parent
75be8512eb
commit
9185d4a564
0
CVoipPanel/__init__.py
Normal file
0
CVoipPanel/__init__.py
Normal file
16
CVoipPanel/asgi.py
Normal file
16
CVoipPanel/asgi.py
Normal file
@ -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()
|
||||
127
CVoipPanel/settings.py
Normal file
127
CVoipPanel/settings.py
Normal file
@ -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'
|
||||
23
CVoipPanel/urls.py
Normal file
23
CVoipPanel/urls.py
Normal file
@ -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')),
|
||||
]
|
||||
16
CVoipPanel/wsgi.py
Normal file
16
CVoipPanel/wsgi.py
Normal file
@ -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()
|
||||
0
Dashboard/__init__.py
Normal file
0
Dashboard/__init__.py
Normal file
3
Dashboard/admin.py
Normal file
3
Dashboard/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
Dashboard/apps.py
Normal file
6
Dashboard/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DashboardConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'Dashboard'
|
||||
0
Dashboard/migrations/__init__.py
Normal file
0
Dashboard/migrations/__init__.py
Normal file
3
Dashboard/models.py
Normal file
3
Dashboard/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
Dashboard/tests.py
Normal file
3
Dashboard/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
11
Dashboard/urls.py
Normal file
11
Dashboard/urls.py
Normal file
@ -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/<int:user_id>/', views.edit_user, name='edit_user'),
|
||||
path('delete_user/<int:user_id>/', views.delete_user, name='delete_user'),
|
||||
path('logout/', views.logout_view, name='logout'),
|
||||
]
|
||||
67
Dashboard/views.py
Normal file
67
Dashboard/views.py
Normal file
@ -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')
|
||||
22
manage.py
Executable file
22
manage.py
Executable file
@ -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()
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Django==5.2.2
|
||||
psycopg-binary==3.2.9
|
||||
35
templates/Dashboard/add_user.html
Normal file
35
templates/Dashboard/add_user.html
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends "Dashboard/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="mb-4">Add New User</h2>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" class="card card-body">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" class="form-control" required value="{{ request.POST.username }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Email</label>
|
||||
<input type="email" name="email" class="form-control" required value="{{ request.POST.email }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Password</label>
|
||||
<input type="password" name="password" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Confirm Password</label>
|
||||
<input type="password" name="confirm_password" class="form-control" required>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<button type="submit" class="btn btn-success me-2">Create User</button>
|
||||
<a href="{% url 'dashboard' %}" class="btn btn-secondary ms-2">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
29
templates/Dashboard/base.html
Normal file
29
templates/Dashboard/base.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CVoip Panel</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Bootstrap 5 CDN -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{% url 'dashboard' %}">CVoip Panel</a>
|
||||
{% if user.is_authenticated %}
|
||||
<div class="ms-auto">
|
||||
<a href="{% url 'logout' %}" class="btn btn-outline-light">Logout</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
36
templates/Dashboard/dashboard.html
Normal file
36
templates/Dashboard/dashboard.html
Normal file
@ -0,0 +1,36 @@
|
||||
{% extends "Dashboard/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2>All Users</h2>
|
||||
<a href="{% url 'add_user' %}" class="btn btn-success">Add User</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Is Superuser</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{ user.id }}</td>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>{{ user.email }}</td>
|
||||
<td>{{ user.is_superuser }}</td>
|
||||
<td>
|
||||
<a href="{% url 'edit_user' user.id %}" class="btn btn-sm btn-primary">Edit</a>
|
||||
{% if not user.is_superuser %}
|
||||
<a href="{% url 'delete_user' user.id %}" class="btn btn-sm btn-danger">Delete</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
35
templates/Dashboard/edit_user.html
Normal file
35
templates/Dashboard/edit_user.html
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends "Dashboard/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="mb-4">Edit User: {{ user.username }}</h2>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" class="card card-body">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" class="form-control" value="{{ user.username }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Email</label>
|
||||
<input type="email" name="email" class="form-control" value="{{ user.email }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>New Password (leave blank to keep current)</label>
|
||||
<input type="password" name="password" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Confirm Password (leave blank to keep current)</label>
|
||||
<input type="password" name="confirm_password" class="form-control">
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<button type="submit" class="btn btn-primary me-2">Update</button>
|
||||
<a href="{% url 'dashboard' %}" class="btn btn-secondary ms-2">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
24
templates/Dashboard/login.html
Normal file
24
templates/Dashboard/login.html
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "Dashboard/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-4">
|
||||
<h3 class="text-center mb-4">Login</h3>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
<input type="text" name="username" class="form-control" placeholder="Username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" name="password" class="form-control" placeholder="Password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Reference in New Issue
Block a user