Archive for the ‘code’ Category

Concrete 5 SQL errors during installation

Friday, February 3rd, 2012

We have seen this error with Concrete 5.5.1

You try to setup Concrete 5, and get strange SQL errors during the installation:

If installing with an empty site, like this

c5-nosample-content-chosen

you get:

c5-mysql-error

mysql error: [1048: Column 'uID' cannot be null] in EXECUTE("INSERT INTO Config (cfKey,cfValue,uID) VALUES ('NEWSFLOW_LAST_VIEWED','FIRSTRUN',NULL)")

If installing with Sample content with Blog:

c5 with sample content

The error you get is:

Catchable fatal error: Argument 1 passed to ContentImporter::importPageAreas() must be an instance of Page, boolean given, called in /concrete/libraries/content/importer.php on line 75 and defined in /concrete/libraries/content/importer.php on line 197.

 

Solution:

You don't run Varnish by any chance, do you? We do, and we had it set up to … dispose of some cookies. The solution is, in Varnish' case, to enable pass-through for the host you are installing on.

You want to enable cookies.

 

Explanation:

The code which breaks is located in concrete5.5.1\concrete\models\package\starting_point.php

Config::save('SITE', SITE);
Config::save('SITE_APP_VERSION', APP_VERSION);
$u = new User();
$u->saveConfig('NEWSFLOW_LAST_VIEWED', 'FIRSTRUN');

As you see, this is the first time a User is created and used.

The User class is defined in concrete5.5.1\concrete\models\user.php

if (isset($_SESSION['uID'])) {
$this->uID = $_SESSION['uID'];
$this->uName = $_SESSION['uName'];
$this->uTimezone = $_SESSION['uTimezone'];
if (isset($_SESSION['uDefaultLanguage'])) {
$this->uDefaultLanguage = $_SESSION['uDefaultLanguage'];
}
$this->superUser = ($_SESSION['uID'] == USER_SUPER_ID) ? true : false;
} else {
$this->uID = null;
$this->uName = null;
$this->superUser = false;
$this->uDefaultLanguage = null;
$this->uTimezone = null;
}
$this->uGroups = $this->_getUserGroups();
if (!isset($args[2])) {
$_SESSION['uGroups'] = $this->uGroups;
}
}

The constructor checks in the Session for a valid user ID. If no user ID is found, it is set to zero. This happens if you throw away the cookies! Because the session is stored in them.

HTH. Feel free to comment on similar errors and solutions.

Purging with Varnish

Tuesday, January 3rd, 2012

For a newbie, it's a bit tricky to understand how to purge old content from Varnish. Here's a description of what works for me:

Add these code snippets to your Varnish configuration file, reload Varnish:

/etc/init.d/varnish reload

This will "install" the PURGE command. Modify the ACL (access control list) as appropriate. Mine is:

acl purge {
"localhost";
"127.0.0.1";
"varnish server IP";
}

Where you need to replace the Varnish server IP with the IP of your Varnish server.

Next, (thanks to this article!) an easy method from the command line of your Varnish server:

curl -X PURGE http://catfind.it/

Replace catfind.it with your URL. The -X tells curl to replace the GET method with the PURGE method. BTW, you could call the PURGE method anything you'd like, ie. CACTUS – just set up the VCL configuration appropriately.

If you want some other server to be able to purge, you need to add it to your ACL.

You need curl to be installed. It's easily done on Debian / Ubuntu via

apt-get install curl

(as root).

What about the other methods?

  • telnetting into the server (telnet localhost 80) does not work for me, as it drops the connection before I'm finished with typing. Probably there is a way to set up telnet to transmit a certain string, if you want to, share it with us here.
  • Purging using the admin CLI of Varnish NEVER worked for me. Either Varnish has changed it's interface in newer versions, or I need some further configuration to enable it. Again, if you know the ropes, please share your knowledge with us!

    varnishadm -T 127.0.0.1:secretport purge req.url == "/"

    yields

    Unknown request.
    Type 'help' for more info.

Redirection with Concrete 5

Wednesday, September 14th, 2011

URL Shortening is all the rage now. Sometimes you want to give people ridiculously long URLs, which might also be subject to change.

So you want to do it with C5, don't you?

