titanium-web-proxy
titanium-web-proxy copied to clipboard
Running titanium web proxy as a windows service
Hi folks, I have been working at this for a bit now... I see there is a way to run titanium web proxy as a windows service. I am building it in a .net framework project, but for whatever reason, when i try to run it...I see my proxy start, it loads my certificate (which ive installed as root already)...but nothing happens, no events seem to fire, and it cannot set it self as default. I know its possible as I have seen it here...but i also see that it may be being finicky about the user account. I have built my code as a desktop app process, which works beautifully. I imported this code into my service and moved its methods as well...no change.
My questions are: Which account (s) are suitable for running as a service? Is LocalSystem not sufficient? is there anyting specific code wise I need? thanks
Hello, we have the same issue when trying titanium web proxy as a windows service, writing to a file log of each internet request out. Here is the code, we managed to soup: ` using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using Titanium.Web.Proxy; using Titanium.Web.Proxy.EventArguments;
namespace Loreen { public partial class MyNewService : ServiceBase { public ProxyServer proxyServer;
public MyNewService() {
InitializeComponent();
}
protected override void OnStart(string[] args) {
proxyServer = new ProxyServer(true, true, true);
proxyServer.BeforeRequest += OnRequest;
proxyServer.Start();
WriteToFile("Service is started at " + DateTime.Now);
}
protected override void OnStop() {
proxyServer.Stop();
WriteToFile("Service is stopped at " + DateTime.Now);
}
public void WriteToFile(string Message) {
string path = "E:\\Downloads\\Logs";
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
string filepath = "E:\\Downloads\\Logs\\ServiceLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".txt";
if (!File.Exists(filepath)) {
// Create a file to write to.
using (StreamWriter sw = File.CreateText(filepath)) {
sw.WriteLine(Message);
}
} else {
using (StreamWriter sw = File.AppendText(filepath)) {
sw.WriteLine(Message);
}
}
}
public async Task OnRequest(object sender, SessionEventArgs e) {
WriteToFile(e.HttpClient.Request.Url);
// To cancel a request with a custom HTML content
// Filter URL
if (e.HttpClient.Request.Method.ToUpper() == "GET" && e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("google.com")) {
e.Ok("<!DOCTYPE html>" +
"<html><body><h1>" +
"Website Blocked" +
"</h1>" +
"<p>Blocked by titanium web proxy.</p>" +
"</body>" +
"</html>");
}
// Redirect example
if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org")) {
e.Redirect("https://www.paypal.com");
}
}
}
} `
The result is just logging of start and stop time.
i'm running it as service without problem (the only problem is a memory leak) i use LocalSystem as service user
Hi folks, I have been working at this for a bit now... I see there is a way to run titanium web proxy as a windows service. I am building it in a .net framework project, but for whatever reason, when i try to run it...I see my proxy start, it loads my certificate (which ive installed as root already)...but nothing happens, no events seem to fire, and it cannot set it self as default. I know its possible as I have seen it here...but i also see that it may be being finicky about the user account. I have built my code as a desktop app process, which works beautifully. I imported this code into my service and moved its methods as well...no change.
My questions are: Which account (s) are suitable for running as a service? Is LocalSystem not sufficient? is there anyting specific code wise I need? thanks