ona
18.1.1
About:
OpenNetAdmin
provides a database managed inventory of your IP network (with Web and CLI interface).
Fossies
Dox
:
ona-18.1.1.tar.gz
("inofficial" and yet experimental doxygen-generated source code documentation)
dcm.php
Go to the documentation of this file.
1
<?php
2
/* -------------------- COMMON HEADER ---------------------- */
3
$base
= dirname(__FILE__);
4
while
(
$base
and (!is_dir(
$base
.
'/include'
)))
$base
= preg_replace(
'+/[^/]*$+'
,
''
,
$base
);
5
$include
=
$base
.
'/include'
;
6
if
(!is_dir(
$include
)) { print
"ERROR => Couldn't find include folder!\n"
;
exit
; }
7
require_once(
$base
.
'/config/config.inc.php'
);
8
/* --------------------------------------------------------- */
9
10
// MP: Since we know ONA will generate a ton of notice level errors, lets turn them off here
11
// I dont believe this will be impactful to anyone. keep an eye out for it however.
12
error_reporting (E_ALL ^ E_NOTICE);
13
14
// These store the output to be displayed
15
$status
= 1;
16
$output
=
"ERROR => No module specified!\n"
;
17
$type
=
'DCM'
;
18
19
20
// FIXME: Add IP Auth in Later --- or just use htaccess method
21
// Disconnect the user if their IP address isn't in our allowed list
22
// $remote_ip = ip_mangle($_SERVER['REMOTE_ADDR'], 'numeric');
23
// if (!in_array($remote_ip, $ips)) { print "1\r\nPermission denied!\n"; exit; }
24
25
printmsg
(
"DEBUG => DCM_USER: {$_SERVER['PHP_AUTH_USER']}"
, 4);
26
27
// If no user name is passed in then use dcm.pl as the login name
28
// be careful as this currently does not require a password.
29
// FIXME: this needs to go away as it is a backdoor. allow it to be configurable at least?
30
// Start out the session as a guest with level 0 access. This is for view only mode.
31
// You can enable or disable this by setting the "disable_guest" sysconfig option
32
if
($_SERVER[
'PHP_AUTH_USER'
] ==
''
and !
$conf
[
'disable_guest'
]) {
33
$_SESSION
[
'ona'
][
'auth'
][
'user'
][
'username'
]=
'dcm.pl'
;
34
// create new local authentication class directly
35
$auth
=
load_auth_class
(
'local'
);
36
get_perms
(
'dcm.pl'
);
37
printmsg
(
"INFO => [{$type}] {$_SESSION['ona']['auth']['user']['username']} has logged in"
,3);
38
}
39
else
{
40
// Set the cli user as the login user
41
$DCMUSER=
$_SESSION
[
'ona'
][
'auth'
][
'user'
][
'username'
]=$_SERVER[
'PHP_AUTH_USER'
];
42
43
printmsg
(
"INFO => [{$type}] Attempting login as "
. $DCMUSER, 4);
44
45
list(
$status
, $js) =
get_authentication
($DCMUSER,$_SERVER[
'PHP_AUTH_PW'
]);
46
47
$errmsg
= substr($js,27);
48
49
if
(
$status
==0) {
50
$PERMSTAT =
get_perms
($DCMUSER);
51
printmsg
(
"INFO => [{$type}] {$_SESSION['ona']['auth']['user']['username']} has logged in"
,3);
52
}
else
{
53
printmsg
(
"ERROR => DCM: Unknown user {$DCMUSER}"
, 4);
54
print
"ERROR => [{$DCMUSER}]: {$errmsg}\nSee -l and -p options within dcm.pl.\n"
;
55
// clear the session
56
// FIXME: should I do a sess_destroy or sess_close instead? to clear crap from the DB
57
unset(
$_SESSION
[
'ona'
][
'auth'
]);
58
exit
;
59
}
60
61
}
62
63
64
// Display the current debug level if it's above 1
65
printmsg
(
"DEBUG => debug level: {$conf['debug']}"
, 1);
66
67
68
/* ----------- RUN A MODULE IF NEEDED ------------ */
69
if
(isset($_REQUEST[
'module'
])) {
70
// Run the module
71
list(
$status
,
$output
) =
run_module
($_REQUEST[
'module'
], $_REQUEST[
'options'
]);
72
}
73
74
// process various types of output formats
75
if
(strstr($_REQUEST[
'options'
],
"format=json"
)) {
76
output_formatter(
'json'
,
'json_encode'
);
77
} elseif (strstr($_REQUEST[
'options'
],
"format=yaml"
)) {
78
output_formatter(
'yaml'
,
'yaml_emit'
);
79
}
else
{
80
// Assume default text format
81
// Send the module status code and output to dcm.pl
82
print
$status
.
"\r\n"
;
83
print
$output
;
84
}
85
86
87
88
// clear the session
89
// FIXME: should I do a sess_destroy or sess_close instead? to clear crap from the DB
90
unset(
$_SESSION
[
'ona'
][
'auth'
]);
91
92
93
// Given a format and format function, execute that output conversion on the $output array
94
function
output_formatter($format=
''
,$function=
''
) {
95
global
$status
,
$output
;
96
// Check that the function exists
97
if
(!function_exists($function)) {
98
print
"998\r\n"
;
99
print
"ERROR => Format output type missing required php function: ${function}"
;
100
}
else
{
101
// Output needs to be an array
102
if
(is_array(
$output
)) {
103
$output
[
'module_exit_status'
] =
$status
;
104
eval(
'print '
.$function.
'($output);'
);
105
}
else
{
106
$out[
'module_exit_status'
] =
$status
;
107
$out[
'module_exit_message'
] =
$output
;
108
eval(
'print '
.$function.
'($out);'
);
109
}
110
}
111
}
112
113
114
?>
$status
$status
Definition:
dcm.php:15
$errmsg
$errmsg
Definition:
dcm.php:47
$include
$include
Definition:
dcm.php:5
exit
exit
Definition:
config.inc.php:186
get_perms
get_perms($login_name='')
Definition:
functions_auth.inc.php:132
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition:
functions_general.inc.php:48
$type
$type
Definition:
dcm.php:17
load_auth_class
load_auth_class($authtype='')
Definition:
functions_auth.inc.php:17
run_module
run_module($module='', $options='', $transaction=1)
Definition:
functions_general.inc.php:1468
$base
$base
Definition:
dcm.php:3
$_SESSION
$_SESSION['ona']['auth']
Definition:
login.php:14
$conf
global $conf
Definition:
2-to-3.php:15
$auth
$auth
Definition:
functions_auth.inc.php:3
$output
$output
Definition:
dcm.php:16
get_authentication
get_authentication($login_name='', $login_password='')
Definition:
functions_auth.inc.php:65
www
dcm.php
Generated by
1.8.16