Login to download the latest version of Mint and your favorite Pepper, purchase additional licenses, or post in the Forum. Don't have an account? Create one!

In Partnership with Media Temple

Mint Forum

modified mint.php to make ip numbers clickable

here is a small piece of code I wanted to share with you guys. I wanted to jump from mint to a whois tool to check the ip number and get more detailed infos (about the location for example).

So I modified the function generateInfoRow in mint.php at line 2907 as follows:

if ( preg_match("/^[0-9]{2,3}[.]{1,1}[0-9]{2,3}[.]{1,1}[0-9]{2,3}[.]{1,1}[0-9]{2,3}$/", $content) ) $html .=’ ‘<tr><th>”.$label.”</th><td>”.”<a style="color:white" href="http://whois.domaintools.com/’.$content.’" else $html .= ”<tr><th>”.$label.”</th><td>”.$content.”</td></tr>”;

this way the ip numbers in the crushes pane become clickable and point to whois.domaintools.com.

hope this can be usueful. It sure is to me…

Sam Brown
Pepper Developer
Posted on Sep 11, '07 at 04:19 am

Very cool little hack.. thanks.

Dick
Minted
Posted on Sep 11, '07 at 06:30 am

Where exactly on the code line do you place the code? I can’t get it to work. Thanks

as I said, at line 2906 of the mint.php file, you have to replace

foreach($data as $label => $content) { $html .= ‘<tr><th>’.$label.’</th><td>’.$content.’</td></tr>’; }

with:

foreach($data as $label => $content) { if ( preg_match("/^[0-9]{2,3}[.]{1,1}[0-9]{2,3}[.]{1,1}[0-9]{2,3}[.]{1,1}[0-9]{2,3}$/", $content) ) $html .= ‘<tr><th>’.$label.’</th><td>’.’<a style="color:white" href="http://whois.domaintools.com/’.$content.’" />’.$content.’</a>’.’</td></tr>’; else $html .= ‘<tr><th>’.$label.’</th><td>’.$content.’</td></tr>’; }

the formatting may look different because of the form, but that’s the code.

p.s. the hack only works if in the crush pane the records show up a domain or a name. Then, clicking on a arrow or on the name/domain a ip number shows up and that will be clickable to point to the whois. If the crush pane only shows ip numbers, those can’t be made clickable because they already are in order to open up the relative entries in the pane.

MAYBE i’ll come with a more refined hack that will take care of that too….

OK, here is the complete hack. It has one little defect, where clicking on the whois link ALSO opens up the relative information for a given record. But what you gonna do. Feel free to correct me or better the code, I am sure it can be more efficient.

  • First:

after this:

$f = (preg_match(“/^[0-9]{4,}$/”,$data[‘tbody’][$j][$k]))?number_format($data[‘tbody’][$j][$k]):$data[‘tbody’][$j][$k];

at line 2857

add these two lines:

if ( preg_match(“/^[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}$/”, $f) )

$f = $f . ‘ whois »’;

  • Second:

after this:

foreach($data as $label => $content)

at line 2906 (now 2910 or something)

add these two lines:

if ( preg_match(“/^[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}$/”, $content) )

$content = $content . ‘ whois »’;

this is it. We are talking of the file mint.php obviously.

Sorry this form isn’t any good to add code. Please if there’s a moderator do delete the previous message. Trying again:

OK, here is the complete hack. It has one little defect, where clicking on the whois link ALSO opens up the relative information for a given record. But what you gonna do. Feel free to correct me or better the code, I am sure it can be more efficient.

  • First:

after this:

$f = (preg_match(&quot;/^[0-9]{4,}$/&quot;,$data[‘tbody’][$j][$k]))?number_format($data[‘tbody’][$j][$k]):$data[‘tbody’][$j][$k]; at line 2857

add these two lines:

if ( preg_match(&quot;/^[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}$/&quot;, $f) )

$f = $f . ‘&lt;small&gt;&lt;a href=&quot;http://whois.domaintools.com/’.$f.’&quot; /&gt;&amp;nbsp;whois &amp;raquo;&lt;/a&gt;&lt;/small&gt;’;

  • Second:

after this:

foreach($data as $label => $content) at line 2906 (now 2910 or something)

add these two lines:

if ( preg_match(&quot;/^[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}[.]{1,1}[0-9]{1,3}$/&quot;, $content) )

$content = $content . ‘&lt;small&gt;&lt;a href=&quot;http://whois.domaintools.com/’.$content.’&quot; /&gt;&amp;nbsp;whois &amp;raquo;&lt;/a&gt;&lt;/small&gt;’;

this is it. We are talking of the file mint.php obviously.

(sorry not good again. I hate this self formatting form. but you are clever enough to figure it out)

Sam Brown
Pepper Developer
Posted on Sep 11, '07 at 10:38 am

See this page for how to display code with Markdown. (Wrap in Backticks)

Shaun Inman
Mint/Pepper Developer
Posted on Sep 11, '07 at 12:00 pm

This modification is unsupported and will have to be applied after every update. I would rather you (nonhocapito) release a Pepper that uses the onAfterDisplay() method and the DOM to manipulate the default output on the client-side. This should be considerably more update-proof. Check out the iPhone Pepper for a bare-bones example of that method.

Shaun, yeah, I wanted to make a pepper of it but had no idea where to start from. Thanks for the input, I’ll look into it.

schmitt
Minted
Posted on Sep 12, '07 at 12:56 pm

Great idea. I’ve been trying to do this with my poor PHP skills with no success.

If you create a pepper, it would be good to allow the user to select WHOIS clients. I happen to like this one. http://ip-lookup.net

As it resolves international IPs very well.

Ok, I don’t think I will be able to write this plugin unless someone help me. I don’t know anything about javascript… I can only write php! the method shaun suggested works only if I add some javascript to the page… you can always learn but I am not a programmer and I don’t know if I have the time… is there any easy way to get this javascript function started? I have to add a piece of html in the middle of the page after a another given piece, I don’t really know how to do that. thanks for any suggestion you may have guys-

I went so far to build a pepper that add a piece of script at the bottom of the page that might or might not do the replacement on the whole page. thing is, I don’t know if the script is being loaded or how to make it happen.

Shaun Inman
Mint/Pepper Developer
Posted on Sep 17, '07 at 05:03 pm

Add an alert('hi'); to the part of your script that you think should be running. If you don’t get a JavaScript alert box saying “hi” then it’s not being loaded.

You must be logged in to reply. Login above or create an account