Skip to content

Commit

Permalink
Merge pull request #3184 from jipperinbham/ui-auth
Browse files Browse the repository at this point in the history
Set basic auth for admin interface in ajax headers
  • Loading branch information
toddboom committed Jul 4, 2015
2 parents af00eb3 + 567751d commit 212430e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions shared/admin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var currentlySelectedDatabase = null;

// connection settings for the server, with sensible defaults
var connectionSettings = {
hostname: "localhost",
hostname: (window.location.hostname ? window.location.hostname: "localhost"),
port: "8086",
username: "",
password: "",
Expand All @@ -19,6 +19,14 @@ var connectionString = function() {
var protocol = (connectionSettings.ssl ? "https" : "http");
var host = connectionSettings.hostname + ":" + connectionSettings.port;

if (connectionSettings.username !== "") {
$.ajaxSetup({
headers: {
'Authorization': "Basic " + btoa(connectionSettings.username + ":" + connectionSettings.password)
}
});
}

return protocol + "://" + host;
}

Expand All @@ -27,7 +35,7 @@ var getSeriesFromJSON = function(data) {
return results;
}

// gets settings from the browser's localStorage and sets defaults if they aren't found
// gets settings from the browser's localStorage and sets defaults if they aren't found
var loadSettings = function() {
var cs = localStorage.getItem("connectionSettings");

Expand Down Expand Up @@ -166,7 +174,7 @@ var handleSubmit = function(e) {
}

var values = series[0].values;

if ((values == null) || (values.length == 0)) {
showQueryError("Query returned no results!");
} else {
Expand Down Expand Up @@ -242,11 +250,11 @@ var stringifyTags = function(tags) {
var DataTable = React.createClass({
render: function() {
var tables = this.props.series.map(function(series) {
return React.createElement("div", null,
React.createElement("h1", null, series.name),
React.createElement("h2", null, stringifyTags(series.tags)),
React.createElement("table", {className: "table"},
React.createElement(TableHeader, {data: series.columns}),
return React.createElement("div", null,
React.createElement("h1", null, series.name),
React.createElement("h2", null, stringifyTags(series.tags)),
React.createElement("table", {className: "table"},
React.createElement(TableHeader, {data: series.columns}),
React.createElement(TableBody, {data: series})
)
);
Expand Down Expand Up @@ -293,7 +301,7 @@ var chooseDatabase = function (databaseName) {

var getDatabases = function () {
var q = "SHOW DATABASES";

var query = $.get(connectionString() + "/query", {q: q, db: currentlySelectedDatabase}, function() {
hideDatabaseWarning();
});
Expand All @@ -320,7 +328,7 @@ var getDatabases = function () {

var series = getSeriesFromJSON(data);
var values = series[0].values;

if ((values == null) || (values.length == 0)) {
availableDatabases = [];
updateDatabaseList();
Expand Down
2 changes: 1 addition & 1 deletion statik/statik.go

Large diffs are not rendered by default.

0 comments on commit 212430e

Please sign in to comment.