<?php
# Example User-Agent: snomM300 03.24.0018 000413623542
$agent = $_SERVER['HTTP_USER_AGENT'];

if (!preg_match("/(snomM[0-9]00) ([0-9.]+) ([0-9A-F]{12})/", $agent, $matches)) {
?>
<html>
<head><Title>Snom M700/M300: auto update from 324BXX to 400B2</Title></head>
<body>
	<h1>Snom M700/M300: auto update script from version 324BXX to 400B2</h1>

	<h3>Info:</h3>
    <p>Updating a DECT base from version 324Bxx to version 400BXX requires an intermediate update to the version 355B25.</p>
    <p>This script provides an automatic / hands-free update from version 324BXX to 400B2 checking the device User-Agent.</p>

	<h3>Important Note:</h3>
	<p>As soon you devices are updated to the version 400B2 you must stop using this script on your devices.</p>
	<p><font color="red"><b>Snom deserves the right to remove/disable this script at any moment</b></font></p>

	<h3>Usage:</h3>
	<ul>
		<li>Logon on the web interface</li>
		<li>Click on the <b>Management</b> link</li>
		<li>Enter into the <b>Configuration server address</b> field the URL <b>http://dect.snom.com/324-to-400/</b></li>
		<li>Enter into the <b>Filename</b> field the name <b>auto-update.php</b></li>
		<li>Click the <b>Save & Reboot</b> button</li>
		<li>Now the base will start the update process, this will take up to 8-10 minutes. The LED will start flashing.</li>
		<li><font color="red"><b>Never unplug/poweroff the device in this phase.</b> You can consider the update phase when the LED remains green for 3 minutes.</font></li>
		<li>Once the update is terminated you can check the device firmware version on the Home page</li>
	</ul>
	<img src="./M300_324_management.png"/>
	<p>You can download this PHP script <a href="http://dect.snom.com/324-to-400/auto-update.php.txt">here</a></p>
</body>
</html>
<?php
	die();
}

$phone_type = $matches[1];
$softwareVersion = $matches[2];
$softwareVersionParts = explode('.', $softwareVersion);
$major = $softwareVersionParts[0];
$minor = $softwareVersionParts[1];
$branch = $softwareVersionParts[2];
$mac = $matches[3];

header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>';
if($major == "03"){
	if($minor == "24"){
# Base is on version 324 send the update to 355B25
?>
<firmware-settings>
  <firmware>http://dect.snom.com/B355B25H355B25</firmware>
  <fp_fwu_sw_version>355</fp_fwu_sw_version>
  <fp_fwu_branch_version>25</fp_fwu_branch_version>
  <pp_fwu_sw_version type="M25">355</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M65">355</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M85">355</pp_fwu_sw_version>
  <pp_fwu_branch_version type="M25">25</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M65">25</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M85">25</pp_fwu_branch_version>
</firmware-settings>
<?php
	}elseif($minor == "55" or $minor == "80"){
# Base is on version 355 or 380, send the update to 400
?>
<firmware-settings>
  <firmware>http://dect.snom.com/</firmware>
  <fp_fwu_sw_version>400</fp_fwu_sw_version>
  <fp_fwu_branch_version>02</fp_fwu_branch_version>
  <pp_fwu_sw_version type="M25">400</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M65">400</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M85">400</pp_fwu_sw_version>
  <pp_fwu_branch_version type="M25">02</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M65">02</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M85">02</pp_fwu_branch_version>
</firmware-settings>
<?php
	}
}elseif($major == "04"){
# Already on version 400, do nothing
?>
<firmware-settings>
  <firmware>http://80.133.119.178/</firmware>
  <fp_fwu_sw_version>530</fp_fwu_sw_version>
  <fp_fwu_branch_version>10</fp_fwu_branch_version>
  <pp_fwu_sw_version type="M25">530</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M65">530</pp_fwu_sw_version>
  <pp_fwu_sw_version type="M85">530</pp_fwu_sw_version>
  <pp_fwu_branch_version type="M25">10</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M65">10</pp_fwu_branch_version>
  <pp_fwu_branch_version type="M85">10</pp_fwu_branch_version>
</firmware-settings>
<?php
}
?>
