Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $file_name = 'SPBE50-WS10005.txt';
- $file_name = 'SPBHDQ-WS31003.txt';
- $path = '/media/audit/info/';
- $mysql_host = "localhost";
- $mysql_pass = "0SCJyxT1fl";
- $mysql_user = "parser";
- $mysql_base = "parser";
- $link = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
- if(!$link){
- echo "Не могу подключиться к серверу MySQL\r\n"; die();
- }
- if(!mysql_select_db($mysql_base, $link)){
- echo "Не могу подключиться к базе данных\r\n"; die();
- }
- $computer_name = pathinfo($file_name, PATHINFO_FILENAME);
- $mac = null;
- $name = null;
- $cpu_z_version = null;
- $res = mysql_query("SELECT `mac` FROM `event` WHERE `comp_name`='{$computer_name}' ORDER BY `date` DESC LIMIT 1");
- if(mysql_num_rows($res) == 1){
- $row = mysql_fetch_assoc($res);
- $mac = $row['mac'];
- } else {
- die("Computer not found! Exit.");
- }
- $content = file_get_contents($path . $file_name);
- $content = iconv('windows-1251', 'utf-8', $content);
- if(preg_match('/CPU-Z\sversion\t\t\t(.*)/u', $content, $match)){
- $cpu_z_version = isset($match[1]) ? trim($match[1]) : null;
- }
- if(preg_match('/\tName\t\t\t(.*)/u', $content, $match1)){
- $processor_name = isset($match1[1]) ? trim($match1[1]) : null;
- }
- $res = mysql_query("INSERT INTO `info` (`mac`,`computer`,`name`,`cpu_z_version`) VALUES ('{$mac}','{$computer_name}','{$processor_name}','{$cpu_z_version}') ON DUPLICATE KEY UPDATE `computer`='{$computer_name}', `name`='{$processor_name}', `cpu_z_version`='{$cpu_z_version}'");
- if(!$res){
- echo mysql_error();
- }
- echo "NAME: {$processor_name}\n";
- echo "CPU-Z VERSION: {$cpu_z_version}\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement