<?php
/* $Id$ */
/*
	v_profiles.php
	Copyright (C) 2008 Mark J Crane
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

require("guiconfig.inc");
require("/usr/local/pkg/v_config.inc");

//$a_extensions 	   = &$config['installedpackages']['freeswitchextensions']['config'];


if ($_GET['a'] == "default") {
	conf_mount_rw();
	exec("cp ".$v_conf_dir.".orig/sip_profiles/".$_GET['f']." ".$v_conf_dir."/sip_profiles/".$_GET['f']);
	$savemsg = "Restore Default";
	conf_mount_ro();
}

if ($_POST['a'] == "save") {
	conf_mount_rw();
	$content = ereg_replace("\r","",$_POST['code']);
	$fd = fopen($v_conf_dir."/sip_profiles/".$_POST['f'], "w");
	fwrite($fd, $content);
	fclose($fd);
	$savemsg = "Saved";
	conf_mount_ro();
}

	
if ($_GET['a'] == "del") {
    if ($_GET['type'] == 'profile') {
        //if ($a_profiles[$_GET['id']]) {
            //unset($a_extensions[$_GET['id']]);
            //write_config();

			exec("rm ".$v_conf_dir."/sip_profiles/".$_GET['f']);			
            header("Location: v_profiles.php");
            exit;
        //}
    }
}

include("head.inc");

?>


<body link="#0000CC" vlink="#0000CC" alink="#0000CC">


<?php
include("fbegin.inc");
if ($v_label_show) {
	echo "<p class=\"pgtitle\">$v_label: Profiles</p>\n";
}
?>

<div id="mainlevel">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="tabnavtbl">
<?php
			
build_menu();
 	
?>
</td></tr>
</table>

	
<table width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr>
     <td class="tabcont" >

<form action="v_profiles.php" method="post" name="iform" id="iform">
  	<table width="100%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td><p><span class="vexpl"><span class="red"><strong>Profiles<br>
            </strong></span>
            Use this to configure your SIP profiles.
            </p></td>
      </tr>
    </table>
    <br />

		
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="25%" class="listhdrr">Name</td>
      <td width="70%" class="listhdr">Description</td>
      <td width="5%" class="list">
      </td>
	</tr>


	<?php

	foreach (ListFiles($v_conf_dir.'/sip_profiles') as $key=>$file){
    ?>
          <tr>
            <td class="listr" ondblclick="document.location='v_profile_edit.php?f=<?=$file;?>';" valign="middle">
              <?=$file;?>&nbsp;
            </td>
            <td class="listbg" ondblclick="document.location='v_profile_edit.php?f=<?=$file;?>';">
			<?php
			              
				switch ($file) {
				case "internal.xml":
					echo "<font color='#FFFFFF'>";
					echo "The Internal profile by default requires registration which is most often used for extensions. ";
					echo "By default the Internal profile binds to the WAN IP which is accessible to the internal network. ";
					echo "A rule can be set from PFSense -> Firewall -> Rules -> WAN to the the WAN IP for port 5060 which ";
					echo "enables phones register from outside the network.";
					echo "";
					echo "</font>";
					echo "&nbsp;";
					break; 
				case "internal-ipv6.xml":
					echo "<font color='#FFFFFF'>The Internal IPV6 profile binds to the IP version 6 address and is similar to the Internal profile.</font>&nbsp;";
					break;	
				case "external.xml":
					echo "<font color='#FFFFFF'>";
					echo "The External profile handles outbound registrations to a SIP provider or other SIP Server. The SIP provider sends calls to you, and you ";
					echo "send calls to your provider, through the external profile. The external profile allows anonymous calling, which is ";
					echo "required as your provider will never authenticate with you to send you a call. Calls can be sent using a SIP URL \"my.domain.com:5080\" ";
					echo "</font>&nbsp;";
					break;
				case "lan.xml":
					echo "<font color='#FFFFFF'>The LAN profile is the same as the Internal profile except that it is bound to the LAN IP.</font>&nbsp;";
					break;				
				default:
					echo "<font color='#FFFFFF'>default</font>&nbsp;";
				}
			?>
            </td>
            <td valign="middle" nowrap class="list" valign="top">
              <table border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td valign="middle"><a href="v_profile_edit.php?type=profile&f=<?=$file;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
                  <td><a href="v_profiles.php?type=profile&a=del&f=<?=$file;?>" onclick="return confirm('Do you really want to delete this?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
				</tr>
             </table>
            </td>
          </tr>
	<?php
        $i++;
    }
     
    ?>

    <tr>
      <td class="list" colspan="4"></td>
      <td class="list">
        <table border="0" cellspacing="0" cellpadding="1">
          <tr>
            <td width="17"></td>
            <td valign="middle"></td>
          </tr>
        </table>
		  </td>
     </tr>


     <tr>
       <td class="list" colspan="4"></td>
       <td class="list"></td>
     </tr>
     </table>

</form>

<br>
<br>
<?php
if ($v_path_show) {
	echo $v_conf_dir."/sip_profiles\n";
}
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

</td>
</tr>
</table>

</div>



<?php include("fend.inc"); ?>
</body>
</html>