#!/usr/bin/php
<?php

require_once('/usr/share/ombutel/www/includes/cli.php');

use ombutel\ami;
use ombutel\helper;

if ($argc = 2) {
	try {
		$ami = ami::current();
        $ami->command("core set verbose 0");
        $ami->command("sip set debug off");
		list(, $filepath) = $argv;
		if (file_exists($filepath)) {
			unlink($filepath);
		}
		helper::execute('diagnostics', "remove_service_timer", $response);

		$level_file = '/tmp/cpbx_ai_diag_log_level';
		if (file_exists($level_file)) {
			$level = trim(@file_get_contents($level_file));
			if ($level) {
				$ctx = stream_context_create(array('http' => array('method' => 'POST')));
				@file_get_contents('http://localhost:8089/log-level?level=' . $level, false, $ctx);
			}
			@unlink($level_file);
		}
	} catch (\Exception $e) {
        echo $e->getMessage();
	}
}