diff --git a/.gitignore b/.gitignore index 8f0270e..f246d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,11 @@ shard.lock bin drop lib + +pongd +pongc +tcpd +tcpc +websocketd +websocketc +plumberd diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..54bb4d8 --- /dev/null +++ b/Makefile @@ -0,0 +1,267 @@ +PACKAGE = 'plumberd' +VERSION = '0.1.0' + +PREFIX := /usr/local +BINDIR := $(PREFIX)/bin +LIBDIR := $(PREFIX)/lib +SHAREDIR := $(PREFIX)/share +INCLUDEDIR := $(PREFIX)/include +MANDIR := $(SHAREDIR)/man + +CC := cc +AR := ar +RANLIB := ranlib +CFLAGS := +LDFLAGS := + +Q := @ + +all: tcpd tcpc pongd pongc plumberd websocketc websocketd + @: + +tcpd: src/tcpd.cr + @echo ' CR > tcpd' + $(Q)crystal src/tcpd.cr -o 'tcpd' + + +tcpd.install: tcpd + @echo ' IN > $(BINDIR)/tcpd' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 tcpd $(DESTDIR)$(BINDIR)/tcpd + +tcpd.clean: + @echo ' RM > tcpd' + $(Q)rm -f tcpd + +tcpd.uninstall: + @echo ' RM > $(BINDIR)/tcpd' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/tcpd' + +tcpc: src/tcpc.cr + @echo ' CR > tcpc' + $(Q)crystal src/tcpc.cr -o 'tcpc' + + +tcpc.install: tcpc + @echo ' IN > $(BINDIR)/tcpc' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 tcpc $(DESTDIR)$(BINDIR)/tcpc + +tcpc.clean: + @echo ' RM > tcpc' + $(Q)rm -f tcpc + +tcpc.uninstall: + @echo ' RM > $(BINDIR)/tcpc' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/tcpc' + +pongd: src/pongd.cr + @echo ' CR > pongd' + $(Q)crystal src/pongd.cr -o 'pongd' + + +pongd.install: pongd + @echo ' IN > $(BINDIR)/pongd' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 pongd $(DESTDIR)$(BINDIR)/pongd + +pongd.clean: + @echo ' RM > pongd' + $(Q)rm -f pongd + +pongd.uninstall: + @echo ' RM > $(BINDIR)/pongd' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/pongd' + +pongc: src/pongc.cr + @echo ' CR > pongc' + $(Q)crystal src/pongc.cr -o 'pongc' + + +pongc.install: pongc + @echo ' IN > $(BINDIR)/pongc' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 pongc $(DESTDIR)$(BINDIR)/pongc + +pongc.clean: + @echo ' RM > pongc' + $(Q)rm -f pongc + +pongc.uninstall: + @echo ' RM > $(BINDIR)/pongc' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/pongc' + +plumberd: src/plumberd.cr + @echo ' CR > plumberd' + $(Q)crystal src/plumberd.cr -o 'plumberd' + + +plumberd.install: plumberd + @echo ' IN > $(BINDIR)/plumberd' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 plumberd $(DESTDIR)$(BINDIR)/plumberd + +plumberd.clean: + @echo ' RM > plumberd' + $(Q)rm -f plumberd + +plumberd.uninstall: + @echo ' RM > $(BINDIR)/plumberd' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/plumberd' + +websocketc: src/websocketc.cr + @echo ' CR > websocketc' + $(Q)crystal src/websocketc.cr -o 'websocketc' + + +websocketc.install: websocketc + @echo ' IN > $(BINDIR)/websocketc' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 websocketc $(DESTDIR)$(BINDIR)/websocketc + +websocketc.clean: + @echo ' RM > websocketc' + $(Q)rm -f websocketc + +websocketc.uninstall: + @echo ' RM > $(BINDIR)/websocketc' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/websocketc' + +websocketd: src/websocketd.cr + @echo ' CR > websocketd' + $(Q)crystal src/websocketd.cr -o 'websocketd' + + +websocketd.install: websocketd + @echo ' IN > $(BINDIR)/websocketd' + $(Q)mkdir -p '$(DESTDIR)$(BINDIR)' + $(Q)install -m0755 websocketd $(DESTDIR)$(BINDIR)/websocketd + +websocketd.clean: + @echo ' RM > websocketd' + $(Q)rm -f websocketd + +websocketd.uninstall: + @echo ' RM > $(BINDIR)/websocketd' + $(Q)rm -f '$(DESTDIR)$(BINDIR)/websocketd' + +$(DESTDIR)$(PREFIX): + @echo ' DIR > $(PREFIX)' + $(Q)mkdir -p $(DESTDIR)$(PREFIX) +$(DESTDIR)$(BINDIR): + @echo ' DIR > $(BINDIR)' + $(Q)mkdir -p $(DESTDIR)$(BINDIR) +$(DESTDIR)$(LIBDIR): + @echo ' DIR > $(LIBDIR)' + $(Q)mkdir -p $(DESTDIR)$(LIBDIR) +$(DESTDIR)$(SHAREDIR): + @echo ' DIR > $(SHAREDIR)' + $(Q)mkdir -p $(DESTDIR)$(SHAREDIR) +$(DESTDIR)$(INCLUDEDIR): + @echo ' DIR > $(INCLUDEDIR)' + $(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR) +$(DESTDIR)$(MANDIR): + @echo ' DIR > $(MANDIR)' + $(Q)mkdir -p $(DESTDIR)$(MANDIR) +install: subdirs.install tcpd.install tcpc.install pongd.install pongc.install plumberd.install websocketc.install websocketd.install + @: + +subdirs.install: + +uninstall: subdirs.uninstall tcpd.uninstall tcpc.uninstall pongd.uninstall pongc.uninstall plumberd.uninstall websocketc.uninstall websocketd.uninstall + @: + +subdirs.uninstall: + +test: all subdirs subdirs.test + @: + +subdirs.test: + +clean: tcpd.clean tcpc.clean pongd.clean pongc.clean plumberd.clean websocketc.clean websocketd.clean + +distclean: clean + +dist: dist-gz dist-xz dist-bz2 + $(Q)rm -- $(PACKAGE)-$(VERSION) + +distdir: + $(Q)rm -rf -- $(PACKAGE)-$(VERSION) + $(Q)ln -s -- . $(PACKAGE)-$(VERSION) + +dist-gz: $(PACKAGE)-$(VERSION).tar.gz +$(PACKAGE)-$(VERSION).tar.gz: distdir + @echo ' TAR > $(PACKAGE)-$(VERSION).tar.gz' + $(Q)tar czf $(PACKAGE)-$(VERSION).tar.gz \ + $(PACKAGE)-$(VERSION)/src/websocketc.cr \ + $(PACKAGE)-$(VERSION)/src/websocketd.cr \ + $(PACKAGE)-$(VERSION)/src/tcpc.cr \ + $(PACKAGE)-$(VERSION)/src/pongc.cr \ + $(PACKAGE)-$(VERSION)/src/tcpd.cr \ + $(PACKAGE)-$(VERSION)/src/plumberd.cr \ + $(PACKAGE)-$(VERSION)/src/pongd.cr + +dist-xz: $(PACKAGE)-$(VERSION).tar.xz +$(PACKAGE)-$(VERSION).tar.xz: distdir + @echo ' TAR > $(PACKAGE)-$(VERSION).tar.xz' + $(Q)tar cJf $(PACKAGE)-$(VERSION).tar.xz \ + $(PACKAGE)-$(VERSION)/src/websocketc.cr \ + $(PACKAGE)-$(VERSION)/src/websocketd.cr \ + $(PACKAGE)-$(VERSION)/src/tcpc.cr \ + $(PACKAGE)-$(VERSION)/src/pongc.cr \ + $(PACKAGE)-$(VERSION)/src/tcpd.cr \ + $(PACKAGE)-$(VERSION)/src/plumberd.cr \ + $(PACKAGE)-$(VERSION)/src/pongd.cr + +dist-bz2: $(PACKAGE)-$(VERSION).tar.bz2 +$(PACKAGE)-$(VERSION).tar.bz2: distdir + @echo ' TAR > $(PACKAGE)-$(VERSION).tar.bz2' + $(Q)tar cjf $(PACKAGE)-$(VERSION).tar.bz2 \ + $(PACKAGE)-$(VERSION)/src/websocketc.cr \ + $(PACKAGE)-$(VERSION)/src/websocketd.cr \ + $(PACKAGE)-$(VERSION)/src/tcpc.cr \ + $(PACKAGE)-$(VERSION)/src/pongc.cr \ + $(PACKAGE)-$(VERSION)/src/tcpd.cr \ + $(PACKAGE)-$(VERSION)/src/plumberd.cr \ + $(PACKAGE)-$(VERSION)/src/pongd.cr + +help: + @echo ' :: plumberd-0.1.0' + @echo '' + @echo 'Generic targets:' + @echo ' - help  Prints this help message.' + @echo ' - all  Builds all targets.' + @echo ' - dist  Creates tarballs of the files of the project.' + @echo ' - install  Installs the project.' + @echo ' - clean  Removes compiled files.' + @echo ' - uninstall  Deinstalls the project.' + @echo '' + @echo 'CLI-modifiable variables:' + @echo ' - CC  ${CC}' + @echo ' - CFLAGS  ${CFLAGS}' + @echo ' - LDFLAGS  ${LDFLAGS}' + @echo ' - DESTDIR  ${DESTDIR}' + @echo ' - PREFIX  ${PREFIX}' + @echo ' - BINDIR  ${BINDIR}' + @echo ' - LIBDIR  ${LIBDIR}' + @echo ' - SHAREDIR  ${SHAREDIR}' + @echo ' - INCLUDEDIR  ${INCLUDEDIR}' + @echo ' - MANDIR  ${MANDIR}' + @echo '' + @echo 'Project targets: ' + @echo ' - tcpd  crystal' + @echo ' - tcpc  crystal' + @echo ' - pongd  crystal' + @echo ' - pongc  crystal' + @echo ' - plumberd  crystal' + @echo ' - websocketc  crystal' + @echo ' - websocketd  crystal' + @echo '' + @echo 'Makefile options:' + @echo ' - gnu: false' + @echo ' - colors: true' + @echo '' + @echo 'Rebuild the Makefile with:' + @echo ' zsh ./build.zsh -c' +.PHONY: all subdirs clean distclean dist install uninstall help + diff --git a/project.zsh b/project.zsh new file mode 100644 index 0000000..497ca9c --- /dev/null +++ b/project.zsh @@ -0,0 +1,11 @@ + +package=plumberd +version=0.1.0 + +targets=(tcpd tcpc pongd pongc plumberd websocketc websocketd) + +for target in tcpd tcpc pongd pongc plumberd websocketc websocketd; do + type[$target]=crystal + sources[$target]=src/${target}.cr +done + diff --git a/src/main.cr b/src/main.cr deleted file mode 100644 index bb23a61..0000000 --- a/src/main.cr +++ /dev/null @@ -1,34 +0,0 @@ -require "./plumberd" - -plumberd = NetworkD.new "plumber" - -# --deny -# --allow -# --redirect -# --redirect - -plumberd.parse_cli ARGV -puts plumberd.to_s - -plumberd.loop do |event| - puts "there is an event!" - case event - when IPC::Event::Connection - puts "\033[32mConnection:\033[00m fd #{event.connection.fd}" - when IPC::Event::Disconnection - puts "\033[32mDisconnection:\033[00m fd #{event.connection.fd}" - when IPC::Event::ExtraSocket - puts "\033[32mExtrasocket:\033[00m fd #{event.connection.fd}" - when IPC::Event::Switch - puts "\033[31mSwitch\033[00m" - when IPC::Exception - puts "\033[31mException\033[00m" - when IPC::Event::Message - puts "\033[32mthere is a message\033[00m" - puts event.message.to_s - - plumberd.service_lookup event.message, event.connection - end -end - -# pp! rules.authorized? Rule::Direction::In, "authd", "tls:192.168.0.42" diff --git a/src/plumberd.cr b/src/plumberd.cr index c70152e..fdb83e8 100644 --- a/src/plumberd.cr +++ b/src/plumberd.cr @@ -144,3 +144,38 @@ class NetworkD < IPC::NetworkD @rules.to_s + "\n" + @redirections.to_s end end + + + +plumberd = NetworkD.new "plumber" + +# --deny +# --allow +# --redirect +# --redirect + +plumberd.parse_cli ARGV +puts plumberd.to_s + +plumberd.loop do |event| + puts "there is an event!" + case event + when IPC::Event::Connection + puts "\033[32mConnection:\033[00m fd #{event.connection.fd}" + when IPC::Event::Disconnection + puts "\033[32mDisconnection:\033[00m fd #{event.connection.fd}" + when IPC::Event::ExtraSocket + puts "\033[32mExtrasocket:\033[00m fd #{event.connection.fd}" + when IPC::Event::Switch + puts "\033[31mSwitch\033[00m" + when IPC::Exception + puts "\033[31mException\033[00m" + when IPC::Event::Message + puts "\033[32mthere is a message\033[00m" + puts event.message.to_s + + plumberd.service_lookup event.message, event.connection + end +end + +# pp! rules.authorized? Rule::Direction::In, "authd", "tls:192.168.0.42" diff --git a/src/pongd.cr b/src/pongd.cr index 40e27c8..8cd46b2 100644 --- a/src/pongd.cr +++ b/src/pongd.cr @@ -5,7 +5,7 @@ require "./colors" verbosity = 1 service_name = "pong" -OptionParser.parse! do |parser| +OptionParser.parse do |parser| parser.on "-s service_name", "--service-name service_name", "URI" do |optsn| service_name = optsn end diff --git a/src/tcpc.cr b/src/tcpc.cr index bd0f8ca..98eae29 100644 --- a/src/tcpc.cr +++ b/src/tcpc.cr @@ -7,7 +7,7 @@ port_to_listen = 1234 hostname = "localhost" requested_service_name = "pong" -OptionParser.parse! do |parser| +OptionParser.parse do |parser| parser.on "-p port", "--port port", "Port to listen on." do |port| port_to_listen = port.to_u16 end diff --git a/src/tcpd.cr b/src/tcpd.cr index 3bdf392..b8b5b69 100644 --- a/src/tcpd.cr +++ b/src/tcpd.cr @@ -14,7 +14,7 @@ end service_name = "tcp" port_to_listen = 1234 -OptionParser.parse! do |parser| +OptionParser.parse do |parser| parser.on "-p port", "--port port", "Port to listen on." do |port| port_to_listen = port.to_u16 end diff --git a/src/websocketc.cr b/src/websocketc.cr index 849a9a5..e6979b3 100644 --- a/src/websocketc.cr +++ b/src/websocketc.cr @@ -8,7 +8,7 @@ require "./ws" uri = "ws://localhost:1234/pong" -OptionParser.parse! do |parser| +OptionParser.parse do |parser| parser.on "-u uri", "--uri uri", "URI" do |opturi| uri = opturi end diff --git a/src/websocketd.cr b/src/websocketd.cr index 61e37fb..896cdf1 100644 --- a/src/websocketd.cr +++ b/src/websocketd.cr @@ -40,7 +40,7 @@ service_name = "websocket" host = "0.0.0.0" port_to_listen = 1234 -OptionParser.parse! do |parser| +OptionParser.parse do |parser| parser.on "-l host", "--l host", "IP address to listen on." do |h| host = h end