Your IP : 3.138.134.163


Current Path : /opt/hc_python/share/doc/pycurl/examples/__pycache__/
Upload File :
Current File : //opt/hc_python/share/doc/pycurl/examples/__pycache__/linksys.cpython-38.pyc

U

hfU�@s�ddlZddlZddlZddlZdd�ZGdd�dej�ZGdd�d�Zedkr�ddl	Z	ddl
Z
Gd	d
�d
e
j�Ze�Z
ejdd�D]Ze
�e�q�dZes�ze
��d
ZWq�ek
r�e��dj\ZZede�Yq�Xq�dS)�NcCstj�|�tj�d�dS)N�
)�sys�stderr�write)�arg�r�Z/opt/hc_python/lib64/python3.8/site-packages/../../../share/doc/pycurl/examples/linksys.py�print_stderr%sr	c@seZdZdd�ZdS)�LinksysErrorcGs
||_dS�N)�args)�selfrrrr�__init__*szLinksysError.__init__N)�__name__�
__module__�__qualname__rrrrrr
)sr
c@s`eZdZdZdZdZdZdZdZdZ	dd	d
ddd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRdS�Z-dTdU�Z.dVdW�Z/dXS)Y�LinksysSessionz/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec�1�2�3�4�5�6zbasic setup functionszFor security reasons,z-You can configure the router to act as a DHCPz3There are some log settings and lists in this page.z5Port forwarding can be used to set up public services)��
Passwd.htmz	DHCP.htmlzLog.htmlzForward.htmcCsg|_d|_d|_i|_dS)Nzhttp://192.168.1.1F)�actions�host�	verbosity�	pagecache�r
rrrrAszLinksysSession.__init__cCs
||_dSr)r�r
�flagrrr�
set_verbosityGszLinksysSession.set_verbositycCs�||jkr�t�|j�}|�|j�|�|�|��|j|<|�d�rPt	dd��n2|�t
j|�s�|j|=t	dtj
�|j|�d��|��dS)NZ401zauthorization failure.Tz!check string for page %s missing!F)r�curl�Curlrr"r�get�bodyZansweredr
r�
check_strings�os�path�join�close)r
�page�fetchrrr�
cache_loadLs


zLinksysSession.cache_loadcCs
i|_dSr)rrrrr�cache_flushXszLinksysSession.cache_flushcCs8|�|�t�|��|j|�}|r0|�d�}nd}|S�N�)r.�re�compile�searchr�group)r
r,�template�match�resultrrr�
screen_scrape\s
zLinksysSession.screen_scrapecCs|�d|d�S)Nrz:[^M]*\(MAC Address: *([^)]*))r9)r
r,�prefixrrr�get_MAC_addressdszLinksysSession.get_MAC_addresscCs*|r|j�||d�n|j�||d�dS)Nr�0�r�append)r
r,r!�valuerrr�set_flagfszLinksysSession.set_flagc	Cs@d}|�d�D],}|j�dd|t|d�|f�|d7}qdS)Nr�.rZF1r1)�splitrr>�repr)r
r,�cgiZrole�ip�ind�octetrrr�set_IP_addressks zLinksysSession.set_IP_addresscCs|�ddtjd�S)Nrz
>([0-9.v]*, (z)[^<]*)<)r9r�monthsrrrr�get_firmware_versionrs
��z#LinksysSession.get_firmware_versioncCs|�dd�S)NrzLAN IP Address�r;rrrr�get_LAN_MACxszLinksysSession.get_LAN_MACcCs|�dd�S)NrZWirelessrKrrrr�get_Wireless_MACzszLinksysSession.get_Wireless_MACcCs|�dd�S)NrzWAN Connection TyperKrrrr�get_WAN_MAC|szLinksysSession.get_WAN_MACcCs|j�dd|f�dS)NrZhostNamer=�r
�namerrr�
set_host_name�szLinksysSession.set_host_namecCs|j�dd|f�dS)NrZ
DomainNamer=rOrrr�set_domain_name�szLinksysSession.set_domain_namecCs|�dd|�dS)Nr�ipAddr�rH�r
rErrr�
set_LAN_IP�szLinksysSession.set_LAN_IPcCs<|�d�st�|�d�d}|dkr(t�|j�dd|�dS)Nz255.255.255.rA���)r<Z128Z192Z240Z252rZnetMask)�
startswith�
ValueErrorrBrr>)r
rEZlastquadrrr�set_LAN_netmask�s
zLinksysSession.set_LAN_netmaskcCs|�dd�dS)NrZwirelessStatus�r@r rrr�set_wireless�szLinksysSession.set_wirelesscCs|j�dd|f�dS)NrZ
wirelessESSIDr=)r
Zssidrrr�set_SSID�szLinksysSession.set_SSIDcCs|�dd�dS)NrZ
broadcastSSIDr[r rrr�set_SSID_broadcast�sz!LinksysSession.set_SSID_broadcastcCs|j�dd|f�dS)NrZwirelessChannelr=)r
Zchannelrrr�set_channel�szLinksysSession.set_channelcCs|�dd�dS)NrZWepTyper[r rrr�set_WEP�szLinksysSession.set_WEPcCs|j�dd|f�dS)NrZWANConnectionTyper=)r
�typerrr�set_connection_type�sz"LinksysSession.set_connection_typecCs|�dd|�dS)NrZaliasIPrTrUrrr�
set_WAN_IP�szLinksysSession.set_WAN_IPcCs|�dd|�dS)NrZaliasMaskIPrTrUrrr�set_WAN_netmask�szLinksysSession.set_WAN_netmaskcCs|�dd|�dS)NrZrouterIPrTrUrrr�set_WAN_gateway_address�sz&LinksysSession.set_WAN_gateway_addresscCs|�ddd||�dS)Nr�dns�ABCrT�r
�indexrErrr�set_DNS_server�szLinksysSession.set_DNS_servercCs$|j�dd|�|j�dd|�dS)NrZ	sysPasswdZsysPasswdConfirmr=)r
�strrrr�set_password�szLinksysSession.set_passwordcCs|�dd�dS)NrZ	UPnP_Workr[r rrr�set_UPnP�szLinksysSession.set_UPnPcCs|j�dd�dS)NrZFactoryDefaultsr=rrrr�reset�szLinksysSession.resetcCs*|r|j�ddd�n|j�ddd�dS)N�DHCP.htmZ
dhcpStatus�Enable�Disabler=r rrr�set_DHCP�szLinksysSession.set_DHCPcCs|j�ddt|��dS)NroZdhcpS4�rr>rk�r
�valrrr�set_DHCP_starting_IP�sz#LinksysSession.set_DHCP_starting_IPcCs|j�ddt|��dS)NroZdhcpLenrsrtrrr�set_DHCP_users�szLinksysSession.set_DHCP_userscCs|j�ddt|��dS)NroZ	leaseTimersrtrrr�set_DHCP_lease_time�sz"LinksysSession.set_DHCP_lease_timecCs|�ddd||�dS)NrorfrgrTrhrrr�set_DHCP_DNS_server�sz"LinksysSession.set_DHCP_DNS_servercCs*|r|j�ddd�n|j�ddd�dS)NzLog.htmZrLogrprqr=r rrr�set_logging�szLinksysSession.set_loggingcCs|j�ddt|��dS)NroZ	trapAddr3rsrtrrr�set_log_address�szLinksysSession.set_log_addresscCs�|jr�g}|��|jD]V\}}}|�|�|j|�|�dkr`td|tj�|j	|�f�qq|�
||f�qg|_t�|j	�}|�
|j�|�dt|��|��dS)z+Write configuration changes to the Linksys.rWz6linksys: field %s not found where expected in page %s!z
Gozila.cgiN)rr/r.r�findr	r(r)r*rr>r#r$r"rr%�tupler+)r
�fieldsr,�fieldr?Ztransactionrrr�	configure�s
zLinksysSession.configureN)0rrrrIZWAN_CONNECT_AUTOZWAN_CONNECT_STATICZWAN_CONNECT_PPOEZWAN_CONNECT_RASZWAN_CONNECT_PPTPZWAN_CONNECT_HEARTBEATr'rr"r.r/r9r;r@rHrJrLrMrNrQrRrVrZr\r]r^r_r`rbrcrdrerjrlrmrnrrrvrwrxryrzr{r�rrrrr-sd�r�__main__c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`da�Z3dbdc�Z4ddde�Z5dfdg�Z6dhdi�Z7djdk�Z8dldm�Z9dndo�Z:dpdq�Z;drds�Z<dtdu�Z=dvdw�Z>dxdy�Z?dzd{�Z@d|d}�ZAd~d�ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�S)��LinksysInterpreterz:Interpret commands to perform LinkSys programming actions.cCsHtj�|�t�|_t�d�r6td�|jjd|_	nd|_	td�dS)NrzType ? or `help' for help.�: rZBar1)
�cmd�Cmdrr�sessionr(�isatty�printr�promptrrrrr�s
zLinksysInterpreter.__init__cCs8|��dkr|d�n|��dkr,|d�ntd�dS)N)�on�enable�yesT)�off�disable�noFzlinksys: unknown switch valuer)�stripr	)r
�func�linerrr�flag_command�s

