Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $remote_ip=$_SERVER['REMOTE_ADDR'];
- /*****************************************************************/
- if(!defined("CONF_FILE"))
- define("CONF_FILE", "/usr/local/etc/alcasar.conf");
- /****************************************************************
- * * FILE reading test *
- * ****************************************************************/
- $conf_files=array(CONF_FILE);
- foreach ($conf_files as $file){
- if (!file_exists($file))
- exit("Fichier ".$file." introuvable");
- if (!is_readable($file))
- exit("Accès impossible à: ".$file);
- }
- /****************************************************************
- * * Read CONF_FILE *
- * *****************************************************************/
- $ouvre=fopen(CONF_FILE,"r");
- if ($ouvre){
- while (!feof ($ouvre)){
- $tampon = fgets($ouvre, 4096);
- if (strpos($tampon,"=")!==false){
- $tmp = explode("=",$tampon);
- $conf[$tmp[0]] = $tmp[1];
- }
- }
- }
- else{
- exit("Fichier inaccessible: ".CONF_FILE);
- }
- fclose($ouvre);
- $organisme = trim($conf["ORGANISM"]);
- $domainname = trim($conf["DOMAIN"]);
- $hostname = trim($conf['HOSTNAME']).".{$domainname}";
- $tabs=Array();
- exec("sudo /usr/sbin/chilli_query list", $tabs);
- // DHCP_TABLE is activity detected from Ethernet received trame and don't use DHCP
- foreach($tabs as $k => $v){
- $r=explode(' ', $v);
- $dhcp_table['mac'][]=$r[0];
- $dhcp_table['ip'][]=$r[1];
- $dhcp_table['is_connected'][]=$r[4];
- }
- if(isset($_SERVER['HTTP_HOST'])){
- if(
- ($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_ADDR'])
- || (preg_match("/^127.0.0.1$/", $_SERVER['HTTP_HOST'])
- ) || (preg_match ("/^$hostname$/", $_SERVER['HTTP_HOST'])) || (preg_match ("/^$organisme$/", $_SERVER['HTTP_HOST']))){
- $direct_access=True;
- exec("sudo /usr/sbin/ipset del not_auth_yet $remote_ip");
- }
- }
- if(!in_array($remote_ip, $dhcp_table['ip'])){
- echo 'Vous avez forcé les réglages de votre équipement, merci d\'activer le DHCP';
- }
- else{
- $match_key=array_search($remote_ip, $dhcp_table['ip']);
- $LIBpath = "./acc/manager/lib/";
- require('/etc/freeradius-web/config.php');
- if (is_file($LIBpath."sql/drivers/{$config['sql_type']}/functions.php")){
- include_once($LIBpath."sql/drivers/{$config['sql_type']}/functions.php");
- }
- else{
- echo "Impossible de poursuivre [ERR BDD LIB]\n";
- exit();
- }
- include_once($LIBpath.'functions.php');
- if ($config['sql_use_operators'] == 'true'){
- include_once($LIBpath."operators.php");
- $text = ',op';
- $passwd_op = ",':='";
- }
- $link = @da_sql_pconnect($config);
- }
- if(is_file($LIBpath."crypt/{$config['general_encryption_method']}.php")){
- include_once($LIBpath."crypt/{$config['general_encryption_method']}.php");
- $login = $dhcp_table['mac'][$match_key];
- $group = 'Clients';
- $password = 'password';
- if ($login != ''){
- $login = da_sql_escape_string($link,$login);
- $passwd = da_sql_escape_string($link,$passwd);
- $passwd = da_encrypt($password);
- if ($config['sql_use_user_info_table'] == 'true' && !$da_abort){
- $res = @da_sql_query($link,$config, "SELECT username FROM {$config['sql_user_info_table']} WHERE username = '$login';");
- if ($res){
- if (!@da_sql_num_rows($res,$config)){ // l'utilisateur n'existe pas
- $res = @da_sql_query($link,$config,"INSERT INTO {$config['sql_check_table']} (attribute,value,username $text) VALUES ('{$config['sql_password_attribute']}','$passwd','$login' $passwd_op);");
- if (!$res || !@da_sql_affected_rows($link,$res,$config)){
- $da_abort=1;
- }
- $res = @da_sql_query($link,$config,"INSERT INTO {$config['sql_user_info_table']} (username) VALUES ('$login');");
- if (!$res || !@da_sql_affected_rows($link,$res,$config))
- echo ""; // <b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
- }
- }
- if ($group != ''){
- $group = da_sql_escape_string($link,$group);
- $res = @da_sql_query($link,$config,"SELECT username FROM {$config['sql_usergroup_table']} WHERE username = '$login' AND groupname = '$group';");
- if ($res){
- if (!@da_sql_num_rows($res,$config)){
- $res = @da_sql_query($link,$config,"INSERT INTO {$config['sql_usergroup_table']} (username,groupname) VALUES ('$login','$group');");
- if (!$res || !@da_sql_affected_rows($link,$res,$config))
- echo ""; // <b>Could not add user to group $group. SQL Error</b><br>\n";
- else
- exec('sudo service chilli reload');
- }
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement