File: ms_custom_info.php

package info (click to toggle)
ocsinventory-server 2.5%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,088 kB
  • sloc: php: 27,462; perl: 8,241; sh: 1,680; sql: 1,355; xml: 1,041; makefile: 34
file content (282 lines) | stat: -rw-r--r-- 12,902 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
/*
 * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
 * See the Contributors file for more details about them.
 *
 * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
 *
 * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of the License,
 * or (at your option) any later version.
 *
 * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */
if (AJAX) {
    parse_str($protectedPost['ocs']['0'], $params);
    $protectedPost += $params;

    ob_start();
}

require_once('require/function_ipdiscover.php');

$form_name = 'info_ipdiscover';
$tab_options = $protectedPost;

//recherche de la personne connectée
if (isset($_SESSION['OCS']['TRUE_USER'])) {
    $user = $_SESSION['OCS']['TRUE_USER'];
} else {
    $user = $_SESSION['OCS']['loggeduser'];
}

//suppression d'une adresse mac
if (isset($protectedPost['SUP_PROF'])) {
    //check if we are deleting an identified peripherials ?
    if ($protectedGet['prov'] == "ident") {
        //dismiss manufacturer name and mac to be able to remove it properly.
        $exploded_data = explode(' ', $protectedPost['SUP_PROF']);
        //var_dump($exploded_data);
        $protectedPost['SUP_PROF'] = $exploded_data[0];
    }

    $sql = "DELETE FROM netmap WHERE mac='%s'";
    mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $protectedPost['SUP_PROF']);
    $sql = "DELETE FROM network_devices WHERE macaddr='%s'";
    mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $protectedPost['SUP_PROF']);
    unset($_SESSION['OCS']['DATA_CACHE']['IPDISCOVER_' . $protectedGet['prov']]);
}
//identification d'une adresse mac
if (isset($protectedPost['Valid_modif'])) {
    if (trim($protectedPost['COMMENT']) == "") {
        $ERROR = $l->g(942);
    }
    if (trim($protectedPost['TYPE']) == "") {
        $ERROR = $l->g(943);
    }
    if (isset($ERROR) && $protectedPost['MODIF_ID'] != '') {
        $protectedPost['USER'] = $protectedPost['USER_ENTER'];
    }

    if (!isset($ERROR)) {
        if ($protectedPost['USER_ENTER'] != '') {
            $sql = "update network_devices
					set DESCRIPTION = '%s',
					TYPE = '%s',
					MACADDR = '%s',
					USER = '%s' where MACADDR='%s'";
            $arg = array($protectedPost['COMMENT'], $protectedPost['TYPE'], $protectedPost['mac'], $user, $protectedPost['MODIF_ID']);
        } else {
            if(!check_if_inv_mac_already_exist($protectedPost['mac'])){
                $sql = "insert into network_devices (DESCRIPTION,TYPE,MACADDR,USER)
                    VALUES('%s','%s','%s','%s')";
                $arg = array($protectedPost['COMMENT'], $protectedPost['TYPE'], $protectedPost['mac'], $user);
            }

        }
        if(isset($sql)){
            mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg);
        }

        //suppression du cache pour prendre en compte la modif
        unset($_SESSION['OCS']['DATA_CACHE']['IPDISCOVER_' . $protectedGet['prov']]);
    } else {
        $protectedPost['MODIF'] = $protectedPost['mac'];
    }
}

