Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php defined('BASEPATH') OR exit('No direct script access allowed'); error_reporting(0); ..

Decoded Output download

<?php defined('BASEPATH') OR exit('No direct script access allowed'); error_reporting(0); class Ajax extends CI_Controller { function __construct() { parent::__construct(); }  private function _get_data_plate_image($image_path, $id) { $img_full_path=LPRDB_PATH.$image_path.'/'.sprintf("%09d_.jpg",$id); return '<div height=20 width=100><img height=20 src="data:image/jpg;base64,'.base64_encode(file_get_contents($img_full_path)).'"/></div>'; } private function _get_data_direction($direction) { if ($direction == 1) return '<img height=20 class="rot90" src="'.base_url("img/0.png").'">'; else if ($direction == 2) return '<img height=20 class="rot270" src="'.base_url("img/0.png").'">'; else return ""; }  private function remote_get_content($file, $data, $timeout_sec=20) { $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded
", 'timeout' => $timeout_sec, 'method'  => 'POST', 'content' => http_build_query($data), ) ); $context  = stream_context_create($options); $res = file_get_contents($file, false, $context);  if ($res === FALSE || $res == "") return FALSE; return $res; }    public function plates_get() { PERM("db_view");  $this->load->model('model_plates','plates'); $records = $this->plates->get_records(); $count_all = $this->plates->count_all(); $count_filtered = $this->plates->count_filtered(); unset($this->plates);  $max_id = 0; $data = array(); $no = $_POST['start']; foreach ($records as $plate) { $no++; $row = array(); $row['id'] = $plate->id; $row['dt'] = $plate->dt.".<small>".sprintf('%03d', $plate->dt_ms)."</small>"; $row['text'] = $plate->text; $row['text_fmt'] = $plate->text_fmt; $row['country'] = $plate->country; if (strlen($plate->state) > 0) $row['country'] .= '-'.$plate->state; $row['plate_image'] = $this->_get_data_plate_image($plate->image_path, $plate->id); $row['p2p_speed'] = $plate->p2p_speed; $row['confidence'] = $plate->confidence."%"; $row['direction'] = $this->_get_data_direction($plate->moving_direction); $row['zone'] = $plate->zone; $row['x'] = $plate->x; $row['y'] = $plate->y; $row['width'] = $plate->width; $row['height'] = $plate->height; $row['camera_id'] = $plate->camera_id; $row['server_id'] = $plate->server_id; $row['image_path'] = $plate->image_path; $data[] = $row;  if ($plate->id > $max_id) $max_id = $plate->id; }  $output = array( "draw" => $_POST['draw'], "recordsTotal" => $count_all, "recordsFiltered" => $count_filtered, "max_id" => $max_id, "data" => $data, ); echo json_encode($output); }  public function get_max_id() { $this->load->model('model_plates','plates'); $res = $this->plates->get_max_id(); unset($this->plates); echo json_encode($res); }  public function plates_delete() { PERM("db_delete"); if (isset($_POST['from_area']) && $_POST['from_area'] === true) { $this->load->model('model_area_plate','area_plate'); $this->area_plate->delete_records(); } else { $this->load->model('model_plates','plates'); $this->plates->delete_records(); } }  public function plates_export() { PERM("db_export");  header('Content-Type: text/plain'); ignore_user_abort(true); $this->load->model('model_plates','plates'); $export_file = $this->plates->export_records(); for ($i=0; $i<2; $i++){ flush(); ob_flush(); if (connection_aborted() && file_exists($export_file)) unlink($export_file); echo " "; } }  public function plates_export_download() { PERM("db_export");  $export_file = LPRDB_PATH .'/tmp/'.$_POST['export_file'].'.zip'; if (file_exists($export_file)) { $size = filesize($export_file); header('Content-Type: application/zip'); header("Content-Length: " . $size); header('Content-Disposition: filename="export.zip"'); ignore_user_abort(true); $fp = fopen($export_file, "r"); while (!feof($fp)){ echo fread($fp, 4096); if (connection_aborted()) break; } fclose($fp); unlink($export_file); return; } header("HTTP/1.1 501 "."Unable to download archive file. The file does not exists."); return; }  public function areas_report_export() { PERM("db_export");  header('Content-Type: text/plain'); ignore_user_abort(true); $this->load->model('model_plates','plates'); $export_file = $this->plates->areas_report_export(); for ($i=0; $i<2; $i++){ flush(); ob_flush(); if (connection_aborted() && file_exists($export_file)) unlink($export_file); echo " "; } }  public function areas_report_download() { PERM("db_export");  $export_file = LPRDB_PATH .'/tmp/'.$_POST['export_file'].'.zip'; if (file_exists($export_file)) { $size = filesize($export_file); header('Content-Type: application/zip'); header("Content-Length: " . $size); header('Content-Disposition: filename="export.zip"'); ignore_user_abort(true); $fp = fopen($export_file, "r"); while (!feof($fp)){ echo fread($fp, 4096); if (connection_aborted()) break; } fclose($fp); unlink($export_file); return; } header("HTTP/1.1 501 "."Unable to download archive file. The file does not exists."); return; }  public function list_get() { PERM("lists_view");  $this->load->model('model_list','list'); $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->list->count_all(), "recordsFiltered" => $this->list->count_filtered(), "data" => $this->list->get_records(), ); echo json_encode($output); }  public function list_update() { PERM("lists_edit");  $this->load->model('model_list','list'); $this->list->update_record(); }  public function list_add() { PERM("lists_add");  $this->load->model('model_list','list'); echo json_encode($this->list->add_record()); }  public function list_delete() { PERM("lists_delete");  $this->load->model('model_list','list'); $this->list->delete_records(); }  public function list_plates_get() { PERM("lists_view");  $this->load->model('model_list_plates','list_plates'); $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->list_plates->count_all(), "recordsFiltered" => $this->list_plates->count_filtered(), "data" =>  $this->list_plates->get_records(), ); echo json_encode($output); } public function list_plates_update() { PERM("lists_plates_edit");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->update_record(); }  public function list_plates_add() { PERM("lists_plates_add");  $this->load->model('model_list_plates','list_plates'); echo json_encode($this->list_plates->add_record()); }  public function list_plates_delete() { PERM("lists_plates_delete");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->delete_records(); }  public function list_plates_set_validity() { PERM("lists_plates_edit");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->set_validity(); }  public function list_plates_import() { PERM("lists_plates_import");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->import(); } public function list_plates_export() { PERM("lists_plates_export");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->export(); }  public function rule_get() { PERM("rules_view");  $this->load->model('model_rule','rule'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->rule->count_all(), "recordsFiltered" => $this->rule->count_filtered(), "data" => $this->rule->get_records() ); echo json_encode($output); }  public function rule_update() { PERM("rules_edit");  $this->load->model('model_rule','rule'); $this->rule->update_record(); }  public function rule_add() { PERM("rules_add");  $this->load->model('model_rule','rule'); $this->rule->add_record(); }  public function rule_delete() { PERM("rules_delete");  $this->load->model('model_rule','rule'); $this->rule->delete_records(); }  public function area_get() { $this->load->model('model_area','area'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->area->count_all(), "recordsFiltered" => $this->area->count_filtered(), "data" => $this->area->get_records() );  echo json_encode($output); }  public function area_update() { $this->load->model('model_area','area'); $this->area->update_record(); }  public function area_add() { $this->load->model('model_area','area'); echo json_encode($this->area->add_record()); }  public function area_delete() { $this->load->model('model_area','area'); $this->area->delete_records(); }  public function p2p_get() { PERM("p2p_view");  $this->load->model('model_p2p','p2p'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->p2p->count_all(), "recordsFiltered" => $this->p2p->count_filtered(), "data" => $this->p2p->get_records() ); echo json_encode($output); }  public function p2p_update() { PERM("p2p_edit");  $this->load->model('model_p2p','p2p'); $this->p2p->update_record(); }  public function p2p_add() { PERM("p2p_add");  $this->load->model('model_p2p','p2p'); $this->p2p->add_record(); }  public function p2p_delete() { PERM("p2p_delete");  $this->load->model('model_p2p','p2p'); $this->p2p->delete_records(); }  public function log_get() { PERM("logs_view");  $this->load->model('model_log','logs'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->logs->count_all(), "recordsFiltered" => $this->logs->count_filtered(), "data" => $this->logs->get_records() ); echo json_encode($output); }  public function log_clear() { PERM("logs_delete");  $this->load->model('model_log','logs'); $this->logs->delete_all_records(); }  public function users_get() { $this->load->model('model_users','users'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->users->count_all(), "recordsFiltered" => $this->users->count_filtered(), "data" => $this->users->get_records() ); echo json_encode($output); }  public function user_delete() { $this->load->model('model_users','users'); $this->users->delete_records(); }  public function user_add() { $user = $this->input->post('user'); unset($user["id"]); $this->load->model('model_users','users'); $id = $this->users->add_record($user); echo $id; }  public function user_update() { $user = $this->input->post('user'); $this->load->model('model_users','users'); $this->users->update_record($user); }  public function user_set_password() { $user_id = $this->input->post('user_id'); $password_cur = $this->input->post('password_cur'); $password_new = $this->input->post('password_new'); $this->load->model('model_users','users'); $this->users->set_password($user_id, $password_cur, $password_new); }   public function dbconfig_get() { $this->load->model('model_config','cfg'); echo json_encode($this->cfg->get_records()); } public function dbconfig_update() { $this->load->model('model_config','cfg'); $this->cfg->update_record(); }  public function cameras_get() { PERM("cam_view");  $this->load->model('model_servers_local','servers'); $servers = $this->servers->get_records(); $cameras = array(); foreach ($servers as $server) { $cams = array(); $url = "http://".$server->server_address.":".$server->server_port."/lprapi/?c=get_cameras"; if (($json = $this->remote_get_content($url, $_POST)) !== FALSE) { if (($cams = json_decode($json)) !== NULL) { foreach ($cams as $cam) { if (strlen($cam->camera_name)==0) $cam->camera_name = " "; $cam->server = $server;  $found = false; foreach ($cameras as $test) { if ($test->camera_uuid == $cam->camera_uuid) { $found = true; break; } }  if (!$found) { array_push($cameras, $cam); } } } } } $output = array( "draw" => 0, "recordsTotal" => sizeof($cameras), "recordsFiltered" => sizeof($cameras), "data" => $cameras ); echo json_encode($output); }  public function camera_control() { $cmd = $this->input->post('cmd'); $data = $this->input->post('data'); for ($i=0; $i<sizeof($data); $i++) { $server_address = $data[$i]['server']['server_address']; $server_port = $data[$i]['server']['server_port']; $service_name = $data[$i]['service_name']; $url = "http://".$server_address.":".$server_port."/lprapi/"; if ($cmd == "start") { PERM("cam_start"); $url .= "?c=camera_start&p=".$service_name; file_get_contents($url); } if ($cmd == "stop") { PERM("cam_stop"); $url .= "?c=camera_stop&p=".$service_name; file_get_contents($url); } if ($cmd == "delete") { PERM("cam_delete"); $url .= "?c=camera_delete&p=".$service_name; file_get_contents($url); } } }  public function get_cameras_status() { $srv_cams = $this->input->post('data'); $url = 'http://' . $srv_cams['server_address'] . ':' . $srv_cams['server_port'] . '/lprapi/?c=cameras_status&p=' . implode(',', $srv_cams['service_names']); $ctx = stream_context_create(array('http'=> array( 'timeout' => 3, ) )); echo file_get_contents($url, false, $ctx); }  public function camera_add() { PERM("cam_add");  $server_id = $this->input->post('server_id'); $camera_name = $this->input->post('camera_name'); $start_type = $this->input->post('start_type');  $this->load->model('model_servers_local','servers'); $server = $this->servers->get_record($server_id); $_POST['server_port'] = $_SERVER['SERVER_PORT']; $url = "http://".$server->server_address.":".$server->server_port."/lprapi/?c=camera_add";  if (($json = $this->remote_get_content($url, $_POST)) !== FALSE) { $camera = json_decode($json); $camera->server = $server; echo json_encode($camera); } else { header("HTTP/1.1 500 "."Error adding new camera"); } }  public function camera_get_config() { $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_get_config&p=".$camera['service_name']; echo file_get_contents($url); } public function camera_set_config() { PERM("cam_config");  $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded
", 'method'  => 'POST', 'content' => http_build_query($_POST) ) ); $context  = stream_context_create($options); $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_set_config"; echo file_get_contents($url, false, $context); }  public function camera_execute_action() { PERM("cam_config");  $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded
", 'method'  => 'POST', 'content' => http_build_query($_POST) ) ); $context  = stream_context_create($options); $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_execute_action"; echo file_get_contents($url, false, $context); } public function server_get() { PERM("srv_view");  $this->load->model('model_servers_local','servers_local'); $data = $this->servers_local->get_records(); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => sizeof($data), "recordsFiltered" => sizeof($data), "data" => $data ); echo json_encode($output); }  public function server_add() { PERM("srv_add");  $server = $this->input->post('server'); $this->load->model('model_servers_local','servers_local'); $this->servers_local->add_record($server); }  public function server_delete() { PERM("srv_delete");  $this->load->model('model_servers_local','servers_local'); $this->servers_local->delete_records(); }  public function server_update() { PERM("srv_edit");  $server = $this->input->post('server'); $this->load->model('model_servers_local','servers_local'); $this->servers_local->update_record($server); }  public function server_get_info() { PERM("srv_view");  $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=server_get_info"; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."Error getting server information"); else echo $res; }  public function lic_activate() { PERM("srv_lic");  $url = 'http://www.dtksoft.com/license/activate/?lic_key='.$this->input->post('lic_key').'&system_id='.$this->input->post('system_id').'&prod=lprs&comments='.urlencode($this->input->post('comments')); $error_text = ""; file_get_contents($url); $activation_code = ""; for ($i=0; $i<sizeof($http_response_header); $i++) { if (strpos($http_response_header[$i], "ACTIVATION_CODE:")===0) $activation_code = trim(substr($http_response_header[$i], 16)); if (strpos($http_response_header[$i], "ERROR_TEXT:")===0) $error_text = trim(substr($http_response_header[$i], 11)); } if ($activation_code != "ERROR") { $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=lic_activate"; unset($_POST); $_POST['activation_code'] = $activation_code; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."License activation error"); } else { header("HTTP/1.1 500 ". $error_text); } } public function lic_activate_offline() { PERM("srv_lic");  $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=lic_activate"; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."License activation error"); }  public function send_test_email() { $smtp_config = array(); $smtp_config['smtp_host'] = $this->input->post("smtp_host"); $smtp_config['smtp_port'] = $this->input->post("smtp_port"); $smtp_config['smtp_user'] = $this->input->post("smtp_user"); $smtp_config['smtp_password'] = base64_encode($this->input->post("smtp_password")); $smtp_config['smtp_encryption'] = $this->input->post("smtp_encryption");  $this->load->model('model_users','users'); $admin_users = $this->users->get_admin_users(); if (sizeof($admin_users) == 0) { echo "No users with Administrator role"; return; } $n=0; include APPPATH."/third_party/mail.php"; foreach ($admin_users as $usr) { if (strlen($usr['email']) == 0) continue; $n++; $subject = LANG2("product_name") . " - Test message"; $res = SendSmtpMail($usr['email'], $usr['full_name'], $usr['email'], $usr['full_name'], $subject, "This is the test message", "", "", $smtp_config); if (strlen($res) > 0) { $p=strpos($res, "https://github"); if ($p !== false) $res = substr($res, 0, $p); echo $res; return; } } if ($n==0) { echo "Email address not defined for Administrator" ; } }  private function LogGetSourceName($id) { if ($id == 1) return "SubmitResult"; else if ($id == 2) return "RulesProcessing"; else if ($id == 3) return "Retention"; else return "Unknown"; } private function LogGetLevelName($id) { if ($id == 1) return "Information"; else if ($id == 2) return "Warning"; else if ($id == 3) return "Error"; else return "Unknown"; } public function cron() { $this->load->model('model_config','cfg'); $this->load->model('model_users','users'); $this->load->model('model_log','logs'); $log_items = $this->logs->get_records_not_email_sent(); if (sizeof($log_items) == 0) return;  $smtp_config = array(); $smtp_config['smtp_host'] = $this->cfg->get("smtp_host"); $smtp_config['smtp_port'] = $this->cfg->get("smtp_port"); $smtp_config['smtp_user'] = $this->cfg->get("smtp_user"); $smtp_config['smtp_password'] = $this->cfg->get("smtp_password"); $smtp_config['smtp_encryption'] = $this->cfg->get("smtp_encryption"); if (strlen($smtp_config['smtp_host']) == 0) return;  $admin_users = $this->users->get_admin_users(); if (sizeof($admin_users) == 0) return;  $subject = LANG2("product_name") . " - Event log"; $message = ""; foreach ($log_items as $log_item) { if (strlen($message) > 0) $message .= "
"; $message .= $log_item->dt . "	" . $this->LogGetSourceName($log_item->source) . "	" . $this->LogGetLevelName($log_item->level) . "	" . $log_item->message; } $ok = true; include APPPATH."/third_party/mail.php"; foreach ($admin_users as $usr) { if (strlen($usr['email']) == 0) continue; $res = SendSmtpMail($usr['email'], $usr['full_name'], $usr['email'], $usr['full_name'], $subject, $message, "", "", $smtp_config); if (strlen($res) > 0) { $p=strpos($res, "https://github"); if ($p !== false) $res = substr($res, 0, $p); $ok = false; break; } } if ($ok) { foreach ($log_items as $log_item) $this->logs->set_email_sent($log_item->id); } }  function send_email() { ob_end_clean(); ignore_user_abort(true); ob_start(); header("Connection: close"); header("Content-Length: " . ob_get_length()); ob_end_flush(); flush(); $email_list = $this->input->post("email_list"); $subject = $this->input->post("subject"); $img_attach = $this->input->post("img"); $id = $this->input->post("id"); $emails = explode(chr(1), str_replace([',', ';'], chr(1), $email_list)); if (sizeof($emails) == 0) return;  $this->load->model('model_config','cfg'); $this->load->model('model_users','users'); $this->load->model('model_log','logs'); $this->load->model('model_plates','plates');  $smtp_config = array(); $smtp_config['smtp_host'] = $this->cfg->get("smtp_host"); $smtp_config['smtp_port'] = $this->cfg->get("smtp_port"); $smtp_config['smtp_user'] = $this->cfg->get("smtp_user"); $smtp_config['smtp_password'] = $this->cfg->get("smtp_password"); $smtp_config['smtp_encryption'] = $this->cfg->get("smtp_encryption"); if (strlen($smtp_config['smtp_host']) == 0) return;  $rec = $this->plates->find($id); if ($rec == null) return;  $subject = str_replace("%DATETIME%", $rec->dt, $subject); $subject = str_replace("%COUNTRY%", $rec->country, $subject); $subject = str_replace("%PLATE_NUM%", $rec->text_fmt, $subject); $subject = str_replace("%NUMBER%", $rec->text_fmt, $subject); $subject = str_replace("%DIRECTION%", $rec->direction, $subject); $subject = str_replace("%CONFIDENCE%", $rec->confidence, $subject); $subject = str_replace("%ZONE%", $rec->zone, $subject);  include APPPATH."/third_party/mail.php"; foreach ($emails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $user = $this->users->find_by_name($email); if ($user == null || strlen($user->email)==0) return; $email = $user->email; } $message = " "; $file = ""; if ($img_attach == "Y") { $file = LPRDB_PATH. $rec->image_path . '/' . sprintf("%09d.jpg",$id); if (!file_exists($file)) $file = ""; } $res = SendSmtpMail($email, "", $email, "", $subject, $message, $file, basename($file), $smtp_config); }  } }  ?>

Did this file decode correctly?

Original Code

<?php defined('BASEPATH') OR exit('No direct script access allowed'); error_reporting(0); class Ajax extends CI_Controller { function __construct() { parent::__construct(); }  private function _get_data_plate_image($image_path, $id) { $img_full_path=LPRDB_PATH.$image_path.'/'.sprintf("%09d_.jpg",$id); return '<div height=20 width=100><img height=20 src="data:image/jpg;base64,'.base64_encode(file_get_contents($img_full_path)).'"/></div>'; } private function _get_data_direction($direction) { if ($direction == 1) return '<img height=20 class="rot90" src="'.base_url("img/0.png").'">'; else if ($direction == 2) return '<img height=20 class="rot270" src="'.base_url("img/0.png").'">'; else return ""; }  private function remote_get_content($file, $data, $timeout_sec=20) { $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded\r\n", 'timeout' => $timeout_sec, 'method'  => 'POST', 'content' => http_build_query($data), ) ); $context  = stream_context_create($options); $res = file_get_contents($file, false, $context);  if ($res === FALSE || $res == "") return FALSE; return $res; }    public function plates_get() { PERM("db_view");  $this->load->model('model_plates','plates'); $records = $this->plates->get_records(); $count_all = $this->plates->count_all(); $count_filtered = $this->plates->count_filtered(); unset($this->plates);  $max_id = 0; $data = array(); $no = $_POST['start']; foreach ($records as $plate) { $no++; $row = array(); $row['id'] = $plate->id; $row['dt'] = $plate->dt.".<small>".sprintf('%03d', $plate->dt_ms)."</small>"; $row['text'] = $plate->text; $row['text_fmt'] = $plate->text_fmt; $row['country'] = $plate->country; if (strlen($plate->state) > 0) $row['country'] .= '-'.$plate->state; $row['plate_image'] = $this->_get_data_plate_image($plate->image_path, $plate->id); $row['p2p_speed'] = $plate->p2p_speed; $row['confidence'] = $plate->confidence."%"; $row['direction'] = $this->_get_data_direction($plate->moving_direction); $row['zone'] = $plate->zone; $row['x'] = $plate->x; $row['y'] = $plate->y; $row['width'] = $plate->width; $row['height'] = $plate->height; $row['camera_id'] = $plate->camera_id; $row['server_id'] = $plate->server_id; $row['image_path'] = $plate->image_path; $data[] = $row;  if ($plate->id > $max_id) $max_id = $plate->id; }  $output = array( "draw" => $_POST['draw'], "recordsTotal" => $count_all, "recordsFiltered" => $count_filtered, "max_id" => $max_id, "data" => $data, ); echo json_encode($output); }  public function get_max_id() { $this->load->model('model_plates','plates'); $res = $this->plates->get_max_id(); unset($this->plates); echo json_encode($res); }  public function plates_delete() { PERM("db_delete"); if (isset($_POST['from_area']) && $_POST['from_area'] === true) { $this->load->model('model_area_plate','area_plate'); $this->area_plate->delete_records(); } else { $this->load->model('model_plates','plates'); $this->plates->delete_records(); } }  public function plates_export() { PERM("db_export");  header('Content-Type: text/plain'); ignore_user_abort(true); $this->load->model('model_plates','plates'); $export_file = $this->plates->export_records(); for ($i=0; $i<2; $i++){ flush(); ob_flush(); if (connection_aborted() && file_exists($export_file)) unlink($export_file); echo " "; } }  public function plates_export_download() { PERM("db_export");  $export_file = LPRDB_PATH .'/tmp/'.$_POST['export_file'].'.zip'; if (file_exists($export_file)) { $size = filesize($export_file); header('Content-Type: application/zip'); header("Content-Length: " . $size); header('Content-Disposition: filename="export.zip"'); ignore_user_abort(true); $fp = fopen($export_file, "r"); while (!feof($fp)){ echo fread($fp, 4096); if (connection_aborted()) break; } fclose($fp); unlink($export_file); return; } header("HTTP/1.1 501 "."Unable to download archive file. The file does not exists."); return; }  public function areas_report_export() { PERM("db_export");  header('Content-Type: text/plain'); ignore_user_abort(true); $this->load->model('model_plates','plates'); $export_file = $this->plates->areas_report_export(); for ($i=0; $i<2; $i++){ flush(); ob_flush(); if (connection_aborted() && file_exists($export_file)) unlink($export_file); echo " "; } }  public function areas_report_download() { PERM("db_export");  $export_file = LPRDB_PATH .'/tmp/'.$_POST['export_file'].'.zip'; if (file_exists($export_file)) { $size = filesize($export_file); header('Content-Type: application/zip'); header("Content-Length: " . $size); header('Content-Disposition: filename="export.zip"'); ignore_user_abort(true); $fp = fopen($export_file, "r"); while (!feof($fp)){ echo fread($fp, 4096); if (connection_aborted()) break; } fclose($fp); unlink($export_file); return; } header("HTTP/1.1 501 "."Unable to download archive file. The file does not exists."); return; }  public function list_get() { PERM("lists_view");  $this->load->model('model_list','list'); $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->list->count_all(), "recordsFiltered" => $this->list->count_filtered(), "data" => $this->list->get_records(), ); echo json_encode($output); }  public function list_update() { PERM("lists_edit");  $this->load->model('model_list','list'); $this->list->update_record(); }  public function list_add() { PERM("lists_add");  $this->load->model('model_list','list'); echo json_encode($this->list->add_record()); }  public function list_delete() { PERM("lists_delete");  $this->load->model('model_list','list'); $this->list->delete_records(); }  public function list_plates_get() { PERM("lists_view");  $this->load->model('model_list_plates','list_plates'); $output = array( "draw" => $_POST['draw'], "recordsTotal" => $this->list_plates->count_all(), "recordsFiltered" => $this->list_plates->count_filtered(), "data" =>  $this->list_plates->get_records(), ); echo json_encode($output); } public function list_plates_update() { PERM("lists_plates_edit");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->update_record(); }  public function list_plates_add() { PERM("lists_plates_add");  $this->load->model('model_list_plates','list_plates'); echo json_encode($this->list_plates->add_record()); }  public function list_plates_delete() { PERM("lists_plates_delete");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->delete_records(); }  public function list_plates_set_validity() { PERM("lists_plates_edit");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->set_validity(); }  public function list_plates_import() { PERM("lists_plates_import");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->import(); } public function list_plates_export() { PERM("lists_plates_export");  $this->load->model('model_list_plates','list_plates'); $this->list_plates->export(); }  public function rule_get() { PERM("rules_view");  $this->load->model('model_rule','rule'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->rule->count_all(), "recordsFiltered" => $this->rule->count_filtered(), "data" => $this->rule->get_records() ); echo json_encode($output); }  public function rule_update() { PERM("rules_edit");  $this->load->model('model_rule','rule'); $this->rule->update_record(); }  public function rule_add() { PERM("rules_add");  $this->load->model('model_rule','rule'); $this->rule->add_record(); }  public function rule_delete() { PERM("rules_delete");  $this->load->model('model_rule','rule'); $this->rule->delete_records(); }  public function area_get() { $this->load->model('model_area','area'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->area->count_all(), "recordsFiltered" => $this->area->count_filtered(), "data" => $this->area->get_records() );  echo json_encode($output); }  public function area_update() { $this->load->model('model_area','area'); $this->area->update_record(); }  public function area_add() { $this->load->model('model_area','area'); echo json_encode($this->area->add_record()); }  public function area_delete() { $this->load->model('model_area','area'); $this->area->delete_records(); }  public function p2p_get() { PERM("p2p_view");  $this->load->model('model_p2p','p2p'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->p2p->count_all(), "recordsFiltered" => $this->p2p->count_filtered(), "data" => $this->p2p->get_records() ); echo json_encode($output); }  public function p2p_update() { PERM("p2p_edit");  $this->load->model('model_p2p','p2p'); $this->p2p->update_record(); }  public function p2p_add() { PERM("p2p_add");  $this->load->model('model_p2p','p2p'); $this->p2p->add_record(); }  public function p2p_delete() { PERM("p2p_delete");  $this->load->model('model_p2p','p2p'); $this->p2p->delete_records(); }  public function log_get() { PERM("logs_view");  $this->load->model('model_log','logs'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->logs->count_all(), "recordsFiltered" => $this->logs->count_filtered(), "data" => $this->logs->get_records() ); echo json_encode($output); }  public function log_clear() { PERM("logs_delete");  $this->load->model('model_log','logs'); $this->logs->delete_all_records(); }  public function users_get() { $this->load->model('model_users','users'); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => $this->users->count_all(), "recordsFiltered" => $this->users->count_filtered(), "data" => $this->users->get_records() ); echo json_encode($output); }  public function user_delete() { $this->load->model('model_users','users'); $this->users->delete_records(); }  public function user_add() { $user = $this->input->post('user'); unset($user["id"]); $this->load->model('model_users','users'); $id = $this->users->add_record($user); echo $id; }  public function user_update() { $user = $this->input->post('user'); $this->load->model('model_users','users'); $this->users->update_record($user); }  public function user_set_password() { $user_id = $this->input->post('user_id'); $password_cur = $this->input->post('password_cur'); $password_new = $this->input->post('password_new'); $this->load->model('model_users','users'); $this->users->set_password($user_id, $password_cur, $password_new); }   public function dbconfig_get() { $this->load->model('model_config','cfg'); echo json_encode($this->cfg->get_records()); } public function dbconfig_update() { $this->load->model('model_config','cfg'); $this->cfg->update_record(); }  public function cameras_get() { PERM("cam_view");  $this->load->model('model_servers_local','servers'); $servers = $this->servers->get_records(); $cameras = array(); foreach ($servers as $server) { $cams = array(); $url = "http://".$server->server_address.":".$server->server_port."/lprapi/?c=get_cameras"; if (($json = $this->remote_get_content($url, $_POST)) !== FALSE) { if (($cams = json_decode($json)) !== NULL) { foreach ($cams as $cam) { if (strlen($cam->camera_name)==0) $cam->camera_name = " "; $cam->server = $server;  $found = false; foreach ($cameras as $test) { if ($test->camera_uuid == $cam->camera_uuid) { $found = true; break; } }  if (!$found) { array_push($cameras, $cam); } } } } } $output = array( "draw" => 0, "recordsTotal" => sizeof($cameras), "recordsFiltered" => sizeof($cameras), "data" => $cameras ); echo json_encode($output); }  public function camera_control() { $cmd = $this->input->post('cmd'); $data = $this->input->post('data'); for ($i=0; $i<sizeof($data); $i++) { $server_address = $data[$i]['server']['server_address']; $server_port = $data[$i]['server']['server_port']; $service_name = $data[$i]['service_name']; $url = "http://".$server_address.":".$server_port."/lprapi/"; if ($cmd == "start") { PERM("cam_start"); $url .= "?c=camera_start&p=".$service_name; file_get_contents($url); } if ($cmd == "stop") { PERM("cam_stop"); $url .= "?c=camera_stop&p=".$service_name; file_get_contents($url); } if ($cmd == "delete") { PERM("cam_delete"); $url .= "?c=camera_delete&p=".$service_name; file_get_contents($url); } } }  public function get_cameras_status() { $srv_cams = $this->input->post('data'); $url = 'http://' . $srv_cams['server_address'] . ':' . $srv_cams['server_port'] . '/lprapi/?c=cameras_status&p=' . implode(',', $srv_cams['service_names']); $ctx = stream_context_create(array('http'=> array( 'timeout' => 3, ) )); echo file_get_contents($url, false, $ctx); }  public function camera_add() { PERM("cam_add");  $server_id = $this->input->post('server_id'); $camera_name = $this->input->post('camera_name'); $start_type = $this->input->post('start_type');  $this->load->model('model_servers_local','servers'); $server = $this->servers->get_record($server_id); $_POST['server_port'] = $_SERVER['SERVER_PORT']; $url = "http://".$server->server_address.":".$server->server_port."/lprapi/?c=camera_add";  if (($json = $this->remote_get_content($url, $_POST)) !== FALSE) { $camera = json_decode($json); $camera->server = $server; echo json_encode($camera); } else { header("HTTP/1.1 500 "."Error adding new camera"); } }  public function camera_get_config() { $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_get_config&p=".$camera['service_name']; echo file_get_contents($url); } public function camera_set_config() { PERM("cam_config");  $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded\r\n", 'method'  => 'POST', 'content' => http_build_query($_POST) ) ); $context  = stream_context_create($options); $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_set_config"; echo file_get_contents($url, false, $context); }  public function camera_execute_action() { PERM("cam_config");  $options = array( 'http' => array( 'header'  => "Content-type: application/x-www-form-urlencoded\r\n", 'method'  => 'POST', 'content' => http_build_query($_POST) ) ); $context  = stream_context_create($options); $camera = $this->input->post('camera'); $url = "http://".$camera['server']['server_address'].":".$camera['server']['server_port']."/lprapi/?c=camera_execute_action"; echo file_get_contents($url, false, $context); } public function server_get() { PERM("srv_view");  $this->load->model('model_servers_local','servers_local'); $data = $this->servers_local->get_records(); $output = array( "draw" => isset($_POST['draw']) ? $_POST['draw'] : 0, "recordsTotal" => sizeof($data), "recordsFiltered" => sizeof($data), "data" => $data ); echo json_encode($output); }  public function server_add() { PERM("srv_add");  $server = $this->input->post('server'); $this->load->model('model_servers_local','servers_local'); $this->servers_local->add_record($server); }  public function server_delete() { PERM("srv_delete");  $this->load->model('model_servers_local','servers_local'); $this->servers_local->delete_records(); }  public function server_update() { PERM("srv_edit");  $server = $this->input->post('server'); $this->load->model('model_servers_local','servers_local'); $this->servers_local->update_record($server); }  public function server_get_info() { PERM("srv_view");  $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=server_get_info"; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."Error getting server information"); else echo $res; }  public function lic_activate() { PERM("srv_lic");  $url = 'http://www.dtksoft.com/license/activate/?lic_key='.$this->input->post('lic_key').'&system_id='.$this->input->post('system_id').'&prod=lprs&comments='.urlencode($this->input->post('comments')); $error_text = ""; file_get_contents($url); $activation_code = ""; for ($i=0; $i<sizeof($http_response_header); $i++) { if (strpos($http_response_header[$i], "ACTIVATION_CODE:")===0) $activation_code = trim(substr($http_response_header[$i], 16)); if (strpos($http_response_header[$i], "ERROR_TEXT:")===0) $error_text = trim(substr($http_response_header[$i], 11)); } if ($activation_code != "ERROR") { $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=lic_activate"; unset($_POST); $_POST['activation_code'] = $activation_code; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."License activation error"); } else { header("HTTP/1.1 500 ". $error_text); } } public function lic_activate_offline() { PERM("srv_lic");  $server = $this->input->post('server'); $url = "http://".$server['server_address'].":".$server['server_port']."/lprapi/?c=lic_activate"; $res = $this->remote_get_content($url, $_POST); if ($res === FALSE) header("HTTP/1.1 500 "."License activation error"); }  public function send_test_email() { $smtp_config = array(); $smtp_config['smtp_host'] = $this->input->post("smtp_host"); $smtp_config['smtp_port'] = $this->input->post("smtp_port"); $smtp_config['smtp_user'] = $this->input->post("smtp_user"); $smtp_config['smtp_password'] = base64_encode($this->input->post("smtp_password")); $smtp_config['smtp_encryption'] = $this->input->post("smtp_encryption");  $this->load->model('model_users','users'); $admin_users = $this->users->get_admin_users(); if (sizeof($admin_users) == 0) { echo "No users with Administrator role"; return; } $n=0; include APPPATH."/third_party/mail.php"; foreach ($admin_users as $usr) { if (strlen($usr['email']) == 0) continue; $n++; $subject = LANG2("product_name") . " - Test message"; $res = SendSmtpMail($usr['email'], $usr['full_name'], $usr['email'], $usr['full_name'], $subject, "This is the test message", "", "", $smtp_config); if (strlen($res) > 0) { $p=strpos($res, "https://github"); if ($p !== false) $res = substr($res, 0, $p); echo $res; return; } } if ($n==0) { echo "Email address not defined for Administrator" ; } }  private function LogGetSourceName($id) { if ($id == 1) return "SubmitResult"; else if ($id == 2) return "RulesProcessing"; else if ($id == 3) return "Retention"; else return "Unknown"; } private function LogGetLevelName($id) { if ($id == 1) return "Information"; else if ($id == 2) return "Warning"; else if ($id == 3) return "Error"; else return "Unknown"; } public function cron() { $this->load->model('model_config','cfg'); $this->load->model('model_users','users'); $this->load->model('model_log','logs'); $log_items = $this->logs->get_records_not_email_sent(); if (sizeof($log_items) == 0) return;  $smtp_config = array(); $smtp_config['smtp_host'] = $this->cfg->get("smtp_host"); $smtp_config['smtp_port'] = $this->cfg->get("smtp_port"); $smtp_config['smtp_user'] = $this->cfg->get("smtp_user"); $smtp_config['smtp_password'] = $this->cfg->get("smtp_password"); $smtp_config['smtp_encryption'] = $this->cfg->get("smtp_encryption"); if (strlen($smtp_config['smtp_host']) == 0) return;  $admin_users = $this->users->get_admin_users(); if (sizeof($admin_users) == 0) return;  $subject = LANG2("product_name") . " - Event log"; $message = ""; foreach ($log_items as $log_item) { if (strlen($message) > 0) $message .= "\r\n"; $message .= $log_item->dt . "\t" . $this->LogGetSourceName($log_item->source) . "\t" . $this->LogGetLevelName($log_item->level) . "\t" . $log_item->message; } $ok = true; include APPPATH."/third_party/mail.php"; foreach ($admin_users as $usr) { if (strlen($usr['email']) == 0) continue; $res = SendSmtpMail($usr['email'], $usr['full_name'], $usr['email'], $usr['full_name'], $subject, $message, "", "", $smtp_config); if (strlen($res) > 0) { $p=strpos($res, "https://github"); if ($p !== false) $res = substr($res, 0, $p); $ok = false; break; } } if ($ok) { foreach ($log_items as $log_item) $this->logs->set_email_sent($log_item->id); } }  function send_email() { ob_end_clean(); ignore_user_abort(true); ob_start(); header("Connection: close"); header("Content-Length: " . ob_get_length()); ob_end_flush(); flush(); $email_list = $this->input->post("email_list"); $subject = $this->input->post("subject"); $img_attach = $this->input->post("img"); $id = $this->input->post("id"); $emails = explode(chr(1), str_replace([',', ';'], chr(1), $email_list)); if (sizeof($emails) == 0) return;  $this->load->model('model_config','cfg'); $this->load->model('model_users','users'); $this->load->model('model_log','logs'); $this->load->model('model_plates','plates');  $smtp_config = array(); $smtp_config['smtp_host'] = $this->cfg->get("smtp_host"); $smtp_config['smtp_port'] = $this->cfg->get("smtp_port"); $smtp_config['smtp_user'] = $this->cfg->get("smtp_user"); $smtp_config['smtp_password'] = $this->cfg->get("smtp_password"); $smtp_config['smtp_encryption'] = $this->cfg->get("smtp_encryption"); if (strlen($smtp_config['smtp_host']) == 0) return;  $rec = $this->plates->find($id); if ($rec == null) return;  $subject = str_replace("%DATETIME%", $rec->dt, $subject); $subject = str_replace("%COUNTRY%", $rec->country, $subject); $subject = str_replace("%PLATE_NUM%", $rec->text_fmt, $subject); $subject = str_replace("%NUMBER%", $rec->text_fmt, $subject); $subject = str_replace("%DIRECTION%", $rec->direction, $subject); $subject = str_replace("%CONFIDENCE%", $rec->confidence, $subject); $subject = str_replace("%ZONE%", $rec->zone, $subject);  include APPPATH."/third_party/mail.php"; foreach ($emails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $user = $this->users->find_by_name($email); if ($user == null || strlen($user->email)==0) return; $email = $user->email; } $message = " "; $file = ""; if ($img_attach == "Y") { $file = LPRDB_PATH. $rec->image_path . '/' . sprintf("%09d.jpg",$id); if (!file_exists($file)) $file = ""; } $res = SendSmtpMail($email, "", $email, "", $subject, $message, $file, basename($file), $smtp_config); }  } } 

Function Calls

None

Variables

None

Stats

MD5 a9fc9fa4cf09b2ba748f78cac5388e9a
Eval Count 0
Decode Time 190 ms