Post by ADD Creative » Thu Jan 02, 2025 8:00 pm

Both $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] should not be trusted. Only use them if you are using a proxy that sets them.

If you do need to use them, then pass both though filter_var or at the very least pass through htmlspecialchars (or use $this->request->server version) if used in HTML. Otherwise HTML could be injected into you email. Yes they would need an admin login, but still better to do things the correct way.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by nonnedelectari » Thu Jan 02, 2025 8:37 pm

ADD Creative wrote:
Thu Jan 02, 2025 8:00 pm
Both $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] should not be trusted. Only use them if you are using a proxy that sets them.

If you do need to use them, then pass both though filter_var or at the very least pass through htmlspecialchars (or use $this->request->server version) if used in HTML. Otherwise HTML could be injected into you email. Yes they would need an admin login, but still better to do things the correct way.
Being "trusted" vs being a proper ip address are two different things.
This is about the fact that $_SERVER['HTTP_X_FORWARDED_FOR'] may not contain a single ip address but a comma separated string of ip addresses.
I.e. a format issue.
Whether you should or should not trust what is ultimately in there is a different issue.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by ADD Creative » Thu Jan 02, 2025 9:17 pm

nonnedelectari wrote:
Thu Jan 02, 2025 8:37 pm
Being "trusted" vs being a proper ip address are two different things.
This is about the fact that $_SERVER['HTTP_X_FORWARDED_FOR'] may not contain a single ip address but a comma separated string of ip addresses.
I.e. a format issue.
Whether you should or should not trust what is ultimately in there is a different issue.
My comment wasn't as a reply to your post, more aimed at anyone using the posted modification.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by jrr » Fri Jan 03, 2025 8:52 am

supak111 wrote:
Thu Jan 02, 2025 3:23 pm
You use the code below if you are making an ocmod for installation through admin->extensions->installer page...
If you are hardcoding the code into the login.php file directly (hardcoding is never really recommended), you don't need the code below, and you don't need a bunch of other code from my original file

Code: Select all

 <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[
I take your XML file - edit the stuff specific to my store (all of which works when I manually dump it into the login.php file) and I then zip it up and rename the zipped xml file AdminLastLogin-EmailJan2.ocmod.zip.

Install seems to be happy with it, no error messages show up, yet the xml never shows up in /extensions/modifications and the login.php file isn't edited.

What might I be doing incorrectly?

OC 3.0.4.0.

Thanks for your patience!

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Fri Jan 03, 2025 10:29 am

Post a copy of your full XML ocmod file

PS did you refresh your modification after installation??
.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Fri Jan 03, 2025 2:55 pm

supak111 wrote:
Fri Jan 03, 2025 10:29 am
Post a copy of your full XML ocmod file

PS did you refresh your modification after installation??
.
This is not my first extension installation...so yes, I refreshed extension/modification (and clear all caches) - it simply doesn't show up! I'm assuming it got stuck and followed the <operation error="skip"> instruction
My complete ocmod file: (will look at ip security remarks later)

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Send email on Admin Login</name>
    <code>Send email On Admin Login</code>
    <version>1.0</version>
    <author>opencart.com username: MyOpe</author>
    <link>https://forum.opencart.com/viewtopic.php?p=876242</link>
    <file path="admin/controller/common/login.php">
        <operation error="skip">
 <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[

$ip_address = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
	$ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
	$ip_list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
	$ip = trim($ip_list[0]);
	if (filter_var ($ip, FILTER_VALIDATE_IP)) $ip_address = $ip;
}
if ($ip_address === '') $ip_address = $_SERVER['REMOTE_ADDR'];

if (!empty($_SERVER['HTTP_REFERER'])) {                  
    $refer = $_SERVER['HTTP_REFERER'];
} else {
    $refer = 'referrer not found';
}

$to = "jrr@flippers.com"; //the address the email is being sent to
$subject = "Admin LOGIN"; //the subject of the message
$msg = "Admin LOGIN
<br><br>
Admin:  {$this->request->post['username']}<br>
Referer:  {$refer}<br>
From IP:  <a href='https://flippers.com/catalog_oc/admin/ip/{$ip_address}'>https://flippers.com/catalog_oc/admin/ip/{$ip_address}</a><br>"; //the message of the email

// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

// Additional headers 
$headers .= 'From: JRR <noreply@flippers.com>' . "\r\n";

mail($to, $subject, $msg, $headers); //send the email

]]>
            </add>
        </operation>
    </file>
</modification>
Everything after:

