403Webshell
Server IP : 61.19.30.66  /  Your IP : 216.73.216.15
Web Server : Apache/2.2.22 (Ubuntu)
System : Linux klw 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64
User : www-data ( 33)
PHP Version : 5.3.10-1ubuntu3.48
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : ON  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/python2.7/dist-packages/ufw/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python2.7/dist-packages/ufw/util.pyc
ó
¢¢^Oc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZeZ
d„Zd„Zd„Zd„Zd„Zd	d
„Zd„Zd„Zd
„Zd„Zed„Zd„Zd„Zed„Zd„Ze	jd„Zd„Z d„Z!d„Z"d„Z#ej$ƒd„Z%ej$ƒd„Z&d„Z'd„Z(d„Z)d„Z*d„Z+d „Z,d!„Z-d"d#„Z.d$„Z/ed%„Z0d&„Z1d'„Z2d(„Z3d)„Z4d*„Z5dS(+s"util.py: utility functions for ufwiÿÿÿÿN(tmkstempcCs£d}ytj|ƒWntk
r-‚nXytj|dƒd}Wntk
r[nXy/tj|dƒ|dkr„d}nd}Wntk
ržnX|S(s8Get the protocol for a specified port from /etc/servicestttcptudptany(tsockett
getservbynamet	Exception(tporttproto((s,/usr/lib/python2.7/dist-packages/ufw/util.pytget_services_proto!s$


	

cCsyd}d}|jdƒ}t|ƒdkr@|d}d}n/t|ƒdkri|d}|d}nt‚||fS(sParse port or port and protocolRt/iiRi(tsplittlent
ValueError(tp_strRR	ttmp((s,/usr/lib/python2.7/dist-packages/ufw/util.pytparse_port_proto;s
	

cCsÅtjstdƒtSt|ƒdks<tjd|ƒr@tS|jdƒ}ytjtj	|dƒWnt
k
r~tSXt|ƒdkr•tSt|ƒdkrÁt|dtƒsÁtSntS(sVerifies if valid IPv6 addresss"python does not have IPv6 support.i+s^[a-fA-F0-9:\./]+$Riii(
Rthas_ipv6twarntFalseR
tretmatchRt	inet_ptontAF_INET6Rt_valid_cidr_netmasktTrue(taddrtnet((s,/usr/lib/python2.7/dist-packages/ufw/util.pytvalid_address6Ks 	
%
cCsÅt|ƒdks%tjd|ƒr)tS|jdƒ}y2tjtj|dƒt|dtƒsitSWnt	k
r~tSXt|ƒdkr•tSt|ƒdkrÁt
|dtƒsÁtSntS(sVerifies if valid IPv4 addressis^[0-9\./]+$Riii(R
RRRRRRtAF_INETt_valid_dotted_quadsRt
valid_netmaskR(RR((s,/usr/lib/python2.7/dist-packages/ufw/util.pytvalid_address4es%
cCst||ƒpt||ƒS(s(Verifies if valid cidr or dotted netmask(RR(tnmtv6((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR }sRcCsX|dkrt|ƒS|dkr,t|ƒS|dkrNt|ƒpMt|ƒSt‚dS(sValidate IP addressest6t4RN(RR!R(Rtversion((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt
valid_addressˆs

c	
Csõg}t}d}tj}|r3d}tj}nd|kr¢|jdƒ}|rn|ddkrn|d=q¯|r¯|ddks•|ddkr¯|d=q¯n
|j|ƒ|r
t|ƒdkr
t|d|ƒr
yt|d|ƒ|d<Wq
t	k
r	q
Xn|d	}tj
|tj||ƒƒ}||d	krNt}nt|ƒdkr¿|d|d7}|s¿t
|ƒ}||kr¼d
||f}t|ƒ|}t}q¼q¿nt||ƒsëd|}t|ƒt‚n||fS(sÎConvert address to standard form. Use no netmask for IP addresses. If
       netmask is specified and not all 1's, for IPv4 use cidr if possible,
       otherwise dotted netmask and for IPv6, use cidr.
    R%R$Rit128t32s255.255.255.255iisUsing '%s' for address '%s'sInvalid address '%s'(RRRRRtappendR
Rt_dotted_netmask_to_cidrRt	inet_ntopRRt_address4_to_networktdebugR'R(	torigR#RtchangedR&ts_typeRtnetworktdbg_msg((s,/usr/lib/python2.7/dist-packages/ufw/util.pytnormalize_address”sJ	
'

,

	


	cCs.yt|dƒ}Wntk
r)‚nX|S(s"Opens the specified file read-onlytr(topenR(tfnR/((s,/usr/lib/python2.7/dist-packages/ufw/util.pytopen_file_readËs

cCs{yt|ƒ}Wntk
r&‚nXytƒ\}}Wntk
rZ|jƒ‚nXi|d6|d6|d6|d6S(s=Opens the specified file read-only and a tempfile read-write.R/torignameRttmpname(R8RRtclose(R7R/RR:((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt
open_filesÕs


cCs\|dkrdS|s+ttjdƒ‚ntj||ƒdkrXttjdƒ‚ndS(s~Write to the file descriptor and error out of 0 bytes written. Intended
       to be used with open_files() and close_files().RNsNot a valid file descriptoris"Could not write to file descriptor(tOSErrorterrnotENOENTtostwritetEIO(tfdtout((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt
write_to_fileåscCs£|djƒtj|dƒ|rsy4tj|d|dƒtj|d|dƒWqstk
ro‚qsXnytj|dƒWntk
rž‚nXdS(suCloses the specified files (as returned by open_files), and update
       original file with the temporary file.
    R/RR9R:N(R;R@tshutiltcopystattcopyRtunlinkR=(tfnstupdate((s,/usr/lib/python2.7/dist-packages/ufw/util.pytclose_filesòs


cCsot|ƒy%tj|dtjdtjƒ}Wn tk
rQ}dt|ƒgSX|jƒd}|j|gS(s!Try to execute the given command.tstdouttstderrii(	R.t
subprocesstPopentPIPEtSTDOUTR=tstrtcommunicatet
returncode(tcommandtsptexRD((s,/usr/lib/python2.7/dist-packages/ufw/util.pytcmds
cCsty4tj|dtjƒ}tj|d|jƒ}Wn tk
rV}dt|ƒgSX|jƒd}|j|gS(s#Try to pipe command1 into command2.RMtstdinii(RORPRQRMR=RSRTRU(tcommand1tcommand2tsp1tsp2RXRD((s,/usr/lib/python2.7/dist-packages/ufw/util.pytcmd_pipescCsCytjd|IJWntk
r(nX|r?tjdƒndS(sPrint error message and exits	ERROR: %siN(tsysRNtIOErrortexit(RDtdo_exit((s,/usr/lib/python2.7/dist-packages/ufw/util.pyterrors
cCs-ytjd|IJWntk
r(nXdS(sPrint warning messagesWARN: %sN(R`RNRa(RD((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR*s
cCs*y|d|IJWntk
r%nXdS(s
Print messages%sN(Ra(RDtoutput((s,/usr/lib/python2.7/dist-packages/ufw/util.pytmsg2s
cCs6tr2ytjd|IJWq2tk
r.q2XndS(sPrint debug messages	DEBUG: %sN(t	DEBUGGINGR`RNRa(RD((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR.:s

cCst|d„|jdƒƒS(s¡
    A word-wrap function that preserves existing line breaks
    and most spaces in the text. Expects that existing line
    breaks are posix newlines (
).
    cSsLd|dt|ƒ|jdƒdt|jddƒdƒ|k|fS(Ns%s%s%ss 
s
ii(R
trfindR(tlinetwordtwidth((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt<lambda>Is
4t (treduceR(ttextRk((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt	word_wrapCscCs
t|dƒS(sWord wrap to a specific widthiK(Rp(Ro((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt	wrap_textSscs&d„‰|jd‡fd†ƒdS(s$Sorts list of strings into numeric order, with text case-insensitive.
       Modifies list in place.

       Eg:
       [ '80', 'a222', 'a32', 'a2', 'b1', '443', 'telnet', '3', 'http', 'ZZZ']

       sorts to:
       ['3', '80', '443', 'a2', 'a32', 'a222', 'b1', 'http', 'telnet', 'ZZZ']
    cSs |jƒrt|ƒS|jƒS(N(tisdigittinttlower(tt((s,/usr/lib/python2.7/dist-packages/ufw/util.pyRlbstkeycs)gtjd|ƒD]}ˆ|ƒ^qS(Ns([0-9]+)(RR(tktc(tnorm(s,/usr/lib/python2.7/dist-packages/ufw/util.pyRlcsN(tsort(tlst((Rys,/usr/lib/python2.7/dist-packages/ufw/util.pyt
human_sortXs
	cCs¸yt|ƒ}Wntk
r/tdƒ‚nXtjjdt|ƒdƒ}tjj|ƒsstd|ƒ‚ny$t	|ƒj
ƒdjƒd}Wntk
r­‚nXt|ƒS(sdFinds parent process id for pid based on /proc/<pid>/stat. See
       'man 5 proc' for details.
    spid must be an integers/proctstatsCouldn't find '%s'ii(RsRRR@tpathtjoinRStisfileRatfilet	readlinesR(tmypidtpidtnametppid((s,/usr/lib/python2.7/dist-packages/ufw/util.pytget_ppidfs
$
cCsXyt|ƒ}WnZtk
r:tdƒ}t|ƒtStk
rltdƒt|ƒ}t|ƒ‚nX|dks…|dkr‰tStj	j
dt|ƒdƒ}tj	j|ƒsØtdƒ|}t|ƒ‚ny$t|ƒj
ƒdjƒd}Wn-tk
r+tdƒ|}t|ƒ‚nXtd	|ƒ|d
krJtSt|ƒSdS(s1Determine if current process is running under sshs%Couldn't find pid (is /proc mounted?)s!Couldn't find parent pid for '%s'is/procR}sCouldn't find '%s'is"Could not find executable for '%s'sunder_ssh: exe is '%s's(sshd)N(R‡Rat_RRRRSRR@R~RR€RR‚RR.Rt	under_ssh(R„R†twarn_msgterr_msgR~texe((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR‰{s0


$
cCsTd}|rd}ntjd|ƒsLt|ƒdksLt|ƒ|krPtStS(sVerifies cidr netmasksi i€s^[0-9]+$i(RRRsRR(R"R#tnum((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR¡s	7cCs|r
tStjd|ƒr‡tjd|ƒ}t|ƒdkrDtSxD|D]5}|s|t|ƒdks|t|ƒdkrKtSqKWntStS(s.Verifies dotted quad ip addresses and netmaskss^[0-9]+\.[0-9\.]+$s\.iiiÿ(RRRRR
RsR(R"R#tquadstq((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR­s
+cCsód}|rt‚nÂt||ƒs-t‚nd}ttjdtj|ƒƒdƒ}t}xKtdƒD]=}||?d@dkrŽt	}qk|ržd}Pqk|d7}qkW|dkr×|dkr×t
d|ƒ}nt||ƒsït‚n|S(s@Convert netmask to cidr. IPv6 dotted netmasks are not supported.Ris>Li iiÿÿÿÿ(RRtlongtstructtunpackRt	inet_atonRtrangeRRSR(R"R#tcidrtmbitstbitst	found_onetn((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR+Æs(		%		cCs¨d}|rt‚nwt||ƒs-t‚nd}x;tdƒD]-}|t|ƒkr@|dd|>O}q@q@Wtjtjd|ƒƒ}t||ƒs¤t‚n|S(s<Convert cidr to netmask. IPv6 dotted netmasks not supported.Rli iis>L(	RRR”RsRt	inet_ntoaR‘tpackR(R•R#R"R—R™((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt_cidr_to_dotted_netmaskìs			c	Cs+d|krtdƒ|S|jdƒ}t|ƒdksOt|dtƒrXt‚n|d}|d}|}t|tƒr®yt|tƒ}Wq®tk
rª‚q®Xnt	t
jdtj
|ƒƒdƒ}t	t
jdtj
|ƒƒdƒ}||@}tjt
jd|ƒƒ}d||fS(s8Convert an IPv4 address and netmask to a network addressRs8_address4_to_network: skipping address without a netmaskiiis>Ls%s/%s(R.RR
RRRRRœRRR‘R’RR“RšR›(	RRthosttorig_nmR"t	host_bitstnm_bitstnetwork_bitsR2((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR-s&
&	



%%
cCsd„}d|kr#tdƒ|S|jdƒ}t|ƒdksXt|dtƒrat‚n|d}|d}tjdtj	tj
|ƒƒ}d}xftd	ƒD]X}|||d
ƒ}x<td
ƒD].}	|dt||	ƒ@d|	|d
>O}qÏWq©Wd}
x;tdƒD]-}|t|ƒkr|
dd|>O}
qqW||
@}g}xFtd	ƒD]8}|j
t||dƒ|d
|d
d
!dƒƒqfWtjtj
tjd|d|d|d|d
|d|d|d|dƒ	ƒ}
d|
|fS(s8Convert an IPv6 address and netmask to a network addresscSs>djgt|dddƒD]}t||?d@ƒ^qƒS(sDecimal to binaryRiiÿÿÿÿ(RR”RS(Rtcountty((s,/usr/lib/python2.7/dist-packages/ufw/util.pytdec2binsRs8_address6_to_network: skipping address without a netmaskiiis>8Hliiii€iiiiis%s/%si(R.RR
R RRR‘R’RRRR”RsR*R,R›(RR¤Rt	orig_hosttnetmasktunpackedRŸtiR™tjR RR{R2((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt_address6_to_networks:	
&	

0
6c	Cs|jdƒ}t|ƒdks5t|d|ƒr>t‚n|d}|d}|dksj|dkrntS|}d|krË|jdƒ}t|ƒdksµt|d|ƒr¾t‚n|d}n|dksã|dkrçtS|rt|ƒst|ƒr6t‚q6n#t|ƒs-t|ƒr6t‚nt||ƒry|ryyt||ƒ}Wqyt	k
ru‚qyXn|rÈt
d||fƒjdƒd}t
d||fƒjdƒd}nFtd||fƒjdƒd}td||fƒjdƒd}||kS(s&Determine if address x is in network yRiiis0.0.0.0s::s%s/%s(RR
R RRRR!RRœRRªR-(	t
tested_addt
tested_netR#RR¥R¦taddresstorig_networkR2((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt
in_networkOsF&	

&	
	

 s/sbin/iptablescCsft|dgƒ\}}|dkr=ttjd|ƒ‚ntjd|ƒ}tjdd|dƒS(sReturn iptables versions-VisError running '%s's\ss^vRi(RYR=R>R?RRtsub(RŒtrcRDR((s,/usr/lib/python2.7/dist-packages/ufw/util.pytget_iptables_versions
cCs{t|ƒ}tƒ}x_|jƒD]Q}|jdƒrN|jdƒrNq"n|jƒ}|d}|djdƒd}tƒ}dj|djdƒd ƒ|d<|d|d	<|d
jdƒd|d<|dd
krò|d|d<n|d
jdƒd|d<|j|ƒs:tƒ||<g|||<n$||j|ƒs^g|||<n|||j|ƒq"W|S(s:Get and parse netstat the output from get_netstat_outout()RRiit:iÿÿÿÿtladdrituidiRR„t-RŒ(tget_netstat_outputtdictt
splitlinest
startswithRRthas_keyR*(R#tnetstat_outputtdRiRR	Rtitem((s,/usr/lib/python2.7/dist-packages/ufw/util.pytparse_netstat_outputŠs,	 
	$
cCs®d}|r d}tjj|ƒs=ttjd|ƒ‚nx¼t|ƒjƒD]¨}|jƒ}||dkrPdj	gt
dt|dƒdƒD]}|d||d!^q•ƒ}|djƒd	krød
|t
|djƒdƒf}qøqPqPW|dkrttjdƒ‚qn}tjtjtjƒ}y?tjtj|jƒd
tjd|d ƒƒdd!ƒ}Wn#tk
rœttjdƒ‚nXt||ƒdS(sGet IP address for interfaceRs/proc/net/if_inet6s'%s' does not existiR³iiit80s%s/%sisNo such devicei‰t256siii(R@R~texistsR=R>R?RR‚RRR”R
RtRsRatENODEVRRt
SOCK_DGRAMRštfcntltioctltfilenoR‘R›RR4(tifnameR#RtprocRiRR¨ts((s,/usr/lib/python2.7/dist-packages/ufw/util.pytget_ip_from_if°s*A-'
c
Csþt}d}t|ƒr't}d}n!t|ƒsHttjdƒ‚ntjj	|ƒsst
tjd|ƒ‚nd}|rrxxt|ƒj
ƒD]Ù}|jƒ}|djƒ}djgtdt|dƒd	ƒD]}|d||d	!^q׃}|d
jƒdkr7d|t|d
jƒd
ƒf}n||ksad|kr’t||tƒr’|}Pq’q’Wnˆx…t|ƒj
ƒD]q}d|krq…n|jdƒdjƒ}yt|tƒ}	Wntk
rßq…nX|	|kr…|}Pq…q…W|S(sGet interface for IP addresss
/proc/net/devs/proc/net/if_inet6sNo such devices'%s' does not existRiR³iiiRÀs%s/%siR(RRRR!RaR>RÃR@R~RÂR=R?RR‚RtstripRR”R
RtRsR¯RË(
RR#RÉtmatchedRiRRÈR¨ttmp_addrtip((s,/usr/lib/python2.7/dist-packages/ufw/util.pytget_if_from_ipÎsD	A&
c	Csbtjdƒ}|jƒtjdƒ}tƒ}x*|D]"}|j|ƒsSq8ntjjd|dƒ}tj	|tj
tjBƒsq8nd}y%tjtjjd|dƒƒ}Wnt
k
rËnXytj|ƒ}Wn
q8nXxk|D]c}y&tjtjj||ƒƒd}Wnt
k
r5qónXd|tjj|ƒf||<qóWq8W|S(sGet inodes of files in /procs/procs^[0-9]+$RCR¶RŒis%s/%s(R@tlistdirRzRtcompileR¸RR~RtaccesstF_OKtR_OKtreadlinkRR}tbasename(	t
proc_filestpattinodesR¨tfd_pathtexe_pathtdirsR©tinode((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt_get_proc_inodesüs4
	
%

&
(cCs²idd6dd6dd6dd6d	d
6dd6d
d6dd6dd6dd6dd6}idd6dd6dd6dd6}tjjd|ƒ}tj|tjtjBƒs¯t‚ng}t}t|ƒj	ƒ}xÞ|D]Ö}|j
ƒ}|søt}qÔn|t||ddƒ}	|j
dƒr+d}	n!|j
dƒrL|	dkrLqÔn||dj
d ƒ\}
}||d}||d}
|j|
t|dƒ||
|	fƒqÔW|S(!s=Read /proc/net/(tcp|udp)[6] file and return a list of tuples tESTABLISHEDitSYN_SENTitSYN_RECVit	FIN_WAIT1it	FIN_WAIT2it	TIME_WAITitCLOSEit
CLOSE_WAITitLAST_ACKi	tLISTENi
tCLOSINGit
local_addrtstateRµRÞs	/proc/netiRtNARR³(R@R~RRÓRÔRÕRRRR‚RRRsRºR*(tprotocolt
tcp_statestproc_net_fieldsR7R{t
skipped_firsttlinesRitfieldsRìR´RRµRÞ((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt_read_proc_net_protocol!sH



	
	)cCsNd}t|ƒdkrÑd}x[tdddƒD]G}|djgt|d|dƒD]}||d|!^qWƒ7}q1Wtdjgtdt|ƒdƒD]}|||d!jƒ^qžƒtƒd}nyg}xTgtdddƒD]}||d|!^qíD]"}|jtt|d	ƒƒƒqWtd
