liquid_feedback_frontend

diff bin/liquid-admin.lua @ 107:eeb167cf9dc4

add comand line admin tool

started a command line admin tool to help development.
currently supports setting login passwords and list users
author Daniel Poelzleithner <poelzi@poelzi.org>
date Sun Sep 19 01:33:23 2010 +0200 (2010-09-19)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bin/liquid-admin.lua	Sun Sep 19 01:33:23 2010 +0200
     1.3 @@ -0,0 +1,86 @@
     1.4 +#!/usr/bin/env lua
     1.5 +
     1.6 +OptionParser = require("utils.optparse")
     1.7 +
     1.8 +COMMANDS = {{"setpwd <username> <password>", "Set a user command"}, 
     1.9 +            {"listuser", "List usernames"},
    1.10 +           }
    1.11 +
    1.12 +t={usage="<some usage message>", version="<version string>", commands=COMMANDS}
    1.13 +op=OptionParser(t)
    1.14 +--op.add_option({"-t", action="safe_true", dest="test", help="<help message for this option>"})
    1.15 +op.add_option({"-c", action="store", dest="config", help="config name to use", default="default"})
    1.16 +op.add_option({"-w", action="store", dest="webmcp", help="path to webmcp", default="../webmcp"})
    1.17 +
    1.18 +options,args = op.parse_args()
    1.19 +
    1.20 +if #args == 0 then
    1.21 +    print("Error: command is required\n")
    1.22 +    op.print_help()
    1.23 +    return
    1.24 +end
    1.25 +
    1.26 +-- dirty dirty dirty, dirty dirty, dirty dirty dow monkey patch env
    1.27 +if not os.setenv then
    1.28 +
    1.29 +    local env, getenv = { }, os.getenv
    1.30 +
    1.31 +    function os.setenv(k,v)
    1.32 +        env[k] = v
    1.33 +    end
    1.34 +
    1.35 +    function os.getenv(k)
    1.36 +        return env[k] or getenv(k)
    1.37 +    end
    1.38 +
    1.39 +end
    1.40 +
    1.41 +-- detect current path FIXME: platform portable
    1.42 +local PWD = io.popen("pwd"):read()
    1.43 +os.setenv("WEBMCP_APP_BASEPATH", PWD)
    1.44 +os.setenv("WEBMCP_CONFIG_NAME", options.config)
    1.45 +os.setenv("WEBMCP_INTERACTIVE", "yes")
    1.46 +
    1.47 +-- load webmcp framework
    1.48 +WEBMCP_PATH = options.webmcp .. "/framework/"
    1.49 +dofile(options.webmcp .. "/framework/cgi-bin/webmcp.lua")
    1.50 +
    1.51 +function error(why)
    1.52 +    print(why)
    1.53 +    os.exit(2)
    1.54 +end
    1.55 +
    1.56 +if args[1] == "setpwd" then
    1.57 +  if #args < 2 then
    1.58 +    error("login is required")
    1.59 +  end
    1.60 +  require("model.member")
    1.61 +  user = Member:by_login(args[2])
    1.62 +  if not user then
    1.63 +    error("User "..args[2].." not found")
    1.64 +  end
    1.65 +  print("Enter password:")
    1.66 +  password = io.read()
    1.67 +  if password then
    1.68 +    user:set_password(password)
    1.69 +    user:save()
    1.70 +  end
    1.71 +end
    1.72 +
    1.73 +if args[1] == "listusers" then
    1.74 +  require("model.member")
    1.75 +  sel = Member:new_selector()
    1.76 +  users = sel:exec()
    1.77 +  --sel:optional_object_mode()
    1.78 +  print("Login                           Active")
    1.79 +  for i,v in pairs(users) do
    1.80 +    if v.login then
    1.81 +      print(v.login .. string.rep(" ", 25-#v.login), v.active)
    1.82 +    end
    1.83 +  end
    1.84 +end
    1.85 +
    1.86 +
    1.87 +
    1.88 +
    1.89 +

Impressum / About Us