go-sharif-net

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.
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
-
Clone the Repository
git clone https://github.com/drippypale/go-sharif-net.git
cd go-sharif-net
-
Build the Application
go build -o go-sharif-net
-
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
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
-
Login with Username and Password
go-sharif-net login -u your_username -p your_password
-
Login and Keep the Session Alive
go-sharif-net login -u your_username -p your_password -a
-
Use a Custom Configuration File
go-sharif-net login --config /path/to/config.yaml -u your_username -p your_password
-
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
-
Clone the Repository
git clone https://github.com/drippypale/go-sharif-net.git
cd go-sharif-net
-
Install Dependencies
go mod download
-
Run the Application
go run main.go login -u your_username -p your_password
-
Run Tests
go test ./...
Contributing
Contributions are welcome! Please follow these steps to contribute:
-
Fork the Repository
-
Create a Feature Branch
git checkout -b feature/YourFeature
-
Commit Your Changes
git commit -m "Add your feature"
-
Push to the Branch
git push origin feature/YourFeature
-
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.