Exemple #1
0
 public function execute()
 {
     if (isset($_SERVER["hide_ss"]) == false) {
         $_SERVER["hide_ss"] = true;
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["submit_button"] == "hidess") {
         $_SERVER["hide_ss"] = is_true($_POST["hide_ss"]);
     }
     $this->output->add_css("banshee/filter.css");
     $filter = new filter($this->db, $this->output, $this->user);
     $filter->to_output($this->model->table, false);
     if (($count = $this->model->count_events($filter->webserver, $_SERVER["hide_ss"])) === false) {
         $this->output->add_tag("result", "Database error.");
         return;
     }
     $paging = new pagination($this->output, "events", $this->settings->event_page_size, $count);
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $paging->reset();
     }
     if (($events = $this->model->get_events($paging->offset, $paging->size, $filter->webserver, $_SERVER["hide_ss"])) === false) {
         $this->output->add_tag("result", "Database error.");
         return;
     }
     $this->output->open_tag("events", array("hide_ss" => show_boolean($_SERVER["hide_ss"])));
     foreach ($events as $event) {
         $event["timestamp"] = date("j F Y, H:i:s", $event["timestamp"]);
         $event["event"] = $this->output->secure_string($event["event"], "_");
         $this->output->record($event, "event");
     }
     $paging->show_browse_links();
     $this->output->close_tag();
 }
Exemple #2
0
 public function execute()
 {
     header("Status: 401");
     $this->output->description = "Login";
     $this->output->keywords = "login";
     $this->output->title = "Login";
     $this->output->add_javascript("banshee/login.js");
     $this->output->open_tag("login", array("password" => show_boolean(module_exists("password")), "register" => show_boolean(module_exists("register"))));
     $this->output->add_tag("url", $_SERVER["REQUEST_URI"]);
     if ($_SERVER["REQUEST_METHOD"] != "POST") {
         $this->output->add_tag("bind");
     } else {
         $this->output->add_tag("username", $_POST["username"]);
         if (is_true($_POST["bind_ip"])) {
             $this->output->add_tag("bind");
         }
     }
     $this->output->add_tag("remote_addr", $_SERVER["REMOTE_ADDR"]);
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if (strpos($_POST["username"], "'") !== false) {
             $this->output->add_message("Sorry, this application does not support SQL injection.");
             header("X-Hiawatha-Monitor: exploit_attempt");
         } else {
             $this->output->add_message("Login incorrect");
         }
     }
     $this->output->close_tag();
 }
Exemple #3
0
 public function execute()
 {
     header("Status: 401");
     $this->output->description = "Login";
     $this->output->keywords = "login";
     $this->output->title = "Login";
     $this->output->add_javascript("banshee/" . PASSWORD_HASH . ".js");
     $this->output->add_javascript("banshee/login.js");
     $this->output->run_javascript("set_focus(); hash = window['" . PASSWORD_HASH . "'];");
     $this->output->open_tag("login");
     $this->output->add_tag("url", $_SERVER["REQUEST_URI"]);
     if ($_SERVER["REQUEST_METHOD"] != "POST") {
         $this->output->add_tag("bind");
     } else {
         $this->output->add_tag("username", $_POST["username"]);
         if (is_true($_POST["bind_ip"])) {
             $this->output->add_tag("bind");
         }
     }
     $this->output->add_tag("remote_addr", $_SERVER["REMOTE_ADDR"]);
     $this->output->add_tag("challenge", $_SESSION["challenge"]);
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if (strpos($_POST["username"], "'") !== false) {
             $this->output->add_message("Sorry, this application does not support SQL injection.");
             header("X-Hiawatha-Monitor: exploit_attempt");
         } else {
             $this->output->add_message("Login incorrect");
         }
     }
     $this->output->close_tag();
 }
Exemple #4
0
 public function execute()
 {
     if (($page = $this->model->get_page($this->page->url)) == false) {
         $this->output->add_tag("website_error", 500);
         return;
     }
     /* Page header
      */
     if (trim($page["description"]) != "") {
         $this->output->description = $page["description"];
     }
     if (trim($page["keywords"]) != "") {
         $this->output->keywords = $page["keywords"];
     }
     $this->output->title = $page["title"];
     if ($page["style"] != null) {
         $this->output->inline_css = $page["style"];
     }
     $this->output->language = $page["language"];
     $this->output->set_layout($page["layout"]);
     $this->output->allow_hiawatha_cache();
     /* Page content
      */
     $this->output->open_tag("page");
     $this->output->add_tag("title", $page["title"]);
     $page["content"] = $this->output->secure_string($page["content"]);
     $this->output->add_tag("content", $page["content"]);
     if (is_true($page["back"])) {
         $parts = explode("/", $this->page->page);
         array_pop($parts);
         $this->output->add_tag("back", implode("/", $parts));
     }
     $this->output->close_tag();
 }
