Advertisement
Guest User

Index with facebook

a guest
Aug 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.29 KB | None | 0 0
  1. <?php
  2. define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
  3. $conf_files=array(CONF_FILE);
  4. foreach ($conf_files as $file){
  5.     if (!file_exists($file)){
  6.         exit("File ".$file." unknown");
  7.     }
  8.     if (!is_readable($file)){
  9.         exit("You don't have read rights on the file ".$file);
  10.     }
  11. }
  12. $ouvre=fopen(CONF_FILE,"r");
  13. if ($ouvre){
  14.     while (!feof ($ouvre)){
  15.         $tampon = fgets($ouvre, 4096);
  16.         if (strpos($tampon,"=")!==false){
  17.             $tmp = explode("=",$tampon);
  18.             $conf[$tmp[0]] = $tmp[1];
  19.         }
  20.     }
  21. }else{
  22.     exit("Error opening the file ".CONF_FILE);
  23. }
  24. fclose($ouvre);
  25. $organisme = trim($conf["ORGANISM"]);
  26. $domainname = trim($conf["DOMAIN"]);
  27. $hostname = "connexion.".$domainname;
  28.  
  29. $diagnostic = "can't contact the default router";
  30. $cert_add = "http://$hostname/certs";
  31. $direct_access = False;
  32. $display_menu=False;
  33. $remote_ip = preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
  34. $tab = array();
  35. $user = array();
  36. $network_pb = False;
  37. // DEBUG RULES
  38. $organisme="ORGANISME";
  39. //
  40. $img_rep = "./images/";
  41. $img_organisme = "organisme.png";
  42.  
  43. $Language = 'fr';
  44. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  45.     $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  46.     $Language = strtolower(substr(chop($Langue[0]),0,2));
  47. }
  48. (isset($_GET['lang'])) ? $Language=htmlentities($_GET['lang']) : null;
  49. switch ($Language) {
  50.     case 'en':
  51.         $l_title_part="Terms of use";
  52.         $l_title="{$organisme} :: {$l_title_part}";
  53.         $l_intro_title="Wifi access";
  54.         $l_intro="We provide you an wifi's internet access, you must accept the terms of use below for continue.";
  55.         $l_button_confirm="I'm agree with terms and I want to continue to the internet";
  56.         $l_facebook_local="en_GB";
  57.         break;
  58.    
  59.     default:
  60.         $l_title_part="Conditions d'utilisation";
  61.         $l_title="{$organisme} :: {$l_title_part}";
  62.         $l_intro_title="Acc&egrave;s Wifi";
  63.         $l_intro="Nous mettons &agrave; votre disposition un acc&egrave;s internet wifi, pour poursuivre vous devez accepter les conditions d'utilisation ci-dessous.";
  64.         $l_button_confirm="J'accepte les conditions et souhaite poursuivre sur internet";
  65.         $l_facebook_local="fr_FR";
  66.         break;
  67. }
  68.  
  69. # Retrieve the user info behind the remote ip
  70. exec ("sudo /usr/sbin/chilli_query list | grep -Ew $remote_ip" , $tab);
  71. $user = explode (" ", $tab[0]);
  72. # Test if it's a direct connexion to ALCASAR
  73. if (isset($_SERVER['HTTP_HOST']) && (($_SERVER['HTTP_HOST'] === $_SERVER['SERVER_ADDR']) || ($_SERVER['HTTP_HOST'] === 'alcasar') || ($_SERVER['HTTP_HOST'] === $hostname) || ($_SERVER['HTTP_HOST'] === $organisme))) {
  74.         $direct_access = true;
  75.         exec("sudo /usr/sbin/ipset del not_auth_yet $remote_ip"); # del user of the ipset "not_auth_yet" to not loop
  76. }
  77.  
  78. # Function to adapt time connexion in seconds to H,M,S
  79. function secondsToDuration($seconds = null){
  80.         if ($seconds == null) return "";
  81.         $temp = $seconds % 3600;
  82.         $time[0] = ( $seconds - $temp ) / 3600 ;        // hours
  83.         $time[2] = $temp % 60 ;                         // seconds
  84.         $time[1] = ( $temp - $time[2] ) / 60;           // minutes
  85.         return $time[0]." h ".$time[1]." m ".$time[2]." s";
  86. }
  87.  
  88.  
  89. if ((isset ($user[4])) && ($user[4] != "0")){ # the user is authenticated
  90.        if(isset($_GET['redirect'])) # if user has been warned, we redirect him to his website
  91.        {
  92.                 header('Location: http://'.$_GET['url'], true, 307);
  93.                 exit;
  94.         }
  95. }
  96. else # the user isn't authenticated
  97. {
  98.         exec("sudo /usr/sbin/ipset list not_auth_yet | grep $remote_ip | wc -l 2>&1", $ipset_not_auth_yet);
  99.         if(!$direct_access && $ipset_not_auth_yet[0] == '0'){ # it's the first stage of the interception
  100.                $display_menu = True; # Display menu for user not_auth_yet
  101.                if (!isset($_SERVER['HTTPS'])){ # In HTTP, the user is redirected on it's home page. In HTTPS, it's on the default page (see $redirect_link)
  102.                        $redirect_link = $_SERVER['HTTP_HOST'];
  103.                 }
  104.         }
  105.         if(isset($_GET['url'])){ # it's the second stage (when user has clicked on the button "open a connection")
  106.                exec("sudo /usr/sbin/ipset add not_auth_yet $remote_ip"); # Add user in the ipset "not_auth_yet" (DNS requests not intercepted)
  107.                $redir = "http://".$_GET['url'];
  108.                 header("Location: $redir",TRUE,307);
  109.                 exit;
  110.         }
  111.         if ($ipset_not_auth_yet[0] == '1'){ # if user not_auth_yet still here (index.php), we force DNS resquest.
  112.                 echo "<script>window.location.reload(true)</script>"; # force DNS request
  113.        }
  114. }
  115.  
  116.  
  117.  
  118. $content="<!DOCTYPE HTML>\n";
  119. $content.="<html lang=\"{$Language}\">\n";
  120. $content.="\t<head>\n";
  121. $content.="\t\t<title>{$l_title}</title>\n";
  122. $content.="\t\t<meta name=\"exploitant\" content=\"{$organisme}\" />\n";
  123. $content.="\t\t<meta charset=\"UTF-8\" />\n";
  124. $content.="\t\t<meta name=\"viewport\" content=\"width=950px\">\n";
  125. $content.="\t</head>\n";
  126. $content.="\t<body style=\"background: rgb(220,220,220);\">\n";
  127. $content.="\t\t<div style=\"width: 900px; margin-left: auto; margin-right: auto;\">\n";
  128. $content.="\t\t\t<div style=\"background: rgba(255,255,255,1); height:100px; padding: 10px 10px 10px 10px;\">\n";
  129. $content.="\t\t\t\t<div style=\"display:block; float:left; vertical-align:middle;\"><img src=\"$img_rep$img_organisme\" alt=\"logo: {$organisme}\" style=\"height: 100px; display:inline-block;\"/></div>\n";
  130. $content.="\t\t\t\t<div style=\"display:inline-block; float:right; font-size: 36px; color:rgb(100,100,100); line-height:100px; text-align:center; width:400px;\">{$l_intro_title}</div>\n";
  131. $content.="\t\t\t\t<div style=\"clear:both;\"></div>\n";
  132. $content.="\t\t\t</div>\n";
  133. $content.="\t\t\t<div style=\"background: rgba(255,255,255,1); margin-top: 8px; padding:2px; text-align:center; font-size:15px; color:rgb(150,25,20); font-weight:bold;\">$l_intro</div>\n";
  134. $content.="\t\t\t<div style=\"background: rgba(255,255,255,1); margin-top: 8px;\">\n";
  135. $content.="\t\t\t\t<table style=\"padding:0;\"><tr>\n";
  136. $content.="\t\t\t\t\t<td style=\"padding:0;\">
  137.     <table>
  138.         <tr><td style=\"padding:0;\"><iframe src=\"./terms_{$Language}.html\" style=\"border: none;\" width=\"435px;\" height=\"450px\"></iframe></td></tr>
  139.         <tr style=\"padding:0;\" height=\"50px\"><td style=\"text-align:center;\">
  140.             <input type=\"button\" style=\"background:rgb(85,170,85); color:white; border:none; border-radius:8px; -webkit-appearance: none; height:32px; line-height: 32px; vertical-align:middle;\" value=\"{$l_button_confirm}\" onclick=\"window.location.replace('http://{$hostname}/index.php?redirect=1&url=".urlencode('www.monsite.fr')."');\"/>
  141.         </td></tr>
  142.     </table>
  143. </td>\n";
  144. $content.="\t\t\t\t\t<td style=\"padding:0;\">";
  145. if(!$network_pb)
  146.     $content.="<iframe src=\"https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2FMA_COMPAGNIE%2F&tabs=timeline&width=450&height=500&small_header=true&adapt_container_width=true&hide_cover=false&show_facepile=false&locale={$l_facebook_local}\" width=\"450px\" height=\"500\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\"></iframe>";
  147. $content.="</td>\n";
  148. $content.="\t\t\t\t</table>\n";
  149. $content.="\t\t\t</div>\n";
  150. $content.="\t\t</div>\n";
  151. $content.="\t</body>\n";
  152. $content.="</html>";
  153. echo $content;
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement