528
528
self.sendLine("\tlink: %s " % pl.sock.nickname)
529
529
do_conn = do_connections
531
def do_control(self, args):
533
host, password = args
534
remote = self.factory.get_host_by_name(host)
535
remote.password = password
537
self.sendLine("Connection OK")
539
self.sendLine("Connection Failed.")
541
def do_udp(self, args):
542
self.sendLine("udp command does not work at the moment")
544
# if self.factory.TCP:
546
# self.sendLine("FAIL udp arguments")
547
# for b in iter(self.factory.bricks):
548
# if b.name == args[2]:
549
# w = PyWire(self.factory, args[1])
550
# w.set_remoteport(args[3])
551
# w.connect(b.socks[0])
554
# self.sendLine("FAIL Brick not found: %s" % args[2])
557
532
def do_python(self, args):
558
533
"""Open a python interpreter. Use ^D (^Z on windows) to exit."""
575
550
class ImagesProtocol(Protocol):
577
552
def do_list(self, parts):
580
host = self.factory.get_host_by_name(parts[0])
581
553
for img in self.factory.disk_images:
582
if len(parts) == 1 and img.host is None:
583
self.sendLine("%s,%s" % (img.name, img.path))
584
if (host is not None and img.host is not None
585
and img.host.addr[0] == host.addr[0]):
586
self.sendLine("%s,%s" % (img.name, img.path))
554
self.sendLine("%s, %s" % (img.name, img.path))
588
556
def do_files(self, parts):
590
host = self.factory.get_host_by_name(parts[0])
591
if host is not None and host.connected:
592
self.sendLine("files not works for remote hosts.")
595
# files = host.get_files_list()
598
# self.sendLine("No files found.")
603
self.sendLine("Not connected to %s" % parts[0])
605
557
dirname = self.factory.settings.get("baseimages")
606
558
for image_file in os.listdir(dirname):
607
559
if os.path.isfile(dirname + "/" + image_file):
610
562
def do_add(self, parts):
612
564
basepath = self.factory.settings.get("baseimages")
614
565
name = parts[0].replace(".", "_")
615
566
name = name.replace("/", "_")
617
host = self.factory.get_host_by_name(parts[1])
619
basepath = host.baseimages
620
if len(parts) == 2 and parts[1].find("/") > -1:
621
img = self.factory.new_disk_image(name, parts[1])
623
img = self.factory.new_disk_image(name, basepath + "/" + parts[0])
626
if host.connected is True:
627
host.send("i add " + parts[1])
567
img = self.factory.new_disk_image(name, basepath + "/" + parts[0])
630
569
def do_del(self, parts):
632
571
image = self.factory.get_image_by_name(parts[0])
633
572
if image is not None:
635
host = self.factory.get_host_by_name(parts[1])
636
if host.connected is False:
640
if host is not None and image.host != host:
642
self.factory.remove_disk_image(image)
643
# self.disk_images.remove(image)
644
if host.connected is True:
645
host.send("i del " + parts[0])
647
if image.host is not None:
649
573
self.factory.remove_disk_image(image)
650
# self.disk_images.remove(image)
652
575
def do_base(self, parts):
653
576
if not parts or parts[0] == "show":
654
self.sendLine("%s" % self.factory.settings.get("baseimages"))
577
self.sendLine(self.factory.settings.get("baseimages"))
655
578
elif parts[0] == "set" and len(parts) > 1:
658
host = self.factory.get_host_by_name(parts[2])
661
host.baseimages = str(parts[1])
663
self.factory.settings.set("baseimages", parts[1])
579
self.factory.settings.set("baseimages", parts[1])
666
582
class ConfigurationProtocol(Protocol):
676
592
# pass # TODO: show all settings
678
594
def do_set(self, args):
680
if self.factory.settings.has_option(args[0]):
683
host = self.factory.get_host_by_name(args[2])
684
if host is not None and host.connected is True:
685
host.send("cfg " + args[0] + " " + args[1])
687
self.factory.settings.set(args[0], args[1])
595
if len(args) > 1 and self.factory.settings.has_option(args[0]):
596
self.factory.settings.set(args[0], args[1])