Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
m_authip Class Reference

Classe de gestion des IP authorisée More...

Public Member Functions

 list_ip_whitelist ()
 hook_menu ()
 list_ip ($whitelist=false)
 ip_delete ($id)
 get_allowed ($s)
 is_wl ($ip)
 is_in_subnet ($o, $ip, $sub)
 ip_save_whitelist ($id, $ipsub, $infos)
 ip_save ($id, $ipsub, $infos, $uid=null)
 alternc_del_member ()
 get_auth_class ()
 ip_affected_save ($authorised_ip_id, $protocol, $parameters, $id=null)
 ip_affected_delete ($id)
 call_hooks ($function, $affectation_id)
 list_affected ($ip_id=null)

Detailed Description

Classe de gestion des IP authorisée

Definition at line 25 of file m_authip.php.

Member Function Documentation

alternc_del_member ( )

Definition at line 236 of file m_authip.php.

References $cuid, $db, and ip_delete().

{
global $cuid,$db;
$db->query("SELECT id FROM authorised_ip WHERE uid ='$cuid';");
while ($db->next_record()) {
$this->ip_delete($db->f('id'));
}
return true;
}
call_hooks (   $function,
  $affectation_id 
)

Definition at line 332 of file m_authip.php.

References $c, $d, $err, $hooks, get_auth_class(), isset, and list_affected().

Referenced by ip_affected_delete(), ip_affected_save(), and ip_save().