Exemple #5
0
 public function fire()
 {
     $options = $this->option();
     $this->seed_path = storage_path('seeder');
     Asset::setFromSeed(true);
     // -------------------------------------
     if (is_true($options['reset'])) {
         if (Config::getEnvironment() == 'production') {
             $really = $this->confirm('This is the *** PRODUCTION *** server are you sure!? [yes|no]');
             if (!$really) {
                 $this->info("**** Exiting ****");
                 exit;
             }
         }
         if (!File::exists($this->seed_path)) {
             File::makeDirectory($this->seed_path);
             $n = 50;
             for ($i = 1; $i <= $n; $i++) {
                 $gender_types = ['men', 'women'];
                 foreach ($gender_types as $gender) {
                     $user_photo_url = "http://api.randomuser.me/portraits/{$gender}/{$i}.jpg";
                     File::put($this->seed_path . "/{$gender}_{$i}.jpg", file_get_contents($user_photo_url));
                 }
                 $this->info("Cache user seed image - {$i}");
             }
         }
         if ($this->confirm('Do you really want to delete the tables? [yes|no]')) {
             // first delete all assets
             if (Schema::hasTable('assets')) {
                 foreach (Asset::all() as $asset) {
                     $asset->delete();
                 }
             }
             $name = $this->call('migrate');
             $name = $this->call('migrate:reset');
             File::deleteDirectory(public_path('assets/content/users'));
             $this->info('--- Halp has been reset ---');
         }
         Auth::logout();
         $this->setupDatabases();
         return;
     }
     // -------------------------------------
     if (is_true($options['setup'])) {
         $this->setupDatabases();
     }
     // -------------------------------------
     if ($options['seed'] == 'all') {
         $this->seed();
     }
     if ($options['seed'] == 'users') {
         $this->seedUsers();
     }
     if ($options['seed'] == 'tasks') {
         $this->seedTasks();
     }
     if ($options['seed'] == 'projects') {
         $this->seedProjects();
     }
 }
Exemple #6
0
 public function fire()
 {
     $options = $this->option();
     $users = User::all();
     $this->repository = new AwardsRepository();
     $this->repository->setListener($this);
     $this->comment("// -------------------------------------");
     $this->comment("           Individual Awards            ");
     $this->comment("// -------------------------------------");
     // user based awards
     foreach ($users as $user) {
         $this->info("Checking awards for: " . $user->getName());
         $this->info($this->repository->checkAwardForUser($user));
     }
     $this->comment("// -------------------------------------");
     $this->comment("             Site Wide Awards           ");
     $this->comment("// -------------------------------------");
     // site wide awards - time based
     if (is_true($options['full'])) {
         $start = Task::orderBy('created_at')->first()->created_at;
         $end = Carbon::now();
         $date = clone $start;
         for ($i = $start->weekOfYear; $i <= $end->weekOfYear; $i++) {
             $this->info("Checking for week of " . $date->toDateString());
             $this->info($this->repository->checkForAwards($date));
             $date->addWeek();
         }
     } else {
         $this->info($this->repository->checkForAwards());
     }
 }
Exemple #7
0
 public function execute()
 {
     if ($this->user->logged_in == false) {
         unset($this->sections["mail"]);
     }
     if (isset($_SESSION["search"]) == false) {
         $_SESSION["search"] = array();
         foreach ($this->sections as $section => $label) {
             $_SESSION["search"][$section] = true;
         }
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $this->log_search_query($_POST["query"]);
         foreach ($this->sections as $section => $label) {
             $_SESSION["search"][$section] = is_true($_POST[$section]);
         }
     }
     $this->output->add_css("banshee/js_pagination.css");
     $this->output->add_javascript("banshee/pagination.js");
     $this->output->add_javascript("search.js");
     $this->output->run_javascript("document.getElementById('query').focus()");
     $this->output->add_tag("query", $_POST["query"]);
     $this->output->open_tag("sections");
     foreach ($this->sections as $section => $label) {
         $params = array("label" => $label, "checked" => show_boolean($_SESSION["search"][$section]));
         $this->output->add_tag("section", $section, $params);
     }
     $this->output->close_tag();
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if (strlen(trim($_POST["query"])) < 3) {
             $this->output->add_tag("result", "Search query too short.");
         } else {
             if (($result = $this->model->search($_POST, $this->sections)) === false) {
                 /* Error
                  */
                 $this->output->add_tag("result", "Search error.");
             } else {
                 if (count($result) == 0) {
                     $this->output->add_tag("result", "No matches found.");
                 } else {
                     /* Results
                      */
                     foreach ($result as $section => $hits) {
                         $this->output->open_tag("section", array("section" => $section, "label" => $this->sections[$section]));
                         foreach ($hits as $hit) {
                             $hit["text"] = strip_tags($hit["text"]);
                             $hit["content"] = strip_tags($hit["content"]);
                             $hit["content"] = preg_replace('/\\[.*?\\]/', "", $hit["content"]);
                             $hit["content"] = truncate_text($hit["content"], 400);
                             $this->output->record($hit, "hit");
                         }
                         $this->output->close_tag();
                     }
                 }
             }
         }
     }
 }
Exemple #8
0
function is_boolean()
{
    $params = func_get_args();
    $count = func_num_args();
    $value = null;
    if (_get_value($params, $count, $value)) {
        if (!is_true($value) && !is_false($value)) {
            return false;
        }
        return true;
    }
    return false;
}
Exemple #9
0
 public function update_profile($profile)
 {
     $profile["status"] = USER_STATUS_ACTIVE;
     $keys = array("email", "notification_key", "notification_method", "daily_report");
     if ($profile["password"] != "") {
         array_push($keys, "password");
         array_push($keys, "status");
         if (is_false($profile["password_hashed"])) {
             $profile["password"] = hash(PASSWORD_HASH, $profile["password"] . hash(PASSWORD_HASH, $this->user->username));
         }
     }
     $profile["daily_report"] = is_true($profile["daily_report"]) ? YES : NO;
     return $this->db->update("users", $this->user->id, $profile, $keys) !== false;
 }
Exemple #10
0
 public function __construct($db, $settings, $user)
 {
     $this->db = $db;
     $this->settings = $settings;
     $this->user = $user;
     /* AJAX request
      */
     if ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" || $_GET["output"] == "ajax") {
         $this->ajax_request = true;
     }
     /* Select module
      */
     if (is_true(ENFORCE_HTTPS) && $_SERVER["HTTPS"] != "on") {
         header(sprintf("Location: https://%s%s", $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
         header("Strict-Transport-Security: max-age=31536000");
         $this->module = ERROR_MODULE;
         $this->http_code = 301;
     } else {
         if (is_false(WEBSITE_ONLINE) && $_SERVER["REMOTE_ADDR"] != WEBSITE_ONLINE) {
             $this->module = "banshee/offline";
         } else {
             if ($this->db->connected == false) {
                 if (module_exists("setup") && is_true(DEBUG_MODE)) {
                     $this->module = "setup";
                 } else {
                     $this->module = ERROR_MODULE;
                     $this->http_code = 500;
                 }
             } else {
                 list($this->url) = explode("?", $_SERVER["REQUEST_URI"], 2);
                 $path = trim($this->url, "/");
                 if ($path == "") {
                     $page = $this->settings->start_page;
                 } else {
                     if (valid_input($path, VALIDATE_URL, VALIDATE_NONEMPTY)) {
                         $page = $path;
                     } else {
                         $this->module = ERROR_MODULE;
                         $this->http_code = 404;
                     }
                 }
                 $this->pathinfo = explode("/", $page);
             }
         }
     }
     if ($this->module === null) {
         $this->select_module($page);
     }
 }
Exemple #11
0
 protected function show_item_form($item)
 {
     if (is_true(DEBUG_MODE) == false && isset($item["id"])) {
         if (($current = $this->model->get_item($item["id"])) === false) {
             $this->output->add_tag("result", "Database error.");
             return false;
         }
         $this->output->add_javascript("cms/settings.js");
         $this->output->open_tag("label");
         $this->output->add_tag("key", $current["key"]);
         $this->output->add_tag("type", $current["type"]);
         $this->output->close_tag();
     }
     parent::show_item_form($item);
 }
Exemple #12
0
 public function execute()
 {
     $menu = array("Authentication & authorization" => array("Users" => array("cms/user", "users.png"), "Roles" => array("cms/role", "roles.png"), "Organisations" => array("cms/organisation", "organisations.png"), "Access" => array("cms/access", "access.png"), "Flags" => array("cms/flag", "flags.png"), "User switch" => array("cms/switch", "switch.png")), "Content" => array("Agenda" => array("cms/agenda", "agenda.png"), "Dictionary" => array("cms/dictionary", "dictionary.png"), "F.A.Q." => array("cms/faq", "faq.png"), "Files" => array("cms/file", "file.png"), "Forum" => array("cms/forum", "forum.png"), "Guestbook" => array("cms/guestbook", "guestbook.png"), "Languages" => array("cms/language", "language.png"), "Links" => array("cms/links", "links.png"), "Menu" => array("cms/menu", "menu.png"), "News" => array("cms/news", "news.png"), "Pages" => array("cms/page", "page.png"), "Polls" => array("cms/poll", "poll.png"), "Weblog" => array("cms/weblog", "weblog.png")), "Photo album" => array("Albums" => array("cms/album", "album.png"), "Collections" => array("cms/collection", "collection.png"), "Photos" => array("cms/photo", "photo.png")), "Newsletter" => array("Newsletter" => array("cms/newsletter", "newsletter.png"), "Subscriptions" => array("cms/subscriptions", "subscriptions.png")), "System" => array("Logging" => array("cms/logging", "logging.png"), "Action log" => array("cms/action", "action.png"), "Settings" => array("cms/settings", "settings.png"), "API test" => array("cms/apitest", "apitest.png")));
     /* Show warnings
      */
     if ($this->user->is_admin) {
         if (module_exists("setup")) {
             $this->output->add_system_warning("The setup module is still available. Remove it from settings/public_modules.conf.");
         }
         if ($this->user->id == 1 && $this->user->password == "c10b391ff5e75af6ee8469539e6a5428f09eff7e693d6a8c4de0e5525cd9b287") {
             $this->output->add_system_warning("Don't forget to change the password of the admin account!");
         }
         if ($this->settings->secret_website_code == "CHANGE_ME_INTO_A_RANDOM_STRING") {
             $this->output->add_system_warning("Don't forget to change the secret_website_code setting.");
         }
         if (is_true(DEBUG_MODE)) {
             $this->output->add_system_warning("Website is running in debug mode. Set DEBUG_MODE in settings/website.conf to 'no'.");
         }
     }
     if ($this->page->pathinfo[1] != null) {
         $this->output->add_system_warning("The administration module '%s' does not exist.", $this->page->pathinfo[1]);
     }
     /* Show icons
      */
     if (is_false(MULTILINGUAL)) {
         unset($menu["Content"]["Languages"]);
     }
     $access_list = page_access_list($this->db, $this->user);
     $private_modules = config_file("private_modules");
     $this->output->open_tag("menu");
     foreach ($menu as $text => $section) {
         $this->output->open_tag("section", array("text" => $text, "class" => strtr(strtolower($text), " &", "__")));
         foreach ($section as $text => $info) {
             list($module, $icon) = $info;
             if (in_array($module, $private_modules) == false) {
                 continue;
             }
             if (isset($access_list[$module])) {
                 $access = $access_list[$module] > 0;
             } else {
                 $access = true;
             }
             $this->output->add_tag("entry", $module, array("text" => $text, "access" => show_boolean($access), "icon" => $icon));
         }
         $this->output->close_tag();
     }
     $this->output->close_tag();
 }
Exemple #13
0
 public function fire()
 {
     $options = $this->option();
     $debug = is_true($options['debug']);
     if ($options['job'] == 'expired_tasks') {
         $this->info("Looking for expired tasks...");
         $tasks = Task::unClaimed()->get()->filter(function ($task) {
             if ($task->notifications()->forEvent(Notification::NOTIFICATION_TASK_EXPIRED)->get()->count() == 0 && $task->isExpired()) {
                 return $task;
             }
         });
         foreach ($tasks as $task) {
             $ago = $task->date->diffForHumans();
             $this->info("({$task->id}) {$task->title} Expired - {$ago}");
             $n = $task->notifications()->forEvent(Notification::NOTIFICATION_TASK_EXPIRED)->get()->count();
             if ($n == 0) {
                 Notification::fire($task, Notification::NOTIFICATION_TASK_EXPIRED);
                 $this->info("\tNotification Created " . $task->id);
             } else {
                 $this->info("*** Notification not sent");
             }
         }
         if ($tasks->count() == 0) {
             $this->info("*** No expired tasks found ***");
         }
         return;
     }
     if ($options['job'] == 'notifications') {
         // first get all users that want to receive notifications
         $users = User::where('notifications', '=', 1)->get();
         // get all notifications that have not been sent out
         $notifications = Notification::whereNull('sent_at')->get();
         if ($notifications->count() == 0) {
             $this->info("*** No New Notification ***");
             return;
         }
         $results = [];
         foreach ($notifications as $notice) {
             $this->info("Notification: " . $notice->getTitle() . " : " . $notice->event);
             $status = $notice->send($debug);
             $this->info("\t status: " . strbool($status));
         }
         return $results;
     }
 }
Exemple #14
0
 public function execute()
 {
     $menu = array("Authentication, authorization & system" => array("Users" => array("cms/user", "users.png"), "Roles" => array("cms/role", "roles.png"), "Organisations" => array("cms/organisation", "organisations.png"), "Access" => array("cms/access", "access.png"), "User switch" => array("cms/switch", "switch.png"), "Action log" => array("cms/action", "action.png"), "Settings" => array("cms/settings", "settings.png")), "Content" => array("Files" => array("cms/file", "file.png"), "Hostnames" => array("cms/hostname", "hostname.gif"), "Menu" => array("cms/menu", "menu.png"), "Pages" => array("cms/page", "page.png"), "Webservers" => array("cms/webserver", "webserver.png")));
     /* Show warnings
      */
     if ($this->user->is_admin) {
         if ($this->user->id == 1 && $this->user->password == "610706e9a48f85476e04d270bd6dc7492cdcd9ad7e91878007dff629ab11f195") {
             $this->output->add_system_warning("Don't forget to change the password of the admin account!");
         }
         if ($this->settings->secret_website_code == "CHANGE_ME_INTO_A_RANDOM_STRING") {
             $this->output->add_system_warning("Don't forget to change the secret_website_code setting.");
         }
         if (is_true(DEBUG_MODE)) {
             $this->output->add_system_warning("Website is running in debug mode. Set DEBUG_MODE in settings/website.conf to 'no'.");
         }
     }
     if ($this->page->pathinfo[1] != null) {
         $this->output->add_system_warning("The administration module '%s' does not exist.", $this->page->pathinfo[1]);
     }
     /* Show icons
      */
     if (is_false(MULTILINGUAL)) {
         unset($menu["Content"]["Languages"]);
     }
     $access_list = page_access_list($this->db, $this->user);
     $private_pages = config_file("private_pages");
     $this->output->open_tag("menu");
     foreach ($menu as $text => $section) {
         $this->output->open_tag("section", array("text" => $text, "class" => strtr(strtolower($text), " &", "__")));
         foreach ($section as $text => $info) {
             list($page, $icon) = $info;
             if (in_array($page, $private_pages) == false) {
                 continue;
             }
             if (isset($access_list[$page])) {
                 $access = $access_list[$page] > 0;
             } else {
                 $access = true;
             }
             $this->output->add_tag("entry", $page, array("text" => $text, "access" => show_boolean($access), "icon" => $icon));
         }
         $this->output->close_tag();
     }
     $this->output->close_tag();
 }
Exemple #15
0
 public function __get($key)
 {
     if ($this->valid_key($key) == false) {
         return null;
     }
     if (isset($this->cache[$key])) {
         return $this->cache[$key];
     }
     if ($this->db === null) {
         return null;
     } else {
         if ($this->db->connected == false) {
             return null;
         }
     }
     $query = "select * from settings where %S=%s";
     if (($setting = $this->db->execute($query, "key", $key)) === false) {
         return null;
     } else {
         if (count($setting) == 0) {
             printf("Unknown setting: %s\n", $key);
             return null;
         }
     }
     $value = $setting[0]["value"];
     switch ($setting[0]["type"]) {
         case "boolean":
             $value = is_true($value);
             break;
         case "float":
             $value = (double) $value;
             break;
         case "integer":
             $value = (int) $value;
             break;
     }
     $this->cache[$key] = $value;
     return $value;
 }
Exemple #16
0
 public function update_weblog($weblog)
 {
     if ($this->get_weblog($weblog["id"]) == false) {
         return false;
     }
     $keys = array("title", "content", "visible");
     $weblog["visible"] = is_true($weblog["visible"]) ? YES : NO;
     if ($this->db->query("begin") === false) {
         return false;
     } else {
         if ($this->db->update("weblogs", $weblog["id"], $weblog, $keys) === false) {
             $this->db->query("rollback");
             return false;
         } else {
             if ($this->handle_tags($weblog["id"], $weblog) == false) {
                 $this->db->query("rollback");
                 return false;
             }
         }
     }
     /* Delete comments
      */
     if (is_array($weblog["comment"])) {
         foreach ($weblog["comment"] as $comment_id) {
             if ($this->db->delete("weblog_comments", $comment_id) === false) {
                 $this->db->query("rollback");
                 return false;
             }
         }
     }
     return $this->db->query("commit") != false;
 }
 protected function add_search_filter(&$query, &$args, $search)
 {
     $filter = array();
     foreach ($this->elements as $key => $element) {
         switch ($element["type"]) {
             case "boolean":
                 if (in_array(strtolower($search), array("yes", "no"))) {
                     array_push($filter, "%S=%d");
                     array_push($args, $key, is_true($search) ? YES : NO);
                 }
                 break;
             case "date":
                 array_push($filter, "DATE_FORMAT(%S.%S, %s) like %s");
                 array_push($args, $this->table, $key, "%W %d %M %Y", "%" . $search . "%");
                 break;
             case "foreignkey":
                 if (is_array($element["column"]) == false) {
                     array_push($filter, "%S.%S like %s");
                     array_push($args, $element["table"], $element["column"], "%" . $search . "%");
                 } else {
                     $concat = array();
                     foreach ($element["column"] as $column) {
                         array_push($concat, "%S.%S");
                         array_push($args, $element["table"], $column);
                     }
                     array_push($filter, "concat(" . implode(", ", $concat) . ") like %s");
                     array_push($args, "%" . $search . "%");
                 }
                 break;
             case "timestamp":
                 array_push($filter, "DATE_FORMAT(%S.%S, %s) like %s");
                 array_push($args, $this->table, $key, "%W %d %M %Y %T", "%" . $search . "%");
                 break;
             default:
                 array_push($filter, "%S.%S like %s");
                 array_push($args, $this->table, $key, "%" . $search . "%");
         }
     }
     $query .= " (" . implode(" or ", $filter) . ")";
 }
Exemple #18
0
 public function update_user($user)
 {
     $keys = array("username", "fullname", "email", "cert_serial", "daily_report");
     if ($user["password"] != "") {
         array_push($keys, "password");
     }
     if ($this->user->is_admin) {
         array_push($keys, "organisation_id");
     }
     if (is_array($user["roles"]) == false) {
         $user["roles"] = array();
     }
     if ($this->user->id != $user["id"]) {
         array_push($keys, "status");
     } else {
         if (($current = $this->get_user($user["id"])) == false) {
             return false;
         } else {
             if (in_array(ADMIN_ROLE_ID, $current["roles"]) && in_array(ADMIN_ROLE_ID, $user["roles"]) == false) {
                 array_unshift($user["roles"], ADMIN_ROLE_ID);
             }
         }
     }
     if ($user["cert_serial"] == "") {
         $user["cert_serial"] = null;
     }
     $user["daily_report"] = is_true($user["daily_report"]) ? YES : NO;
     if ($this->db->query("begin") == false) {
         return false;
     }
     if ($this->db->update("users", $user["id"], $user, $keys) === false) {
         $this->db->query("rollback");
         return false;
     }
     if ($this->assign_roles_to_user($user) == false) {
         $this->db->query("rollback");
         return false;
     }
     if ($this->assign_webservers_to_user($user) === false) {
         $this->db->query("rollback");
         return false;
     }
     return $this->db->query("commit") != false;
 }
Exemple #19
0
 public function update_webserver($webserver)
 {
     $keys = array("name", "ip_address", "port", "tls", "active");
     $webserver["tls"] = is_true($webserver["tls"]) ? YES : NO;
     $webserver["active"] = is_true($webserver["active"]) ? YES : NO;
     if ($this->db->query("begin") === false) {
         return false;
     }
     if ($this->db->update("webservers", $webserver["id"], $webserver, $keys) === false) {
         $this->db->query("rollback");
         return false;
     }
     if ($this->assign_users_to_webserver($webserver) == false) {
         $this->db->query("rollback");
         return false;
     }
     return $this->db->query("commit") !== false;
 }
Exemple #20
0
 protected static function NOT_TRUE($var1)
 {
     return !is_true($var1) ? true : false;
 }
Exemple #21
0
    $_output->open_tag("content", array("mobile" => show_boolean($_output->mobile)));
}
/* Include the controller
 */
if (file_exists($file = "../controllers/" . $_page->module . ".php")) {
    include $file;
    $controller_class = str_replace("/", "_", $_page->module) . "_controller";
    if (class_exists($controller_class) == false) {
        print "Controller class '" . $controller_class . "' does not exist.\n";
    } else {
        if (is_subclass_of($controller_class, "controller") == false) {
            print "Controller class '" . $controller_class . "' does not extend 'controller'.\n";
        } else {
            $_controller = new $controller_class($_database, $_settings, $_user, $_page, $_output, $_language);
            $method = "execute";
            if (is_true(URL_PARAMETERS)) {
                $reflection = new reflectionobject($_controller);
                $param_count = count($reflection->getmethod($method)->getParameters());
                unset($reflection);
                $params = array_pad($_page->parameters, $param_count, null);
                call_user_func_array(array($_controller, $method), $params);
            } else {
                $_controller->{$method}();
            }
            unset($_controller);
            if ($_output->disabled) {
                print ob_get_clean();
                exit;
            }
            while ($_output->depth > 2) {
                print "System error: controller didn't close an open tag.";
 /**
  * vdebug()
  * 
  * @param mixed $data
  * @param bool $die FALSE
  * @param bool $add_var_dump FALSE
  * @param bool $add_last_query TRUE
  * @return void
  */
 function vdebug($data, $die = false, $add_var_dump = false, $add_last_query = true)
 {
     $CI =& get_instance();
     $CI->load->library('unit_test');
     $bt = debug_backtrace();
     $src = file($bt[0]["file"]);
     $line = $src[$bt[0]['line'] - 1];
     # Match the function call and the last closing bracket
     preg_match('#' . __FUNCTION__ . '\\((.+)\\)#', $line, $match);
     $max = strlen($match[1]);
     $varname = NULL;
     $c = 0;
     for ($i = 0; $i < $max; $i++) {
         if ($match[1][$i] == "(") {
             $c++;
         } elseif ($match[1][$i] == ")") {
             $c--;
         }
         if ($c < 0) {
             break;
         }
         $varname .= $match[1][$i];
     }
     if (is_object($data)) {
         $message = 'Variable holds an OBJECT';
     } elseif (is_array($data)) {
         $message = 'Variable holds an ARRAY';
     } elseif (is_string($data)) {
         $message = 'Variable holds a  STRING';
     } elseif (is_int($data)) {
         $message = 'Variable holds a  INTEGER';
     } elseif (is_true($data)) {
         $message = 'Variable holds a  TRUE BOOLEAN';
     } elseif (is_false($data)) {
         $message = 'Variable holds a  FALSE BOOLEAN';
     } elseif (is_null($data)) {
         $message = 'Variable is NULL';
     } elseif (is_float($data)) {
         $message = 'Variable is FLOAT';
     } else {
         $message = 'N/A';
     }
     $output = '<div style="clear:both;"></div>';
     $output .= '<meta charset="UTF-8" />';
     $output .= '<style>::selection{background-color:#E13300!important;color:#fff}::moz-selection{background-color:#E13300!important;color:#fff}::webkit-selection{background-color:#E13300!important;color:#fff}div.debugbody{background-color:#fff;margin:40px;font:9px/12px normal;font-family:Arial,Helvetica,sans-serif;color:#4F5155;min-width:500px}a.debughref{color:#039;background-color:transparent;font-weight:400}h1.debugheader{color:#444;background-color:transparent;border-bottom:1px solid #D0D0D0;font-size:12px;line-height:14px;font-weight:700;margin:0 0 14px;padding:14px 15px 10px;font-family:Consolas}code.debugcode{font-family:Consolas,Monaco,Courier New,Courier,monospace;font-size:12px;background-color:#f9f9f9;border:1px solid #D0D0D0;color:#002166;display:block;margin:10px 0;padding:5px 10px 15px}pre.debugpre{display:block;padding:0;margin:0;color:#002166;font:12px/14px normal;font-family:Consolas,Monaco,Courier New,Courier,monospace;background:0;border:0}div.debugcontent{margin:0 15px}p.debugp{margin:0;padding:0}.debugitalic{font-style:italic}.debutextR{text-align:right;margin-bottom:0;margin-top:0}.debugbold{font-weight:700}p.debugfooter{text-align:right;font-size:11px;border-top:1px solid #D0D0D0;line-height:32px;padding:0 10px;margin:20px 0 0}div.debugcontainer{margin:10px;border:1px solid #D0D0D0;-webkit-box-shadow:0 0 8px #D0D0D0}code.debug p{padding:0;margin:0;width:100%;text-align:right;font-weight:700;text-transform:uppercase;border-bottom:1px dotted #CCC;clear:right}code.debug span{float:left;font-style:italic;color:#CCC}</style>';
     $output .= '<div class="debugbody"><div class="debugcontainer">';
     $output .= '<h1 class="debugheader">' . $varname . '</h1>';
     $output .= '<div class="debugcontent">';
     $output .= '<code class="debugcode"><p class="debugp debugbold debutextR">:: Variable Type</p>' . $message . '</code>';
     if ($add_last_query) {
         if ($CI->db->last_query()) {
             $output .= '<code class="debugcode"><p class="debugp debugbold debutextR">:: $CI->db->last_query()</p>';
             $output .= $CI->db->last_query();
             $output .= '</code>';
         }
     }
     $output .= '<code class="debugcode"><p class="debugp debugbold debutextR">:: print_r</p><pre class="debugpre">';
     ob_start();
     print_r($data);
     $output .= trim(ob_get_clean());
     $output .= '</pre></code>';
     if ($add_var_dump) {
         $output .= '<code class="debugcode"><p class="debugp debugbold debutextR">:: var_dump</p><pre class="debugpre">';
         ob_start();
         var_dump($data);
         $vardump = trim(ob_get_clean());
         $vardump = preg_replace("/\\]\\=\\>\n(\\s+)/m", "] => ", $vardump);
         $output .= $vardump;
         $output .= '</pre></code>';
     }
     $output .= '</div><p class="debugfooter">Vayes Debug Helper © Yahya A. Erturan</p></div></div>';
     $output .= '<div style="clear:both;"></div>';
     if (PHP_SAPI == 'cli') {
         echo $varname . ' = ' . PHP_EOL . $output . PHP_EOL . PHP_EOL;
         return;
     }
     echo $output;
     if ($die) {
         exit;
     }
 }
Exemple #23
0
 private function fix_key_type($item)
 {
     switch ($item["type"]) {
         case "boolean":
             $item["value"] = is_true($item["value"]) ? "true" : "false";
             break;
         case "float":
             $item["value"] = rtrim((double) $item["value"], "0");
             break;
         case "integer":
             $item["value"] = (int) $item["value"];
             break;
     }
     return $item;
 }
Exemple #24
0
function show_boolean($bool)
{
    return is_true($bool) ? "yes" : "no";
}
Exemple #25
0
 public function add_javascript($script)
 {
     if (substr($script, 0, 7) != "http://" && substr($script, 0, 8) != "https://") {
         if (file_exists("js/" . $script) == false) {
             if (is_true(DEBUG_MODE)) {
                 printf("Javascript %s not found.\n", $script);
             }
             return false;
         }
         $script = "/js/" . $script;
     }
     if (in_array($script, $this->javascripts) == false) {
         array_push($this->javascripts, $script);
     }
     return true;
 }
Exemple #26
0
<?php

/* Because the model file is loaded before any output is generated,
 * it is used to handle the login submit.
 */
$login_successful = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    /* Login via password
     */
    if ($_user->login_password($_POST["username"], $_POST["password"], is_true($_POST["use_cr_method"]))) {
        if (is_true($_POST["bind_ip"])) {
            $_user->bind_to_ip();
        }
        $_SERVER["REQUEST_METHOD"] = "GET";
        $_POST = array();
        $login_successful = true;
    } else {
        $_user->log_action("login failed: %s", $_POST["username"]);
    }
} else {
    if (isset($_GET["login"])) {
        /* Login via one time key
         */
        if ($_user->login_one_time_key($_GET["login"])) {
            $login_successful = true;
        }
    } else {
        if ($_SERVER["HTTPS"] == "on" && isset($_SERVER[TLS_CERT_SERIAL_VAR])) {
            /* Login via client SSL certificate
             */
            if ($_user->login_ssl_auth($_SERVER[TLS_CERT_SERIAL_VAR])) {
Exemple #27
0
 public function update_page($page, $page_id)
 {
     $keys = array("url", "language", "layout", "private", "style", "title", "description", "keywords", "content", "visible", "back");
     $page["private"] = is_true($page["private"]) ? 1 : 0;
     $page["visible"] = is_true($page["visible"]) ? 1 : 0;
     $page["back"] = is_true($page["back"]) ? 1 : 0;
     if ($page["layout"] == $this->default_layout) {
         $page["layout"] = null;
     }
     if ($page["style"] == "") {
         $page["style"] = null;
     }
     if ($this->db->query("begin") == false) {
         return false;
     } else {
         if ($this->db->update("pages", $page_id, $page, $keys) === false) {
             $this->db->query("rollback");
             return false;
         } else {
             if ($this->save_access($page_id, $page["roles"]) == false) {
                 $this->db->query("rollback");
                 return false;
             }
         }
     }
     return $this->db->query("commit") != false;
 }
Exemple #28
0
 public function testIsNotTrue()
 {
     $this->assertFalse(is_true(null));
 }
Exemple #29
0
 public function execute($errors)
 {
     $errors = str_replace("<br />", "", trim($errors));
     if (is_true(DEBUG_MODE)) {
         $this->add_to_output($errors);
     } else {
         $this->send_via_email($errors);
     }
 }
Exemple #30
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save user") {
             /* Fix password
              */
             if (is_true($_POST["generate"])) {
                 $_POST["password"] = random_string(10);
             }
             /* Save user
              */
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_user_form($_POST);
             } else {
                 if (isset($_POST["id"]) === false) {
                     /* Create user
                      */
                     if ($this->model->create_user($_POST) === false) {
                         $this->output->add_message("Database error while creating user.");
                         $this->show_user_form($_POST);
                     } else {
                         $this->user->log_action("user %s created", $_POST["username"]);
                         if (is_true($_POST["generate"])) {
                             $this->model->send_notification($_POST);
                         }
                         $this->show_user_overview();
                     }
                 } else {
                     /* Update user
                      */
                     $username = $this->model->get_username($_POST["id"]);
                     if ($this->model->update_user($_POST) === false) {
                         $this->output->add_message("Database error while updating user.");
                         $this->show_user_form($_POST);
                     } else {
                         if ($_POST["username"] == $username) {
                             $name = $_POST["id"];
                         } else {
                             $name = sprintf("%s -> %s", $username, $_POST["username"]);
                         }
                         $this->user->log_action("user %s updated", $name);
                         if (is_true($_POST["generate"])) {
                             $this->model->send_notification($_POST);
                         }
                         $this->show_user_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete user") {
                 /* Delete user
                  */
                 $username = $this->model->get_username($_POST["id"]);
                 if ($this->model->delete_oke($_POST["id"]) == false) {
                     $this->show_user_form($_POST);
                 } else {
                     if ($this->model->delete_user($_POST["id"]) == false) {
                         $this->output->add_tag("result", "Database error while deleting user.");
                     } else {
                         $this->user->log_action("user %s deleted", $username);
                         $this->show_user_overview();
                     }
                 }
             } else {
                 $this->show_user_overview();
             }
         }
     } else {
         if ($this->page->pathinfo[2] == "new") {
             /* Show the user webform
              */
             $user = array("organisation_id" => $this->user->organisation_id, "roles" => array(ADMIN_ROLE_ID + 1), "status" => USER_STATUS_CHANGEPWD);
             $this->show_user_form($user);
         } else {
             if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Show the user webform
                  */
                 if (($user = $this->model->get_user($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "User not found.");
                 } else {
                     $this->show_user_form($user);
                 }
             } else {
                 /* Show a list of all users
                  */
                 $this->show_user_overview();
             }
         }
     }
 }