2007-06-22 19:07:28 +00:00
|
|
|
//
|
|
|
|
|
// The Antville Project
|
2007-06-22 19:12:44 +00:00
|
|
|
// http://code.google.com/p/antville
|
2007-06-22 19:07:28 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2001-2007 by The Antville People
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an ``AS IS'' BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
// $Revision$
|
|
|
|
|
// $LastChangedBy$
|
|
|
|
|
// $LastChangedDate$
|
2007-06-22 19:12:44 +00:00
|
|
|
// $URL$
|
2007-06-22 19:07:28 +00:00
|
|
|
//
|
|
|
|
|
|
2008-04-22 14:57:18 +00:00
|
|
|
Root.VERSION = "1.2";
|
2008-03-26 12:33:54 +00:00
|
|
|
|
2008-06-15 17:22:44 +00:00
|
|
|
Root.getScopes = defineConstants(Root, markgettext("any site"),
|
2007-09-14 23:25:23 +00:00
|
|
|
markgettext("public sites"), markgettext("trusted sites"),
|
|
|
|
|
markgettext("no site"));
|
|
|
|
|
|
|
|
|
|
this.handleMetadata("notificationScope");
|
|
|
|
|
this.handleMetadata("quota");
|
|
|
|
|
this.handleMetadata("creationScope");
|
|
|
|
|
this.handleMetadata("creationDelay");
|
|
|
|
|
this.handleMetadata("qualifyingPeriod");
|
|
|
|
|
this.handleMetadata("qualifyingDate");
|
|
|
|
|
this.handleMetadata("autoCleanupEnabled");
|
|
|
|
|
this.handleMetadata("autoCleanupStartTime");
|
|
|
|
|
this.handleMetadata("phaseOutPrivateSites");
|
|
|
|
|
this.handleMetadata("phaseOutInactiveSites");
|
|
|
|
|
this.handleMetadata("phaseOutNotificationPeriod");
|
|
|
|
|
this.handleMetadata("phaseOutGracePeriod");
|
|
|
|
|
|
2008-05-14 11:11:56 +00:00
|
|
|
Root.restore = function(ref) {
|
|
|
|
|
var backup;
|
|
|
|
|
if (backup = session.data.backup) {
|
|
|
|
|
ref.title = decodeURIComponent(backup.title);
|
|
|
|
|
ref.text = decodeURIComponent(backup.text);
|
|
|
|
|
}
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:58:26 +00:00
|
|
|
Root.commitRequests = function() {
|
|
|
|
|
var requests = app.data.requests;
|
|
|
|
|
app.data.requests = {};
|
|
|
|
|
for each (var item in requests) {
|
|
|
|
|
switch (item.type) {
|
|
|
|
|
case Story:
|
|
|
|
|
var story = Story.getById(item.id);
|
|
|
|
|
story && (story.requests = item.requests);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-15 13:47:58 +00:00
|
|
|
res.commit();
|
2008-05-15 12:58:26 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-15 17:42:49 +00:00
|
|
|
Root.commitEntries = function() {
|
2008-06-15 20:28:25 +00:00
|
|
|
var entries = app.data.entries;
|
|
|
|
|
if (entries.length < 1) {
|
2008-05-15 12:58:26 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-15 17:42:49 +00:00
|
|
|
app.data.entries = [];
|
2008-05-15 12:58:26 +00:00
|
|
|
var history = [];
|
|
|
|
|
|
2008-06-15 20:28:25 +00:00
|
|
|
for each (var item in entries) {
|
2008-05-15 12:58:26 +00:00
|
|
|
var referrer = helma.Http.evalUrl(item.referrer);
|
|
|
|
|
if (!referrer) {
|
2008-05-15 13:47:58 +00:00
|
|
|
continue;
|
2008-05-15 12:58:26 +00:00
|
|
|
}
|
2008-05-15 13:47:58 +00:00
|
|
|
|
2008-05-15 12:58:26 +00:00
|
|
|
// Only log unique combinations of context, ip and referrer
|
|
|
|
|
referrer = String(referrer);
|
|
|
|
|
var key = item.context_type + "#" + item.context_id + ":" +
|
|
|
|
|
item.ip + ":" + referrer;
|
|
|
|
|
if (history.indexOf(key) > -1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
history.push(key);
|
|
|
|
|
|
|
|
|
|
// Exclude requests coming from the same site
|
|
|
|
|
if (item.site) {
|
|
|
|
|
var href = item.site.href().toLowerCase();
|
2008-05-15 13:47:58 +00:00
|
|
|
if (referrer.toLowerCase().contains(href.substr(0, href.length-1))) {
|
2008-05-15 12:58:26 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-15 15:15:08 +00:00
|
|
|
item.persist();
|
2008-05-15 12:58:26 +00:00
|
|
|
}
|
2008-05-15 13:47:58 +00:00
|
|
|
|
2008-05-15 12:58:26 +00:00
|
|
|
res.commit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Root.purgeReferrers = function() {
|
|
|
|
|
var sql = new Sql;
|
|
|
|
|
var result = sql.execute("delete from log where action = 'main' and " +
|
2008-05-15 13:59:53 +00:00
|
|
|
"created < date_add(now(), interval -1 day)");
|
2008-05-15 12:58:26 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-12 14:02:42 +00:00
|
|
|
Root.invokeCallbacks = function() {
|
|
|
|
|
var http = helma.Http();
|
|
|
|
|
http.setTimeout(200);
|
|
|
|
|
http.setReadTimeout(300);
|
|
|
|
|
http.setMethod("POST");
|
|
|
|
|
|
|
|
|
|
var ref, site, item;
|
|
|
|
|
while (ref = app.data.callbacks.pop()) {
|
|
|
|
|
site = Site.getById(ref.site);
|
|
|
|
|
item = ref.handler && ref.handler.getById(ref.id);
|
|
|
|
|
if (!site || !item) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
app.log("Invoking callback URL " + site.callbackUrl + " for " + item);
|
|
|
|
|
try {
|
|
|
|
|
http.setContent({
|
|
|
|
|
type: item.constructor.name,
|
|
|
|
|
id: item.name || item._id,
|
|
|
|
|
url: item.href(),
|
|
|
|
|
date: item.modified.valueOf(),
|
|
|
|
|
user: item.modifier.name,
|
2008-06-12 14:41:30 +00:00
|
|
|
site: site.title || site.name,
|
|
|
|
|
origin: site.href()
|
2008-06-12 14:02:42 +00:00
|
|
|
});
|
|
|
|
|
http.getUrl(site.callbackUrl);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
app.debug("Invoking callback URL " + site.callbackUrl + " failed: " + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Root.updateHealth = function() {
|
|
|
|
|
var health = Root.health || {};
|
|
|
|
|
if (!health.modified || new Date - health.modified > 5 * Date.ONEMINUTE) {
|
|
|
|
|
health.modified = new Date;
|
|
|
|
|
health.requestsPerUnit = app.requestCount -
|
|
|
|
|
(health.currentRequestCount || 0);
|
|
|
|
|
health.currentRequestCount = app.requestCount;
|
|
|
|
|
health.errorsPerUnit = app.errorCount - (health.currentErrorCount || 0);
|
|
|
|
|
health.currentErrorCount = app.errorCount;
|
|
|
|
|
Root.health = health;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-14 15:27:47 +00:00
|
|
|
Root.exportImport = function() {
|
2009-09-21 13:24:37 +00:00
|
|
|
if (app.data.exportImportIsRunning) {
|
2008-12-14 15:27:47 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
app.invokeAsync(this, function() {
|
2009-09-21 13:24:37 +00:00
|
|
|
app.data.exportImportIsRunning = true;
|
2008-12-14 15:27:47 +00:00
|
|
|
Exporter.run();
|
2008-12-14 19:49:12 +00:00
|
|
|
Importer.run();
|
2009-09-21 13:24:37 +00:00
|
|
|
app.data.exportImportIsRunning = false;
|
2008-12-14 15:27:47 +00:00
|
|
|
}, [], -1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-14 11:11:56 +00:00
|
|
|
Root.prototype.processHref = function(href) {
|
|
|
|
|
return app.properties.defaulthost + href;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-14 23:25:23 +00:00
|
|
|
Root.prototype.getPermission = function(action) {
|
|
|
|
|
if (action.contains("admin")) {
|
2007-10-01 21:52:25 +00:00
|
|
|
return User.require(User.PRIVILEGED);
|
2007-09-14 23:25:23 +00:00
|
|
|
}
|
|
|
|
|
switch (action) {
|
2008-04-15 21:16:21 +00:00
|
|
|
case "debug":
|
2007-10-16 16:48:14 +00:00
|
|
|
return true;
|
2007-09-14 23:25:23 +00:00
|
|
|
case "create":
|
2008-12-14 19:49:12 +00:00
|
|
|
case "import":
|
2008-10-15 08:37:08 +00:00
|
|
|
return User.require(User.PRIVILEGED); // this.getCreationPermission();
|
2007-10-16 13:33:10 +00:00
|
|
|
case "default.hook":
|
2008-10-15 08:37:08 +00:00
|
|
|
case "health":
|
|
|
|
|
case "mrtg":
|
2008-01-13 01:39:01 +00:00
|
|
|
case "sites":
|
2008-10-15 08:37:08 +00:00
|
|
|
case "sitemap.xml":
|
2007-10-12 10:20:46 +00:00
|
|
|
case "updates.xml":
|
2007-10-06 10:26:30 +00:00
|
|
|
return this.mode !== Site.CLOSED;
|
2007-09-14 23:25:23 +00:00
|
|
|
}
|
|
|
|
|
return Site.prototype.getPermission.apply(this, arguments);
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-10-08 23:55:29 +00:00
|
|
|
|
2007-10-09 15:09:06 +00:00
|
|
|
Root.prototype.main_action = function() {
|
2008-09-21 17:44:18 +00:00
|
|
|
// FIXME: Should this better go into HopObject.onRequest?
|
|
|
|
|
if (this.users.size() < 1) {
|
|
|
|
|
root.title = "Antville";
|
|
|
|
|
res.redirect(this.members.href("register"));
|
|
|
|
|
} else if (session.user && this.members.owners.size() < 1) {
|
|
|
|
|
this.creator = this.modifier = this.layout.creator =
|
|
|
|
|
this.layout.modifier = session.user;
|
|
|
|
|
this.created = this.modified =
|
|
|
|
|
this.layout.created = this.layout.modified = new Date;
|
|
|
|
|
session.user.role = User.PRIVILEGED;
|
|
|
|
|
res.handlers.membership.role = Membership.OWNER;
|
|
|
|
|
}
|
2008-04-21 20:46:29 +00:00
|
|
|
return Site.prototype.main_action.apply(this);
|
|
|
|
|
|
2008-04-15 21:16:21 +00:00
|
|
|
/*var re = /("[^"]*"|'[^']*'|<%(\S*)|/gm;
|
|
|
|
|
var macro = '"1xfoo {0} 2xbar {1}" foo "bar bar" <% test %>';
|
|
|
|
|
var result = macro.replace(re, function() {
|
|
|
|
|
res.debug(arguments[1])
|
|
|
|
|
});
|
|
|
|
|
// res.debug(result)
|
|
|
|
|
return;*/
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-06-22 19:07:28 +00:00
|
|
|
|
2007-09-30 23:59:13 +00:00
|
|
|
Root.prototype.getFormOptions = function(name) {
|
|
|
|
|
switch (name) {
|
|
|
|
|
case "notificationScope":
|
|
|
|
|
return Root.getScopes();
|
|
|
|
|
case "creationScope":
|
|
|
|
|
return User.getScopes();
|
|
|
|
|
case "autoCleanupStartTime":
|
|
|
|
|
return Admin.getHours();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return Site.prototype.getFormOptions.apply(this, arguments);
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-30 23:59:13 +00:00
|
|
|
|
2007-09-14 13:13:50 +00:00
|
|
|
Root.prototype.error_action = function() {
|
2008-05-14 11:11:56 +00:00
|
|
|
res.status = 500;
|
2007-09-14 23:25:23 +00:00
|
|
|
res.data.title = root.getTitle() + " - Error";
|
2008-05-14 11:11:56 +00:00
|
|
|
res.data.body = root.renderSkinAsString("$Root#error", res);
|
|
|
|
|
res.handlers.site.renderSkin("Site#page");
|
2007-09-14 23:25:23 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-14 23:25:23 +00:00
|
|
|
|
|
|
|
|
Root.prototype.notfound_action = function() {
|
2008-05-14 11:11:56 +00:00
|
|
|
res.status = 404;
|
|
|
|
|
res.data.title = root.getTitle() + " - Error";
|
|
|
|
|
res.data.body = root.renderSkinAsString("$Root#notfound", req);
|
|
|
|
|
res.handlers.site.renderSkin("Site#page");
|
2007-09-14 13:13:50 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-09-14 13:13:50 +00:00
|
|
|
|
2007-09-08 17:20:59 +00:00
|
|
|
Root.prototype.create_action = function() {
|
2007-10-08 23:55:29 +00:00
|
|
|
var site = new Site;
|
2007-09-08 17:20:59 +00:00
|
|
|
if (req.postParams.create) {
|
2007-06-22 19:07:28 +00:00
|
|
|
try {
|
2007-10-08 23:55:29 +00:00
|
|
|
site.update(req.postParams);
|
2008-09-21 17:44:18 +00:00
|
|
|
|
2009-09-21 13:24:37 +00:00
|
|
|
var copy = function(source, target) {
|
2008-09-21 17:44:18 +00:00
|
|
|
source.list().forEach(function(name) {
|
|
|
|
|
var file = new helma.File(source, name);
|
|
|
|
|
if (file.isDirectory()) {
|
2009-09-21 13:24:37 +00:00
|
|
|
copy(file, new helma.File(target, name));
|
2008-09-21 17:44:18 +00:00
|
|
|
} else {
|
2009-09-21 13:24:37 +00:00
|
|
|
target.makeDirectory();
|
|
|
|
|
file.hardCopy(new helma.File(target, name));
|
2008-09-21 17:44:18 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2009-09-21 13:24:37 +00:00
|
|
|
copy(root.layout.getFile(), site.layout.getFile());
|
2008-09-21 17:44:18 +00:00
|
|
|
|
2007-10-08 23:55:29 +00:00
|
|
|
this.add(site);
|
|
|
|
|
site.members.add(new Membership(session.user, Membership.OWNER));
|
2008-06-15 20:28:25 +00:00
|
|
|
root.admin.log(site, "Added site");
|
2008-12-14 15:27:47 +00:00
|
|
|
res.message = gettext("Successfully created your site.");
|
2007-09-08 17:20:59 +00:00
|
|
|
res.redirect(site.href());
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
res.message = ex;
|
|
|
|
|
app.log(ex);
|
2007-06-22 19:07:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.data.action = this.href(req.action);
|
2007-09-08 17:20:59 +00:00
|
|
|
res.data.title = gettext("Create a new site");
|
2008-04-21 13:35:50 +00:00
|
|
|
res.data.body = site.renderSkinAsString("$Site#create");
|
2008-01-13 01:39:01 +00:00
|
|
|
root.renderSkin("Site#page");
|
2007-06-22 19:07:28 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-06-22 19:07:28 +00:00
|
|
|
|
2008-01-13 01:39:01 +00:00
|
|
|
Root.prototype.sites_action = function() {
|
|
|
|
|
res.data.list = renderList(root.sites,
|
2008-10-15 08:37:08 +00:00
|
|
|
"$Site#listItem", 25, req.queryParams.page);
|
2008-01-13 01:39:01 +00:00
|
|
|
res.data.pager = renderPager(root.sites,
|
2008-10-15 08:37:08 +00:00
|
|
|
this.href(req.action), 25, req.queryParams.page);
|
2008-01-13 01:39:01 +00:00
|
|
|
res.data.title = gettext("Sites of {0}", root.title);
|
2008-10-15 08:37:08 +00:00
|
|
|
res.data.body = this.renderSkinAsString("$Root#sites");
|
2008-01-13 01:39:01 +00:00
|
|
|
root.renderSkin("Site#page");
|
2007-06-22 19:07:28 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-06-22 19:07:28 +00:00
|
|
|
|
2007-10-12 10:20:46 +00:00
|
|
|
Root.prototype.updates_xml_action = function() {
|
|
|
|
|
var now = new Date;
|
|
|
|
|
var feed = new rome.SyndFeedImpl();
|
|
|
|
|
feed.setFeedType("rss_2.0");
|
|
|
|
|
feed.setLink(root.href());
|
2008-04-15 21:16:21 +00:00
|
|
|
feed.setTitle("Recently updated sites at " + root.title);
|
2007-10-12 10:20:46 +00:00
|
|
|
feed.setDescription(root.tagline);
|
2007-10-21 16:49:16 +00:00
|
|
|
feed.setLanguage(root.locale.replace("_", "-"));
|
2007-10-12 10:20:46 +00:00
|
|
|
feed.setPublishedDate(now);
|
|
|
|
|
var entries = new java.util.ArrayList();
|
|
|
|
|
var entry, description;
|
2008-05-09 20:50:45 +00:00
|
|
|
var sites = root.updates.list(0, 25).sort(Number.Sorter("modified",
|
2008-04-15 21:16:21 +00:00
|
|
|
Number.Sorter.DESC));
|
|
|
|
|
for each (var site in sites) {
|
2007-10-12 10:20:46 +00:00
|
|
|
entry = new rome.SyndEntryImpl();
|
|
|
|
|
entry.setTitle(site.title);
|
|
|
|
|
entry.setLink(site.href());
|
|
|
|
|
entry.setAuthor(site.creator.name);
|
2008-03-27 15:10:31 +00:00
|
|
|
entry.setPublishedDate(site.modified);
|
2007-10-12 10:20:46 +00:00
|
|
|
description = new rome.SyndContentImpl();
|
|
|
|
|
description.setType("text/plain");
|
|
|
|
|
description.setValue(site.tagline);
|
|
|
|
|
entry.setDescription(description);
|
|
|
|
|
entries.add(entry);
|
2007-06-22 19:07:28 +00:00
|
|
|
}
|
2007-10-12 10:20:46 +00:00
|
|
|
feed.setEntries(entries);
|
|
|
|
|
var output = new rome.SyndFeedOutput();
|
|
|
|
|
//output.output(feed, res.servletResponse.writer); return;
|
|
|
|
|
var xml = output.outputString(feed);
|
|
|
|
|
res.contentType = "text/xml";
|
2008-03-27 15:10:31 +00:00
|
|
|
res.write(xml); //injectXslDeclaration(xml));
|
2007-06-22 19:07:28 +00:00
|
|
|
return;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|
2007-06-22 19:07:28 +00:00
|
|
|
|
2008-10-15 08:37:08 +00:00
|
|
|
Root.prototype.sitemap_xml_action = function() {
|
|
|
|
|
res.contentType = "text/xml";
|
|
|
|
|
res.writeln('<?xml version="1.0" encoding="UTF-8"?>');
|
|
|
|
|
res.writeln('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
|
|
|
|
|
this.sites.forEach(function() {
|
|
|
|
|
res.writeln('<url>');
|
|
|
|
|
res.writeln('<loc>' + this.href() + '</loc>');
|
|
|
|
|
if (this.modified) {
|
|
|
|
|
res.writeln('<lastmod>' + this.modified.format("yyyy-MM-dd") + '</lastmod>');
|
|
|
|
|
}
|
|
|
|
|
res.writeln('</url>');
|
|
|
|
|
});
|
|
|
|
|
res.writeln('</urlset>');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-14 12:25:15 +00:00
|
|
|
Root.prototype.health_action = function() {
|
|
|
|
|
var jvm = java.lang.Runtime.getRuntime();
|
|
|
|
|
var totalMemory = jvm.totalMemory() / 1024 / 1024;
|
|
|
|
|
var freeMemory = jvm.freeMemory() / 1024 / 1024;
|
|
|
|
|
|
2008-05-14 13:30:28 +00:00
|
|
|
var param = {
|
|
|
|
|
uptime: formatNumber((new Date - app.upSince.getTime()) /
|
|
|
|
|
Date.ONEDAY, "0.##"),
|
|
|
|
|
freeMemory: formatNumber(freeMemory),
|
|
|
|
|
totalMemory: formatNumber(totalMemory),
|
|
|
|
|
usedMemory: formatNumber(totalMemory - freeMemory),
|
|
|
|
|
sessions: formatNumber(app.countSessions()),
|
|
|
|
|
cacheSize: formatNumber(getProperty("cacheSize"))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for each (key in ["activeThreads", "freeThreads", "requestCount",
|
|
|
|
|
"errorCount", "xmlrpcCount", "cacheusage"]) {
|
|
|
|
|
param[key] = formatNumber(app[key]);
|
|
|
|
|
}
|
2008-05-14 12:54:44 +00:00
|
|
|
|
|
|
|
|
if (Root.health) {
|
2008-05-14 13:16:12 +00:00
|
|
|
param.requestsPerUnit = formatNumber(Root.health.requestsPerUnit);
|
|
|
|
|
param.errorsPerUnit = formatNumber(Root.health.errorsPerUnit);
|
2008-05-14 12:54:44 +00:00
|
|
|
}
|
2008-06-12 14:02:42 +00:00
|
|
|
|
2008-06-15 17:42:49 +00:00
|
|
|
param.entries = app.data.entries.length;
|
2008-06-12 14:02:42 +00:00
|
|
|
param.mails = app.data.mails.length;
|
2008-06-12 14:41:30 +00:00
|
|
|
param.requests = 0;
|
|
|
|
|
for (var i in app.data.requests) {
|
|
|
|
|
param.requests += 1;
|
|
|
|
|
}
|
|
|
|
|
param.callbacks = app.data.callbacks.length;
|
2008-05-14 12:25:15 +00:00
|
|
|
|
|
|
|
|
res.data.title = "Health of " + root.getTitle();
|
|
|
|
|
res.data.body = this.renderSkinAsString("$Root#health", param);
|
|
|
|
|
this.renderSkin("Site#page");
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-14 19:49:12 +00:00
|
|
|
Root.prototype.import_action = function() {
|
|
|
|
|
res.debug(app.data.imports.toSource())
|
|
|
|
|
var baseDir = this.getStaticFile();
|
|
|
|
|
var importDir = new java.io.File(baseDir, "import");
|
|
|
|
|
if (req.postParams.submit === "import") {
|
|
|
|
|
var data = req.postParams;
|
|
|
|
|
try {
|
|
|
|
|
if (!data.file) {
|
|
|
|
|
throw Error(gettext("Please choose a ZIP file to import"));
|
|
|
|
|
}
|
|
|
|
|
var site = new Site;
|
|
|
|
|
site.update({name: data.name});
|
|
|
|
|
site.members.add(new Membership(session.user, Membership.OWNER));
|
|
|
|
|
root.add(site);
|
|
|
|
|
Importer.add(new java.io.File(importDir, data.file),
|
|
|
|
|
site, session.user);
|
2008-12-14 22:04:47 +00:00
|
|
|
res.message = gettext("Queued import of {0} into site »{1}«",
|
|
|
|
|
data.file, site.name);
|
2008-12-14 19:49:12 +00:00
|
|
|
res.redirect(this.href(req.action));
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
res.message = ex.toString();
|
|
|
|
|
app.log(ex.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.push();
|
|
|
|
|
for each (var file in importDir.listFiles()) {
|
|
|
|
|
if (file.toString().endsWith(".zip")) {
|
2008-12-14 22:04:47 +00:00
|
|
|
this.renderSkin("$Root#importItem", {
|
|
|
|
|
file: file.getName(),
|
|
|
|
|
status: Importer.getStatus(file)
|
|
|
|
|
});
|
2008-12-14 19:49:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
res.data.body = this.renderSkinAsString("$Root#import", {list: res.pop()});
|
|
|
|
|
this.renderSkin("Site#page");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-05 10:44:27 +00:00
|
|
|
Root.prototype.mrtg_action = function() {
|
|
|
|
|
res.contentType = "text/plain";
|
|
|
|
|
switch (req.queryParams.target) {
|
|
|
|
|
case "cache":
|
2008-10-10 18:02:18 +00:00
|
|
|
res.writeln(0);
|
|
|
|
|
res.writeln(app.cacheusage * 100 / getProperty("cacheSize"));
|
2008-10-05 10:44:27 +00:00
|
|
|
break;
|
|
|
|
|
case "threads":
|
2008-10-10 18:02:18 +00:00
|
|
|
res.writeln(0);
|
|
|
|
|
res.writeln(app.activeThreads * 100 / app.freeThreads);
|
2008-10-05 10:44:27 +00:00
|
|
|
break;
|
|
|
|
|
case "requests":
|
2008-10-09 19:40:48 +00:00
|
|
|
res.writeln(app.errorCount);
|
|
|
|
|
res.writeln(app.requestCount);
|
2008-10-05 10:44:27 +00:00
|
|
|
break;
|
|
|
|
|
case "users":
|
|
|
|
|
res.writeln(app.countSessions());
|
|
|
|
|
res.writeln(root.users.size());
|
|
|
|
|
break;
|
|
|
|
|
case "postings":
|
|
|
|
|
var db = getDBConnection("antville");
|
2008-10-05 11:33:51 +00:00
|
|
|
var postings = db.executeRetrieval("select count(*) as count from content");
|
|
|
|
|
postings.next();
|
2008-10-10 18:02:18 +00:00
|
|
|
res.writeln(0);
|
2008-10-07 16:37:58 +00:00
|
|
|
res.writeln(postings.getColumnItem("count"));
|
2008-10-05 11:33:51 +00:00
|
|
|
postings.release();
|
2008-10-05 10:44:27 +00:00
|
|
|
break;
|
|
|
|
|
case "uploads":
|
|
|
|
|
var db = getDBConnection("antville");
|
|
|
|
|
var files = db.executeRetrieval("select count(*) as count from file");
|
|
|
|
|
var images = db.executeRetrieval("select count(*) as count from image");
|
|
|
|
|
files.next();
|
|
|
|
|
images.next()
|
|
|
|
|
res.writeln(files.getColumnItem("count"));
|
|
|
|
|
res.writeln(images.getColumnItem("count"));
|
|
|
|
|
files.release();
|
|
|
|
|
images.release();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-10 18:02:18 +00:00
|
|
|
res.writeln(app.upSince);
|
|
|
|
|
res.writeln("mrtg." + req.queryParams.target + " of Antville version " + Root.VERSION);
|
2008-10-05 10:44:27 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-14 11:11:56 +00:00
|
|
|
Root.prototype.getMacroHandler = function(name) {
|
|
|
|
|
switch (name) {
|
|
|
|
|
case "admin":
|
2008-06-12 09:40:39 +00:00
|
|
|
case "api":
|
|
|
|
|
case "sites":
|
2008-05-14 11:11:56 +00:00
|
|
|
return this[name];
|
|
|
|
|
}
|
|
|
|
|
return Site.prototype.getMacroHandler.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-14 23:25:23 +00:00
|
|
|
Root.prototype.getCreationPermission = function() {
|
|
|
|
|
var user;
|
|
|
|
|
if (!(user = session.user)) {
|
|
|
|
|
return false;
|
2007-10-01 21:52:25 +00:00
|
|
|
} if (User.require(User.PRIVILEGED)) {
|
2007-09-14 23:25:23 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-06-22 19:31:18 +00:00
|
|
|
|
2007-09-14 23:25:23 +00:00
|
|
|
switch (root.creationScope) {
|
|
|
|
|
case User.PRIVILEGEDUSERS:
|
|
|
|
|
return false;
|
|
|
|
|
case User.TRUSTEDUSERS:
|
2007-10-01 21:52:25 +00:00
|
|
|
return User.require(User.TRUSTED);
|
2007-09-14 23:25:23 +00:00
|
|
|
default:
|
|
|
|
|
case User.ALLUSERS:
|
|
|
|
|
if (root.qualifyingPeriod) {
|
|
|
|
|
var days = Math.floor((new Date - user.created) / Date.ONEDAY);
|
|
|
|
|
if (days < root.qualifyingPeriod) {
|
|
|
|
|
//throw Error(gettext("Sorry, you have to be a member for at " +
|
|
|
|
|
// "least {0} days to create a new site.",
|
|
|
|
|
// formatDate(root.qualifyingPeriod));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (root.qualifyingDate) {
|
|
|
|
|
if (user.created > root.qualifyingDate) {
|
|
|
|
|
//throw Error(gettext("Sorry, only members who have registered " +
|
|
|
|
|
// "before {0} are allowed to create a new site.",
|
|
|
|
|
// formatDate(root.qualifyingDate));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-06-22 19:31:18 +00:00
|
|
|
}
|
2007-09-14 23:25:23 +00:00
|
|
|
if (user.sites.count() > 0) {
|
|
|
|
|
var days = Math.floor((new Date - user.sites.get(0).created) /
|
|
|
|
|
Date.ONEDAY);
|
|
|
|
|
if (days < root.creationDelay) {
|
|
|
|
|
//throw Error(gettext("Sorry, you still have to wait {0} days " +
|
|
|
|
|
// "before you can create another site.",
|
|
|
|
|
// root.creationDelay - days));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-06-22 19:31:18 +00:00
|
|
|
}
|
2007-09-14 23:25:23 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
2008-04-21 13:57:01 +00:00
|
|
|
}
|