#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <radiusclient-ng.h>
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
Go to the source code of this file.
Defines | |
#define | DATE_FORMAT "%Y-%m-%d %T %z" |
#define | VENDOR_CODE 22736 |
Enumerations | |
enum | { PW_AST_ACCT_CODE = 101, PW_AST_SRC = 102, PW_AST_DST = 103, PW_AST_DST_CTX = 104, PW_AST_CLID = 105, PW_AST_CHAN = 106, PW_AST_DST_CHAN = 107, PW_AST_LAST_APP = 108, PW_AST_LAST_DATA = 109, PW_AST_START_TIME = 110, PW_AST_ANSWER_TIME = 111, PW_AST_END_TIME = 112, PW_AST_DURATION = 113, PW_AST_BILL_SEC = 114, PW_AST_DISPOSITION = 115, PW_AST_AMA_FLAGS = 116, PW_AST_UNIQUE_ID = 117, PW_AST_USER_FIELD = 118 } |
enum | { RADIUS_FLAG_USEGMTIME = (1 << 0), RADIUS_FLAG_LOGUNIQUEID = (1 << 1), RADIUS_FLAG_LOGUSERFIELD = (1 << 2) } |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | build_radius_record (VALUE_PAIR **send, struct ast_cdr *cdr) |
static int | load_module (void) |
static int | radius_log (struct ast_cdr *cdr) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "RADIUS CDR Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | cdr_config = "cdr.conf" |
static char * | desc = "RADIUS CDR Backend" |
static struct ast_flags | global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD } |
static char * | name = "radius" |
static char | radiuscfg [PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf" |
static rc_handle * | rh = NULL |
Definition in file cdr_radius.c.
#define DATE_FORMAT "%Y-%m-%d %T %z" |
ISO 8601 standard format
Definition at line 53 of file cdr_radius.c.
#define VENDOR_CODE 22736 |
anonymous enum |
Definition at line 57 of file cdr_radius.c.
00057 { 00058 PW_AST_ACCT_CODE = 101, 00059 PW_AST_SRC = 102, 00060 PW_AST_DST = 103, 00061 PW_AST_DST_CTX = 104, 00062 PW_AST_CLID = 105, 00063 PW_AST_CHAN = 106, 00064 PW_AST_DST_CHAN = 107, 00065 PW_AST_LAST_APP = 108, 00066 PW_AST_LAST_DATA = 109, 00067 PW_AST_START_TIME = 110, 00068 PW_AST_ANSWER_TIME = 111, 00069 PW_AST_END_TIME = 112, 00070 PW_AST_DURATION = 113, 00071 PW_AST_BILL_SEC = 114, 00072 PW_AST_DISPOSITION = 115, 00073 PW_AST_AMA_FLAGS = 116, 00074 PW_AST_UNIQUE_ID = 117, 00075 PW_AST_USER_FIELD = 118 00076 };
anonymous enum |
RADIUS_FLAG_USEGMTIME | Log dates and times in UTC |
RADIUS_FLAG_LOGUNIQUEID | Log Unique ID |
RADIUS_FLAG_LOGUSERFIELD | Log User Field |
Definition at line 78 of file cdr_radius.c.
00078 { 00079 /*! Log dates and times in UTC */ 00080 RADIUS_FLAG_USEGMTIME = (1 << 0), 00081 /*! Log Unique ID */ 00082 RADIUS_FLAG_LOGUNIQUEID = (1 << 1), 00083 /*! Log User Field */ 00084 RADIUS_FLAG_LOGUSERFIELD = (1 << 2) 00085 };
static void __reg_module | ( | void | ) | [static] |
Definition at line 279 of file cdr_radius.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 279 of file cdr_radius.c.
static int build_radius_record | ( | VALUE_PAIR ** | send, | |
struct ast_cdr * | cdr | |||
) | [static] |
Definition at line 97 of file cdr_radius.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_localtime(), ast_test_flag, ast_cdr::billsec, ast_cdr::channel, ast_cdr::clid, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, global_flags, ast_cdr::lastapp, ast_cdr::lastdata, PW_AST_ACCT_CODE, PW_AST_AMA_FLAGS, PW_AST_ANSWER_TIME, PW_AST_BILL_SEC, PW_AST_CHAN, PW_AST_CLID, PW_AST_DISPOSITION, PW_AST_DST, PW_AST_DST_CHAN, PW_AST_DST_CTX, PW_AST_DURATION, PW_AST_END_TIME, PW_AST_LAST_APP, PW_AST_LAST_DATA, PW_AST_SRC, PW_AST_START_TIME, PW_AST_UNIQUE_ID, PW_AST_USER_FIELD, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_LOGUSERFIELD, RADIUS_FLAG_USEGMTIME, ast_cdr::src, ast_cdr::start, ast_cdr::uniqueid, ast_cdr::userfield, and VENDOR_CODE.
Referenced by radius_log().
00098 { 00099 int recordtype = PW_STATUS_STOP; 00100 struct tm tm; 00101 char timestr[128]; 00102 char *tmp; 00103 00104 if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) 00105 return -1; 00106 00107 /* Account code */ 00108 if (!rc_avpair_add(rh, send, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE)) 00109 return -1; 00110 00111 /* Source */ 00112 if (!rc_avpair_add(rh, send, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE)) 00113 return -1; 00114 00115 /* Destination */ 00116 if (!rc_avpair_add(rh, send, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE)) 00117 return -1; 00118 00119 /* Destination context */ 00120 if (!rc_avpair_add(rh, send, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE)) 00121 return -1; 00122 00123 /* Caller ID */ 00124 if (!rc_avpair_add(rh, send, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE)) 00125 return -1; 00126 00127 /* Channel */ 00128 if (!rc_avpair_add(rh, send, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE)) 00129 return -1; 00130 00131 /* Destination Channel */ 00132 if (!rc_avpair_add(rh, send, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE)) 00133 return -1; 00134 00135 /* Last Application */ 00136 if (!rc_avpair_add(rh, send, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE)) 00137 return -1; 00138 00139 /* Last Data */ 00140 if (!rc_avpair_add(rh, send, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE)) 00141 return -1; 00142 00143 00144 /* Start Time */ 00145 if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME)) 00146 gmtime_r(&(cdr->start.tv_sec), &tm); 00147 else 00148 ast_localtime(&(cdr->start.tv_sec), &tm, NULL); 00149 strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); 00150 if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00151 return -1; 00152 00153 /* Answer Time */ 00154 if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME)) 00155 gmtime_r(&(cdr->answer.tv_sec), &tm); 00156 else 00157 ast_localtime(&(cdr->answer.tv_sec), &tm, NULL); 00158 strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); 00159 if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00160 return -1; 00161 00162 /* End Time */ 00163 if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME)) 00164 gmtime_r(&(cdr->end.tv_sec), &tm); 00165 else 00166 ast_localtime(&(cdr->end.tv_sec), &tm, NULL); 00167 strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm); 00168 if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00169 return -1; 00170 00171 /* Duration */ 00172 if (!rc_avpair_add(rh, send, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE)) 00173 return -1; 00174 00175 /* Billable seconds */ 00176 if (!rc_avpair_add(rh, send, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE)) 00177 return -1; 00178 00179 /* Disposition */ 00180 tmp = ast_cdr_disp2str(cdr->disposition); 00181 if (!rc_avpair_add(rh, send, PW_AST_DISPOSITION, tmp, strlen(tmp), VENDOR_CODE)) 00182 return -1; 00183 00184 /* AMA Flags */ 00185 tmp = ast_cdr_flags2str(cdr->amaflags); 00186 if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, tmp, strlen(tmp), VENDOR_CODE)) 00187 return -1; 00188 00189 if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUNIQUEID)) { 00190 /* Unique ID */ 00191 if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE)) 00192 return -1; 00193 } 00194 00195 if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUSERFIELD)) { 00196 /* append the user field */ 00197 if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE)) 00198 return -1; 00199 } 00200 00201 /* Setting Acct-Session-Id & User-Name attributes for proper generation 00202 of Acct-Unique-Session-Id on server side */ 00203 /* Channel */ 00204 if (!rc_avpair_add(rh, send, PW_USER_NAME, &cdr->channel, strlen(cdr->channel), 0)) 00205 return -1; 00206 00207 /* Unique ID */ 00208 if (!rc_avpair_add(rh, send, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0)) 00209 return -1; 00210 00211 return 0; 00212 }
static int load_module | ( | void | ) | [static] |
Definition at line 244 of file cdr_radius.c.
References ast_cdr_register(), ast_config_destroy(), ast_config_load(), ast_copy_string(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_set2_flag, ast_true(), ast_variable_retrieve(), global_flags, LOG_NOTICE, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_LOGUSERFIELD, RADIUS_FLAG_USEGMTIME, and radius_log().
00245 { 00246 struct ast_config *cfg; 00247 int res; 00248 const char *tmp; 00249 00250 if ((cfg = ast_config_load(cdr_config))) { 00251 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); 00252 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); 00253 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); 00254 if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) 00255 ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); 00256 ast_config_destroy(cfg); 00257 } else 00258 return AST_MODULE_LOAD_DECLINE; 00259 00260 /* start logging */ 00261 rc_openlog("asterisk"); 00262 00263 /* read radiusclient-ng config file */ 00264 if (!(rh = rc_read_config(radiuscfg))) { 00265 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); 00266 return AST_MODULE_LOAD_DECLINE; 00267 } 00268 00269 /* read radiusclient-ng dictionaries */ 00270 if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { 00271 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); 00272 return AST_MODULE_LOAD_DECLINE; 00273 } 00274 00275 res = ast_cdr_register(name, desc, radius_log); 00276 return AST_MODULE_LOAD_SUCCESS; 00277 }
static int radius_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 214 of file cdr_radius.c.
References ast_log(), build_radius_record(), LOG_DEBUG, LOG_ERROR, and option_debug.
Referenced by load_module().
00215 { 00216 int result = ERROR_RC; 00217 VALUE_PAIR *send = NULL; 00218 00219 if (build_radius_record(&send, cdr)) { 00220 if (option_debug) 00221 ast_log(LOG_DEBUG, "Unable to create RADIUS record. CDR not recorded!\n"); 00222 goto return_cleanup; 00223 } 00224 00225 result = rc_acct(rh, 0, send); 00226 if (result != OK_RC) { 00227 ast_log(LOG_ERROR, "Failed to record Radius CDR record!\n"); 00228 } 00229 00230 return_cleanup: 00231 if (send) { 00232 rc_avpair_free(send); 00233 } 00234 00235 return result; 00236 }
static int unload_module | ( | void | ) | [static] |
Definition at line 238 of file cdr_radius.c.
References ast_cdr_unregister().
00239 { 00240 ast_cdr_unregister(name); 00241 return 0; 00242 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "RADIUS CDR Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 279 of file cdr_radius.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 279 of file cdr_radius.c.
char* cdr_config = "cdr.conf" [static] |
Definition at line 89 of file cdr_radius.c.
char* desc = "RADIUS CDR Backend" [static] |
Definition at line 87 of file cdr_radius.c.
struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD } [static] |
Definition at line 93 of file cdr_radius.c.
char* name = "radius" [static] |
Definition at line 88 of file cdr_radius.c.
char radiuscfg[PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf" [static] |
Definition at line 91 of file cdr_radius.c.
rc_handle* rh = NULL [static] |
Definition at line 95 of file cdr_radius.c.