mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-26 17:29:05 +01:00
Enhance CyberPanel functionality with FTP Quota and Bandwidth Management features: Added models, views, and templates for managing FTP quotas and bandwidth resets. Implemented IP blocking functionality with associated views and templates. Updated system scripts for improved repository synchronization and OS detection. Removed outdated workflow files.
This commit is contained in:
44
scripts/block_ip.py
Normal file
44
scripts/block_ip.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
"""
|
||||
Quick IP blocking script for CyberPanel
|
||||
Usage: python block_ip.py <ip_address> [reason]
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import django
|
||||
|
||||
# Add CyberPanel to Python path
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
|
||||
try:
|
||||
django.setup()
|
||||
except:
|
||||
pass
|
||||
|
||||
from plogical.firewallUtilities import FirewallUtilities
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python block_ip.py <ip_address> [reason]")
|
||||
print("Example: python block_ip.py 192.168.1.100 'Suspicious activity'")
|
||||
sys.exit(1)
|
||||
|
||||
ip_address = sys.argv[1]
|
||||
reason = sys.argv[2] if len(sys.argv) > 2 else "Manual block via CLI"
|
||||
|
||||
print(f"Blocking IP address: {ip_address}")
|
||||
print(f"Reason: {reason}")
|
||||
|
||||
success, message = FirewallUtilities.blockIP(ip_address, reason)
|
||||
|
||||
if success:
|
||||
print(f"✅ {message}")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print(f"❌ {message}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,121 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Enable FTP User Quota Feature
|
||||
# This script applies the quota configuration and restarts Pure-FTPd
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging function
|
||||
log_message() {
|
||||
echo -e "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | tee -a /var/log/cyberpanel_ftp_quota.log
|
||||
}
|
||||
|
||||
log_message "${BLUE}Starting FTP Quota Feature Setup...${NC}"
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
log_message "${RED}Please run as root${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup existing configurations
|
||||
log_message "${YELLOW}Backing up existing Pure-FTPd configurations...${NC}"
|
||||
|
||||
if [ -f /etc/pure-ftpd/pure-ftpd.conf ]; then
|
||||
cp /etc/pure-ftpd/pure-ftpd.conf /etc/pure-ftpd/pure-ftpd.conf.backup.$(date +%Y%m%d_%H%M%S)
|
||||
log_message "${GREEN}Backed up pure-ftpd.conf${NC}"
|
||||
fi
|
||||
|
||||
if [ -f /etc/pure-ftpd/pureftpd-mysql.conf ]; then
|
||||
cp /etc/pure-ftpd/pureftpd-mysql.conf /etc/pure-ftpd/pureftpd-mysql.conf.backup.$(date +%Y%m%d_%H%M%S)
|
||||
log_message "${GREEN}Backed up pureftpd-mysql.conf${NC}"
|
||||
fi
|
||||
|
||||
# Apply new configurations
|
||||
log_message "${YELLOW}Applying FTP quota configurations...${NC}"
|
||||
|
||||
# Copy the updated configurations
|
||||
if [ -f /usr/local/CyberCP/install/pure-ftpd/pure-ftpd.conf ]; then
|
||||
cp /usr/local/CyberCP/install/pure-ftpd/pure-ftpd.conf /etc/pure-ftpd/pure-ftpd.conf
|
||||
log_message "${GREEN}Updated pure-ftpd.conf${NC}"
|
||||
fi
|
||||
|
||||
if [ -f /usr/local/CyberCP/install/pure-ftpd/pureftpd-mysql.conf ]; then
|
||||
cp /usr/local/CyberCP/install/pure-ftpd/pureftpd-mysql.conf /etc/pure-ftpd/pureftpd-mysql.conf
|
||||
log_message "${GREEN}Updated pureftpd-mysql.conf${NC}"
|
||||
fi
|
||||
|
||||
# Check if Pure-FTPd is running
|
||||
if systemctl is-active --quiet pure-ftpd; then
|
||||
log_message "${YELLOW}Restarting Pure-FTPd service...${NC}"
|
||||
systemctl restart pure-ftpd
|
||||
|
||||
if systemctl is-active --quiet pure-ftpd; then
|
||||
log_message "${GREEN}Pure-FTPd restarted successfully${NC}"
|
||||
else
|
||||
log_message "${RED}Failed to restart Pure-FTPd${NC}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_message "${YELLOW}Starting Pure-FTPd service...${NC}"
|
||||
systemctl start pure-ftpd
|
||||
|
||||
if systemctl is-active --quiet pure-ftpd; then
|
||||
log_message "${GREEN}Pure-FTPd started successfully${NC}"
|
||||
else
|
||||
log_message "${RED}Failed to start Pure-FTPd${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify quota enforcement is working
|
||||
log_message "${YELLOW}Verifying quota enforcement...${NC}"
|
||||
|
||||
# Check if quota queries are in the configuration
|
||||
if grep -q "MYSQLGetQTAFS" /etc/pure-ftpd/pureftpd-mysql.conf; then
|
||||
log_message "${GREEN}Quota queries found in MySQL configuration${NC}"
|
||||
else
|
||||
log_message "${RED}Quota queries not found in MySQL configuration${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -q "Quota.*yes" /etc/pure-ftpd/pure-ftpd.conf; then
|
||||
log_message "${GREEN}Quota enforcement enabled in Pure-FTPd configuration${NC}"
|
||||
else
|
||||
log_message "${RED}Quota enforcement not enabled in Pure-FTPd configuration${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test database connection
|
||||
log_message "${YELLOW}Testing database connection...${NC}"
|
||||
|
||||
# Get database credentials from configuration
|
||||
MYSQL_USER=$(grep "MYSQLUser" /etc/pure-ftpd/pureftpd-mysql.conf | cut -d' ' -f2)
|
||||
MYSQL_PASS=$(grep "MYSQLPassword" /etc/pure-ftpd/pureftpd-mysql.conf | cut -d' ' -f2)
|
||||
MYSQL_DB=$(grep "MYSQLDatabase" /etc/pure-ftpd/pureftpd-mysql.conf | cut -d' ' -f2)
|
||||
|
||||
if mysql -u"$MYSQL_USER" -p"$MYSQL_PASS" -e "USE $MYSQL_DB; SELECT COUNT(*) FROM users;" >/dev/null 2>&1; then
|
||||
log_message "${GREEN}Database connection successful${NC}"
|
||||
else
|
||||
log_message "${RED}Database connection failed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_message "${GREEN}FTP User Quota feature has been successfully enabled!${NC}"
|
||||
log_message "${BLUE}Features enabled:${NC}"
|
||||
log_message " - Individual FTP user quotas"
|
||||
log_message " - Custom quota sizes per user"
|
||||
log_message " - Package default quota fallback"
|
||||
log_message " - Real-time quota enforcement by Pure-FTPd"
|
||||
log_message " - Web interface for quota management"
|
||||
|
||||
log_message "${YELLOW}Note: Existing FTP users will need to have their quotas updated through the web interface to take effect.${NC}"
|
||||
|
||||
exit 0
|
||||
@@ -1,164 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CyberPanel Repository Sync Fix Script
|
||||
# This script resolves the current sync conflict between GitHub and Gitee
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
GITHUB_REPO="https://github.com/usmannasir/cyberpanel.git"
|
||||
GITEE_REPO="https://gitee.com/qtwrk/cyberpanel.git"
|
||||
TEMP_DIR="/tmp/cyberpanel-sync-$(date +%s)"
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Function to check if command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Check prerequisites
|
||||
check_prerequisites() {
|
||||
print_status "Checking prerequisites..."
|
||||
|
||||
if ! command_exists git; then
|
||||
print_error "Git is not installed. Please install git first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command_exists ssh; then
|
||||
print_warning "SSH is not available. HTTPS will be used for authentication."
|
||||
fi
|
||||
|
||||
print_success "Prerequisites check completed"
|
||||
}
|
||||
|
||||
# Setup Git configuration
|
||||
setup_git_config() {
|
||||
print_status "Setting up Git configuration..."
|
||||
|
||||
git config --global user.name "CyberPanel Sync Bot"
|
||||
git config --global user.email "support@cyberpanel.net"
|
||||
git config --global init.defaultBranch main
|
||||
git config --global pull.rebase false
|
||||
git config --global push.default simple
|
||||
|
||||
print_success "Git configuration completed"
|
||||
}
|
||||
|
||||
# Clone and sync repositories
|
||||
sync_repositories() {
|
||||
print_status "Starting repository synchronization..."
|
||||
|
||||
# Create temporary directory
|
||||
mkdir -p "$TEMP_DIR"
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
# Clone GitHub repository
|
||||
print_status "Cloning GitHub repository..."
|
||||
git clone --mirror "$GITHUB_REPO" cyberpanel.git
|
||||
cd cyberpanel.git
|
||||
|
||||
# Add Gitee remote
|
||||
print_status "Adding Gitee remote..."
|
||||
git remote add gitee "$GITEE_REPO"
|
||||
|
||||
# Fetch from Gitee to check current state
|
||||
print_status "Fetching from Gitee..."
|
||||
if git fetch gitee --all --prune; then
|
||||
print_success "Successfully fetched from Gitee"
|
||||
else
|
||||
print_warning "Failed to fetch from Gitee, continuing with force push"
|
||||
fi
|
||||
|
||||
# Push all branches and tags to Gitee
|
||||
print_status "Pushing all branches to Gitee..."
|
||||
if git push gitee --all --force; then
|
||||
print_success "Successfully pushed all branches to Gitee"
|
||||
else
|
||||
print_error "Failed to push branches to Gitee"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_status "Pushing all tags to Gitee..."
|
||||
if git push gitee --tags --force; then
|
||||
print_success "Successfully pushed all tags to Gitee"
|
||||
else
|
||||
print_warning "Failed to push some tags to Gitee"
|
||||
fi
|
||||
|
||||
print_success "Repository synchronization completed"
|
||||
}
|
||||
|
||||
# Verify sync
|
||||
verify_sync() {
|
||||
print_status "Verifying synchronization..."
|
||||
|
||||
cd "$TEMP_DIR/cyberpanel.git"
|
||||
|
||||
# Check if main branches exist
|
||||
for branch in main stable v2.5.5-dev v2.4.0-dev; do
|
||||
if git show-ref --verify --quiet "refs/remotes/gitee/$branch"; then
|
||||
print_success "Branch $branch exists on Gitee"
|
||||
else
|
||||
print_error "Branch $branch missing on Gitee"
|
||||
fi
|
||||
done
|
||||
|
||||
# Show recent commits
|
||||
print_status "Recent commits on main branch:"
|
||||
git log --oneline -5 refs/remotes/origin/main || true
|
||||
}
|
||||
|
||||
# Cleanup
|
||||
cleanup() {
|
||||
print_status "Cleaning up temporary files..."
|
||||
|
||||
if [ -d "$TEMP_DIR" ]; then
|
||||
rm -rf "$TEMP_DIR"
|
||||
print_success "Cleanup completed"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
print_status "Starting CyberPanel Repository Sync Fix"
|
||||
print_status "========================================"
|
||||
|
||||
# Set up error handling
|
||||
trap cleanup EXIT
|
||||
|
||||
# Execute steps
|
||||
check_prerequisites
|
||||
setup_git_config
|
||||
sync_repositories
|
||||
verify_sync
|
||||
|
||||
print_success "Repository sync fix completed successfully!"
|
||||
print_status "The GitHub Actions workflow should now work properly."
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
@@ -1,51 +0,0 @@
|
||||
@echo off
|
||||
REM CyberPanel Bandwidth Reset Script for Windows
|
||||
REM This script resets bandwidth usage for all domains in CyberPanel
|
||||
|
||||
echo CyberPanel Bandwidth Reset Script
|
||||
echo =================================
|
||||
echo.
|
||||
|
||||
REM Check if running as administrator
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% == 0 (
|
||||
echo Running with administrator privileges...
|
||||
) else (
|
||||
echo Please run as administrator
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Check if CyberPanel is installed
|
||||
if not exist "C:\Program Files\CyberPanel\bin\python.exe" (
|
||||
echo CyberPanel not found. Please ensure CyberPanel is installed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Resetting bandwidth for all domains...
|
||||
echo.
|
||||
|
||||
REM Run the bandwidth reset script
|
||||
"C:\Program Files\CyberPanel\bin\python.exe" "C:\Program Files\CyberPanel\plogical\bandwidthReset.py" --reset-all
|
||||
|
||||
if %errorLevel% == 0 (
|
||||
echo.
|
||||
echo Bandwidth reset completed successfully!
|
||||
echo.
|
||||
echo To verify the reset, you can:
|
||||
echo 1. Check the CyberPanel logs
|
||||
echo 2. Check individual domain bandwidth in CyberPanel web interface
|
||||
echo 3. Check bandwidth metadata files
|
||||
) else (
|
||||
echo.
|
||||
echo Bandwidth reset failed. Please check the logs for details.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Note: This script only resets the displayed bandwidth values.
|
||||
echo The actual bandwidth calculation will resume from the current access logs.
|
||||
echo For a complete reset, you may also need to clear access logs if desired.
|
||||
pause
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# CyberPanel Bandwidth Reset Script
|
||||
# This script resets bandwidth usage for all domains in CyberPanel
|
||||
|
||||
echo "CyberPanel Bandwidth Reset Script"
|
||||
echo "================================="
|
||||
echo ""
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root (use sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if CyberPanel is installed
|
||||
if [ ! -f "/usr/local/CyberCP/bin/python" ]; then
|
||||
echo "CyberPanel not found. Please ensure CyberPanel is installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Resetting bandwidth for all domains..."
|
||||
echo ""
|
||||
|
||||
# Run the bandwidth reset script
|
||||
/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/bandwidthReset.py --reset-all
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "Bandwidth reset completed successfully!"
|
||||
echo ""
|
||||
echo "To verify the reset, you can:"
|
||||
echo "1. Check the CyberPanel logs: /usr/local/lscp/logs/error.log"
|
||||
echo "2. Check individual domain bandwidth in CyberPanel web interface"
|
||||
echo "3. Check bandwidth metadata files: ls -la /home/cyberpanel/*.bwmeta"
|
||||
else
|
||||
echo ""
|
||||
echo "Bandwidth reset failed. Please check the logs for details."
|
||||
echo "Log file: /usr/local/lscp/logs/error.log"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Note: This script only resets the displayed bandwidth values."
|
||||
echo "The actual bandwidth calculation will resume from the current access logs."
|
||||
echo "For a complete reset, you may also need to clear access logs if desired."
|
||||
Reference in New Issue
Block a user