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

Manage the AlternC's account administration (create/edit/delete) More...

Public Member Functions

 __construct ()
 Constructor. More...
 
 hook_menu ()
 Hook function called by the menu class to add menu to the left panel. More...
 
 alternc_password_policy ()
 Password kind used in this class (hook for admin class) More...
 
 stop_if_jobs_locked ()
 
 get_uid_by_login ($login)
 return the uid of an alternc account More...
 
 get_login_by_uid ($uid)
 return the name of an alternc account More...
 
 get ($uid, $recheck=false)
 Returns the known information about a hosted account. More...
 
 get_creator ($uid)
 Returns the known information about a specific hosted account. More...
 
 onesu ()
 
 get_list ($all=0, $creator=0, $pattern=FALSE, $pattern_type=FALSE)
 @TODO :EM: those request should have been escaped Returns the list of the hosted accounts More...
 
 mailallmembers ($subject, $message, $from)
 Send an email to all AlternC's accounts. More...
 
 get_creator_list ()
 Returns an array with the known information about resellers (uid, login, number of accounts) Does not include account 2000 in the list. More...
 
 checkcreator ($uid)
 Check if I am the creator of the member $uid. More...
 
 add_shared_domain ($u, $domain_name)
 When the admin want to delegate a subdomain to an account. More...
 
 add_mem ($login, $pass, $nom, $prenom, $mail, $canpass=1, $type='default', $duration=0, $notes="", $force=0, $create_dom='', $db_server_id)
 Creates a new hosted account. More...
 
 hook_admin_add_member ()
 AlternC's standard function called when a user is created This sends an email if configured through the interface. More...
 
 update_mem ($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type='default', $duration=0, $notes="", $reset_quotas=false)
 Edit an account. More...
 
 lock_mem ($uid)
 Lock an account. More...
 
 unlock_mem ($uid)
 UnLock an account. More...
 
 del_mem ($uid)
 Deletes an account Deletes the specified account. More...
 
 renew_mem ($uid, $periods=1)
 Renew an account. More...
 
 renew_update ($uid, $duration)
 Update the duration information for an account. More...
 
 renew_get_expiry ($uid)
 Get the expiry date for an account. More...
 
 renew_get_status ($uid)
 Get the expiry status for an account. More...
 
 renew_get_expiring_accounts ()
 Get the expired/about to expire accounts. More...
 
 normal2su ($uid)
 Turns a common account into a super-admin account. More...
 
 su2normal ($uid)
 Turns a super-admin account into a common account. More...
 
 listtld ()
 List of the authorized TLDs Returns the list of the authorized TLDs and also the way they are authorized. More...
 
 dom_list ($alsocheck=false, $forcecheck=false)
 List the hosted domains on this server. More...
 
 checkalldom ()
 Check all the domains for their NS MX and IPs. More...
 
 dom_lock ($domain)
 Lock / Unlock a domain. More...
 
 gettld ($tld)
 Add a new TLD to the list of the authorized TLDs. More...
 
 selecttldmode ($current=false)
 Prints the list of the actually authorized TLDs. More...
 
 deltld ($tld)
 Deletes the specified tld in the list of the authorized TLDs Note : This function does not delete the domains depending on this TLD. More...
 
 addtld ($tld, $mode)
 Add a TLD to the list of the authorized TLDs during the installation. More...
 
 edittld ($tld, $mode)
 Modify a TLD of the list of the authorized TLDs. More...
 
 getadmin ()
 Get the login name of the main administrator account. More...
 
 listPasswordPolicies ()
 List the password policies currently installed in the policy table. More...
 
 editPolicy ($policy, $minsize, $maxsize, $classcount, $allowlogin)
 Change a password policy for one kind of password. More...
 
 checkPolicy ($policy, $login, $password, $canbeempty=false)
 

Public Attributes

 $enabled = 0
 $enabled tells if the logged user is super-admin or not More...
 
 $tldmode = array()
 List of the controls made for each TLD. More...
 
 $archive = ''
 

Detailed Description

Manage the AlternC's account administration (create/edit/delete)

Definition at line 26 of file m_admin.php.

Constructor & Destructor Documentation

◆ __construct()

m_admin::__construct ( )

Constructor.

Parameters
globaltype $db
globaltype $cuid

Definition at line 50 of file m_admin.php.

50  {
51  global $db, $cuid;
52  $db->query("SELECT su FROM membres WHERE uid=?;", array($cuid));
53  $db->next_record();
54  $this->enabled = $db->f("su");
55 
56  $this->tldmode = array(
57  0 => _("This TLD is forbidden"),
58  1 => _("primary DNS is checked in WHOIS db"),
59  2 => _("primary & secondary DNS are checked in WHOIS db"),
60  3 => _("Domain must exist, but don't do any DNS check"),
61  4 => _("Domain can be installed, no check at all"),
62  5 => _("Domain can be installed, force NO DNS hosting"),
63  );
64  $this->archive = variable_get('archive_del_data', '', 'If folder specified html folder of deleted user is archived, else it is deleted. ');
65  }
global $db
Definition: bootstrap.php:26
$cuid
Definition: bootstrap.php:43
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85
$admin enabled
Definition: newone.php:38

References $cuid, $db, enabled, and variable_get().

Member Function Documentation

◆ add_mem()

m_admin::add_mem (   $login,
  $pass,
  $nom,
  $prenom,
  $mail,
  $canpass = 1,
  $type = 'default',
  $duration = 0,
  $notes = "",
  $force = 0,
  $create_dom = '',
  $db_server_id 
)

Creates a new hosted account.

Creates a new hosted account (in the tables membres and local). Prevents any manipulation of the account if the account $mid is not super-admin.

Parameters
globalm_messages $msg
globalm_quota $quota
globalarray $classes
globalint $cuid
globalm_mem $mem
globalstring $L_MYSQL_DATABASE
globalstring $L_MYSQL_LOGIN
globalm_hooks $hooks
globalm_action $action
string$loginLogin name like [a-z][a-z0-9]*
string$passPassword (max. 64 characters)
string$nomName of the account owner
string$prenomFirst name of the account owner
string$mailEmail address of the account owner, useful to get one's lost password
integer$canpass
string$typeAccount type for quotas
int$duration
string$notes
integer$force
string$create_dom
int$db_server_id
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 593 of file m_admin.php.

