REST API: Link Error

Forum dedicated to Mods for HESK created by Mike Koch

Moderator: mkoch227

Post Reply
Beleth
Posts: 4
Joined: Tue Jan 10, 2017 12:04 pm

REST API: Link Error

Post by Beleth »

Script URL:
Mods for HESK version: 3.1.1
HESK version: 2.7.3
Hosting company: my own vps
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: REST API: Link

Write your message below:

The Imap function doesn't works fine, some mails remains in mail account and are not updated in hesk replies. When mails are not managed to tickets i found this messages in register:

REST API: Link - Call to undefined function getallheaders()
#0 /var/www/vhosts/mydomain.com/httpdocs/hesk/api/Link.php(42): Link::getRequestMethod()
#1 /var/www/vhosts/mydomain.com/httpdocs/crm/api/index.php(225): Link::all(Array)
#2 {main}

(maybe related with this issue?)

Any idea?
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: REST API: Link Error

Post by mkoch227 »

Well, I thought I responded to this a while ago.... apparently not :?

Are you still having this issue? Looking at the stack trace, it appears you're switching between two different directories which seems odd. Also, the IMAP fetching function does not use the REST API in any way, so I'm not sure why you're seeing anything coming from the /api folder.
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
ingenuitor
Posts: 6
Joined: Sun Dec 03, 2017 2:45 pm

Re: REST API: Link Error

Post by ingenuitor »

I seem to have somewhat of the same issue: This happens when I try to send a notification email from this page > admin/admin_ticket.php?track=XYZ&Refresh=XYZ

Error occurred when trying to send notification email

I see this in the error logs page here > admin/view_message_log.php

Code: Select all

Date	User	Location	Message	Stack Trace
2017-12-03 14:42:23		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:41:55		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:41:55		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:41:18		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:41:18		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:39:31		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-03 14:39:30		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:35:07		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:35:07		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:29:27		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:29:27		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:08:46		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 18:08:36		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:42:42		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:42:42		REST API: index	/home/accountname/public_html/help/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/help/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:34:46		REST API: index	/home/accountname/public_html/support/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/support/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:34:46		REST API: index	/home/accountname/public_html/support/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/support/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:32:45		REST API: index	/home/accountname/public_html/support/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/support/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
2017-12-02 17:32:45		REST API: index	/home/accountname/public_html/support/api/Link.php:129 Call to undefined function getallheaders()	#0 /home/accountname/public_html/support/api/index.php(181): errorHandler(1, 'Call to undefin...', '/home/accountname/...', 129)
#1 [internal function]: fatalErrorShutdownHandler()
#2 {main}
Let me know your thoughts and how I can resolve this issue ASAP.
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: REST API: Link Error

Post by mkoch227 »

What version of PHP are you using? Also, are you using Apache or nginx?
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
ingenuitor
Posts: 6
Joined: Sun Dec 03, 2017 2:45 pm

Re: REST API: Link Error

Post by ingenuitor »

Hello,

Found on this page > /admin/admin_settings.php

HESK version: 2.7.5
Mods for HESK Version: 3.2.4
PHP version: 5.4.45 (MySQLi)
MySQL version: 5.6.38

For sure I'm using Apache on CentOS 6.9

Server Version: Apache/2.4.29 (cPanel) OpenSSL/1.0.2m mod_bwlimited/1.4
Server MPM: prefork
Server Built: Dec 4 2017 15:15:53

Looking at the cpanel settings here is what I can find. ea-php54 > php-fpm

I'm also seeing this error on the admin_settings.php page just when I go to the page that error shows up all the time, somewhat hidden under the left menu.

Image

Code: Select all

<div class="alert alert-warning">
<b>Note:</b> Your server does not allow large enough posts, try reducing number of attachments or allowed file size!</div>
Plus I still see all the api/Link.php:129 Call to undefined function getallheaders() errors growing by the day as the ticketing system is active. I did buy the paid version, it's a great software for sure, once these bugs are resolved, it will be perfect for my needs.

REF: Image

Thanks again for your help...
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: REST API: Link Error

Post by mkoch227 »

I see the issue now. Apparently PHP-FPM does not have the "getallheaders()" function which the REST API uses to pull any relevant request headers. I have a fix for this ready to go, so I hope to have it out sometime today.

If you want to apply this fix immediately, add the following to the end of /api/autoload.php:

Code: Select all

