File: function_machine.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 (328 lines) | stat: -rw-r--r-- 14,520 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?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.
 */

/*
 * Page de fonction communes aux détails d'une machine
 *
 */

//fonction de traitement de l'ID envoyé
function info($GET, $post_systemid) {
    global $l, $protectedPost;
    //send post
    if ($post_systemid != '') {
        $systemid = $protectedPost['systemid'];
    }
    //you can see computer's detail by deviceid
    if (isset($GET['deviceid']) && !isset($systemid)) {
        $querydeviceid = "SELECT ID FROM hardware WHERE deviceid='%s'";
        $argdevicedid = mb_strtoupper($GET['deviceid']);
        $resultdeviceid = mysql2_query_secure($querydeviceid, $_SESSION['OCS']["readServer"], $argdevicedid);
        $item = mysqli_fetch_object($resultdeviceid);
        $GET['systemid'] = $item->ID;
        //echo $GET['systemid'];
        if ($GET['systemid'] == "") {
            return $l->g(837);
        }
    }

    //you can see computer's detail by md5(deviceid)
    if (isset($GET['crypt'])) {
        $querydeviceid = "SELECT ID FROM hardware WHERE md5(deviceid)='%s'";
        $argdevicedid = ($GET['crypt']);
        $resultdeviceid = mysql2_query_secure($querydeviceid, $_SESSION['OCS']["readServer"], $argdevicedid);
        $item = mysqli_fetch_object($resultdeviceid);
        $GET['systemid'] = $item->ID;
        //echo $GET['systemid'];
        if ($GET['systemid'] == "") {
            return $l->g(837);
        }
    }

    //si le systemid de la machine existe
    if (isset($GET['systemid']) && !isset($systemid)) {
        $systemid = $GET['systemid'];
    }
    //problème sur l'id
    if ($systemid == "" || !is_numeric($systemid)) {
        return $l->g(837);
    }
    //recherche des infos de la machine
    $querydeviceid = "SELECT * FROM hardware h left join accountinfo a on a.hardware_id=h.id
						 WHERE h.id=" . $systemid . " ";
    if ($_SESSION['OCS']['profile']->getRestriction('GUI') == "YES"
            and isset($_SESSION['OCS']['mesmachines'])
            and $_SESSION['OCS']['mesmachines'] != ''
            and ! isset($GET['crypt'])) {
        $querydeviceid .= " and (" . $_SESSION['OCS']['mesmachines'] . " or a.tag is null or a.tag='')";
    }
    $resultdeviceid = mysqli_query($_SESSION['OCS']["readServer"], $querydeviceid) or mysqli_error($_SESSION['OCS']["readServer"]);
    $item = mysqli_fetch_object($resultdeviceid);
    if ($item->ID == "") {
        return $l->g(837);
    }
    return $item;
}

function subnet_name($systemid) {
    if (!is_numeric($systemid)) {
        return false;
    }
    $reqSub = "select NAME,NETID from subnet left join networks on networks.ipsubnet = subnet.netid
				where  networks.status='Up' and hardware_id=" . $systemid;
    $resSub = mysqli_query($_SESSION['OCS']["readServer"], $reqSub) or die(mysqli_error($_SESSION['OCS']["readServer"]));
    while ($valSub = mysqli_fetch_object($resSub)) {

        $returnVal[] = $valSub->NAME . "  (" . $valSub->NETID . ")";
    }
    return $returnVal;
}

function print_item_header($text) {
    echo '<h4 class="item-header">' . mb_strtoupper($text, "UTF-8") . '</h4>';
}

function bandeau($data, $lbl, $link = array()) {
    if (!is_array($link)) {
        $link = array();
    }

    $nb_col = 2;
    echo "<table ALIGN = 'Center' class='mlt_bordure' border=0 width:100%><tr><td align =center>";
    echo "		<table align=center border='0' width='100%'  ><tr>";
    $i = 0;
    foreach ($data as $name => $value) {
        if (trim($value) == '') {
            // Only if we have datas...
            continue;
        }

        if ($i == $nb_col) {
            echo "</tr><tr>";
            $i = 0;
        }
        if (!array_key_exists($name, $link)) {
            //$value=htmlentities($value,ENT_COMPAT,'UTF-8');
            $value = strip_tags_array($value);
        }

        if ($name == "IPADDR") {
            $value = preg_replace('/([x0-9])\//', '$1 / ', $value);
        }

        echo "<td>&nbsp;<b>" . $lbl[$name] . ": </b></td><td >" . $value . "</td>";
        $i++;
    }

    echo "</tr></table></td>";
    echo "</tr></table>";
}

