Skip to content

Commit 362ecdd

Browse files
committed
docs: update doc for script before connect.
1 parent 71f8954 commit 362ecdd

File tree

10 files changed

+104
-10
lines changed

10 files changed

+104
-10
lines changed
26.4 KB
Loading

source/docs/usage/database/data-synchronization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This means you can copy the database to other device using sync tools, and 1Remo
1717
> please do not remove the database file while 1Remote is still in used.
1818
1919
!!! tip
20-
In `Options` -> `Database` -> `Local` -> `Edit`, you can check up where your database file is.
20+
In `Options` -> `Database` -> `Local` -> `Edit`, you can check up where your database file is.
2121

2222
You can also change the db path there.
2323

74 KB
Loading
62.9 KB
Loading

source/docs/usage/misc/open-a-vpn-before-connect.md renamed to source/docs/usage/misc/pre-post-script-control/open-a-vpn-before-connect.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Maybe your server needs a VPN connection before you can connect to it. 1Remote c
22

33
> One of my windows servers is behind VPN. So I have to connect the VPN tunnel first, wait until it's connected, then run the RDP connection. I'm trying to automate this with 1Remote using OpenVPN 2.5.8.
44
5-
You can open vpn in `Script before connect`
5+
You can open vpn in `Script before connect`
66
and close it in `Script after disconnected`
77

88
![image](img/vpn-scripts.jpg)
@@ -16,9 +16,9 @@ Write-Host "Checking VPN connection" -NoNewLine
1616
$i = 0
1717
while(1) {
1818
Write-Host -NoNewLine ' .'
19-
$portOpened = Test-Port $Env:PRM_HOST $Env:PRM_PORT | ? { $_.PortOpened }
19+
$portOpened = Test-Port $Env:PRM_HOST $Env:PRM_PORT | ? { $_.PortOpened }
2020
if ($portOpened -or $i -gt 60) { break } else { Start-Sleep 1; $i++}
21-
}
21+
}
2222
if ($i -gt 60) { Write-Error 'timeout' }
2323
```
2424
@@ -29,4 +29,3 @@ close-vpn.ps1:
2929
```
3030
3131
{% include 'footer.md' %}
32-
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
# Using Pre- and Post-Connection Scripts in 1Remote
3+
4+
1Remote is a remote access application that allows users to establish connections to remote computers. One of its features is the ability to run pre- and post-connection scripts. These scripts can be written in cmd(*.bat), PowerShell(*.ps1) or Python(*.py) and can be used to perform various tasks before a connection is established or after it disconnected.
5+
6+
```plantuml format="svg"
7+
@startuml
8+
(*)
9+
if (Run script befor conncect?) then (yes)
10+
if (Script exit code is 0?) then (no)
11+
:Terminate connection;
12+
stop
13+
endif
14+
endif
15+
-Open connection
16+
-Have fun with your server
17+
-Disconnected
18+
-Run script disconnected
19+
stop
20+
@enduml
21+
```
22+
23+
To facilitate the script in identify each sessions, 1Remote will start the script with **`SESSION_ID`**, **`SERVER_ID`**, **`SERVER_NAME`**, and **`SERVER_HOST`** as environment variables.
24+
25+
!!! note
26+
Noted:For the same server, the **SESSION_ID** for each session is different, while **SERVER_ID**, **SERVER_NAME**, and **SERVER_HOST** remain the same.
27+
28+
## Setting Up Scripts
29+
30+
To set up a script in 1Remote:
31+
32+
1. Find a place to keep your script files, and create scripts there.
33+
2. Navigate to the `Edit` page of your server in 1Remote.
34+
3. Click the `Select` button and select the script file you want.
35+
36+
![steps](img/step1.jpg)
37+
38+
4. Click `Test` button to test the script, the debug info will popup.
39+
40+
![steps](img/step2.jpg)
41+
42+
5. If it is all green, click `Save` button to save.
43+
6. Then your script will be run every time you start this server.
44+
45+
## Example Pre-Connection Script
46+
47+
Here is an example of a script. The script will be executed in the directory where the script file is.
48+
49+
``` powershell
50+
$sessionID = $env:SESSION_ID
51+
$serverID = $env:SERVER_ID
52+
$serverName = $env:SERVER_NAME
53+
$serverHost = $env:SERVER_HOST
54+
$serverTags = $env:SERVER_TAGS
55+
56+
echo "SESSION_ID: $sessionID"
57+
echo "SERVER_ID: $serverID"
58+
echo "SERVER_NAME: $serverName"
59+
echo "SERVER_HOST: $serverHost"
60+
echo "SERVER_TAGS: $serverTags"
61+
62+
63+
Set-Content -Path "temp.txt" -Value "SESSION_ID: $sessionID`r`nSERVER_ID: $serverID`r`nSERVER_NAME: $serverName`r`nSERVER_HOST: $serverHost`r`SERVER_TAGS: $serverTags"
64+
65+
# in the script before connect:
66+
# TODO: save $sessionID into file in pre-connect script
67+
# TODO: if $serverTags contains "HOME" then open VPN1
68+
# TODO: if $serverTags contains "WORK" then open VPN2
69+
70+
71+
# in the script after disconnected:
72+
# TODO: read $sessionID from file in post-connect script
73+
# TODO: if $sessionID == "12345" then close VPN1
74+
# TODO: if $sessionID == "ABCDE" then close VPN2
75+
76+
77+
# do some long time jobs, like opening a VPN
78+
sleep 3
79+
80+
# exit with non-zero will terminate your connection request.
81+
exit 0
82+
```
83+
84+
A typical application is to open a VPN before establishing a remote connection, and automatically close the VPN after terminating the remote connection.
85+
86+
[Learn more](/usage/misc/pre-post-script-control/open-a-vpn-before-connect){ .md-button }
87+
88+
{% include 'footer.md' %}

