liquid_feedback_frontend
view bin/liquid-admin.lua @ 754:a4f4e783c67c
Updated german translations
| author | bsw | 
|---|---|
| date | Thu Jun 28 22:44:54 2012 +0200 (2012-06-28) | 
| parents | eeb167cf9dc4 | 
| children | 
 line source
     1 #!/usr/bin/env lua
     3 OptionParser = require("utils.optparse")
     5 COMMANDS = {{"setpwd <username> <password>", "Set a user command"}, 
     6             {"listuser", "List usernames"},
     7            }
     9 t={usage="<some usage message>", version="<version string>", commands=COMMANDS}
    10 op=OptionParser(t)
    11 --op.add_option({"-t", action="safe_true", dest="test", help="<help message for this option>"})
    12 op.add_option({"-c", action="store", dest="config", help="config name to use", default="default"})
    13 op.add_option({"-w", action="store", dest="webmcp", help="path to webmcp", default="../webmcp"})
    15 options,args = op.parse_args()
    17 if #args == 0 then
    18     print("Error: command is required\n")
    19     op.print_help()
    20     return
    21 end
    23 -- dirty dirty dirty, dirty dirty, dirty dirty dow monkey patch env
    24 if not os.setenv then
    26     local env, getenv = { }, os.getenv
    28     function os.setenv(k,v)
    29         env[k] = v
    30     end
    32     function os.getenv(k)
    33         return env[k] or getenv(k)
    34     end
    36 end
    38 -- detect current path FIXME: platform portable
    39 local PWD = io.popen("pwd"):read()
    40 os.setenv("WEBMCP_APP_BASEPATH", PWD)
    41 os.setenv("WEBMCP_CONFIG_NAME", options.config)
    42 os.setenv("WEBMCP_INTERACTIVE", "yes")
    44 -- load webmcp framework
    45 WEBMCP_PATH = options.webmcp .. "/framework/"
    46 dofile(options.webmcp .. "/framework/cgi-bin/webmcp.lua")
    48 function error(why)
    49     print(why)
    50     os.exit(2)
    51 end
    53 if args[1] == "setpwd" then
    54   if #args < 2 then
    55     error("login is required")
    56   end
    57   require("model.member")
    58   user = Member:by_login(args[2])
    59   if not user then
    60     error("User "..args[2].." not found")
    61   end
    62   print("Enter password:")
    63   password = io.read()
    64   if password then
    65     user:set_password(password)
    66     user:save()
    67   end
    68 end
    70 if args[1] == "listusers" then
    71   require("model.member")
    72   sel = Member:new_selector()
    73   users = sel:exec()
    74   --sel:optional_object_mode()
    75   print("Login                           Active")
    76   for i,v in pairs(users) do
    77     if v.login then
    78       print(v.login .. string.rep(" ", 25-#v.login), v.active)
    79     end
    80   end
    81 end
