[PHP]NOD32 AMC - automatic mirror creater
Hi 2 all :) .Yesterday i browsed the Internet and founded a Perl script to create a local update mirror for NOD32.But i don't like him so i rewrote it in PHP :] .
Anybody can use it. One problem - i didn't implemented an update from official servers yet, but it will be soon .
PHP Code:
<?php
/**
* @name NOD32 AMC - automatic mirror creater
* @version 1.1
* @author CodexFactory(www.91th.org)
* @uses PHP5
* @uses sockets
*/
set_time_limit(0); //For dummies .
class nod32upd
{
/**
* This class creates a local mirror of NOD32 update files .
* Official servers not supported at this time .
* Variables to edit :
*
* @var string $server Remote server
* @var string $save_path Local path for new files
* @var string $handler Don't touch !
* @var array $updfiles Similarly .
*/
public $server = 'w00t, bad link :D';
public $save_path = '/webprojects/localhost.lan/public_html/nod32upd/';
private $handler = '';
private $updfiles = array();
#private $login = ''; //Will be implemented soon
#private $password = ''; //Will be implemented soon
/**
* Constructor
*/
public function nod32upd()
{
//Constructor
$this->checkUPDFiles();
}
/**
* Parses update.ver and inserts data into the object array
* @param none
* @return null
*/
public function getNparse()
{
$this->handler = file_get_contents($this->server . 'update.ver');
preg_match_all("/file\=(.*)\n/",$this->handler,$file_parse);
$file_parse = array_pop($file_parse);
foreach($file_parse as $k => $v)
{
$this->updfiles[] = trim($v);
}
}
/**
* Checks whether new update exists and downloads it .
* By the way, removes old update files .
* @param none
* @return null
*/
public function checkUPDFiles()
{
if(count($this->updfiles == 1))
{
$this->getNparse();
}
if(file_exists($this->save_path . 'update.ver'))
{
if(crc32($this->handler) != crc32(file_get_contents($this->save_path . 'update.ver')))
{
@unlink($this->save_path . 'update.ver');
$fd = opendir('.');
while($file = readdir($fd))
{
if(preg_match("/.+?\.nup/",$file))
{
@unlink($file);
}
}
@file_put_contents($this->save_path . 'update.ver',$this->handler);
$this->getFiles();
}
else
{
print('All right.');
}
}
else
{
@file_put_contents($this->save_path . 'update.ver',$this->handler);
$this->getFiles();
}
}
/**
* Alias for saveContent()
* @see saveContent
* @param none
* @return null
*/
public function getFiles()
{
foreach ($this->updfiles as $k => $v)
{
$this->saveContent($this->server . $v,$this->save_path . $v);
}
}
/**
* Gets data from remote file and writes it to new file incrementally
* @param string $host Remote host
* @param string $path Remote file
* @return bool true|false
*/
public function saveContent($path,$destination)
{
$fh = fopen($path,'r');
$fw = fopen($destination,'w+');
if(!$fh)
{
die('Cannot open remote file - 404/403 error or wrong URL');
}
while($fr = fread($fh,8012))
{
fwrite($fw,$fr);
}
print($path . "successfully downloaded .");
unset($fr);
fclose($fh);
fclose($fw);
return true;
}
}
/**
* Creates an object .
*/
$do = new nod32upd();
?>
Re: [PHP]NOD32 AMC - automatic mirror creater
Nice job :), this will automatically update NOD32, or what?
Re: [PHP]NOD32 AMC - automatic mirror creater
Quote:
Originally Posted by
Daevius
Nice job :), this will automatically update NOD32, or what?
No, its creates a mirror for NOD32 .
For example, you updates your NOD32 from remote server .
But you have difficulties with speed/bandwidth etc. You runs this script on other server(in your local network,for example) and updates NOD32 from it :] .
Re: [PHP]NOD32 AMC - automatic mirror creater
Ah nice, but shouldn't it be better if it was an executable? I mean, now the user needs to install a webserver etc to run the script ;). Nice job though :), as some really nasty software can block the internet for NOD32 so it doesn't get updated.
Re: [PHP]NOD32 AMC - automatic mirror creater
I can use php2exe to make it executable, but then server will be static :[
Otherwise, why i need to make it executable ? If you have your own host you can run it under crontab and update your NOD32 from it without any problems :]
Re: [PHP]NOD32 AMC - automatic mirror creater
sounds cool. but i have no need and you may want to remove your sig as warez links are prohibited.