Skip to content
Browse files

added delete-42-domain

  • Loading branch information...
1 parent 0906335 commit 14c7280386a0f8c9d5de497b2db4d2c00096443d @matthewfl matthewfl committed Dec 18, 2010
Showing with 60 additions and 2 deletions.
  1. +36 −1 Bespin/control.js
  2. +3 −1 config.sample.js
  3. +21 −0 front-end.js
View
37 Bespin/control.js
@@ -194,12 +194,24 @@
"pointer":"#reloadCheck",
"params":[],
"key": "ctrl_r"
+ },
+ {
+ "ep": "command",
+ "name": "delete-42-domain",
+ "pointer": "#deleteDomainCommand",
+ "params": [
+ {
+ "name": "domain",
+ "type": "text",
+ "description": "Domain to delete"
+ }
+ ]
}
]
});
"end";
- var discardChanges = "Are you sure that you want to discard all changes";
+var discardChanges = "Are you sure that you want to discard all changes";
require('facebox'); // just to load it into jquery
@@ -646,6 +658,29 @@ exports.shareCommand = function (args, request) {
Ajax.send();
};
+var deletedDomainAlready=false;
+exports.deleteDomainCommand = function (args, request) {
+ if(!userToken) { alert("you need to login for this command"); return request.done("Not logedin"); }
+ if(!('domain' in args) || args['domain'] == "" || hostList.indexOf(args['domain']) == -1) {
+ return request.done("domain name not found, your domains:<br>"+hostList.join("<br>"));
+ }
+ if(deletedDomainAlready) {
+ return request.done("To delete another domain logout and log back in, one domain delete per login");
+ }
+ var domain=args['domain'];
+ if(prompt("To delete "+domain+" enter:\nI "+userName+" want to delete "+domain, "") != "I "+userName+" want to delete "+domain) return request.done("domain was not deleted");
+ Ajax.Call({
+ "action": "delete-sub-domain",
+ "domain": domain
+ }, function (b) {
+ deletedDomainAlready = b;
+ request.done(b ? "Domain was deleted" : "failed to delete domain");
+ if(b) {
+ hostList.splice(hostList.indexOf(domain), 1);
+ }
+ });
+ Ajax.send();
+};
exports.docsCommand = function () {
//window.open("http://wiki.matthewfl.com/jsapp:start");
View
4 config.sample.js
@@ -23,4 +23,6 @@ exports.errorPage="http://jsapp.us/error";
exports.testDbPort=8081;
exports.dbPort='/tmp/tyrant';
exports.dbHost="";
-exports.dbSyncTime=10*1000;
+exports.dbSyncTime=10*1000;
+
+exports.deleteDomainFile="/home/matthew/jsapp_delete_domain"; // change this to some place that you can write to
View
21 front-end.js
@@ -197,6 +197,27 @@ var ajaxActions = {
back(true);
});
});
+ },
+ "delete-sub-domain": function (data, user, back) {
+ if(!user) back(false);
+ if((/[^a-zA-Z0-9\-]/.exec(data.name))) return back(false);
+ db.get("lsOwn_"+user, function (list) {
+ list = list.split("*");
+ if(list.indexOf(data.domain) == -1) return back(false);
+ db.get("owner_"+data.domain, function (ownerC) {
+ if(ownerC != user) back(false);
+ db.remove("app_"+data.domain);
+ fs.open(config.deleteDomainFile, 'a+', function (err, fd) {
+ fs.write(fd, new Buffer(data.domain+'\n', 'ascii'), 0, data.domain.length+1, 0, function (err, written) {
+ fs.close(fd);
+ db.remove("owner_"+data.domain);
+ list.splice(list.indexOf(data.domain), 1);
+ db.set("lsOwn_"+user, list.join("*"));
+ back(true);
+ });
+ });
+ });
+ });
}
};

0 comments on commit 14c7280

Please sign in to comment.
Something went wrong with that request. Please try again.