{
global $hooks,$err;
// On récure l'objet dont on parle
$d = $this->list_affected();
if (! isset($d[$affectation_id] )) {
$err->raise('authip', _("Object not available"));
return false;
}
$affectation = $d[$affectation_id];
// On en déduis la classe qui le concerne
$e = $this->get_auth_class();
if (! isset($e[$affectation['protocol']])) {
$err->raise('authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
return false;
}
$c = $e[$affectation['protocol']]['class'];
// On appelle le hooks de cette classe
$hooks->invoke($function, Array($affectation), Array($c) );
return true;
}
get_allowed (   $s)

Definition at line 109 of file m_authip.php.

References $cuid, $db, and $r.

{
global $db, $cuid;
if (! $db->query("select ai.ip, ai.subnet, ai.infos, aia.parameters from authorised_ip ai, authorised_ip_affected aia where aia.protocol='$s' and aia.authorised_ip_id = ai.id and ai.uid='$cuid';") ) {
echo "query failed: ".$db->Error;
return false;
}
$r=Array();
while ($db->next_record()) {
$r[]=Array("ip"=>$db->f("ip"), "subnet"=>$db->f("subnet"), "infos"=>$db->f("infos"), "parameters"=>$db->f("parameters"));
}
return $r;
}
get_auth_class ( )

Definition at line 252 of file m_authip.php.

References $hooks.

Referenced by call_hooks().

{
global $hooks;
$authclass=array();
$authclass = $hooks->invoke('authip_class');
// Je rajoute la class DANS l'objet parce que
// ca m'interesse
foreach ($authclass as $k => $v) {
$authclass[$k]['class']=$k;
}
return $authclass;
}
hook_menu ( )

Definition at line 38 of file m_authip.php.

{
$obj = array(
'title' => _("Access security"),
'ico' => 'images/ip.png',
'link' => 'ip_main.php',
'pos' => 120,
) ;
return $obj;
}
ip_affected_delete (   $id)

Definition at line 309 of file m_authip.php.

References $db, and call_hooks().

Referenced by ip_delete().

{
global $db;
$id=intval($id);
// Call hooks
$this->call_hooks("authip_on_delete", $id );
if (! $db->query("delete from authorised_ip_affected where id='$id' limit 1;") ) {
echo "query failed: ".$db->Error;
return false;
}
return true;
}
ip_affected_save (   $authorised_ip_id,
  $protocol,
  $parameters,
  $id = null 
)

Definition at line 277 of file m_authip.php.

References $db, $parameters, and call_hooks().

{
global $db;
$authorised_ip_id=intval($authorised_ip_id);
$protocol=mysql_real_escape_string($protocol);
$parameters=mysql_real_escape_string($parameters);
if ($id) {
$id=intval($id);
$this->call_hooks("authip_on_delete", $id );
if (! $db->query("update authorised_ip_affected set authorised_ip_id='$authorised_ip_id', protocol='$protocol', parameters='$parameters' where id ='$id' limit 1;") ) {
echo "query failed: ".$db->Error;
return false;
}
$this->call_hooks("authip_on_create", $id );
} else {
if (! $db->query("insert into authorised_ip_affected (authorised_ip_id, protocol, parameters) values ('$authorised_ip_id', '$protocol', '$parameters');") ) {
echo "query failed: ".$db->Error;
return false;
}
$this->call_hooks("authip_on_create", mysql_insert_id() );
}
return true;
}
ip_delete (   $id)

Definition at line 87 of file m_authip.php.

References $cuid, $db, and ip_affected_delete().

Referenced by alternc_del_member().

{
global $db, $cuid;
$id=intval($id);
$db->query("SELECT id FROM authorised_ip_affected where authorised_ip_id ='$id';");
while ($db->next_record()) {
$this->ip_affected_delete($db->f('id'));
}
if (! $db->query("delete from authorised_ip where id='$id' and ( uid='$cuid' or uid=0) limit 1;") ) {
echo "query failed: ".$db->Error;
return false;
}
return true;
}
ip_save (   $id,
  $ipsub,
  $infos,
  $uid = null 
)

Definition at line 175 of file m_authip.php.

References $cuid, $db, $infos, $mem, $uid, call_hooks(), checkip(), checkipv6(), isset, and list_affected().

Referenced by ip_save_whitelist().

{
global $db, $mem;
// If we ask for uid=0, we have to check to be super-user
// else, juste use global cuid;
if ($uid === 0 && $mem->checkRight() ) {
$cuid=0;
} else {
global $cuid;
}
$id=intval($id);
$infos=mysql_real_escape_string($infos);
// Extract subnet from ipsub
$tmp=explode('/',$ipsub);
$ip=$tmp[0];
// Error if $ip not an IP
if ( ! checkip($ip) && ! checkipv6($ip) ) {
echo "Failed : not an IP address";
return false;
}
// Check the subnet, if not defined, give a /32 or a /128
if (isset($tmp[1])) {
$subnet=intval($tmp[1]);
} else {
if ( checkip($ip) ) $subnet=32;
else $subnet=128;
}
// An IPv4 can't have subnet > 32
if (checkip($ip) && $subnet > 32 ) $subnet=32;
if ($id) { // Update
$list_affected = $this->list_affected($id);
foreach($list_affected as $k => $v) {
$this->call_hooks("authip_on_delete", $k );
}
if (! $db->query("update authorised_ip set ip='$ip', subnet='$subnet', infos='$infos' where id='$id' and uid='$cuid' ;") ) {
echo "query failed: ".$db->Error;
return false;
}
foreach($list_affected as $k => $v) {
$this->call_hooks("authip_on_create", $k );
}
} else { // Insert
if (! $db->query("insert into authorised_ip (uid, ip, subnet, infos) values ('$cuid', '$ip', '$subnet', '$infos' );") ) {
echo "query failed: ".$db->Error;
return false;
}
}
return true;
}
ip_save_whitelist (   $id,
  $ipsub,
  $infos 
)

Definition at line 158 of file m_authip.php.

References $infos, $mem, and ip_save().

{
global $mem;
if (!$mem->checkRight()) return false;
return $this->ip_save($id, $ipsub, $infos, 0);
}
is_in_subnet (   $o,
  $ip,
  $sub 
)

Definition at line 138 of file m_authip.php.

References $sub.

Referenced by is_wl().

{
$o = inet_pton($o);
$ip = inet_pton($ip);
$sub = pow(2, $sub);
if ( $o >= $ip && $o <= ($ip+$sub) ) return true;
return false;
}
is_wl (   $ip)

Definition at line 122 of file m_authip.php.

References $db, and is_in_subnet().

{
global $db;
if (! $db->query("select ai.ip, ai.subnet from authorised_ip ai where ai.uid='0';") ) {
echo "query failed: ".$db->Error;
return false;
}
while ($db->next_record()) {
if ( $this->is_in_subnet($ip, $db->f('ip'), $db->f('subnet') ) ) return true;
}
return false;
}
list_affected (   $ip_id = null)

Definition at line 363 of file m_authip.php.

References $cuid, $db, and $r.

Referenced by call_hooks(), and ip_save().

{
global $db, $cuid;
$r = array();
if ( is_null($ip_id) ) {
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = ai.id order by protocol, parameters;");
} else {
$db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid='$cuid' and aia.authorised_ip_id = '".intval($ip_id)."' order by protocol, parameters;");
}
while ($db->next_record()) {
$r[$db->f('id')]=$db->Record;
}
return $r;
}
list_ip (   $whitelist = false)

Definition at line 54 of file m_authip.php.

References $cuid, $db, $mem, $r, checkip(), and checkipv6().

Referenced by list_ip_whitelist().

{
global $db, $mem;
if ($whitelist && $mem->checkRight() ) {
$cuid=0;
} else {
global $cuid;
}
$r = array();
$db->query("SELECT * FROM authorised_ip WHERE uid='$cuid' order by ip,subnet;");
while ($db->next_record()) {
$r[$db->f('id')]=$db->Record;
if ( (checkip($db->f('ip')) && $db->f('subnet') == 32) ||
(checkipv6($db->f('ip')) && $db->f('subnet') == 128) ) {
$r[$db->f('id')]['ip_human']=$db->f('ip');
} else {
$r[$db->f('id')]['ip_human']=$db->f('ip')."/".$db->f('subnet');
}
}
return $r;
}
list_ip_whitelist ( )

Definition at line 32 of file m_authip.php.

References $mem, and list_ip().

{
global $mem;
if (!$mem->checkRight()) return false;
return $this->list_ip(true);
}

The documentation for this class was generated from the following file: