:KSdddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZejdZGddeZGdd eZGd d eZGd d eZGddeZdS)N)etree open_nofollow)get_all_user_domainsnormalize_domain litespeedceZdZdS)LiteSpeedExceptionN__name__ __module__ __qualname__/builddir/build/BUILDROOT/lve-stats-4.3.2-1.el9.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/commons/litespeed.pyr r Drr ceZdZdS)LiteSpeedDisabledExceptionNr rrrrrrrrceZdZdS)LiteSpeedInvalidCredentialsNr rrrrrrrrceZdZdZdZdZdZdS)LiteSpeedDataMappingN)r r rTIMEHOSTREQUEST TOTAL_LENrrrrr#s" D DGIIIrrceZdZdgZdZdZdZdZdZe dZ e dZ e d Z e d Z d Zd ZddZdZdefdZdZe dZdS) LiteSpeeds _AdminVHostz/tmp/lshttpd/lshttpd.pidz&/usr/local/lsws/admin/htpasswds/statusz+/usr/local/lsws/admin/conf/admin_config.xmlc"||_||_dS)N)loginpassword)selfr%r&s r__init__zLiteSpeed.__init__2s   rc t|S)ziThin wrapper around :func:`fileutil.open_nofollow` kept for backward-compatible mocking in tests.r)paths r_open_nofollowzLiteSpeed._open_nofollow6sT"""rcttj} tj|jdkrt dtj|d5}d}| tj }dddn #1swxYwY|dkrtj |n #|dkrtj |wwxYwt|}|dkrt dtj d|d jdkrt d |S) z Read and validate PID from litespeed's pidfile. :return: str pid value :raises: OSError, ValueError on any validation failure rzpid file not owned by rootutf-8encodingNzinvalid pid valuez/proc/z/statuszprocess not owned by root)r"r+ PID_FILE_PATHosfstatst_uid ValueErrorfdopenreadlinerstriplinesepcloseintstat)fdfpid_strpids r_read_pid_filezLiteSpeed._read_pid_file<sd % %i&= > > x||"a'' !=>>>2000 :A**,,--bj99 : : : : : : : : : : : : : : :Rxx Rxx 'll !88011 1 7(C((( ) ) 0A 5 5899 9s0AC(4B( C(B,,C/B,0CC+ctjtjr)tjtjsdS tS#ttf$rYdSwxYw)zX Returns pid that is stored in litespeed's pidfile :return: str N) r2r*isfiler"r1 HTPASSWD_PATHrAOSErrorr5rrr_get_litespeed_pidzLiteSpeed._get_litespeed_pidTsx w~~i566 bgnnYMd>e>e 4 ++-- -$   44 sA//BBc8tduS)zG Checks whether pid is not None. :return: bool N)r"rFrrris_litespeed_runningzLiteSpeed.is_litespeed_runningas ++--T99rc t|jdd5}tj|}dddn #1swxYwY|dd}|jddS#tttttf$r }td |jd ||d}~wwxYw) z} Retrives current LiteSpeed webadmin console port :return: LiteSpeed webadmin console port as string rr-r.NzlistenerList/listener/addressr:zDCan't determine current LiteSpeed webadmin console port from config z: )openLS_ADMIN_CONFIGrparsegetrootxpathtextsplitAttributeError IndexErrorr5rEIOErrorr )r'r> ls_adm_cfgdataes r_get_litespeed_webadmin_portz&LiteSpeed._get_litespeed_webadmin_portis&  d*C'BBB 6a"[^^3355  6 6 6 6 6 6 6 6 6 6 6 6 6 6 6##$CDDQGD9??3''* * JI   $@$($8@@<=@@  s:B'A  B ABA=B#C5CCc6|}|d|dd}||d|dd}|tdd |tjD}|S) z Get info about connections from litespeed and returns array of rows with data :return: list :raise: [LiteSpeedInvalidCredentials, LiteSpeedDisabledException] zhttp://localhost:z/status?rpt=detailsF)raise_on_auth_errorNzhttps://localhost:Tzz+LiteSpeed._get_requests..s+WWW#CIIKKSVDVDV#DVDVDVr)rZ _fetch_statusrrSr2r9encode)r'portrXresults r _get_requestszLiteSpeed._get_requestss0022!!"Od"O"O"O6;"== <%%&T4&T&T&T:>&@@D <,N  XWBJ,=,=,?,?!@!@WWW rTcHtj|}tjd|j|jfz}|dd|z tj }tj ||j |5}| cdddS#1swxYwYdS#tjj$rd}|jdvr9|rt#d|t$d||jYd}~dSt)t+||d}~wtjjt.f$r'}t$d ||Yd}~dSd}~wwxYw) a Fetch LiteSpeed status page at the given URL. :param raise_on_auth_error: if True, raise LiteSpeedInvalidCredentials on 401/403; if False, return None (allows caller to retry with a different URL scheme) :return: response bytes on success, None on failure :raise: LiteSpeedInvalidCredentials on 401/403 (when raise_on_auth_error=True) :raise: LiteSpeedDisabledException on non-auth HTTP errors s%s:%ss AuthorizationsBasic %s)timeoutcontextN)iizILitespeed login / password invalid. Please, try restart lvestats service.z&Auth error on %s (HTTP %s), will retryz&Connection error on %s: %s, will retry)urllibrequestRequestbase64 b64encoder%rcr& add_headerssl_create_unverified_contexturlopen HTTP_TIMEOUTreaderror HTTPErrorcoderlogdebugrstrURLErrorrE)r' status_urlr\rk base64stringriresponserYs rrbzLiteSpeed._fetch_statuss.((44'DJ4E4E4G4GI]I]I_I_3`(`aa +[<-GHHH 466G'')( '}}  ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' |% < < <v##&5@ BJPQPVWWWttttt-SVV44! ; %w/    II> A N N N44444  sN:C);C C)C  C)#C $C))F!=rs  777777LLLLLLLLg $$             !3        "4   6ggggggggggr