Example #1
0
 /**
  * called by $this->store() after storing $this->values in the database
  * can be used to update additional tables, call scripts etc.
  */
 protected function storemore()
 {
     # store list of allowed domains in the domain_admins table
     if (isset($this->values['domains'])) {
         if (is_array($this->values['domains'])) {
             $domains = $this->values['domains'];
         } elseif ($this->values['domains'] == '') {
             $domains = array();
         } else {
             $domains = explode(',', $this->values['domains']);
         }
         db_delete('domain_admins', 'username', $this->id, "AND domain != 'ALL'");
         foreach ($domains as $domain) {
             $values = array('username' => $this->id, 'domain' => $domain);
             db_insert('domain_admins', $values, array('created'));
             # TODO: check for errors
         }
     }
     # Temporary workaround to keep the database compatible with 2.3.x
     if (isset($this->values['superadmin'])) {
         if ($this->values['superadmin'] == 1) {
             $values = array('username' => $this->id, 'domain' => 'ALL');
             $where = db_where_clause(array('username' => $this->id, 'domain' => 'ALL'), $this->struct);
             $result = db_query("SELECT username from " . table_by_key('domain_admins') . " " . $where);
             if ($result['rows'] == 0) {
                 db_insert('domain_admins', $values, array('created'));
                 # TODO: check for errors
             }
         } else {
             db_delete('domain_admins', 'username', $this->id, "AND domain = 'ALL'");
         }
     }
     return true;
     # TODO: don't hardcode
 }