593  {
594  global $msg, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action;
595  $msg->log("admin", "add_mem", $login . "/" . $mail);
596  if (!$this->enabled) {
597  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
598  return false;
599  }
600  if (empty($db_server_id)) {
601  $msg->raise("ERROR", "admin", _("Missing db_server field"));
602  return false;
603  }
604  if (($login == "") || ($pass == "")) {
605  $msg->raise("ERROR", "admin", _("Please fill all mandatory fields"));
606  return false;
607  }
608  if (!$force) {
609  if ($mail == "") {
610  $msg->raise("ERROR", "admin", _("Please fill all mandatory fields"));
611  return false;
612  }
613  //@todo remove cf functions.php
614  if (checkmail($mail) != 0) {
615  $msg->raise("ERROR", "admin", _("Please enter a valid email address"));
616  return false;
617  }
618  }
619  $login = strtolower($login);
620  if (!preg_match("#^[a-z0-9]+$#", $login)) { //$
621  $msg->raise("ERROR", "admin", _("Login can only contains characters a-z and 0-9"));
622  return false;
623  }
624  if (strlen($login) > 14) {
625  // Not an arbitrary value : MySQL user names can be up to 16 characters long
626  // If we want to allow people to create a few mysql_user (and we want to!)
627  // we have to limit the login lenght
628  $msg->raise("ERROR", "admin", _("The login is too long (14 chars max)"));
629  return false;
630  }
631  // Some login are not allowed...
632  if ($login == $L_MYSQL_DATABASE || $login == $L_MYSQL_LOGIN || $login == "mysql" || $login == "root") {
633  $msg->raise("ERROR", "admin", _("Login can only contains characters a-z, 0-9 and -"));
634  return false;
635  }
636  $pass = password_hash($pass, PASSWORD_BCRYPT);
637  $db = new DB_System();
638  // Already exist?
639  $db->query("SELECT count(*) AS cnt FROM membres WHERE login= ?;", array($login));
640  $db->next_record();
641  if (!$db->f("cnt")) {
642  $db->query("SELECT max(m.uid)+1 as nextid FROM membres m");
643  if (!$db->next_record()) {
644  $uid = 2000;
645  } else {
646  $uid = $db->Record["nextid"];
647  if ($uid <= 2000) {
648  $uid = 2000;
649  }
650  }
651  $db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?);", array($uid, $login, $pass, $mail, $cuid, $canpass, $type, $notes, $db_server_id));
652  $db->query("INSERT INTO local(uid,nom,prenom) VALUES(?, ?, ?);", array($uid, $nom, $prenom));
653  $this->renew_update($uid, $duration);
654  $action->create_dir(getuserpath("$login"));
655  $action->fix_user($uid);
656 
657  // Triggering hooks
658  $mem->su($uid);
659 
660  $hooks->invoke("alternc_add_member");
661  // New hook way
662  $hooks->invoke("hook_admin_add_member", array(), array('quota')); // First !!! The quota !!! Eitherway, we can't be sure to be able to create all
663  $hooks->invoke("hook_admin_add_member");
664  $mem->unsu();
665 
666  if (!empty($create_dom)) {
667  $this->add_shared_domain($uid, $create_dom);
668  }
669 
670  return $uid;
671  } else {
672  $msg->raise("ERROR", "admin", _("This login already exists"));
673  return false;
674  }
675  }
$hooks
Definition: bootstrap.php:74
global $L_MYSQL_LOGIN
Definition: bootstrap.php:26
$mem
Definition: bootstrap.php:71
$msg
Definition: bootstrap.php:75
global $L_MYSQL_DATABASE
Definition: bootstrap.php:26
add_shared_domain($u, $domain_name)
When the admin want to delegate a subdomain to an account.
Definition: m_admin.php:531
renew_update($uid, $duration)
Update the duration information for an account.
Definition: m_admin.php:945
checkmail($mail)
Check an email address, use filter_var with emails, which works great ;)
Definition: functions.php:244
getuserpath($user=null)
get the home of the user
Definition: functions.php:329
$uid
$login

References $cuid, $db, $hooks, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $login, $mem, $msg, $uid, add_shared_domain(), checkmail(), enabled, getuserpath(), and renew_update().

◆ add_shared_domain()

m_admin::add_shared_domain (   $u,
  $domain_name 
)

When the admin want to delegate a subdomain to an account.

Parameters
globalm_mysql $db
globalm_messages $msg
globalm_dom $dom
globalm_mem $mem
globalint $cuid
string$u
string$domain_name
Returns
boolean

Definition at line 531 of file m_admin.php.

531  {
532  global $msg, $dom, $mem;
533  $msg->log("admin", "add_shared_domain", $u . "/" . $domain_name);
534 
535  if (!$mem->checkright()) {
536  $msg->raise("ERROR", "admin", _("-- Only administrators can do that! --"));
537  return false;
538  }
539 
540  // Check if this domain exist on this admin account
541  if ((!in_array($domain_name, $dom->enum_domains()))&&($domain_name!=variable_get("hosting_tld"))) {
542  $msg->raise("ERROR", "admin", _("You don't seem to be allowed to delegate this domain"));
543  $msg->log("admin", "add_shared_domain", "domain not allowed");
544  return false;
545  }
546 
547  // Clean the domain_name
548  $domain_name = preg_replace("/^\.\.*/", "", $domain_name);
549 
550  $mem->su($u);
551  $dom->lock();
552  // option : 1=hébergement dns, 1=noerase, empeche de modifier, 1=force
553  // we do not allow DNS modification for hosting_tld
554  $dns=($domain_name==variable_get("hosting_tld")) ? 0 : 1;
555  $dom->add_domain($mem->user['login'] . "." . $domain_name, $dns, 1, 1);
556  $dom->unlock();
557  $mem->unsu();
558  return true;
559  }
$dom
Definition: whois_test.php:10

References $dom, $mem, $msg, and variable_get().

Referenced by add_mem().

◆ addtld()

m_admin::addtld (   $tld,
  $mode 
)

Add a TLD to the list of the authorized TLDs during the installation.

Note: If you check in the whois, be sure that m_domains knows how to name the whois of the specified domain!

Parameters
globalm_mysql $db
globalm_messages $msg
string$tldstring TLD we want to authorize
boolean$modeControls to make on this TLD.
Returns
boolean TRUE if the TLD has been successfully added. FALSE if not.

Definition at line 1336 of file m_admin.php.

1336  {
1337  global $db, $msg;
1338  if (!$tld) {
1339  $msg->raise("ERROR", "admin", _("The TLD name is mandatory"));
1340  return false;
1341  }
1342  $tld = trim($tld);
1343 
1344  $db->query("SELECT tld FROM tld WHERE tld= ?;", array($tld));
1345  if ($db->next_record()) {
1346  $msg->raise("ERROR", "admin", _("This TLD already exist"));
1347  return false;
1348  }
1349  if (substr($tld, 0, 1) == ".") {
1350  $tld = substr($tld, 1);
1351  }
1352  $mode = intval($mode);
1353  if ($mode == 0) {
1354  $mode = "0";
1355  }
1356  $db->query("INSERT INTO tld (tld,mode) VALUES (?,?);", array($tld, $mode));
1357  return true;
1358  }
$mode
Definition: adm_tldedit.php:40

References $db, $mode, and $msg.

◆ alternc_password_policy()

m_admin::alternc_password_policy ( )

Password kind used in this class (hook for admin class)

Returns
array

Definition at line 144 of file m_admin.php.

144  {
145  return array("adm" => "Administration section");
146  }

◆ checkalldom()

m_admin::checkalldom ( )

Check all the domains for their NS MX and IPs.

Parameters
globalm_mysql $db
globalstring $L_NS1
globalstring $L_NS2
globalstring $L_MX
globalstring $L_PUBLIC_IP
Returns
int

Definition at line 1154 of file m_admin.php.

1154  {
1155  global $db, $L_NS1, $L_NS2, $L_MX, $L_PUBLIC_IP;
1156  $checked = array();
1157 
1158  $query = "SELECT * FROM domaines ";
1159  $query_args = array();
1160  if($hosting_tld = variable_get("hosting_tld")){
1161  $query .= " WHERE domaine not like ?";
1162  array_push($query_args, "%.".$hosting_tld);
1163  }
1164  $query .= " ORDER BY domaine";
1165  $db->query($query, $query_args);
1166  $dl = array();
1167  while ($db->next_record()) {
1168  $dl[$db->Record["domaine"]] = $db->Record;
1169  }
1170 
1171  // won't search for MX and subdomains record if DNS is hosted here
1172  $lazycheck=1;
1173 
1174  sort($dl);
1175  foreach ($dl as $c) {
1176  // For each domain check its type:
1177  $errno = 0;
1178  $errstr = "";
1179  $dontexist = false;
1180  // Check the domain.
1181  if ($c["gesdns"] == 1) {
1182  // Check the NS pointing to us
1183  $out = array();
1184  exec("dig +short NS " . escapeshellarg($c["domaine"]), $out);
1185  if (count($out) == 0) {
1186  $dontexist = true;
1187  } else {
1188  if (!in_array($L_NS1 . ".", $out) || !in_array($L_NS2 . ".", $out)) {
1189  $errno = 1;
1190  $errstr.=sprintf(_("NS for this domain are not %s and %s BUT %s"),
1191  $L_NS1, $L_NS2, implode(",", $out)) . "\n";
1192  }
1193  }
1194  }
1195 
1196  if (!$dontexist&&(!$lazycheck||!$c["gesdns"])) {
1197  if ($c["gesmx"] == 1) {
1198  $out = array();
1199  exec("dig +short MX " . escapeshellarg($c["domaine"]), $out);
1200  $out2 = array();
1201  foreach ($out as $o) {
1202  list($t, $out2[]) = explode(" ", $o);
1203  }
1204  if (!in_array($L_MX . ".", $out2)) {
1205  $errno = 1;
1206  $errstr.=sprintf(_("MX is not %s BUT %s"), $L_MX, implode(",", $out2))."\n";
1207  }
1208  }
1209 
1210  // We list all subdomains and check they are pointing to us.
1211  $db->query("SELECT * FROM sub_domaines WHERE domaine=? ORDER BY sub;", array($c["domaine"]));
1212  while ($db->next_record()) {
1213  $d = $db->Record;
1214  if ($d["type"] == 'VHOST') {
1215  // Check the IP:
1216  $out = array();
1217  exec("dig +short A " . escapeshellarg($d["sub"] . (($d["sub"] != "") ? "." : "") . $c["domaine"]), $out);
1218  if (!is_array($out)) { // exec dig can fail
1219  $errno = 1;
1220  $errstr.=_("Fail to get the DNS information. Try again.")."\n";
1221  } else {
1222  if (!in_array($L_PUBLIC_IP, $out)) {
1223  $errstr.=sprintf(_("subdomain '%s' doesn't point to %s but to '%s'"), $d["sub"], $L_PUBLIC_IP, implode(",", $out))."\n" ;
1224  $errno = 1;
1225  }
1226  }
1227  }
1228  }
1229  }
1230  if ($dontexist) {
1231  $errno = 2;
1232  $errstr = _("Domain doesn't exist anymore !");
1233  }
1234  if ($errno == 0)
1235  $errstr = "OK";
1236  $checked[$c["domaine"]] = array("errno" => $errno, "errstr" => $errstr);
1237  }
1238  return $checked;
1239  }
$query
Definition: 3.0.0~3.php:37
$c
Definition: bootstrap.php:47
$d
$errstr
Definition: change.php:62
$dl
Definition: dom_add.php:61
foreach($domaines_user as $domaine) $t

References $c, $d, $db, $dl, $errstr, $query, $t, and variable_get().

Referenced by dom_list().

◆ checkcreator()

m_admin::checkcreator (   $uid)

Check if I am the creator of the member $uid.

Parameters
globaltype $msg
globaltype $mem
globaltype $db
globaltype $cuid
int$uida unique integer identifying the account
Returns
boolean TRUE if I am the creator of that account. FALSE else.

Definition at line 504 of file m_admin.php.

504  {
505  global $msg, $db, $cuid;
506  if ($cuid == 2000) {
507  return true;
508  }
509  $db->query("SELECT creator FROM membres WHERE uid= ?;", array($uid));
510  $db->next_record();
511  if ($db->Record["creator"] != $cuid) {
512  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
513  return false;
514  }
515  return true;
516  }

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

◆ checkPolicy()

m_admin::checkPolicy (   $policy,
  $login,
  $password,
  $canbeempty = false 
)
Parameters
globalm_mysql $db
globalm_messages $msg
string$policyName of the policy to check for
string$loginThe login that will be set
string$passwordThe password we have to check
Returns
boolean TRUE if the password if OK for this login and this policy, FALSE if it is not.

Definition at line 1485 of file m_admin.php.

1485  {
1486  global $msg;
1487 
1488  if (empty($login)) {
1489  $msg->raise("ALERT", "admin", _("Please enter a login"));
1490  return false;
1491  }
1492  if (empty($password) && !$canbeempty) {
1493  $msg->raise("ALERT", "admin", _("Please enter a password"));
1494  return false;
1495  }
1496 
1497  $pol = $this->listPasswordPolicies();
1498  if (!$pol[$policy]) {
1499  $msg->raise("ERROR", "admin", _("-- Program error -- The requested password policy does not exist!"));
1500  return false;
1501  }
1502  $pol = $pol[$policy];
1503  // Ok, now let's check it :
1504  $plen = strlen($password);
1505 
1506  if ($plen < $pol["minsize"] && !($canbeempty && empty($password))) {
1507  $msg->raise("ERROR", "admin", _("The password length is too short according to the password policy"));
1508  return false;
1509  }
1510 
1511  if ($plen > $pol["maxsize"] && !($canbeempty && empty($password))) {
1512  $msg->raise("ERROR", "admin", _("The password is too long according to the password policy"));
1513  return false;
1514  }
1515 
1516  if (!$pol["allowlogin"]) {
1517  // We do misc check on password versus login :
1518  $logins = preg_split("/[@_-]/", $login);
1519  $logins[] = $login;
1520  foreach ($logins as $l) {
1521  if (!$l) {
1522  continue;
1523  }
1524  if (strpos($password, $l) !== false || strpos($l, $password) !== false) {
1525  $msg->raise("ERROR", "admin", _("The password policy prevents you to use your login name inside your password or the other way around"));
1526  return false;
1527  }
1528  }
1529  }
1530 
1531  if ($pol["classcount"] > 0 && !($canbeempty && empty($password))) {
1532  $cls = array(0, 0, 0, 0, 0);
1533  for ($i = 0; $i < strlen($password); $i++) {
1534  $p = substr($password, $i, 1);
1535  if (strpos("abcdefghijklmnopqrstuvwxyz", $p) !== false) {
1536  $cls[0] = 1;
1537  } elseif (strpos("ABCDEFGHIJKLMNOPQRSTUVWXYZ", $p) !== false) {
1538  $cls[1] = 1;
1539  } elseif (strpos("0123456789", $p) !== false) {
1540  $cls[2] = 1;
1541  } elseif (strpos('!"#$%&\'()*+,-./:;<=>?@[\\]^_`', $p) !== false) {
1542  $cls[3] = 1;
1543  } else {
1544  $cls[4] = 1;
1545  }
1546  } // foreach
1547  $clc = array_sum($cls);
1548  if ($clc < $pol["classcount"]) {
1549  $msg->raise("ERROR", "admin", _("Your password contains not enough different classes of character, between low-case, up-case, figures and special characters."));
1550  return false;
1551  }
1552  }
1553  return true; // congratulations !
1554  }
$p
Definition: bro_editor.php:46
listPasswordPolicies()
List the password policies currently installed in the policy table.
Definition: m_admin.php:1410
$password
Definition: bootstrap.php:85
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))
$i

References $i, $login, $msg, $p, $password, elseif, and listPasswordPolicies().

◆ del_mem()

m_admin::del_mem (   $uid)

Deletes an account Deletes the specified account.

Prevents any manipulation of the account if the account $mid is not super-admin.

Parameters
globalm_messages $msg
globalm_quota $quota
globalarray $classes
globalint $cuid
globalm_mem $mem
globalm_dom $dom
globalm_hooks $hooks
globalm_action $action
int$uidThe uid number of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 871 of file m_admin.php.

871  {
872  global $msg, $mem, $dom, $hooks, $action;
873  $msg->log("admin", "del_mem", $uid);
874 
875  if (!$this->enabled) {
876  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
877  return false;
878  }
879  $db = new DB_System();
880  $tt = $this->get($uid);
881 
882  $mem->su($uid);
883  // This script may take a long time on big accounts, let's give us some time ... Fixes 1132
884  @set_time_limit(0);
885  // WE MUST call m_dom before all others because of conflicts ...
886  $dom->admin_del_member();
887 
888  # New way of deleting or backup delted user html folders using action class
889  $path = getuserpath($tt['login']);
890  $action->archive($path);
891 
892  $hooks->invoke("alternc_del_member");
893  $hooks->invoke("hook_admin_del_member");
894 
895  if (($db->query("DELETE FROM membres WHERE uid= ?;", array($uid))) &&
896  ($db->query("DELETE FROM local WHERE uid= ?;", array($uid)))) {
897  $mem->unsu();
898  // If this user was (one day) an administrator one, he may have a list of his own accounts. Let's associate those accounts to nobody as a creator.
899  $db->query("UPDATE membres SET creator=2000 WHERE creator= ?;", array($uid));
900  return true;
901  } else {
902  $msg->raise("ERROR", "admin", _("Account not found"));
903  $mem->unsu();
904  return false;
905  }
906  }

References $db, $dom, $hooks, $mem, $msg, $uid, enabled, and getuserpath().

◆ deltld()

m_admin::deltld (   $tld)

Deletes the specified tld in the list of the authorized TLDs Note : This function does not delete the domains depending on this TLD.

Parameters
globalm_mysql $db
globalm_messages $msg
string$tldThe TLD you want to delete
Returns
boolean returns true if the TLD has been deleted, or false if an error occured.

Definition at line 1311 of file m_admin.php.

1311  {
1312  global $db, $msg;
1313  $db->query("SELECT tld FROM tld WHERE tld= ?;", array($tld));
1314  if (!$db->next_record()) {
1315  $msg->raise("ERROR", "admin", _("This TLD does not exist"));
1316  return false;
1317  }
1318  $db->query("DELETE FROM tld WHERE tld= ?;", array($tld));
1319  return true;
1320  }

References $db, and $msg.

◆ dom_list()

m_admin::dom_list (   $alsocheck = false,
  $forcecheck = false 
)

List the hosted domains on this server.

Return the list of hosted domains on this server, (an array of associative arrays)

Parameters
globalm_mysql $db
boolean$alsocheckReturns also errstr and errno telling the domains dig checks
boolean$forcecheckForce the check of dig domain even if a cache exists.
Returns
array $r[$i] / [domaine][member][noerase][gesdns][gesmx]

Definition at line 1109 of file m_admin.php.

1109  {
1110  global $db;
1111  $cachefile = "/tmp/alternc_dig_check_cache";
1112  $cachetime = 3600; // The dns cache file can be up to 1H old
1113  if ($alsocheck) {
1114  if (!$forcecheck && file_exists($cachefile) && filemtime($cachefile) + $cachetime > time()) {
1115  $checked = unserialize(file_get_contents($cachefile));
1116  } else {
1117  // TODO : do the check here (cf checkdom.php) and store it in $checked
1118  $checked = $this->checkalldom();
1119  file_put_contents($cachefile, serialize($checked));
1120  }
1121  }
1122 
1123  $query = "SELECT m.uid,m.login,d.domaine,d.gesdns,d.gesmx,d.noerase FROM domaines d LEFT JOIN membres m ON m.uid=d.compte ";
1124  $query_args = array();
1125  if($hosting_tld = variable_get("hosting_tld")){
1126  $query .= " WHERE domaine not like ?";
1127  array_push($query_args, "%.".$hosting_tld);
1128  }
1129  $query .= " ORDER BY domaine;";
1130  $db->query($query, $query_args);
1131  $c = array();
1132  while ($db->next_record()) {
1133  $tmp = $db->Record;
1134  if ($alsocheck) {
1135  $tmp["errstr"] = $checked[$tmp["domaine"]]["errstr"];
1136  $tmp["errno"] = $checked[$tmp["domaine"]]["errno"];
1137  }
1138  $c[] = $tmp;
1139  }
1140  return $c;
1141  }
$forcecheck
Definition: adm_doms.php:49
checkalldom()
Check all the domains for their NS MX and IPs.
Definition: m_admin.php:1154

References $c, $db, $forcecheck, $query, checkalldom(), and variable_get().

◆ dom_lock()

m_admin::dom_lock (   $domain)

Lock / Unlock a domain.

Lock (or unlock) a domain, so that the member will be (not be) able to delete it from its account

Parameters
globalm_mysql $db
globalm_messages $msg
string$domainDomain name to lock / unlock
Returns
boolean TRUE if the domain has been locked/unlocked or FALSE if it does not exist.

Definition at line 1253 of file m_admin.php.

1253  {
1254  global $db, $msg;
1255  $db->query("SELECT compte FROM domaines WHERE domaine= ?;", array($domain));
1256  if (!$db->next_record()) {
1257  $msg->raise("ERROR", "dom", _("Domain '%s' not found."), $domain);
1258  return false;
1259  }
1260  $db->query("UPDATE domaines SET noerase=1-noerase WHERE domaine= ?;", array($domain));
1261  return true;
1262  }
$domain
Definition: dom_import.php:36

References $db, $domain, and $msg.

◆ editPolicy()

m_admin::editPolicy (   $policy,
  $minsize,
  $maxsize,
  $classcount,
  $allowlogin 
)

Change a password policy for one kind of password.

Parameters
globalm_mysql $db
string$policyName of the policy to edit
int$minsizeMinimum Password size
int$maxsizeMaximum Password size
int$classcountHow many class of characters must this password have
boolean$allowloginDo we allow the password to be like the login ?
Returns
boolean if the policy has been edited, or FALSE if an error occured.

Definition at line 1456 of file m_admin.php.

1456  {
1457  global $db;
1458  $minsize = intval($minsize);
1459  $maxsize = intval($maxsize);
1460  $classcount = intval($classcount);
1461  $allowlogin = intval($allowlogin);
1462 
1463  $db->query("SELECT * FROM policy WHERE name= ?;", array($policy));
1464  if (!$db->next_record()) {
1465  return false; // Policy not found
1466  }
1467  if ($minsize < 0 || $minsize > 64 || $maxsize < 0 || $maxsize > 64 || $maxsize < $minsize || $classcount < 0 || $classcount > 4) {
1468  return false; // Incorrect policy ...
1469  }
1470  $allowlogin = ($allowlogin) ? 1 : 0;
1471  $db->query("UPDATE policy SET minsize= ?, maxsize= ?, classcount= ?, allowlogin= ? WHERE name= ?;", array($minsize, $maxsize, $classcount, $allowlogin, $policy));
1472  return true;
1473  }

References $db.

◆ edittld()

m_admin::edittld (   $tld,
  $mode 
)

Modify a TLD of the list of the authorized TLDs.

Parameters
globalm_mysql $db
globalm_messages $msg
string$tldTLD we want to modify
int$modeControls to make on this TLD.
Returns
boolean TRUE if the TLD has been successfully modified. FALSE if not.

Definition at line 1372 of file m_admin.php.

1372  {
1373  global $db, $msg;
1374  $db->query("SELECT tld FROM tld WHERE tld= ?;", array($tld));
1375  if (!$db->next_record()) {
1376  $msg->raise("ERROR", "admin", _("This TLD does not exist"));
1377  return false;
1378  }
1379  $mode = intval($mode);
1380  if ($mode == 0) {
1381  $mode = "0";
1382  }
1383  $db->query("UPDATE tld SET mode= ? WHERE tld= ?;", array($mode, $tld));
1384  return true;
1385  }

