summaryrefslogtreecommitdiffstats
path: root/src/modules/rlm_python3/example.py
blob: bb2d99775ade0a78f7390bfb352904568c0139e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/env python3
#
# Python module example file
# Miguel A.L. Paraz <mparaz@mparaz.com>
#
# $Id$

import radiusd

# Check post_auth for the most complete example using different
# input and output formats

def instantiate(p):
  print("*** instantiate ***")
  print(p)
  # return 0 for success or -1 for failure


def authorize(p):
  print("*** authorize ***")
  radiusd.radlog(radiusd.L_INFO, '*** radlog call in authorize ***')
  print()
  print(p)
  print()
  print(radiusd.config)
  return radiusd.RLM_MODULE_OK


def preacct(p):
  print("*** preacct ***")
  print(p)
  return radiusd.RLM_MODULE_OK


def accounting(p):
  print("*** accounting ***")
  radiusd.radlog(radiusd.L_INFO, '*** radlog call in accounting (0) ***')
  print()
  print(p)
  return radiusd.RLM_MODULE_OK


def pre_proxy(p):
  print("*** pre_proxy ***")
  print(p)
  return radiusd.RLM_MODULE_OK


def post_proxy(p):
  print("*** post_proxy ***")
  print(p)
  return radiusd.RLM_MODULE_OK


def post_auth(p):
  print("*** post_auth ***")

  # This is true when using pass_all_vps_dict
  if type(p) is dict:
    print("Request:", p["request"])
    print("Reply:", p["reply"])
    print("Config:", p["config"])
    print("State:", p["session-state"])
    print("Proxy-Request:", p["proxy-request"])
    print("Proxy-Reply:", p["proxy-reply"])

  else:
    print(p)

  # Dictionary representing changes we want to make to the different VPS
  update_dict = {
        "request": (("User-Password", ":=", "A new password"),),
        "reply": (("Reply-Message", "The module is doing its job"),
                  ("User-Name", "NewUserName")),
        "config": (("Cleartext-Password", "A new password"),),
  }

  return radiusd.RLM_MODULE_OK, update_dict
  # Alternatively, you could use the legacy 3-tuple output
  # (only reply and config can be updated)
  # return radiusd.RLM_MODULE_OK, update_dict["reply"], update_dict["config"]


def recv_coa(p):
  print("*** recv_coa ***")
  print(p)
  return radiusd.RLM_MODULE_OK


def send_coa(p):
  print("*** send_coa ***")
  print(p)
  return radiusd.RLM_MODULE_OK


def detach(p):
  print("*** goodbye from example.py ***")
  return radiusd.RLM_MODULE_OK