Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hotspot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
hotspot
Commits
a77a56ee
Verified
Commit
a77a56ee
authored
4 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Address website review comments
parent
63c86874
No related branches found
No related tags found
1 merge request
!9
Use HTML template to render designed website
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/org/briarproject/hotspot/NetworkUtils.java
+7
-1
7 additions, 1 deletion
app/src/main/java/org/briarproject/hotspot/NetworkUtils.java
app/src/main/java/org/briarproject/hotspot/WebServer.java
+21
-14
21 additions, 14 deletions
app/src/main/java/org/briarproject/hotspot/WebServer.java
with
28 additions
and
15 deletions
app/src/main/java/org/briarproject/hotspot/NetworkUtils.java
+
7
−
1
View file @
a77a56ee
...
...
@@ -7,14 +7,20 @@ import java.net.NetworkInterface;
import
java.net.SocketException
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.logging.Logger
;
import
androidx.annotation.Nullable
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
list
;
import
static
java
.
util
.
logging
.
Level
.
WARNING
;
import
static
java
.
util
.
logging
.
Logger
.
getLogger
;
import
static
org
.
briarproject
.
hotspot
.
LogUtils
.
logException
;
class
NetworkUtils
{
private
final
static
Logger
LOG
=
getLogger
(
NetworkUtils
.
class
.
getName
());
@Nullable
static
InetAddress
getAccessPointAddress
()
{
for
(
NetworkInterface
i
:
getNetworkInterfaces
())
{
...
...
@@ -48,7 +54,7 @@ class NetworkUtils {
NetworkInterface
.
getNetworkInterfaces
();
return
ifaces
==
null
?
emptyList
()
:
list
(
ifaces
);
}
catch
(
SocketException
e
)
{
e
.
printStackTrace
(
);
logException
(
LOG
,
WARNING
,
e
);
return
emptyList
();
}
}
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/org/briarproject/hotspot/WebServer.java
+
21
−
14
View file @
a77a56ee
...
...
@@ -10,6 +10,7 @@ import java.io.FileInputStream;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.logging.Logger
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -21,13 +22,19 @@ import static fi.iki.elonen.NanoHTTPD.Response.Status.INTERNAL_ERROR;
import
static
fi
.
iki
.
elonen
.
NanoHTTPD
.
Response
.
Status
.
NOT_FOUND
;
import
static
fi
.
iki
.
elonen
.
NanoHTTPD
.
Response
.
Status
.
OK
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
static
java
.
util
.
logging
.
Level
.
WARNING
;
import
static
java
.
util
.
logging
.
Logger
.
getLogger
;
import
static
org
.
briarproject
.
hotspot
.
BuildConfig
.
VERSION_NAME
;
import
static
org
.
briarproject
.
hotspot
.
LogUtils
.
logException
;
public
class
WebServer
extends
NanoHTTPD
{
final
static
int
PORT
=
9999
;
private
static
final
Logger
LOG
=
getLogger
(
WebServer
.
class
.
getName
());
private
static
final
String
FILE_HTML
=
"hotspot.html"
;
private
final
Pattern
REGEX_AGENT
=
Pattern
.
compile
(
"Android ([0-9]+)"
);
private
static
final
Pattern
REGEX_AGENT
=
Pattern
.
compile
(
"Android ([0-9]+)"
);
private
final
Context
ctx
;
...
...
@@ -45,20 +52,20 @@ public class WebServer extends NanoHTTPD {
if
(
session
.
getUri
().
endsWith
(
"favicon.ico"
))
{
return
newFixedLengthResponse
(
NOT_FOUND
,
MIME_PLAINTEXT
,
NOT_FOUND
.
getDescription
());
}
else
if
(
session
.
getUri
().
endsWith
(
".apk"
))
{
}
if
(
session
.
getUri
().
endsWith
(
".apk"
))
{
return
serveApk
();
}
else
{
Response
res
;
try
{
String
html
=
getHtml
(
session
.
getHeaders
().
get
(
"user-agent"
));
res
=
newFixedLengthResponse
(
OK
,
MIME_HTML
,
html
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
res
=
newFixedLengthResponse
(
INTERNAL_ERROR
,
MIME_PLAINTEXT
,
INTERNAL_ERROR
.
getDescription
());
}
return
res
;
}
Response
res
;
try
{
String
html
=
getHtml
(
session
.
getHeaders
().
get
(
"user-agent"
));
res
=
newFixedLengthResponse
(
OK
,
MIME_HTML
,
html
);
}
catch
(
Exception
e
)
{
logException
(
LOG
,
WARNING
,
e
);
res
=
newFixedLengthResponse
(
INTERNAL_ERROR
,
MIME_PLAINTEXT
,
INTERNAL_ERROR
.
getDescription
());
}
return
res
;
}
private
String
getHtml
(
@Nullable
String
userAgent
)
throws
Exception
{
...
...
@@ -112,7 +119,7 @@ public class WebServer extends NanoHTTPD {
res
=
newFixedLengthResponse
(
OK
,
mime
,
fis
,
fileLen
);
res
.
addHeader
(
"Content-Length"
,
""
+
fileLen
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
(
);
logException
(
LOG
,
WARNING
,
e
);
res
=
newFixedLengthResponse
(
NOT_FOUND
,
MIME_PLAINTEXT
,
"Error 404, file not found."
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment