Example #1
0
 public function action_test()
 {
     /*$lock = BackendLock::get('testing', BackendLock::LOCK_CUSTOM);
     		if (!$lock) {
     			Backend::addError('Could not aquire lock');
     		} else {
     			Backend::addSuccess('Testing is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}
     		$lock = BackendLock::release('testing');
     		Backend::addSuccess('Testing is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		if ($lock = BackendLock::get('testing_expiry', BackendLock::LOCK_CUSTOM, '2010-01-01')) {
     			Backend::addSuccess('Testing Expiry is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}
     		if ($lock = BackendLock::get('testing_type', 5)) {
     			Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}*/
     if ($lock = BackendLock::get('testing_system', BackendLock::LOCK_SYSTEM)) {
         Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     } else {
         Backend::addSuccess('Should not get System lock (no expiry or password)');
     }
     if ($lock = BackendLock::get('testing_system', BackendLock::LOCK_SYSTEM, 'now + 1 minutes', 'Abc123')) {
         Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     } else {
         Backend::addError('Could not get System lock');
     }
     return false;
 }
Example #2
0
 public function action_check()
 {
     $roles = GateKeeper::getRoles();
     if (!$roles || !count($roles)) {
         if (Controller::$debug) {
             Backend::addNotice('No roles setup, addings some');
         }
         $roles = $this->getDefaultRoles();
         if ($roles) {
             foreach ($roles as $role) {
                 GateKeeper::assign($role['role'], $role['access_type'], $role['access_id']);
                 if (Controller::$debug) {
                     Backend::addSuccess('Added role ' . $role['role']);
                 }
             }
         }
         $permits = $this->getDefaultPermissions();
         if ($permits) {
             foreach ($permits as $permit) {
                 GateKeeper::permit($permit['role'], $permit['control'], $permit['action'], $permit['subject'], $permit['subject_id']);
                 if (Controller::$debug) {
                     Backend::addSuccess('Added permission to ' . $role['action'] . ' to ' . $permit['role']);
                 }
             }
         }
     } else {
         if (Controller::$debug) {
             var_dump($roles);
         }
     }
 }
Example #3
0
 public function html_tweet($result)
 {
     if ($result) {
         Backend::addSuccess('Tweeted!');
         Backend::addContent(var_export($result, true));
     }
 }
Example #4
0
 public static function add($hook, $type, $class, array $options = array())
 {
     if (!Backend::getDB('default')) {
         return false;
     }
     $mode = array_key_exists('mode', $options) ? $options['mode'] : '*';
     $name = array_key_exists('name', $options) ? $options['name'] : ucwords($class . ' ' . $type . ' ' . $hook);
     $description = array_key_exists('description', $options) ? $options['description'] : '';
     $method = array_key_exists('method', $options) ? $options['method'] : 'hook_' . ($type == 'post' ? 'post_' : '') . strtolower($hook);
     $global = array_key_exists('global', $options) ? $options['global'] : 0;
     $sequence = array_key_exists('sequence', $options) ? $options['sequence'] : 0;
     //Certain hooks should be global
     if (in_array($hook, array('init'))) {
         $global = 1;
     }
     $data = array('class' => $class, 'hook' => $hook, 'type' => $type, 'mode' => $mode, 'name' => $name, 'description' => $description, 'method' => $method, 'global' => $global, 'sequence' => $sequence);
     $hook = new HookObj();
     if ($hook->replace($data)) {
         Backend::addSuccess('Added hook ' . $name . '(' . $class . '::' . $method . ')');
         $toret = true;
     } else {
         Backend::addError('Could not add hook ' . $name . '(' . $class . '::' . $method . ')');
         $toret = false;
     }
     return $toret;
 }
Example #5
0
 public static function install(array $options = array())
 {
     $options['drop_table'] = array_key_exists('drop_table', $options) ? $options['drop_table'] : true;
     $toret = parent::install($options);
     foreach (self::getDefaults() as $assignment) {
         if (GateKeeper::assign($assignment['role'], $assignment['access_type'], $assignment['access_id'])) {
             Backend::addSuccess('Added assignment to ' . $assignment['role']);
             $toret = $toret && true;
         } else {
             Backend::addError('Could not add assignment to ' . $assignment['role']);
             $toret = false;
         }
     }
     return $toret;
 }
Example #6
0
 public static function add($name, $description, array $options = array())
 {
     $id = array_key_exists('id', $options) ? $options['id'] : null;
     $active = array_key_exists('active', $options) ? $options['active'] : null;
     $data = array('name' => $name, 'description' => $description, 'active' => $active);
     if (!is_null($active)) {
         $data['id'] = $id;
     }
     $RoleObj = new RoleObj();
     if ($RoleObj->replace($data)) {
         Backend::addSuccess('Added role ' . $data['name']);
         $toret = true;
     } else {
         Backend::addError('Could not add role ' . $data['name']);
         $toret = false;
     }
     return $toret;
 }
Example #7
0
 public static function doIndex(TableCtl $controller, $fields = array('content'))
 {
     if (!is_array($fields)) {
         $fields = array($fields);
     }
     //TODO This is a bad idea. rather use a query and while
     $object = $controller->get_list('all', 0);
     $total = false;
     if ($object->list) {
         $total = 0;
         $first = current($object->list);
         foreach ($fields as $field) {
             if (array_key_exists($field, $first)) {
                 $result = 0;
                 foreach ($object->list as $row) {
                     $info = str_word_count($row[$field], 1);
                     $counts = array_count_values($info);
                     $sequence = 0;
                     foreach ($counts as $word => $count) {
                         unset($counts[$word]);
                         if ($word = self::filter($word, $count)) {
                             $data = array('table' => $object->getSource(), 'table_id' => $row[$object->getMeta('id_field')], 'word' => $word, 'count' => $count, 'sequence' => $sequence++);
                             $b_search = new BackendSearchObj();
                             if ($b_search->replace($data)) {
                                 $result++;
                                 $total++;
                             } else {
                                 if ($b_search->error_msg != 'Error executing statement(1062)') {
                                     Backend::addError('Could not add ' . $word . ' to ' . get_class($controller) . '::' . $field . ' index');
                                 }
                             }
                         }
                     }
                 }
                 if ($result > 0) {
                     Backend::addSuccess($result . ' words were indexed for ' . get_class($controller) . '::' . $field);
                 }
             } else {
                 Backend::addError($field . ' does not exist in ' . get_class($object));
             }
         }
     }
     return $total;
 }
Example #8
0
 public function html_import($result)
 {
     switch (true) {
         case $result instanceof DBObject:
             if (!Backend::get('Sub Title')) {
                 Backend::add('Sub Title', 'Import');
                 Backend::add('Sub Title', 'Import ' . $result->getMeta('name'));
             }
             $template_file = array($result->getArea() . '.import.tpl.php', $result->getArea() . '/import.tpl.php');
             if (!Render::checkTemplateFile($template_file[0]) && !Render::checkTemplateFile($template_file[1])) {
                 $template_file = 'std_import.tpl.php';
             }
             Backend::addContent(Render::file($template_file, array('db_object' => $result)));
             break;
         case is_numeric($result) && $result >= 0:
             Backend::addSuccess($result . ' records imported');
             Controller::redirect('?q=' . Controller::$area . '/list');
             break;
         default:
             Controller::redirect();
             break;
     }
     return $result;
 }
Example #9
0
 public static function install(array $options = array())
 {
     $options['install_model'] = array_key_exists('install_model', $options) ? $options['install_model'] : false;
     $toret = parent::install($options);
     foreach (self::getDefaults() as $permit) {
         GateKeeper::permit($permit['role'], $permit['action'], $permit['subject'], $permit['subject_id'], $permit['control']);
         if (Controller::$debug) {
             Backend::addSuccess('Added permission to ' . $permit['action'] . ' to ' . $permit['role']);
         }
     }
     return $toret;
 }
