-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGanian App (VPN).ps1
More file actions
156 lines (125 loc) · 4.5 KB
/
Ganian App (VPN).ps1
File metadata and controls
156 lines (125 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
############################## GLOBALS ##############################
$global:debug = 0
$global:display = 'Normal'
$global:title = 'Ganian App'
$global:args = $args
############################## VARIABLES ##############################
$domain = 'ganian'
$vpn_ip = '26.235.25.211'
############################## MAIN CODE ##############################
function main {
run_as_admin
show_title $global:title -set_title
"`n`n`t Αρχείο διευθύνσεων Windows:"
$hosts = @{
path = "$env:WINDIR\System32\drivers\etc\hosts"
content = $NULL
old_content = $NULL
differences = $NULL
}
$hosts.content = $hosts.old_content = Get-Content $hosts.path
$domains_with_ip = $hosts.content -Match $domain -Match $vpn_ip
if ($domains_with_ip.count -eq 0) {
list_item 'Προσθήκη νέας διεύθυνσης...'
$hosts.content += "`n$vpn_ip $domain"
check_mark
}
$domains_without_ip = $hosts.content -Match $domain -NotMatch $vpn_ip
if ($domains_without_ip.count -gt 0) {
list_item 'Αφαίρεση παλαιών διευθύνσεων...'
$hosts.content = $hosts.content -Replace ($domains_without_ip -join '|'), ''
check_mark
}
$hosts.differences = Compare-Object $hosts.content $hosts.old_content
if ($NULL -ne $hosts.differences) {
list_item 'Αποθήκευση...'
$hosts.content -join "`n" -replace '\n{3,}', "`n`n" | Out-File -Encoding ASCII $hosts.path
check_mark
}
"`n`n`n`t Εικονικό ιδιωτικό δίκτυο Radmin:"
$radmin = @{
path = "${env:ProgramFiles(x86)}\Radmin VPN\RvRvpnGui.exe"
url = 'https://www.radmin-vpn.com/'
download = "$env:TMP/radmin_vpn.exe"
}
if (-Not (Test-Path $radmin.path)) {
list_item 'Λήψη...'
$radmin_page = Invoke-RestMethod $radmin.url
$download_url = ($radmin_page | Select-String "<a href=""(.*?)"" class=""buttonDownload""").Matches.Groups[1].Value
$ProgressPreference = "SilentlyContinue"
Start-BitsTransfer -Source $download_url -Destination $radmin.download -DisplayName 'Λήψη...'
check_mark
list_item 'Εγκατάσταση...'
Start-Process $radmin.download '/VERYSILENT /NORESTART' -Wait
check_mark
list_item 'Διαγραφή λήψης...'
Remove-Item $radmin.download
check_mark
}
if (Test-Path $radmin.path) {
list_item 'Εκκίνηση...'
Start-Process $radmin.path '/show'
check_mark
}
Write-Host -NoNewLine "`n`n`n`t Άνοιγμα πρoγράμματος περιήγησης... "
Start-Process "http://$domain"
check_mark
finish_gr
}
############################## FUNCTIONS ##############################
function run_as_admin {
$has_admin_rights = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
if (-not $has_admin_rights) {
Start-Process 'powershell' '-NoProfile -ExecutionPolicy Bypass', $(if ($NULL -ne $PSCommandPath) { "-File `"$PSCommandPath`" $global:args" } else { $MyInvocation.MyCommand.Definition -replace '"', "'" }) -WorkingDirectory $pwd -Verb 'RunAs' -WindowStyle $(if ($global:debug) { 'Normal' } else { $global:display })
if ($global:debug) { pause }
exit
}
}
function show_title {
param (
[Parameter(Mandatory)] [string] $title,
[switch] $set_title
)
if ($set_title) { $Host.UI.RawUI.WindowTitle = $title }
Write-Host "`n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $title ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
}
function list_item {
param (
[Parameter(Mandatory)] [string] $text,
[string] $symbol = '•'
)
Write-Host -NoNewLine -ForegroundColor Gray "`n`t $symbol $text "
}
function check_mark {
param (
[string] $symbol = '√',
[string] $color = 'Green'
)
Write-Host -ForegroundColor $color $symbol
}
function finish_gr {
param (
[string] $title = 'Η διαδικασία ολοκληρώθηκε',
[switch] $restart
)
''
show_title $title
[system.media.systemsounds]::Beep.play()
if ($restart) {
Write-Host -ForegroundColor Yellow -NoNewline "`n`n`t`t Απαιτείται επανεκκίνηση, επανεκκίνηση τώρα? [ν/ο] "
do {
$user_choice = [console]::ReadKey($TRUE).Key
} until (@('Ν', 'Ο') -contains $user_choice)
if ($user_choice -eq 'Ν') {
Start-Process 'shutdown' '/t /t 0'
}
}
else {
Write-Host -ForegroundColor Yellow "`n`n`t`t`t (Πατήστε οποιδήποτε πλήκτρο για να εξέλθετε)"
$NULL = [Console]::ReadKey($TRUE)
}
exit
}
############################## RUN MAIN CODE ##############################
main