Advertisement
Guest User

Alcasar auto with mac

a guest
Aug 28th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.43 KB | None | 0 0
  1. <?php
  2. $remote_ip=$_SERVER['REMOTE_ADDR'];
  3. /*****************************************************************/
  4. if(!defined("CONF_FILE"))
  5.     define("CONF_FILE", "/usr/local/etc/alcasar.conf");
  6. /****************************************************************
  7. * *         FILE reading test           *
  8. * ****************************************************************/
  9. $conf_files=array(CONF_FILE);
  10. foreach ($conf_files as $file){
  11.     if (!file_exists($file))
  12.         exit("Fichier ".$file." introuvable");
  13.     if (!is_readable($file))
  14.         exit("Acc&egrave;s impossible &agrave;: ".$file);
  15. }
  16. /****************************************************************
  17. * *         Read CONF_FILE              *
  18. * *****************************************************************/
  19. $ouvre=fopen(CONF_FILE,"r");
  20. if ($ouvre){
  21.     while (!feof ($ouvre)){
  22.         $tampon = fgets($ouvre, 4096);
  23.         if (strpos($tampon,"=")!==false){
  24.             $tmp = explode("=",$tampon);
  25.             $conf[$tmp[0]] = $tmp[1];
  26.         }
  27.     }
  28. }
  29. else{
  30.     exit("Fichier inaccessible: ".CONF_FILE);
  31. }
  32. fclose($ouvre);
  33. $organisme = trim($conf["ORGANISM"]);
  34. $domainname = trim($conf["DOMAIN"]);
  35. $hostname = trim($conf['HOSTNAME']).".{$domainname}";
  36. $tabs=Array();
  37. exec("sudo /usr/sbin/chilli_query list", $tabs);
  38. // DHCP_TABLE is activity detected from Ethernet received trame and don't use DHCP
  39. foreach($tabs as $k => $v){
  40.     $r=explode(' ', $v);
  41.     $dhcp_table['mac'][]=$r[0];
  42.     $dhcp_table['ip'][]=$r[1];
  43.     $dhcp_table['is_connected'][]=$r[4];
  44. }
  45.  
  46. if(isset($_SERVER['HTTP_HOST'])){
  47.     if(
  48.         ($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_ADDR'])
  49.         || (preg_match("/^127.0.0.1$/", $_SERVER['HTTP_HOST'])
  50.     ) || (preg_match ("/^$hostname$/", $_SERVER['HTTP_HOST'])) || (preg_match ("/^$organisme$/", $_SERVER['HTTP_HOST']))){
  51.         $direct_access=True;
  52.         exec("sudo /usr/sbin/ipset del not_auth_yet $remote_ip");
  53.     }
  54. }
  55.  
  56. if(!in_array($remote_ip, $dhcp_table['ip'])){
  57.     echo 'Vous avez forc&eacute; les r&eacute;glages de votre &eacute;quipement, merci d\'activer le DHCP';
  58. }
  59. else{
  60.     $match_key=array_search($remote_ip, $dhcp_table['ip']);
  61.     $LIBpath = "./acc/manager/lib/";
  62.     require('/etc/freeradius-web/config.php');
  63.     if (is_file($LIBpath."sql/drivers/{$config['sql_type']}/functions.php")){
  64.         include_once($LIBpath."sql/drivers/{$config['sql_type']}/functions.php");
  65.     }
  66.     else{
  67.         echo "Impossible de poursuivre [ERR BDD LIB]\n";
  68.         exit();
  69.     }
  70.     include_once($LIBpath.'functions.php');
  71.     if ($config['sql_use_operators'] == 'true'){
  72.         include_once($LIBpath."operators.php");
  73.         $text = ',op';
  74.         $passwd_op = ",':='";
  75.     }
  76.     $link = @da_sql_pconnect($config);
  77. }
  78. if(is_file($LIBpath."crypt/{$config['general_encryption_method']}.php")){
  79.     include_once($LIBpath."crypt/{$config['general_encryption_method']}.php");         
  80.     $login = $dhcp_table['mac'][$match_key];
  81.     $group = 'Clients';
  82.     $password = 'password';
  83.     if ($login != ''){
  84.         $login = da_sql_escape_string($link,$login);
  85.         $passwd = da_sql_escape_string($link,$passwd);
  86.         $passwd = da_encrypt($password);
  87.        
  88.         if ($config['sql_use_user_info_table'] == 'true' && !$da_abort){
  89.             $res = @da_sql_query($link,$config, "SELECT username FROM {$config['sql_user_info_table']} WHERE username = '$login';");
  90.             if ($res){
  91.                 if (!@da_sql_num_rows($res,$config)){ // l'utilisateur n'existe pas
  92.                     $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);");
  93.                     if (!$res || !@da_sql_affected_rows($link,$res,$config)){
  94.                         $da_abort=1;
  95.                     }
  96.                     $res = @da_sql_query($link,$config,"INSERT INTO {$config['sql_user_info_table']} (username) VALUES ('$login');");
  97.                     if (!$res || !@da_sql_affected_rows($link,$res,$config))
  98.                         echo ""; // <b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
  99.                 }
  100.             }
  101.             if ($group != ''){
  102.                 $group = da_sql_escape_string($link,$group);
  103.                 $res = @da_sql_query($link,$config,"SELECT username FROM {$config['sql_usergroup_table']} WHERE username = '$login' AND groupname = '$group';");
  104.                 if ($res){
  105.                     if (!@da_sql_num_rows($res,$config)){
  106.                         $res = @da_sql_query($link,$config,"INSERT INTO {$config['sql_usergroup_table']} (username,groupname) VALUES ('$login','$group');");
  107.                         if (!$res || !@da_sql_affected_rows($link,$res,$config))
  108.                             echo ""; // <b>Could not add user to group $group. SQL Error</b><br>\n";
  109.                         else
  110.                             exec('sudo service chilli reload');
  111.                     }
  112.                 }
  113.             }
  114.         }  
  115.     }
  116. }
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement