-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathUI.java
130 lines (112 loc) · 2.59 KB
/
UI.java
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
import java.util.Map;
import fi.iki.elonen.*;
import java.sql.*;
import java.io.IOException;
public class UI extends NanoHTTPD
{
public static int webPort = 8080;
public static String gpVersion = "AO";
public static String sessions = "";
public static String configFile = "";
public static void main(String[] args)
{
for (int i = 0; i < args.length; ++i)
{
if (i == 0)
webPort = Integer.parseInt(args[0]);
if (i == 1)
sessions = args[1];
if (i == 2)
configFile = args[2];
}
gpVersion = UIModel.getVersion();
ServerRunnerUI.run(UI.class);
}
public UI()
{
super(webPort);
}
@Override
public Response serve(String uri, Method method, Map<String, String> header, Map<String, String> parms, Map<String, String> files)
{
String username = parms.get("username");
String password = parms.get("password");
String submit = parms.get("submit_form");
String action_type = parms.get("action_type");
String loginMessage = "";
boolean alive = false;
String msg = "";
boolean auth = false;
if (submit == null || submit.equals(""))
submit = "0";
if (username == null)
username = "";
if (password == null)
password = "";
if (action_type == null)
action_type = "";
String sessionID = UIModel.getSessionID(header);
if (sessionID == null)
sessionID = "0";
if (action_type.equals("logout"))
{
sessionID = "0";
}
if (!uri.equals("/favicon.ico"))
{
if (submit.equals("1") && (!username.equals("")) && (!password.equals("")))
{
try
{
auth = UIModel.authenticate(username, password);
}
catch (SQLException ex)
{
loginMessage = ex.getMessage();
}
if (auth)
{
sessionID = UIModel.setSessionID(header);
try
{
UIModel.insertSession(sessionID);
}
catch (SQLException ex)
{
loginMessage = ex.getMessage();
}
}
else if (loginMessage.equals(""))
{
loginMessage = "Failed to login. Must use a valid Greenplum database account that is a SuperUser.";
}
}
if (!(sessionID.equals("0")))
{
try
{
alive = UIModel.keepAlive(sessionID);
}
catch (SQLException ex)
{
loginMessage = ex.getMessage();
}
}
if (alive)
msg = OutsourcerControl.buildPage(uri, parms);
else
sessionID = "0";
if (sessionID.equals("0"))
{
msg = UIView.viewLogin(loginMessage);
}
}
NanoHTTPD.Response out = new NanoHTTPD.Response(msg);
if (!uri.equals("/favicon.ico"))
{
out.addHeader("Set-Cookie", "OutsourcerSessionID=" + sessionID + ";");
UIModel.logger(uri, sessionID);
}
return out;
}
}