Skip to content

vpsroot.sh fix syntax err #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 31 additions & 58 deletions ssh/ram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def std_exceptions(etype, value, tb):
sys.excepthook = sys.__excepthook__
if issubclass(etype, KeyboardInterrupt):
pass
elif issubclass(etype, IOError) and value.errno == errno.EPIPE:
pass
else:
elif not issubclass(etype, IOError) or value.errno != errno.EPIPE:
sys.__excepthook__(etype, value, tb)
sys.excepthook = std_exceptions

Expand All @@ -104,10 +102,7 @@ have_swap_pss = 0
class Proc:
def __init__(self):
uname = os.uname()
if uname[0] == "FreeBSD":
self.proc = '/compat/linux/proc'
else:
self.proc = '/proc'
self.proc = '/compat/linux/proc' if uname[0] == "FreeBSD" else '/proc'

def path(self, *args):
return os.path.join(self.proc, *(str(a) for a in args))
Expand All @@ -120,8 +115,7 @@ class Proc:
return open(self.path(*args), errors='ignore')
except (IOError, OSError):
val = sys.exc_info()[1]
if (val.errno == errno.ENOENT or # kernel thread or process gone
val.errno == errno.EPERM):
if val.errno in [errno.ENOENT, errno.EPERM]:
raise LookupError
raise

Expand Down Expand Up @@ -194,7 +188,7 @@ def parse_options():


def help():
help_msg = 'Usage: ps_mem [OPTION]...\n' \
return 'Usage: ps_mem [OPTION]...\n' \
'Show program core memory usage\n' \
'\n' \
' -h, -help Show this help\n' \
Expand All @@ -208,8 +202,6 @@ def help():
' -w <N> Measure and show process memory every'\
' N seconds\n'

return help_msg


# (major,minor,release)
def kernel_ver():
Expand Down Expand Up @@ -264,20 +256,20 @@ def getMemStats(pid):
elif line.startswith("SwapPss:"):
have_swap_pss = 1
Swap_pss_lines.append(line)
Shared = sum([int(line.split()[1]) for line in Shared_lines])
Private = sum([int(line.split()[1]) for line in Private_lines])
Shared = sum(int(line.split()[1]) for line in Shared_lines)
Private = sum(int(line.split()[1]) for line in Private_lines)
#Note Shared + Private = Rss above
#The Rss in smaps includes video card mem etc.
if have_pss:
pss_adjust = 0.5 # add 0.5KiB as this avg error due to truncation
Pss = sum([float(line.split()[1])+pss_adjust for line in Pss_lines])
Pss = sum(float(line.split()[1])+pss_adjust for line in Pss_lines)
Shared = Pss - Private
# Note that Swap = Private swap + Shared swap.
Swap = sum([int(line.split()[1]) for line in Swap_lines])
Swap = sum(int(line.split()[1]) for line in Swap_lines)
if have_swap_pss:
# The kernel supports SwapPss, that shows proportional swap share.
# Note that Swap - SwapPss is not Private Swap.
Swap_pss = sum([int(line.split()[1]) for line in Swap_pss_lines])
Swap_pss = sum(int(line.split()[1]) for line in Swap_pss_lines)
elif (2,6,1) <= kernel_ver() <= (2,6,9):
Shared = 0 #lots of overestimation, but what can we do?
Private = Rss
Expand All @@ -301,8 +293,7 @@ def getCmdName(pid, split_args, discriminate_by_pid):
path = path.split('\0')[0]
except OSError:
val = sys.exc_info()[1]
if (val.errno == errno.ENOENT or # either kernel thread or process gone
val.errno == errno.EPERM):
if val.errno in [errno.ENOENT, errno.EPERM]:
raise LookupError
raise

Expand All @@ -312,14 +303,10 @@ def getCmdName(pid, split_args, discriminate_by_pid):
path = path[:-10]
if os.path.exists(path):
path += " [updated]"
elif os.path.exists(cmdline[0]):
path = f'{cmdline[0]} [updated]'
else:
#The path could be have prelink stuff so try cmdline
#which might have the full path present. This helped for:
#/usr/libexec/notification-area-applet.#prelink#.fX7LCT (deleted)
if os.path.exists(cmdline[0]):
path = cmdline[0] + " [updated]"
else:
path += " [deleted]"
path += " [deleted]"
exe = os.path.basename(path)
cmd = proc.open(pid, 'status').readline()[6:-1]
if exe.startswith(cmd):
Expand All @@ -338,21 +325,17 @@ def getCmdName(pid, split_args, discriminate_by_pid):
#The following matches "du -h" output
#see also human.py
def human(num, power="Ki", units=None):
if units is None:
powers = ["Ki", "Mi", "Gi", "Ti"]
while num >= 1000: #4 digits
num /= 1024.0
power = powers[powers.index(power)+1]
return "%.1f %sB" % (num, power)
else:
if units is not None:
return "%.f" % ((num * 1024) / units)
powers = ["Ki", "Mi", "Gi", "Ti"]
while num >= 1000: #4 digits
num /= 1024.0
power = powers[powers.index(power)+1]
return "%.1f %sB" % (num, power)


def cmd_with_count(cmd, count):
if count > 1:
return "%s (%u)" % (cmd, count)
else:
return cmd
return "%s (%u)" % (cmd, count) if count > 1 else cmd

#Warn of possible inaccuracies
#2 = accurate & can total
Expand All @@ -364,15 +347,10 @@ def shared_val_accuracy():
kv = kernel_ver()
pid = os.getpid()
if kv[:2] == (2,4):
if proc.open('meminfo').read().find("Inact_") == -1:
return 1
return 0
return 1 if proc.open('meminfo').read().find("Inact_") == -1 else 0
elif kv[:2] == (2,6):
if os.path.exists(proc.path(pid, 'smaps')):
if proc.open(pid, 'smaps').read().find("Pss:")!=-1:
return 2
else:
return 1
return 2 if proc.open(pid, 'smaps').read().find("Pss:")!=-1 else 1
if (2,6,1) <= kv <= (2,6,9):
return -1
return 0
Expand Down Expand Up @@ -440,12 +418,9 @@ def get_memory_usage(pids_to_show, split_args, discriminate_by_pid,
private, shared, mem_id, swap, swap_pss = getMemStats(pid)
except RuntimeError:
continue #process gone
if shareds.get(cmd):
if have_pss: #add shared portion of PSS together
shareds[cmd] += shared
elif shareds[cmd] < shared: #just take largest shared val
shareds[cmd] = shared
else:
if shareds.get(cmd) and have_pss: #add shared portion of PSS together
shareds[cmd] += shared
elif shareds.get(cmd) and shareds[cmd] < shared or not shareds.get(cmd): #just take largest shared val
shareds[cmd] = shared
cmds[cmd] = cmds.setdefault(cmd, 0) + private
if cmd in count:
Expand Down Expand Up @@ -548,13 +523,12 @@ def verify_environment():
kernel_ver()
except (IOError, OSError):
val = sys.exc_info()[1]
if val.errno == errno.ENOENT:
sys.stderr.write(
"Couldn't access " + proc.path('') + "\n"
"Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
sys.exit(2)
else:
if val.errno != errno.ENOENT:
raise
sys.stderr.write(
"Couldn't access " + proc.path('') + "\n"
"Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
sys.exit(2)

def main():
split_args, pids_to_show, watch, only_total, discriminate_by_pid, \
Expand Down Expand Up @@ -582,8 +556,7 @@ def main():

sys.stdout.flush()
time.sleep(watch)
else:
sys.stdout.write('Process does not exist anymore.\n')
sys.stdout.write('Process does not exist anymore.\n')
except KeyboardInterrupt:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion vpsroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Akun Root (Akun Utama)
Ip address = $(curl -Ls http://ipinfo.io/ip)
Username = root
Password = $pwe
============================================
============================================"
echo "";
exit;
12 changes: 4 additions & 8 deletions websocket/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, socClient, server, addr):
self.client = socClient
self.client_buffer = ''
self.server = server
self.log = 'Connection: ' + str(addr)
self.log = f'Connection: {str(addr)}'

def close(self):
try:
Expand Down Expand Up @@ -147,7 +147,7 @@ def run(self):
self.server.removeConn(self)

def findHeader(self, head, header):
aux = head.find(header + ': ')
aux = head.find(f'{header}: ')

if aux == -1:
return ''
Expand All @@ -167,19 +167,15 @@ def connect_target(self, host):
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = sys.argv[1]

port = 443 if self.method=='CONNECT' else sys.argv[1]
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]

self.target = socket.socket(soc_family, soc_type, proto)
self.targetClosed = False
self.target.connect(address)

def method_CONNECT(self, path):
self.log += ' - CONNECT ' + path
self.log += f' - CONNECT {path}'

self.connect_target(path)
self.client.sendall(RESPONSE)
Expand Down
12 changes: 4 additions & 8 deletions websocket/ws-nontls
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ConnectionHandler(threading.Thread):
self.client = socClient
self.client_buffer = ''
self.server = server
self.log = 'Connection: ' + str(addr)
self.log = f'Connection: {str(addr)}'

def close(self):
try:
Expand Down Expand Up @@ -147,7 +147,7 @@ class ConnectionHandler(threading.Thread):
self.server.removeConn(self)

def findHeader(self, head, header):
aux = head.find(header + ': ')
aux = head.find(f'{header}: ')

if aux == -1:
return ''
Expand All @@ -167,19 +167,15 @@ class ConnectionHandler(threading.Thread):
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = sys.argv[1]

port = 443 if self.method=='CONNECT' else sys.argv[1]
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]

self.target = socket.socket(soc_family, soc_type, proto)
self.targetClosed = False
self.target.connect(address)

def method_CONNECT(self, path):
self.log += ' - CONNECT ' + path
self.log += f' - CONNECT {path}'

self.connect_target(path)
self.client.sendall(RESPONSE)
Expand Down
12 changes: 4 additions & 8 deletions websocket/ws-ovpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, socClient, server, addr):
self.client = socClient
self.client_buffer = ''
self.server = server
self.log = 'Connection: ' + str(addr)
self.log = f'Connection: {str(addr)}'

