Vtiger Custom Module : "Sorry! Attempt to access restricted file." - php

I have created a test module name Mytest. While saving values from the module, I am getting a blank page and it saying "Sorry! Attempt to access restricted file. " . Do anyone know, why this happening. Any help on this is really appreciating.

The most likely cause for the vTiger error “Sorry! Attempt to access restricted file.” is the $root_directory value in the ‘config.inc.php’ is incorrect or misspelled.
In order to correct it follow the steps below:
Go to your vTigerCRM directory
Open “config.inc.php” with your favorite text editor
Go to line 86 and adjust $root_directory value to correct vTiger
directory. Note, that the directory must end with /. It should look
something like this – $root_directory = ‘/var/www/vtigercrm/’;
Also there is a problem with cache memory. So do check your cache file for template files. For that go to your vTigerCRM directory.
Then Go to Smarty->templates_c.
Here you will get list of cache files. Delete this file and check weather your problem is solved or not.
Don't worry about deletion of this file.

When trying to include files from your custom module, you will get these messages because Vtiger thinks you are including these files from a location they find rather unsafe.
To avoid this error you could use the standard way a module is used in Vtiger by navigating to it like so: ......./index.php?module=Mytest&action=index. Vtiger will include your module and now there is no need for you to include CRMEntity and other data or utils related files. It should all be available this way but make sure you are using the global statement for $current_user, $current_module etc though.
Another way is to edit the following functions located in utils/CommonUtils.php:
heckFileAccessForInclusion() and checkFileAccess()
Remove or comment out the die() in these functions to fix it.

In Save.php file, just add a line.
$focus->column_fields['assigned_user_id'] = '';
before the
if($_REQUEST['assigntype'] == 'U') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif($_REQUEST['assigntype'] == 'T') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}

To second what caspersky said:
Go to /include/database/PearDatabase.php and add
$adb->setDebug(true); right after $adb->connect();
I just wrote a module and received this error and it was because the record could not save because I left out:
$moduleInstance->setEntityIdentifier($fieldInstance);

Check out file permissions and file path it's trying to refer.
If you want to debug more set $adb->setDebug(true) in your index file and checkout for the errors.

A couple of things spring to mind:
Have you actually created the modules/CustomeModule directory and populated
it? (Using the template in vtlib/ModuleDir/5.4.0 and then editing the
filenames and class of CustomeModule.php)
Check the case of your module class definition, e.g. class CustomeModule
vs. class Customemodule
If you are using any version control or symlinks in the development
of your modules/Mytest code then this can trigger the "Sorry! Attempt
to access restricted file." messages.
In module setup script make sure you have added this lines.
$module->initTables();
$module->initWebservice();

Check that all language files exist.
The user module allows the admin user to configure a user's language even though the language file is not present on disk.
To quickly verify this is indeed the issue :-
- Edit the include/utils/CommonUtils.php and print the $realfilepath variable ,and comment out the die();
- In the database, "select distinct language from xxx_users";
You can fix this by downloading the required files.
As a quick fix (read:hack):-
- go to the include/language directory
- copy an existing language file as the required one. (may not always work - for example en_us to en_gb is great, but en_us to sp_es is not)

It seems you did not set write permission for Smarty folder

Probably a file is missing in your vtiger install.
To find out which one is mission you would need to edit the include/utils/CommonUtils.php file. Open it with a text editor, go around line 2755 and add the following
echo “REAL: $realfilepath, ROOT: $rootdirpath”;
Before die(Sorry....)
This would print on the screen which one is the missing file.

Sometimes this error is caused by an nonexistent module, what I mean here is that vtiger thinks you have a module but the files are not in there (might be caused by a bad migration to a new server).
Disable some modules and try again until you find which module is broken.
In my case the broken module was VGS.

I solved this on vtiger 7.3.. (maybe it works for other vesion)
I went to users permission on vtiger inside configuration settings and update tham all again with the same settings .. and got them to a more default settings .. them all users appeared back and I was able to create new users ..change password again.
I suggest logging out and maybe forcing refresh and waiting a little to make it work .

Related

How to wp_dequeue_script or wp_deregister_script jquery (not effected) file from wp theme

NOTE: I already use wp_dequeue_script or wp_deregister_script but not successfull
Here is the scenario, i make a image slider plugin that use jquery-cycle2 and it work successfully.
There is a user who used a wp theme and in theme there is a jquery-cycle1, now when he install my plugin the jquery-cycle1 and jquery-cycle2 conflicts, when user delete the jquery-cycle1 file all things work fine and perfectly but i don't want to delete file by user.
Now i am trying that when user install my plugin the jquery-cycle1 in theme close or deregister or stop its effect.
I get file from theme successfully
if((file_exists($theme_file_path."/jquery.cycle.all.js"))){
echo "yes";
}
but i have no idea to close jquery-cycle1 file or stop its effect.
Last Option: I have last solution that delete the file from theme but its my last option.
Please any suggestions, help me.
You will have to place an incompatibility notice on your theme.
It is not possible to attempt to detect the existence of script from server side. You are able to detect queued scripts via the word press methods, however, this assumes that the user has not simply linked the file with a <script></script> tag. The file_exists method assume the file is stored on the server itself - it could be linked from a CDN or another server.
Also, whatever methods you use to detect and remove jQuery-Cycle; You are going to break any feature on the site that uses the existing plugin.
Thus, any solution you able to devise would either be extremely complicated, or would not be generalised enough to account for all these possibilities.
You may be able to use the following to prevent loading your script
if (jQuery().cycle) {
// Script already loaded
console.log("Error: Another version of jQuery-Cycle is already loaded!");
} else {
// Load your script
}
but this cannot unload what is already loaded.
There is a simple hack you can do on you end. In the Cycle2 source replace all $.fn.cycle with $.fn.cycle2 and ).cycle( to ).cycle2(.
I am using the source from here http://malsup.github.io/jquery.cycle2.js
After that You can access it like
$("#id").cycle2({option})
Here is a demo http://jsfiddle.net/33g6z79h/
Here i assume that you are not using cycle events http://jquery.malsup.com/cycle2/api/#events
and cycle extra transitions.
If you are using it you can make a fiddle for your cycle2 implementation and i would be glad to help :)

How to write debug messages to Silverstripe log file

I've got a Silverstripe 3.1 site in development and want to write messages to the default log file - silverstripe.log
This is what we use to output variables or messages to the screen:
Debug::show($variable);
Debug::message("Debug message goes here");
What is the simplest way to output these to the silverstripe.log file? I've been looking through the documentation and can't find the correct approach: http://doc.silverstripe.com/framework/en/topics/debugging
You could do the following:
in mysite/_config.php
SS_Log::add_writer(new SS_LogFileWriter('silverstripe.log'), SS_Log::WARN, '>');
in your code:
SS_Log::log("Dammit, an issue with variable ".$var, SS_Log::WARN);
More at http://doc.silverstripe.com/framework/en/topics/error-handling
Also reading the code in framework/dev/Log.php will give you more insight on how priorities work.
PS: ensure to define 'silverstripe.log' in a folder writable by the apache user
The simplest solution is actually pretty close to your original attempt.
Debug::log("output");
This will output to a debug.log file in the site root.

Opencart how to test if vqmod installed?

