I have two websites running on the same server, the first is an owncloud server, the second a site built from scratch. The second site will only be accessible to users currently logged into their owncloud account, but I'm struggling to get the public lib working for me. What I have so far.
<?php
require_once '/var/www/owncloud9/html/lib/base.php';
require_once '/var/www/owncloud9/html/lib/public/user.php';
if ( \OCP\User::isLoggedIn() )
echo( "Hi ".\OCP\User::getDisplayName()."\n" );
else
echo( "You are not logged in.\n");
?>
The result is always "You are not logged in" even though that is not the case. How do I get the second site to detect the user's owncloud session?
You have to add some comments, like in https://github.com/pbek/qownnotesapi/blob/develop/controller/noteapicontroller.php.
/**
* Returns information about the ownCloud server
*
* #NoAdminRequired
* #NoCSRFRequired
* #CORS
*
* #return string
*/
public function getAppInfo() {
$appManager = \OC::$server->getAppManager();
$versionsAppEnabled = $appManager->isEnabledForUser('files_versions');
$trashAppEnabled = $appManager->isEnabledForUser('files_trashbin');
$notesPathExists = false;
$notesPath = $this->request->getParam( "notes_path", "" );
// check if notes path exists
if ($notesPath !== "")
{
$notesPath = "/files" . (string)$notesPath;
$view = new \OC\Files\View('/' . $this->user);
$notesPathExists = $view->is_dir($notesPath);
}
return [
"versions_app" => $versionsAppEnabled,
"trash_app" => $trashAppEnabled,
"versioning" => true,
"app_version" => \OC::$server->getConfig()->getAppValue('qownnotesapi', 'installed_version'),
"server_version" => \OC::$server->getSystemConfig()->getValue('version'),
"notes_path_exists" => $notesPathExists,
];
}
#NoAdminRequired and #NoCSRFRequired in the comments above the method turn off security checks.
(see: https://doc.owncloud.org/server/9.0/developer_manual/app/tutorial.html)
If you now make to your requests with simple auth it should work.
Example: https://user:password#your-server/path/to/your/controller
I do that for example in OwnCloudService::checkAppInfo at https://github.com/pbek/QOwnNotes/blob/develop/src/services/owncloudservice.cpp#L322
Related
public function onSystemCron(&$logs, &$lastRun, $force)
{
$clear_tmp = true;
$clear_logs = [];
$log_files = $this->_application->Filter('system_admin_system_logs', []);
foreach ($log_files as $log_name => $log) {
$clear_logs[$log_name] = empty($log['days']) ? 365 : $log['days'];
}
if (!isset($lastRun[$this->_name])) {
$lastRun[$this->_name] = [];
} elseif (!is_array($lastRun[$this->_name])) {
$lastRun[$this->_name] = [
'tmp' => $lastRun[$this->_name]
];
}
if (!$force) {
if (!empty($lastRun[$this->_name]['tmp'])
&& time() - $lastRun[$this->_name]['tmp'] < 604800
) {
// Less than a week since last run so do not clear tmp
$clear_tmp = false;
}
<?php
namespace -\System\Tool;
class RunCronTool extends AbstractTool
{
protected function _systemToolInfo()
{
return [
'label' => __('Run cron', 'directories'),
'description' => __('Use this tool to manually run cron.', 'directories'),
'weight' => 15,
];
}
public function systemToolRunTask($task, array $settings, $iteration, $total, array &$storage, array &$logs)
{
$this->_application->callHelper('System_Cron', [&$logs, true]);
return 1;
}
}
I have an issue with a WordPress plugin. It offers a button which will force run cron. Usually, making use of this button is not necessary. I tested my WP Cron and it's working fine, so the plugin is the problem. Any data which is in relation to the plugin does not get updated by WP cron. So I'm forced to click this button manually.
So, is there any solution to automate the function of the button?
I mean, I have to open the plugin settings and click on a button to run Cron. Is there any chance to automate this process?
Can provide more information if needed.
Many thanks.
Yes, I have no idea what I'm doing thanks.
When the OS wants to "kick" WordPress's cron system, it does an HTTP(S) GET to example.com/wp-cron.php .
It's possible to do this from php code, like so.
if ( ! wp_doing_cron() ) {
$url = get_site_url( null, 'wp-cron.php' );
$req = new \WP_Http();
$req->get( $url );
}
Do this last in a page view. I do it from the shutdown hook. It won't hang your page because wp-cron.php uses fastcgi_finish_request() to respond immediately to its client.
This lets you run cron from your code if DISABLE_WP_CRON is true or in other circumstances where it won't get called on its own.
But be careful. Don't use this unless you really need it. It's a bad idea to work around a site owner's need to set DISABLE_WP_CRON.
I am facing issue when i add user using RestApi
include "vendor/autoload.php";
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;
$api->secret = "mySecretKey";
$api->host = "HostName";
$api->port = "9090";
$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1"; // plugin
For adding user to Roster i am using following code
$jid="xyz#domainname";
//Add to roster
$data=$api->addToRoster("abc", $jid);
Which points to OpenFireRestApi.php which do have function named addToRoster
/**
* Adds to this OpenFire user's roster
*
* #param string $username Username
* #param string $jid JID
* #param string|false $name Name (Optional)
* #param int|false $subscription Subscription (Optional)
* #return json|false Json with data or error, or False when something went fully wrong
*/
public function addToRoster($username, $jid, $name=false, $subscription=false)
{
$endpoint = '/users/'.$username.'/roster';
return $this->doRequest('post', $endpoint, compact('jid','name','subscription'));
}
So I've used
$data=$api->addToRoster("abc", $jid,"DummyName",3);
Where 3 is subscription type as both = 3 which is mentioned.
But when i add user shows subscription type as none only.
UPDATE
I came to know about subscription plugin
So I've installed plugin configure it
Plugin itself says it will automatically subscribe both way.
Afterwards i've again tried with
$data=$api->addToRoster("abc", $jid);
Which aspects to be working but again subscriptions is none only.
Any Help would be appreciated.
There is problem with php-openfire-restapi classes
Need to change name of parameters
So do following changes :
//Add to roster
$username = "username in which you want to add roster";
$jid = "another users JID";
$nickname= "nick name of another user";
$subscription ="3";
$result = $api->addToRoster($username, $jid,$nickname,$subscription);
and change following line in /src/Gidkom/OpenFireRestApi/OpenFireRestApi.php file
public function addToRoster($username, $jid, $name=false, $subscription=false)
{
$nickname=$name;
$subscriptionType=$subscription;
$endpoint = '/users/'.$username.'/roster';
return $this->doRequest('post', $endpoint, compact('jid','nickname','subscriptionType'));
}
Here I have changed parameter names.
Good Luck.
How can I get the current browser name being used? I'm using Chrome and Firefox with my feature tests going under features -> chrome, features -> firefox. I want to take screenshots when a test fails. When I generate a screenshot, it just saves in my root dir. I want the file to be saved under the appropriate browser when I do this:
print_r($this->getSession()->getDriver())
I get that it has a private variable of browserName, but how do I access it?
[browserName:Behat\Mink\Driver\Selenium2Driver:private] => chrome
[desiredCapabilities:Behat\Mink\Driver\Selenium2Driver:private] => Array
(
[browserName] => chrome
[browser] => chrome
[version] => 25
[platform] => ANY
This is what worked for me.
$session = $this->getSession();
$driver = $session->getDriver();
$userAgent = $driver->evaluateScript('return navigator.userAgent');
$provider = $driver->evaluateScript('return navigator.vendor');
$browser = null;
if (preg_match('/google/i', $provider)) {
//using chrome
$browser = 'chrome';
} elseif (preg_match('/firefox/i',$userAgent)) {
$browser = 'firefox';
}
Have you tried executing
driver.executeScript("return navigator.userAgent;")
and parse the user agent string to get this information ?
This should help you get the browser name, its version, the OS information etc.,
Try this
/**
* Returns current browser name.
*
* #return string Browser name.
*/
function getBrowserName(): string
{
return $this->getCapabilities()['browserName'];
}
Just finished migrating a Magento website to a new server. Using the following steps:
-Backup the database in the backend
-Import the database on new server
-Copy all files from old server to new server
-Set correct file permissions
-Update /app/etc/local.xml
-Update secure and unsecure base_url in database
-Remove cache and session files
The website itself works fine, but it seems to give a fatal error on the order button now (see screenshot of source)
This is the block of code the error refers to:
/**
* Product type instance factory
*
* #param Mage_Catalog_Model_Product $product
* #param bool $singleton
* #return Mage_Catalog_Model_Product_Type_Abstract
*/
public static function factory($product, $singleton = false)
{
$types = self::getTypes();
$typeId = $product->getTypeId();
if (!empty($types[$typeId]['model'])) {
$typeModelName = $types[$typeId]['model'];
} else {
$typeModelName = self::DEFAULT_TYPE_MODEL;
$typeId = self::DEFAULT_TYPE;
}
if ($singleton === true) {
$typeModel = Mage::getSingleton($typeModelName);
}
else {
$typeModel = Mage::getModel($typeModelName);
$typeModel->setProduct($product);
}
$typeModel->setConfig($types[$typeId]); /**this is line 80**/
return $typeModel;
}
I also tried to make a fresh install and copy the needed files, but that did not work either.
This is my first time working with Magento, and searching online for a solution did not bring up anything useful to me. Could anyone point me to the right direction?
I want to put my module in Prestashop market place, and make it standard everyone can use it. This plugin needs to know the admin directory name dynamically to do its service.
I have searched on the Internet a lot of times, but I didn't find a solution to this issue.
You can use _PS_ADMIN_DIR_ witch is set in [your_admin_dir]/index.php:
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', getcwd());
}
This constant is only set when you're on an admin context. Your FrontOffice doesn't have knowledge of this directory and should not for obvious security reason.
There's also a getAdminLink method in class Link:
/**
* Use controller name to create a link
*
* #param string $controller
* #param bool $with_token include or not the token in the url
* #return string url
*/
public function getAdminLink($controller, $with_token = true)
{
$id_lang = Context::getContext()->language->id;
$params = $with_token ? array('token' => Tools::getAdminTokenLite($controller)) : array();
return Dispatcher::getInstance()->createUrl($controller, $id_lang, $params, false);
}
Example:
// Here we create a link to the dashboard without token
$this->context->link->getAdminLink(Tab::getClassNameById(1), false)