prim-ctrl 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.1
2
+ Name: prim-ctrl
3
+ Version: 0.3.0
4
+ Summary: Primitive Ctrl - Remote control of your phone's Primitive FTPd Android SFTP server and optionally Tailscale VPN.
5
+ Home-page: https://github.com/lmagyar/prim-ctrl
6
+ License: Apache-2.0
7
+ Author: Laszlo Magyar
8
+ Author-email: lmagyar1973@gmail.com
9
+ Requires-Python: >=3.12,<4.0
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: aiohttp (==3.10.5)
17
+ Requires-Dist: platformdirs (==4.3.2)
18
+ Requires-Dist: zeroconf (==0.134.0)
19
+ Project-URL: Change Log, https://github.com/lmagyar/prim-ctrl/blob/main/CHANGELOG.md
20
+ Project-URL: Repository, https://github.com/lmagyar/prim-ctrl
21
+ Description-Content-Type: text/markdown
22
+
23
+
24
+ > [!WARNING]
25
+ > ***This repository works with both the original and the forked version of the Primitive FTPd Android SFTP server!***
26
+ > - ***install my fork from https://github.com/lmagyar/prim-ftpd - and use the prim-ctrl-lmagyar Automate flow below***
27
+ > - ***install the original version from https://github.com/wolpi/prim-ftpd - and use the prim-ctrl Automate flow below***
28
+
29
+ # Primitive Ctrl
30
+
31
+ Remote control of your phone's [Primitive FTPd Android SFTP server](https://github.com/wolpi/prim-ftpd) and optionally [Tailscale VPN](https://tailscale.com/).
32
+
33
+ Though Primitive FTPd consumes minimal power when it is not used, remote start/stop can be usefull for zeroconf (DNS-SD). Android doesn't reply DSN-SD queries when the screen is off, but Android announces the new service when the Primitive FTPd server starts up. So SFTP clients can/should capture and cache the announcement at Primitive FTPd server startup to connect to a phone through zeroconf even when the screen is off.
34
+
35
+ But in case of Tailscale, it is a real battery and mobile network data drain when not used, remote start/stop is de facto very useful.
36
+
37
+ With the help of this script you can sync your phone with eg. your home NAS server whereever your phone is on a WiFi network - or even on cellular. Your phone doesn't have to be on the same LAN to make zeroconf working when you have alternative access through VPN.
38
+
39
+ See my other project, https://github.com/lmagyar/prim-sync, for bidirectional and unidirectional sync over SFTP (multiplatform Python script optimized for the Primitive FTPd SFTP server).
40
+
41
+ See my other project, https://github.com/lmagyar/prim-batch, for batch execution of prim-ctrl and prim-sync commands.
42
+
43
+ **Note:** These are my first ever Python projects, any comments on how to make them better are appreciated.
44
+
45
+ ## Features
46
+
47
+ - Remote start/stop of Primitive FTPd Android SFTP server and optionally Tailscale VPN
48
+ - Using VPN on cellular can be refused
49
+ - Backup states before starting them, restore when stopping (ie. they won't be stopped if they were running before the script were asked to start them)
50
+
51
+ ## Installation
52
+
53
+ You need to install:
54
+ - Automate on your phone - see: https://llamalab.com/automate/
55
+
56
+ - Python 3.12+, pip and venv on your laptop - see: https://www.python.org/downloads/ or
57
+ <details><summary>Unix</summary>
58
+
59
+ ```
60
+ sudo apt update
61
+ sudo apt upgrade
62
+ sudo apt install python3 python3-pip python3-venv
63
+ ```
64
+ </details>
65
+ <details><summary>Windows</summary>
66
+
67
+ - Install from Microsoft Store the latest [Python 3](https://apps.microsoft.com/search?query=python+3&department=Apps) (search), [Python 3.12](https://www.microsoft.com/store/productId/9NCVDN91XZQP) (App)
68
+ - Install from Chocolatey: `choco install python3 -y`
69
+ </details>
70
+
71
+ - pipx - see: https://pipx.pypa.io/stable/installation/#installing-pipx or
72
+ <details><summary>Unix</summary>
73
+
74
+ ```
75
+ sudo apt install pipx
76
+ pipx ensurepath
77
+ ```
78
+ </details>
79
+ <details><summary>Windows</summary>
80
+
81
+ ```
82
+ py -m pip install --user pipx
83
+ py -m pipx ensurepath
84
+ ```
85
+ </details>
86
+
87
+ - This repo
88
+ ```
89
+ pipx install prim-ctrl
90
+ ```
91
+
92
+ Optionally you can install:
93
+ - Tailscale on your phone and laptop - see: https://tailscale.com/download
94
+
95
+ Optionally, if you want to edit or even contribute to the source, you also need to install:
96
+ - poetry - see: https://python-poetry.org/
97
+ ```
98
+ pipx install poetry
99
+ ```
100
+
101
+ ## Configuration
102
+
103
+ ### Automate
104
+
105
+ - Depending on whether you installed the [forked](https://github.com/lmagyar/prim-ftpd) or the [original](https://github.com/wolpi/prim-ftpd) version of Primitive FTPd, download the appropriate Automate flow to your phone:
106
+ - Flow for the **forked** Primitive FTPd: https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl-lmagyar.flo (see [image](https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl-lmagyar.png) of the flow)
107
+ - Flow for the **original** Primitive FTPd: https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl.flo (see [image](https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl.png) of the flow)
108
+ - Import it with the ... menu / Import command
109
+ - Enable all privileges
110
+ - Click on the flow, edit the 2. block ("Set variable google_account to...), enter your Google account and press Save
111
+ - Start the flow
112
+ - Settings
113
+ - Run on system startup: enable
114
+
115
+ ### Primitive FTPd
116
+
117
+ - Configuration tab
118
+ - UI
119
+ - Show notification to start/stop server(s): disable - this is necessary to determine whether Primitive FTPd is running on the phone or not, because the Automate flow determines whether the server is started with checking the existence of it's notification, and if the notification is always shown, that would make it false positive; please use another way, eg. a Quick Settings Tile to start/stop the server manually
120
+
121
+ ### Tailscale VPN (optional)
122
+
123
+ Follow Tailscale's instructions on how to configure Tailscale VPN on your phone and laptop.
124
+
125
+ For more details see: https://login.tailscale.com/start
126
+
127
+ ### Tailscale Funnel (optional)
128
+
129
+ You can configure Tailscale Funnel on your laptop (for incoming connections to this script's webhooks from the internet). Until the Tailscale VPN is up on the phone, the phone can't send information directly to your laptop, to this script's webhooks. But Tailscale Funnel makes it possible to access a Tailscale VPN connected device's services from the wider internet.
130
+
131
+ For more details see: https://tailscale.com/kb/1223/funnel
132
+
133
+ An example Tailscale Funnel config command for this script is: `tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345"`
134
+
135
+ ## Usage
136
+
137
+ If you decide to use this script, I suggest to configure Tailscale VPN and Tailscale Funnel, this will provide the most functionality.
138
+
139
+ Without any VPN, the script will start and stop the Primitive FTPd app on your phone making a best effort and assumes the phone is on the same LAN (ie. zeroconf works). This is fine if you start the script manually and your phone is with you.
140
+
141
+ But if the script runs scheduled, we can't be sure whether the phone is on WiFi, is on the same WiFi as your laptop: it is better to configure the VPN and Funnel. And I suggest to use the backup and restore functionality also, in this case a scheduled script will not interfere with a manually started Primitive FTPd or VPN, you won't notice the synchronization is running while you are doing something else on the phone with the Primitive FTPd or the VPN.
142
+
143
+ Notes:
144
+ - Even when -b option is **not** used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script
145
+
146
+ ### Some example
147
+
148
+ <details><summary>Unix</summary>
149
+
150
+ ```
151
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
152
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r ${PREV_STATE}
153
+ ```
154
+ </details>
155
+ <details><summary>Windows</summary>
156
+
157
+ ```
158
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
159
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r !PREV_STATE!
160
+ ```
161
+ </details>
162
+
163
+ ### Options
164
+
165
+ ```
166
+ usage: prim-ctrl Automate [-h] [-i {test,start,stop}] [-t] [-s] [--debug] [--tailscale tailnet remote-machine-name sftp-port] [--funnel local-machine-name local-port local-path external-port] [-ac] [-b] [-r STATE]
167
+ automate-account automate-device automate-tokenfile server-name
168
+
169
+ Remote control of your phone's Primitive FTPd and optionally Tailscale app statuses via the Automate app, for more details see https://github.com/lmagyar/prim-ctrl
170
+
171
+ Note: you must install Automate app on your phone, download prim-ctrl flow into it, and configure your Google account in the flow to receive messages (see the project's GitHub page for more details)
172
+ Note: optionally if your phone is not accessible on local network but your laptop is part of the Tailscale VPN then Tailscale VPN can be started on the phone
173
+ Note: optionally if your laptop is accessible through Tailscale Funnel then VPN on cellular can be refused and app statuses on the phone can be backed up and restored
174
+
175
+ Output: even when -b option is not used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script
176
+
177
+ positional arguments:
178
+ automate-account your Google account email you set up in the Automate flow's first Set variable block's Value field
179
+ automate-device the device name you can see at the Automate flow's Cloud receive block's This device field
180
+ automate-tokenfile filename containing Automates's Secret that located under your .secrets folder
181
+ (generated on https://llamalab.com/automate/cloud, use the same Google account you set up on the Cloud receive block)
182
+ server-name the Servername configuration option from Primitive FTPd app
183
+
184
+ options:
185
+ -h, --help show this help message and exit
186
+ -i {test,start,stop}, --intent {test,start,stop}
187
+ what to do with the apps, default: test
188
+
189
+ logging:
190
+ -t, --timestamp prefix each message with an UTC timestamp
191
+ -s, --silent only errors printed
192
+ --debug use debug level logging and add stack trace for exceptions, disables the --silent and enables the --timestamp options
193
+
194
+ VPN:
195
+ To use --tailscale option you must install Tailscale and configure Tailscale VPN on your phone and your laptop
196
+ To use --funnel option you must configure Tailscale Funnel on your laptop for prim-ctrl's local webhook to accept responses from the Automate app
197
+ (eg.: tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345")
198
+ Note: --funnel, --backup-state and --restore-state options can be used only when --tailscale is used
199
+ Note: --backup-state is accurate only, when --funnel is used
200
+ Note: --accept-cellular option can be used only when --funnel is used
201
+
202
+ --tailscale tailnet remote-machine-name sftp-port
203
+ tailnet: your Tailscale tailnet name (eg. tailxxxx.ts.net)
204
+ remote-machine-name: your phone's name within your tailnet (just the name, without the tailnet)
205
+ sftp-port: Primitive FTPd's sftp port
206
+ --funnel local-machine-name local-port local-path external-port
207
+ local-machine-name: your laptop's name within your tailnet (just the name, without the tailnet)
208
+ local-port: 12345 - if you used the example tailscale funnel command above (the local webhook will be started on this port)
209
+ local-path: /prim-ctrl - if you used the example tailscale funnel command above
210
+ external-port: 8443 - if you used the example tailscale funnel command above
211
+ -ac, --accept-cellular in case of start, if WiFi is not connected, don't return error, but start VPN up
212
+ -b, --backup-state in case of start, backup current state to stdout as single string (in case of an error, it will try to restore the original state but will not write it to stdout)
213
+ -r STATE, --restore-state STATE in case of stop, restore previous state from STATE (use -b to get a valid STATE string)
214
+ ```
215
+
@@ -0,0 +1,192 @@
1
+
2
+ > [!WARNING]
3
+ > ***This repository works with both the original and the forked version of the Primitive FTPd Android SFTP server!***
4
+ > - ***install my fork from https://github.com/lmagyar/prim-ftpd - and use the prim-ctrl-lmagyar Automate flow below***
5
+ > - ***install the original version from https://github.com/wolpi/prim-ftpd - and use the prim-ctrl Automate flow below***
6
+
7
+ # Primitive Ctrl
8
+
9
+ Remote control of your phone's [Primitive FTPd Android SFTP server](https://github.com/wolpi/prim-ftpd) and optionally [Tailscale VPN](https://tailscale.com/).
10
+
11
+ Though Primitive FTPd consumes minimal power when it is not used, remote start/stop can be usefull for zeroconf (DNS-SD). Android doesn't reply DSN-SD queries when the screen is off, but Android announces the new service when the Primitive FTPd server starts up. So SFTP clients can/should capture and cache the announcement at Primitive FTPd server startup to connect to a phone through zeroconf even when the screen is off.
12
+
13
+ But in case of Tailscale, it is a real battery and mobile network data drain when not used, remote start/stop is de facto very useful.
14
+
15
+ With the help of this script you can sync your phone with eg. your home NAS server whereever your phone is on a WiFi network - or even on cellular. Your phone doesn't have to be on the same LAN to make zeroconf working when you have alternative access through VPN.
16
+
17
+ See my other project, https://github.com/lmagyar/prim-sync, for bidirectional and unidirectional sync over SFTP (multiplatform Python script optimized for the Primitive FTPd SFTP server).
18
+
19
+ See my other project, https://github.com/lmagyar/prim-batch, for batch execution of prim-ctrl and prim-sync commands.
20
+
21
+ **Note:** These are my first ever Python projects, any comments on how to make them better are appreciated.
22
+
23
+ ## Features
24
+
25
+ - Remote start/stop of Primitive FTPd Android SFTP server and optionally Tailscale VPN
26
+ - Using VPN on cellular can be refused
27
+ - Backup states before starting them, restore when stopping (ie. they won't be stopped if they were running before the script were asked to start them)
28
+
29
+ ## Installation
30
+
31
+ You need to install:
32
+ - Automate on your phone - see: https://llamalab.com/automate/
33
+
34
+ - Python 3.12+, pip and venv on your laptop - see: https://www.python.org/downloads/ or
35
+ <details><summary>Unix</summary>
36
+
37
+ ```
38
+ sudo apt update
39
+ sudo apt upgrade
40
+ sudo apt install python3 python3-pip python3-venv
41
+ ```
42
+ </details>
43
+ <details><summary>Windows</summary>
44
+
45
+ - Install from Microsoft Store the latest [Python 3](https://apps.microsoft.com/search?query=python+3&department=Apps) (search), [Python 3.12](https://www.microsoft.com/store/productId/9NCVDN91XZQP) (App)
46
+ - Install from Chocolatey: `choco install python3 -y`
47
+ </details>
48
+
49
+ - pipx - see: https://pipx.pypa.io/stable/installation/#installing-pipx or
50
+ <details><summary>Unix</summary>
51
+
52
+ ```
53
+ sudo apt install pipx
54
+ pipx ensurepath
55
+ ```
56
+ </details>
57
+ <details><summary>Windows</summary>
58
+
59
+ ```
60
+ py -m pip install --user pipx
61
+ py -m pipx ensurepath
62
+ ```
63
+ </details>
64
+
65
+ - This repo
66
+ ```
67
+ pipx install prim-ctrl
68
+ ```
69
+
70
+ Optionally you can install:
71
+ - Tailscale on your phone and laptop - see: https://tailscale.com/download
72
+
73
+ Optionally, if you want to edit or even contribute to the source, you also need to install:
74
+ - poetry - see: https://python-poetry.org/
75
+ ```
76
+ pipx install poetry
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ ### Automate
82
+
83
+ - Depending on whether you installed the [forked](https://github.com/lmagyar/prim-ftpd) or the [original](https://github.com/wolpi/prim-ftpd) version of Primitive FTPd, download the appropriate Automate flow to your phone:
84
+ - Flow for the **forked** Primitive FTPd: https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl-lmagyar.flo (see [image](https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl-lmagyar.png) of the flow)
85
+ - Flow for the **original** Primitive FTPd: https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl.flo (see [image](https://raw.githubusercontent.com/lmagyar/prim-ctrl/main/res/prim-ctrl.png) of the flow)
86
+ - Import it with the ... menu / Import command
87
+ - Enable all privileges
88
+ - Click on the flow, edit the 2. block ("Set variable google_account to...), enter your Google account and press Save
89
+ - Start the flow
90
+ - Settings
91
+ - Run on system startup: enable
92
+
93
+ ### Primitive FTPd
94
+
95
+ - Configuration tab
96
+ - UI
97
+ - Show notification to start/stop server(s): disable - this is necessary to determine whether Primitive FTPd is running on the phone or not, because the Automate flow determines whether the server is started with checking the existence of it's notification, and if the notification is always shown, that would make it false positive; please use another way, eg. a Quick Settings Tile to start/stop the server manually
98
+
99
+ ### Tailscale VPN (optional)
100
+
101
+ Follow Tailscale's instructions on how to configure Tailscale VPN on your phone and laptop.
102
+
103
+ For more details see: https://login.tailscale.com/start
104
+
105
+ ### Tailscale Funnel (optional)
106
+
107
+ You can configure Tailscale Funnel on your laptop (for incoming connections to this script's webhooks from the internet). Until the Tailscale VPN is up on the phone, the phone can't send information directly to your laptop, to this script's webhooks. But Tailscale Funnel makes it possible to access a Tailscale VPN connected device's services from the wider internet.
108
+
109
+ For more details see: https://tailscale.com/kb/1223/funnel
110
+
111
+ An example Tailscale Funnel config command for this script is: `tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345"`
112
+
113
+ ## Usage
114
+
115
+ If you decide to use this script, I suggest to configure Tailscale VPN and Tailscale Funnel, this will provide the most functionality.
116
+
117
+ Without any VPN, the script will start and stop the Primitive FTPd app on your phone making a best effort and assumes the phone is on the same LAN (ie. zeroconf works). This is fine if you start the script manually and your phone is with you.
118
+
119
+ But if the script runs scheduled, we can't be sure whether the phone is on WiFi, is on the same WiFi as your laptop: it is better to configure the VPN and Funnel. And I suggest to use the backup and restore functionality also, in this case a scheduled script will not interfere with a manually started Primitive FTPd or VPN, you won't notice the synchronization is running while you are doing something else on the phone with the Primitive FTPd or the VPN.
120
+
121
+ Notes:
122
+ - Even when -b option is **not** used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script
123
+
124
+ ### Some example
125
+
126
+ <details><summary>Unix</summary>
127
+
128
+ ```
129
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
130
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r ${PREV_STATE}
131
+ ```
132
+ </details>
133
+ <details><summary>Windows</summary>
134
+
135
+ ```
136
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
137
+ prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r !PREV_STATE!
138
+ ```
139
+ </details>
140
+
141
+ ### Options
142
+
143
+ ```
144
+ usage: prim-ctrl Automate [-h] [-i {test,start,stop}] [-t] [-s] [--debug] [--tailscale tailnet remote-machine-name sftp-port] [--funnel local-machine-name local-port local-path external-port] [-ac] [-b] [-r STATE]
145
+ automate-account automate-device automate-tokenfile server-name
146
+
147
+ Remote control of your phone's Primitive FTPd and optionally Tailscale app statuses via the Automate app, for more details see https://github.com/lmagyar/prim-ctrl
148
+
149
+ Note: you must install Automate app on your phone, download prim-ctrl flow into it, and configure your Google account in the flow to receive messages (see the project's GitHub page for more details)
150
+ Note: optionally if your phone is not accessible on local network but your laptop is part of the Tailscale VPN then Tailscale VPN can be started on the phone
151
+ Note: optionally if your laptop is accessible through Tailscale Funnel then VPN on cellular can be refused and app statuses on the phone can be backed up and restored
152
+
153
+ Output: even when -b option is not used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script
154
+
155
+ positional arguments:
156
+ automate-account your Google account email you set up in the Automate flow's first Set variable block's Value field
157
+ automate-device the device name you can see at the Automate flow's Cloud receive block's This device field
158
+ automate-tokenfile filename containing Automates's Secret that located under your .secrets folder
159
+ (generated on https://llamalab.com/automate/cloud, use the same Google account you set up on the Cloud receive block)
160
+ server-name the Servername configuration option from Primitive FTPd app
161
+
162
+ options:
163
+ -h, --help show this help message and exit
164
+ -i {test,start,stop}, --intent {test,start,stop}
165
+ what to do with the apps, default: test
166
+
167
+ logging:
168
+ -t, --timestamp prefix each message with an UTC timestamp
169
+ -s, --silent only errors printed
170
+ --debug use debug level logging and add stack trace for exceptions, disables the --silent and enables the --timestamp options
171
+
172
+ VPN:
173
+ To use --tailscale option you must install Tailscale and configure Tailscale VPN on your phone and your laptop
174
+ To use --funnel option you must configure Tailscale Funnel on your laptop for prim-ctrl's local webhook to accept responses from the Automate app
175
+ (eg.: tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345")
176
+ Note: --funnel, --backup-state and --restore-state options can be used only when --tailscale is used
177
+ Note: --backup-state is accurate only, when --funnel is used
178
+ Note: --accept-cellular option can be used only when --funnel is used
179
+
180
+ --tailscale tailnet remote-machine-name sftp-port
181
+ tailnet: your Tailscale tailnet name (eg. tailxxxx.ts.net)
182
+ remote-machine-name: your phone's name within your tailnet (just the name, without the tailnet)
183
+ sftp-port: Primitive FTPd's sftp port
184
+ --funnel local-machine-name local-port local-path external-port
185
+ local-machine-name: your laptop's name within your tailnet (just the name, without the tailnet)
186
+ local-port: 12345 - if you used the example tailscale funnel command above (the local webhook will be started on this port)
187
+ local-path: /prim-ctrl - if you used the example tailscale funnel command above
188
+ external-port: 8443 - if you used the example tailscale funnel command above
189
+ -ac, --accept-cellular in case of start, if WiFi is not connected, don't return error, but start VPN up
190
+ -b, --backup-state in case of start, backup current state to stdout as single string (in case of an error, it will try to restore the original state but will not write it to stdout)
191
+ -r STATE, --restore-state STATE in case of stop, restore previous state from STATE (use -b to get a valid STATE string)
192
+ ```
File without changes