References $db, $mode, and $msg.

◆ get()

m_admin::get (   $uid,
  $recheck = false 
)

Returns the known information about a hosted account.

Returns all what we know about an account (contents of the tables membres et local) Ckecks if the account is super-admin

Parameters
globaltype $msg
globaltype $db
globalstring $lst_users_properties
int$uida unique integer identifying the account
boolean$recheck
Returns
array|boolean an associative array containing all the fields of the table membres and local of the corresponding account. Returns FALSE if an error occurs.

Definition at line 212 of file m_admin.php.

212  {
213  global $msg, $db, $lst_users_properties;
214  $msg->debug("admin","get",$uid);
215  if (!$this->enabled) {
216  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
217  return false;
218  }
219 
220  if (!isset($lst_users_properties) || empty($lst_users_properties) || !is_array($lst_users_properties) || $recheck) {
221  $lst_users_properties = array();
222  $db->query("
223  SELECT
224  m.uid as muid,
225  l.*,
226  m.*,
227  parent.login as parentlogin,
228  dbs.name as db_server_name,
229  m.renewed + INTERVAL m.duration MONTH as expiry,
230  CASE
231  WHEN m.duration IS NULL THEN 0
232  WHEN m.renewed + INTERVAL m.duration MONTH <= NOW() THEN 3
233  WHEN m.renewed <= NOW() THEN 2
234  ELSE 1 END 'status'
235 
236  FROM membres as m
237  LEFT JOIN membres as parent ON (parent.uid = m.creator)
238  LEFT JOIN db_servers as dbs ON (m.db_server_id = dbs.id)
239  LEFT JOIN local as l ON (m.uid = l.uid) ;");
240  while ($db->next_record()) {
241  $lst_users_properties[$db->f('muid')] = $db->Record;
242  }
243  }
244 
245  if (!isset($lst_users_properties[$uid])) {
246  if (!$recheck) {
247  // don't exist, but is not a forced check. Do a forced check
248  return $this->get($uid, true);
249  }
250  $msg->raise("ERROR", "admin", _("Account not found"));
251  return false;
252  }
253 
254  return $lst_users_properties[$uid];
255  }

◆ get_creator()

m_admin::get_creator (   $uid)

Returns the known information about a specific hosted account.

Similar to get_list() but for creators/resellers.

Parameters
globaltype $msg
globaltype $db
int$uid
Returns
boolean

Definition at line 268 of file m_admin.php.

268  {
269  global $msg, $db;
270  $msg->debug("admin","get_creator",$uid);
271  if (!$this->enabled) {
272  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
273  return false;
274  }
275 
276  $db->query("SELECT m.*, parent.login as parentlogin FROM membres as m LEFT JOIN membres as parent ON (parent.uid = m.creator) WHERE m.uid= ?;", array($uid));
277 
278  if ($db->num_rows()) {
279  $db->next_record();
280  $c = $db->Record;
281  } else {
282  $msg->raise("ERROR", "admin", _("Account not found"));
283  return false;
284  }
285 
286  $db->query("SELECT * FROM local WHERE uid= ?;", array($uid));
287  if ($db->num_rows()) {
288  $db->next_record();
289  reset($db->Record);
290  while (list($key, $val) = each($db->Record)) {
291  $c[$key] = $val;
292  }
293  }
294 
295  $db->query("SELECT count(*) as nbcreated FROM membres WHERE creator= ?;", array($uid));
296  if ($db->num_rows()) {
297  $db->next_record();
298  reset($db->Record);
299  while (list($key, $val) = each($db->Record)) {
300  $c[$key] = $val;
301  }
302  }
303 
304  return $c;
305  }
$val
Definition: tempovars.php:15
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14

References $c, $db, $key, $msg, $uid, $val, and enabled.

Referenced by get_creator_list().

◆ get_creator_list()

m_admin::get_creator_list ( )

Returns an array with the known information about resellers (uid, login, number of accounts) Does not include account 2000 in the list.

May only be called by the admin account (2000) If there are no reseller accounts, returns an empty array.

Parameters
globaltype $msg
globaltype $mem
globaltype $cuid
Returns
boolean

Definition at line 468 of file m_admin.php.

468  {
469  global $msg, $cuid;
470 
471  $creators = array();
472 
473  $msg->debug("admin", "get_creator_list");
474  if (!$this->enabled) {
475  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
476  return false;
477  }
478 
479  $db = new DB_System();
480  $db->query("SELECT DISTINCT creator FROM membres WHERE creator <> 0 ORDER BY creator ASC;");
481  if ($db->num_rows()) {
482  while ($db->next_record()) {
483  $creators[] = $this->get_creator($db->f("creator"));
484  }
485  }
486  $creators2 = array();
487  foreach ($creators as $cc) {
488  $creators2[$cc['uid']] = $cc;
489  }
490  return $creators2;
491  }
get_creator($uid)
Returns the known information about a specific hosted account.
Definition: m_admin.php:268

References $cuid, $db, $msg, enabled, and get_creator().

◆ get_list()

m_admin::get_list (   $all = 0,
  $creator = 0,
  $pattern = FALSE,
  $pattern_type = FALSE 
)

@TODO :EM: those request should have been escaped Returns the list of the hosted accounts

Returns all what we know about ALL the accounts (contents of the tables membres et local) Check for super-admin accounts

Parameters

Definition at line 343 of file m_admin.php.

343  {
344  global $msg, $mem, $cuid;
345  $msg->debug("admin", "get_list");
346  if (!$this->enabled) {
347  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
348  return false;
349  }
350  $db = new DB_System();
351 
352 
353  if ($pattern) {
354 
355  if ($pattern_type === 'domaine') {
356 
357  $request = 'SELECT compte AS uid FROM domaines WHERE 1';
358 
359  if ($pattern && preg_match('/[.a-zA-Z0-9]+/', $pattern)) {
360  $request .= sprintf(' AND domaine LIKE "%%%s%%"', $pattern);
361  }
362  if ($creator) {
363  $request .= sprintf(' AND compte in (select uid from membres where creator = "%s" ) ', $creator);
364  }
365  if ($mem->user['uid'] != 2000 && !$all) {
366  $request .= sprintf(' AND compte in (select uid from membres where creator = "%s") ', $cuid);
367  }
368 
369  $request .= ' GROUP BY uid';
370  } elseif ($pattern_type === 'login') {
371 
372  $request = 'SELECT uid FROM membres WHERE 1';
373 
374  if ($pattern && preg_match('/[a-zA-Z0-9]+/', $pattern)) {
375  $request .= sprintf(' AND login LIKE "%%%s%%"', $pattern);
376  }
377  if ($creator) {
378  $request .= sprintf(' AND creator = "%s"', $creator);
379  }
380  if ($mem->user['uid'] != 2000 && !$all) {
381  $request .= sprintf(' AND creator = "%s"', $cuid);
382  }
383  $request .= ' ORDER BY login;';
384  } else {
385  $msg->raise("ERROR", "admin", _("Invalid pattern type provided. Are you even performing a legitimate action?"));
386  return FALSE;
387  }
388  } else {
389  if ($creator) {
390  // Limit listing to a specific reseller
391  $request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;";
392  } elseif ($mem->user['uid'] == 2000 || $all) {
393  $request = "SELECT uid FROM membres ORDER BY login;";
394  } else {
395  $request = "SELECT uid FROM membres WHERE creator='" . $cuid . "' ORDER BY login;";
396  }
397  }
398 
399  $db->query($request);
400 
401  if ($db->num_rows()) {
402  $c = array();
403  while ($db->next_record()) {
404  $c[$db->f("uid")] = $this->get($db->f("uid"));
405  }
406  return $c;
407  } else {
408  return false;
409  }
410  }
$request

References $c, $cuid, $db, $mem, $msg, $request, elseif, and enabled.

◆ get_login_by_uid()

m_admin::get_login_by_uid (   $uid)

return the name of an alternc account

Parameters
globaltype $db
type$uid
Returns
null if missing

Definition at line 186 of file m_admin.php.

186  {
187  global $db;
188  $db->query("SELECT login FROM membres WHERE uid= ?;", array($uid));
189  if (!$db->next_record()) {
190  return null;
191  }
192  return $db->f('login');
193  }

◆ get_uid_by_login()

m_admin::get_uid_by_login (   $login)

return the uid of an alternc account

Parameters
globaltype $db
type$login
Returns
null

Definition at line 169 of file m_admin.php.

169  {
170  global $db;
171  $db->query("SELECT uid FROM membres WHERE login= ?;", array($login));
172  if (!$db->next_record()) {
173  return null;
174  }
175  return $db->f('uid');
176  }

◆ getadmin()

m_admin::getadmin ( )

Get the login name of the main administrator account.

Parameters
globalm_mysql $db
Returns
string the login name of admin, like 'root' for older alterncs

Definition at line 1394 of file m_admin.php.

1394  {
1395  global $db;
1396  $db->query("SELECT login FROM membres WHERE uid=2000;");
1397  $db->next_record();
1398  return $db->f("login");
1399  }

References $db.

◆ gettld()

m_admin::gettld (   $tld)

Add a new TLD to the list of the authorized TLDs.

Parameters
globalm_mysql $db
globalm_messages $msg
string$tldtop-level domain to add (org, com...)
Returns
boolean TRUE if the tld has been successfully added, FALSE if not.

Definition at line 1273 of file m_admin.php.

1273  {
1274  global $db, $msg;
1275  $db->query("SELECT mode FROM tld WHERE tld= ?;", array($tld));
1276  if (!$db->next_record()) {
1277  $msg->raise("ERROR", "admin", _("This TLD does not exist"));
1278  return false;
1279  }
1280  return $db->Record["mode"];
1281  }

References $db, and $msg.

◆ hook_admin_add_member()

m_admin::hook_admin_add_member ( )

AlternC's standard function called when a user is created This sends an email if configured through the interface.

Parameters
globalm_messages $msg
globalint $cuid
globalstring $L_FQDN
globalstring $L_HOSTING
Returns
boolean

Definition at line 688 of file m_admin.php.

688  {
689  global $msg, $cuid, $L_FQDN, $L_HOSTING;
690  $dest = variable_get('new_email', '0', 'An email will be sent to this address when new accounts are created if set.', array('desc' => 'Enabled', 'type' => 'boolean'));
691  if (!$dest) {
692  return false;
693  }
694  $db = new DB_System();
695  if (!$db->query("SELECT m.*, parent.login as parentlogin FROM membres m LEFT JOIN membres parent ON parent.uid=m.creator WHERE m.uid= ?", array($cuid))) {
696  $msg->raise("ERROR", "admin", sprintf(_("query failed: %s "), $db->Error));
697  return false;
698  }
699  if ($db->next_record()) {
700  // TODO: put that string into gettext !
701  $mail = '
702  A new AlternC account was created on %fqdn by %creator.
703 
704  Account details
705  ---------------
706 
707  login: %login (%uid)
708  email: %mail
709  createor: %creator (%cuid)
710  can change password: %canpass
711  type: %type
712  notes: %notes
713  ';
714  $mail = strtr($mail, array('%fqdn' => $L_FQDN,
715  '%creator' => $db->Record['parentlogin'],
716  '%uid' => $db->Record['uid'],
717  '%login' => $db->Record['login'],
718  '%mail' => $db->Record['mail'],
719  '%cuid' => $db->Record['creator'],
720  '%canpass' => $db->Record['canpass'],
721  '%type' => $db->Record['type'],
722  '%notes' => $db->Record['notes']));
723  $subject = sprintf(_("New account %s from %s on %s"), $db->Record['login'], $db->Record['parentlogin'], $L_HOSTING);
724  if (mail($dest, $subject, $mail, "From: postmaster@$L_FQDN")) {
725  //sprintf(_("Email successfully sent to %s"), $dest);
726  return true;
727  } else {
728  $msg->raise("ERROR", "admin", sprintf(_("Cannot send email to %s"), $dest));
729  return false;
730  }
731  } else {
732  $msg->raise("ERROR", "admin", sprintf(_("Query failed: %s"), $db->Error));
733  return false;
734  }
735  }

References $cuid, $db, $msg, and variable_get().

◆ hook_menu()

m_admin::hook_menu ( )

Hook function called by the menu class to add menu to the left panel.

Parameters
globaltype $mem
globaltype $cuid
globaltype $debug_alternc
globaltype $L_INOTIFY_UPDATE_DOMAIN
Returns
boolean|string

Definition at line 76 of file m_admin.php.

76  {
77  global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN;
78  if (!$mem->checkRight()) {
79  return false;
80  }
81  $obj = array(
82  'title' => _("Administration"),
83  'link' => 'toggle',
84  'class' => 'adminmenu',
85  'pos' => 10,
86  'links' =>
87  array(
88  array(
89  'txt' => _("Manage AlternC accounts"),
90  'url' => 'adm_list.php',
91  'class' => 'adminmenu'
92  ),
93  array(
94  'txt' => _("User Quotas"),
95  'url' => 'quotas_users.php?mode=4',
96  'class' => 'adminmenu'
97  ),
98  )
99  );
100 
101  if ($cuid == 2000) { // only ADMIN, not available to subadmins
102  $obj['links'][] = array(
103  'txt' => _("Admin Control Panel"),
104  'url' => 'adm_panel.php',
105  'class' => 'adminmenu'
106  );
107  $obj['links'][] = array(
108  'txt' => _("PhpMyAdmin"),
109  'url' => 'sql_pma_sso.php',
110  'class' => 'adminmenu',
111  'target' => '_blank',
112  );
113  $obj['links'][] = array(
114  'txt' => ($debug_alternc->status) ? _("Switch debug Off") : _("Switch debug On"),
115  'url' => "alternc_debugme.php?enable=" . ($debug_alternc->status ? "0" : "1"),
116  'class' => 'adminmenu'
117  );
118  if (empty($L_INOTIFY_UPDATE_DOMAIN) || file_exists("$L_INOTIFY_UPDATE_DOMAIN")) {
119  $obj['links'][] = array(
120  'txt' => _("Applying..."),
121  'url' => 'javascript:alert(\'' . _("Domain changes are already applying") . '\');',
122  'class' => 'adminmenu',
123  );
124  } else {
125  $obj['links'][] = array(
126  'txt' => _("Apply changes"),
127  'url' => 'adm_update_domains.php',
128  'class' => 'adminmenu',
129  'onclick' => 'return confirm("' . addslashes(_("Server configuration changes are applied every 5 minutes. Do you want to do it right now?")) . '");',
130  );
131  } // L_INOTIFY_UPDATE_DOMAIN
132  } // cuid == 2000
133 
134 
135  return $obj;
136  }

References $cuid, and $mem.

◆ listPasswordPolicies()

m_admin::listPasswordPolicies ( )

List the password policies currently installed in the policy table.

Parameters
globalm_mysql $db
globalarray $classes
globalm_hooks $hooks
Returns
array an indexed array of associative array from the MySQL "policy" table

Definition at line 1410 of file m_admin.php.

1410  {
1411  global $db, $hooks;
1412  $tmp1 = array();
1413  $tmp2 = array();
1414  $policies = array();
1415  $db->query("SELECT * FROM policy;");
1416  while ($db->next_record()) {
1417  $tmp1[$db->Record["name"]] = $db->Record;
1418  }
1419  $tmp3 = $hooks->invoke("alternc_password_policy");
1420  foreach ($tmp3 as $v) {
1421  foreach ($v as $l => $m) {
1422  $tmp2[$l] = $m;
1423  }
1424  }
1425  foreach ($tmp2 as $k => $v) {
1426  if (!isset($tmp1[$k])) {
1427  // Default policy :
1428  $db->query("INSERT INTO policy SET name= ?, minsize=0, maxsize=64, classcount=0, allowlogin=0;", array($k));
1429  $tmp1[$k] = array(
1430  "minsize" => 0, "maxsize" => 64, "classcount" => 0, "allowlogin" => 0
1431  );
1432  }
1433  $policies[$k] = $tmp1[$k];
1434  $policies[$k]["description"] = _($v);
1435  unset($tmp1[$k]);
1436  }
1437  foreach ($tmp1 as $k => $v) {
1438  // Delete disabled modules :
1439  $db->query("DELETE FROM policy WHERE name= ?;", array($k));
1440  }
1441  return $policies;
1442  }

References $db, and $hooks.

Referenced by checkPolicy().

◆ listtld()

m_admin::listtld ( )

List of the authorized TLDs Returns the list of the authorized TLDs and also the way they are authorized.

A TLD is the last members (or the last two) of a domain. For example, "com", "org" etc... AlternC keeps a table containing the list of the TLDs authorized to be installed on the server with the instructions to validate the installation of a domain for each TLD (if necessary).

Parameters
globalm_mysql $db
Returns
array An associative array like $r["tld"], $r["mode"] where tld is the tld and mode is the authorized mode.

Definition at line 1088 of file m_admin.php.

1088  {
1089  global $db;
1090  $db->query("SELECT tld,mode FROM tld ORDER BY tld;");
1091  $c = array();
1092  while ($db->next_record()) {
1093  $c[] = $db->Record;
1094  }
1095  return $c;
1096  }

References $c, and $db.

◆ lock_mem()

m_admin::lock_mem (   $uid)

Lock an account.

Lock an account and prevent the user to access its account.

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 811 of file m_admin.php.

811  {
812  global $msg, $db;
813  $msg->log("admin", "lock_mem", $uid);
814  if (!$this->enabled) {
815  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
816  return false;
817  }
818  $db = new DB_System();
819  if ($db->query("UPDATE membres SET enabled='0' WHERE uid= ?;", array($uid))) {
820  return true;
821  } else {
822  $msg->raise("ERROR", "admin", _("Account not found"));
823  return false;
824  }
825  }

References $db, $msg, $uid, and enabled.

◆ mailallmembers()

m_admin::mailallmembers (   $subject,
  $message,
  $from 
)

Send an email to all AlternC's accounts.

Parameters
globaltype $msg
globaltype $mem
globaltype $cuid
globaltype $db
string$subjectSubject of the email to send
string$messageMessage to send
string$fromExpeditor of that email
Returns
boolean

Definition at line 425 of file m_admin.php.

425  {
426  global $msg, $db;
427  $msg->log("admin", "mailallmembers");
428  if (!$this->enabled) {
429  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
430  return false;
431  }
432  $subject = trim($subject);
433  $message = trim($message);
434  $from = trim($from);
435 
436  if (empty($subject) || empty($message) || empty($from)) {
437  $msg->raise("ERROR", "admin", _("Subject, message and sender are mandatory"));
438  return false;
439  }
440  //@todo remove cf functions.php
441  if (checkmail($from) != 0) {
442  $msg->raise("ERROR", "admin", _("Sender is syntaxically incorrect"));
443  return false;
444  }
445 
446  @set_time_limit(1200);
447  $db->query("SELECT DISTINCT mail FROM membres WHERE mail!='';");
448  while ($db->next_record()) {
449  // Can't do BCC due to postfix limitation
450  // FIXME: use phpmailer, far better for mass-mailing than sendmail (reply-to issue among others)
451  mail($db->f('mail'), $subject, $message, null, "-f$from");
452  }
453  return true;
454  }

References $db, $msg, checkmail(), and enabled.

◆ normal2su()

m_admin::normal2su (   $uid)

Turns a common account into a super-admin account.

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
Returns
boolean

Definition at line 1035 of file m_admin.php.

1035  {
1036  global $msg, $db;
1037  $db->query("SELECT su FROM membres WHERE uid= ?;", array($uid));
1038  if (!$db->next_record()) {
1039  $msg->raise("ERROR", "admin", _("Account not found"));
1040  return false;
1041  }
1042  if ($db->Record["su"] != 0) {
1043  $msg->raise("ERROR", "admin", _("This account is ALREADY an administrator account"));
1044  return false;
1045  }
1046  $db->query("UPDATE membres SET su=1 WHERE uid= ?;", array($uid));
1047  return true;
1048  }

References $db, $msg, and $uid.

◆ onesu()

m_admin::onesu ( )
Parameters
globaltype $db
Returns
boolean TRUE if there is only one admin account (allow the program to prevent the destruction of the last admin account)

Definition at line 314 of file m_admin.php.

314  {
315  global $db;
316  $db->query("SELECT COUNT(*) AS cnt FROM membres WHERE su=1");
317  $db->next_record();
318  return ($db->f("cnt") == 1);
319  }

References $db.

◆ renew_get_expiring_accounts()

m_admin::renew_get_expiring_accounts ( )

Get the expired/about to expire accounts.

Parameters
globalm_mysql $db
Returns
array The recordset of the corresponding accounts

Definition at line 1006 of file m_admin.php.

1006  {
1007  global $db;
1008 
1009  if (!$db->query("SELECT *, m.renewed + INTERVAL duration MONTH 'expiry'," .
1010  " CASE WHEN m.duration IS NULL THEN 0" .
1011  " WHEN m.renewed + INTERVAL m.duration MONTH <= NOW() THEN 3" .
1012  " WHEN m.renewed <= NOW() THEN 2" .
1013  " ELSE 1 END 'status' FROM membres m, local l" .
1014  " WHERE m.uid = l.uid" .
1015  " HAVING status=2 or status=3 ORDER BY status DESC, expiry;")) {
1016  return false;
1017  } else {
1018  $res = array();
1019  while ($db->next_record()) {
1020  $res[] = $db->Record;
1021  }
1022  return $res;
1023  }
1024  }
$res
Definition: index.php:111

References $db, and $res.

◆ renew_get_expiry()

m_admin::renew_get_expiry (   $uid)

Get the expiry date for an account.

Parameters
int$uidThe uid number of the account
Returns
string The expiry date, a string as printed by MySQL

Definition at line 970 of file m_admin.php.

970  {
971  $jj = $this->get($uid);
972  if (isset($jj) && isset($jj['expiry']) && !empty($jj['expiry'])) {
973  return $jj['expiry'];
974  }
975  return '';
976  }

References $uid.

◆ renew_get_status()

m_admin::renew_get_status (   $uid)

Get the expiry status for an account.

Parameters
int$uidThe uid number of the account
Returns
integer The expiry status: 0: account does not expire 1: expires in more than duration, 2: expires within the duration 3: has expired past the duration

Definition at line 989 of file m_admin.php.

989  {
990  $jj = $this->get($uid);
991 
992  if (isset($jj) && isset($jj['status']) && !empty($jj['status'])) {
993  return $jj['status'];
994  }
995 
996  return 0;
997  }

References $uid.

◆ renew_mem()

m_admin::renew_mem (   $uid,
  $periods = 1 
)

Renew an account.

Renew an account for its duration

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
int$periodsThe new duration, in months, of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 920 of file m_admin.php.

920  {
921  global $msg, $db;
922 
923  $periods = intval($periods);
924  if ($periods == 0) {
925  return false;
926  }
927  if ($db->query("UPDATE membres SET renewed = renewed + INTERVAL (duration * ?) MONTH WHERE uid= ?;", array($periods, $uid))) {
928  return true;
929  } else {
930  $msg->raise("ERROR", "admin", _("Account not found"));
931  return false;
932  }
933  }

References $db, $msg, and $uid.

◆ renew_update()

m_admin::renew_update (   $uid,
  $duration 
)

Update the duration information for an account.

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
int$durationThe new duration, in months, of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 945 of file m_admin.php.

945  {
946  global $msg, $db;
947 
948  if ($duration == 0) {
949  if ($db->query("UPDATE membres SET duration = NULL, renewed = NULL WHERE uid= ?;", array($uid))) {
950  return true;
951  }
952  } else {
953  if ($db->query("UPDATE membres SET duration = ? WHERE uid= ?", array($duration, $uid)) &&
954  $db->query("UPDATE membres SET renewed = NOW() WHERE uid= ? and renewed is null;", array($uid))) {
955  return true;
956  }
957  }
958 
959  $msg->raise("ERROR", "admin", _("Account not found"));
960  return false;
961  }

References $db, $msg, and $uid.

Referenced by add_mem(), and update_mem().

◆ selecttldmode()

m_admin::selecttldmode (   $current = false)

Prints the list of the actually authorized TLDs.

Parameters
boolean$currentValue to select in the list

Definition at line 1289 of file m_admin.php.

1289  {
1290  for ($i = 0; $i < count($this->tldmode); $i++) {
1291  echo "<option value=\"$i\"";
1292  if ($current == $i) {
1293  echo " selected=\"selected\"";
1294  }
1295  echo ">" . _($this->tldmode[$i]) . "</option>\n";
1296  }
1297  }

References $i.

◆ stop_if_jobs_locked()

m_admin::stop_if_jobs_locked ( )

Definition at line 152 of file m_admin.php.

152  {
153  if (file_exists(ALTERNC_LOCK_JOBS)) {
154  echo "There is a file " . ALTERNC_LOCK_JOBS . "\n";
155  echo "So no jobs are allowed\n";
156  echo "Did you launch alternc.install ?\n";
157  die();
158  }
159  }
const ALTERNC_LOCK_JOBS
Definition: bootstrap.php:16

◆ su2normal()

m_admin::su2normal (   $uid)

Turns a super-admin account into a common account.

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 1059 of file m_admin.php.

1059  {
1060  global $msg, $db;
1061  $db->query("SELECT su FROM membres WHERE uid= ?;", array($uid));
1062  if (!$db->next_record()) {
1063  $msg->raise("ERROR", "admin", _("Account not found"));
1064  return false;
1065  }
1066  if ($db->Record["su"] != 1) {
1067  $msg->raise("ERROR", "admin", _("This account is NOT an administrator account!"));
1068  return false;
1069  }
1070  $db->query("UPDATE membres SET su=0 WHERE uid= ?;", array($uid));
1071  return true;
1072  }

References $db, $msg, and $uid.

◆ unlock_mem()

m_admin::unlock_mem (   $uid)

UnLock an account.

UnLock an account and prevent the user to access its account.

Parameters
globalm_messages $msg
globalm_mysql $db
int$uidThe uid number of the account
Returns
boolean Returns FALSE if an error occurs, TRUE if not.

Definition at line 839 of file m_admin.php.

839  {
840  global $msg, $db;
841  $msg->log("admin", "unlock_mem", $uid);
842  if (!$this->enabled) {
843  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
844  return false;
845  }
846  $db = new DB_System();
847  if ($db->query("UPDATE membres SET enabled='1' WHERE uid= ?;", array($uid))) {
848  return true;
849  } else {
850  $msg->raise("ERROR", "admin", _("Account not found"));
851  return false;
852  }
853  }

References $db, $msg, $uid, and enabled.

◆ update_mem()

m_admin::update_mem (   $uid,
  $mail,
  $nom,
  $prenom,
  $pass,
  $enabled,
  $canpass,
  $type = 'default',
  $duration = 0,
  $notes = "",
  $reset_quotas = false 
)

Edit an account.

Change an account (in the tables membres and local). Prevents any manipulation of the account if the account $mid is not super-admin.

Parameters
globalm_messages $msg
globalm_mysql $db
globalint $cuid
globalm_quota $quota
int$uidThe uid number of the account we want to modify
string$mailNew email address of the account owner
string$nomNew name of the account owner
string$prenomNew first name of the account owner
string$passNew password (max. 64 characters)
string$enabled(value: 0 or 1) activates or desactivates the
boolean$canpass
int$typeNew type of account
int$duration
string$notes
boolean$reset_quotas
Returns
boolean Returns FALSE if an error occurs, TRUE if not

Definition at line 762 of file m_admin.php.

762  {
763  global $msg, $db, $quota;
764 
765  $msg->log("admin", "update_mem", $uid);
766 
767  if (!$this->enabled) {
768  $msg->raise("ERROR", "admin", _("-- Only administrators can access this page! --"));
769  return false;
770  }
771  $db = new DB_System();
772 
773  if ($pass) {
774  $pass = password_hash($pass, PASSWORD_BCRYPT);
775  $second_query = "UPDATE membres SET mail= ?, canpass= ?, enabled= ?, `type`= ?, notes= ? , pass = ? WHERE uid= ?;";
776  $second_query_args = array($mail, $canpass, $enabled, $type, $notes, $pass, $uid);
777  } else {
778  $second_query = "UPDATE membres SET mail= ?, canpass= ?, enabled= ?, `type`= ?, notes= ? WHERE uid= ?;";
779  $second_query_args = array($mail, $canpass, $enabled, $type, $notes, $uid);
780  }
781 
782  $old_mem = $this->get($uid);
783 
784  if(
785  ($db->query("UPDATE local SET nom= ?, prenom= ? WHERE uid=?;", array($nom, $prenom, $uid))) &&
786  ($db->query($second_query, $second_query_args))
787  ){
788  if ($reset_quotas == "on" || $type != $old_mem['type']) {
789  $quota->addquotas();
790  $quota->synchronise_user_profile();
791  }
792  $this->renew_update($uid, $duration);
793  return true;
794  } else {
795  $msg->raise("ERROR", "admin", _("Account not found"));
796  return false;
797  }
798  }
$enabled
$enabled tells if the logged user is super-admin or not
Definition: m_admin.php:32

References $db, $enabled, $msg, $uid, enabled, and renew_update().

Member Data Documentation

◆ $archive

m_admin::$archive = ''

Definition at line 41 of file m_admin.php.

◆ $enabled

m_admin::$enabled = 0

$enabled tells if the logged user is super-admin or not

Definition at line 32 of file m_admin.php.

Referenced by update_mem().

◆ $tldmode

m_admin::$tldmode = array()

List of the controls made for each TLD.

$tldmode is used by the administration panel, while choosing the authorized TLDs. It's an array of strings explaining the current state of the TLD.

Definition at line 40 of file m_admin.php.


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