net

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 1 Imported by: 0

README ΒΆ

go-sharif-net

go-sharif-net License

go-sharif-net is a command-line interface (CLI) tool written in Go, designed to simplify the authentication process for accessing the internet at Sharif University of Technology. By automating the login process to net2.sharif.edu, this tool ensures seamless and efficient network access management.

image

Table of Contents

Features

Implemented Features
  • Login Command

    • Authenticate to net2.sharif.edu using username and password.
    • Support for specifying configuration files.
    • Option to use IP instead of domain for authentication.
    • Interactive session monitoring with the ability to stay alive and manage session termination.
  • Help and Autocompletion

    • Comprehensive help texts for all commands and flags.
    • Generate shell autocompletion scripts for various shells.
Features to Be Implemented
Feature Description Progress
Logout Command Allow users to terminate their network session manually. To Do
Automatic Reconnection Automatically attempt to reconnect if the session drops. Done 🚧
Enhanced Logging Provide detailed logs for authentication and session status. To Do
Cross-Platform Support Ensure compatibility with Windows, macOS, and Linux. To Do
Configuration Management Simplify configuration through environment variables or a GUI. In Progress 🚧

Installation

Prerequisites
  • Go (version 1.16 or later)
Steps
  1. Clone the Repository

    git clone https://github.com/drippypale/go-sharif-net.git
    cd go-sharif-net
    
  2. Build the Application

    go build -o go-sharif-net
    
  3. Move the Binary to Your PATH

    sudo mv go-sharif-net /usr/local/bin/
    

    Alternatively, you can use package managers like brew or apt if supported in the future.

Usage

go-sharif-net provides a simple CLI interface to manage your network authentication. Below are the available commands and examples of how to use them.

Commands
  • login

    • Authenticate to the network.
  • help

    • Display help information about commands.
  • completion

    • Generate shell autocompletion scripts.
Global Flags
  • --config string
    Specify the configuration file (default is $HOME/.go-sharif-net.yaml).

  • --use-ip
    Use the IP address specified in the configuration instead of the domain.

Login Command Flags
  • -u, --username string
    Username for login. (Required)

  • -p, --password string
    Password for login. (Required)

  • -a, --alive
    Keep the session alive to monitor and maintain the connection.

Examples
  1. Login with Username and Password

    go-sharif-net login -u your_username -p your_password
    
  2. Login and Keep the Session Alive

    go-sharif-net login -u your_username -p your_password -a
    
  3. Use a Custom Configuration File

    go-sharif-net login --config /path/to/config.yaml -u your_username -p your_password
    
  4. Generate Autocompletion Script for Bash

    go-sharif-net completion bash > /etc/bash_completion.d/go-sharif-net
    

Permissions and Running with sudo

Certain features of go-sharif-net, such as Automatic Reconnection and Internet Connection Monitoring, require elevated privileges to function correctly. This is because these features utilize ICMP (Internet Control Message Protocol) operations, which typically require root or administrative access.

Why sudo is Necessary
  • ICMP Operations: Monitoring the internet connection involves sending ICMP packets (ping) to check the connectivity status. Most operating systems restrict ICMP operations to users with root privileges to enhance security.
  • Automatic Reconnection: To seamlessly reconnect to the network without manual intervention, the CLI needs to continuously monitor the connection status, which involves privileged network operations.
How to Run go-sharif-net with sudo

To enable these advanced features, you should run the CLI with sudo. Below are examples of how to execute the login command with elevated privileges:

sudo go-sharif-net login -u your_username -p your_password -a


## Configuration

`go-sharif-net` allows customization through a configuration file. By default, it looks for a file named `.go-sharif-net.yaml` in the home directory.

### Example Configuration (`~/.go-sharif-net.yaml`)

```yaml
username: your_username
password: your_password
use_ip: false
session_duration: 8h

Note: Storing passwords in plaintext configuration files can be a security risk. Consider using environment variables or secure storage mechanisms to handle sensitive information.

Development

Project Structure
go-sharif-net/
β”œβ”€β”€ cmd/                # Command implementations
β”‚   └── login.go
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ http/           # HTTP handlers
β”‚   └── ui/             # User interface components
β”œβ”€β”€ util/               # Utility functions
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── README.md
Code Highlights
  • Cobra & Viper: Utilizes Cobra for CLI commands and Viper for configuration management.
  • Session Management: Handles session login and maintains it with optional monitoring.
  • Concurrency: Implements goroutines and channels to manage asynchronous tasks like pinging and session checking.
Building from Source
  1. Clone the Repository

    git clone https://github.com/drippypale/go-sharif-net.git
    cd go-sharif-net
    
  2. Install Dependencies

    go mod download
    
  3. Run the Application

    go run main.go login -u your_username -p your_password
    
  4. Run Tests

    go test ./...
    

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the Repository

  2. Create a Feature Branch

    git checkout -b feature/YourFeature
    
  3. Commit Your Changes

    git commit -m "Add your feature"
    
  4. Push to the Branch

    git push origin feature/YourFeature
    
  5. Open a Pull Request

Please ensure your code follows the project's coding standards and includes appropriate tests.

License

This project is licensed under the MIT License.


Note: This README is a living document. As the project evolves, please keep this file updated to reflect the latest changes and features.

Documentation ΒΆ

Overview ΒΆ

Copyright Β© 2024 Saman Dehestani <github.com/drippypale>

Directories ΒΆ

Path Synopsis
internal
ui

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL