Using a Python script, I fetch users plus their expiration date from a MySQL database. Since SofEther VPN accepts DateTime value and I stored expiration date as Date value in the database, a formatted version is passed to the SoftEther. Although after running the script I get the below message, still SoftEther VPN Manager shows that expiration date for the corresponding users has not been set:
vpncmd command - SoftEther VPN Command Line Management Utility SoftEther VPN Command Line Management Utility (vpncmd command) Version 4.43 Build 9799 (English) Compiled 2023/08/31 10:50:49 by buildsan at crosswin with OpenSSL 3.0.9 Copyright (c) 2012-2023 SoftEther VPN Project. All Rights Reserved.
Connection has been established with VPN Server "localhost" (port 443).
You have administrator privileges for the entire VPN Server.
The Virtual Hub "VPN" has been selected. VPN Server/VPN>UserExpiresSet h31403 /EXPIRES: 2024/11/30 00:00:00 UserExpiresSet command - Set User's Expiration Date The command completed successfully.
This part of my script handles the job of setting expiration date for SoftEther users.
def set_user_expiration(username, expiry_date):
# Convert the date object to a datetime object at midnight
expiry_datetime = datetime.combine(expiry_date, time.min)
# Format the expiration date and time in a format SoftEther understands
formatted_expiry_date = expiry_datetime.strftime("%Y/%m/%d %H:%M:%S")
# Command to set the expiration date for a user
expiration_cmd = f"/server {server}:{port} /adminhub:{hub} /PASSWORD:{admin_password} /CMD UserExpiresSet {username} /EXPIRES: {formatted_expiry_date}"
# Execute the command
subprocess.run([vpncmd_path] + expiration_cmd.split(), shell=False)