Great, you think – there's the "add external link" menu option in Concrete's sitemap. Unfortunately it does not work the way you expect it to – it just adds the link to the Navigation, but no page alias to point to the external page (i.e. http://www.synapse-redaktion.de/FaceBook won't work after adding a "FaceBook" external link).

What to do to solve this dilemma?

My suggestion is to use both: add a (hidden) page "FaceBook" which does header JavaScript forwarding to the other page, so you can give out the links to the people, and a "real external link" so you don't have to rely on JavaScript for most of your visitors.

The SiteMap will look like this:

sitemap

Adding custom attributes: (Header Extra Content, Exclude from Page List, Exclude from Nav)

header extra content

The page's setup:

setup

The script is easy:

<script type="text/javascript">
<!–
window.location = "http://www.surfnext.com"
//–>
</script>

with surfnext.com being the URL you are forwarding to.

If you have the time, you might want to add a static link or icon to the page (/*comment*/ the window.location = … part to be able to edit the page!) in case some person has their JavaScript turned off.

amMap for MediaWiki

Thursday, August 4th, 2011

For my worldwide Internet access project surfnext.com I developed an extension for MediaWiki to use amMap.

What is amMap?

amMap is a pretty cool Flash-based map which allows you to display geographical information. Check out the examples on amMap.com. It has been used on many pages world-wide, and now – thanks to SurfNext's needs – it is coming to MediaWiki!

What is MediaWiki?

It is the Wiki software which is behind Wikipedia and many other major wikis. SurfNext.com is also based on MediaWiki. Ah, the power of free software!

Why Flash, why amMap?

Because there is no free JavaScript-based map out there, which is not based on tiles. (Please post a link if you know any vector-based JavaScript map !!!)

Unfortunately iDevices (iPhone, etc) do not have Flash capabilities. Thus, you can't see the amMap on them.

Android has Flash support.

Download & Credits

Download version 0.5. (amMap v. 2.5.7 is included).

amMap requires you to leave the link to amMap (inside the map) intact, or to buy a commercial license.

I ask you to provide a back-link to my project SurfNext.com, if this extension is of value to you.

This extension is still in early beta, use at your own risk. Post comments about the extension on this blog page, thank you!

Installation

snAmmap requires MediaWiki 1.17 or higher, as it uses ResourceLoader. (Feel free to fork a version for earlier MediaWikis).

An alternative, of course, is to upgrade your Wiki. It is advisable, as the new release sports significant speed enhancements.

  • Put the snAmmap folder in your extensions folder.
  • Add require_once("$IP/extensions/snAmmap/snAmmap.php"); to your LocalSettings.php
  • If you want to, you can create custom data and settings files and put them somewhere in your Wiki installation path. (i.e. a folder custom)

Usage

Currently snAmmap only supports one map per page. After you have installed the extension, use the following tag in your Wiki where you want to include the map:

<ammap height="500px" width="500px" bgcolor="#FFFFFF" data_file="/custom/data.xml" settings_file="/custom/settings.xml">Placeholder text</ammap>

None of the tag's attributes are required, there are sensible defaults for them (falling back on the data_file and settings_file provided with amMap, for instance.)

  • height => sets the height of the map. Can be a percentage
  • width => sets the width. Can also be a percentage.
  • bgcolor => sets the initial background color, which can be modified in the settings file later.
  • data_file => sets the path (URL!) for the data_file. Can be a full URL with hostname, but you have to enable cross-site scripting, which is dangerous. Use a file from your server, preferably.
  • settings_file => sets the path for the settings_file

See the documentation of amMap for more details and information what you can modify.

Live Example

SurfNext.com uses the snAmmap extension on the main page in conjunction with custom data and settings files for a map which links to Wiki pages. It also has a dropdown menu from which you can select the individual countries by name, which also links to the Wiki pages.

SurfNext shows you how to obtain Internet access everywhere in the world. Feel free to join and participate!

Feel free to comment about SurfNext on this blog page.

Privoxy rules to unblock Concrete 5 editing

Friday, May 20th, 2011

In Concrete 5, TinyMCE is used as an editor for Content blocks. If you have Privoxy installed with the default settings, crucial parts of this editor will be blocked, and you would be unable to edit the Content block properly. (no editor appears, you see a small box with the HTML instead).

You can verify that it's indeed Privoxy which is doing it, by checking the Network tab of Dragonfly or Firebug in Opera or FireFox, Privoxy will add a status message to files which have been blocked.

To fix this problem, edit your user.action file (located in the application's toplevel directory), and add a new line under the { fragile } section:

{ fragile }
#.forbes.com
/concrete/js/tiny_mce/plugins/.*
/updates/concrete.*

This should unblock all Concrete 5 – based sites.

Update (23.10.2011): The fix now works with updated Concrete 5 sites.

Logging out users

Tuesday, February 22nd, 2011

Do you track users by using cookies?

There are some handy JS libraries to read cookies and determine whether a user-cookie is set.

But what do you do if you want to logout your user without them having to refresh the page?

Make an AJAX request.

Your server-side script which is called using the AJAX request can update your cookie state, i.e. remove the cookie. Something my JS libraries did not manage to do, in spite of them having a function for that.

In PHP it's simple to do:

<?PHP
/*We delete the cookie by setting it's time to -3600*/
setcookie ('usercookie', ", time()-3600, '/');

Lectoras external HTML object and z-index

Sunday, February 20th, 2011

Given the limited flexibility of Lectora, in some cases you need to include custom scripted HTML objects.

For instance you want to build an overlay for a login dialog, which would communicate directly with the server using AJAX.

After positioning your external HTML object on the page and building the HTML you want to include (by i.e. a PHP "include" call), sometimes you will find Lectora is putting other things on top of your HTML object's contents.

The first possibility to fix this would be modifying Lectora's "Layering" option of your object: "Bring to Front".

The second possibility comes in handy, if you do not want to modify the Lectora project itself: on-the fly z-index – updating.

I use the JS library JQuery to efficiently work on the DOM across browsers. Using it, you can set the z-index during runtime (i.e. reacting to a mouseclick on an icon):

$('#object-name').css('z-index','1000');

You can find out the name of the DIV Lectora creates for your external HTML object using Firebug, or looking up the object name property in Lectora (double click your object to see the settings dialogue).

Creating DIVs inside your Lectora object and setting their z-indices to higher values, i.e. by CSS, does not work. You need to alter the z-index of the wrapper DIV provided by Lectora. It is created during run-time using this code:

object-name = new ObjInline('object-name',null,0,580,900,40,1,15,null,'div')
object-name.build()

The Lectora code sets the z-index! Thus, your z-index from the CSS would be ignored, and you need to update it during runtime, as I have described above.

Trafficverschwendung

Sunday, January 30th, 2011

Und die Chinesen "attackieren" unseren Server weiter. Heute habe ich erfahren, dass wir innerhalb von 30 Tagen 125 GB incoming traffic auf unserer SIP VZ hatten, das meiste selbstverständlich von einer einzigen chinesischen IP. Sehr schön wird das auch dadurch gezeigt dass der Outgoing Traffic nur 5 GB betragen hat (und da die Gespräche sowohl rein als auch raus laufen, also durch den Server geproxyied werden bei uns, entspricht das eher dem wahren Gesprächsaufkommen).

Ich habe ausgerechnet, dass es ca. 0,38 MBit pro sec Dauertraffic entspricht, d.h. wir haben genug Reserven. (mit einer 100 MBit Anbindung, die bei Bedarf auf 1 GBit umgestellt werden kann).

The Chinese once again …

Wednesday, January 5th, 2011

In another post I already blocked the Chinese from scanning my YATE server (actually attempting a kind of DOS attack? Perhaps this would bring another VoIP software down?)

Anyways, the Chinese are back and they have changed their IP adress to

218.72.254.43

Also the message is slightly different:

sip:venice@<my IP>

I will attempt to block them once again, if this happens a third time with yet another IP, I will think about other measures.

Developing with Concrete: New Block Type not showing up

Wednesday, November 17th, 2010

Problem: you are adding a new block type to your package. You are updating the package using Concrete's update functionality, but no new block type shows up.

Solution: remove the package completely (uninstall – but leave it in the package directory, when C5 offers to move it to trash!), and install it again. Your block type should show up now.