<?php
if(!isset($msg)){
if (isset($_POST['readchilliconfig']) ){
if ( isset($_POST['conf_file']) && $_POST['conf_file']!='') {
$opt['conf_file']=$_POST['conf_file'];
$opt['bin_file']=$_POST['bin_file'];
if (file_exists($_POST['conf_file'])) {
$array_tmp = file($_POST['conf_file']);
foreach($array_tmp as $v)
{
if ((substr(trim($v),0,1)!='#') && (substr_count($v,' ')>=0))
{//La ligne ne doit pas commencer par un ';' et doit contenir au moins un signe '='.
$pos = strpos($v, ' ');
if ($pos==0) $pos=strlen($v);
if (trim(substr($v,0,$pos))=="net")
$opt['network'] = trim(substr($v, $pos+1));
else {
if (trim(substr($v,0,$pos))=="coanoipcheck")
$opt['coanoipcheck'] = 1;
else
if (trim(substr($v,0,$pos))=="uamanydns")
$opt['uamanydns'] = 1;
else
if (trim(substr($v,0,$pos))=="macauth")
$opt['macauth'] = 1;
else
$opt[trim(substr($v,0,$pos))] = trim(substr($v, $pos+1));
}
}
}
unset($array_tmp);
echo "Successfull read configuration file";
}else
echo "Unable to read configuration file";
}
else
echo "You must enter a configuration file name";
}
if (isset($_POST['savechilliconfigfile']) ){
$myFile = $_POST['conf_file'];
$fh = fopen($myFile, 'w');
if ($_POST['debug']!='' ) fwrite($fh, "debug\n");
if ($_POST['ipdown_script']!='') fwrite($fh, "ipdown ".$_POST['ipdown_script']."\n");
if ($_POST['ipup_script']!='') fwrite($fh, "ipup ".$_POST['ipup_script']."\n");
if ($_POST['conup_script']!='') fwrite($fh, "conup ".$_POST['conup_script']."\n");
if ($_POST['condow_script']!='') fwrite($fh, "condown ".$_POST['condown_script']."\n");
if ($_POST['network']!='') fwrite($fh, "network ".$_POST['network']."\n");
if ($_POST['dynip']!='') fwrite($fh, "dynip ".$_POST['dynip']."\n");
if ($_POST['statip']!='') fwrite($fh, "statip ".$_POST['statip']."\n");
if ($_POST['dns1']!='') fwrite($fh, "dns1 ".$_POST['dns1']."\n");
if ($_POST['dns2']!='') fwrite($fh, "dns2 ".$_POST['dns2']."\n");
if ($_POST['domain']!='') fwrite($fh, "domain ".$_POST['domain']."\n");
if ($_POST['coaport']!='') fwrite($fh, "coaport ".$_POST['coaport']."\n");
if ($_POST['coanoipcheck']=='1') fwrite($fh, "coanoipcheck\n");
if ($_POST['dhcpif']!='') fwrite($fh, "dhcpif ".$_POST['dhcpif']."\n");
if ($_POST['radiuslisten']!='') fwrite($fh, "radiuslisten ".$_POST['radiuslisten']."\n");
if ($_POST['radiusserver1']!='') fwrite($fh, "radiusserver1 ".$_POST['radiusserver1']."\n");
if ($_POST['radiusserver2']!='') fwrite($fh, "radiusserve2 ".$_POST['radiusserver2']."\n");
if ($_POST['radiusauthport']!='') fwrite($fh, "radiusauthport ".$_POST['radiusauthport']."\n");
if ($_POST['radiusacctport']!='') fwrite($fh, "radiusacctport ".$_POST['radiusacctport']."\n");
if ($_POST['radiussecret']!='') fwrite($fh, "radiussecret ".$_POST['radiussecret']."\n");
if ($_POST['radiusnasid']!='') fwrite($fh, "radiusnasid ".$_POST['radiusnasid']."\n");
if ($_POST['radiuscalled']!='') fwrite($fh, "radiuscalled ".$_POST['radiuscalled']."\n");
if ($_POST['uamserver']!='') fwrite($fh, "uamserver ".$_POST['uamserver']."\n");
if ($_POST['uamhomepage']!='') fwrite($fh, "uamhomepage ".$_POST['uamhomepage']."\n");
if ($_POST['uamsecret']!='') fwrite($fh, "uamsecret ".$_POST['uamsecret']."\n");
if ($_POST['uamanydns']=='1' ) fwrite($fh, "uamanydns\n");
if ($_POST['uamallowed']!='' ) fwrite($fh, "uamallowed $opt->uamallowed\n");
if ($_POST['macauth']=='1' ) fwrite($fh, "macauth macauth\n");
if ($_POST['macallowed']!='' ) fwrite($fh, "macallowed $opt->macallowed\n");
if ($_POST['macpasswd']!='' ) fwrite($fh, "macpasswd $opt->macpasswd\n");
if ($_POST['macsuffix']!='' ) fwrite($fh, "macsuffix $opt->macsuffix\n");
$opt=$oreon->database->getchilliconfiguration($_SESSION['locID']);
fclose($fh);
copy_file($myFile,"",$_POST['conf_file'],$_SESSION['locID']);
}
if (isset($_POST['restartchilli']) ) {
if (file_exists("/var/run/chilli.pid")) {
if (file_exists('/etc/init.d/chilli')) {
shell_exec("/etc/init.d/chilli restart");
}
else
{
shell_exec("killall chilli");
shell_exec($_POST['bin_file']);
}
}
else
if (file_exists('/etc/init.d/chilli')) {
shell_exec("/etc/init.d/chilli restart");
}
else {
shell_exec($_POST['bin_file']);
}
$opt=$oreon->database->getchilliconfiguration($_SESSION['locID']);
}
if (isset($_POST['savechilliconfig']) ){
//GENERAL
$opt->conf_file=$_POST['conf_file'];
$opt->bin_file=$_POST['bin_file'];
$opt->ipup_script=$_POST['ipup_script'];
$opt->ipdown_script=$_POST['ipdown_script'];
$opt->conup_script=$_POST['conup_script'];
$opt->condown_script=$_POST['condown_script'];
$opt->network=$_POST['network'];
$opt->dynip=$_POST['dynip'];
$opt->statip=$_POST['statip'];
$opt->dns1=$_POST['dns1'];
$opt->dns2=$_POST['dns2'];
$opt->domain=$_POST['domain'];
$opt->coaport=$_POST['coaport'];
$opt->coanoipcheck=$_POST['coanoipcheck'];
$opt->dhcpif=$_POST['dhcpif'];
$opt->radiuslisten=$_POST['radiuslisten'];
$opt->radiusserver1=$_POST['radiusserver1'];
$opt->radiusserver2=$_POST['radiusserver2'];
$opt->radiusauthport=$_POST['radiusauthport'];
$opt->radiusacctport=$_POST['radiusacctport'];
$opt->radiussecret=$_POST['radiussecret'];
$opt->radiusnasid=$_POST['radiusnasid'];
$opt->radiuscalled=$_POST['radiuscalled'];
$opt->uamserver=$_POST['uamserver'];
$opt->uamhomepage=$_POST['uamhomepage'];
$opt->uamsecret=$_POST['uamsecret'];
$opt->uamanydns=$_POST['uamanydns'];
$opt->uamallowed=$_POST['uamallowed'];
$opt->macauth=$_POST['macauth'];
$opt->macallowed=$_POST['macallowed'];
$opt->macpasswd=$_POST['macpasswd'];
$opt->macsuffix=$_POST['macsuffix'];
$opt->debug=$_POST['debug'];
$opt->location_id=$_SESSION['locID'];
$oreon->database->savechilliconfiguration($opt);
$opt=$oreon->database->getchilliconfiguration($_SESSION['locID']);
echo "Configuration have been saved";
}
if (isset($_POST['load_default']))
{
$lid=-1;
unset($_POST['load_default']);
}
else
$lid=$_SESSION['locID'];
if ($opt=='')
$opt=$oreon->database->getchilliconfiguration($lid);
echo "
<form action=\"phpmyprepaid.php\" method=\"post\">
<hr>
<big><big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Chillispot configuration</span></b></big></big><br>
<hr>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Divers configuration</span></b></big><br>
<table>
<br>
<td>Configuration File : </td>
<td><input name=\"conf_file\" value=\"".$opt['conf_file']."\"></td><td>
<input name=\"readchilliconfig\" type=\"submit\" class=\"smallButton\" value=\"Read Configuration\" ></td><td>
<input name=\"savechilliconfigfile\" type=\"submit\" class=\"smallButton\" value=\"Save config file\" >
</td></tr><tr>
<td>Binary file : </td>
<td><input name=\"bin_file\" value=\"".$opt['bin_file']."\"></td>
</td><td>
<input name=\"restartchilli\" type=\"submit\" class=\"smallButton\" value=\"Restart Chilli\" >
</td></tr>
</tr><tr>
<td>Ip up script : </td>
<td><input name=\"ipup_script\" value=\"".$opt['ipup_script']."\"></td>
</tr><tr>
<td>Ip down script : </td>
<td><input name=\"ipdown_script\" value=\"".$opt['ipdown_script']."\"></td>
</tr><tr>
<td>Connection up script : </td>
<td><input name=\"conup_script\" value=\"".$opt['conup_script']."\"></td>
</tr><tr>
<td>Connection down script : </td>
<td><input name=\"condown_script\" value=\"".$opt['condown_script']."\"></td>
</tr>
</table>
<hr>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Network configuration</span></b></big><br>
<table>
<td>Network : </td>
<td><input name=\"network\" value=\"".$opt['network']."\"></td>
</tr><tr>
<td>Dynamic ip : </td>
<td><input name=\"dynip\" value=\"".$opt['dynip']."\"></td>
</tr><tr>
<td>Static ip : </td>
<td><input name=\"statip\" value=\"".$opt['statip']."\"></td>
</tr><tr>
<td>Primary DNS server : </td>
<td><input name=\"dns1\" value=\"".$opt['dns1']."\"></td>
</tr><tr>
<td>Secondary DNS server : </td>
<td><input name=\"dns2\" value=\"".$opt['dns2']."\"></td>
</tr><tr>
<td>Domain : </td>";
if ($opt['domain']!='')
echo "<td><input name=\"domain\" value=\"".$opt['domain']."\"></td>";
else
{
$opt['domain']=getLocDomain($_SESSION['locID']);
echo "<td><input name=\"domain\" value=\"".$opt['domain']."\"></td>";
}
echo "</tr><tr>
<td>Coaport : </td>
<td><input name=\"coaport\" value=\"".$opt['coaport']."\"></td>
</tr><tr>
<td>Coanoipcheck : </td>";
if ($opt['coanoipcheck'])
echo "<td><INPUT type=\"checkbox\" checked name=\"coanoipcheck\" value=\"1\" alt=\"Coanoipcheck\"></td>";
else
echo "<td><INPUT type=\"checkbox\" name=\"coanoipcheck\" value=\"1\" alt=\"Coanoipcheck\"></td>";
echo "</tr><tr>
<td><b>Dhcp interface : </td><td>";
echo ('<select name="dhcpif">'),
("<option value=\"\">");
$tab=split(',',$interfacelist);
foreach($tab as $val)
if ($val==$opt['dhcpif'])
echo ("<option selected=\"selected\" value=\"$val\">$val");
else
echo ("<option value=\"$val\">$val");
echo ('</select>');
echo "</td>
</tr>
</table>
<hr>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Radius configuration</span></b></big><br>
<table>
<td>Radius listen : </td>
<td><input name=\"radiuslisten\" value=\"".$opt['radiuslisten']."\"></td>
</tr><tr>
<td>Radius server 1 : </td>
<td><input name=\"radiusserver1\" value=\"".$opt['radiusserver1']."\"></td>
</tr><tr>
<td>Radius server 2 : </td>
<td><input name=\"radiusserver2\" value=\"".$opt['radiusserver2']."\"></td>
</tr><tr>
<td>Radius authorisation port : </td>
<td><input name=\"radiusauthport\" value=\"".$opt['radiusauthport']."\"></td>
</tr><tr>
<td>Radius accounting port : </td>
<td><input name=\"radiusacctport\" value=\"".$opt['radiusacctport']."\"></td>
</tr><tr>
<td>Radius secret : </td>
<td><input name=\"radiussecret\" value=\"".$opt['radiussecret']."\"></td>
</tr><tr>
<td>Radius nas id : </td>
<td><input name=\"radiusnasid\" value=\"".$opt['radiusnasid']."\"></td>
</tr><tr>
<td>Radius called : </td>
<td><input name=\"radiuscalled\" value=\"".$opt['radiuscalled']."\"></td>
</tr><table>
<hr>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Uam configuration</span></b></big><br>
<table>
<td>Uam server : </td>
<td><input name=\"uamserver\" value=\"".$opt['uamserver']."\"></td>
</tr><tr>
<td>Uam homepage : </td>
<td><input name=\"uamhomepage\" value=\"".$opt['uamhomepage']."\"></td>
</tr><tr>
<td>Uam secret : </td>
<td><input name=\"uamsecret\" value=\"".$opt['uamsecret']."\"></td>
</tr><tr>
<td>Uam Allowed : </td>
<td><input name=\"uamallowed\" value=\"".$opt['uamallowed']."\"></td>
</tr><tr>
<td>Uam dynamic dns : </td>";
if ($opt['uamanydns'])
echo "<td><INPUT type=\"checkbox\" checked name=\"uamanydns\" value=\"1\" alt=\"Uam any dns\"></td>";
else
echo "<td><INPUT type=\"checkbox\" name=\"uamanydns\" value=\"1\" alt=\"Uam any dns\"></td>";
echo "</tr></table>";
echo "<hr>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Mac authentification</span></b></big><br>
<table>
<td>Mac auth : </td>";
if ($opt['macauth'])
echo "<td><INPUT type=\"checkbox\" checked name=\"macauth\" value=\"1\" alt=\"Mac auth\"></td>";
else
echo "<td><INPUT type=\"checkbox\" name=\"macauth\" value=\"1\" alt=\"Mac auth\"></td>";
echo "</tr><tr>
<td>Mac suffix : </td>
<td><input name=\"macsuffix\" value=\"".$opt['macsuffix']."\"></td>
</tr><tr>
<td>Mac password : </td>
<td><input name=\"macpasswd\" value=\"".$opt['macpasswd']."\"></td>
</tr><tr>
<td>Mac Allowed : </td>
<td><input name=\"macallowed\" style=\"width=\"200px\";\" value=\"".$opt['macallowed']."\"></td>
</tr>";
echo "<hr><table>
<tr>
<td>
<input name=\"savechilliconfig\" type=\"submit\" class=\"smallButton\" value=\"Save Configuration\" >
</form>
</td><td>
<form action=\"phpmyprepaid.php\" method=\"post\">
<input type=\"hidden\" name=\"buttonID\" value=\"chilli_config\">
<input type=\"hidden\" name=\"load_default\" value=\"chilli_config\">
<input name=\"submit\" type=\"submit\" class=\"smallButton\" value=\"Get default configuration\" >
</form>
</td></tr>
</table>
";
}
else echo $msg;