-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
EXAMPLES = local-reader lwnbd-server | ||
CFLAGS = -I../include | ||
LDFLAGS := ../lwnbd.a | ||
BIN = local-reader lwnbd-server | ||
CFLAGS = -I../include $(CFLAGS-$@) | ||
LDLIBS := ../lwnbd.a | ||
LDFLAGS += $(LDFLAGS-$@) | ||
APP_VERSION := $(shell git describe --always --tags) | ||
CC_VERSION := "$(CC) $(shell $(CC) -dumpversion)" | ||
CFLAGS += $(CFLAGS-$@) | ||
|
||
all: $(EXAMPLES) | ||
all: $(BIN) | ||
|
||
local-reader: local-reader.o | ||
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
|
||
CFLAGS-lwnbd-server.o += $(shell pkg-config --cflags libuv) \ | ||
-DAPP_VERSION=\"$(APP_VERSION)\" \ | ||
-DCC_VERSION=\"$(CC_VERSION)\" \ | ||
-DAPP_NAME=\"lwnbd-server\" | ||
|
||
LDFLAGS-lwnbd-server += $(shell pkg-config --libs libuv) | ||
lwnbd-server: lwnbd-server.o | ||
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(shell pkg-config --libs libuv) | ||
|
||
clean: | ||
rm -f $(EXAMPLES) *.o | ||
rm -f $(BIN) *.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,51 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Sample to demonstrate usage of URI with query as a way | ||
# to send command remotely | ||
# | ||
# usage: | ||
# export TARGET_IP=192.168.1.5 | ||
# python remoteshell.py motd%3fmemset=p | ||
# ./remoteshell.py dumpmem offset=0x200 size=0x200 | ||
# | ||
# On Alpine : | ||
# echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && apk update | ||
# apk add libnbd@testing | ||
|
||
#!/usr/bin/python3 | ||
import argparse | ||
import nbd | ||
import os | ||
import sys | ||
from urllib.parse import urlunsplit, urlencode, quote, parse_qs | ||
|
||
# TODO read from cli first [-h hostname] | ||
host = os.environ['TARGET_IP'] | ||
if not host: | ||
print("no host") | ||
p = argparse.ArgumentParser(description='remote command for lwNBD', | ||
epilog='This software is part of lwNBD project https://github.com/bignaux/lwNBD') | ||
p.add_argument('query', default='list', nargs='*') | ||
p.add_argument('-t', '--target', default=os.environ['TARGET_IP'], help='hostname or IP of target') | ||
p.add_argument('-e', '--exportname', default='shell', help='name of export') | ||
p.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity') | ||
args = p.parse_args() | ||
|
||
n = len(sys.argv) | ||
if n > 1: | ||
query = sys.argv[1] | ||
if not args.target: | ||
sys.exit("You should provide a target via export TARGET_IP or --target argument") | ||
|
||
# would need encoding URI | ||
### not very happy with that parsing | ||
if args.verbose: print(args.query) | ||
query = parse_qs('&'.join(args.query), keep_blank_values=True) | ||
if args.verbose: print(query) | ||
args.query = urlencode(query, doseq=True, quote_via=quote) | ||
if args.verbose: print(args.query) | ||
# query = args.command + '=' + ' '.join(args.arguments) | ||
uri = urlunsplit(('nbd', args.target, args.exportname, args.query, '')) | ||
if args.verbose: print('Clear URI:', uri) | ||
encoded_url = quote(uri, safe=':/%=') | ||
if args.verbose: print('Request:', encoded_url) | ||
|
||
h = nbd.NBD() | ||
uri = "nbd://" + host + '/' + query | ||
|
||
h.connect_uri(uri) | ||
ret = h.pread(512, 0) | ||
h.connect_uri(encoded_url) | ||
size = h.get_size() | ||
if args.verbose: | ||
print('Response:', size, 'bytes') | ||
ret = h.pread(size, 0) | ||
s = str(ret, 'utf-8') | ||
print(s) | ||
h.shutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OBJ += plugins/command/command.o | ||
PLUGIN_COMMAND = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.