def close(self):
try:
Expand Down Expand Up @@ -147,7 +147,7 @@ def run(self):
self.server.removeConn(self)

def findHeader(self, head, header):
aux = head.find(header + ': ')
aux = head.find(f'{header}: ')

if aux == -1:
return ''
Expand All @@ -167,19 +167,15 @@ def connect_target(self, host):
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = sys.argv[1]

port = 443 if self.method=='CONNECT' else sys.argv[1]
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]

self.target = socket.socket(soc_family, soc_type, proto)
self.targetClosed = False
self.target.connect(address)

def method_CONNECT(self, path):
self.log += ' - CONNECT ' + path
self.log += f' - CONNECT {path}'

self.connect_target(path)
self.client.sendall(RESPONSE)
Expand Down
12 changes: 4 additions & 8 deletions websocket/ws-tls
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ConnectionHandler(threading.Thread):
self.client = socClient
self.client_buffer = ''
self.server = server
self.log = 'Connection: ' + str(addr)
self.log = f'Connection: {str(addr)}'

def close(self):
try:
Expand Down Expand Up @@ -147,7 +147,7 @@ class ConnectionHandler(threading.Thread):
self.server.removeConn(self)

def findHeader(self, head, header):
aux = head.find(header + ': ')
aux = head.find(f'{header}: ')

if aux == -1:
return ''
Expand All @@ -167,19 +167,15 @@ class ConnectionHandler(threading.Thread):
port = int(host[i+1:])
host = host[:i]
else:
if self.method=='CONNECT':
port = 443
else:
port = sys.argv[1]

port = 443 if self.method=='CONNECT' else sys.argv[1]
(soc_family, soc_type, proto, _, address) = socket.getaddrinfo(host, port)[0]

self.target = socket.socket(soc_family, soc_type, proto)
self.targetClosed = False
self.target.connect(address)

def method_CONNECT(self, path):
self.log += ' - CONNECT ' + path
self.log += f' - CONNECT {path}'

self.connect_target(path)
self.client.sendall(RESPONSE)
Expand Down