Code: Select all

 <search>
                <![CDATA[$this->session->data['user_token'] = token(32);]]>
            </search>
            <add position="after">
                <![CDATA[
works as it should when manually inserted into /admin/controller/common/login.php
Arghh!
Thanks!

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Sat Jan 04, 2025 9:32 am

Does your admin/controller/common/login.php file have this line of code in it:

Code: Select all

$this->session->data['user_token'] = token(32);
It should be there around line 15.

Your OCmod file looks fine, I don't see why it woundn't work. Maybe someone else here sees an issue?
"Send email on Admin Login" should be there in you Modification List

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Sat Jan 04, 2025 9:52 am

Yup -

Code: Select all

$this->session->data['user_token'] = token(32);
- is on line 15.

Weird.

Probably all my fault...

Thanks!

John :-#)#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by by mona » Sat Jan 04, 2025 9:53 am

Try this and check your error logs if it does not work
Tested and Send Email on Admin Login (seoal for short) is working on 3.0.4.0

IMPORTANT : this download has site specific addresses

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by jrr » Sat Jan 04, 2025 10:09 am

by mona wrote:
Sat Jan 04, 2025 9:53 am
Try this and check your error logs if it does not work
Tested and Send Email on Admin Login (seoal for short) is working on 3.0.4.0

IMPORTANT : this download has site specific addresses
Hi Mona,

That worked as it should - I'm getting the emails from admin logins - and the extension now shows up in extensions/modifications.

Thank you!

John :-#)#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by supak111 » Sat Jan 04, 2025 10:25 am

I just compared his code to your new OCmod code and there is nothing in there that I can see that would make his code not work.

No clue why his code didn't work lol

.
Last edited by supak111 on Sat Jan 04, 2025 11:55 pm, edited 1 time in total.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Sat Jan 04, 2025 4:30 pm

supak111 wrote:
Sat Jan 04, 2025 10:25 am
I just compared his code to your new OCmod code and there is nothing in there that I can see that would make his code not work lol.

No clue why his code didn't work lol

.
There is something wrong with my compress function in osx Sonoma. I tried expanding Mona's extension and then recompressed it using osx's native compress that appears to make zipped files but I realized that it did NOT actually compress the file. Mona's compressed file was 1K in size, and mine was 3K.

I then compressed this on a Windows XP machine and tried uploading the XP Zipped file and see if that worked...nope same null result.

Something is wrong with how the compressed file is being created on both Windows and OSX. It's late, and I'm tired...anyone have a bright idea I can check on tomorrow?

Thanks!

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by OSWorX » Sat Jan 04, 2025 6:04 pm

jrr wrote:
Sat Jan 04, 2025 4:30 pm
There is something wrong with my compress function in osx Sonoma. I tried expanding Mona's extension and then recompressed it using osx's native compress that appears to make zipped files but I realized that it did NOT actually compress the file. Mona's compressed file was 1K in size, and mine was 3K.

I then compressed this on a Windows XP machine and tried uploading the XP Zipped file and see if that worked...nope same null result.

Something is wrong with how the compressed file is being created on both Windows and OSX.
Maybe use this : https://www.7-zip.org/ and install (or use) it on every device instead of their internal compression functions.
With that it should work on every device ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by by mona » Sat Jan 04, 2025 9:32 pm

jrr wrote:
Sat Jan 04, 2025 4:30 pm
Mona's compressed file was 1K in size, and mine was 3K.
My mac will zip it to 2k

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by OSWorX » Sat Jan 04, 2025 10:47 pm

by mona wrote:
Sat Jan 04, 2025 9:32 pm
jrr wrote:
Sat Jan 04, 2025 4:30 pm
Mona's compressed file was 1K in size, and mine was 3K.
My mac will zip it to 2k
And my Atari can do that to 720 B :joker:
7zip use 1.12 KB

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by by mona » Sat Jan 04, 2025 11:39 pm

OSWorX wrote:
Sat Jan 04, 2025 10:47 pm
by mona wrote:
Sat Jan 04, 2025 9:32 pm
jrr wrote:
Sat Jan 04, 2025 4:30 pm
Mona's compressed file was 1K in size, and mine was 3K.
My mac will zip it to 2k
And my Atari can do that to 720 B :joker:
7zip use 1.12 KB
@OSWorX It was to jrr not you.
Point being jrr has made an assumption that the zip function is the problem because of the difference in file size.
This is not a reliable way to debug a problem.
Each zip and rounding method will produce a different result.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by supak111 » Sat Jan 04, 2025 11:58 pm

I do all my coding and compression on a M1 MacBook Air and never had issues with a compressed ocmod "install.xml"

Double click the install.xml file, and click: "Compress install.xml", then rename the compressed file so that it ends with: XXX.ocmod.zip

.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by jrr » Sun Jan 05, 2025 12:12 am

supak111 wrote:
Sat Jan 04, 2025 11:58 pm
I do all my coding and compression on a M1 MacBook Air and never had issues with a compressed ocmod "install.xml"

Double click the install.xml file, and click: "Compress install.xml", then rename the compressed file so that it ends with: XXX.ocmod.zip

.
It was all my fault - as I suspected. Nothing to do with the zip function at all.

I hadn't followed the ocmod file convention!

I hadn't named the xml file install.xml and then zipped it and renamed the zip to what I wanted.

Much like this: viewtopic.php?t=216022

Sigh, crawling back under my rock now...and sorry to waste folk's time!

John :-#(#

jrr
Active Member

Posts

Joined
Mon Nov 20, 2017 1:48 pm

Post by OSWorX » Sun Jan 05, 2025 1:43 am

by mona wrote:
Sat Jan 04, 2025 11:39 pm
@OSWorX It was to jrr not you.
Point being jrr has made an assumption that the zip function is the problem because of the difference in file size.
This is not a reliable way to debug a problem.
Each zip and rounding method will produce a different result.
It was half a joke ..
Seriousely: I know that each and every compression tool will output a different result.
Depends on what definitions are made and a few other settings of the tool.

But my suggestion was true, because on whatever system I use the same tool (like here 7zip), the output will be the same.
And then I can compare between all.
Was to eleminate possible user faults - as this is in 99% of all cases the reason why something fails.

And for example, Win* PCs had a problem with compressing files long a time.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by supak111 » Sun Jan 05, 2025 1:55 am

Haha, I was gonna ask if you named the xml file: install.xml

And it's a not waste of time, forums are for learning... I'm sure this will help many others in future

.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm
Who is online

Users browsing this forum: No registered users and 17 guests