prosodyctl

changeset 3233
8f78e8164032
parent 2706
c2dde8bda3fe
child 3234
2d61773d7ab4
equal deleted inserted replaced
3225:90dc4afe7352 3233:8f78e8164032
497 497
498 show_message(error_messages[msg]) 498 show_message(error_messages[msg])
499 return 1; 499 return 1;
500 end 500 end
501 501
502 local http_errors = {
503 [404] = "Plugin not found, did you type the address correctly?"
504 };
505
506 function commands.addplugin(arg)
507 if not arg[1] or arg[1] == "--help" then
508 show_usage("addplugin URL", "Download and install a plugin from a URL");
509 return 1;
510 end
511 local url = arg[1];
512 if url:match("^http://") then
513 local http = require "socket.http";
514 show_message("Fetching...");
515 local code, err = http.request(url);
516 if not code or not tostring(err):match("^[23]") then
517 show_message("Failed: "..(http_errors[err] or ("HTTP error "..err)));
518 return 1;
519 end
520 if url:match("%.lua$") then
521 local ok, err = datamanager.store(url:match("/mod_([^/]+)$"), "*", "plugins", {code});
522 if not ok then
523 show_message("Failed to save to data store: "..err);
524 return 1;
525 end
526 end
527 show_message("Saved. Don't forget to load the module using the config file or admin console!");
528 else
529 show_message("Sorry, I don't understand how to fetch plugins from there.");
530 end
531 end
532
533 --------------------- 502 ---------------------
534 503
535 if command and command:match("^mod_") then -- Is a command in a module 504 if command and command:match("^mod_") then -- Is a command in a module
536 local module_name = command:match("^mod_(.+)"); 505 local module_name = command:match("^mod_(.+)");
537 local ret, err = modulemanager.load("*", module_name); 506 local ret, err = modulemanager.load("*", module_name);

mercurial