Ë
    À7jð  ã                  ó®   — d Z ddlmZ ddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZ dd	lmZ  ed
«      ZdZdZdd„Zdd„Zdd„Zddd„Zy)u  Full discovery: the complete read-only inventory.

Orchestrates the individual discovery modules, writes the snapshot to
/var/lib/wolfpanel/discovery/last.json, and optionally uploads it to the
Central API. Strictly read-only â€” no server state is changed.
é    )ÚannotationsN)ÚdatetimeÚtimezone)ÚPath)ÚAny)ÚConfig)ÚgitÚprojectsÚservicesÚsystem)Ú
get_loggerzdiscovery.full)z/etc/nginx/sites-enabledz/etc/nginx/conf.dz/etc/apache2/sites-enabled)z/etc/letsencrypt/livez/etc/ssl/certsc                 ó¦   — g } t         D ]E  }t        |«      }|j                  «       sŒ| j                  d„ |j	                  d«      D «       «       ŒG | S )zHList vhost config file paths (read-only; contents are not parsed in v1).c              3  óT   K  — | ]   }|j                  «       sŒt        |«      –— Œ" y ­w)N)Úis_fileÚstr)Ú.0Úps     úH/var/www/downloads.wolfpanel.net/public_html/agent/src/discovery/full.pyú	<genexpr>z_vhost_files.<locals>.<genexpr>    s   è ø€ ÒG A¸1¿9¹9½;œ˜QŸÑGùs   ‚(˜(Ú*)Ú_VHOST_DIRSr   Úis_dirÚextendÚglob)ÚfoundÚ	directoryÚbases      r   Ú_vhost_filesr      sK   € à€EÜ ò Hˆ	Ü�I‹ˆØ�;‰;�=Ø�L‰LÑG¨¯©°3«ÔGÕGðHð €Ló    c                 óô  — g } t         D ]ì  }t        |«      }|j                  «       sŒt        |j	                  d«      «      dd t        |j	                  d«      «      z   D ]“  }d|j
                  v sd|j
                  j                  «       v rŒ.t        j                  ddd	d
dt        |«      g«      }| j                  t        |«      |r#|j                  «       j                  dd«      d   nddœ«       Œ• Œî | S )u›   Locate certificate files and read their expiry via openssl if present.

    SECURITY: only certificates (public) are inspected â€” never private keys.
    z**/*.pemNéÈ   z**/fullchain*ÚprivkeyÚkeyÚopensslÚx509z-enddatez-nooutz-inú=é   éÿÿÿÿ)ÚpathÚ	not_after)Ú
_CERT_DIRSr   r   Úlistr   ÚnameÚlowerr   Úrun_readonlyr   ÚappendÚstripÚsplit)Úcertsr   r   ÚcertÚenddates        r   Ú_ssl_certificatesr6   $   sê   € ð
 #%€EÜò ˆ	Ü�I‹ˆØ�{‰{Œ}ØÜ˜Ÿ™ :Ó.Ó/°°Ð5¼¸T¿Y¹YÀÓ=WÓ8XÑXò 	ˆDØ˜DŸI™IÑ%¨°$·)±)·/±/Ó2CÑ)CØÜ×)Ñ)Ø˜F J°¸%ÄÀTÃÐKóˆGð �L‰Lä ›IÙFM §¡£×!6Ñ!6°s¸AÓ!>¸rÒ!BÐSWñõñ	ð	ð  €Lr   c                 óJ  — t        j                  «       } i dt        j                  «       “dt        j                  «       “dt        j
                  «       “dt        j                  «       “dt        j                  «       “dt        j                  «       “dt        j                  «       “dt        j                  «       “d	t        j                  «       “d