source/docs/usage/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ Press default shortcut ++alt++ + ++m++ and select server you want then press ++e
3131
- Change theme: **`Setting`** -> **`Theme`** -> **`Theme`**. On this page, you can also customize your favorite color scheme.
3232
- Change SSH color scheme: **`Setting`** -> **`Protocol`** -> **`SSH`** -> **`KiTTY`** -> **`Themes`**
3333

34-
[Learn more from the **Overview**](./overview.md){ .md-button .md-button--primary .inline .auto_width}
34+
[Learn more from the **Overview**](./overview.md){ .md-button }
3535

3636
{% include 'footer.md' %}

source/mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ nav:
184184
- Team deploy: usage/team/team-deploy.md
185185
- Misc:
186186
- Highline a server: usage/misc/highline-a-server.md
187-
- Pre-open a VPN: usage/misc/open-a-vpn-before-connect.md
187+
- Streamline by pre/post connect script:
188+
- Overview: usage/misc/pre-post-script-control/overview.md
189+
- Pre-open a VPN: usage/misc/pre-post-script-control/open-a-vpn-before-connect.md
188190
- Note for servers: usage/misc/note-for-servers.md
189191
- Help translation: usage/misc/help-translation.md
190192
# - Customized: usage/misc/customized.md

source/overrides/home.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ <h1>Multiple monitors <br/>meet high resolution RDP</h1>
209209
<div class="md-grid md-typeset">
210210
<div class="hero">
211211
<div class="container-image-right" style="margin-top: 50px;">
212-
<img src="https://raw.githubusercontent.com/1Remote/PRemoteM/Doc/DocPic/multi-screen.jpg" width="500px" draggable="false" align="right">
212+
<img src="img/home_override/cli-integrate.jpg" width="500px" draggable="false" align="right">
213213
</div>
214214
<div class="container-content-left">
215215
<h1>Connect the way you want</h1>
@@ -219,7 +219,7 @@ <h1>Connect the way you want</h1>
219219
<a href="usage/protocol/runner"
220220
target="_blank"
221221
class="md-button md-button">
222-
Learn more
222+
Learn more About CLI tools integrate
223223
</a>
224224
</div>
225225
</div>
@@ -249,7 +249,12 @@ <h1>Streamline your server management</h1>
249249
<a href="usage/alternative-credential/"
250250
target="_blank"
251251
class="md-button md-button">
252-
Learn more
252+
Learn more About Multi-credential
253+
</a>
254+
<a href="usage/misc/pre-post-script-control/overview"
255+
target="_blank"
256+
class="md-button md-button">
257+
Learn more About Auto script
253258
</a>
254259
</div>
255260
</div>

0 commit comments

Comments
 (0)