Alternc  latest
Alternc logiel libre pour l'hébergement
m_authip Class Reference

Authorized-ip class. More...

Public Member Functions

 list_ip_whitelist ()
 Retourne la liste des ip whitelist. More...
 
 hook_menu ()
 
 list_ip ($whitelist=false)
 Retourne la liste des ip spécifiées par cet utilisateur. More...
 
 ip_delete ($id)
 Supprime une IP des IP de l'utilisateur et supprime les droits attaché en cascade. More...
 
 get_allowed ($s)
 Liste les IP et subnet authorisés pour une classe donnée. More...
 
 is_wl ($ip)
 
 is_in_subnet ($o, $ip, $sub)
 Retourne si l'ip appartient au subnet. More...
 
 ip_save_whitelist ($id, $ipsub, $infos)
 Sauvegarde une IP dans les IP TOUJOURS authorisée. More...
 
 ip_save ($id, $ipsub, $infos, $uid=null)
 Sauvegarde une IP dans les IP authorisée. More...
 
 alternc_del_member ()
 Fonction appelée par Alternc lors de la suppression d'un utilisateur. More...
 
 get_auth_class ()
 Analyse les classes et récupéres les informations des classes voulant de la restriction IP. More...
 
 ip_affected_save ($authorised_ip_id, $protocol, $parameters, $id=null)
 Enregistre ou modifie une affectation ip<=>ressource Nota : lance des hooks sur la classe correspondante pour informer de l'édition/création. More...
 
 ip_affected_delete ($id)
 Supprime une affectation ip<=>ressource Nota : lance des hooks dans la classe correspondante pour informer de la suppression. More...
 
 call_hooks ($function, $affectation_id)
 Appel les hooks demandé avec en parametres les affectationt ip<=>ressource dont l'id est en parametre. More...
 
 list_affected ($ip_id=null)
 Liste les affectation ip<=>ressource d'un utilisateur. More...
 

Detailed Description

Authorized-ip class.

Definition at line 26 of file m_authip.php.

Member Function Documentation

◆ alternc_del_member()

m_authip::alternc_del_member ( )

Fonction appelée par Alternc lors de la suppression d'un utilisateur.

Parameters
globalint $cuid
globalm_mysql $db
Returns
boolean Retourne TRUE

Definition at line 282 of file m_authip.php.

282  {
283  global $cuid, $db;
284  $db->query("SELECT id FROM authorised_ip WHERE uid = ?;", array($cuid));
285  while ($db->next_record()) {
286  $this->ip_delete($db->f('id'));
287  }
288  return true;
289  }
global $db
Definition: bootstrap.php:26
$cuid
Definition: bootstrap.php:43
ip_delete($id)
Supprime une IP des IP de l'utilisateur et supprime les droits attaché en cascade.
Definition: m_authip.php:105

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

◆ call_hooks()

m_authip::call_hooks (   $function,
  $affectation_id 
)

Appel les hooks demandé avec en parametres les affectationt ip<=>ressource dont l'id est en parametre.

Parameters
globalm_hooks $hooks
globalm_messages $msg
string$functionNom de la fonction a rechercher et appeller dans les classes
integer$affectation_idId de l'affectation correspondante
Returns
boolean Retourne TRUE

Definition at line 381 of file m_authip.php.

381  {
382  global $hooks, $msg;
383 
384  // On récure l'objet dont on parle
385  $d = $this->list_affected();
386  if (!isset($d[$affectation_id])) {
387  $msg->raise("ERROR", 'authip', _("Object not available"));
388  return false;
389  }
390 
391  $affectation = $d[$affectation_id];
392 
393  // On en déduis la classe qui le concerne
394  $e = $this->get_auth_class();
395  if (!isset($e[$affectation['protocol']])) {
396  $msg->raise("ERROR", 'authip', sprintf(_("Can't identified class for the protocole %s"), $affectation['protocol']));
397  return false;
398  }
399  $c = $e[$affectation['protocol']]['class'];
400 
401  // On appelle le hooks de cette classe
402  $hooks->invoke($function, Array($affectation), Array($c));
403 
404  return true;
405  }
$hooks
Definition: bootstrap.php:74
$msg
Definition: bootstrap.php:75
$c
Definition: bootstrap.php:47
$d
get_auth_class()
Analyse les classes et récupéres les informations des classes voulant de la restriction IP.
Definition: m_authip.php:298
list_affected($ip_id=null)
Liste les affectation ip<=>ressource d'un utilisateur.
Definition: m_authip.php:416

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

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

