diff --git a/Dockerfile b/Dockerfile index 7e8d072..54d1fd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,8 @@ RUN apk add --no-cache tini # Set the working directory inside the container WORKDIR /app +ENV MIX_ENV=prod + RUN mkdir output/ RUN chmod 777 output/ diff --git a/lib/binoculo/args.ex b/lib/binoculo/args.ex index 3dd2c2c..092ddd9 100644 --- a/lib/binoculo/args.ex +++ b/lib/binoculo/args.ex @@ -7,6 +7,45 @@ defmodule Binoculo.Args do def parse_args(argv) do version = Util.version() + no_args = Enum.empty?(argv) + is_api = Enum.any?(argv, fn arg -> arg in ["--server", "-s"] end) + + host_notation_config = [ + value_name: "host_notation", + long: "--range", + help: "CIDR or IP range: 192.168.1.0/24 or 192.168.1.0..192.168.1.255", + parser: fn notation -> + case Util.parse_range_or_cidr_notation(notation) do + {:error, _} -> {:error, "invalid cidr or notation"} + {:ok, _} -> {:ok, notation} + end + end, + required: + if no_args or is_api do + false + else + true + end + ] + + port_config = [ + value_name: "port(s)", + short: "-p", + long: "--port", + help: "Port(s) to scan: 80,443,8080 or 80-8080 or 21,80-8080", + parser: fn port -> + case Util.parse_ports_notation(port) do + {:error, _} -> {:error, "invalid port(s)"} + {:ok, port_parsed} -> {:ok, port_parsed} + end + end, + required: + if no_args or is_api do + false + else + true + end + ] optimus = Optimus.new!( @@ -31,29 +70,8 @@ defmodule Binoculo.Args do ] ], options: [ - host_notation: [ - value_name: "host_notation", - long: "--range", - help: "CIDR or IP range: 192.168.1.0/24 or 192.168.1.0..192.168.1.255", - parser: fn notation -> - case Util.parse_range_or_cidr_notation(notation) do - {:error, _} -> {:error, "invalid cidr or notation"} - {:ok, _} -> {:ok, notation} - end - end - ], - ports: [ - value_name: "port(s)", - short: "-p", - long: "--port", - help: "Port(s) to scan: 80,443,8080 or 80-8080 or 21,80-8080", - parser: fn port -> - case Util.parse_ports_notation(port) do - {:error, _} -> {:error, "invalid port(s)"} - {:ok, port_parsed} -> {:ok, port_parsed} - end - end - ], + host_notation: host_notation_config, + ports: port_config, output: [ value_name: "output", short: "-o", @@ -66,7 +84,8 @@ defmodule Binoculo.Args do with {:ok, _file} <- File.open("output/#{output}", [:append]) do {:ok, output} end - end + end, + default: "output.txt" ], write: [ value_name: "write", diff --git a/mix.exs b/mix.exs index e8d7992..b9a1f1a 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Binoculo.MixProject do [ app: :binoculo, version: "1.3.0", - elixir: "~> 1.18", + elixir: "~> 1.17", start_permanent: Mix.env() == :prod, deps: deps(), test_coverage: [