/** * Updates the user password, this is only a smart reference * @param $user * @param $user_password * @return unknown_type * @throws AppKitException * @author Marius Hein */ public function updateUserPassword(NsmUser &$user, $user_password) { AppKitRandomUtil::initRand(); $user->updatePassword($user_password); $user->save(); return true; }
/** * Add a condition by a defined xml field * @param string $field * @param mixed $val * @param integer $op * @return string the id of the condition (for deletion) */ public function setCondition($field, $val, $op = null) { if ($op === null) { $op = AppKitSQLConstants::SQL_OP_IS; } $id = 'c-' . AppKitRandomUtil::genSimpleId(15); $filter = $this->getTemplate()->getFieldByName($field, 'filter'); $database = $this->getTemplate()->getFieldByName($field, 'datasource'); $new_field = null; $ff = $this->getAdditionalFilterFields(); if (array_key_exists($field, $ff) == true) { $new_field = $ff[$field]; } elseif ($filter->getParameter('field', null)) { $new_field = $filter->getParameter('field'); } else { $new_field = $database->getParameter('field'); } if (!$new_field) { throw new CronkGridTemplateWorkerException('Could not determine the icinga api field for ' . $field); } // Add or replace some asterix within count if ($op == AppKitSQLConstants::SQL_OP_CONTAIN || $op == AppKitSQLConstants::SQL_OP_NOTCONTAIN) { if (strpos($val, '*') === false) { $val = '%' . $val . '%'; } else { $val = str_replace('*', '%', $val); } } $new_op = AppKitSQLConstants::getIcingaMatch($op); if ($new_op == false) { throw new CronkGridTemplateWorkerException('No existing icinga search match operator found!'); } $this->conditions[$id] = array('val' => $val, 'field' => $new_field, 'op' => $new_op); return $id; }
/** * Returns a simple id string based on letters and numbers * @param unknown_type $length * @param unknown_type $prefix */ public static function genSimpleId($length = 5, $prefix = "") { static $chars = null; if ($chars === null) { $chars = array_merge(range(48, 57, 1), range(65, 90, 1), range(97, 122, 1)); shuffle($chars); // MIX THE CHARS } $o = null; for ($i = 0; $i < $length; $i++) { $o .= chr($chars[mt_rand(0, count($chars) - 1)]); } return $prefix . $o; } /** * Generate a unique continuous html id string * @param unknown_type $prefix */ public static function htmlId($prefix = 'appkit-htmlid') { return sprintf('%s-%04d', $prefix, ++self::$htmlid_counter); } } // Lazy initialising AppKitRandomUtil::initRand();
/** * Sets a random password for the user * @return null really nothing * @param integer $length */ public function generateRandomPassword($length = 10) { $password = AppKitRandomUtil::genSimpleId($length, microtime(true)); $this->__updatePassword($password); }