◆ get_allowed()

m_authip::get_allowed (   $s)

Liste les IP et subnet authorisés pour une classe donnée.

Parameters
globalm_mysql $db
globalint $cuid
string$sClasse concernée
Returns
array

Definition at line 130 of file m_authip.php.

130  {
131  global $db, $cuid, $msg;
132  if (!$db->query("select ai.ip, ai.subnet, ai.infos, aia.parameters from authorised_ip ai, authorised_ip_affected aia where aia.protocol= ? and aia.authorised_ip_id = ai.id and ai.uid= ?;", array($s, $cuid))) {
133  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
134  return false;
135  }
136  $r = Array();
137  while ($db->next_record()) {
138  $r[] = Array("ip" => $db->f("ip"), "subnet" => $db->f("subnet"), "infos" => $db->f("infos"), "parameters" => $db->f("parameters"));
139  }
140  return $r;
141  }
$r
Definition: aws_add.php:75

References $cuid, $db, $msg, and $r.

◆ get_auth_class()

m_authip::get_auth_class ( )

Analyse les classes et récupéres les informations des classes voulant de la restriction IP.

Returns
array Retourne un tableau compliqué

Definition at line 298 of file m_authip.php.

298  {
299  global $hooks;
300  $authclass = $hooks->invoke('authip_class');
301 
302  // Je rajoute la class DANS l'objet parce que
303  // ca m'interesse
304  foreach ($authclass as $k => $v) {
305  $authclass[$k]['class'] = $k;
306  }
307 
308  return $authclass;
309  }

References $hooks.

Referenced by call_hooks().

◆ hook_menu()

m_authip::hook_menu ( )
Returns
array

Definition at line 48 of file m_authip.php.

48  {
49  $obj = array(
50  'title' => _("FTP Access Security"),
51  'link' => 'ip_main.php',
52  'pos' => 120,
53  );
54 
55  return $obj;
56  }

◆ ip_affected_delete()

m_authip::ip_affected_delete (   $id)

Supprime une affectation ip<=>ressource Nota : lance des hooks dans la classe correspondante pour informer de la suppression.

Parameters
globalm_mysql $db
int$idid de la ligne à supprimer
Returns
boolean Retourne FALSE si erreur, sinon TRUE

Definition at line 356 of file m_authip.php.

356  {
357  global $db, $msg;
358  $id = intval($id);
359 
360  // Call hooks
361  $this->call_hooks("authip_on_delete", $id);
362 
363  if (!$db->query("delete from authorised_ip_affected where id= ? limit 1;", array($id))) {
364  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
365  return false;
366  }
367  return true;
368  }
call_hooks($function, $affectation_id)
Appel les hooks demandé avec en parametres les affectationt ip<=>ressource dont l'id est en parametre...
Definition: m_authip.php:381
if(!isset($is_include)) if(! $key &&! $crt) $id

References $db, $id, $msg, and call_hooks().

Referenced by ip_delete().

◆ ip_affected_save()

m_authip::ip_affected_save (   $authorised_ip_id,
  $protocol,
  $parameters,
  $id = null 
)

Enregistre ou modifie une affectation ip<=>ressource Nota : lance des hooks sur la classe correspondante pour informer de l'édition/création.

Parameters
globalm_mysql $db
int$authorised_ip_idid de l'ip affecté
string$protocolnom du protocole (définie dans la classe correspondante)
string$parametersinformation propre au protocole
int$id$id présent si c'est une édition
Returns
boolean Retourne FALSE si erreur, sinon TRUE

Definition at line 324 of file m_authip.php.

324  {
325  global $db, $msg;
326  $authorised_ip_id = intval($authorised_ip_id);
327 
328  if ($id) {
329  $id = intval($id);
330  $this->call_hooks("authip_on_delete", $id);
331  if (!$db->query("update authorised_ip_affected set authorised_ip_id= ?, protocol= ?, parameters= ? where id = ? limit 1;", array($authorised_ip_id, $protocol, $parameters, $id))) {
332  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
333  return false;
334  }
335  $this->call_hooks("authip_on_create", $id);
336  } else {
337  if (!$db->query("insert into authorised_ip_affected (authorised_ip_id, protocol, parameters) values (?, ?, ?);", array($authorised_ip_id, $protocol, $parameters))) {
338  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
339  return false;
340  }
341  $this->call_hooks("authip_on_create", $db->lastid());
342  }
343  return true;
344  }

References $db, $id, $msg, and call_hooks().

