function group_actions($command, $values) { // Set initial return value $r = false; $ga = explode(';', $command); $mode = $ga[0]; switch ($mode) { case "account": foreach ($values as $key => $value) { // key contains mail $key1 = explode('@', $key); // Create right DN for account and domain $dn = 'mail=' . $key . ',vd=' . $key1[1] . ',' . LDAP_BASE; $dn_domain = 'vd=' . $key1[1] . ',' . LDAP_BASE; // Pre-load values for account adn domain $self_values = PhammLdap::phamm_self_values($dn, $filter = "(objectClass=*)"); $domain_values = PhammLdap::phamm_self_values($dn_domain, $filter = "(objectClass=*)"); // (string) needed for TRUE and FALSE not real boolean... $entry[$ga[1]] = (string) $ga[2]; $is_alias = in_array('VirtualMailAlias', $self_values[0]["objectclass"]) ? true : false; foreach ($entry as $k_entry => $v_entry) { if ($v_entry == 'TRUE') { $max_key = strtolower('max' . $k_entry); if (isset($domain_values[0][$max_key][0])) { $max_val = $domain_values[0][$max_key][0]; $active_val = PhammLdap::phamm_self_values($dn_domain, '(&(objectClass=*)(' . $k_entry . '=TRUE))'); if ($active_val["count"] >= $max_val) { phamm_print_message('warning', sprintf(_("The maximum number of attribute %s (%s) has been reached or exceeded!"), $k_entry, $max_val)); return false; } } } } // Delete immediate if VirtualMailAlias if (isset($entry["delete"]) && $is_alias) { $r = PhammLdap::phamm_delete($dn, $recursive = false); } else { $r = PhammLdap::phamm_modify($dn, $entry); } } break; case "domain": foreach ($values as $key => $value) { // Create right DN // $dn = 'cn=postmaster,vd='.$key.','.LDAP_BASE; $dn = 'vd=' . $key . ',' . LDAP_BASE; // (string) needed for TRUE and FALSE not real boolean... $entry[$ga[1]] = (string) $ga[2]; // Change single value $r = PhammLdap::phamm_modify($dn, $entry); } break; case "postmaster": foreach ($values as $key => $value) { // Create right DN // $dn = 'cn=postmaster,vd='.$key.','.LDAP_BASE; $dn = 'cn=postmaster,vd=' . $key . ',' . LDAP_BASE; // (string) needed for TRUE and FALSE not real boolean... $entry[$ga[1]] = (string) $ga[2]; // Change single value $r = PhammLdap::phamm_modify($dn, $entry); } break; } return $r; }
/** * Create a XHTML form for plugin attribute * * @author Alessandro De Zorzi <*****@*****.**> * * @param string $p_name The plugin name * @param array $attributes The attributes * @return mixed **/ function form_template($p_name, $attributes, $myvalues, $skip_table = null) { global $action; global $minAuthLevel; global $domain; $dn_domain = 'vd=' . $domain . ',' . LDAP_BASE; $domain_values = PhammLdap::phamm_self_values($dn_domain, $filter = "(objectClass=*)"); $tag = ''; if (!isset($skip_table)) { $tag .= '<table class="">'; } if (is_array($attributes)) { foreach ($attributes as $key => $attr) { if (!isset($hidden)) { $tag .= '<tr><td>'; } // Set attributes $name = strtolower($key); $hidden = isset($attr["HIDDEN"]) ? 'type="hidden"' : null; $minAuthLevel = isset($attr["MINAUTHLEVEL"]) ? $attr["MINAUTHLEVEL"] : 0; $size = isset($attr["SIZE"]) && !isset($attr["HIDDEN"]) ? 'size="' . $attr["SIZE"] . '"' : null; $disabled = isset($attr["DISABLED"]) ? 'disabled="disabled"' : null; $maxlength = isset($attr["MAXLENGHT"]) ? strtolower($attr["MAXLENGTH"]) : null; $subordinated = isset($attr["SUBORDINATED"]) ? strtoupper($attr["SUBORDINATED"]) : null; $subordinatedreverse = isset($attr["SUBORDINATEDREVERSE"]) ? strtoupper($attr["SUBORDINATEDREVERSE"]) : null; $max_key = strtolower('max' . $key); if (isset($domain_values[0][$max_key][0])) { // Disable value is possible only from TRUE to FALSE if (isset($myvalues[0][$name][0]) || $myvalues[0][$name][0] == 'FALSE') { $max_val = $domain_values[0][$max_key][0]; // For Bool attrbute only check the sum of total account with attribute set TRUE if ($attr["BOOL"] == 1) { $active_val = PhammLdap::phamm_self_values($dn_domain, '(&(objectClass=*)(' . $key . '=TRUE))'); $current_val_count = $active_val["count"]; } else { $active_val = PhammLdap::phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=VirtualMailAccount))', array($key)); $total_key = 0; foreach ($active_val as $one_val) { if ($one_val[$key][0]) { $total_key = $total_key + $one_val[$key][0]; } } // @todo if ('quota' == $key) { $total_key = $total_key / 1024 / 1024 - $active_val['count'] * 2000; } $current_val_count = $total_key; } if ($current_val_count >= $max_val) { phamm_print_message('info', sprintf(_("The maximum number of attribute %s (%s) has been reached or exceeded. Attribute has been disabled!"), $key, $max_val)); $disabled = 'disabled="disabled"'; } } } // Set XHTML Tags $required = isset($attr["REQUIRED"]) ? ' *' : null; // Set Default value $value = ''; // Set standard value if (isset($myvalues[$p_name][$name])) { $value = $myvalues[$p_name][$name]; } elseif (isset($myvalues[0][$name][0])) { // If attr is multiple if (isset($attr["MULTIPLE"])) { $value = $myvalues[0][$name]; } else { $value = $myvalues[0][$name][0]; } } // Multiplier (Ex. Quota x 1024) if (isset($attr["MULTIPLIER"]) && in_array($action, array('modify_account', 'domain_property'))) { $value = $value / $attr["MULTIPLIER"]; } elseif (isset($attr["DEFAULT"]) && ($action == 'add_account' || $action == 'add_domain')) { if (preg_match('/^=php\\.(\\w+)\\((.*)\\)$/', $attr["DEFAULT"], $matches)) { $args = preg_split('/,/', $matches[2]); $function_name = $matches[1]; switch ($function_name) { case "Value": foreach ($args as $arg) { // Global vars if (preg_match('/^%(\\w+)(\\|.+)?(\\/[lU])?%/U', $arg, $matches)) { $var_name = $matches[1]; global ${$var_name}; $value .= ${$var_name}; } elseif (preg_match('/^\\+(\\w+)(\\|.+)?(\\/[lU])?\\+/U', $arg, $matches)) { $var_name = $matches[1]; $value .= $_POST[$var_name]; } else { $value .= $arg; } } break; // Call PHP Function // Call PHP Function default: if (function_exists($function_name)) { // Escape a string to be used as a shell argument foreach ($args as $arg) { $args_escaped = escapeshellarg($arg); } $value = call_user_func_array($function_name, $args_escaped); } break; } } else { $value = $attr["DEFAULT"]; } } // Hide values if SUBORDINATED to another if (isset($attr["SUBORDINATED"])) { if (isset($myvalues[0][strtolower($subordinated)][0])) { $hidden = $myvalues[0][strtolower($subordinated)][0] == "TRUE" ? null : 1; } elseif (isset($myvalues[$p_name][strtolower($subordinated)])) { $hidden = $myvalues[$p_name][strtolower($subordinated)] == "TRUE" ? null : 1; } else { $hidden = 1; } } if (isset($attr["SUBORDINATEDREVERSE"])) { if (isset($myvalues[0][strtolower($subordinatedreverse)][0])) { $hidden = $myvalues[0][strtolower($subordinatedreverse)][0] == "FALSE" ? null : 1; } elseif (isset($myvalues[$p_name][strtolower($subordinatedreverse)])) { $hidden = $myvalues[$p_name][strtolower($subordinatedreverse)] == "FALSE" ? null : 1; } else { $hidden = 1; } } if (!isset($hidden)) { $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $key; $tag .= gettext($label); $tag .= $required; $tag .= "</td><td>"; } if (isset($attr["BOOL"]) && !isset($hidden)) { $reverse = isset($attr["REVERSE"]) ? 1 : null; $tag .= trueorfalse("values[" . $p_name . "]", $value, $name, $reverse, $disabled); } elseif (isset($attr["OPTIONS"]) && !isset($hidden)) { if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= $value; } else { $tag .= '<select class="form-control" name="values[' . $p_name . '][' . $name . ']">'; foreach ($attr["OPTIONS"] as $k => $v) { $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $k; $label = $k; $selected = $value == $v["VALUE"] ? 'selected="selected"' : ''; $tag .= '<option value="' . $v["VALUE"] . '" ' . $selected . '>' . $label . ' (' . $v["VALUE"] . ')</option>' . "\n"; } $tag .= '</select>' . "\n\n"; } } elseif (isset($attr["DATE"]) && !isset($hidden)) { $current_date = $value ? $value : date('Y' . '-' . 'm' . '-' . 'd'); if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= $value; } else { $tag .= date_input('values_date[' . $p_name . '][' . $name . ']', $current_date, $format = 'ymd'); } } elseif (isset($attr["TEXTAREA"]) && !isset($hidden)) { if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= nl2br($value); } else { // Show box to add multiple values $tag .= '<textarea name="values[' . $p_name . '][' . $name . ']" cols="35" rows="5">'; $tag .= stripslashes($value); $tag .= "</textarea><br/>"; } } elseif (isset($attr["MULTIPLE"]) && !isset($hidden)) { // Show box to add multiple values $tag .= '<textarea name="values_multi[' . $p_name . '][' . $name . ']" cols="35" rows="5">'; if (isset($attr["TEXTAREA"])) { $tag .= stripslashes($value); } $tag .= "</textarea><br/>"; // Show the values if (is_array($value)) { for ($i = 0; $i < $value["count"]; $i++) { $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . '][]" value="' . $value[$i] . '" />'; $tag .= $value[$i] . "<br/>"; } } } elseif (isset($attr["SUBORDINATEDDELETE"]) && $value) { $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . ']" value="' . $value . '" id="subordinatedelete" />'; $tag .= $value . "<br/>"; } else { if (isset($hidden)) { $input_type = 'hidden'; } else { $input_type = 'text'; } // Show Value Only if auth level > level required if ($_SESSION["login"]["level"] >= $minAuthLevel) { $tag .= '<input type="' . $input_type . '" class="form-control" value="' . $value . '" name="values[' . $p_name . '][' . $name . ']" ' . $size . ' ' . $disabled . ' />'; } elseif (!isset($hidden)) { $tag .= $value; } } if (!isset($hidden)) { $tag .= "</td></tr>"; } } } // Exception, if last array attribute is hidden // XHTML Syntax required to close a TR if (isset($hidden)) { $tag .= "</td><td></td></tr>"; } if (!isset($skip_table)) { $tag .= "</table>"; } return $tag; }
phamm_print_xhtml('<li><a href="?action=domain_property&domain=' . $domain . '">' . _("Domain property") . '</a></li> '); phamm_print_xhtml('</ul>'); //Special link for catch-all if (in_array($pn, array('mail', 'alias'))) { // Check if catch_all exists $catch_all_dn = 'vd=' . $domain . ',' . LDAP_BASE; $values = PhammLdap::phamm_search($catch_all_dn, 'mail=@' . $domain, array('mail')); if (isset($values[0]["mail"][0])) { phamm_print_message('warning', ': ' . _("Catch all active"), null, 'label'); } else { phamm_print_xhtml('<p><a href="?action=catch_all&domain=' . $domain . '">' . _("Catch all") . '</a></p>'); } } // Create domain Object $domain_obj = new PhammLdap(); $domain_val = $domain_obj->phamm_self_values('vd=' . $domain . ',' . LDAP_BASE, $filter = "(vd={$domain})"); $values = array(); // Attributes in the table if (isset($pv[$pn]["ACCOUNT"])) { $values = array_merge($values, $pv[$pn]["ACCOUNT"]); } phamm_print_xhtml(accounts_list($domain, $values, $initial, $domain_val)); phamm_print_xhtml(action_select('account')); break; // Insert a new account // // Insert a new account // case "insert_account": $values = $_POST["values"]; $values_date = isset($_POST["values_date"]) ? $_POST["values_date"] : null;