function show_packages($systemid, $page = "ms_computer") {
    global $l, $pages_refs, $ii, $td3, $td2, $td4;
    $query = "SELECT a.name, d.tvalue,d.ivalue,d.comments,e.fileid, e.pack_loc,h.name as name_server,h.id,a.comment
			FROM devices d left join download_enable e on e.id=d.ivalue
						LEFT JOIN download_available a ON e.fileid=a.fileid
						LEFT JOIN hardware h on h.id=e.server_id
			WHERE d.name='DOWNLOAD' and a.name != '' and pack_loc != ''   AND d.hardware_id=%s
			union
			SELECT '%s', d.tvalue,d.ivalue,d.comments,e.fileid, '%s',h.name,h.id,a.comment
			FROM devices d left join download_enable e on e.id=d.ivalue
						LEFT JOIN download_available a ON e.fileid=a.fileid
						LEFT JOIN hardware h on h.id=e.server_id
			WHERE d.name='DOWNLOAD' and a.name is null and pack_loc is null  AND d.hardware_id=%s";

    $arg_query = array($systemid, $l->g(1129), $l->g(1129), $systemid);
    $resDeploy = mysql2_query_secure($query, $_SESSION['OCS']["readServer"], $arg_query);
    if (mysqli_num_rows($resDeploy) > 0) {
        
    print_item_header($l->g(481));

        ?>
        <div class='row'>
            <div class='col-md-12'>
                <p>
                    <table class='table table-striped'>
                      <thead>
                        <tr>
                          <th><?php echo $l->g(1037) ?></th>
                          <th><?php echo $l->g(475) ?></th>
                          <th><?php echo $l->g(499) ?></th>
                          <th><?php echo $l->g(1102) ?></th>
                        </tr>
                      </thead>
                      <tbody>
        <?php 
        
        while ($valDeploy = mysqli_fetch_array($resDeploy)) {
            $ii++;
            $td3 = $ii % 2 == 0 ? $td2 : $td4;
            if ((strpos($valDeploy["comment"], "[VISIBLE=1]")
                    or strpos($valDeploy["comment"], "[VISIBLE=]")
                    or ( !$_SESSION['OCS']['profile']->getRestriction('TELEDIFF_VISIBLE')
                    and strpos($valDeploy["comment"], "[VISIBLE=0]"))
                    or ! strpos($valDeploy["comment"], "[VISIBLE"))
                    or ( $_SESSION['OCS']['profile']->getRestriction('TELEDIFF_VISIBLE', 'NO') == "NO"
                    and preg_match("[VISIBLE=0]", $valDeploy["comment"]))) {
                
                    ?>
                    <tr>
                        <td><?php echo $valDeploy["name"]  ?></td>
                        <td><?php echo $valDeploy["fileid"] ?></td>
                        <td><?php 
                        if ($valDeploy["name_server"] != "") {
                            echo " redistrib: <a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&head=1&systemid=" . $valDeploy["id"] . "' target='_blank'><b>" . $valDeploy["name_server"] . "</b></a>";
                        } else {
                            echo  $valDeploy["pack_loc"];
                        } 
                        ?>
                        </td>
                        <td><?php  
                        if ($page == "ms_computer") {
                        echo ($valDeploy["tvalue"] != "" ? $valDeploy["tvalue"] : $l->g(482));
                        echo ($valDeploy["comments"] != "" ? " (" . $valDeploy["comments"] . ")" : "");
                        if ($_SESSION['OCS']['profile']->getConfigValue('TELEDIFF') == "YES") {
                            echo "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&head=1&suppack=" . $valDeploy["ivalue"] . "&systemid=" .
                            urlencode($systemid) . "&cat=teledeploy'>" . $l->g(122) . "</a>";
                        } elseif (strstr($valDeploy["tvalue"], 'ERR_') || strstr($valDeploy["tvalue"], 'EXIT_CODE')) {
                            echo "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&head=1&affect_reset=" . $valDeploy["ivalue"] . "&systemid=" .
                            urlencode($systemid) . "&cat=teledeploy'>" . $l->g(113) . "</a>";
                            if ($valDeploy["name"] != $l->g(1129)) {
                                echo "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&head=1&affect_again=" . $valDeploy["ivalue"] . "&systemid=" .
                                urlencode($systemid) . "&cat=teledeploy'>" . $l->g(1246) . "</a>";
                            }
                        } elseif (strstr($valDeploy["tvalue"], 'NOTIFIED')) {
                            if (isset($valDeploy["comments"]) && strtotime($valDeploy["comments"]) < strtotime("-12 week")) {
                                echo "<a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&head=1&reset_notified=" . $valDeploy["ivalue"] . "&systemid=" .
                                urlencode($systemid) . "&cat=teledeploy'><img src=image/delete-small.png></a>";
                            }
                        }
                        } else {
                            if ($_SESSION['OCS']['profile']->getConfigValue('TELEDIFF') == "YES") {
                                echo " <a href='index.php?" . PAG_INDEX . "=" . $pages_refs[$page] . "&popup=1&suppack=" . $valDeploy["ivalue"] . "&systemid=" .
                                urlencode($systemid) . "&option=" . urlencode($l->g(500)) . "'>" . $l->g(122) . "</a>";
                            }
                            show_stat($valDeploy["fileid"]);
                        }
                        ?></td>
                    </tr> 
                    <?php
                    }
                }
                ?>
                    </tbody>
                </table>
            </p>
        </div>
    </div>
    <?php
            
        
    }
}

