Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AlpacaMax
GitHub Repository: AlpacaMax/Shadow-Browser
Path: blob/master/api/__pycache__/main.cpython-36.pyc
249 views
3

	[)�@sddlmZddlZddlmZddlmZddlZddlZee�Z	dZ
dZee
ZgZ
ej�Zejjd�Zede�e	jd	�d
d��Zdd
�Zdd�Zdd�Zdd�Ze	jddgd�dd��Ze	jd�dd��Ze	jd�dd��Zedkr�e	jd d!d"d#�dS)$�)�FlaskN)�request)�Timeri>ip�HOSTNAMEz	HOSTNAME:�/cCstjjdd�}|jd�S)z
    Hello-world test
    Zalpinezecho hello world, alpine�ascii)�client�
containers�run�decode)Ztxt�r�	./main.py�hellosrcCs.x(ttt�D]}|tkrtj|�|SqWdS)zL
    get an available port no in use
    return -1 if no port available
    ������)�range�MIN_PORT�MAX_PORT�ports_in_use�append)�portrrr
�get_ports

rcCs |tkrtj|�ntd��dS)za
    release a port from the pool
    return 0 if successful
    return -1 if not successful
    zPort not in use!N)r�remove�	Exception)rrrr
�release_port+srcCs"t|jd�|j�t|�dS)Nz killed!)�print�id�killr)�	containerrrrr
�kill_container7srcCs@tjjddd|fidddt|�gd�}t|t||f�j�dS)zU
    start a container on port with duration and password
    duration in second
    z
siomiz/chromez5900/tcpz0.0.0.0Tz
VNC_PASSWORD=)Zports�detachZauto_removeZenvironmentN)rr	r
�strrr�start)r�duration�passwordrrrr
�start_chrome_container=sr%z/run_chromeZGET)�methodscCsNtjjd�}t�}tjdd�}t|t|�|�tdt	|�dt	|�}|S)z�
    example: http://localhost/run_chrome?duration=5
    duration: the duration of a container in minutes
    duration = -1 for unlimited time
    return: the port of the service
    r#ri����#)
r�args�getr�randomZrandintr%�intrr!)r#rr$Zoutrrr
�
run_chromeHsr,z	/hostnamecCstS)zS
    check if the hostname is correct
    :return: the host name of the server
    )rrrrr
�hostnameXsr-z/browsers_infocCshtt�}t|}tt|�td�}tt|�td�}t|�dt|�dt|�dt|�}|S)N�dr')�lenr�TOTALr+�floatr!)ZinuseZ	availableZ	per_inuseZ
per_available�inforrr
�get_info`s,r3Z__main__z0.0.0.0T�P)�host�debugr)ZflaskrZdockerrZ	threadingrr*�os�__name__Zapprrr0rZfrom_envr�environr)rr�routerrrrr%r,r-r3r
rrrr
�<module>s.