mirror of
https://gh.wpcy.net/https://github.com/DecisiveDesignDE/wp-quickstart-installer.git
synced 2026-04-26 00:24:00 +08:00
1. WordPress Installation Check (Step04):
- When you successfully 'Test Connection', I will now also check for the presence of 'wp-config.php' in the remote directory.
- If 'wp-config.php' is found, I will display a warning message to you, alerting you to a potential existing WordPress installation.
2. Password Obfuscation (Step04 & Step05):
- The password you enter in Step04 is now Base64 encoded before being saved to `connection_data.json`.
- In Step05, the Base64 encoded password is decoded before being used for FTP/SFTP operations.
- This prevents the password from being stored in plaintext, making it not immediately discernible by eye in the JSON file.
These changes improve your awareness of existing installations and provide a basic level of security for stored credentials.
156 lines
6.4 KiB
Python
156 lines
6.4 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
import subprocess
|
|
from ftplib import FTP
|
|
import paramiko
|
|
import json
|
|
import base64
|
|
|
|
class Step04(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
super().__init__(parent)
|
|
self.controller = controller
|
|
self.configure(bg="#f4f4f4")
|
|
|
|
# Storage for connection data
|
|
self.connection_data = {}
|
|
|
|
# Headline
|
|
title_label = tk.Label(self, text="Connection Data", font=("Arial", 18, "bold"), bg="#f4f4f4")
|
|
title_label.pack(pady=(20, 10))
|
|
|
|
# Dropdown for connection type
|
|
connection_frame = tk.Frame(self, bg="#f4f4f4")
|
|
connection_frame.pack(pady=5)
|
|
tk.Label(connection_frame, text="FTP Connection:", font=("Arial", 12), bg="#f4f4f4").pack(side=tk.LEFT, padx=5)
|
|
|
|
self.connection_type = tk.StringVar(value="SFTP (Recommended)")
|
|
connection_dropdown = ttk.Combobox(connection_frame, textvariable=self.connection_type, values=["FTP", "SFTP (Recommended)"], state="readonly")
|
|
connection_dropdown.pack(side=tk.LEFT)
|
|
connection_dropdown.bind("<<ComboboxSelected>>", self.update_port)
|
|
|
|
# Input Fields
|
|
input_frame = tk.Frame(self, bg="#f4f4f4")
|
|
input_frame.pack(pady=10)
|
|
|
|
labels = ["Server:", "Username:", "Password:", "Port:"]
|
|
self.entries = {}
|
|
|
|
for idx, label in enumerate(labels):
|
|
frame = tk.Frame(input_frame, bg="#f4f4f4")
|
|
frame.pack(pady=5, fill=tk.X, padx=20)
|
|
tk.Label(frame, text=label, font=("Arial", 12), bg="#f4f4f4", width=15, anchor="w").pack(side=tk.LEFT)
|
|
entry = ttk.Entry(frame, width=30, show="*" if "Password" in label else "")
|
|
entry.pack(side=tk.LEFT, padx=5)
|
|
self.entries[label] = entry
|
|
|
|
# Default port
|
|
self.entries["Port:"].insert(0, "22")
|
|
|
|
# Test Connection Button
|
|
self.status_label = tk.Label(self, text="", font=("Arial", 12), bg="#f4f4f4")
|
|
self.status_label.pack(pady=5)
|
|
test_button = ttk.Button(self, text="Test Connection", command=self.test_connection)
|
|
test_button.pack(pady=10)
|
|
|
|
# Button Frame
|
|
button_frame = tk.Frame(self, bg="#f4f4f4")
|
|
button_frame.pack(pady=20)
|
|
|
|
prev_button = ttk.Button(button_frame, text="< Prev", command=lambda: controller.show_frame("Step03"))
|
|
prev_button.grid(row=0, column=0, padx=10)
|
|
|
|
self.next_button = ttk.Button(button_frame, text="> Next", command=self.next_window, state=tk.DISABLED)
|
|
self.next_button.grid(row=0, column=1, padx=10)
|
|
|
|
def update_port(self, event):
|
|
"""Update the port field when switching between FTP and SFTP"""
|
|
if self.connection_type.get() == "SFTP (Recommended)":
|
|
self.entries["Port:"].delete(0, tk.END)
|
|
self.entries["Port:"].insert(0, "22")
|
|
else:
|
|
self.entries["Port:"].delete(0, tk.END)
|
|
self.entries["Port:"].insert(0, "21")
|
|
|
|
def test_connection(self):
|
|
server = self.entries["Server:"].get()
|
|
username = self.entries["Username:"].get()
|
|
password = self.entries["Password:"].get()
|
|
port = self.entries["Port:"].get()
|
|
connection_type = self.connection_type.get()
|
|
|
|
# Store the connection data
|
|
self.connection_data = {
|
|
"server": server,
|
|
"username": username,
|
|
"password": password,
|
|
"port": port,
|
|
"connection_type": connection_type
|
|
}
|
|
|
|
wp_config_exists = False # Initialize flag
|
|
try:
|
|
if connection_type == "FTP":
|
|
ftp = FTP()
|
|
ftp.connect(server, int(port))
|
|
ftp.login(username, password)
|
|
# Check for wp-config.php
|
|
try:
|
|
ftp.size("wp-config.php")
|
|
wp_config_exists = True
|
|
except Exception as e_wp:
|
|
# print(f"FTP: wp-config.php not found or error: {e_wp}")
|
|
pass # wp_config_exists remains False
|
|
ftp.quit()
|
|
else: # SFTP
|
|
transport = paramiko.Transport((server, int(port)))
|
|
transport.connect(username=username, password=password)
|
|
sftp = None
|
|
try:
|
|
sftp = paramiko.SFTPClient.from_transport(transport)
|
|
sftp.stat("wp-config.php") # Check if file exists
|
|
wp_config_exists = True
|
|
except FileNotFoundError:
|
|
# print("SFTP: wp-config.php not found.")
|
|
pass # wp_config_exists remains False
|
|
except Exception as e_wp:
|
|
# print(f"SFTP: Error checking for wp-config.php: {e_wp}")
|
|
pass # wp_config_exists remains False
|
|
finally:
|
|
if sftp:
|
|
sftp.close()
|
|
transport.close()
|
|
|
|
current_status_text = "Connection successful"
|
|
current_status_color = "green"
|
|
|
|
if wp_config_exists:
|
|
current_status_text += "\n⚠️ WARNING: 'wp-config.php' found! An existing WordPress installation might be present."
|
|
# Color remains green as connection itself was successful
|
|
|
|
self.status_label.config(text=current_status_text, fg=current_status_color)
|
|
self.next_button.config(state=tk.NORMAL)
|
|
|
|
except Exception as e:
|
|
self.status_label.config(text="Connection failed. Please check your inputs", fg="red")
|
|
self.next_button.config(state=tk.DISABLED)
|
|
print(f"Error: {e}")
|
|
|
|
def next_window(self):
|
|
# Save connection data before proceeding
|
|
|
|
# Make a copy to avoid altering the in-memory plain password if it's used elsewhere,
|
|
# though in this specific flow, Step04 instance might be destroyed or not reused.
|
|
# For safety, let's operate on a copy for saving.
|
|
data_to_save = self.connection_data.copy()
|
|
|
|
if "password" in data_to_save:
|
|
plain_password = data_to_save["password"]
|
|
# Encode password to Base64
|
|
encoded_password_bytes = base64.b64encode(plain_password.encode('utf-8'))
|
|
data_to_save["password"] = encoded_password_bytes.decode('utf-8') # Store as string
|
|
|
|
with open("connection_data.json", "w") as f:
|
|
json.dump(data_to_save, f) # Save the version with the encoded password
|
|
|
|
self.controller.show_frame("Step05")
|