I have written a module that uses vqmod for opencart. How can I check if vqmod is installed from within the admin module?
I would like to display a warning inside of the module that checks if vqmod is installed? Even better would be to check if it also has correct write permission to generate cached files and write to the vamod.log
What is the best way of doing this?
PS: it would be cool if you could tag questions with vqmod. I dont have enough reputation to create a new tag.
/vqmod/install
if it is installed it will tell you "vqmod is already installed"
<?php
if(class_exists('VQMod')) {
// vqmod exists
}
?>
To check via code, you would need to do
global $vqmod;
if(!empty($vqmod) && is_a($vqmod, 'VQMod')) {
// INSTALLED
} else {
//
}
While #NADH's is along the right lines, it only checks that vqmod's class has been included, not that it's been set to the $vqmod variable
Edit
As of 2.4.0, this will no longer work, and it's recommended to use NADH's method
Based on your comments #John, since you're looking for confirmation that VQmod is installed and also executing correctly, the safest thing to do to is check for the filename you are expecting to appear in the vqmod/cache directory. You'll know the filename if you have created the vqmod/xml definition file yourself.
You could also check for the VQMod class existing like #NADH suggested, but it doesn't mean that its working correctly. A bit like writing unit tests, always assert on the desired output. In this case its' the cache file you are creating.

How do I use require_once()?

I create a PHP page with the following content:
<?php session_start(); ?>
<?php require_once(./classes/MaterialUtil.class.php);
$mUtil = new MaterialUtil();
?>
I put the MaterialUtil.class.php file in D:\xampp\htdocs\drupal\sites\all\themes\zeropoint\classes, but I get the following error message:
Parse error: syntax error, unexpected '.' in D:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code on line 7
Could you please tell me what I do wrong?
The error is caused from the fact you didn't use a string for the filename, and PHP understood the dot as being the concatenation operator; as such, because there wasn't any value before the operator, PHP gave you an error saying it found the concatenation operator in the wrong place.
As kalabro said, the correct code is the following one:
<?php session_start(); ?>
<?php require_once('./classes/MaterialUtil.class.php');
$mUtil = new MaterialUtil();
?>
This is the part of the answer that is not strictly related to Drupal.
What you are doing is not what I would suggest to do, for two reasons:
You are putting the "classes" directory in the wrong place. Those files are not related to the theme being enabled, but they are related to the page being viewed. Even if you have a single theme, and users are not allowed to select a theme for themselves, it still wrong to put those files in a theme directory.
Putting the files in the directory containing a theme, which will needs to be updated when a new version is available, could cause you to lose the additional files you added, if you are not careful.
Executing PHP through eval() to, e.g., get content to show in a node is not something that you should do. This is because:
As you have used the PHP filter for the node, the node becomes only editable to a restricted group of users. (I would not suggest to allow untrusted users to use PHP as input format)
When you have PHP code that you need to execute, it is always better to create a custom module that is enabled for the site.
If you were trying to include a PHP file from inside a module, then you should use module_load_include(), instead of require_once(), as already suggested by marcvangend.
XAMP server does not run on windows file system format. You must write your file location like localhost/xyz/abc ..

Disable a file include if it generates error (in php)

I would like to implement a simple plugin system for my script. I'll be including the files of the plugins which the user selects as available.
Currently, if any of the files has some parse error, it causes the complete thing to go down, until I hack into the db to remove that plugin entry.
Is there any easy way to do this? (Somehow check the files for parse errors atleast)?
You could make a HTTP request to a PHP file that tries to include the file, and outputs "OK" at the end.
Check_include.php:
$filename = $_GET["plugin"];
$filename = sanitize_filename($filename); // Here you make sure only plugins can be loaded
include ($filename);
echo "OK";
then, in your admin panel or whatever, call
file_get_contents("http://mydomain/check_include.php?plugin=my_new_plugin");
and see whether the result contains the word "OK". If the result is okay, there was no fatal error, and you can activate the plugin; otherwise, you can even output the error message that got output when trying to include it.
WordPress uses a variation of this involving an IFRAME to check new plugins.
Note: Making a HTTP request is expensive. You should under no circumstances do this every time the plugin is included, but only once on installation. Use a flag of some sort (e.g. a underscore _ in front of the plugin name) to enable / disable plugins.
No. A parse error is a fatal error that you cannot recover from.

Categories