//formulaire de saisie de l'identification de l'adresse mac
if (is_defined($protectedPost['MODIF'])) {
    //cas d'une modification de la donnée déjà saisie
    if ($protectedGet['prov'] == "ident" && !isset($protectedPost['COMMENT'])) {
        $sql = "select DESCRIPTION,TYPE,MACADDR,USER from network_devices where id ='%s'";
        $arg = $protectedPost['MODIF'];
        $res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
        $val = mysqli_fetch_array($res);
        $protectedPost['COMMENT'] = $val['DESCRIPTION'];
        $protectedPost['MODIF'] = $val['MACADDR'];
        $protectedPost['TYPE'] = $val['TYPE'];
        $protectedPost['USER'] = $val['USER'];
        $protectedPost['MODIF_ID'] = $protectedPost['MODIF'];
    }
    $tab_hidden['USER_ENTER'] = $protectedPost['USER'];
    $tab_hidden['MODIF_ID'] = $protectedPost['MODIF_ID'];
    //si on est dans le cas d'une modif, on affiche le login qui a saisi la donnée
    if ($protectedPost['MODIF_ID'] != '') {
        $tab_typ_champ[3]['DEFAULT_VALUE'] = $protectedPost['USER'];
        $tab_typ_champ[3]['INPUT_NAME'] = "USER";
        $tab_typ_champ[3]['INPUT_TYPE'] = 3;
        $tab_name[3] = $l->g(944) . ": ";

        $title = $l->g(945);
    } else {
        $title = $l->g(946);
    }

    $tab_typ_champ[0]['DEFAULT_VALUE'] = $protectedPost['MODIF'];
    $tab_typ_champ[0]['INPUT_NAME'] = "MAC";
    $tab_typ_champ[0]['INPUT_TYPE'] = 13;
    $tab_name[0] = $l->g(95) . ": ";

    $tab_typ_champ[1]['DEFAULT_VALUE'] = $protectedPost['COMMENT'];
    $tab_typ_champ[1]['INPUT_NAME'] = "COMMENT";
    $tab_typ_champ[1]['INPUT_TYPE'] = 0;
    $tab_typ_champ[1]['CONFIG']['SIZE'] = 60;
    $tab_typ_champ[1]['CONFIG']['MAXLENGTH'] = 255;
    $tab_name[1] = $l->g(53) . ": ";

    $sql = "select distinct NAME from devicetype ";
    $res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"]);
    while ($row = mysqli_fetch_object($res)) {
        $list_type[$row->NAME] = $row->NAME;
    }
    $tab_typ_champ[2]['DEFAULT_VALUE'] = $list_type;
    $tab_typ_champ[2]['INPUT_NAME'] = "TYPE";
    $tab_typ_champ[2]['INPUT_TYPE'] = 2;
    $tab_name[2] = $l->g(66) . ": ";

    $tab_hidden['mac'] = $protectedPost['MODIF'];
    if (isset($ERROR)) {
        msg_error($ERROR);
    }
    modif_values($tab_name, $tab_typ_champ, $tab_hidden, array(
        'title' => $title
    ));
} else { //affichage des périphériques
    if (!(isset($protectedPost["pcparpage"]))) {
        $protectedPost["pcparpage"] = 5;
    }
    if (isset($protectedGet['value'])) {
        $value_preg = preg_replace("/[^A-zA-Z0-9\._]/", "", $protectedGet['value']);
        if ($protectedGet['prov'] == "no_inv") {
            $title = $l->g(947);
            $sql = "SELECT ip, mac, mask, date, name FROM netmap n
                            LEFT JOIN networks ns ON ns.macaddr=n.mac
                            WHERE n.netid='%s'
                            AND (ns.macaddr IS NULL)
                            AND mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)";
            $tab_options['ARG_SQL'] = array($value_preg);
            $list_fields = array($l->g(34) => 'ip', 'MAC' => 'mac',
                $l->g(208) => 'mask',
                $l->g(232) => 'date',
                $l->g(318) => 'name');
            $tab_options['FILTRE'] = array_flip($list_fields);
            $tab_options['ARG_SQL_COUNT'] = array($value_preg);
            $list_fields['SUP'] = 'mac';
            $list_fields['MODIF'] = 'mac';
            $tab_options['MODIF']['IMG'] = "image/prec16.png";
            $tab_options['LBL']['MODIF'] = $l->g(114);
            $default_fields = $list_fields;
        } elseif ($protectedGet['prov'] == "ident") {
            $title = $l->g(948);
            $sql = "select n.ID,n.TYPE,n.DESCRIPTION,a.IP,a.MAC,a.MASK,a.NETID,a.NAME,a.date,n.USER
				 from network_devices n LEFT JOIN netmap a ON a.mac=n.macaddr
				 where netid='%s'";
            $tab_options['ARG_SQL'] = array($value_preg);
            $list_fields = array($l->g(66) => 'TYPE', $l->g(53) => 'DESCRIPTION',
                $l->g(34) => 'IP',
                $l->g(95) => 'MAC',
                $l->g(208) => 'MASK',
                $l->g(316) => 'NETID',
                $l->g(318) => 'NAME',
                $l->g(232) => 'date',
                $l->g(369) => 'USER');
            $tab_options['FILTRE'] = array_flip($list_fields);
            $tab_options['ARG_SQL_COUNT'] = array($value_preg);
            $list_fields['SUP'] = 'MAC';
            $list_fields['MODIF'] = 'ID';
            $default_fields = array($l->g(34) => $l->g(34), $l->g(66) => $l->g(66), $l->g(53) => $l->g(53),
                $l->g(95)  => 'MAC', $l->g(232) => $l->g(232), $l->g(369) => $l->g(369), 'SUP' => 'SUP', 'MODIF' => 'MODIF');
        } elseif ($protectedGet['prov'] == "inv" || $protectedGet['prov'] == "ipdiscover") {
            //BEGIN SHOW ACCOUNTINFO
            require_once('require/function_admininfo.php');
            $accountinfo_value = interprete_accountinfo($list_fields, $tab_options);
            if (array($accountinfo_value['TAB_OPTIONS']))
                $tab_options = $accountinfo_value['TAB_OPTIONS'];
            if (array($accountinfo_value['DEFAULT_VALUE']))
                $default_fields = $accountinfo_value['DEFAULT_VALUE'];
            $list_fields = $accountinfo_value['LIST_FIELDS'];
            $tab_options['FILTRE'] = array_flip($list_fields);
            //END SHOW ACCOUNTINFO
            $list_fields2 = array($l->g(46) => "h.lastdate",
                'NAME' => 'h.name',
                $l->g(24) => "h.userid",
                $l->g(25) => "h.osname",
                $l->g(33) => "h.workgroup",
                $l->g(275) => "h.osversion",
                $l->g(34) => "h.ipaddr",
                $l->g(95) => 'n.macaddr',
                $l->g(557) => "h.userdomain");

            $tab_options["replace_query_arg"]['MD5_DEVICEID'] = " md5(deviceid) ";
            $list_fields = array_merge($list_fields, $list_fields2);
            $sql = prepare_sql_tab($list_fields);
            $list_fields = array_merge($list_fields, array('MD5_DEVICEID' => "MD5_DEVICEID"));
            $tab_options['ARG_SQL'] = $sql['ARG'];
            if ($protectedGet['prov'] == "inv") {
                $title = $l->g(1271);
                $sql = $sql['SQL'] . ",md5(deviceid) as MD5_DEVICEID from accountinfo a,hardware h LEFT JOIN networks n ON n.hardware_id=h.id";
                $sql .= " where ipsubnet='%s' and status='Up' and a.hardware_id=h.id ";
            } else {
                $title = $l->g(492);
                $sql = $sql['SQL'] . " from accountinfo a,hardware h left join devices d on d.hardware_id=h.id";
                $sql .= " where a.hardware_id=h.id and (d.ivalue=1 or d.ivalue=2) and d.name='IPDISCOVER' and d.tvalue='%s'";
            }

            array_push($tab_options['ARG_SQL'], $value_preg);
            $default_fields['NAME'] = 'NAME';
            $default_fields[$l->g(34)] = $l->g(34);
            $default_fields[$l->g(24)] = $l->g(24);
            $default_fields[$l->g(25)] = $l->g(25);
            $default_fields[$l->g(275)] = $l->g(275);
            $tab_options['ARG_SQL_COUNT'] = array($value_preg);
            $tab_options['FILTRE']['h.name'] = $l->g(49);
            $tab_options['FILTRE']['h.userid'] = $l->g(24);
            $tab_options['FILTRE']['h.osname'] = $l->g(25);
            $tab_options['FILTRE']['h.ipaddr'] = $l->g(34);
        }
        printEnTete($title);
        echo "<br><br>";

        $tab_options['LBL']['MAC'] = $l->g(95);

        $list_col_cant_del = array($l->g(66) => $l->g(66), 'SUP' => 'SUP', 'MODIF' => 'MODIF');
        $table_name = "IPDISCOVER_" . $protectedGet['prov'];
        $tab_options['table_name'] = $table_name;
        $form_name = $table_name;
        $tab_options['form_name'] = $form_name;
        echo open_form($form_name, '', '', 'form-horizontal');
        $result_exist = ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
        $fipdisc = "ipdiscover-util.pl";
        $values = look_config_default_values(array('IPDISCOVER_IPD_DIR'), '', array('IPDISCOVER_IPD_DIR' => array('TVALUE' => VARLIB_DIR)));
        $IPD_DIR = $values['tvalue']['IPDISCOVER_IPD_DIR'] . "/ipd";
        if ($scriptPresent = @stat($fipdisc)) {
            $filePresent = true;
            if (!is_executable($fipdisc)) {
                $msg_info = $fipdisc . " " . $l->g(341);
            } else if (!is_writable($IPD_DIR)) {
                $msg_info = $l->g(342) . " " . $fipdisc . " (" . $IPD_DIR . ")";
            }
            if (!isset($msg_info)) {
                echo "<p><input type='button' onclick=window.open(\"index.php?" . PAG_INDEX . "=" . $pages_refs['ms_ipdiscover_analyse'] . "&head=1&rzo=" . $value_preg . "\",\"analyse\",\"location=0,status=0,scrollbars=1,menubar=0,resizable=0,width=800,height=650\") name='analyse' value='" . $l->g(317) . "' class='btn'></p>";
            } else {
                msg_info($msg_info);
            }
        }
        echo close_form();
    }
}
if (AJAX) {
    ob_end_clean();
    tab_req($list_fields, $default_fields, $list_col_cant_del, $sql, $tab_options);
}
?>