0

Good afternoon, I am working in giving logged in user controlled FTP access. Reason: I don't want FTP access open to all IP addresses on the internet.

What I am trying to achieve is when a user logs in at the website a PHP script adds their IP address to the hosts.allow list.

What I am currently experiencing: PHP is adding the address, but I can't connect to the FTP server. When I make a little change on my own through nano it directly works.

My question is am I doing something dumb or do I miss something?

<?php
$ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
$myfile = fopen("/etc/hosts.allow", "r") or die("Unable to open file!");
$current = fread($myfile,filesize("/etc/hosts.allow"));
echo $current . "<br>";
echo "test";
$myfile = fopen("/tmp/hosts.allowprepare", "w+") or die("Unable to open file!");
$newline = $current . " " . $ip;
fwrite($myfile, $newline);
fclose($myfile);

echo copy("/tmp/hosts.allowprepare","/etc/hosts.allow");

?> 
178024
  • 36
  • 3
  • 15

0 Answers0