Spaces:
Sleeping
Sleeping
Upload 31 files
Browse files- admins/__init__.py +0 -0
- admins/__pycache__/__init__.cpython-310.pyc +0 -0
- admins/__pycache__/__init__.cpython-312.pyc +0 -0
- admins/__pycache__/__init__.cpython-37.pyc +0 -0
- admins/__pycache__/admin.cpython-310.pyc +0 -0
- admins/__pycache__/admin.cpython-312.pyc +0 -0
- admins/__pycache__/admin.cpython-37.pyc +0 -0
- admins/__pycache__/apps.cpython-310.pyc +0 -0
- admins/__pycache__/apps.cpython-312.pyc +0 -0
- admins/__pycache__/apps.cpython-37.pyc +0 -0
- admins/__pycache__/models.cpython-310.pyc +0 -0
- admins/__pycache__/models.cpython-312.pyc +0 -0
- admins/__pycache__/models.cpython-37.pyc +0 -0
- admins/__pycache__/views.cpython-310.pyc +0 -0
- admins/__pycache__/views.cpython-312.pyc +0 -0
- admins/__pycache__/views.cpython-37.pyc +0 -0
- admins/admin.py +3 -0
- admins/apps.py +6 -0
- admins/management/__init__.py +0 -0
- admins/management/__pycache__/__init__.cpython-312.pyc +0 -0
- admins/management/commands/__init__.py +0 -0
- admins/management/commands/__pycache__/__init__.cpython-312.pyc +0 -0
- admins/management/commands/__pycache__/run_telegram_bot.cpython-312.pyc +0 -0
- admins/management/commands/run_telegram_bot.py +188 -0
- admins/migrations/__init__.py +0 -0
- admins/migrations/__pycache__/__init__.cpython-310.pyc +0 -0
- admins/migrations/__pycache__/__init__.cpython-312.pyc +0 -0
- admins/migrations/__pycache__/__init__.cpython-37.pyc +0 -0
- admins/models.py +3 -0
- admins/tests.py +3 -0
- admins/views.py +60 -0
admins/__init__.py
ADDED
|
File without changes
|
admins/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (231 Bytes). View file
|
|
|
admins/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (233 Bytes). View file
|
|
|
admins/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (228 Bytes). View file
|
|
|
admins/__pycache__/admin.cpython-310.pyc
ADDED
|
Binary file (272 Bytes). View file
|
|
|
admins/__pycache__/admin.cpython-312.pyc
ADDED
|
Binary file (277 Bytes). View file
|
|
|
admins/__pycache__/admin.cpython-37.pyc
ADDED
|
Binary file (269 Bytes). View file
|
|
|
admins/__pycache__/apps.cpython-310.pyc
ADDED
|
Binary file (510 Bytes). View file
|
|
|
admins/__pycache__/apps.cpython-312.pyc
ADDED
|
Binary file (539 Bytes). View file
|
|
|
admins/__pycache__/apps.cpython-37.pyc
ADDED
|
Binary file (501 Bytes). View file
|
|
|
admins/__pycache__/models.cpython-310.pyc
ADDED
|
Binary file (269 Bytes). View file
|
|
|
admins/__pycache__/models.cpython-312.pyc
ADDED
|
Binary file (274 Bytes). View file
|
|
|
admins/__pycache__/models.cpython-37.pyc
ADDED
|
Binary file (266 Bytes). View file
|
|
|
admins/__pycache__/views.cpython-310.pyc
ADDED
|
Binary file (1.77 kB). View file
|
|
|
admins/__pycache__/views.cpython-312.pyc
ADDED
|
Binary file (2.71 kB). View file
|
|
|
admins/__pycache__/views.cpython-37.pyc
ADDED
|
Binary file (1.76 kB). View file
|
|
|
admins/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
admins/apps.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class AdminsConfig(AppConfig):
|
| 5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
| 6 |
+
name = 'admins'
|
admins/management/__init__.py
ADDED
|
File without changes
|
admins/management/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (244 Bytes). View file
|
|
|
admins/management/commands/__init__.py
ADDED
|
File without changes
|
admins/management/commands/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (253 Bytes). View file
|
|
|
admins/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import asyncio
|
| 3 |
+
from django.core.management.base import BaseCommand
|
| 4 |
+
from django.conf import settings
|
| 5 |
+
from users.models import UserRegistrationModel
|
| 6 |
+
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup
|
| 7 |
+
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, CallbackQueryHandler, MessageHandler, filters
|
| 8 |
+
from asgiref.sync import sync_to_async
|
| 9 |
+
import webbrowser
|
| 10 |
+
|
| 11 |
+
# Constants
|
| 12 |
+
TOKEN = '8394032591:AAG_9Kitz0j1A00mvD3iBVgWlJe9as6Oix8'
|
| 13 |
+
|
| 14 |
+
# Configure Logging
|
| 15 |
+
logging.basicConfig(
|
| 16 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 17 |
+
level=logging.INFO
|
| 18 |
+
)
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
+
|
| 21 |
+
class Command(BaseCommand):
|
| 22 |
+
help = 'Runs the Telegram Bot for FraudGuard Admin'
|
| 23 |
+
|
| 24 |
+
def handle(self, *args, **options):
|
| 25 |
+
self.stdout.write(self.style.SUCCESS('Starting Telegram Bot...'))
|
| 26 |
+
|
| 27 |
+
application = ApplicationBuilder().token(TOKEN).build()
|
| 28 |
+
|
| 29 |
+
# Add handlers
|
| 30 |
+
application.add_handler(CommandHandler('start', self.start))
|
| 31 |
+
application.add_handler(CommandHandler('help', self.help_command))
|
| 32 |
+
application.add_handler(CommandHandler('pending', self.pending_users))
|
| 33 |
+
application.add_handler(CommandHandler('menu', self.menu))
|
| 34 |
+
application.add_handler(CommandHandler('links', self.links))
|
| 35 |
+
|
| 36 |
+
# Handle Buttons
|
| 37 |
+
application.add_handler(CallbackQueryHandler(self.button_handler))
|
| 38 |
+
|
| 39 |
+
# Handle Menu Text (if they type the menu options)
|
| 40 |
+
application.add_handler(MessageHandler(filters.Regex('^(PENDING USERS|LINKS|STATS)$'), self.menu_handler))
|
| 41 |
+
|
| 42 |
+
# Run
|
| 43 |
+
application.run_polling()
|
| 44 |
+
|
| 45 |
+
async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 46 |
+
keyboard = [
|
| 47 |
+
["PENDING USERS", "LINKS"],
|
| 48 |
+
["STATS"]
|
| 49 |
+
]
|
| 50 |
+
reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
|
| 51 |
+
|
| 52 |
+
await update.message.reply_text(
|
| 53 |
+
"🤖 *Welcome to FraudGuard Bot!*\n\n"
|
| 54 |
+
"I can help you manage your application directly from Telegram.\n\n"
|
| 55 |
+
"🔹 *Approve Users*: Get notified and activate new registrations.\n"
|
| 56 |
+
"🔹 *Quick Links*: Access your Admin and User portals.\n"
|
| 57 |
+
"🔹 *Stats*: See system status.\n\n"
|
| 58 |
+
"Use the menu below or type /help.",
|
| 59 |
+
reply_markup=reply_markup,
|
| 60 |
+
parse_mode='Markdown'
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
async def help_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 64 |
+
await update.message.reply_text(
|
| 65 |
+
"📋 *Available Commands:*\n\n"
|
| 66 |
+
"/start - Main Menu\n"
|
| 67 |
+
"/pending - List users waiting for activation\n"
|
| 68 |
+
"/links - Get direct links to your app pages\n"
|
| 69 |
+
"/stats - View application statistics\n"
|
| 70 |
+
"/menu - Show the keyboard menu",
|
| 71 |
+
parse_mode='Markdown'
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
async def menu(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 75 |
+
await self.start(update, context)
|
| 76 |
+
|
| 77 |
+
async def menu_handler(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 78 |
+
text = update.message.text
|
| 79 |
+
if text == "PENDING USERS":
|
| 80 |
+
await self.pending_users(update, context)
|
| 81 |
+
elif text == "LINKS":
|
| 82 |
+
await self.links(update, context)
|
| 83 |
+
elif text == "STATS":
|
| 84 |
+
await self.stats(update, context)
|
| 85 |
+
|
| 86 |
+
async def pending_users(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 87 |
+
users = await sync_to_async(list)(UserRegistrationModel.objects.filter(status='waiting'))
|
| 88 |
+
|
| 89 |
+
if not users:
|
| 90 |
+
await update.message.reply_text("✅ No pending user registrations found.")
|
| 91 |
+
return
|
| 92 |
+
|
| 93 |
+
await update.message.reply_text(f"found {len(users)} pending users:")
|
| 94 |
+
|
| 95 |
+
for user in users:
|
| 96 |
+
keyboard = [
|
| 97 |
+
[
|
| 98 |
+
InlineKeyboardButton("✅ Activate", callback_data=f"activate_{user.id}"),
|
| 99 |
+
InlineKeyboardButton("❌ Delete", callback_data=f"delete_{user.id}"),
|
| 100 |
+
]
|
| 101 |
+
]
|
| 102 |
+
reply_markup = InlineKeyboardMarkup(keyboard)
|
| 103 |
+
text = (
|
| 104 |
+
f"👤 *Registration Request*\n"
|
| 105 |
+
f"━━━━━━━━━━━━━━━━━━\n"
|
| 106 |
+
f"**Name:** {user.name}\n"
|
| 107 |
+
f"**ID:** `{user.loginid}`\n"
|
| 108 |
+
f"**Email:** {user.email}\n"
|
| 109 |
+
f"**Mobile:** {user.mobile}\n"
|
| 110 |
+
f"**Locality:** {user.locality}"
|
| 111 |
+
)
|
| 112 |
+
await update.message.reply_text(text, reply_markup=reply_markup, parse_mode='Markdown')
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
async def stats(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 117 |
+
total_users = await sync_to_async(UserRegistrationModel.objects.count)()
|
| 118 |
+
active_users = await sync_to_async(UserRegistrationModel.objects.filter(status='activated').count)()
|
| 119 |
+
pending_users = await sync_to_async(UserRegistrationModel.objects.filter(status='waiting').count)()
|
| 120 |
+
|
| 121 |
+
text = (
|
| 122 |
+
"📊 *System Statistics*\n"
|
| 123 |
+
f"━━━━━━━━━━━━━━━━━━\n"
|
| 124 |
+
f"**Total Users:** {total_users}\n"
|
| 125 |
+
f"**Active:** {active_users}\n"
|
| 126 |
+
f"**Pending:** {pending_users}\n"
|
| 127 |
+
)
|
| 128 |
+
await update.message.reply_text(text, parse_mode='Markdown')
|
| 129 |
+
|
| 130 |
+
async def links(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 131 |
+
keyboard = [
|
| 132 |
+
[InlineKeyboardButton("🖥 Open Admin (Host)", callback_data="open_admin")],
|
| 133 |
+
[InlineKeyboardButton("🖥 Open User Login (Host)", callback_data="open_user")],
|
| 134 |
+
[InlineKeyboardButton("� Open Registration (Host)", callback_data="open_register")],
|
| 135 |
+
[InlineKeyboardButton("🖥 Open Home (Host)", callback_data="open_home")],
|
| 136 |
+
]
|
| 137 |
+
reply_markup = InlineKeyboardMarkup(keyboard)
|
| 138 |
+
|
| 139 |
+
text = (
|
| 140 |
+
"� *Remote Control Links*\n"
|
| 141 |
+
"Click below to open these pages **on your laptop/server**."
|
| 142 |
+
)
|
| 143 |
+
await update.message.reply_text(text, reply_markup=reply_markup, parse_mode='Markdown')
|
| 144 |
+
|
| 145 |
+
async def button_handler(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 146 |
+
query = update.callback_query
|
| 147 |
+
await query.answer()
|
| 148 |
+
|
| 149 |
+
data = query.data
|
| 150 |
+
base_url = "http://127.0.0.1:8000"
|
| 151 |
+
|
| 152 |
+
match data:
|
| 153 |
+
case "open_admin":
|
| 154 |
+
webbrowser.open(f"{base_url}/admins/AdminLoginCheck/")
|
| 155 |
+
await query.edit_message_text("✅ Opened **Admin Login** on host machine.", parse_mode='Markdown')
|
| 156 |
+
return
|
| 157 |
+
case "open_user":
|
| 158 |
+
webbrowser.open(f"{base_url}/users/UserLoginCheck/")
|
| 159 |
+
await query.edit_message_text("✅ Opened **User Login** on host machine.", parse_mode='Markdown')
|
| 160 |
+
return
|
| 161 |
+
case "open_register":
|
| 162 |
+
webbrowser.open(f"{base_url}/UserRegisterForm")
|
| 163 |
+
await query.edit_message_text("✅ Opened **Registration** on host machine.", parse_mode='Markdown')
|
| 164 |
+
return
|
| 165 |
+
case "open_home":
|
| 166 |
+
webbrowser.open(f"{base_url}/")
|
| 167 |
+
await query.edit_message_text("✅ Opened **Home Page** on host machine.", parse_mode='Markdown')
|
| 168 |
+
return
|
| 169 |
+
|
| 170 |
+
# Handle User Actions (Activate/Delete)
|
| 171 |
+
try:
|
| 172 |
+
action, user_id = data.split('_')
|
| 173 |
+
user_id = int(user_id)
|
| 174 |
+
|
| 175 |
+
user = await sync_to_async(UserRegistrationModel.objects.get)(id=user_id)
|
| 176 |
+
|
| 177 |
+
if action == 'activate':
|
| 178 |
+
user.status = 'activated'
|
| 179 |
+
await sync_to_async(user.save)()
|
| 180 |
+
await query.edit_message_text(text=f"✅ User *{user.name}* has been **ACTIVATED**.", parse_mode='Markdown')
|
| 181 |
+
elif action == 'delete':
|
| 182 |
+
await sync_to_async(user.delete)()
|
| 183 |
+
await query.edit_message_text(text=f"❌ User *{user.name}* has been **DELETED**.", parse_mode='Markdown')
|
| 184 |
+
|
| 185 |
+
except UserRegistrationModel.DoesNotExist:
|
| 186 |
+
await query.edit_message_text(text="⚠️ User not found (might have been processed already).")
|
| 187 |
+
except Exception as e:
|
| 188 |
+
await query.edit_message_text(text=f"⚠️ Error: {str(e)}")
|
admins/migrations/__init__.py
ADDED
|
File without changes
|
admins/migrations/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (242 Bytes). View file
|
|
|
admins/migrations/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (244 Bytes). View file
|
|
|
admins/migrations/__pycache__/__init__.cpython-37.pyc
ADDED
|
Binary file (239 Bytes). View file
|
|
|
admins/models.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
# Create your models here.
|
admins/tests.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.test import TestCase
|
| 2 |
+
|
| 3 |
+
# Create your tests here.
|
admins/views.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.shortcuts import render
|
| 2 |
+
|
| 3 |
+
# Create your views here.
|
| 4 |
+
from django.shortcuts import render
|
| 5 |
+
|
| 6 |
+
# Create your views here.
|
| 7 |
+
from django.shortcuts import render
|
| 8 |
+
|
| 9 |
+
# Create your views here.
|
| 10 |
+
from django.shortcuts import render,redirect
|
| 11 |
+
from django.contrib import messages
|
| 12 |
+
from users.models import UserRegistrationModel
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# Create your views here.
|
| 16 |
+
def AdminLoginCheck(request):
|
| 17 |
+
if request.method == 'POST':
|
| 18 |
+
usrid = request.POST.get('loginid')
|
| 19 |
+
pswd = request.POST.get('pswd')
|
| 20 |
+
print("User ID is = ", usrid)
|
| 21 |
+
if usrid == 'admin' and pswd == 'admin':
|
| 22 |
+
return redirect('adminhome')
|
| 23 |
+
else:
|
| 24 |
+
messages.error(request, 'Invalid Administrator Credentials')
|
| 25 |
+
return render(request, 'AdminLogin.html', {})
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def RegisterUsersView(request):
|
| 30 |
+
data = UserRegistrationModel.objects.all()
|
| 31 |
+
return render(request, 'admins/viewregisterusers.html', context={'data': data})
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def ActivaUsers(request):
|
| 37 |
+
if request.method == 'GET':
|
| 38 |
+
user_id = request.GET.get('uid')
|
| 39 |
+
|
| 40 |
+
if user_id: # Ensure user_id is not None
|
| 41 |
+
status = 'activated'
|
| 42 |
+
print("Activating user with ID =", user_id)
|
| 43 |
+
UserRegistrationModel.objects.filter(id=user_id).update(status=status)
|
| 44 |
+
|
| 45 |
+
# Redirect to the view where users are listed after activation
|
| 46 |
+
return redirect('RegisterUsersView') # Replace with your actual URL name
|
| 47 |
+
|
| 48 |
+
def DeleteUsers(request):
|
| 49 |
+
if request.method == 'GET':
|
| 50 |
+
user_id = request.GET.get('uid')
|
| 51 |
+
|
| 52 |
+
if user_id: # Ensure user_id is not None
|
| 53 |
+
print("Deleting user with ID =", user_id)
|
| 54 |
+
UserRegistrationModel.objects.filter(id=user_id).delete()
|
| 55 |
+
|
| 56 |
+
# Redirect to the view where users are listed after deletion
|
| 57 |
+
return redirect('RegisterUsersView') # Replace with your actual URL name
|
| 58 |
+
def adminhome(request):
|
| 59 |
+
return render(request,'admins/AdminHome.html')
|
| 60 |
+
|