Compare commits

...

20 Commits

Author SHA1 Message Date
46b534d447 [~] Refactor 2024-07-01 08:58:47 +03:00
aba9020f34 [~] Refactor 2024-07-01 08:58:47 +03:00
8a4a8eaa32 [~] Refactor 2024-07-01 08:58:47 +03:00
67ce19ca44 [~] Refactor 2024-07-01 08:58:46 +03:00
fefee3c3ea [~] Refactor 2024-07-01 08:58:46 +03:00
9bc2752fab [~] Refactor 2024-07-01 08:58:46 +03:00
d17e9cf880 [~] Refactor 2024-07-01 08:58:45 +03:00
8dd1a9f612 [~] Refactor 2024-07-01 08:58:10 +03:00
7775cdc6a2 [~] Refactor 2024-07-01 08:58:10 +03:00
d7b8c2f974 [~] Refactor 2024-07-01 08:58:10 +03:00
b742a0ef61 [~] Refactor 2024-07-01 08:58:10 +03:00
3112e15b82 [~] Refactor 2024-07-01 08:58:10 +03:00
ccb055c766 [~] Refactor 2024-07-01 08:58:10 +03:00
5f978ac438 [~] Refactor 2024-07-01 08:58:10 +03:00
b5dc2e1d01 [~] Refactor 2024-07-01 08:58:10 +03:00
af343a1dd1 [~] Refactor 2024-07-01 08:58:10 +03:00
9c855ffd3b [~] Refactor 2024-07-01 08:58:10 +03:00
7b21f92287 [~] Refactor 2024-07-01 08:58:10 +03:00
e2bbae5b99 [~] Refactor 2024-07-01 08:58:10 +03:00
f99cf5d304 [~] Refactor 2024-07-01 08:58:10 +03:00
3 changed files with 257 additions and 25 deletions

