Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
4f8a2170
Commit
4f8a2170
authored
May 23, 2017
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup firefox
parent
2bfb116c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
50 deletions
+27
-50
Firefox.cs
Titanium.Web.Proxy/Helpers/Firefox.cs
+17
-35
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+10
-15
No files found.
Titanium.Web.Proxy/Helpers/Firefox.cs
View file @
4f8a2170
...
@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary>
/// <summary>
/// Add Firefox settings.
/// Add Firefox settings.
/// </summary>
/// </summary>
internal
void
AddFirefox
()
internal
void
UseSystemProxy
()
{
{
try
try
{
{
...
@@ -19,48 +19,30 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -19,48 +19,30 @@ namespace Titanium.Web.Proxy.Helpers
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
"\\Mozilla\\Firefox\\Profiles\\"
).
GetDirectories
(
"*.default"
);
"\\Mozilla\\Firefox\\Profiles\\"
).
GetDirectories
(
"*.default"
);
var
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
var
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
if
(!
File
.
Exists
(
myFfPrefFile
))
return
;
if
(!
File
.
Exists
(
myFfPrefFile
))
// We have a pref file so let''s make sure it has the proxy setting
{
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
return
;
var
myPrefContents
=
myReader
.
ReadToEnd
();
}
myReader
.
Close
();
if
(!
myPrefContents
.
Contains
(
"user_pref(\"network.proxy.type\", 0);"
))
return
;
// Add the proxy enable line and write it back to the file
myPrefContents
=
myPrefContents
.
Replace
(
"user_pref(\"network.proxy.type\", 0);"
,
""
);
File
.
Delete
(
myFfPrefFile
);
File
.
WriteAllText
(
myFfPrefFile
,
myPrefContents
);
}
catch
(
Exception
)
{
// Only exception should be a read/write error because the user opened up FireFox so they can be ignored.
}
}
/// <summary>
/// Remove firefox settings.
/// </summary>
internal
void
RemoveFirefox
()
{
try
{
var
myProfileDirectory
=
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
"\\Mozilla\\Firefox\\Profiles\\"
).
GetDirectories
(
"*.default"
);
var
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
if
(!
File
.
Exists
(
myFfPrefFile
))
return
;
// We have a pref file so let''s make sure it has the proxy setting
// We have a pref file so let''s make sure it has the proxy setting
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
var
myPrefContents
=
myReader
.
ReadToEnd
();
var
myPrefContents
=
myReader
.
ReadToEnd
();
myReader
.
Close
();
myReader
.
Close
();
if
(!
myPrefContents
.
Contains
(
"user_pref(\"network.proxy.type\", 0);"
))
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
{
// Add the proxy enable line and write it back to the file
var
searchStr
=
$"user_pref(\"network.proxy.type\",
{
i
}
);"
;
myPrefContents
=
myPrefContents
+
"\n\r"
+
"user_pref(\"network.proxy.type\", 0);"
;
File
.
Delete
(
myFfPrefFile
);
if
(
myPrefContents
.
Contains
(
searchStr
))
File
.
WriteAllText
(
myFfPrefFile
,
myPrefContents
);
{
// Add the proxy enable line and write it back to the file
myPrefContents
=
myPrefContents
.
Replace
(
searchStr
,
"user_pref(\"network.proxy.type\", 5);"
);
}
}
}
File
.
Delete
(
myFfPrefFile
);
File
.
WriteAllText
(
myFfPrefFile
,
myPrefContents
);
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
4f8a2170
...
@@ -61,12 +61,13 @@ namespace Titanium.Web.Proxy
...
@@ -61,12 +61,13 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
private
SystemProxyManager
systemProxySettingsManager
{
get
;
}
private
SystemProxyManager
systemProxySettingsManager
{
get
;
}
#if !DEBUG
/// <summary>
/// <summary>
/// Set firefox to use default system proxy
/// Set firefox to use default system proxy
/// </summary>
/// </summary>
private
FireFoxProxySettingsManager
firefoxProxySettingsManager
=
new
FireFoxProxySettingsManager
();
private
FireFoxProxySettingsManager
firefoxProxySettingsManager
#endif
=
new
FireFoxProxySettingsManager
();
/// <summary>
/// <summary>
/// Buffer size used throughout this proxy
/// Buffer size used throughout this proxy
...
@@ -287,9 +288,7 @@ namespace Titanium.Web.Proxy
...
@@ -287,9 +288,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints
=
new
List
<
ProxyEndPoint
>();
ProxyEndPoints
=
new
List
<
ProxyEndPoint
>();
tcpConnectionFactory
=
new
TcpConnectionFactory
();
tcpConnectionFactory
=
new
TcpConnectionFactory
();
systemProxySettingsManager
=
new
SystemProxyManager
();
systemProxySettingsManager
=
new
SystemProxyManager
();
#if !DEBUG
new
FireFoxProxySettingsManager
();
#endif
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
CertificateManager
=
new
CertificateManager
(
ExceptionFunc
);
if
(
rootCertificateName
!=
null
)
if
(
rootCertificateName
!=
null
)
...
@@ -363,9 +362,9 @@ namespace Titanium.Web.Proxy
...
@@ -363,9 +362,9 @@ namespace Titanium.Web.Proxy
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Loopback
)
?
"127.0.0.1"
:
endPoint
.
IpAddress
.
ToString
(),
endPoint
.
Port
);
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Any
)
|
Equals
(
endPoint
.
IpAddress
,
IPAddress
.
Loopback
)
?
"127.0.0.1"
:
endPoint
.
IpAddress
.
ToString
(),
endPoint
.
Port
);
endPoint
.
IsSystemHttpProxy
=
true
;
endPoint
.
IsSystemHttpProxy
=
true
;
#if !DEBUG
firefoxProxySettingsManager
.
AddFirefox
();
firefoxProxySettingsManager
.
UseSystemProxy
();
#endif
Console
.
WriteLine
(
"Set endpoint at Ip {0} and port: {1} as System HTTP Proxy"
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
Console
.
WriteLine
(
"Set endpoint at Ip {0} and port: {1} as System HTTP Proxy"
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
}
}
...
@@ -407,9 +406,8 @@ namespace Titanium.Web.Proxy
...
@@ -407,9 +406,8 @@ namespace Titanium.Web.Proxy
endPoint
.
IsSystemHttpsProxy
=
true
;
endPoint
.
IsSystemHttpsProxy
=
true
;
#if !DEBUG
firefoxProxySettingsManager
.
UseSystemProxy
();
firefoxProxySettingsManager
.
AddFirefox
();
#endif
Console
.
WriteLine
(
"Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy"
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
Console
.
WriteLine
(
"Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy"
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
}
}
...
@@ -500,9 +498,6 @@ namespace Titanium.Web.Proxy
...
@@ -500,9 +498,6 @@ namespace Titanium.Web.Proxy
if
(
setAsSystemProxy
)
if
(
setAsSystemProxy
)
{
{
systemProxySettingsManager
.
DisableAllProxy
();
systemProxySettingsManager
.
DisableAllProxy
();
#if !DEBUG
firefoxProxySettingsManager
.
RemoveFirefox
();
#endif
}
}
foreach
(
var
endPoint
in
ProxyEndPoints
)
foreach
(
var
endPoint
in
ProxyEndPoints
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment