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.
*/
//fonction pour avoir tous les groupes
//$group_type = STATIC,DYNAMIC,SERVER
//return tableau [id]=group_name
function all_groups($group_type) {
//récupération des groupes demandés
if ($group_type == "SERVER") {
$reqGetId = "SELECT id,name FROM hardware
WHERE deviceid = '_DOWNLOADGROUP_'";
} else {
if ($group_type == "STATIC") {
$reqGetId = "SELECT id,name FROM hardware,groups
WHERE groups.hardware_id=hardware.id
and deviceid = '_SYSTEMGROUP_'
and (request is null or trim(request) = '')
and (xmldef is null or trim(xmldef) = '')";
if (!($_SESSION['OCS']['profile']->getConfigValue('GROUPS') == "YES")) {
$reqGetId .= " and workgroup = 'GROUP_4_ALL'";
}
} else {
$reqGetId = "SELECT id,name FROM hardware,groups
WHERE groups.hardware_id=hardware.id
and deviceid = '_SYSTEMGROUP_'
and ((request is not null and trim(request) != '')
or (xmldef is not null and trim(xmldef) != ''))";
}
}
$resGetId = mysql2_query_secure($reqGetId, $_SESSION['OCS']["readServer"]);
while ($valGetId = mysqli_fetch_array($resGetId)) {
$list_group[$valGetId['id']] = $valGetId['name'];
}
return $list_group;
}
//fonction pour sortir les machines d'un groupe
function remove_of_group($id_group, $list_id) {
$sql_delcache = "DELETE FROM groups_cache WHERE group_id='%s' and hardware_id in ";
$arg_delcache[] = $id_group;
$delcache = mysql2_prepare($sql_delcache, $arg_delcache, $list_id);
mysql2_query_secure($delcache['SQL'], $_SESSION['OCS']["writeServer"], $delcache['ARG']);
$cached = mysqli_affected_rows($_SESSION['OCS']["writeServer"]);
return $cached;
}
//fonction de remplacement d'un groupe
function replace_group($id_group, $list_id, $req, $group_type) {
//static group?
if ($group_type == 'STATIC') {
$static = 1;
$req = "";
} else {
$static = 0;
}
//delete cache
$sql_delcache = "DELETE FROM groups_cache WHERE group_id='%s'";
$arg_delcache = $id_group;
mysql2_query_secure($sql_delcache, $_SESSION['OCS']["writeServer"], $arg_delcache);
//update group
$sql_updGroup = "UPDATE groups set request='', xmldef='%s' where hardware_id=%s";
$arg_updGroup = array(generate_xml($req), $id_group);
mysql2_query_secure($sql_updGroup, $_SESSION['OCS']["writeServer"], $arg_updGroup);
$nb_computer = add_computers_cache($list_id, $id_group, $static);
return $nb_computer;
}
//create group function
function creat_group($name, $descr, $list_id, $req, $group_type) {
global $l;
if (trim($name) == "") {
return array('RESULT' => 'ERROR', 'LBL' => $l->g(638));
}
if (trim($descr) == "") {
return array('RESULT' => 'ERROR', 'LBL' => $l->g(1234));
}
//static group?
if ($group_type == 'STATIC') {
$static = 1;
$req = "";
} else {
$static = 0;
}
//does $name group already exists
$reqGetId = "SELECT id FROM hardware WHERE name='%s' and deviceid = '_SYSTEMGROUP_'";
$argGetId = $name;
$resGetId = mysql2_query_secure($reqGetId, $_SESSION['OCS']["readServer"], $argGetId);
if (mysqli_fetch_array($resGetId)) {
return array('RESULT' => 'ERROR', 'LBL' => $l->g(621));
}
//insert new group
$sql_insert = "INSERT INTO hardware(deviceid,name,description,lastdate) VALUES( '_SYSTEMGROUP_' , '%s', '%s', NOW())";
$arg_insert = array($name, $descr);
mysql2_query_secure($sql_insert, $_SESSION['OCS']["writeServer"], $arg_insert);
//Getting hardware id
$insertId = mysqli_insert_id($_SESSION['OCS']["writeServer"]);
$xml = generate_xml($req);
//Creating group
$sql_group = "INSERT INTO groups(hardware_id, xmldef, create_time) VALUES ( %s, '%s', UNIX_TIMESTAMP() )";
$arg_group = array($insertId, $xml);
mysql2_query_secure($sql_group, $_SESSION['OCS']["writeServer"], $arg_group);
addLog("CREATE GROUPE", $name);
//Generating cache
if ($list_id != '') {
$nb_computer = add_computers_cache($list_id, $insertId, $static);
return array('RESULT' => 'OK', 'LBL' => $nb_computer);
}
return array('RESULT' => 'OK', 'LBL' => $l->g(607) . " " . $l->g(608));
}
//function to add computer in groups_cache
function add_computers_cache($list_id, $groupid, $static) {
require_once('function_computers.php');
//Generating cache
if (lock($groupid)) {
$reqCache = "INSERT IGNORE INTO groups_cache(hardware_id, group_id, static)
SELECT id, %s, %s from hardware where id in ";
$argCache = array($groupid, $static);
$cache = mysql2_prepare($reqCache, $argCache, $list_id);
mysql2_query_secure($cache['SQL'], $_SESSION['OCS']["writeServer"], $cache['ARG']);
$cached = mysqli_affected_rows($_SESSION['OCS']["writeServer"]);
unlock($groupid);
return $cached;
}
}
//generation du xml en fonction des requetes
function generate_xml($req) {
//si il exite une requete
if (isset($req[0])) {
//création du début du xml
$xml = "<xmldef>";
$i = 0;
//concaténation des différentes requetes
while (isset($req[$i])) {
$xml .= "<REQUEST>" . clean($req[$i]) . "</REQUEST>";
$i++;
}
$xml .= "</xmldef>";
} else { //si aucune requete n'exite, on renvoie un xml vide
$xml = "";
}
return $xml;
}
function clean($txt) {
$cherche = array("&", "<", ">", "\"", "'");
$replace = array("&", "<", ">", """, "'");
return str_replace($cherche, $replace, $txt);
}
function delete_group($id_supp) {
global $l;
if ($id_supp == "") {
return array('RESULT' => 'ERROR', 'LBL' => "ID IS NULL");
}
if (!is_numeric($id_supp)) {
return array('RESULT' => 'ERROR', 'LBL' => "ID IS NOT NUMERIC");
}
$sql_verif_group = "select id from hardware where id=%s and DEVICEID='_SYSTEMGROUP_' or DEVICEID='_DOWNLOADGROUP_'";
$arg_verif_group = $id_supp;
$res_verif_group = mysql2_query_secure($sql_verif_group, $_SESSION['OCS']["readServer"], $arg_verif_group);
if (mysqli_fetch_array($res_verif_group)) {
deleteDid($arg_verif_group);
addLog("DELETE GROUPE", $id_supp);
return array('RESULT' => 'OK', 'LBL' => '');
} else {
return array('RESULT' => 'ERROR', 'LBL' => $l->g(623));
}
}
function group_4_all($id_group) {
if ($id_group == "") {
return array('RESULT' => 'ERROR', 'LBL' => "ID IS NULL");
}
if (!is_numeric($id_group)) {
return array('RESULT' => 'ERROR', 'LBL' => "ID IS NOT NUMERIC");
}
$sql_verif = "select WORKGROUP from hardware where id=%s";
$arg_verif = $id_group;
$res = mysql2_query_secure($sql_verif, $_SESSION['OCS']["readServer"], $arg_verif);
$item = mysqli_fetch_object($res);
if ($item->WORKGROUP != "GROUP_4_ALL") {
$sql_update = "update hardware set workgroup= 'GROUP_4_ALL' where id=%s";
$return_result['LBL'] = "Groupe visible pour tous";
} else {
$sql_update = "update hardware set workgroup= '' where id=%s";
$return_result['LBL'] = "Groupe invisible";
}
mysql2_query_secure($sql_update, $_SESSION['OCS']["writeServer"], $arg_verif);
$return_result['RESULT'] = "OK";
addLog("ACTION VISIBILITY OF GROUPE", $id_group);
return $return_result;
}
function show_redistrib_groups_packages($systemid){
global $l;
$query = "select da.NAME, da.PRIORITY,da.FRAGMENTS,da.SIZE,da.OSNAME,de.INFO_LOC,de.CERT_FILE,de.CERT_PATH,de.PACK_LOC
from download_enable de,download_available da
where de.GROUP_ID =%s
and da.FILEID=de.FILEID
group by de.fileid;";
$arg_query = array($systemid);
$resDeploy = mysql2_query_secure($query, $_SESSION['OCS']["readServer"], $arg_query);
if (mysqli_num_rows($resDeploy) > 0) {
?>
<div class='row'>
<div class='col-md-12'>
<p>
<table class='table table-striped'>
<thead>
<tr>
<th><?php echo $l->g(49) ?></th>
<th><?php echo $l->g(440) ?></th>
<th><?php echo $l->g(464) ?></th>
<th><?php echo $l->g(462) ?></th>
<th><?php echo $l->g(1387) ?></th>
<th>INFO_LOC</th>
<th>CERT_FILE</th>
<th>CERT_PATH</th>
<th>PACK_LOC</th>
</tr>
</thead>
<tbody>
<?php
while ($valDeploy = mysqli_fetch_array($resDeploy)) {
?>
<tr>
<td><?php echo $valDeploy['NAME'] ?></td>
<td><?php echo $valDeploy['PRIORITY'] ?></td>
<td><?php echo $valDeploy['FRAGMENTS'] ?></td>
<td><?php echo $valDeploy['SIZE'] ?></td>
<td><?php echo $valDeploy['OSNAME'] ?></td>
<td><?php echo $valDeploy['INFO_LOC'] ?></td>
<td><?php echo $valDeploy['CERT_FILE'] ?></td>
<td><?php echo $valDeploy['CERT_PATH'] ?></td>
<td><?php echo $valDeploy['PACK_LOC'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</p>
</div>
</div>
<?php
}
}
?>
|