File: ms_local.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 (215 lines) | stat: -rwxr-xr-x 7,473 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
<?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.
 */
require_once('require/function_files.php');
$form_name="insert_computers";
$data_on['FILE']=$l->g(288);
$data_on['MANUEL']=$l->g(1258);
echo open_form($form_name, '', '', 'form-horizontal');
//$protectedPost['onglet']='FILE';
show_tabs($data_on,$form_name,"onglet",true);
echo "<div class='col col-md-10' >";

if ($protectedPost['onglet'] == 'FILE'){
	?>
	<script language='javascript'>
	    
	    function getext(filename){
	    	 var parts = filename.split('.');
	   		return(parts[(parts.length-1)]);    
	    }
	    
	    function namefile(filename){
	     	var parts = filename.split('.');
	    	return(parts[0]);    
	    }    
	
	    function verif_file_format(champ){
	        var ExtList=['ocs','OCS','xml','XML'];
			filename = document.getElementById(champ).value.toLowerCase();
			fileExt = getext(filename);
			for (i=0; i<ExtList.length; i++)
			{
				if ( fileExt == ExtList[i] ) 
				{
					return (true);
				}
			}
			alert('<?php mysqli_real_escape_string($_SESSION['OCS']["readServer"],$l->g(559)) ?>');
			return (false);
	     }
	          
	</script>
	<?php
	//   
	$form_name1="SEND_FILE";
	$data_config=look_config_default_values(array('LOCAL_URI_SERVER'),'',
											array('TVALUE'=>array('LOCAL_URI_SERVER'=>'http://localhost:80/ocsinventory')));
											
	$server = $data_config['tvalue']['LOCAL_URI_SERVER'];
	$array_port=explode(':',$server);
	$port_trait=array_pop($array_port);
	$array_port=explode('/',$port_trait);
	$port=$array_port[0];
	if(is_uploaded_file($_FILES['file_upload']['tmp_name'])) {
		
			$fd = fopen($_FILES['file_upload']['tmp_name'], "r");
			if ($_FILES['file_upload']['size'] != 0){
				$contents = fread($fd, filesize ($_FILES['file_upload']['tmp_name']));
				fclose($fd);
		
				$result = post_ocs_file_to_server($contents, $server, $port);
				
				if (isset($result["errno"])) {
					$errno = $result["errno"];
					$errstr = $result["errstr"];
					msg_error($l->g(344). " ". $errno . " / " . $errstr);
				}else {
					if( ! strstr ( $result[0], "200") )
						msg_error($l->g(344). " " . $result[0]);
					else {
						msg_success($l->g(287)." OK");
					}
				}
			}else
				msg_error($l->g(1244));
	}
	printEntete($l->g(560).": ".$server);
	echo close_form();
	echo "<br>";
	echo open_form($form_name1,'',"enctype='multipart/form-data' onsubmit=\"return verif_file_format('file_upload');\"", 'form-horizontal');
	formGroup('file', 'file_upload', $l->g(1048), '', '', $protectedPost['file_upload']);

	echo "<input name='GO' class='btn btn-success' id='GO' type='submit' value='".$l->g(13)."'>";
	echo close_form();
}else{
	require_once('require/function_computers.php');
	require_once('require/function_admininfo.php');	
	//list fields for form
	$form_fields_typeinput=array('COMPUTER_NAME_GENERIC'=>$l->g(35),
					   'SERIAL_GENERIC'=>$l->g(36),
					   'ADDR_MAC_GENERIC'=>$l->g(95));
	
	
	if (isset($protectedPost['Valid_modif'])){
		$error='';
		if (!is_numeric($protectedPost['NB_COMPUTERS']))
			$error.=$l->g(28).',';
			
		foreach ($form_fields_typeinput as $key=>$value){
			if (trim($protectedPost[$key]) == '')
				$error.=$value.',';
			
		}
		
		if ($error == ""){
			$check_trait=array();
			foreach ($protectedPost as $key=>$value){
				if ($value != ''){
					if (substr($key,0,7) == 'fields_' or $key == 'TAG'){
						$temp_field=explode('_',$key);
						
						//checkbox cas
						if (isset($temp_field[2])){
							$check_trait[$temp_field[0].'_'.$temp_field[1]].=$temp_field[2]."&&&";
						}else{
							$fields[]=$key;
							$values_fields[]=$value;
						}
					}			
				}	
			}
			//cas of checkbox
			if ($check_trait != array()){				
				foreach ($check_trait as $key=>$value){
					$fields[]=$key;
					$values_fields[]=$value;					
				}							
			}
			/*if ($protectedPost['NB_COMPUTERS'] === 1)
				$protectedPost['NB_COMPUTERS']='';*/
			$i=0;
			while ($i < $protectedPost['NB_COMPUTERS']){
				$id_computer=insert_manual_computer($protectedPost,$protectedPost['NB_COMPUTERS']);
				if (!is_array($fields)){
					$fields[]='TAG';
					$values_fields[]='';
				}
				insertinfo_computer($id_computer,$fields,$values_fields);
				$i++;			
			}
			msg_success($l->g(881));
		}else
			msg_error($l->g(684)."<br>".$error);
	}

	$i=0;
	$info_form['FIELDS']['name_field'][$i]='NB_COMPUTERS';
	$info_form['FIELDS']['type_field'][$i]=0;
	$info_form['FIELDS']['value_field'][$i]=($protectedPost['NB_COMPUTERS'] != '' ? $protectedPost['NB_COMPUTERS']:'1');
	$info_form['FIELDS']['tab_name'][$i]=$l->g(28);
	$config[$i]['CONFIG']['SIZE']=4	;
	$config[$i]['CONFIG']['MAXLENGTH']=4	;
	$other_data['COMMENT_AFTER'][$i]='';
	$config[$i]['CONFIG']['JAVASCRIPT']=$chiffres;
	
	foreach ($form_fields_typeinput as $key=>$value){
		$i++;
		$info_form['FIELDS']['name_field'][$i]=$key;
		$info_form['FIELDS']['type_field'][$i]=0;
		if ($key == 'ADDR_MAC_GENERIC')
			$info_form['FIELDS']['value_field'][$i]=(isset($protectedPost[$key])? $protectedPost[$key]:RandomMAC()) ;
		else
			$info_form['FIELDS']['value_field'][$i]=(isset($protectedPost[$key])? $protectedPost[$key]:rand()) ;
		$info_form['FIELDS']['tab_name'][$i]=$value."*";
		$config[$i]['CONFIG']['SIZE']=30;
		$other_data['COMMENT_AFTER'][$i]='_M';		
	}
		
	$accountinfo_form=show_accountinfo('','COMPUTERS','5'); 
	
	//merge data
	$info_form['FIELDS']['name_field']=array_merge ($info_form['FIELDS']['name_field'],$accountinfo_form['FIELDS']['name_field']);
	$info_form['FIELDS']['type_field']=array_merge ($info_form['FIELDS']['type_field'],$accountinfo_form['FIELDS']['type_field']);
	$info_form['FIELDS']['value_field']=array_merge ($info_form['FIELDS']['value_field'],$accountinfo_form['FIELDS']['value_field']);
	$info_form['FIELDS']['tab_name']=array_merge ($info_form['FIELDS']['tab_name'],$accountinfo_form['FIELDS']['tab_name']);
	$config=array_merge ($config,$accountinfo_form['CONFIG']);
	$other_data['COMMENT_AFTER']=array_merge ($other_data['COMMENT_AFTER'],$accountinfo_form['COMMENT_AFTER']);

	
	$tab_typ_champ=show_field($info_form['FIELDS']['name_field'],$info_form['FIELDS']['type_field'],$info_form['FIELDS']['value_field']);
	foreach ($config as $key=>$value){
		$tab_typ_champ[$key]['CONFIG']=$value['CONFIG'];
		$tab_typ_champ[$key]['COMMENT_AFTER']=$other_data['COMMENT_AFTER'][$key];		
	}
	
	
	if (isset($tab_typ_champ)){
		modif_values($info_form['FIELDS']['tab_name'],$tab_typ_champ,$tab_hidden, array(
			'show_frame' => false
		));
	}

	echo "</div>";
	echo close_form();
}
?>