gatekeeper

pub package Null Safety Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

gatekeeper is a Dart package for managing TCP ports, offering a manager, server, and client for seamless control. You can list, block, and unblock ports programmatically, through inter-process communication (IPC), or remotely, providing a flexible and efficient solution for port management.

Usage

You can use Gatekeeper programmatically:

import 'package:gatekeeper/gatekeeper_iptables.dart';

void main() async {
  var gatekeeper = Gatekeeper(
    driver: GatekeeperIpTables(), // Use `iptables` to handle ports.
    allowedPorts: {2080, 2443}, // Only handle ports 2080 and 2443.
  );

  // List blocked TCP ports:
  var blockedTCPPorts = await gatekeeper.listBlockedTCPPorts();
  print("-- Blocked TCP ports: $blockedTCPPorts");

  // Block port 2222:
  var blocked = await gatekeeper.blockTCPPort(2080);
  print("-- Blocked 2080: $blocked");

  // Unblock port 2222:
  var unblocked = await gatekeeper.unblockTCPPort(2080);
  print("-- Unblocked 2080: $unblocked");

  // Try to block a not allowed port:
  var failedBlock = await gatekeeper.blockTCPPort(8080);
  print("-- Failed block of 2080: $failedBlock");
}

CLI

Activate the gatekeeper commands:

dart pub global activate gatekeeper

gatekeeper

To run a GatekeeperServer listening on port 2243 and managing ports 2221,2222,2223:

gatekeeper --port 2243 --allowed-ports 2221,2222,2223

gatekeeper_client

To connect to a GatekeeperServer on port 2243:

gatekeeper_client server-host 2243

Configuration (.gatekeeper directory)

The client also looks for a .gatekeeper directory in the current user's home (resolved on all OSes supported by Dart) to load default options:

  • ~/.gatekeeper/config.json: a JSON object with optional defaults:

    {
      "host": "localhost",
      "port": 2243,
      "access-key": "<ACCESS_KEY>",
      "verbose": false
    }
    
  • ~/.gatekeeper/access-key: a plain text file with the access key, used when neither the --access-key option nor config.json provides one.

Command-line arguments/options take precedence over the .gatekeeper configuration. The access key may also be passed with --access-key - (or .) to read it from stdin.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Author

Graciliano M. Passos: gmpassos@GitHub.

License

Dart free & open-source license.

Libraries

gatekeeper
Gatekeeper - Network Port Manager
gatekeeper_client
Gatekeeper - Client
gatekeeper_iptables
Gatekeeper - with iptables driver
gatekeeper_server
Gatekeeper - Server