feat: machine binding and version enforcement
migration 017 adds machine_id to agents table middleware validates X-Machine-ID header on authed routes agent client sends machine ID with requests MIN_AGENT_VERSION config defaults 0.1.22 version utils added for comparison blocks config copying attacks via hardware fingerprint old agents get 426 upgrade required breaking: <0.1.22 agents rejected
This commit is contained in:
124
discord/setup.py
Normal file
124
discord/setup.py
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
RedFlag Discord Setup Assistant
|
||||
Helps configure Discord bot for server management
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
def setup_discord():
|
||||
"""Interactive Discord setup"""
|
||||
print("🚀 RedFlag Discord Bot Setup Assistant")
|
||||
print("=" * 50)
|
||||
|
||||
# Check if .env exists
|
||||
env_file = ".env"
|
||||
if not os.path.exists(env_file):
|
||||
print(f"📝 Creating {env_file} from template...")
|
||||
|
||||
if os.path.exists(".env.example"):
|
||||
import shutil
|
||||
shutil.copy(".env.example", env_file)
|
||||
print(f"✅ Created {env_file} from .env.example")
|
||||
else:
|
||||
# Create basic .env file
|
||||
with open(env_file, 'w') as f:
|
||||
f.write("# Discord Bot Configuration\n")
|
||||
f.write("DISCORD_BOT_TOKEN=your_bot_token_here\n")
|
||||
f.write("DISCORD_SERVER_ID=your_server_id_here\n")
|
||||
f.write("DISCORD_APPLICATION_ID=your_app_id_here\n")
|
||||
f.write("DISCORD_PUBLIC_KEY=your_public_key_here\n")
|
||||
f.write("\n# Server Settings\n")
|
||||
f.write("SERVER_NAME=RedFlag Security\n")
|
||||
f.write("ADMIN_ROLE_ID=\n")
|
||||
print(f"✅ Created basic {env_file}")
|
||||
|
||||
# Load environment
|
||||
load_dotenv(env_file)
|
||||
|
||||
print("\n📋 Discord Configuration Checklist:")
|
||||
print("1. ✅ Discord Developer Portal: https://discord.com/developers/applications")
|
||||
print("2. ✅ Create Application: Click 'New Application'")
|
||||
print("3. ✅ Create Bot: Go to 'Bot' → 'Add Bot'")
|
||||
print("4. ✅ Enable Privileged Intents:")
|
||||
print(" - ✅ Server Members Intent")
|
||||
print(" - ✅ Server Management Intent")
|
||||
print(" - ✅ Message Content Intent")
|
||||
print("5. ✅ OAuth2 URL Generator:")
|
||||
print(" - ✅ Scope: bot")
|
||||
print(" - ✅ Scope: applications.commands")
|
||||
print(" - ✅ Permissions: Administrator (or specific)")
|
||||
print("6. ✅ Invite Bot to Server")
|
||||
print("7. ✅ Copy Values Below:")
|
||||
|
||||
print("\n🔑 Required Discord Information:")
|
||||
print("From your Discord Developer Portal, copy these values:")
|
||||
print("-" * 50)
|
||||
|
||||
# Get user input (with masking)
|
||||
def get_sensitive_input(prompt, key):
|
||||
value = input(f"{prompt}: ").strip()
|
||||
if value:
|
||||
# Update .env file
|
||||
update_env_file(key, value)
|
||||
# Show masked version
|
||||
masked_value = value[:8] + "..." + value[-4:] if len(value) > 12 else value
|
||||
print(f"✅ {key}: {masked_value}")
|
||||
return value
|
||||
|
||||
def update_env_file(key, value):
|
||||
"""Update .env file with value"""
|
||||
env_path = os.path.join(os.path.dirname(__file__), env_file)
|
||||
|
||||
# Read current file
|
||||
with open(env_path, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Update or add the line
|
||||
updated = False
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith(f"{key}="):
|
||||
lines[i] = f"{key}={value}\n"
|
||||
updated = True
|
||||
break
|
||||
|
||||
if not updated:
|
||||
lines.append(f"{key}={value}\n")
|
||||
|
||||
# Write back to file
|
||||
with open(env_path, 'w') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
# Get required values
|
||||
bot_token = get_sensitive_input("Discord Bot Token", "DISCORD_BOT_TOKEN")
|
||||
server_id = get_sensitive_input("Discord Server ID", "DISCORD_SERVER_ID")
|
||||
app_id = get_sensitive_input("Discord Application ID", "DISCORD_APPLICATION_ID")
|
||||
public_key = get_sensitive_input("Discord Public Key", "DISCORD_PUBLIC_KEY")
|
||||
|
||||
print("-" * 50)
|
||||
print("🎉 Configuration Complete!")
|
||||
print("\n📝 Next Steps:")
|
||||
print("1. Run the Discord bot:")
|
||||
print(" cd /home/memory/Desktop/Projects/RedFlag/discord")
|
||||
print(" python discord_manager.py")
|
||||
print("\n2. Available Commands (slash commands):")
|
||||
print(" • /status - Show server status")
|
||||
print(" • /create-channels - Create standard channels")
|
||||
print(" • /list-channels - List all channels")
|
||||
print(" • /send-message - Send message to channel")
|
||||
print(" • /create-category - Create new category")
|
||||
print(" • /help - Show all commands")
|
||||
print("\n🔒 Security Note:")
|
||||
print("• Your bot token is stored locally in .env")
|
||||
print("• Never share the .env file")
|
||||
print("• The bot only has Administrator permissions you grant it")
|
||||
print("• All actions are logged locally")
|
||||
|
||||
def main():
|
||||
"""Main setup function"""
|
||||
setup_discord()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user