From 515d4047e04eb35566bb4402a512dc4d00ee31a2 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Sun, 5 Nov 2023 21:25:52 -0500 Subject: [PATCH 01/16] Updated readme to use venv and crontab --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b979d6b..f14d20d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ However, Beeper is completely free and easy to use, and comes packed with multip You will first install Pypush onto your machine. *Please keep in mind that you will have to have a script running on a home server or PC 24/7 to keep your number active! See below for instructions.* ### PNRgateway -In order for Apple to verify your number, a specialized message has to be sent from your phone to Apple's "gateway number" and have the response captured. This number is different for each carrier, however the newest app version should automatically find your gateway number. If PNRgateway cannot find your gateway number, see below for help. +In order for Apple to verify your number, a specialized message has to be sent from your phone to Apple's "gateway number" and have the r nbnnnnnnnnnnnnnnnnnnnnnnesponse captured. This number is different for each carrier, however the newest app version should automatically find your gateway number. If PNRgateway cannot find your gateway number, see below for help. 1. Enable USB debugging/ADB on your phone. There are multiple online guides that guide you through this based on your phone. 2. Install the APK. The message link containing the APK is located [here](https://discord.com/channels/1130633272595066880/1145177252015915080/1153070972090470481), and the GitHub repository is [here](https://github.com/JJTech0130/PNRGatewayClientV2). @@ -22,18 +22,84 @@ In order for Apple to verify your number, a specialized message has to be sent f Make sure you have git and Python installed. 1. `git clone -b sms-registration https://github.com/beeper/pypush` -2. `cd pypush` , `python3 -m pip install -r requirements.txt` +2. `cd pypush` -# Number Registration +# Number Registration on Linux/MacOS +It is *strongly* recommended to use a Python virtual environment to setup Pypush. This ensures changes in your system's Python installation does not +break compatibility with Pypush with system updates. -1. `python3 demo.py --phone [ip]`. Replace `ip` with your phone's local IP. *(Usually this starts with `192.168.x.x`, however it can also start with `172` or `10`.)* -2. If the previous command ran successfully, you can now run `python3 demo.py --reregister` +1. If you do not already have a directory where Python virtual environments are located then +create a directory for your Python virtual environment. If you already have one then skip this step. +Virtual environments are traditionally placed in a hidden folder in your home directory on Linux/MacOS. +It can be created anywhere you wish. These instructions will assume you created it in your home directory. +``` +mkdir ~/.venv +``` +2. Create a virtual environment using Python 3.10: +``` +python3.10 -m pypush ~/.venv +``` +3. Activate the virtual environment: +``` +source ~/.venv/pypush/bin/activate +``` +4. Install the required packages using pip: +``` +pip install -r requirements.txt +``` +5. Run the demo script, replacing `[ip]` with your phone's local IP address: +``` +python demo.py --phone [ip] +``` +# Number reregistration option 1, automatic reregistration +Automatic reregistration is handled by determining when your imessage registration certificate expires +and reregistering 5 minutes before expiration. Put the following in a text file and save as `pypush_reregister.sh` in your home directory: +``` +#!/bin/bash +cd /path/to/pypush +source ~/.venv/pypush/bin/activate +python ./demo.py --reregister --daemon +``` +1. Make the reregistration script executable: +``` +chmod +x ~/pypush_reregister.sh +``` +2. Use [Screen](https://www.gnu.org/software/screen/manual/screen.html) to easily monitor reregistration status and set to run on boot, replacing "user" with your username: +``` +@reboot screen -S pypush /home/user/pypush_reregister.sh > /dev/null 2>&1 +``` +3. Reboot + +The basics of using screen are outlined below but this is not intended to be a tutorial in using screen. In order to see a more complete +guid please visit the following [guide](https://linuxize.com/post/how-to-use-linux-screen/). To monitor the status of registration you can +connect to the virtual screen you created. +``` +$ screen -r pypush +``` +To disconnect from the virtual screen press ctrl+a d. + +# Number reregistration option 2, registration every 30 minutes +Put the following in a text file and save as `pypush_reregister.sh` in your home directory: +``` +#!/bin/bash +cd /path/to/pypush +source ~/.venv/pypush/bin/activate +python ./demo.py --reregister +``` +1. Make the reregistration script executable: +``` +chmod +x ~/pypush_reregister.sh +``` +2. To automatically reregister every 30 minutes, execute the following: +```crontab -e +``` +3. Add the following to your crontab file, replacing "user" with your username: +``` +*/30 * * * * /home/user/pypush_reregister.sh +``` ***Please note:*** This last script is the script you will be running continuously. We recommend every 30 minutes. -### Automatic registration -There should also be a file called `reregister.py`, if you run this it should reregister you every 30 minutes. You can edit this file to rerun at any other interval. You can also use a cronjob to do this task for you in a more streamlined way if you are more familiar with IT. - ### Good to Know You will have to reregister your number every so often. This can last anywhere between 10 minutes to 48 hours, and *usually* the longer you run the script, the longer it takes to deregister. We may implement a feature to automatically detect deregistration in the future. From 089fdfdc7bc65e956316c68cdffbd8398b78ab87 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Mon, 6 Nov 2023 21:05:04 -0500 Subject: [PATCH 02/16] removed --reregister from --daemon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f14d20d..06ddd36 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ and reregistering 5 minutes before expiration. Put the following in a text file #!/bin/bash cd /path/to/pypush source ~/.venv/pypush/bin/activate -python ./demo.py --reregister --daemon +python ./demo.py --daemon ``` 1. Make the reregistration script executable: ``` From ba25dfe27142c79c3f87ca50d0ce13c2e6b6547d Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Tue, 7 Nov 2023 18:00:35 -0500 Subject: [PATCH 03/16] fixed typo in crontab entry --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06ddd36..204b863 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ chmod +x ~/pypush_reregister.sh ``` 2. Use [Screen](https://www.gnu.org/software/screen/manual/screen.html) to easily monitor reregistration status and set to run on boot, replacing "user" with your username: ``` -@reboot screen -S pypush /home/user/pypush_reregister.sh > /dev/null 2>&1 +@reboot screen -S pypush -d -m /home/user/pypush_reregister.sh > /dev/null 2>&1 ``` 3. Reboot From b4db7fac66ba8c48cfde51cb216f48c52ddcf9f2 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Tue, 7 Nov 2023 21:10:08 -0500 Subject: [PATCH 04/16] Added sleep to cron call to account for slow startup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 204b863..13e9fe9 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ chmod +x ~/pypush_reregister.sh ``` 2. Use [Screen](https://www.gnu.org/software/screen/manual/screen.html) to easily monitor reregistration status and set to run on boot, replacing "user" with your username: ``` -@reboot screen -S pypush -d -m /home/user/pypush_reregister.sh > /dev/null 2>&1 +@reboot sleep 60;screen -S pypush -d -m /home/user/pypush_reregister.sh > /dev/null 2>&1 ``` 3. Reboot From e34a1e2b87b5c5991448cae99cadd5c28f0d45b7 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Wed, 8 Nov 2023 19:05:00 -0500 Subject: [PATCH 05/16] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13e9fe9..d4a578c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ However, Beeper is completely free and easy to use, and comes packed with multip You will first install Pypush onto your machine. *Please keep in mind that you will have to have a script running on a home server or PC 24/7 to keep your number active! See below for instructions.* ### PNRgateway -In order for Apple to verify your number, a specialized message has to be sent from your phone to Apple's "gateway number" and have the r nbnnnnnnnnnnnnnnnnnnnnnnesponse captured. This number is different for each carrier, however the newest app version should automatically find your gateway number. If PNRgateway cannot find your gateway number, see below for help. +In order for Apple to verify your number, a specialized message has to be sent from your phone to Apple's "gateway number" and have the response captured. This number is different for each carrier, however the newest app version should automatically find your gateway number. If PNRgateway cannot find your gateway number, see below for help. 1. Enable USB debugging/ADB on your phone. There are multiple online guides that guide you through this based on your phone. 2. Install the APK. The message link containing the APK is located [here](https://discord.com/channels/1130633272595066880/1145177252015915080/1153070972090470481), and the GitHub repository is [here](https://github.com/JJTech0130/PNRGatewayClientV2). From e38d9fcda2bcfffad8e7232c45aa28471db526b6 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Thu, 9 Nov 2023 20:53:10 -0500 Subject: [PATCH 06/16] Added new cronreg argument for conditional reregistration --- demo.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/demo.py b/demo.py index 60eb440..3cba176 100644 --- a/demo.py +++ b/demo.py @@ -221,6 +221,28 @@ async def main(args: argparse.Namespace): logging.info("Reregistered!") + if args.cronreg: + reregister_within = 60 # Minutes, time where if expiration time is less than, rereg. + for user in users: + if "P:" in str(user.user_id): + logging.info(f'The user is: {user}') + cert = x509.load_pem_x509_certificate(user.id_cert.encode('utf-8')) + expiration = cert.not_valid_after + logging.info(f'Certificate expires on: {expiration}') + reregister_time = expiration - datetime.timedelta(minutes=reregister_within) + reregister_time = reregister_time.astimezone(datetime.timezone.utc) + logging.info(f'Reregistration will occur at: {reregister_time}') + reregister_delta = (reregister_time - datetime.datetime.now(datetime.timezone.utc)).total_seconds() + logging.info(f'The time between now and reregistration time is: {reregister_delta / 3600} hours or {reregister_delta / 86400} days') + if reregister_delta > 3600: + logging.info('Certificates expiration is greater than 60 minutes, quiting') + else: + logging.info('Certificate expires soon, reregistering now') + expiration = await reregister(conn, users) + expiration = expiration.replace(tzinfo=datetime.timezone.utc) + logging.info('Reregistered') + logging.info(expire_msg(expiration)) + if args.reregister: await reregister(conn, users) @@ -255,6 +277,7 @@ if __name__ == "__main__": parser.add_argument("--phone", type=str, help="Override the phone IP") parser.add_argument("--gateway", type=str, help="Override the gateway phone number") parser.add_argument("--daemon", action="store_true", help="Continuously reregister 5 minutes before the certificate expires") + parser.add_argument("--cronreg", action="store_true", help="Reregister if less than 60 minutes from expiration") args = parser.parse_args() From 07ecf064dda51951fb65695d11d83b7c768df04c Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Thu, 9 Nov 2023 23:07:33 -0500 Subject: [PATCH 07/16] truncated time decimals. --- demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo.py b/demo.py index 3cba176..0964b1f 100644 --- a/demo.py +++ b/demo.py @@ -233,7 +233,7 @@ async def main(args: argparse.Namespace): reregister_time = reregister_time.astimezone(datetime.timezone.utc) logging.info(f'Reregistration will occur at: {reregister_time}') reregister_delta = (reregister_time - datetime.datetime.now(datetime.timezone.utc)).total_seconds() - logging.info(f'The time between now and reregistration time is: {reregister_delta / 3600} hours or {reregister_delta / 86400} days') + logging.info(f'The time between now and reregistration time is: {(reregister_delta / 3600):.2f} hours or {(reregister_delta / 86400):.2f} days') if reregister_delta > 3600: logging.info('Certificates expiration is greater than 60 minutes, quiting') else: From 256eb232981a2af62a9ba5f1b0287f1431769e60 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Fri, 10 Nov 2023 20:44:38 -0500 Subject: [PATCH 08/16] deleted extra expiration assignment --- demo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/demo.py b/demo.py index 0964b1f..f66cebe 100644 --- a/demo.py +++ b/demo.py @@ -239,7 +239,6 @@ async def main(args: argparse.Namespace): else: logging.info('Certificate expires soon, reregistering now') expiration = await reregister(conn, users) - expiration = expiration.replace(tzinfo=datetime.timezone.utc) logging.info('Reregistered') logging.info(expire_msg(expiration)) From 2e59865f9d0f304de46eeb0b4214d8d543a73f59 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Fri, 10 Nov 2023 20:49:21 -0500 Subject: [PATCH 09/16] deleted unassigned variable --- demo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/demo.py b/demo.py index f66cebe..81a7d95 100644 --- a/demo.py +++ b/demo.py @@ -240,7 +240,6 @@ async def main(args: argparse.Namespace): logging.info('Certificate expires soon, reregistering now') expiration = await reregister(conn, users) logging.info('Reregistered') - logging.info(expire_msg(expiration)) if args.reregister: await reregister(conn, users) From 3556dacf0fb1c16d24b1c7672d101e12f51094a7 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Fri, 10 Nov 2023 21:51:33 -0500 Subject: [PATCH 10/16] added draft CLI installers --- unix_installer.sh | 32 ++++++++++++++++++++++++++++ windows_installer.ps1 | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 unix_installer.sh create mode 100644 windows_installer.ps1 diff --git a/unix_installer.sh b/unix_installer.sh new file mode 100644 index 0000000..2cfa60e --- /dev/null +++ b/unix_installer.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +mkdir -p ~/.venv +python3.10 -m pypush ~/.venv +source ~/.venv/pypush/bin/activate + +# Clone the repo +git clone -b sms-registration https://github.com/beeper/pypush +cd pypush + +# Change directories to the repository. +cd ~/pypush + +# Prompt the user for the IP address of their phone. +read -p "Enter the IP address of your phone: " phoneIp + +# Execute the `python demo.py` script with the phone IP address passed as a parameter. +python demo.py --phone $phoneIp + +# Create a reregistration script +cat > reregister.sh <> /dev/null 2&>1"; } | crontab - \ No newline at end of file diff --git a/windows_installer.ps1 b/windows_installer.ps1 new file mode 100644 index 0000000..872b25f --- /dev/null +++ b/windows_installer.ps1 @@ -0,0 +1,49 @@ +# Check if Python is installed. +if (!Test-Path "C:\Python3\python.exe") { + # Python is not installed, so download and install it. + $pythonUrl = "https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe" + $pythonInstaller = "$($env:TEMP)\python.exe" + Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller + Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet" -Wait +} + +# Check if Git is installed. +if (!Test-Path "C:\Program Files\Git\cmd\git.exe") { + # Git is not installed, so download and install it. + $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.38.1/Git-for-Windows-2.38.1.exe" + $gitInstaller = "$($env:TEMP)\git.exe" + Invoke-WebRequest -Uri $gitUrl -OutFile $gitInstaller + Start-Process -FilePath $gitInstaller -ArgumentList "/SILENT" -Wait +} + +# Create the folder for virtual environments if it doesn't exist. +if (!Test-Path "C:\Users\$env:USERNAME\AppData\Local\Python\VirtualEnvs") { + New-Item "C:\Users\$env:USERNAME\AppData\Local\Python\VirtualEnvs" -ItemType Directory +} + +# Create a Python 3.10 virtual environment named "pypush" in the user's home folder. +python3 -m venv "~\pypush" + +# Activate the virtual environment. +. "~\pypush\Scripts\activate.ps1" + +# Install dependencies from the requirements.txt file using pip. +pip install -r requirements.txt + +# Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git. +git clone -b sms-registration https://github.com/beeper/pypush("~/pypush") + +# Change directories to the repository. +cd "~/pypush" + +# Prompt the user for the IP address of their phone. +$phoneIp = Read-Host "Enter the IP address of your phone: " + +# Store the IP address in a variable. +$phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global + +# Execute the `python demo.py` script with the phone IP address passed as a parameter. +python demo.py --phone $phoneIpVariable + +# Execute the daemon for reregistration +python demo.py --daemon From f0642d7ff7ec1bb2920f60e42a353ea30892e584 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Sun, 12 Nov 2023 19:43:59 -0500 Subject: [PATCH 11/16] added necessary module --- windows_installer.ps1 | 80 +++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/windows_installer.ps1 b/windows_installer.ps1 index 872b25f..2818515 100644 --- a/windows_installer.ps1 +++ b/windows_installer.ps1 @@ -1,49 +1,53 @@ +Install-Module -Name Microsoft.PowerShell.Management +Import-Module Microsoft.PowerShell.Management + # Check if Python is installed. -if (!Test-Path "C:\Python3\python.exe") { +if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe") { # Python is not installed, so download and install it. $pythonUrl = "https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe" $pythonInstaller = "$($env:TEMP)\python.exe" Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet" -Wait -} - -# Check if Git is installed. -if (!Test-Path "C:\Program Files\Git\cmd\git.exe") { + } + + # Check if Git is installed. + if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe") { # Git is not installed, so download and install it. $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.38.1/Git-for-Windows-2.38.1.exe" $gitInstaller = "$($env:TEMP)\git.exe" Invoke-WebRequest -Uri $gitUrl -OutFile $gitInstaller Start-Process -FilePath $gitInstaller -ArgumentList "/SILENT" -Wait -} - -# Create the folder for virtual environments if it doesn't exist. -if (!Test-Path "C:\Users\$env:USERNAME\AppData\Local\Python\VirtualEnvs") { - New-Item "C:\Users\$env:USERNAME\AppData\Local\Python\VirtualEnvs" -ItemType Directory -} - -# Create a Python 3.10 virtual environment named "pypush" in the user's home folder. -python3 -m venv "~\pypush" - -# Activate the virtual environment. -. "~\pypush\Scripts\activate.ps1" - -# Install dependencies from the requirements.txt file using pip. -pip install -r requirements.txt - -# Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git. -git clone -b sms-registration https://github.com/beeper/pypush("~/pypush") - -# Change directories to the repository. -cd "~/pypush" - -# Prompt the user for the IP address of their phone. -$phoneIp = Read-Host "Enter the IP address of your phone: " - -# Store the IP address in a variable. -$phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global - -# Execute the `python demo.py` script with the phone IP address passed as a parameter. -python demo.py --phone $phoneIpVariable - -# Execute the daemon for reregistration -python demo.py --daemon + } + + # Create the folder for virtual environments if it doesn't exist. + if (!Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") { + New-Item "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs" -ItemType Directory + } + + # Create a Python 3.10 virtual environment named "pypush" in the user's home folder. + python3 -m venv "$env:USERPROFILE\pypush" + + # Activate the virtual environment. + . "$env:USERPROFILE\pypush\Scripts\activate.ps1" + + # Install dependencies from the requirements.txt file using pip. + pip install -r "$env:USERPROFILE\pypush\requirements.txt" + + # Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git. + git clone -b sms-registration https://github.com/beeper/pypush "$env:USERPROFILE\pypush" + + # Change directories to the repository. + cd "$env:USERPROFILE\pypush" + + # Prompt the user for the IP address of their phone. + $phoneIp = Read-Host "Enter the IP address of your phone: " + + # Store the IP address in a variable. + $phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global + + # Execute the `python demo.py` script with the phone IP address passed as a parameter. + python demo.py --phone $phoneIpVariable + + # Execute the daemon for reregistration + python demo.py --daemon + From b93dc9ce0895960029dab13e2c03d89d8fde466d Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Tue, 14 Nov 2023 17:08:26 -0500 Subject: [PATCH 12/16] udpated for syntax errors --- windows_installer.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/windows_installer.ps1 b/windows_installer.ps1 index 2818515..65821ae 100644 --- a/windows_installer.ps1 +++ b/windows_installer.ps1 @@ -1,8 +1,7 @@ -Install-Module -Name Microsoft.PowerShell.Management Import-Module Microsoft.PowerShell.Management # Check if Python is installed. -if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe") { +if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe")) { # Python is not installed, so download and install it. $pythonUrl = "https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe" $pythonInstaller = "$($env:TEMP)\python.exe" @@ -11,7 +10,7 @@ if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python. } # Check if Git is installed. - if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe") { + if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe")) { # Git is not installed, so download and install it. $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.38.1/Git-for-Windows-2.38.1.exe" $gitInstaller = "$($env:TEMP)\git.exe" @@ -20,7 +19,7 @@ if (!Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python. } # Create the folder for virtual environments if it doesn't exist. - if (!Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") { + if (Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") { New-Item "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs" -ItemType Directory } From f0549c86b74248cff38d094631dbe4a3f59be23e Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Tue, 14 Nov 2023 17:19:35 -0500 Subject: [PATCH 13/16] fixed borken link and added prints --- windows_installer.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/windows_installer.ps1 b/windows_installer.ps1 index 65821ae..5dffb25 100644 --- a/windows_installer.ps1 +++ b/windows_installer.ps1 @@ -1,18 +1,22 @@ Import-Module Microsoft.PowerShell.Management # Check if Python is installed. +Write-Output "Checking if Python is installed" if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe")) { # Python is not installed, so download and install it. + Write-Output "Installing Python" $pythonUrl = "https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe" $pythonInstaller = "$($env:TEMP)\python.exe" Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet" -Wait } + Write-Output "Checking if git is installed" # Check if Git is installed. if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe")) { # Git is not installed, so download and install it. - $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.38.1/Git-for-Windows-2.38.1.exe" + Write-Output "Installing git" + $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-32-bit.exe" $gitInstaller = "$($env:TEMP)\git.exe" Invoke-WebRequest -Uri $gitUrl -OutFile $gitInstaller Start-Process -FilePath $gitInstaller -ArgumentList "/SILENT" -Wait From 11e400c8922e4ddfc3e1579010376301d0acd8f0 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Tue, 14 Nov 2023 18:43:36 -0500 Subject: [PATCH 14/16] fixed a lot of bugs --- windows_installer.ps1 | 64 +++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/windows_installer.ps1 b/windows_installer.ps1 index 5dffb25..42370b4 100644 --- a/windows_installer.ps1 +++ b/windows_installer.ps1 @@ -1,5 +1,8 @@ Import-Module Microsoft.PowerShell.Management +# Prompt the user for the IP address of their phone. +$phoneIp = Read-Host "Enter the IP address of your phone: " + # Check if Python is installed. Write-Output "Checking if Python is installed" if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\python.exe")) { @@ -11,46 +14,59 @@ if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Python\Python310\py Start-Process -FilePath $pythonInstaller -ArgumentList "/quiet" -Wait } +Write-Output "Adding Python to Path" +[Environment]::SetEnvironmentVariable("Path", "$env:Path;$env:USERPROFILE\AppData\Local\Programs\Python\Python310") + Write-Output "Checking if git is installed" # Check if Git is installed. - if (-not (Test-Path "$env:USERPROFILE\AppData\Local\Programs\Git\cmd\git.exe")) { + if (-not (Test-Path "C:\Program Files\Git\bin\git.exe")) { # Git is not installed, so download and install it. Write-Output "Installing git" - $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-32-bit.exe" + $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-64-bit.exe" $gitInstaller = "$($env:TEMP)\git.exe" Invoke-WebRequest -Uri $gitUrl -OutFile $gitInstaller Start-Process -FilePath $gitInstaller -ArgumentList "/SILENT" -Wait } + +Write-Output "Adding Git to Path" +[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Program Files\Git\bin\") - # Create the folder for virtual environments if it doesn't exist. - if (Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") { +# Create the folder for virtual environments if it doesn't exist. +Write-Output "Creating folder for virtual environment" +if (Test-Path "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs") { New-Item "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs" -ItemType Directory } # Create a Python 3.10 virtual environment named "pypush" in the user's home folder. - python3 -m venv "$env:USERPROFILE\pypush" +Write-Output "Creating virtual environment" +python -m venv "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs\pypush" - # Activate the virtual environment. - . "$env:USERPROFILE\pypush\Scripts\activate.ps1" +# Activate the virtual environment. +Write-Output "Activating virtual environment" +. "$env:USERPROFILE\AppData\Local\Python\VirtualEnvs\pypush\Scripts\activate.ps1" + +cd "$env:USERPROFILE" + +# Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git. +Write-Output "Cloning sms-registration branch" +git clone -b sms-registration https://github.com/beeper/pypush - # Install dependencies from the requirements.txt file using pip. - pip install -r "$env:USERPROFILE\pypush\requirements.txt" +# Change directories to the repository. +Write-Output "Changing directories" +cd "$env:USERPROFILE\pypush" + +# Install dependencies from the requirements.txt file using pip. +Write-Output "Installing dependencies" +pip install -r "requirements.txt" - # Clone the "sms-registration" branch of the repository located at https://github.com/beeper/pypush using git. - git clone -b sms-registration https://github.com/beeper/pypush "$env:USERPROFILE\pypush" +# Store the IP address in a variable. +$phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global - # Change directories to the repository. - cd "$env:USERPROFILE\pypush" +# Execute the `python demo.py` script with the phone IP address passed as a parameter. +Write-Output "Registering" +python demo.py --phone $phoneIpVariable - # Prompt the user for the IP address of their phone. - $phoneIp = Read-Host "Enter the IP address of your phone: " - - # Store the IP address in a variable. - $phoneIpVariable = Set-Variable -Name phoneIp -Value $phoneIp -Scope Global - - # Execute the `python demo.py` script with the phone IP address passed as a parameter. - python demo.py --phone $phoneIpVariable - - # Execute the daemon for reregistration - python demo.py --daemon +# Execute the daemon for reregistration +Write-Output "Executing the daemon" +python demo.py --daemon From a8f6a44c4567a49d5615c186747ffe77606694d0 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Wed, 15 Nov 2023 21:31:42 -0500 Subject: [PATCH 15/16] fixed venv typo --- README.md | 2 +- demo.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4a578c..972839a 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ mkdir ~/.venv ``` 2. Create a virtual environment using Python 3.10: ``` -python3.10 -m pypush ~/.venv +python3.10 -m venv ~/.venv/pypush ``` 3. Activate the virtual environment: ``` diff --git a/demo.py b/demo.py index 81a7d95..ef21323 100644 --- a/demo.py +++ b/demo.py @@ -3,6 +3,7 @@ import logging import os import threading import time +import traceback from base64 import b64decode, b64encode from getpass import getpass from cryptography import x509 @@ -225,7 +226,7 @@ async def main(args: argparse.Namespace): reregister_within = 60 # Minutes, time where if expiration time is less than, rereg. for user in users: if "P:" in str(user.user_id): - logging.info(f'The user is: {user}') + # logging.info(f'The user is: {user}') cert = x509.load_pem_x509_certificate(user.id_cert.encode('utf-8')) expiration = cert.not_valid_after logging.info(f'Certificate expires on: {expiration}') From 846297f477f1989cb06b57c82445595c92de9212 Mon Sep 17 00:00:00 2001 From: Steven Burnham Date: Wed, 15 Nov 2023 22:01:07 -0500 Subject: [PATCH 16/16] added macos/linux check and OS specifics --- unix_installer.sh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/unix_installer.sh b/unix_installer.sh index 2cfa60e..e1b6b63 100644 --- a/unix_installer.sh +++ b/unix_installer.sh @@ -1,32 +1,54 @@ #!/bin/bash +set -o +set -x +set -u + +OS_NAME=$(uname -s) + +if [[ "$OS_NAME" == "Darwin" ]]; then + echo "The operating system is macOS." + if command -v brew >/dev/null 2>&1; then + echo "Homebrew is already installed." + else + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + brew install cmake + brew install pkgconfig +elif [[ "$OS_NAME" == "Linux" ]]; then + echo "The operating system is Linux." +else + echo "Unknown operating system: $OS_NAME" +fi + +# Create a virtual environment mkdir -p ~/.venv -python3.10 -m pypush ~/.venv +python3.10 -m venv ~/.venv/pypush source ~/.venv/pypush/bin/activate # Clone the repo +cd ~ git clone -b sms-registration https://github.com/beeper/pypush cd pypush -# Change directories to the repository. -cd ~/pypush - # Prompt the user for the IP address of their phone. -read -p "Enter the IP address of your phone: " phoneIp +read -p "Enter the IP address of your phone: " PHONEIP # Execute the `python demo.py` script with the phone IP address passed as a parameter. -python demo.py --phone $phoneIp +python demo.py --phone $PHONEIP # Create a reregistration script cat > reregister.sh <> /dev/null 2&>1"; } | crontab - \ No newline at end of file