zLinksysInterpreter.flag_commandcCs>|��}|r.||j_|j��|jjd|_nt|jj�dS)Nr�r)r�r�rr/r�r�)r
r�Znewhostrrr�
do_connect�s
zLinksysInterpreter.do_connectcCstd�td�td�dS)Nz!Usage: connect [<hostname-or-IP>]z+Connect to a Linksys by name or IP address.z0If no argument is given, print the current host.�r�rrrr�help_connect�szLinksysInterpreter.help_connectcCsd|j�d�d|jjkr`td|j���td|j���td|j���td|j���td�dS)Nrz	Firmware:zLAN MAC:z
Wireless MAC:zWAN MAC:rAr)r�r.rr�rJrLrMrN�r
r�rrr�	do_statusszLinksysInterpreter.do_statuscCs$td�td�td�td�dS)Nz
Usage: statusz3The status command shows the status of the Linksys.z2It is mainly useful as a sanity check to make surez the box is responding correctly.r�rrrr�help_statusszLinksysInterpreter.help_statuscCs|�|jj|�dSr)r�r�r"r�rrr�
do_verboseszLinksysInterpreter.do_verbosecCstd�td�dS)Nz-Usage: verbose {on|off|enable|disable|yes|no}z!Enables display of HTTP requests.r�rrrr�help_verboseszLinksysInterpreter.help_verbosecCs|j�|�dS�Nr)r�rQr�rrr�do_hostszLinksysInterpreter.do_hostcCstd�td�dS)NzUsage: host <hostname>z-Sets the Host field to be queried by the ISP.r�rrrr�	help_hostszLinksysInterpreter.help_hostcCstd�|j�|�dS)NzUsage: host <domainname>r)r�r�rRr�rrr�	do_domainszLinksysInterpreter.do_domaincCstd�dS)Nz/Sets the Domain field to be queried by the ISP.r�rrrr�help_domain#szLinksysInterpreter.help_domaincCs|j�|�dSr�)r�rVr�rrr�do_lan_address&sz!LinksysInterpreter.do_lan_addresscCstd�td�dS)NzUsage: lan_address <ip-address>zSets the LAN IP address.r�rrrr�help_lan_address)sz#LinksysInterpreter.help_lan_addresscCs|j�|�dSr�)r�rZr�rrr�do_lan_netmask-sz!LinksysInterpreter.do_lan_netmaskcCstd�td�dS)NzUsage: lan_netmask <ip-mask>�Sets the LAN subnetwork mask.r�rrrr�help_lan_netmask0sz#LinksysInterpreter.help_lan_netmaskcCs|�|jj|�dSr�)r�r�r\r�rrr�do_wireless4szLinksysInterpreter.do_wirelesscCstd�td�dS)Nz.Usage: wireless {on|off|enable|disable|yes|no}z.Switch to enable or disable wireless features.r�rrrr�
help_wireless7sz LinksysInterpreter.help_wirelesscCs|j�|�dSr�)r�r]r�rrr�do_ssid;szLinksysInterpreter.do_ssidcCstd�td�dS)NzUsage: ssid <string>z.Sets the SSID used to control wireless access.r�rrrr�	help_ssid>szLinksysInterpreter.help_ssidcCs|�|jj|�dSr�)r�r�r^r�rrr�do_ssid_broadcastBsz$LinksysInterpreter.do_ssid_broadcastcCstd�td�dS)Nz4Usage: ssid_broadcast {on|off|enable|disable|yes|no}z+Switch to enable or disable SSID broadcast.r�rrrr�help_ssid_broadcastEsz&LinksysInterpreter.help_ssid_broadcastcCs|j�|�dSr�)r�r_r�rrr�
do_channelIszLinksysInterpreter.do_channelcCstd�td�dS)NzUsage: channel <number>zSets the wireless channel.r�rrrr�help_channelLszLinksysInterpreter.help_channelcCs|�|jj|�dSr�)r�r�r`r�rrr�do_wepPszLinksysInterpreter.do_wepcCstd�td�dS)Nz)Usage: wep {on|off|enable|disable|yes|no}z)Switch to enable or disable WEP security.r�rrrr�help_wepSszLinksysInterpreter.help_wepcCsFz$td|�����}|j�|�Wntk
r@td�YnXdS)NzLinksysSession.WAN_CONNECT_z!linksys: unknown connection type.r)�evalr��upperr�rbrYr	)r
r�rarrr�do_wan_typeWszLinksysInterpreter.do_wan_typecCstd�td�dS)Nz5Usage: wan_type {auto|static|ppoe|ras|pptp|heartbeat}zSet the WAN connection type.r�rrrr�
help_wan_type^sz LinksysInterpreter.help_wan_typecCs|j�|�dSr�)r�rcr�rrr�do_wan_addressbsz!LinksysInterpreter.do_wan_addresscCstd�td�dS)NzUsage: wan_address <ip-address>zSets the WAN IP address.r�rrrr�help_wan_addressesz#LinksysInterpreter.help_wan_addresscCs|j�|�dSr�)r�rdr�rrr�do_wan_netmaskisz!LinksysInterpreter.do_wan_netmaskcCstd�td�dS)NzUsage: wan_netmask <ip-mask>zSets the WAN subnetwork mask.r�rrrr�help_wan_netmasklsz#LinksysInterpreter.help_wan_netmaskcCs|j�|�dSr�)r�Zset_WAN_gatewayr�rrr�do_wan_gatewaypsz!LinksysInterpreter.do_wan_gatewaycCstd�td�dS)NzUsage: wan_gateway <ip-address>r�r�rrrr�help_wan_gatewayssz#LinksysInterpreter.help_wan_gatewaycCs4|��\}}|dkr(|j�t|�|�ntd�dS�N)rrrz$linksys: server index out of bounds.r)rBr�rjr�r	�r
r�ri�addressrrr�do_dnsws
zLinksysInterpreter.do_dnscCstd�td�dS)NzUsage: dns {1|2|3} <ip-mask>z:Sets a primary, secondary, or tertiary DNS server address.r�rrrr�help_dns~szLinksysInterpreter.help_dnscCs|j�|�dSr�)r�rlr�rrr�do_password�szLinksysInterpreter.do_passwordcCstd�td�dS)NzUsage: password <string>zSets the router password.r�rrrr�
help_password�sz LinksysInterpreter.help_passwordcCs|�|jj|�dSr�)r�r�rmr�rrr�do_upnp�szLinksysInterpreter.do_upnpcCstd�td�dS)Nz*Usage: upnp {on|off|enable|disable|yes|no}z4Switch to enable or disable Universal Plug and Play.r�rrrr�	help_upnp�szLinksysInterpreter.help_upnpcCs|j��dSr)r�rnr�rrr�do_reset�szLinksysInterpreter.do_resetcCstd�td�dS)NzUsage: resetz+Reset Linksys settings to factory defaults.r�rrrr�
help_reset�szLinksysInterpreter.help_resetcCs|�|jj|�dSr)r�r�rrr�rrr�do_dhcp�szLinksysInterpreter.do_dhcpcCstd�td�dS)Nz*Usage: dhcp {on|off|enable|disable|yes|no}z*Switch to enable or disable DHCP features.r�rrrr�	help_dhcp�szLinksysInterpreter.help_dhcpcCs|j�|�dSr)r�rvr�rrr�
do_dhcp_start�sz LinksysInterpreter.do_dhcp_startcCstd�td�dS)NzUsage: dhcp_start <number>z'Set the start address of the DHCP pool.r�rrrr�help_dhcp_start�sz"LinksysInterpreter.help_dhcp_startcCs|j�|�dSr)r�rwr�rrr�
do_dhcp_users�sz LinksysInterpreter.do_dhcp_userscCstd�td�dS)NzUsage: dhcp_users <number>�9Set number of address slots to allocate in the DHCP pool.r�rrrr�help_dhcp_users�sz"LinksysInterpreter.help_dhcp_userscCs|j�|�dSr)r�Zset_DHCP_leaser�rrr�
do_dhcp_lease�sz LinksysInterpreter.do_dhcp_leasecCstd�td�dS)NzUsage: dhcp_lease <number>r�r�rrrr�help_dhcp_lease�sz"LinksysInterpreter.help_dhcp_leasecCs4|��\}}|dkr(|j�t|�|�ntd�dSr�)rBr�ryr�r	r�rrr�do_dhcp_dns�s
zLinksysInterpreter.do_dhcp_dnscCstd�td�dS)Nz!Usage: dhcp_dns {1|2|3} <ip-mask>z8Sets primary, secondary, or tertiary DNS server address.r�rrrr�
help_dhcp_dns�sz LinksysInterpreter.help_dhcp_dnscCs|�|jj|�dSr)r�r�rzr�rrr�
do_logging�szLinksysInterpreter.do_loggingcCstd�td�dS)Nz-Usage: logging {on|off|enable|disable|yes|no}z,Switch to enable or disable session logging.r�rrrr�help_logging�szLinksysInterpreter.help_loggingcCs|j�|�dSr)r�Zset_Log_addressr�rrr�do_log_address�sz!LinksysInterpreter.do_log_addresscCstd�td�dS)NzUsage: log_address <number>z1Set the last quad of the address to which to log.r�rrrr�help_log_address�sz#LinksysInterpreter.help_log_addresscCs|j��dSr�)r�r�r�rrr�do_configure�s
zLinksysInterpreter.do_configurecCstd�td�dS)NzUsage: configurez(Writes the configuration to the Linksys.r�rrrr�help_configure�sz!LinksysInterpreter.help_configurecCst|jj�dSr)r�r�rr�rrr�do_cache�szLinksysInterpreter.do_cachecCstd�td�dS)NzUsage: cachezDisplay the page cache.r�rrrr�
help_cache�szLinksysInterpreter.help_cachecCsdSr0rr�rrr�do_quit�szLinksysInterpreter.do_quitcCstd�td�dS)Nz2The quit command ends your linksys session withoutz-writing configuration changes to the Linksys.r�r�rrr�	help_quit�szLinksysInterpreter.help_quitcCstd�|j��dS)Nrr1)r�r�r�r�rrr�do_EOF�s
zLinksysInterpreter.do_EOFcCstd�td�dS)Nz7The EOF command writes the configuration to the linksyszand ends your session.r�rrrr�help_EOF�szLinksysInterpreter.help_EOFcCst�|�dS)z5Pass the command through to be executed by the shell.r)r(�systemr�rrr�default�s
zLinksysInterpreter.defaultcCstd�td�dS)Nz/On-line help is available through this command.z"? is a convenience alias for help.r�rrrr�	help_help�szLinksysInterpreter.help_helpcCstd�dS)Na�
This program supports changing the settings on Linksys blue-box routers.  This
capability may come in handy when they freeze up and have to be reset.  Though
it can be used interactively (and will command-prompt when standard input is a
terminal) it is really designed to be used in batch mode. Commands are taken
from the command line first, then standard input.