◆ ip_delete()

m_authip::ip_delete (   $id)

Supprime une IP des IP de l'utilisateur et supprime les droits attaché en cascade.

Parameters
integer$id
Returns
boolean
Parameters
globalm_mysql $db
globalint $cuid
int$idid de la ligne à supprimer
Returns
boolean Retourne FALSE si erreur, sinon TRUE

Definition at line 105 of file m_authip.php.

105  {
106  global $db, $cuid, $msg;
107  $id = intval($id);
108 
109  $db->query("SELECT id FROM authorised_ip_affected where authorised_ip_id = ?;", array($id));
110  while ($db->next_record()) {
111  $this->ip_affected_delete($db->f('id'));
112  }
113  if (!$db->query("delete from authorised_ip where id= ? and ( uid= ? or uid=0) limit 1;", array($id, $cuid))) {
114  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
115  return false;
116  }
117  return true;
118  }
ip_affected_delete($id)
Supprime une affectation ip<=>ressource Nota : lance des hooks dans la classe correspondante pour inf...
Definition: m_authip.php:356

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

Referenced by alternc_del_member().

◆ ip_save()

m_authip::ip_save (   $id,
  $ipsub,
  $infos,
  $uid = null 
)

Sauvegarde une IP dans les IP authorisée.

Parameters
globalm_mysql $db
globalm_mem $mem
globalint $cuid
int$idid de la ligne à modifier. Si vide ou égal à 0, alors c'est une insertion
string$ipsubIP (v4 ou v6), potentiellement avec un subnet ( /24)
string$infosCommentaire pour l'utilisateur
int$uidSi $uid=0 et qu'on est super-admin, insertion avec uid=0 ce qui correspond a une ip toujours authorisée
Returns
boolean Retourne FALSE si erreur, sinon TRUE

Definition at line 213 of file m_authip.php.

213  {
214  global $db, $mem, $msg;
215 
216  // If we ask for uid=0, we have to check to be super-user
217  // else, juste use global cuid;
218  if ($uid === 0 && $mem->checkRight()) {
219  $cuid = 0;
220  } else {
221  global $cuid;
222  }
223 
224  $id = intval($id);
225  $infos = $db->quote(trim($infos));
226 
227  // Extract subnet from ipsub
228  $tmp = explode('/', $ipsub);
229  $ip = $tmp[0];
230 
231  // Error if $ip not an IP
232  if (!checkip($ip) && !checkipv6($ip)) {
233  $msg->raise("ERROR", 'authip', _("Failed : not an IP address"));
234  return false;
235  }
236 
237  // Check the subnet, if not defined, give a /32 or a /128
238  if (isset($tmp[1])) {
239  $subnet = intval($tmp[1]);
240  } else {
241  if (checkip($ip)) {
242  $subnet = 32;
243  } else {
244  $subnet = 128;
245  }
246  }
247 
248  // An IPv4 can't have subnet > 32
249  if (checkip($ip) && $subnet > 32) {
250  $subnet = 32;
251  }
252 
253  if ($id) { // Update
254  $list_affected = $this->list_affected($id);
255  foreach ($list_affected as $k => $v) {
256  $this->call_hooks("authip_on_delete", $k);
257  }
258  if (!$db->query("update authorised_ip set ip= ?, subnet= ?, infos= ? where id= ? and uid=? ;", array($ip, $subnet, $infos, $id, $cuid))) {
259  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
260  return false;
261  }
262  foreach ($list_affected as $k => $v) {
263  $this->call_hooks("authip_on_create", $k);
264  }
265  } else { // Insert
266  if (!$db->query("insert into authorised_ip (uid, ip, subnet, infos) values (?, ?, ?, ?);", array($cuid, $ip, $subnet, $infos))) {
267  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
268  return false;
269  }
270  }
271  return true;
272  }
$mem
Definition: bootstrap.php:71
checkipv6($ip)
Check that $ip is a correct ipv6 ip.
Definition: functions.php:221
checkip($ip)
Check that $ip is a correct 4 Dotted ip.
Definition: functions.php:210
$uid
if(in_array($action, array('start', 'stop', 'monit'))) switch($action) if($lxc->error &&! $script) $infos
Definition: vm.php:32

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

Referenced by ip_save_whitelist().

◆ ip_save_whitelist()

m_authip::ip_save_whitelist (   $id,
  $ipsub,
  $infos 
)

Sauvegarde une IP dans les IP TOUJOURS authorisée.

Parameters
globalm_mem $mem

