Exemplo n.º 1
0
def install_agent(request):
    """ Installs an okagent on a remote host """
    c = {}
    c['errors'] = []
    c['messages'] = []
    c['form'] = forms.InstallAgentForm(initial=request.GET)
    c['nsclient_installfiles'] = okconfig.config.nsclient_installfiles
    if request.method == 'POST':
        c['form'] = f = forms.InstallAgentForm(request.POST)
        if f.is_valid():
            f.clean()
            host = f.cleaned_data['remote_host']
            user = f.cleaned_data['username']
            passw = f.cleaned_data['password']
            method = f.cleaned_data['install_method']
            domain = f.cleaned_data['windows_domain']
            try:
                status, out, err = okconfig.install_okagent(
                    remote_host=host,
                    domain=domain,
                    username=user,
                    password=passw,
                    install_method=method)
                c['exit_status'] = status
                c['stderr'] = err
                # Do a little cleanup in winexe stdout, it is irrelevant
                out = out.split('\n')
                c['stdout'] = []
                for i in out:
                    if i.startswith('Unknown parameter encountered:'):
                        continue
                    elif i.startswith('Ignoring unknown parameter'):
                        continue
                    elif 'NT_STATUS_LOGON_FAILURE' in i:
                        c['hint'] = "NT_STATUS_LOGON_FAILURE usually means there is a problem with username or password. Are you using correct domain ?"
                    elif 'NT_STATUS_DUPLICATE_NAME' in i:
                        c['hint'] = "The security settings on the remote windows host might forbid logins if the host name specified does not match the computername on the server. Try again with either correct hostname or the ip address of the server."
                    elif 'NT_STATUS_ACCESS_DENIED' in i:
                        c['hint'] = "Please make sure that %s is a local administrator on host %s" % (
                            user, host)
                    elif i.startswith('Error: Directory') and i.endswith(
                            'not found'):
                        c['hint'] = "No nsclient copy found "
                    c['stdout'].append(i)
                c['stdout'] = '\n'.join(c['stdout'])
            except Exception, e:
                c['errors'].append(e)
        else:
            c['errors'].append('invalid input')
Exemplo n.º 2
0
def install_agent(request):
    """ Installs an okagent on a remote host """
    c = {}
    c["errors"] = []
    c["messages"] = []
    c["form"] = forms.InstallAgentForm(initial=request.GET)
    c["nsclient_installfiles"] = okconfig.config.nsclient_installfiles
    if request.method == "POST":
        c["form"] = f = forms.InstallAgentForm(request.POST)
        if f.is_valid():
            f.clean()
            host = f.cleaned_data["remote_host"]
            user = f.cleaned_data["username"]
            passw = f.cleaned_data["password"]
            method = f.cleaned_data["install_method"]
            domain = f.cleaned_data["windows_domain"]
            try:
                status, out, err = okconfig.install_okagent(
                    remote_host=host, domain=domain, username=user, password=passw, install_method=method
                )
                c["exit_status"] = status
                c["stderr"] = err
                # Do a little cleanup in winexe stdout, it is irrelevant
                out = out.split("\n")
                c["stdout"] = []
                for i in out:
                    if i.startswith("Unknown parameter encountered:"):
                        continue
                    elif i.startswith("Ignoring unknown parameter"):
                        continue
                    elif "NT_STATUS_LOGON_FAILURE" in i:
                        c[
                            "hint"
                        ] = "NT_STATUS_LOGON_FAILURE usually means there is a problem with username or password. Are you using correct domain ?"
                    elif "NT_STATUS_DUPLICATE_NAME" in i:
                        c[
                            "hint"
                        ] = "The security settings on the remote windows host might forbid logins if the host name specified does not match the computername on the server. Try again with either correct hostname or the ip address of the server."
                    elif "NT_STATUS_ACCESS_DENIED" in i:
                        c["hint"] = "Please make sure that %s is a local administrator on host %s" % (user, host)
                    elif i.startswith("Error: Directory") and i.endswith("not found"):
                        c["hint"] = "No nsclient copy found "
                    c["stdout"].append(i)
                c["stdout"] = "\n".join(c["stdout"])
            except Exception, e:
                c["errors"].append(e)
        else:
            c["errors"].append("invalid input")
Exemplo n.º 3
0
def install_agent(request):
    """ Installs an okagent on a remote host """
    c = {}
    c['errors'] = []
    c['messages'] = []
    c['form'] = forms.InstallAgentForm(initial=request.GET)
    c['nsclient_installfiles'] = okconfig.config.nsclient_installfiles
    if request.method == 'POST':
        c['form'] = f = forms.InstallAgentForm(request.POST)
        if f.is_valid():
            f.clean()
            host = f.cleaned_data['remote_host']
            user = f.cleaned_data['username']
            passw = f.cleaned_data['password']
            method = f.cleaned_data['install_method']
            domain = f.cleaned_data['windows_domain']
            try:
                status, out, err = okconfig.install_okagent(
                    remote_host=host, domain=domain, username=user, password=passw, install_method=method)
                c['exit_status'] = status
                c['stderr'] = err
                # Do a little cleanup in winexe stdout, it is irrelevant
                out = out.split('\n')
                c['stdout'] = []
                for i in out:
                    if i.startswith(_('Unknown parameter encountered:')):
                        continue
                    elif i.startswith(_('Ignoring unknown parameter')):
                        continue
                    elif 'NT_STATUS_LOGON_FAILURE' in i:
                        c['hint'] = _("NT_STATUS_LOGON_FAILURE usually means there is a problem with username or password. Are you using correct domain ?")
                    elif 'NT_STATUS_DUPLICATE_NAME' in i:
                        c['hint'] = _("The security settings on the remote windows host might forbid logins if the host name specified does not match the computername on the server. Try again with either correct hostname or the ip address of the server.")
                    elif 'NT_STATUS_ACCESS_DENIED' in i:
                        c['hint'] = _("Please make sure that %s is a local administrator on host %s") % (
                            user, host)
                    elif i.startswith('Error: Directory') and i.endswith('not found'):
                        c['hint'] = _("No nsclient copy found ")
                    c['stdout'].append(i)
                c['stdout'] = '\n'.join(c['stdout'])
            except Exception, e:
                c['errors'].append(e)
        else:
            c['errors'].append(_('invalid input'))
def main():
    """ Main function of the program """
    arguments = parse_arguments()
    remote_host = arguments.get('host') or usage('remote host was not provided')
    username = arguments.get('username') or usage('username was not provided')
    password = arguments.get('password') or usage('password was not provided')
    domain = arguments.get('domain', None)
    platform = arguments.get('platform', None)
    install_method = None
    if 'linux' in platform:
        install_method = 'ssh'
    elif 'windows' in platform:
        install_method = 'winexe'
    status, stdout, stderr = okconfig.install_okagent(
        remote_host=remote_host,
        username=username,
        password=password,
        domain=domain,
        install_method=install_method,
    )
    if status == 0:
        success(stdout)
    else:
        error(stdout)