<?php 
$ip=$_GET["ip"];
	$target_url = "http://$ip/cgi-bin/upgrade_handle";
        //This needs to be the full path to the file you want to send.
	$file_name_with_full_path = realpath('bittel_vn.tar');
        /* curl will accept an array here too.
         * Many examples I found showed a url-encoded string instead.
         * Take note that the 'key' in the array will be the key that shows up in the
         * $_FILES array of the accept script. and the at sign '@' is required before the
         * file name.
         */
	$post = array('upgrade_start' => '   Start Upgrade   ','upgrade_file'=>'@'.$file_name_with_full_path);
 
        $ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,$target_url);
	curl_setopt($ch, CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	$result=curl_exec ($ch);
	curl_close ($ch);
	//echo $result;
	

		$url = "http://$ip/cgi-bin/config_handle";
$fields = array(
	'admin_pin' => 'sapoop23',
					'update' => '   OK   ',
					'ip_type' => '1',
					'ip' => '192.168.20.223',
					'subnet_mask' => '255.255.255.0',
					'router_ip' => '192.168.20.1',
					'dns_type' => '1',
					'dns_ip' => '192.168.20.1',
					'dns_ip2' => '192.168.20.1',
					'voice_vid' => '0',
					'data_vid' => '0',
					'admin_ip' => '0.0.0.0',
					'reset' => '  Cancel  '
);
$fields_string="";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);
echo("Terminado");
?>