// Fix for getallheaders() on PHP-FPM
if (!function_exists('getallheaders')) {
    function getallheaders() {
        $headers = [];
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }
}
Regarding the warning; your setting allow for the possibility for a user to upload more attachments in a single ticket than your server supports. This is caulculated by taking the max # of attachments per ticket multiplied by the max size of a single attachment. If the value is larger than your PHP's max post size (post_max_size in php.ini), the warning will appear. Mods for HESK uses a drag & drop uploader which uploads each attachment individually, so this issue should not occur (unless your user's browser does not support the drag & drop uploader)
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
ingenuitor
Posts: 6
Joined: Sun Dec 03, 2017 2:45 pm

Re: REST API: Link Error

Post by ingenuitor »

Hello I tried what you posted here, thanks for such a fast response and sadly I now see this error and it still can't send a notification >

2017-12-06 20:58:11 Admin REST API: BasicEmailSender /home/account/public_html/help/api/BusinessLogic/Emails/BasicEmailSender.php:13 Array to string conversion

Code: Select all

Date	User	Location	Message	Stack Trace
2017-12-06 20:58:11	Admin	REST API: BasicEmailSender	/home/account/public_html/help/api/BusinessLogic/Emails/BasicEmailSender.php:13 Array to string conversion	#0 /home/account/public_html/help/api/BusinessLogic/Emails/BasicEmailSender.php(13): errorHandler(8, 'Array to string...', '/home/account/...', 13, Array)
#1 /home/account/public_html/help/api/BusinessLogic/Emails/EmailSenderHelper.php(72): BusinessLogic\Emails\BasicEmailSender->sendEmail(Object(BusinessLogic\Emails\EmailBuilder), Array, Array, '1')
#2 /home/account/public_html/help/api/Controllers/Tickets/ResendTicketEmailToCustomerController.php(72): BusinessLogic\Emails\EmailSenderHelper->sendEmailForTicket(2, 'English', Object(BusinessLogic\Emails\Addressees), Object(BusinessLogic\Tickets\Ticket), Array, Array)
#3 [internal function]: Controllers\Tickets\ResendTicketEmailToCustomerController->get('26111')
#4 /home/account/public_html/help/api/Link.php(220): call_user_func_array(Array, Array)
#5 /home/account/public_html/help/api/Link.php(113): Link::callFunction('Controllers\\Tic...', Array, 'GET', Array)
#6 /home/account/public_html/help/api/index.php(227): Link::all(Array)
#7 {main}
Using this code for the autoload.php

Code: Select all

<?php

// Files that are needed that aren't classes, as well as basic initialization
// Core requirements
define('IN_SCRIPT', 1);
define('HESK_PATH', '../');
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/bootstrap.php');
require_once(__DIR__ . '/../hesk_settings.inc.php');
require_once(__DIR__ . '/../inc/common.inc.php');
require_once(__DIR__ . '/Core/output.php');
require_once(__DIR__ . '/../hesk_settings.inc.php');
require_once(__DIR__ . '/http_response_code.php');
require_once(__DIR__ . '/../inc/admin_functions.inc.php');

hesk_load_api_database_functions();

global $hesk_settings;

// HESK files that require database access
require_once(__DIR__ . '/../inc/custom_fields.inc.php');

// Load the ApplicationContext
$builder = new \DI\ContainerBuilder();

$applicationContext = $builder->build();

// Fix for getallheaders() on PHP-FPM
if (!function_exists('getallheaders')) {
    function getallheaders() {
        $headers = [];
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }
}
I will restore it back to defaults, let me know what I should do from here and thanks again for the great support.
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: REST API: Link Error

Post by mkoch227 »

There's a fix for that as well.... just needs to be released ;). At least the headers are being read properly now.

You can follow the changes at https://gitlab.com/mike-koch/Mods-for-H ... 25d7d52efd if you don't want to wait :lol: . Remove any lines in red and add any lines in green.
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
ingenuitor
Posts: 6
Joined: Sun Dec 03, 2017 2:45 pm

Re: REST API: Link Error

Post by ingenuitor »

Hello,

These updates seemed to solve all the issues for now, thank you very much :D

Keep up the great work, I love what you did with the Hesk UI / UX, the front end need a little tweaking, but the back-end is just about perfect. :mrgreen:
mkoch227
Posts: 666
Joined: Wed Jul 04, 2012 3:37 pm

Re: REST API: Link Error

Post by mkoch227 »

ingenuitor wrote: Thu Dec 07, 2017 7:54 pm the front end need a little tweaking
Feel free to come forward with any constructive criticism you may have about the UI so it can be improved in future releases :D .
Mike, Lead Developer of Image HESK: A surprisingly simple, user-friendly and FREE help desk software with integrated knowledgebase.
Post Reply