| Server IP : 66.29.153.156 / Your IP : 216.73.217.178 Web Server : LiteSpeed System : Linux premium322.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64 User : lastyfjz ( 1521) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/proc/self/root/usr/lib/python3.6/site-packages/up2date_client/ |
Upload File : |
import os
from subprocess import PIPE, Popen
def get_users_count_from_cllib():
"""
Get user count using the common CloudLinux library.
This number is more accurate for systems
with a control panel installed.
"""
if not os.path.exists('/opt/cloudlinux/venv/bin'):
raise ValueError("CloudLinux virtual environment not found")
cmd = '/opt/cloudlinux/venv/bin/python3 -c "from clcommon.cpapi import cpusers; print(cpusers())"'
process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
output, errors = [result.decode().strip() for result in process.communicate()]
if errors:
raise ValueError(f"Failed to get users from CloudLinux library: {errors}")
return len(output[1:-1].split(', '))
def get_users_count_generic():
"""
Fallback method to get the user count
by looking into the /etc/passwd file.
"""
from up2date_client.clpwd import ClPwd
pwd = ClPwd()
return len(pwd.get_uid_dict())
def count_server_users():
"""
Get the total count of users on the server.
Tries the CloudLinux library first, falls back to generic method if it fails.
"""
try:
users_count = get_users_count_from_cllib()
except Exception:
users_count = get_users_count_generic()
return users_count