j|ƒt	ƒd}|S(sDConvert an address from /proc/net/(tcp|udp)* to a normalized addressRiii iþÿÿÿiR³iit.(
R
R”RR4RtRR*RSRsR(tpaddrt	convertedRR¨R©((s,/usr/lib/python2.7/dist-packages/ufw/util.pytconvert_proc_addressOsE	<7 c
CsFtƒ}ddg}|r.|ddg7}nxS|D]K}yt|ƒ||<Wq5tk
rtd|ƒ}t|ƒq5q5Xq5Wtƒ}|jƒ}|jƒd}x–|D]Ž}x…||D]y\}}	}
}}t|ƒ}
d}|j	t
|ƒƒr|t
|ƒ}n|d|d	|
|	f||
||f7}qÁWq°W|S(
s5netstat-style output, without IPv6 address truncationRRttcp6tudp6s!Could not get statistics for '%s'RR¶s%-5s %-46s %-11s %-5s %-11s %s
s%s:%s(R¸RôRRˆRRßtkeysRzRøR»Rs(R#t
proc_net_dataR	tpRŠRÚt	protocolsRÊR´RRµRÞRìRRŒ((s,/usr/lib/python2.7/dist-packages/ufw/util.pyR·bs2	


	

 	
(6t__doc__R>RÅR@RRFRR‘ROR`ttempfileRRRgR
RRR!R R'R4R8R<RERRLRYR_RdRRMRfR.RpRqR|tgetpidR‡R‰RRR+RœR-RªR¯R²R¿RËRÐRßRôRøR·(((s,/usr/lib/python2.7/dist-packages/ufw/util.pyt<module>s`						7	
		
	
							&			&			2	2		&	.	%	.	

Youez - 2016 - github.com/yon3zu
LinuXploit