-
Notifications
You must be signed in to change notification settings - Fork 0
/
roleedit.html
159 lines (152 loc) · 6.38 KB
/
roleedit.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/jquery-1.9.0rc1.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<!--<script type="text/javascript" src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.18.4/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="splunkjs/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="splunkjs/css/dashboard.css" />
</head>
<body>
<div id="content">
<p>
<label>Add Index to role(comma-separated,include both existing and new): </label>
<input id="index" type="text" value="" placeholder="main" />
</p>
<p>
<label>Url:</label>
<div id="url"></div>
</p>
<p>
<input type="submit" onclick="return modifyRole();"/>
</p>
</div>
<script type="text/javascript" src="splunkjs/splunk.min.js"></script>
<link rel="stylesheet" type="text/css" href="splunkjs/css/bootstrap.css" />
<script src="splunkjs/config.js"></script>
<script>
var opts = {};
var username = opts.username || "uidev";
var password = opts.password || "uidev";
var scheme = opts.scheme || "https";
var host = opts.host || "10.5.250.38";
var port = opts.port || "8089";
var version = opts.version || "default";
var webapp = opts.webapp || "storage";
var owner = opts.owner || "admin";
var app = opts.app || "search";
var group = opts.group || "admin";
var sharing = opts.sharing || "admin";
var http = new splunkjs.JQueryHttp();
var service = new splunkjs.Service(http, {
username: username,
password: password,
scheme: scheme,
host: host,
port: port,
version: version,
owner : owner,
app: app,
group: group,
sharing : sharing,
});
// Configure SplunkJS Stack
splunkjs.config({
proxyPath: "",
scheme: "",
host: host,
USERNAME: username,
authenticate: function(done) {
console.log('service created');
service.login(function(err, success) {
if (err || !success) {
console.log("Error in logging in" + err.status);
done(err || "Login failed");
return;
}
});
}
});
require.config({
baseUrl: "https://" + host + "/" + webapp
});
function modifyRole(){
rolename = $("#url").html();
if (!rolename) return false;
rolename = rolename.split('/');
if (!rolename) return false;
rolename = rolename[rolename.length-1];
rolename = rolename.trim('/');
if (rolename=="") return false;
delete service.owner;
delete service.app;
delete service.sharing;
delete service.group;
var indexes = $("#index").val();
indexes = indexes.split(",");
params = [];
indexes.forEach(function(element, index, array){
array[index] = array[index].trim();
if (array[index])
params.push(array[index]);
});
var args = {"srchIndexesAllowed": params};
var endpoint = new splunkjs.Service.Endpoint(service, "authorization/roles");
endpoint.post(rolename,
args,
function(err, response) {
if (err) {
//alert(err.response.statusCode + ":" + err.error);
return false;
}
else {
console.log(response.data);
setRoleProps(response);
return true;
}
});
}
var deps = [
//"jquery",
"splunkjs/mvc",
];
require(deps, function(mvc) {
rolename = document.location.search.split("=")[1];
rolename = rolename.trim('/');
delete service.owner;
delete service.app;
delete service.group;
delete service.sharing;
var endpoint = new splunkjs.Service.Endpoint(service, "authorization/roles/"+rolename);
endpoint.get("",
{},
function(err, response) {
if (err) {console.log(err.response.statusCode + ":" + err.error);}
else {
console.log(response.data.entry[0]["id"]);
setRoleProps(response);
}
});
});
function setRoleProps(response) {
var role= response.data.entry[0];
$("#url").html(role["id"]);
$("#index").val(role.content["srchIndexesAllowed"]);
}
</script>
</body>
</html>