Small bug in ports.php

Ryan Schmidt ryandesign at macports.org
Sat Nov 24 14:59:58 PST 2007


On Nov 24, 2007, at 12:59, Juan Manuel Palacios wrote:

> On Nov 24, 2007, at 12:42 PM, Chris Pickel wrote:
>
>> On 24 Nov, 2007, at 5:58, Ryan Schmidt wrote:
>>
>>> I believe I fixed it in r31443. I did not test it locally because  
>>> I haven't looked into what's required to set up a local  
>>> installation of the web site. But it's a very simple change and I  
>>> believe it's correct. If there's a document telling me what to do  
>>> to set up a local installation of the site, please let me know. I  
>>> already have apache2, php5 and mysql5 installed and have no  
>>> trouble administering them so as long as I just have to install a  
>>> database and user that's no trouble.
>>>
>>>> 	That bug might also affect the categories.
>>>
>>> Ports with multiple categories look fine.
>>
>> Indeed you did [1]. However, I'm now noticing that the order of  
>> those maintainers and categories is wrong. Do we not enforce any  
>> ordering in the SELECT statement? I don't believe MySQL guarantees  
>> any.
>
> 	Yes, we impose an ordering in our maintainers query:
>
> $nquery = "SELECT maintainer FROM $portsdb.maintainers WHERE  
> portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY  
> is_primary DESC, maintainer";
>
> 	And the primary key is enforced by the PortIndex2MySQL script for  
> categories and maintainers, so I don't really know what's at fault  
> here. At first I thought that it had to be order in which addresses  
> appear in your portfile (gnutls), but clicking on a single link  
> reveals that's not it either. I'll investigate.

I can take a look too once I get a local environment set up.


>> As for setting up a mirror of the website, it seems to have gotten  
>> much more complex to get the PortIndex2MySQL script working than  
>> it was when I set up my mirror. Maybe jmpp can enlighten us as to  
>> how to get /opt/local/share/macports/resources/portmgr to be created?
>
> 	The website is very easy to mirror:
>
> pre-1) Setup your web server to work with php & mysql (I don't  
> think we have any versioning requirements on any of those);
>
> 1) manually create a database for the site (just the DB entry,  
> PortIndex2MySQL does all the tables and records):
> 	*) PortIndex2MySQL has parameters for write access to that DB,  
> including its name, so adapt them as necessary (I standardized  
> variable naming across the board in r31455 & r31456, so remember to  
> svn up first);
> 	*) trunk/www/includes/common.inc has parameters for read access to  
> the DB, including its name, so adapt them as necessary (I  
> standardized variable naming across the board in r31455 & r31456,  
> so remember to svn up first);
>
> 2) setup the PortIndex2MySQL script to run periodically; we provide  
> both the script and a launchd plist, but their installation  
> locations and run frequency are completely arbitrary:
> 	*) to craete the script off of its .tcl file you first have to run  
> configure for your MacPorts base sources and then cd into portmgr/ 
> jobs and "make";
> 	*) I use the ${prefix}/share/macports/resources/portmgr location  
> simply because that's where the script used to be installed long  
> ago, but we no longer do that (totally unnecessary to install that  
> script, I believe, so I create the location manually);
> 	*) the $passwdfile variable in PortIndex2MySQL has to be adapted  
> to point it to a file with the password for your $portsdb_name  
> database, and it has to be an absolute path as otherwise the script  
> will not be able to find the file when running off launchd (which  
> seems to do a chdir to / for its jobs);
> 	*) I run the script twice a day, exactly an hour after the  
> refreshed index comes in (no sense at all in running it more  
> frequently, as it takes all of its information from the index),  
> with its plist installed into /Library/LaunchDaemons;
> 	*) the $SPAM_LOVERS variable in the script is adapted to send mail  
> to me locally in case something goes wrong, as it wouldn't make any  
> sense at all having that information go to this list;
>
> 3) create a location for your webserver to access the appropriate  
> files in trunk/www (which on my server it's just a symlink to  
> precisely my trunk/www checkout);
>
>
> 	And that's it! It might seem like a long list for an "easy" setup,  
> but if you read over it again you'll realize that I'm just being  
> verbose in explanations (as always ;-), but the steps themselves  
> are really short and easy.

Got the database created, a user created, edited the script to point  
to a password file, changed the spam lovers to me, ran make. Am now  
trying to run the script.

$ env tclsh PortIndex2MySQL

It tickles my hard drive for awhile, then ends with no output.

$ echo $?
1
$

So it's failing but I don't know why. I see there should be ui_error  
output on failures. How can I see it?


>> However, the question makes me think: once the MacPorts website is  
>> moved over, we want to remove the "not official" notice.
>
> 	Sure thing! I have this on my list as the last (victorious!)  
> commit I'll make to those files right before we move the files over  
> to the official web server :-D
>
>
>> However, there's still a use for mirrors, for testing purposes.  
>> So, perhaps we should add an additional warning if !preg_match 
>> ('(www.)?macports.org', $_SERVER['HTTP_HOST']) to the effect of  
>> "this is a mirror and may not contain up-to-date information".
>
> 	Very good suggestion indeed! Will add it once we go live with the  
> website.

Properly:

<?php

if (isset($_SERVER['HTTP_HOST']) && !preg_match('%(^|\.)macports\.org$ 
%', $_SERVER['HTTP_HOST'])) {
	echo "warning";
}

?>

Some clients don't set $_SERVER['HTTP_HOST'] so you must test for its  
existence first.

Fixed the regular expression to actually be a regular expression.

Of course we already have a redirect in place from macports.org to  
www.macports.org so nobody will ever be accessing our web site as  
"http://macports.org/" (it'll always be "http://www.macports.org/").



More information about the macports-dev mailing list