Example #2
0
 protected function initStruct()
 {
     # hide 'goto_mailbox' if $this->new
     # (for existing aliases, init() hides it for non-mailbox aliases)
     $mbgoto = 1 - $this->new;
     $this->struct = array('status' => pacol(0, 0, 0, 'html', '', '', '', '', array('not_in_db' => 1)), 'address' => pacol($this->new, 1, 1, 'mail', 'alias', 'pCreate_alias_catchall_text'), 'localpart' => pacol($this->new, 0, 0, 'text', 'alias', 'pCreate_alias_catchall_text', '', '', 1), 'domain' => pacol($this->new, 0, 1, 'enum', '', '', '', $this->allowed_domains), 'goto' => pacol(1, 1, 1, 'txtl', 'to', 'pEdit_alias_help', array()), 'is_mailbox' => pacol(0, 0, 1, 'int', '', '', 0, '', 0, 1, 'coalesce(__is_mailbox,0) as is_mailbox, __mailbox_username', 'LEFT JOIN ( ' . ' SELECT 1 as __is_mailbox, username as __mailbox_username ' . ' FROM ' . table_by_key('mailbox') . ' WHERE username IS NOT NULL ' . ' ) AS __mailbox ON __mailbox_username = address'), 'goto_mailbox' => pacol($mbgoto, $mbgoto, $mbgoto, 'bool', 'pEdit_alias_forward_and_store', '', 0, '', 1), 'on_vacation' => pacol(1, 0, 1, 'bool', 'pUsersMenu_vacation', '', 0, '', 1), 'created' => pacol(0, 0, 0, 'ts', 'created', ''), 'modified' => pacol(0, 0, 1, 'ts', 'last_modified', ''), 'active' => pacol(1, 1, 1, 'bool', 'active', '', 1), '_can_edit' => pacol(0, 0, 1, 'vnum', '', '', 0, '', array('select' => '1 as _can_edit')), '_can_delete' => pacol(0, 0, 1, 'vnum', '', '', 0, '', array('select' => '1 as _can_delete')));
 }
 protected function initStruct()
 {
     # TODO: shorter PALANG labels ;-)
     $super = $this->is_superadmin;
     $transp = min($super, Config::intbool('transport'));
     $editquota = min($super, Config::intbool('quota'));
     $quota = Config::intbool('quota');
     $edit_dom_q = min($super, Config::intbool('domain_quota'), $quota);
     $dom_q = min(Config::intbool('domain_quota'), $quota);
     $query_used_domainquota = 'round(coalesce(__total_quota/' . intval(Config::read('quota_multiplier')) . ',0))';
     # NOTE: There are dependencies between alias_count, mailbox_count and total_quota.
     # NOTE: If you disable "display in list" for one of them, the SQL query for the others might break.
     # NOTE: (Disabling all of them shouldn't be a problem.)
     $this->struct = array('domain' => pacol($this->new, 1, 1, 'text', 'domain', '', '', '', array('linkto' => 'list-virtual.php?domain=%s')), 'description' => pacol($super, $super, $super, 'text', 'description', ''), 'aliases' => pacol($super, $super, 0, 'num', 'aliases', 'pAdminEdit_domain_aliases_text', Config::read('aliases')), 'alias_count' => pacol(0, 0, 1, 'vnum', '', '', '', '', 0, 1, 'coalesce(__alias_count,0) - coalesce(__mailbox_count,0)  as alias_count', 'left join ( select count(*) as __alias_count, domain as __alias_domain from ' . table_by_key('alias') . ' group by domain) as __alias on domain = __alias_domain'), 'aliases_quot' => pacol(0, 0, 1, 'quot', 'aliases', '', 0, '', array('select' => db_quota_text('__alias_count - coalesce(__mailbox_count,0)', 'aliases', 'aliases_quot'))), '_aliases_quot_percent' => pacol(0, 0, 1, 'vnum', '', '', 0, '', array('select' => db_quota_percent('__alias_count - coalesce(__mailbox_count,0)', 'aliases', '_aliases_quot_percent'))), 'mailboxes' => pacol($super, $super, 0, 'num', 'mailboxes', 'pAdminEdit_domain_aliases_text', Config::read('mailboxes')), 'mailbox_count' => pacol(0, 0, 1, 'vnum', '', '', '', '', 0, 1, 'coalesce(__mailbox_count,0) as mailbox_count', 'left join ( select count(*) as __mailbox_count, sum(quota) as __total_quota, domain as __mailbox_domain from ' . table_by_key('mailbox') . ' group by domain) as __mailbox on domain = __mailbox_domain'), 'mailboxes_quot' => pacol(0, 0, 1, 'quot', 'mailboxes', '', 0, '', array('select' => db_quota_text('__mailbox_count', 'mailboxes', 'mailboxes_quot'))), '_mailboxes_quot_percent' => pacol(0, 0, 1, 'vnum', '', '', 0, '', array('select' => db_quota_percent('__mailbox_count', 'mailboxes', '_mailboxes_quot_percent'))), 'maxquota' => pacol($editquota, $editquota, $quota, 'num', 'pOverview_get_quota', 'pAdminEdit_domain_maxquota_text', Config::read('maxquota')), 'quota' => pacol($edit_dom_q, $edit_dom_q, 0, 'num', 'pAdminEdit_domain_quota', 'pAdminEdit_domain_maxquota_text', Config::read('domain_quota_default')), 'total_quota' => pacol(0, 0, 1, 'vnum', '', '', '', '', array('select' => "{$query_used_domainquota} AS total_quota")), 'total_quot' => pacol(0, 0, $dom_q, 'quot', 'pAdminEdit_domain_quota', '', 0, '', array('select' => db_quota_text($query_used_domainquota, 'quota', 'total_quot'))), '_total_quot_percent' => pacol(0, 0, $dom_q, 'vnum', '', '', 0, '', array('select' => db_quota_percent($query_used_domainquota, 'quota', '_total_quot_percent'))), 'transport' => pacol($transp, $transp, $transp, 'enum', 'transport', 'pAdminEdit_domain_transport_text', Config::read('transport_default'), Config::read('transport_options')), 'backupmx' => pacol($super, $super, 1, 'bool', 'pAdminEdit_domain_backupmx', '', 0), 'active' => pacol($super, $super, 1, 'bool', 'active', '', 1), 'default_aliases' => pacol($this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '', 1, '', 1), 'created' => pacol(0, 0, 0, 'ts', 'created', ''), 'modified' => pacol(0, 0, $super, 'ts', 'last_modified', ''), '_can_edit' => pacol(0, 0, 1, 'int', '', '', 0, '', 0, 1, $this->is_superadmin . ' as _can_edit'), '_can_delete' => pacol(0, 0, 1, 'int', '', '', 0, '', 0, 1, $this->is_superadmin . ' as _can_delete'));
 }
/**
 * db_update
 * Action: Updates a specified table
 * Call: db_update (string table, array values, string where)
 * @param String $table - table name
 * @param String - WHERE condition
 * @param array - key/value map of data to insert into the table.
 * @param array (optional) - array of fields to set to now()
 * @return int - number of updated rows
 */
