Exemplo n.º 1
0
 /**
  * User self update method
  *
  * @access public
  * @param mixed $post //posted user details
  * @return void
  */
 public function self_update($post)
 {
     # set items to update
     $items = array("real_name" => $post['real_name'], "mailNotify" => $post['mailNotify'], "mailChangelog" => $post['mailChangelog'], "email" => $post['email'], "lang" => $post['lang'], "id" => $this->user->id, "compressOverride" => $post['compressOverride'], "hideFreeRange" => $this->verify_checkbox(@$post['hideFreeRange']), "printLimit" => @$post['printLimit']);
     if (strlen($post['password1']) > 0) {
         $items['password'] = $this->crypt_user_pass($post['password1']);
     }
     # prepare log file
     $log = array_to_log($post);
     # update
     try {
         $this->Database->updateObject("users", $items);
     } catch (Exception $e) {
         $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
         write_log("User self update", "User self update failed!<br>" . $log, 2, $this->username);
         return false;
     }
     # update language
     $this->update_session_language();
     # ok, update log table
     write_log("User self update", "User self update suceeded!", 0, $this->username);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Updates custom field definition
  *
  * @access public
  * @param array $field
  * @return bool
  */
 public function update_custom_field_definition($field)
 {
     # set type definition and size of needed
     if ($field['fieldType'] == "bool" || $field['fieldType'] == "text" || $field['fieldType'] == "date" || $field['fieldType'] == "datetime") {
         $field['ftype'] = $field['fieldType'];
     } else {
         $field['ftype'] = $field['fieldType'] . "(" . $field['fieldSize'] . ")";
     }
     # default value null
     if (strlen($field['fieldDefault']) == 0) {
         $field['fieldDefault'] = "NULL";
     } else {
         $field['fieldDefault'] = "'{$field['fieldDefault']}'";
     }
     # character set if needed
     if ($field['fieldType'] == "varchar" || $field['fieldType'] == "text" || $field['fieldType'] == "set") {
         $charset = "CHARACTER SET utf8";
     } else {
         $charset = "";
     }
     # escape fields
     $field['table'] = $this->Database->escape($field['table']);
     $field['name'] = $this->Database->escape($field['name']);
     $field['oldname'] = $this->Database->escape($field['oldname']);
     # strip values
     $field['action'] = $this->strip_input_tags($field['action']);
     $field['Comment'] = $this->strip_input_tags($field['Comment']);
     # set update query
     if ($field['action'] == "delete") {
         $query = "ALTER TABLE `{$field['table']}` DROP `{$field['name']}`;";
     } else {
         if ($field['action'] == "edit" && @$field['NULL'] == "NO") {
             $query = "ALTER IGNORE TABLE `{$field['table']}` CHANGE COLUMN `{$field['oldname']}` `{$field['name']}` {$field['ftype']} {$charset} DEFAULT {$field['fieldDefault']} NOT NULL COMMENT '{$field['Comment']}';";
         } else {
             if ($field['action'] == "edit") {
                 $query = "ALTER TABLE `{$field['table']}` CHANGE COLUMN `{$field['oldname']}` `{$field['name']}` {$field['ftype']} {$charset} DEFAULT {$field['fieldDefault']} COMMENT '{$field['Comment']}';";
             } else {
                 if ($field['action'] == "add" && @$field['NULL'] == "NO") {
                     $query = "ALTER TABLE `{$field['table']}` ADD COLUMN \t`{$field['name']}` \t\t\t\t\t{$field['ftype']} {$charset} DEFAULT {$field['fieldDefault']} NOT NULL COMMENT '{$field['Comment']}';";
                 } else {
                     if ($field['action'] == "add") {
                         $query = "ALTER TABLE `{$field['table']}` ADD COLUMN \t`{$field['name']}` \t\t\t\t\t{$field['ftype']} {$charset} DEFAULT {$field['fieldDefault']} NULL COMMENT '{$field['Comment']}';";
                     } else {
                         return false;
                     }
                 }
             }
         }
     }
     # execute
     try {
         $res = $this->Database->runQuery($query, array(@$field['Comment']));
     } catch (Exception $e) {
         $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
         write_log("Custom field {$field['action']}", "Custom Field {$field['action']} failed ({$field['name']})<hr>" . array_to_log($field), 2, $this->User->username);
         return false;
     }
     # field updated
     write_log("Custom field {$field['action']}", "Custom Field {$field['action']} success ({$field['name']})<hr>" . array_to_log($field), 0, $this->User->username);
     return true;
 }
Exemplo n.º 3
0
            # reset IP address field
            $address['ip_addr'] = $m;
            # modify action - if delete ok, dynamically reset add / edit -> if IP already exists set edit
            if ($action != "delete") {
                $address['action'] = $Addresses->address_exists($m, $address['subnetId']) === true ? "edit" : "add";
            }
            # if it fails set error log
            if (!$Addresses->modify_address($address)) {
                $errors[] = _('Cannot') . ' ' . $address['action'] . ' ' . _('IP address') . ' ' . $Addresses->transform_to_dotted($m);
            }
            # next IP
            $m = gmp_strval(gmp_add($m, 1));
        }
        # print errors if they exist
        if (isset($errors)) {
            $log = array_to_log($errors);
            $Result->show("danger", $log, false);
            write_log("IP address modification", "'Error {$action} range {$address['start']} - {$address['stop']}<br> {$log}", 2, $User->username);
        } else {
            # reset IP for mailing
            $address['ip_addr'] = $address['start'] . ' - ' . $address['stop'];
            /* @mail functions ------------------- */
            include_once '../../../functions/functions-mail.php';
            //sendObjectUpdateMails("ip", $action, array(), $address, true);
            $Result->show("success", _("Range") . " {$address['start']} - {$address['stop']} " . _($action) . " " . _("successfull") . "!", false);
            write_log("IP address modification", "Range {$address['start']} - {$address['stop']} {$action} successfull!", 0, $User->username);
        }
    }
} else {
    # unique hostname requested?
    if (isset($address['unique'])) {
Exemplo n.º 4
0
 /**
  * Resize subnet with new mask
  *
  * @access private
  * @param mixed $subnetId
  * @param mixed $mask
  * @return void
  */
 private function subnet_resize($subnetId, $mask)
 {
     # save old values
     $old_subnet = $this->fetch_subnet(null, $subnetId);
     # execute
     try {
         $this->Database->updateObject("subnets", array("id" => $subnetId, "mask" => $mask), "id");
     } catch (Exception $e) {
         $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
         write_log("Subnet edit", "Failed to resize subnet<hr>" . $e->getMessage(), 2, $this->User->username);
         return false;
     }
     # ok
     write_log("Subnet resize", "Subnet resized<hr>" . array_to_log(array("id" => $subnetId, "mask" => $mask)), 0, $this->User->username);
     return true;
 }
Exemplo n.º 5
0
 /**
  * Delete section, subsections, subnets and ip addresses
  *
  * @access private
  * @param mixed $values
  * @return void
  */
 private function section_delete($values)
 {
     # subnets class
     $Subnets = new Subnets($this->Database);
     # save old values
     $old_section = $this->fetch_section("id", $values['id']);
     # check for subsections and store all ids
     $all_ids = $this->get_all_section_and_subsection_ids($values['id']);
     //array of section + all subsections
     # truncate and delete all subnets in all sections, than delete sections
     foreach ($all_ids as $id) {
         $section_subnets = $Subnets->fetch_section_subnets($id);
         if (sizeof($section_subnets) > 0) {
             foreach ($section_subnets as $ss) {
                 //delete subnet
                 $Subnets->modify_subnet("delete", array("id" => $ss->id));
             }
         }
         # delete all sections
         try {
             $this->Database->deleteRow("sections", "id", $id);
         } catch (Exception $e) {
             write_log("Section {$old_section->name} delete", "Failed to delete section {$old_section->name}<hr>" . $e->getMessage() . "<hr>" . array_to_log($values), 2, $this->user->username);
             $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
             return false;
         }
     }
     # write changelog
     write_changelog('section', "delete", 'success', $old_section, array());
     # log
     write_log("Section {$old_section->name} delete", "Section {$old_section->name} deleted<hr>" . array_to_log($old_section), 0, $this->user->username);
     return true;
 }