@ -2,6 +2,7 @@
import asyncio
import enum
import threading
import shutil
import collections
import datetime
import functools
@ -22,6 +23,9 @@ import time
import traceback
logger = logging.getLogger(__name__)
def custom_notify(
title=None,
msg=None,
@ -1056,12 +1060,37 @@ def http_server(argv):
action='store_true',
default=False,
)
parser.add_option(
'--force',
dest='force',
action='store_true',
default=False,
)
parser.add_option(
'--token',
dest='token',
type=str,
default=None,
)
parser.add_option(
'--port',
dest='port',
type='int',
default=80,
)
parser.add_option(
'--no_docker',
dest='docker',
action='store_false',
default=None,
)
parser.add_option(
'-H', '--header',
dest='response_headers',
type='str',
action='append',
default=[],
)
parser.add_option(
'--host',
dest='host',
@ -1088,46 +1117,185 @@ def http_server(argv):
raise RuntimeError('invalid ip address %s' % options.host)
if options.docker is None:
options.docker = True
index_section = 'autoindex on;'
if options.public:
options.token = 'public'
location_section = 'location / {%s}' % index_section
else:
token = os.urandom(16).hex()
if options.token is None:
options.token = os.urandom(16).hex()
if options.docker:
DATA_DIR = '/usr/share/nginx'
APP_DIR = '/app'
CONF_DIR = '/etc/nginx'
else:
DATA_DIR = '/opt/nginx/%s/data/' % options.token
CONF_DIR = '/opt/nginx/%s/conf/' % options.token
APP_DIR = os.path.abspath(os.path.curdir)
if not options.public:
if not options.prefix is None:
token = options.prefix + token
print(
path = options.prefix + options.token
else:
path = options.token
logger.info(
'access url is http://%s:%d/%s/' % (
options.host,
options.port,
token,
path,
)
)
assert all([
not re.compile(
r'^[A-Za-z-]+ [a-z0-9A-Z-\.]+$'
).match(o) is None
for o in options.response_headers
])
location_section = (
'location / {'
'deny all;'
'}'
'location /%s/ {'
'alias /app/;'
'alias %s/;'
'%s'
'%s'
'}'
) % (token, index_section)
subprocess.check_call(
r'''
sudo docker run \
-p %s:%d:80 \
-u root \
-it --entrypoint=/bin/bash \
-v $PWD:/app:ro \
--log-driver none \
nginx:latest \
-c 'echo "server{listen 80; charset UTF-8; root /app; %s}" > /etc/nginx/conf.d/default.conf; nginx -g "daemon off;"'
''' % (
options.host,
options.port,
location_section,
),
shell=True)
) % (
path,
APP_DIR,
'\n'.join([
'add_header %s;' % o
for o in options.response_headers
]),
index_section
)
if options.docker:
subprocess.check_call(
r'''
sudo docker run \
-p %s:%d:80 \
-u root \
-it --entrypoint=/bin/bash \
-v $PWD:%s:ro \
--log-driver none \
nginx:latest \
-c 'echo "server{listen 80; charset UTF-8; root /app; %s}" > /etc/nginx/conf.d/default.conf; nginx -g "daemon off;"'
''' % (
options.host,
options.port,
APP_DIR,
location_section,
),
shell=True
)
else:
if os.path.exists(CONF_DIR):
assert options.force
shutil.rmtree(CONF_DIR)
if os.path.exists(DATA_DIR):
assert options.force
shutil.rmtree(DATA_DIR)
os.makedirs(CONF_DIR, exist_ok=True)
os.makedirs(
os.path.join(
CONF_DIR,
'conf.d',
),
exist_ok=True
)
os.makedirs(DATA_DIR, exist_ok=True)
with io.open(
os.path.join(CONF_DIR, 'nginx.conf'),
'w'
) as f:
f.write(r'''
events {
multi_accept on;
worker_connections 32;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
expires off;
open_file_cache off;
log_format main
'[$time_local][$remote_addr, $http_x_forwarded_for, $t1, $server_name]'
'[$request_length,$bytes_sent,$request_time]'
'[$status][$request]'
'[$http_user_agent][$http_referer]';
access_log /dev/null combined;
access_log /dev/stderr main;
include %s/conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
''' % CONF_DIR)
with io.open(
os.path.join(
CONF_DIR,
'conf.d',
'default.conf',
),
'w',
) as f:
f.write(r'''
server {
server_name %s;
listen %d;
charset UTF-8;
client_max_body_size 2K;
set $t1 $remote_addr;
if ($http_x_forwarded_for)
{
set $t1 $http_x_forwarded_for;
}
root %s;
%s
}
''' % (
options.host,
options.port,
DATA_DIR,
location_section,
))
sys.stderr.flush()
sys.stdout.flush()
os.execv(
'/usr/sbin/nginx',
[
'/usr/sbin/nginx',
'-c',
os.path.join(CONF_DIR, 'nginx.conf'),
'-p', DATA_DIR,
'-g', 'daemon off;',
],
)
def pass_ssh_osx(argv):
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
@ -3196,6 +3364,7 @@ def media_keys(argv):
def commands_cli():
logging.getLogger().setLevel(logging.INFO)
logger.setLevel(logging.INFO)
msg = None

@ -33,10 +33,50 @@ def f5_1(pattern, flags, info):
#print([pattern, flags, info])
completed_process = None
options = dict(
recursive=False,
ext=[],
)
#print('fuck')
if b'r' in flags:
while True:
ext_m = re.compile('^.([^\,]+),(.*)$').match(pattern)
if pattern[:3] in [r'\r,']:
options['recursive'] = True
pattern = pattern[3:]
elif not ext_m is None:
options['ext'].append(
ext_m[1]
)
pattern = ext_m[2]
else:
break
print([flags, pattern, options,])
try:
completed_process = subprocess.run([
'git', 'grep', '-n', '-P', pattern,
], capture_output=True,)
git_cmd = [
'git', 'grep',
'-n',
]
if options['recursive']:
git_cmd.append('--recurse-submodules')
git_cmd.extend(['-P', pattern])
if len(options['ext']) > 0:
git_cmd.extend(['--', *[
'**/*%s' % o
for o in options['ext']
]])
completed_process = subprocess.run(
git_cmd,
capture_output=True,
)
assert (
completed_process.returncode == 0 or
(

@ -19,6 +19,7 @@ set backspace=indent,eol,start
set mouse=a
au FileType netrw nmap <buffer> <LeftMouse> <LeftMouse> <CR>
au FocusLost * silent! wa
set term=xterm-256color
@ -28,12 +29,34 @@ set hls
colorscheme morning
hi MatchParen guifg=white guibg=black gui=NONE ctermfg=1 ctermbg=0
function! MakeSession()
let b:sessiondir = '.vim/'
if (filewritable(b:sessiondir) != 2)
exe 'silent !mkdir -p ' b:sessiondir
redraw!
endif
let b:filename = b:sessiondir . '/session.vim'
exe "mksession! " . b:filename
endfunction
function! LoadSession()
let b:sessiondir = '.vim/'
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe 'source ' b:sessionfile
else
echo "No session loaded."
endif
endfunction
map <Leader>w <C-w>
map <Leader>wo :py3 print('fuck')<CR>
map <Leader>z :wqa<CR>
map <Leader>m :py3 f1()<CR>
map <Leader>r :redraw!<CR>
map <Leader>s :call MakeSession()<CR>
map <Leader>l :call LoadSession()
map <Leader>cq :cq<CR>
map <Leader>f2 :py3 f2()<CR>
map <Leader>f3 :source ~/.vimrc<CR>:echo 'reloaded'<CR>