-
Notifications
You must be signed in to change notification settings - Fork 3
Add code for large amount of users creation and few recommendations #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ifuensan
wants to merge
16
commits into
pinheadmz:master
Choose a base branch
from
ifuensan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1d8de39
Update README.md
ifuensan d1dd19f
Create bulk_users.py
ifuensan 001bc95
Delete src/bulk_users.py
ifuensan 0618a42
Create bulk_users.py
ifuensan 0255c79
Update README.md
ifuensan aa74517
Update README.md
ifuensan 6becb70
Update README.md
ifuensan 95f9c76
Update README.md
ifuensan 0c3fe34
Update README.md
ifuensan 4a323b3
Update README.md
ifuensan 1fee3ad
Update README.md
ifuensan 892a563
Update README.md
ifuensan 8d5e7d4
Update README.md
ifuensan f911cbd
Update README.md
ifuensan eee170b
Update README.md
ifuensan f348f08
Update README.md
ifuensan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,9 @@ and bitcoin-cli RPC usage, without requiring students to sync the node themselve | |
|
|
||
| ## Install | ||
|
|
||
| 1. clone repo | ||
| 2. `pip install -r requirements.txt` | ||
| 1. Clone repo | ||
| 2. Create and activate a Python Virtual Environment | ||
| 3. `pip install -r requirements.txt` | ||
|
|
||
| ## Run | ||
|
|
||
|
|
@@ -17,10 +18,11 @@ with bitcoin-cli. | |
|
|
||
| Networks supported: `main`, `testnet`, `signet`, `regtest` | ||
|
|
||
| - Start Bitcoin Core: `bitcoind -conf=/path/to/repo/rpc-auth-proxy/etc/bitcoin.conf` | ||
| - Start Bitcoin Core: `bitcoind -daemon -conf=/path/to/repo/rpc-auth-proxy/etc/bitcoin.conf` | ||
| - Optionally add `-signet`, etc for different network | ||
| - Start proxy server: `python src/server.py main` | ||
| - Optionally replace `main` with `signet`, etc. | ||
| - Use `nohup` or `tmux` to ensure that the server process is not killed when exiting the terminal or session. | ||
|
|
||
| ## Adding Users | ||
|
|
||
|
|
@@ -34,6 +36,15 @@ Password for newuser1: lYDk7mbTiN60 | |
| ~/rpc-auth-proxy$ python src/users.py newuser2 -p hunter2 | ||
| Password for newuser2: hunter2 | ||
| ``` | ||
| ### Large amount of Users ### | ||
| To add large amount of users a utility is provided in `src/bulk_users.py`. Hashed passwords are saved by | ||
| default in a JSON file at `~/.rpc-auth-proxy-passwords.json`, but another file is saved too with the pair of username and clear password. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the other files name and path? |
||
|
|
||
| ```sh | ||
| ~/rpc-auth-proxy$ python src/bulk_users.py 100 | ||
| 100 users and passwords have been generated and saved to users_pass.csv. | ||
| 100 users and passwords have been added to ~/.rpc-auth-proxy-passwords.json. | ||
| ``` | ||
|
|
||
| ## Remote Access | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import argparse | ||
| import csv | ||
| import json | ||
| import os | ||
| import random | ||
| import string | ||
|
|
||
| from werkzeug.security import generate_password_hash | ||
|
|
||
| from config import password_file_path | ||
|
|
||
| # Parse command line arguments for username and optional password | ||
| parser = argparse.ArgumentParser(description="Add user and hashed password to JSON file.") | ||
| parser.add_argument("user_count", type=int, help="Number of users to generate") | ||
| parser.add_argument("-l", "--password_length", type=int, default=12, help="Length of the generated password") | ||
| args = parser.parse_args() | ||
|
|
||
| # Generate and save user credentials to a CSV file | ||
| with open("users_pass.csv", "w", newline='') as user_pass_file: | ||
| csv_writer = csv.writer(user_pass_file) | ||
| csv_writer.writerow(['Username', 'Password']) | ||
|
|
||
| users = {} | ||
| for i in range(args.user_count): | ||
| # Generate username | ||
| username = f"user_{i+1:03d}" | ||
|
|
||
| # Generate password | ||
| characters = string.ascii_letters + string.digits | ||
| password = ''.join(random.choice(characters) for _ in range(args.password_length)) | ||
|
|
||
| # Write user and password to the CSV file | ||
| csv_writer.writerow([username, password]) | ||
|
|
||
| # Add user and hashed password to dictionary | ||
| hashed_password = generate_password_hash(password) | ||
| users[username] = hashed_password | ||
|
|
||
| # Output message | ||
| print(f"{args.user_count} users and passwords have been generated and saved to users_pass.csv.") | ||
|
|
||
| # File to store hashed passwords | ||
| PASSWORD_FILE_PATH = password_file_path() | ||
|
|
||
| # Load existing data from file | ||
| if os.path.exists(PASSWORD_FILE_PATH): | ||
| with open(PASSWORD_FILE_PATH, 'r') as file: | ||
| try: | ||
| existing_users = json.load(file) | ||
| except json.JSONDecodeError: | ||
| existing_users = {} | ||
| else: | ||
| existing_users = {} | ||
|
|
||
| # Add or update user passwords | ||
| existing_users.update(users) | ||
|
|
||
| # Write back to the file | ||
| with open(PASSWORD_FILE_PATH, 'w') as file: | ||
| json.dump(existing_users, file, indent=4) | ||
|
|
||
| # Output message | ||
| print(f"{args.user_count} users and passwords have been added to {PASSWORD_FILE_PATH}.") | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should go before "start proxy server" and indicate its optional.