Definition at line 189 of file m_authip.php.

189  {
190  global $mem;
191  if (!$mem->checkRight()) {
192  return false;
193  }
194  return $this->ip_save($id, $ipsub, $infos, 0);
195  }
ip_save($id, $ipsub, $infos, $uid=null)
Sauvegarde une IP dans les IP authorisée.
Definition: m_authip.php:213

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

◆ is_in_subnet()

m_authip::is_in_subnet (   $o,
  $ip,
  $sub 
)

Retourne si l'ip appartient au subnet.

Parameters
string$o
string$ip
string$sub
Returns
boolean

Definition at line 172 of file m_authip.php.

172  {
173  $o = inet_pton($o);
174  $ip = inet_pton($ip);
175  $sub = pow(2, $sub);
176 
177  if ($o >= $ip && $o <= ($ip + $sub)) {
178  return true;
179  }
180  return false;
181  }
$sub

References $sub.

Referenced by is_wl().

◆ is_wl()

m_authip::is_wl (   $ip)
Parameters
globalm_mysql $db
string$ip
Returns
boolean

Definition at line 150 of file m_authip.php.

150  {
151  global $db, $msg;
152  if (!$db->query("select ai.ip, ai.subnet from authorised_ip ai where ai.uid='0';")) {
153  $msg->raise("ERROR", 'authip', _("query failed: " . $db->Error));
154  return false;
155  }
156  while ($db->next_record()) {
157  if ($this->is_in_subnet($ip, $db->f('ip'), $db->f('subnet')))
158  return true;
159  }
160  return false;
161  }
is_in_subnet($o, $ip, $sub)
Retourne si l'ip appartient au subnet.
Definition: m_authip.php:172

References $db, $msg, and is_in_subnet().

◆ list_affected()

m_authip::list_affected (   $ip_id = null)

Liste les affectation ip<=>ressource d'un utilisateur.

Parameters
globalm_mysql $db
globalint $cuid
int$ip_id
Returns
array Retourne un tableau de valeurs

Definition at line 416 of file m_authip.php.

416  {
417  global $db, $cuid;
418 
419  $r = array();
420  if (is_null($ip_id)) {
421  $db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid= ? and aia.authorised_ip_id = ai.id order by protocol, parameters;", array($cuid));
422  } else {
423  $db->query("select aia.* from authorised_ip_affected aia, authorised_ip ai where ai.uid= ? and aia.authorised_ip_id = ? order by protocol, parameters;", array($cuid, intval($ip_id)));
424  }
425  while ($db->next_record()) {
426  $r[$db->f('id')] = $db->Record;
427  }
428  return $r;
429  }

References $cuid, $db, and $r.

Referenced by call_hooks(), and ip_save().

◆ list_ip()

m_authip::list_ip (   $whitelist = false)

Retourne la liste des ip spécifiées par cet utilisateur.

Parameters
globalm_mysql $db
globalm_mem $mem
globalint $cuid
boolean$whitelist
Returns
array Retourne un tableau indexé des ip de l'utilisateur

Definition at line 69 of file m_authip.php.

69  {
70  global $db, $mem;
71 
72  if ($whitelist && $mem->checkRight()) {
73  $cuid = 0;
74  } else {
75  global $cuid;
76  }
77 
78  $r = array();
79  $db->query("SELECT * FROM authorised_ip WHERE uid= ? order by ip,subnet;", array($cuid));
80  while ($db->next_record()) {
81  $r[$db->f('id')] = $db->Record;
82  if ((checkip($db->f('ip')) && $db->f('subnet') == 32) ||
83  (checkipv6($db->f('ip')) && $db->f('subnet') == 128)) {
84  $r[$db->f('id')]['ip_human'] = $db->f('ip');
85  } else {
86  $r[$db->f('id')]['ip_human'] = $db->f('ip') . "/" . $db->f('subnet');
87  }
88  }
89  return $r;
90  }

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

Referenced by list_ip_whitelist().

◆ list_ip_whitelist()

m_authip::list_ip_whitelist ( )

Retourne la liste des ip whitelist.

Parameters
globalm_mem $mem
Returns
array retourne un tableau indexé des ip de l'utilisateur

Definition at line 35 of file m_authip.php.

35  {
36  global $mem;
37  if (!$mem->checkRight()) {
38  return false;
39  }
40  return $this->list_ip(true);
41  }
list_ip($whitelist=false)
Retourne la liste des ip spécifiées par cet utilisateur.
Definition: m_authip.php:69

References $mem, and list_ip().


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