function db_update($table, $where, $values, $timestamp = array())
{
    $table = table_by_key($table);
    foreach (array_keys($values) as $key) {
        $sql_values[$key] = escape_string($key) . "='" . escape_string($values[$key]) . "'";
    }
    foreach ($timestamp as $key) {
        $sql_values[$key] = escape_string($key) . "=now()";
    }
    $sql = "UPDATE {$table} SET " . implode(",", $sql_values) . " WHERE {$where}";
    $result = db_query($sql);
    return $result['rows'];
}
Example #5
0
if ($display_mailbox_aliases) {
    $sql_select .= ", {$table_alias}.goto ";
    $sql_join .= " LEFT JOIN {$table_alias} ON {$table_mailbox}.username={$table_alias}.address ";
}
if (Config::bool('vacation_control_admin')) {
    $table_vacation = table_by_key('vacation');
    $sql_select .= ", {$table_vacation}.active AS v_active ";
    $sql_join .= " LEFT JOIN {$table_vacation} ON {$table_mailbox}.username={$table_vacation}.email ";
}
if (Config::bool('used_quotas') && Config::bool('new_quota_table')) {
    $table_quota2 = table_by_key('quota2');
    $sql_select .= ", {$table_quota2}.bytes as current ";
    $sql_join .= " LEFT JOIN {$table_quota2} ON {$table_mailbox}.username={$table_quota2}.username ";
}
if (Config::bool('used_quotas') && !Config::bool('new_quota_table')) {
    $table_quota = table_by_key('quota');
    $sql_select .= ", {$table_quota}.current ";
    $sql_join .= " LEFT JOIN {$table_quota} ON {$table_mailbox}.username={$table_quota}.username ";
    $sql_where .= " AND ( {$table_quota}.path='quota/storage' OR  {$table_quota}.path IS NULL ) ";
}
$mailbox_pagebrowser_query = "{$sql_from}\n{$sql_join}\n{$sql_where}\n{$sql_order}";
$query = "{$sql_select}\n{$mailbox_pagebrowser_query}\n{$sql_limit}";
$result = db_query($query);
if ($result['rows'] > 0) {
    $delimiter = preg_quote($CONF['recipient_delimiter'], "/");
    $goto_single_rec_del = "";
    $tMailbox = array();
    while ($row = db_array($result['result'])) {
        if ($display_mailbox_aliases) {
            $goto_split = explode(",", $row['goto']);
            $row['goto_mailbox'] = 0;
function upgrade_6()
{
    $table = table_by_key('originaltemplatesdetails');
    db_query_one("insert  into " . $table . " (`template_type_id`,`template_framework`,`template_name`,`description`,`date_uploaded`,`display_name`,`display_id`,`access_rights`,`active`) values (17,'decision','decision','A template for presenting a series of questions to reach a solution to a problem.','2009-01-01','Decision Tree Template',0,'*',1)");
    return true;
}
Example #7
0
         $lostpw_error = 1;
     } else {
         list($lostpw_error, $lostpw_result) = check_setup_password(safepost('setup_password'), 1);
         $setupMessage = $lostpw_result;
         $setuppw = "changed";
     }
 } elseif (safepost("form") == "createadmin") {
     # "create admin" form submitted
     list($pw_check_error, $pw_check_result) = check_setup_password(safepost('setup_password'));
     if ($pw_check_result != 'pass_OK') {
         $error += 1;
         $setupMessage = $pw_check_result;
     }
     if ($error == 0 && $pw_check_result == 'pass_OK') {
         // XXX need to ensure domains table includes an 'ALL' entry.
         $table_domain = table_by_key('domain');
         $r = db_query("SELECT * FROM {$table_domain} WHERE domain = 'ALL'");
         if ($r['rows'] == 0) {
             db_insert('domain', array('domain' => 'ALL', 'description' => '', 'transport' => ''));
             // all other fields should default through the schema.
         }
         $values = array('username' => safepost('username'), 'password' => safepost('password'), 'password2' => safepost('password2'), 'superadmin' => 1, 'domains' => array(), 'active' => 1);
         list($error, $setupMessage, $errormsg) = create_admin($values);
         if ($error != 0) {
             $tUsername = htmlentities($values['username']);
         } else {
             $setupMessage .= "<p>You are done with your basic setup. ";
             $setupMessage .= "<p><b>You can now <a href='login.php'>login to PostfixAdmin</a> using the account you just created.</b>";
         }
     }
 }
Example #8
0
 /**
  * @param string $subject
  * @param string $body
  * @param string $interval_time
  * @param date $activeFrom
  * @param date $activeUntil
  */
 function set_away($subject, $body, $interval_time, $activeFrom, $activeUntil)
 {
     $this->remove();
     // clean out any notifications that might already have been sent.
     $E_username = escape_string($this->username);
     $activeFrom = date("Y-m-d 00:00:00", strtotime($activeFrom));
     # TODO check if result looks like a valid date
     $activeUntil = date("Y-m-d 23:59:59", strtotime($activeUntil));
     # TODO check if result looks like a valid date
     list(, $domain) = explode('@', $this->username);
     $vacation_data = array('email' => $this->username, 'domain' => $domain, 'subject' => $subject, 'body' => $body, 'interval_time' => $interval_time, 'active' => db_get_boolean(true), 'activefrom' => $activeFrom, 'activeuntil' => $activeUntil);
     // is there an entry in the vacaton table for the user, or do we need to insert?
     $table_vacation = table_by_key('vacation');
     $result = db_query("SELECT * FROM {$table_vacation} WHERE email = '{$E_username}'");
     if ($result['rows'] == 1) {
         $result = db_update('vacation', 'email', $this->username, $vacation_data);
     } else {
         $result = db_insert('vacation', $vacation_data);
     }
     # TODO error check
     # TODO wrap whole function in db_begin / db_commit (or rollback)?
     return $this->updateAlias(1);
 }
Example #9
0
    }
} elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isset($_POST['fDomain'])) {
        $fDomain = escape_string($_POST['fDomain']);
    }
} else {
    die('Unknown request method');
}
if (!(check_owner($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))) {
    $error = 1;
    flash_error($PALANG['pViewlog_result_error']);
}
// we need to initialize $tLog as an array!
$tLog = array();
if ($error != 1) {
    $table_log = table_by_key('log');
    $query = "SELECT timestamp,username,domain,action,data FROM {$table_log} WHERE domain='{$fDomain}' ORDER BY timestamp DESC LIMIT 10";
    if (db_pgsql()) {
        $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM {$table_log} WHERE domain='{$fDomain}' ORDER BY timestamp DESC LIMIT 10";
    }
    $result = db_query($query);
    if ($result['rows'] > 0) {
        while ($row = db_array($result['result'])) {
            if (db_pgsql()) {
                $row['timestamp'] = gmstrftime('%c %Z', $row['timestamp']);
            }
            $tLog[] = $row;
        }
    }
}
for ($i = 0; $i < count($tLog); $i++) {
function create_admin($fUsername, $fPassword, $fPassword2, $fDomains, $no_generate_password = 0)
{
    global $PALANG;
    global $CONF;
    $error = 0;
    $tMessage = '';
    $pAdminCreate_admin_username_text = '';
    $pAdminCreate_admin_password_text = '';
    if (!check_email($fUsername)) {
        $error = 1;
        $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text_error1'];
    }
    if (empty($fUsername) or admin_exist($fUsername)) {
        $error = 1;
        $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text_error2'];
    }
    if (empty($fPassword) or empty($fPassword2) or $fPassword != $fPassword2) {
        if (empty($fPassword) and empty($fPassword2) and $CONF['generate_password'] == "YES" && $no_generate_password == 0) {
            $fPassword = generate_password();
        } else {
            $error = 1;
            $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text'];
            $pAdminCreate_admin_password_text = $PALANG['pAdminCreate_admin_password_text_error'];
        }
    }
    if ($error != 1) {
        $password = pacrypt($fPassword);
        $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text'];
        $result = db_query("INSERT INTO " . table_by_key('admin') . " (username,password,created,modified) VALUES ('{$fUsername}','{$password}',NOW(),NOW())");
        if ($result['rows'] != 1) {
            $tMessage = $PALANG['pAdminCreate_admin_result_error'] . "<br />({$fUsername})<br />";
        } else {
            if (!empty($fDomains[0])) {
                for ($i = 0; $i < sizeof($fDomains); $i++) {
                    $domain = $fDomains[$i];
                    $result = db_query("INSERT INTO " . table_by_key('domain_admins') . " (username,domain,created) VALUES ('{$fUsername}','{$domain}',NOW())");
                }
            }
            $tMessage = $PALANG['pAdminCreate_admin_result_success'] . "<br />({$fUsername}";
            if ($CONF['generate_password'] == "YES" && $no_generate_password == 0) {
                $tMessage .= " / {$fPassword})</br />";
            } else {
                if ($CONF['show_password'] == "YES" && $no_generate_password == 0) {
                    $tMessage .= " / {$fPassword})</br />";
                } else {
                    $tMessage .= ")</br />";
                }
            }
        }
    }
    # TODO: should we log creation, editing and deletion of admins?
    # Note: needs special handling in viewlog, because domain is empty
    # db_log ($SESSID_USERNAME, '', 'create_admin', "$fUsername");
    return array($error, $tMessage, $pAdminCreate_admin_username_text, $pAdminCreate_admin_password_text);
}
Example #11
0
function gen_show_status($show_alias)
{
    global $CONF;
    $table_alias = table_by_key('alias');
    $stat_string = "";
    $show_alias = escape_string($show_alias);
    $stat_goto = "";
    $stat_result = db_query("SELECT goto FROM {$table_alias} WHERE address='{$show_alias}'");
    if ($stat_result['rows'] > 0) {
        $row = db_row($stat_result['result']);
        $stat_goto = $row[0];
    }
    if (!empty($CONF['recipient_delimiter'])) {
        $delimiter = preg_quote($CONF['recipient_delimiter'], "/");
        $delimiter_regex = '/' . $delimiter . '[^' . $delimiter . '@]*@/';
    }
    // UNDELIVERABLE CHECK
    if ($CONF['show_undeliverable'] == 'YES') {
        $gotos = array();
        $gotos = explode(',', $stat_goto);
        $undel_string = "";
        //make sure this alias goes somewhere known
        $stat_ok = 1;
        while (($g = array_pop($gotos)) && $stat_ok) {
            list(, $stat_domain) = explode('@', $g);
            $stat_delimiter = "";
            if (!empty($CONF['recipient_delimiter'])) {
                $stat_delimiter = "OR address = '" . preg_replace($delimiter_regex, "@", $g) . "'";
            }
            $stat_result = db_query("SELECT address FROM {$table_alias} WHERE address = '{$g}' OR address = '@{$stat_domain}' {$stat_delimiter}");
            if ($stat_result['rows'] == 0) {
                $stat_ok = 0;
            }
            if ($stat_ok == 0) {
                if ($stat_domain == $CONF['vacation_domain'] || in_array($stat_domain, $CONF['show_undeliverable_exceptions'])) {
                    $stat_ok = 1;
                }
            }
        }
        // while
        if ($stat_ok == 0) {
            $stat_string .= "<span style='background-color:" . $CONF['show_undeliverable_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
        } else {
            $stat_string .= $CONF['show_status_text'] . "&nbsp;";
        }
    }
    // POP/IMAP CHECK
    if ($CONF['show_popimap'] == 'YES') {
        $stat_delimiter = "";
        if (!empty($CONF['recipient_delimiter'])) {
            $stat_delimiter = ',' . preg_replace($delimiter_regex, "@", $stat_goto);
        }
        //if the address passed in appears in its own goto field, its POP/IMAP
        # TODO: or not (might also be an alias loop) -> check mailbox table!
        if (preg_match('/,' . $show_alias . ',/', ',' . $stat_goto . $stat_delimiter . ',')) {
            $stat_string .= "<span  style='background-color:" . $CONF['show_popimap_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
        } else {
            $stat_string .= $CONF['show_status_text'] . "&nbsp;";
        }
    }
    // CUSTOM DESTINATION CHECK
    if (count($CONF['show_custom_domains']) > 0) {
        for ($i = 0; $i < sizeof($CONF['show_custom_domains']); $i++) {
            if (preg_match('/^.*' . $CONF['show_custom_domains'][$i] . '.*$/', $stat_goto)) {
                $stat_string .= "<span  style='background-color:" . $CONF['show_custom_colors'][$i] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
            } else {
                $stat_string .= $CONF['show_status_text'] . "&nbsp;";
            }
        }
    } else {
        $stat_string .= ";&nbsp;";
    }
    //   $stat_string .= "<span style='background-color:green'> &nbsp; </span> &nbsp;" .
    //                  "<span style='background-color:blue'> &nbsp; </span> &nbsp;";
    return $stat_string;
}
Example #12
0
     include "templates/menu.php";
     include "templates/message.php";
     include "templates/footer.php";
 } else {
     fwrite($fh, $header);
     $tables = array('admin', 'alias', 'config', 'domain', 'domain_admins', 'fetchmail', 'log', 'mailbox', 'vacation', 'vacation_notification');
     for ($i = 0; $i < sizeof($tables); ++$i) {
         $result = db_query("SHOW CREATE TABLE " . table_by_key($tables[$i]));
         if ($result['rows'] > 0) {
             while ($row = db_array($result['result'])) {
                 fwrite($fh, "{$row['1']};\n\n");
             }
         }
     }
     for ($i = 0; $i < sizeof($tables); ++$i) {
         $result = db_query("SELECT * FROM " . table_by_key($tables[$i]));
         if ($result['rows'] > 0) {
             while ($row = db_assoc($result['result'])) {
                 foreach ($row as $key => $val) {
                     $fields[] = $key;
                     $values[] = $val;
                 }
                 fwrite($fh, "INSERT INTO " . $tables[$i] . " (" . implode(',', $fields) . ") VALUES ('" . implode('\',\'', $values) . "');\n");
                 $fields = "";
                 $values = "";
             }
         }
     }
 }
 header("Content-Type: text/plain");
 header("Content-Disposition: attachment; filename=\"{$filename}\"");
Example #13
0
function upgrade_4()
{
    $error1 = _db_add_field('templatedetails', 'extra_flags', 'varchar(45)', '', 'access_to_whom');
    $table = table_by_key('templatedetails');
    $error2 = _upgrade_db_query("UPDATE `{$table}`  set `extra_flags`='engine=flash'");
    $table = table_by_key('originaltemplatesdetails');
    $error3 = _upgrade_db_query("UPDATE `{$table}`  set `template_framework`='site' where `template_name`='site'");
    $table = table_by_key('sitedetails');
    $error4 = _upgrade_db_query("ALTER TABLE `{$table}` CHANGE COLUMN `site_text` `site_text` TEXT NULL DEFAULT NULL");
    $error_returned = true;
    if ($error1 === false || $error2 === false || $error3 === false || $error4 === false) {
        $error_returned = false;
        // echo "creating lti tables FAILED";
    }
    return "Creating default engine flag - ok ? " . ($error_returned ? 'true' : 'false');
}
Example #14
0
function upgrade_1767()
{
    # 'active' was just added, so make sure all existing jobs stay active
    $table = table_by_key('fetchmail');
    db_query_parsed("UPDATE {$table} SET active='{BOOL_TRUE}'");
}
 * message
 */
require_once 'common.php';
authentication_require_role('global-admin');
if ($CONF['sendmail'] != 'YES') {
    header("Location: main.php");
    exit;
}
$smtp_from_email = smtp_get_admin_email();
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name'])) {
        $error = 1;
        flash_error($PALANG['pBroadcast_error_empty']);
    } else {
        $table_mailbox = table_by_key('mailbox');
        $table_alias = table_by_key('alias');
        $q = "select username from {$table_mailbox} union select goto from {$table_alias} " . "where goto not in (select username from {$table_mailbox})";
        $result = db_query($q);
        if ($result['rows'] > 0) {
            mb_internal_encoding("UTF-8");
            $b_name = mb_encode_mimeheader($_POST['name'], 'UTF-8', 'Q');
            $b_subject = mb_encode_mimeheader($_POST['subject'], 'UTF-8', 'Q');
            $b_message = base64_encode($_POST['message']);
            $i = 0;
            while ($row = db_array($result['result'])) {
                $fTo = $row[0];
                $fHeaders = 'To: ' . $fTo . "\n";
                $fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
                $fHeaders .= 'Subject: ' . $b_subject . "\n";
                $fHeaders .= 'MIME-Version: 1.0' . "\n";
                $fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
Example #16
0
 /**
  * Attempt to log a user in.
  * @param string $username
  * @param string $password
  * @return boolean true on successful login (i.e. password matches etc)
  */
 public function login($username, $password)
 {
     $username = escape_string($username);
     $table = table_by_key($this->db_table);
     $active = db_get_boolean(True);
     $query = "SELECT password FROM {$table} WHERE " . $this->id_field . "='{$username}' AND active='{$active}'";
     $result = db_query($query);
     if ($result['rows'] == 1) {
         $row = db_array($result['result']);
         $crypt_password = pacrypt($password, $row['password']);
         if ($row['password'] == $crypt_password) {
             return true;
         }
     }
     return false;
 }
Example #17
0
/**
 * Change description fields to UTF-8
 */
function upgrade_373_mysql()
{
    # MySQL only
    $table_domain = table_by_key('domain');
    $table_mailbox = table_by_key('mailbox');
    $all_sql = split("\n", trim("\n        ALTER TABLE `{$table_domain}`  CHANGE `description`  `description` VARCHAR( 255 ) {UTF-8}  NOT NULL\n        ALTER TABLE `{$table_mailbox}` CHANGE `name`         `name`        VARCHAR( 255 ) {UTF-8}  NOT NULL\n    "));
    foreach ($all_sql as $sql) {
        $result = db_query_parsed($sql);
    }
}
 protected function check_quota($quota)
 {
     $rval = false;
     if (!Config::bool('quota')) {
         return true;
         # enforcing quotas is disabled - just allow it
     }
     list(, $domain) = explode('@', $this->id);
     $limit = get_domain_properties($domain);
     if ($limit['maxquota'] == 0) {
         $rval = true;
         # maxquota unlimited -> OK, but domain level quota could still be hit
     }
     if ($limit['maxquota'] < 0 and $quota < 0) {
         return true;
         # maxquota and $quota are both disabled -> OK, no need for more checks
     }
     if ($limit['maxquota'] > 0 and $quota == 0) {
         return false;
         # mailbox with unlimited quota on a domain with maxquota restriction -> not allowed, no more checks needed
     }
     if ($limit['maxquota'] != 0 && $quota > $limit['maxquota']) {
         return false;
         # mailbox bigger than maxquota restriction (and maxquota != unlimited) -> not allowed, no more checks needed
     } else {
         $rval = true;
         # mailbox size looks OK, but domain level quota could still be hit
     }
     if (!$rval) {
         return false;
         # over quota - no need to check domain_quota
     }
     # TODO: detailed error message ("domain quota exceeded", "mailbox quota too big" etc.) via flash_error? Or "available quota: xxx MB"?
     if (!Config::bool('domain_quota')) {
         return true;
         # enforcing domain_quota is disabled - just allow it
     } elseif ($limit['quota'] <= 0) {
         # TODO: CHECK - 0 (unlimited) is fine, not sure about <= -1 (disabled)...
         $rval = true;
     } elseif ($quota == 0) {
         # trying to create an unlimited mailbox, but domain quota is set
         return false;
     } else {
         $table_mailbox = table_by_key('mailbox');
         $query = "SELECT SUM(quota) FROM {$table_mailbox} WHERE domain = '" . escape_string($domain) . "'";
         $query .= " AND username != '" . escape_string($this->id) . "'";
         $result = db_query($query);
         $row = db_row($result['result']);
         $cur_quota_total = divide_quota($row[0]);
         # convert to MB
         if ($quota + $cur_quota_total > $limit['quota']) {
             $rval = false;
         } else {
             $rval = true;
         }
     }
     return $rval;
 }
Example #19
0
function upgrade_1824_sqlite()
{
    $admin_table = table_by_key('admin');
    $alias_table = table_by_key('alias');
    $alias_domain_table = table_by_key('alias_domain');
    $domain_table = table_by_key('domain');
    $domain_admins_table = table_by_key('domain_admins');
    $fetchmail_table = table_by_key('fetchmail');
    $log_table = table_by_key('log');
    $mailbox_table = table_by_key('mailbox');
    $quota_table = table_by_key('quota');
    $quota2_table = table_by_key('quota2');
    $vacation_table = table_by_key('vacation');
    $vacation_notification_table = table_by_key('vacation_notification');
    db_query_parsed("\n      CREATE TABLE {$admin_table} (\n          `username` varchar(255) NOT NULL,\n          `password` varchar(255) NOT NULL,\n          `superadmin` {BOOLEAN},\n          `created` {DATE},\n          `modified` {DATE},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`username`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$alias_table} (\n          `address` varchar(255) NOT NULL,\n          `goto` {FULLTEXT} NOT NULL,\n          `domain` varchar(255) NOT NULL,\n          `created` {DATE},\n          `modified` {DATE},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`address`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$alias_domain_table} (\n          `alias_domain` varchar(255) NOT NULL,\n          `target_domain` varchar(255) NOT NULL,\n          `created` {DATE},\n          `modified` {DATE},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`alias_domain`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$domain_table} (\n          `domain` varchar(255) NOT NULL,\n          `description` varchar(255) NOT NULL,\n          `aliases` {INT},\n          `mailboxes` {INT},\n          `maxquota` {BIGINT},\n          `quota` {BIGINT},\n          `transport` varchar(255) NOT NULL,\n          `backupmx` {BOOLEAN},\n          `created` {DATE},\n          `modified` {DATE},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`domain`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$domain_admins_table} (\n          `username` varchar(255) NOT NULL,\n          `domain` varchar(255) NOT NULL,\n          `created` {DATE},\n          `active` {BOOLEAN_TRUE});\n    ");
    db_query_parsed("\n      CREATE TABLE {$fetchmail_table} (\n          `id` {AUTOINCREMENT},\n          `domain` varchar(255) DEFAULT '',\n          `mailbox` varchar(255) NOT NULL,\n          `src_server` varchar(255) NOT NULL,\n          `src_auth` varchar(255) DEFAULT NULL,\n          `src_user` varchar(255) NOT NULL,\n          `src_password` varchar(255) NOT NULL,\n          `src_folder` varchar(255) NOT NULL,\n          `poll_time` int(11)  NOT NULL DEFAULT '10',\n          `fetchall` {BOOLEAN},\n          `keep` {BOOLEAN},\n          `protocol` {FULLTEXT} DEFAULT NULL,\n          `usessl` {BOOLEAN},\n          `sslcertck` {BOOLEAN},\n          `sslcertpath` varchar(255) DEFAULT '',\n          `sslfingerprint` varchar(255) DEFAULT '',\n          `extra_options` {FULLTEXT},\n          `returned_text` {FULLTEXT},\n          `mda` varchar(255) NOT NULL,\n          `date` {DATE},\n          `created` {DATE},\n          `modified` {DATECURRENT},\n          `active` {BOOLEAN});\n    ");
    db_query_parsed("\n      CREATE TABLE {$log_table} (\n          `timestamp` {DATE},\n          `username` varchar(255) NOT NULL,\n          `domain` varchar(255) NOT NULL,\n          `action` varchar(255) NOT NULL,\n          `data` {FULLTEXT} NOT NULL);\n    ");
    db_query_parsed("\n      CREATE TABLE {$mailbox_table} (\n          `username` varchar(255) NOT NULL,\n          `password` varchar(255) NOT NULL,\n          `name` varchar(255) NOT NULL,\n          `maildir` varchar(255) NOT NULL,\n          `quota` {BIGINT},\n          `local_part` varchar(255) NOT NULL,\n          `domain` varchar(255) NOT NULL,\n          `created` {DATE},\n          `modified` {DATE},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`username`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$quota_table} (\n          `username` varchar(255) NOT NULL,\n          `path` varchar(100) NOT NULL,\n          `current` {BIGINT},\n          {PRIMARY} (`username`,`path`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$quota2_table} (\n          `username` varchar(255) NOT NULL,\n          `bytes` {BIGINT},\n          `messages` {INT},\n          {PRIMARY} (`username`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$vacation_table} (\n          `email` varchar(255) NOT NULL,\n          `subject` varchar(255) NOT NULL,\n          `body` {FULLTEXT} NOT NULL,\n          `activefrom` {DATE},\n          `activeuntil` {DATE},\n          `cache` {FULLTEXT} NOT NULL DEFAULT '',\n          `domain` varchar(255) NOT NULL,\n          `interval_time` {INT},\n          `created` {DATE},\n          `modified` {DATECURRENT},\n          `active` {BOOLEAN_TRUE},\n          {PRIMARY} (`email`));\n    ");
    db_query_parsed("\n      CREATE TABLE {$vacation_notification_table} (\n          `on_vacation` varchar(255) NOT NULL,\n          `notified` varchar(255) NOT NULL,\n          `notified_at` {DATECURRENT},\n          {PRIMARY} (`on_vacation`,`notified`),\n          CONSTRAINT `vacation_notification_pkey` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE);\n    ");
}