By default, it is assumed that the Linksys is at http://192.168.1.1, the
default LAN address.  You can connect to a different address or IP with the
'connect' command.  Note that your .netrc must contain correct user/password
credentials for the router.  The entry corresponding to the defaults is:

machine 192.168.1.1
    login ""
    password admin

Most commands queue up changes but don't actually send them to the Linksys.
You can force pending changes to be written with 'configure'.  Otherwise, they
will be shipped to the Linksys at the end of session (e.g.  when the program
running in batch mode encounters end-of-file or you type a control-D).  If you
end the session with `quit', pending changes will be discarded.

For more help, read the topics 'wan', 'lan', and 'wireless'.r�rrrr�help_introduction�sz$LinksysInterpreter.help_introductioncCstd�dS)Nz�The `lan_address' and `lan_netmask' commands let you set the IP location of
the Linksys on your LAN, or inside.  Normally you'll want to leave these
untouched.r�rrrr�help_lanszLinksysInterpreter.help_lancCstd�dS)Na{The WAN commands become significant if you are using the BEFSR41 or any of
the other Linksys boxes designed as DSL or cable-modem gateways.  You will
need to use `wan_type' to declare how you expect to get your address.

If your ISP has issued you a static address, you'll need to use the
`wan_address', `wan_netmask', and `wan_gateway' commands to set the address
of the router as seen from the WAN, the outside. In this case you will also
need to use the `dns' command to declare which remote servers your DNS
requests should be forwarded to.

Some ISPs may require you to set host and domain for use with dynamic-address
allocation.r�rrrr�help_wanszLinksysInterpreter.help_wancCstd�dS)NzWThe channel, ssid, ssid_broadcast, wep, and wireless commands control
wireless routing.r�rrrr�help_wireless_descsz%LinksysInterpreter.help_wireless_desccCstd�td�td�dS)Nz8Switches may be turned on with 'on', 'enable', or 'yes'.z:Switches may be turned off with 'off', 'disable', or 'no'.z2Switch commands include: wireless, ssid_broadcast.r�rrrr�
help_switchessz LinksysInterpreter.help_switchescCstd�td�td�dS)Nz/An address argument must be a valid IP address;z-four decimal numbers separated by dots, each zbetween 0 and 255.r�rrrr�help_addresses!sz!LinksysInterpreter.help_addressescCsdSrrrrrr�	emptyline&szLinksysInterpreter.emptylineN)Mrrr�__doc__rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s�
			r�r1FTz	linksys: )rr2r#�
exceptionsr	�	Exceptionr
rrr(r�r�r��interpreter�argvrZonecmd�fatalZcmdloop�exc_infor�messager�rrrr�<module>#s( 1K

?>