t        j                  «       “dt        j                  «       “dt        j                  «       “d| “dt        j                  «       “dt        j                   «       “dt        j"                  «       “dt        j$                  «       “t'        «       t)        «       t+        j,                  «       t/        j0                  «       dœ¥S )z$Build the full inventory dictionary.ÚosÚkernelÚ	cpu_countÚmemoryÚdiskÚload_averageÚuptimeÚprivate_ipsÚ	public_ipÚnetwork_interfacesÚ
open_portsÚsystemd_servicesÚweb_serversÚlanguage_runtimesÚ
containersÚ	databasesÚ	cron_jobs)ÚvhostsÚssl_certificatesÚgit_repositoriesr
   )r   rD   r   Úos_infor9   r:   Úmemory_usageÚ
disk_usager=   Úuptime_secondsr?   r@   rA   rB   rC   rE   rF   rG   rH   r   r6   r	   Úfind_repositoriesr
   Úfind_projects)Úwebs    r   ÚcollectrS   =   s—  € ä
×
Ñ
Ó
 €CðØŒf�n‰nÓðà”&—-‘-“/ðð 	”V×%Ñ%Ó'ðð 	”&×%Ñ%Ó'ð	ð
 	”×!Ñ!Ó#ðð 	œ×+Ñ+Ó-ðð 	”&×'Ñ'Ó)ðð 	”v×)Ñ)Ó+ðð 	”V×%Ñ%Ó'ðð 	œf×7Ñ7Ó9ðð 	”f×'Ñ'Ó)ðð 	œH×5Ñ5Ó7ðð 	�sðð 	œX×7Ñ7Ó9ðð 	”h×)Ñ)Ó+ðð  	”X×'Ñ'Ó)ð!ð" 	”X×'Ñ'Ó)ð#ô$ “.Ü-Ó/Ü×1Ñ1Ó3Ü×*Ñ*Ó,ò+ð r   c                ó  — t        «       }| j                  | j                  t        j                  t
        j                  «      j                  «       |dœ}| j                  j                  dd¬«       | j                  dz  }|j                  t        j                  |d¬«      d¬«       t        j                  d	|«       |rd
dlm}m} 	  || |d ||«      «       |S |S # t$        $ r!}t        j'                  d|«       Y d}~|S d}~ww xY w)z‰Collect, persist the snapshot, and optionally upload it.

    Returns the snapshot dict. Upload failures are logged but never fatal.
    )Ú	server_idÚagent_versionÚcollected_atÚ	discoveryT)ÚparentsÚexist_okz	last.jsoné   )Úindentzutf-8)Úencodingz discovery snapshot written to %sr   )Úcategories_from_inventoryÚupload_inventoryÚfullz9discovery upload failed (will rely on local snapshot): %sN)rS   rU   rV   r   Únowr   ÚutcÚ	isoformatÚdiscovery_dirÚmkdirÚ
write_textÚjsonÚdumpsÚlogÚinfoÚdiscovery.uploadr^   r_   Ú	ExceptionÚwarning)	ÚconfigÚ
api_clientÚuploadÚ	inventoryÚsnapshotÚsnapshot_pathr^   r_   Úexcs	            r   Úrunru   Y   sô   € ô
 “	€Ià×%Ñ%Ø×-Ñ-Ü Ÿ™¤X§\¡\Ó2×<Ñ<Ó>Øñ	€Hð ×Ñ×Ñ t°dÐÔ;Ø×(Ñ(¨;Ñ6€MØ×ÑœTŸZ™Z¨¸Ô;ÀgÐÔNÜ‡H�HÐ/°Ô?áßPð	ZÙØØØÙ)¨)Ó4ô	ð €Oˆ8€Oøô ò 	ZÜ�K‰KÐSÐUX×YÐYà€Oûð	Zús   Ã
C Ã	D	Ã(DÄD	)Úreturnz	list[str])rv   zlist[dict[str, Any]])rv   údict[str, Any])T)rn   r   rp   Úboolrv   rw   )Ú__doc__Ú
__future__r   rg   r   r   Úpathlibr   Útypingr   rn   r   rX   r	   r
   r   r   Úloggerr   ri   r   r+   r   r6   rS   ru   © r   r   ú<module>r      sS   ðñõ #ã ß 'Ý Ý å ß 5Ó 5Ý áÐ!Ó"€ð ^€Ø8€
óóó2õ8 r   