-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
78 lines (63 loc) · 2.12 KB
/
Program.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
using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using Fardin;
using NLua;
using Mahi.HtmLua;
using System.Runtime.Versioning;
using Mahi.Properties;
using static Mahi.Core.Logger;
using Mahi.Core;
using CookieCollection = Fardin.CookieCollection;
namespace Mahi
{
internal class Program
{
const string ip = "127.0.0.1";
const int port = 1010;
static readonly Logger logger = new Logger();
static void Main()
{
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Console.Title = "Mahi1.0.0";
// installing default modules
InstallModules();
var server = new HttpServer(IPAddress.Parse(ip), port, "cert.pfx", Resources.CertificationPassword);
//var server = new HttpServer(IPAddress.Parse(ip), port);
server.BaseDirectory = "wwwapp";
try
{
server.Start();
}
catch (Exception ex)
{
logger.Log("&c" + ex.ToString());
return;
}
logger.Log("[&2Info&r] &fStarting server ...");
logger.Log($"[&2Info&r] &fServer started and binded on &7http{(server.IsTlsSecure ? "s" : "")}://{ip}:{port}/");
RequestHandler.Process(server);
logger.Dispose();
}
static void InstallModules()
{
string moduesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "modules");
if (!Directory.Exists(moduesDirectory))
Directory.CreateDirectory(moduesDirectory);
string jsonModulePath = Path.Combine(moduesDirectory, "json.lua");
if (!File.Exists(jsonModulePath))
File.WriteAllText(jsonModulePath, Encoding.UTF8.GetString(Resources.dkjson));
string mssqlModulePath = Path.Combine(moduesDirectory, "mssql.lua");
if (!File.Exists(mssqlModulePath))
File.WriteAllText(mssqlModulePath, Encoding.UTF8.GetString(Resources.mssql));
string hashModulePath = Path.Combine(moduesDirectory, "hash.lua");
if (!File.Exists(hashModulePath))
File.WriteAllText(hashModulePath, Encoding.UTF8.GetString(Resources.hash));
}
internal static void Log(string message, bool newLine = true)
=> logger.Log(message, newLine);
}
}