Example #10
0
    public static function purgeUnconfirmed()
    {
        $query = new DeleteQuery('BackendUser');
        $query->filter('`confirmed` = 0')->filter('`added` < DATE_SUB(DATE(NOW()), INTERVAL 1 WEEK)');
        $deleted = $query->execute();
        Backend::addSuccess($deleted . ' unconfirmed users deleted');
        if ($deleted) {
            send_email(ConfigValue::get('author.Email', ConfigValue::get('application.Email', 'info@' . SITE_DOMAIN)), 'Unconfirmed Users purged: ' . $deleted, $deleted . ' users were deleted from the database.
They were unconfirmed, and more than a week old

Site Admin
');
        }
        return true;
    }
Example #11
0
 public function html_scaffold($result)
 {
     if (is_post() && $result) {
         Backend::addSuccess('Scaffolds created for ' . class_name(Controller::$parameters[0]));
         Controller::redirect();
     } else {
         if (!$result) {
             Controller::redirect();
         }
     }
     Backend::addContent(Render::file('admin.scaffold.tpl.php', $result));
     return $result;
 }
Example #12
0
 public function html_permissions($result)
 {
     if (is_post()) {
         if ($result === false) {
             Backend::addError('Could not update Permissions');
         } else {
             Backend::addSuccess($result . ' Permissions Updated');
         }
         Controller::redirect('previous');
     }
     //GET
     if (!empty(Controller::$parameters[0])) {
         Backend::add('Sub Title', class_name(Controller::$parameters[0]) . ' Permissions');
         Links::add('All Permissions', '?q=gate_manager/permissions', 'secondary');
     } else {
         Backend::add('Sub Title', ConfigValue::get('Title') . ' Permissions');
     }
     Backend::addContent(Render::renderFile('gate_manager.permissions.tpl.php', (array) $result));
 }
Example #13
0
 public function action_check()
 {
     $toret = 0;
     $files = self::fromFolder();
     $table = Component::retrieve(false, 'list');
     $table = array_flatten($table, null, 'filename');
     foreach ($files as $component) {
         if (!in_array($component, $table)) {
             if (self::add($component)) {
                 Backend::addSuccess('Added ' . basename($component));
                 $toret++;
             }
         }
     }
     return $toret;
 }
Example #14
0
 function action_check()
 {
     if (!Backend::getConfig('application.file_provider', false)) {
         return false;
     }
     $files = Component::fromFolder();
     $count = 0;
     foreach ($files as $file) {
         if ($rev_id = bzr_get_file_revision(BACKEND_FOLDER . '/' . $file)) {
             $name = preg_replace('/\\.obj\\.php$/', '', basename($file));
             $be_file = BackendFile::retrieve($file, 'dbobject');
             if ($be_file->array) {
                 if ($rev_id != $be_file->array['version']) {
                     if ($be_file->update(array('version' => $rev_id))) {
                         $count++;
                         Backend::addSuccess($name . ' updated to ' . $rev_id);
                     } else {
                         Backend::addError('Could not update version for ' . $name);
                     }
                 }
             } else {
                 $data = array('name' => $name, 'file' => $file, 'version' => $rev_id, 'active' => 1);
                 if ($be_file->create($data)) {
                     $count++;
                     Backend::addSuccess($name . ' added');
                 } else {
                     Backend::addError('Could not add info for ' . $name);
                 }
             }
         }
     }
     return $count;
 }
Example #15
0
 /**
  * Redirect to a specified location.
  *
  * If the location is omitted, go to the current URL. If $location == 'previous', go the previous URL for the current mode.
  */
 public static function redirect($location = false)
 {
     if (self::$mode == self::MODE_REQUEST) {
         switch ($location) {
             case 'previous':
                 if (!empty($_SESSION['previous_url'])) {
                     if (is_array($_SESSION['previous_url'])) {
                         $location = !empty($_SESSION['previous_url'][self::$view->mode]) ? $_SESSION['previous_url'][self::$view->mode] : reset($_SESSION['previous_url']);
                     } else {
                         $location = $_SESSION['previous_url'];
                     }
                 } else {
                     $location = false;
                 }
                 break;
         }
         if (!$location) {
             $location = $_SERVER['REQUEST_URI'];
         }
         //The following is only for on site redirects
         if (substr($location, 0, 7) != 'http://' || substr($location, 0, strlen(SITE_LINK)) == SITE_LINK) {
             //This should fix most redirects, but it may happen that location == '?debug=true&q=something/or/another' or something similiar
             if (ConfigValue::get('CleanURLs', false) && substr($location, 0, 3) == '?q=') {
                 $location = SITE_LINK . substr($location, 3);
             }
             //Add some meta variables
             if (!empty($_SERVER['QUERY_STRING'])) {
                 parse_str($_SERVER['QUERY_STRING'], $vars);
                 $new_vars = array();
                 if (array_key_exists('debug', $vars)) {
                     $new_vars['debug'] = $vars['debug'];
                 }
                 if (array_key_exists('nocache', $vars)) {
                     $new_vars['nocache'] = $vars['nocache'];
                 }
                 if (array_key_exists('recache', $vars)) {
                     $new_vars['recache'] = $vars['recache'];
                 }
                 if (array_key_exists('mode', $vars)) {
                     $new_vars['mode'] = $vars['mode'];
                 }
                 $url = parse_url($location);
                 if (!empty($url['query'])) {
                     parse_str($url['query'], $old_vars);
                 } else {
                     $old_vars = array();
                 }
                 //Allow the redirect to overwrite these vars
                 $new_vars = array_merge($new_vars, $old_vars);
                 $old_url = parse_url(get_current_url());
                 $url['query'] = http_build_query($new_vars);
                 $url = array_merge($old_url, $url);
                 $location = build_url($url);
             }
         }
         try {
             if (self::$debug) {
                 Backend::addSuccess('The script should now redirect to <a href="' . $location . '">here</a>');
             } else {
                 //Redirect
                 header('X-Redirector: Controller-' . __LINE__);
                 header('Location: ' . $location);
                 die('redirecting to <a href="' . $location . '">');
             }
         } catch (Exception $e) {
             Backend::addError('Could not redirect');
         }
     }
     return true;
 }