You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-07-31 10:04:20 +03:00
Merge pull request #200 from doktoil-makresh/master
Support for password expiration, managed in PostFix Admin
This commit is contained in:
@ -260,6 +260,18 @@ function check_domain($domain) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get password expiration value for a domain
|
||||
* @param string $domain - a string that may be a domain
|
||||
* @return int password expiration value for this domain (DAYS, or zero if not enabled)
|
||||
*/
|
||||
function get_password_expiration_value ($domain) {
|
||||
$table_domain = table_by_key('domain');
|
||||
$query = "SELECT password_expiry FROM $table_domain WHERE domain='$domain'";
|
||||
$result = db_query ($query);
|
||||
$password_expiration_value = db_array ($result['result']);
|
||||
return $password_expiration_value[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* check_email
|
||||
@ -1871,7 +1883,7 @@ function db_delete($table, $where, $delete, $additionalwhere='') {
|
||||
* @param array $timestamp (optional) - array of fields to set to now() - default: array('created', 'modified')
|
||||
* @return int - number of inserted rows
|
||||
*/
|
||||
function db_insert($table, $values, $timestamp = array('created', 'modified')) {
|
||||
function db_insert ($table, $values, $timestamp = array('created', 'modified'), $timestamp_expiration = array('password_expiry') ) {
|
||||
$table = table_by_key($table);
|
||||
|
||||
foreach (array_keys($values) as $key) {
|
||||
@ -1886,6 +1898,19 @@ function db_insert($table, $values, $timestamp = array('created', 'modified')) {
|
||||
}
|
||||
}
|
||||
|
||||
global $CONF;
|
||||
if ($CONF['password_expiration_enabled'] == 'YES') {
|
||||
if ($table == 'mailbox') {
|
||||
$domain_dirty = $values['domain'];
|
||||
$domain = substr($domain_dirty, 1, -1); // really the update to the mailbox password_expiry should be based on a trigger, or a query like :
|
||||
// .... NOW() + INTERVAL domain.password_expiry DAY
|
||||
$password_expiration_value = get_password_expiration_value($domain);
|
||||
foreach($timestamp_expiration as $key) {
|
||||
$values[$key] = "now() + interval " . $password_expiration_value . " day";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql_values = "(" . implode(",", escape_string(array_keys($values))).") VALUES (".implode(",", $values).")";
|
||||
|
||||
$result = db_query("INSERT INTO $table $sql_values");
|
||||
@ -1934,6 +1959,19 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) {
|
||||
}
|
||||
}
|
||||
|
||||
global $CONF;
|
||||
if ($CONF['password_expiration_enabled'] == 'YES') {
|
||||
$where_type = explode('=',$where);
|
||||
$email = ($where_type[1]);
|
||||
$domain_dirty = explode('@',$email)[1];
|
||||
$domain = substr($domain_dirty, 0, -1);
|
||||
if ($table == 'mailbox') {
|
||||
$password_expiration_value = get_password_expiration_value($domain);
|
||||
$key = 'password_expiry';
|
||||
$sql_values[$key] = $key . " = now() + interval " . $password_expiration_value . " day";
|
||||
}
|
||||
}
|
||||
|
||||
$sql="UPDATE $table SET " . implode(",", $sql_values) . " WHERE $where";
|
||||
|
||||
$result = db_query($sql);
|
||||
@ -2190,6 +2228,36 @@ function gen_show_status($show_alias) {
|
||||
}
|
||||
}
|
||||
|
||||
// Vacation CHECK
|
||||
if ( $CONF['show_vacation'] == 'YES' ) {
|
||||
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = 1");
|
||||
if ($stat_result['rows'] == 1) {
|
||||
$stat_string .= "<span style='background-color:" . $CONF['show_vacation_color'] . "'>" . $CONF['show_status_text'] . "</span> ";
|
||||
} else {
|
||||
$stat_string .= $CONF['show_status_text'] . " ";
|
||||
}
|
||||
}
|
||||
|
||||
// Disabled CHECK
|
||||
if ( $CONF['show_disabled'] == 'YES' ) {
|
||||
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = 0");
|
||||
if ($stat_result['rows'] == 1) {
|
||||
$stat_string .= "<span style='background-color:" . $CONF['show_disabled_color'] . "'>" . $CONF['show_status_text'] . "</span> ";
|
||||
} else {
|
||||
$stat_string .= $CONF['show_status_text'] . " ";
|
||||
}
|
||||
}
|
||||
|
||||
// Expired CHECK
|
||||
if ( $CONF['show_expired'] == 'YES' ) {
|
||||
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND password_expiry <= now()");
|
||||
if ($stat_result['rows'] == 1) {
|
||||
$stat_string .= "<span style='background-color:" . $CONF['show_expired_color'] . "'>" . $CONF['show_status_text'] . "</span> ";
|
||||
} else {
|
||||
$stat_string .= $CONF['show_status_text'] . " ";
|
||||
}
|
||||
}
|
||||
|
||||
// POP/IMAP CHECK
|
||||
if ($CONF['show_popimap'] == 'YES') {
|
||||
$stat_delimiter = "";
|
||||
|
Reference in New Issue
Block a user