-
Notifications
You must be signed in to change notification settings - Fork 3
/
Mind.cs
173 lines (108 loc) · 4.19 KB
/
Mind.cs
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright (c) 2023 Fox Council - VintageHive - https://github.com/FoxCouncil/VintageHive
using System.Diagnostics;
using VintageHive.Data.Contexts;
using VintageHive.Processors;
using VintageHive.Proxy.Ftp;
using VintageHive.Proxy.Http;
using VintageHive.Proxy.Irc;
using VintageHive.Proxy.Oscar;
using VintageHive.Proxy.Pop3;
using VintageHive.Proxy.Printer;
using VintageHive.Proxy.Smtp;
using VintageHive.Proxy.Telnet;
namespace VintageHive;
public static class Mind
{
public static readonly string ApplicationVersion = typeof(HttpProxy).Assembly.GetName().Version?.ToString() ?? "NA";
static readonly ManualResetEvent resetEvent = new(false);
// static DnsProxy dnsProxy;
// static Socks5Proxy socks5Proxy;
static HttpProxy httpProxy;
static HttpProxy httpsProxy;
static FtpProxy ftpProxy;
static TelnetServer telnetServer;
static SmtpProxy smtpProxy;
static Pop3Proxy pop3Proxy;
static IrcProxy ircProxy;
static OscarServer oscarServer;
static PrinterProxy printerProxy;
public static bool IsDebug => Debugger.IsAttached;
public static bool IsDocker => Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true";
public static CacheDbContext Cache { get; private set; }
public static HiveDbContext Db { get; private set; }
public static GeonamesDbContext Geonames { get; private set; }
public static PostOfficeDbContext PostOfficeDb { get; private set; }
public static RadioBrowserDbContext RadioBrowserDB { get; private set; }
public static RadioBrowserClient RadioBrowser { get; private set; }
public static async Task Init()
{
// Files
Resources.Initialize();
VFS.Init();
// Data
Cache = new();
Db = new();
PostOfficeDb = new();
// Services
Geonames = new();
RadioBrowserDB = new();
RadioBrowser = new();
await RadioBrowser.Init();
await GeoIpUtils.CheckGeoIp();
await ProtoWebUtils.GetSites();
// Proxies
var ipAddressString = Db.ConfigGet<string>(ConfigNames.IpAddress);
var ipAddress = IPAddress.Parse(ipAddressString);
var httpPort = Db.ConfigGet<int>(ConfigNames.PortHttp);
httpProxy = new(ipAddress, httpPort, false);
httpProxy
.Use(HelperProcessor.ProcessHttpRequest)
.Use(LocalServerProcessor.ProcessHttpRequest)
.Use(ProtoWebProcessor.ProcessHttpRequest)
.Use(InternetArchiveProcessor.ProcessHttpRequest);
// var httpsPort = Db.ConfigGet<int>(ConfigNames.PortHttps); // Soon?
httpsProxy = new(ipAddress, 9999, true);
httpsProxy
.Use(LocalServerProcessor.ProcessHttpsRequest)
.Use(DialNineProcessor.ProcessHttpsRequest);
var ftpPort = Db.ConfigGet<int>(ConfigNames.PortFtp);
ftpProxy = new(ipAddress, ftpPort)
{
CacheDb = Cache
};
ftpProxy
.Use(ProtoWebProcessor.ProcessFtpRequest)
.Use(LocalServerProcessor.ProcessFtpRequest);
var telnetPort = Db.ConfigGet<int>(ConfigNames.PortTelnet);
telnetServer = new(ipAddress, telnetPort);
oscarServer = new(ipAddress);
#if DEBUG
printerProxy = new PrinterProxy(ipAddress, 9100);
var smtpProxyPort = Db.ConfigGet<int>(ConfigNames.PortSmtp);
smtpProxy = new(ipAddress, smtpProxyPort);
var pop3ProxyPort = Db.ConfigGet<int>(ConfigNames.PortPop3);
pop3Proxy = new(ipAddress, pop3ProxyPort);
var ircProxyPort = Db.ConfigGet<int>(ConfigNames.PortIrc);
ircProxy = new(ipAddress, ircProxyPort);
// ==== TESTING AREA =====
// var socks5Port = ConfigDb.SettingGet<int>(ConfigNames.PortSocks5);
// socks5Proxy = new(ipAddress, socks5Port);
#endif
}
public static void Start()
{
httpProxy.Start();
httpsProxy.Start();
ftpProxy.Start();
telnetServer.Start();
#if DEBUG
printerProxy.Start();
smtpProxy.Start();
pop3Proxy.Start();
ircProxy.Start();
// socks5Proxy.Start();
#endif
oscarServer.Start();
resetEvent.WaitOne();
}
}