Project

General

Profile

Bug #9211 » ntopng.inc.diff

DRago_Angel [InV@DER], 08/16/2019 06:20 AM

View differences:

usr/local/pkg/ntopng.inc
43 43
	$ntopng_config = $config['installedpackages']['ntopng']['config'][0];
44 44
	if ($ntopng_config['keepdata'] != "on") {
45 45
		if (is_dir("/var/db/ntopng/")) {
46
			mwexec("rm -rf /var/db/ntopng/");
46
			exec("rm -rf /var/db/ntopng/");
47 47
		}
48 48
		if (is_array($config['installedpackages']['ntopng'])) {
49 49
			unset($config['installedpackages']['ntopng']);
......
200 200
	$redis_started = false;
201 201

  
202 202
	if (!is_process_running("redis-server")) {
203
		mwexec_bg("{$redis_path}/redis-server --bind 127.0.0.1 ::1 --dir /var/db/ntopng/ --dbfilename ntopng.rdb");
203
		exec_bg("{$redis_path}/redis-server --bind 127.0.0.1 ::1 --dir /var/db/ntopng/ --dbfilename ntopng.rdb");
204 204
		for ($i = 0; $i <= 10; $i++) {
205 205
			if (is_process_running("redis-server")) {
206 206
				$redis_started = true;
......
222 222
	if (!empty($ntopng_config['redis_password'])) {
223 223
		$password = md5($ntopng_config['redis_password']);
224 224
		if (ntopng_redis_started()) {
225
			mwexec("{$redis_path}/redis-cli SET ntopng.user.admin.password " . escapeshellarg($password));
225
			exec("{$redis_path}/redis-cli SET ntopng.user.admin.password " . escapeshellarg($password));
226 226
			// Make sure the preferences menu is accessible (Bug #6999)
227
			mwexec("{$redis_path}/redis-cli SET ntopng.user.admin.group administrator");
228
			mwexec("{$redis_path}/redis-cli save");
227
			exec("{$redis_path}/redis-cli SET ntopng.user.admin.group administrator");
228
			exec("{$redis_path}/redis-cli save");
229 229
		} else {
230 230
			log_error(gettext("[ntopng] Cannot set admin password - redis-server is not running."));
231 231
		}
......
234 234

  
235 235
function ntopng_create_datadir() {
236 236
	safe_mkdir("/var/db/ntopng/rrd/graphics", 0755);
237
	mwexec("/bin/chmod -R 755 /var/db/ntopng");
238
	mwexec("/usr/sbin/chown -R nobody:nobody /var/db/ntopng");
237
	exec("/bin/chmod -R 755 /var/db/ntopng");
238
	exec("/usr/sbin/chown -R nobody:nobody /var/db/ntopng");
239 239
}
240 240

  
241 241
function ntopng_update_geoip() {
242 242
	global $config;
243 243
	$fetchcmd = "/usr/bin/fetch";
244
	$geolite_city = "https://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz";
245
	$geolite_city_v6 = "https://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz";
246
	$geoip_asnum = "https://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz";
247
	$geoip_asnum_v6 = "https://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz";
244
	$geolite_city = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz";
245
	$geoip_asnum = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz";
248 246
	$output_dir = "/usr/local/share/ntopng";
249

  
250
	mwexec("{$fetchcmd} -o {$output_dir} -T 5 {$geolite_city}");
251
	mwexec("{$fetchcmd} -o {$output_dir} -T 5 {$geolite_city_v6}");
252
	mwexec("{$fetchcmd} -o {$output_dir} -T 5 {$geoip_asnum}");
253
	mwexec("{$fetchcmd} -o {$output_dir} -T 5 {$geoip_asnum_v6}");
247
	
248
	exec("{$fetchcmd} -o {$output_dir} -T 5 {$geolite_city}");
249
	exec("{$fetchcmd} -o {$output_dir} -T 5 {$geoip_asnum}");
254 250

  
255 251
	ntopng_fixup_geoip();
256 252

  
......
271 267

  
272 268
	safe_mkdir($target_dir, 0755);
273 269

  
274
	foreach(glob("{$source_dir}/Geo*.dat*") as $geofile) {
270
	foreach(glob("{$source_dir}/Geo*.tar.gz") as $geofile) {
275 271
		/* Decompress if needed. */
276
		if (substr($geofile, -3, 3) == ".gz") {
277
			// keep -f here, otherwise the files will not get updated
278
			mwexec("/usr/bin/gzip -d -f " . escapeshellarg($geofile));
272
		if (substr($geofile, -7, 7) == ".tar.gz") {			
273
			exec("tar -C {$source_dir} -f {$geofile} --strip 1 -xz '*.mmdb'");
279 274
		}
280 275
	}
281 276

  
282 277
	/* Use a separate glob since the filenames could have changed since the last run */
283
	foreach(glob("{$source_dir}/Geo*.dat*") as $geofile) {
278
	foreach(glob("{$source_dir}/Geo*.mmdb") as $geofile) {
284 279
		$target_file = $target_dir . '/' . basename($geofile);
285 280
		if (!file_exists($target_file)) {
286 281
			symlink($geofile, $target_file);
......
295 290

  
296 291
	if (ntopng_redis_started()) {
297 292
		/* Delete all the keys of all the existing Redis databases */
298
		mwexec("{$redis_path}/redis-cli flushall");
293
		exec("{$redis_path}/redis-cli flushall");
299 294
		log_error(gettext("[ntopng] Flushed Redis DB."));
300 295
		/* Set admin password while redis-server is still running */
301 296
		ntopng_set_redis_password();
......
303 298
		/* Stop services and delete all graphs, data and dump flows */
304 299
		ntopng_services_stop();
305 300
		if (is_dir("/var/db/ntopng/")) {
306
			mwexec("rm -rf /var/db/ntopng/");
301
			exec("rm -rf /var/db/ntopng/");
307 302
			log_error(gettext("[ntopng] Deleted ntopng traffic data and graphs."));
308 303
		} else {
309 304
			log_error(gettext("[ntopng] Nothing to delete; /var/db/ntopng/ directory not found."));
(2-2/3)