function checkForComputerPackagesAction(){
    
    global $protectedGet, $l;
    
    //you can delete all packets if status=NOTIFIED and date>3 mounths
    if (isset($protectedGet['reset_notified']) && is_numeric($protectedGet['reset_notified'])) {
        desactive_packet($systemid, $protectedGet['reset_notified']);
    }

    //affect again a packet
    if ($protectedPost['Valid_modif']) {
        if (trim($protectedPost['MOTIF'])) {
            if ($protectedPost["ACTION"] == "again") {
                //delete all info of specific teledeploy
                desactive_download_option($systemid, $protectedGet['affect_again']);
                active_option('DOWNLOAD', $systemid, $protectedGet['affect_again']);
            } elseif ($protectedPost["ACTION"] == "reset") {
                desactive_packet($systemid, $protectedGet['affect_reset']);
            }
            mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg);

            if (mysqli_affected_rows($_SESSION['OCS']["writeServer"]) != 0) {
                $sql = "INSERT INTO itmgmt_comments (hardware_id,comments,user_insert,date_insert,action)
                                            values ('%s','%s','%s',%s,'%s => %s')";
                $arg = array($systemid, $protectedPost['MOTIF'], $_SESSION['OCS']["loggeduser"],
                    "sysdate()", $protectedPost["ACTION"], $protectedPost['NAME_PACK']);
                mysql2_query_secure($sql, $_SESSION['OCS']["writeServer"], $arg);
            }
        } else {
            msg_error($l->g(903));
        }
    }

    if ($protectedPost['Reset_modif']) {
        unset($protectedGet['affect_again'], $protectedGet['affect_reset']);
    }

    if ($protectedGet['affect_again'] || $protectedGet['affect_reset']) {
        if ($protectedGet['affect_again']) {
            $id_pack_affect = $protectedGet['affect_again'];
            $hidden_action = 'again';
            $title_action = $l->g(904);
            $lbl_action = $l->g(905);
        } else {
            $id_pack_affect = $protectedGet['affect_reset'];
            $hidden_action = 'reset';
            $title_action = $l->g(906);
            $lbl_action = $l->g(907);
        }
        $sql = "select da.name from devices d,
                                                      download_enable de,
                                                            download_available da
              where de.id='%s' and de.FILEID=da.FILEID
                            and d.IVALUE=de.ID
                            AND d.hardware_id='%s' AND d.name='%s'
                            and (tvalue like '%s' or tvalue like '%s') ";
        $arg = array($id_pack_affect, $protectedGet['systemid'], "DOWNLOAD", "ERR_%", "EXIT_CODE%");
        $res = mysql2_query_secure($sql, $_SESSION['OCS']["readServer"], $arg);
        $val = mysqli_fetch_array($res);
        if (isset($val['name'])) {
            $tab_typ_champ[0]['INPUT_NAME'] = "MOTIF";
            $tab_typ_champ[0]['INPUT_TYPE'] = 1;
            $data_form[0] = "<center>" . $lbl_action . "</center>";
            modif_values($data_form, $tab_typ_champ, array('NAME_PACK' => $val['name'], 'ACTION' => $hidden_action), array(
                'title' => $title_action . $val['name']
            ));
        }
    }
    if (isset($protectedGet["suppack"]) & $_SESSION['OCS']['profile']->getConfigValue('TELEDIFF') == "YES") {

        if ($_SESSION['OCS']["justAdded"] == false) {
            desactive_packet($systemid, $protectedGet["suppack"]);
        } else {
            $_SESSION['OCS']["justAdded"] = false;
        }
        addLog($l->g(512), $l->g(886) . " " . $protectedGet["suppack"] . " => " . $systemid);
    } else {
        $_SESSION['OCS']["justAdded"] = false;
    }
    
}



?>