Expat-IT Tech Bits




Search this site:


/ (289)
  Admin/ (123)
    Apache/ (10)
      HTTPS-SSL/ (4)
      PHP/ (3)
      performance/ (2)
    Cherokee/ (1)
    LAN/ (4)
    LVM/ (6)
    Monitoring/ (2)
      munin/ (2)
    SSH/ (6)
    SSL/ (1)
    Samba/ (1)
    VPN-options/ (7)
      OpenVPN/ (1)
      SSH-Proxy/ (3)
      Tinc/ (1)
      sshuttle/ (1)
    backups/ (17)
      SpiderOak/ (1)
      backuppc/ (5)
      dirvish/ (1)
      misc/ (6)
      rdiff-backup/ (1)
      rsync/ (1)
      unison/ (2)
    commandLine/ (24)
      files/ (8)
      misc/ (10)
      network/ (6)
    crontab/ (1)
    databases/ (15)
      MSSQL/ (2)
      MySQL/ (8)
      Oracle/ (3)
      PostgreSQL/ (1)
    dynamicDNS/ (2)
    email/ (11)
      Dovecot/ (1)
      deliverability/ (1)
      misc/ (1)
      postfix/ (7)
      puppet/ (1)
    iptables/ (3)
    tripwire/ (1)
    virtualization/ (9)
      VMware/ (1)
      virtualBox/ (8)
  Coding/ (14)
    bash/ (1)
    gdb/ (1)
    git/ (3)
    php/ (5)
    python/ (4)
      Django/ (2)
  Education/ (1)
  Hosting/ (27)
    Amazon/ (18)
      EBS/ (3)
      EC2/ (10)
      S3/ (1)
      commandline/ (4)
    Godaddy/ (2)
    NearlyFreeSpeech/ (3)
    Rackspace/ (1)
    vpslink/ (3)
  Linux/ (31)
    Android/ (1)
    Awesome/ (3)
    CPUfreq/ (1)
    China/ (2)
    Debian/ (8)
      APT/ (3)
      WPA/ (1)
    audio/ (1)
    encryption/ (3)
    fonts/ (1)
    misc/ (6)
    remoteDesktop/ (1)
    router-bridge/ (3)
  SW/ (45)
    Micro$soft/ (1)
    browser/ (2)
      Chrome/ (1)
      Firefox/ (1)
    business/ (28)
      Drupal/ (9)
      KnowledgeTree/ (6)
      Redmine/ (2)
      SugarCRM/ (7)
      WebERP/ (2)
      WordPress/ (1)
      eGroupware/ (1)
    chat/ (1)
    email/ (1)
    fileSharing/ (2)
      btsync/ (1)
      mldonkey/ (1)
    graphics/ (2)
    research/ (2)
    website/ (6)
      blog/ (6)
        blosxom/ (3)
        rss2email/ (1)
        webgen/ (1)
  Security/ (15)
    IMchat/ (2)
    circumvention/ (2)
    cryptoCurrency/ (1)
    e-mail/ (4)
    greatFirewall/ (1)
    hacking/ (1)
    password/ (1)
    privacy/ (2)
    skype/ (1)
  Services/ (1)
    fileSharing/ (1)
  TechWriting/ (1)
  xHW/ (14)
    Lenovo/ (1)
    Motorola_A1200/ (2)
    Thinkpad_600e/ (1)
    Thinkpad_a21m/ (3)
    Thinkpad_i1300/ (1)
    Thinkpad_x24/ (1)
    USB_audio/ (1)
    scanner/ (1)
    wirelessCards/ (2)
  xLife/ (17)
    China/ (9)
      Beijing/ (5)
        OpenSource/ (3)
    Expatriation/ (1)
    Vietnam/ (7)


  • 2019/06
  • 2016/07
  • 2016/05
  • 2016/02
  • 2016/01
  • 2015/12
  • 2015/11
  • 2015/06
  • 2015/01
  • 2014/12
  • 2014/11
  • 2014/10
  • 2014/09
  • 2014/07
  • 2014/04
  • 2014/02
  • 2014/01
  • 2013/12
  • 2013/10
  • 2013/08
  • 2013/07
  • 2013/06
  • 2013/05
  • 2013/04
  • 2013/02
  • 2013/01
  • 2012/12
  • 2012/10
  • 2012/09
  • 2012/08
  • 2012/07
  • 2012/06
  • 2012/05
  • 2012/04
  • 2012/03
  • 2012/01
  • 2011/12
  • 2011/11
  • 2011/10
  • 2011/09
  • 2011/08
  • 2011/07
  • 2011/06
  • 2011/05
  • 2011/04
  • 2011/02
  • 2010/12
  • 2010/11
  • 2010/10
  • 2010/09
  • 2010/08
  • 2010/07
  • 2010/06
  • 2010/05
  • 2010/04
  • 2010/03
  • 2010/02
  • 2010/01
  • 2009/12
  • 2009/11
  • 2009/10
  • 2009/09
  • 2009/08
  • 2009/07
  • 2009/06
  • 2009/05
  • 2009/04
  • 2009/03
  • 2009/02
  • 2009/01
  • 2008/12
  • 2008/11
  • 2008/10
  • 2008/09
  • Subscribe XML RSS Feed

    Creative Commons License
    This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

    This site has no ads. To help with hosting, crypto donations are accepted:
    Bitcoin: 1JErV8ga9UY7wE8Bbf1KYsA5bkdh8n1Bxc
    Zcash: zcLYqtXYFEWHFtEfM6wg5eCV8frxWtZYkT8WyxvevzNC6SBgmqPS3tkg6nBarmzRzWYAurgs4ThkpkD5QgiSwxqoB7xrCxs

    Thu, 18 Jul 2013

    /SW/business/Drupal: Drupal: How to Delete Users Without Content

    I run a community Drupal 6 site that allows anyone to register, and my MySQL dumps were starting to get pretty big. I just reduced the number of users from 105,121 to 98 by deleting all users who had contributed no content or comments. There seems to be no easy way to do this, so here is my way. It is a little complicated:

    mysql> select users.mail, node.title from users, node where users.uid=node.uid;

    will list all users with content, ie. a Drupal "node".

    mysql> select * from users where users.mail not in (select users.mail from users, node where users.uid=node.uid)

    will list all users WITHOUT content.

    mysql> select users.mail, comments.subject from users, comments where users.uid=comments.uid;

    will list all users who have made a comment, and....

    mysql> select * from users where users.mail not in (select users.mail from users, comments where users.uid=comments.uid);

    will list all users who have never made a comment. Now this

    mysql> select * from users where (users.mail not in (select users.mail from users, comments where users.uid=comments.uid)) and (users.mail not in (select users.mail from users, node where users.uid=node.uid));

    will display all users who have neither content nor comments, which would lead one to expect that this

    mysql> delete from users where (users.mail not in (select users.mail from users, comments where users.uid=comments.uid)) and (users.mail not in (select users.mail from users, node where users.uid=node.uid));

    would work. But no,

    ERROR 1093 (HY000): You can't specify target table 'users' for update in FROM clause

    Stupid, but true. Damn MySQL. So now we have to play rocket scientist to get it done, and create a temporary table of users we want to delete:

    mysql> CREATE TEMPORARY TABLE t select mail from users where (users.mail not in (select users.mail from users, comments where users.uid=comments.uid)) and (users.mail not in (select users.mail from users, node where users.uid=node.uid));

    And now finally delete the damn SPAMers (which would be the vast majority of this garbage):

    mysql> delete users from users join t on t.mail = users.mail;

    posted at: 02:31 | path: /SW/business/Drupal | permanent link to this entry

    Tue, 25 Oct 2011

    /SW/business/Drupal: Drupal Migrate Module Basics

    The Drupal migrate module[1] is an impressive tool for migrating databases from other web applications (or anywhere, really) into the Drupal database. It even has fairly impressive documentation[2], but not unlike a lot of other big chunks of documentation, it can be hard to extract from the documentation where to start in creating a simple functional example of the migrate module at work. Hopefully this example will help to fill that gap a little.

    First install and enable the migrate family of modules in a sandbox Drupal site:

    drush dl migrate migrate_example migrate_extras migrate_ui
    drush en migrate migrate_example migrate_extras migrate_ui

    If you then point your browser at:


    you will see the migrate module's UI, which shows a couple of example migrations ("beer" and "wine") already coded and setup for you by the migrate_example sub-module. You can play with importing and rolling back data with the UI, or with drush:

    drush help --filter="migrate"

    To create your own migration, you need to create a custom module containing the migrate code. Using a MySQL database from another application, and based upon the beer.inc example from migrate_example, I was able to get a working migrate setup with three fairly small files in a new sub-module called "migrate_test" in sites/all/modules/migrate/migrate_test/ :


    <?php /* * You must implement hook_migrate_api(), setting the API level to 2, for * your migration classes to be recognized by the Migrate module. */ function migrate_test_migrate_api() { $api = array( 'api' => 2, ); return $api; }


    name = "Migrate Test" description = "My migration data." package = "Development" core = 6.x php = 5.2 dependencies[] = taxonomy dependencies[] = imagefield dependencies[] = comment dependencies[] = migrate dependencies[] = content dependencies[] = date dependencies[] = migrate_extras files[] = migrate_test.module files[] = langex.inc ; Information added by drupal.org packaging script on 2011-09-18 version = "6.x-2.2" core = "6.x" project = "migrate" datestamp = "1316388105"


    <?php // This is the connection information for the database containing the source data. Database::addConnectionInfo('for_migration', 'default', array( 'driver' => 'mysql', 'database' => 'langex', 'username' => 'langex', 'password' => 'anypass', 'host' => 'localhost', 'prefix' => '', )); /** * To define a migration process from a set of source data to a particular * kind of Drupal object (for example, a specific node type), you define * a class derived from Migration. You must define a constructor to initialize * your migration object. By default, your class name will be the "machine name" * of the migration, by which you refer to it. Note that the machine name is * case-sensitive. * * In any serious migration project, you will find there are some options * which are common to the individual migrations you're implementing. You can * define an abstract intermediate class derived from Migration, then derive your * individual migrations from that, to share settings, utility functions, etc. */ abstract class LangexMigration extends Migration { public function __construct() { // Always call the parent constructor first for basic setup parent::__construct(); // With migrate_ui enabled, migration pages will indicate people involved in // the particular migration, with their role and contact info. We default the // list in the shared class; it can be overridden for specific migrations. $this->team = array( new MigrateTeamMember('John Doe', 'john.doe@gmail.com', t('contractor')), new MigrateTeamMember('Larry Brewer', 'lbrewer@example.com', t('Implementor')), ); } } /** * There are four essential components to set up in your constructor: * $this->source - An instance of a class derived from MigrateSource, this * will feed data to the migration. * $this->destination - An instance of a class derived from MigrateDestination, * this will receive data that originated from the source and has been mapped * by the Migration class, and create Drupal objects. * $this->map - An instance of a class derived from MigrateMap, this will keep * track of which source items have been imported and what destination objects * they map to. * Mappings - Use $this->addFieldMapping to tell the Migration class what source * fields correspond to what destination fields, and additional information * associated with the mappings. */ class LangexUserMigration extends LangexMigration { public function __construct() { // The basic setup is similar to BeerTermMigraiton parent::__construct(); $this->description = t('Language Exchange Network users'); $this->map = new MigrateSQLMap($this->machineName, array('userid' => array( 'type' => 'int', 'not null' => TRUE, 'description' => 'Account ID.' ) ), MigrateDestinationUser::getKeySchema() ); $query = Database::getConnection('default', 'for_migration') ->select('users', 'u') ->fields('u', array('userid', 'name', 'username', 'password', 'email_address', 'sex', 'signup_date')); // $this->source = new MigrateSourceSQL($query); $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); $this->destination = new MigrateDestinationUser(); // One good way to organize your mappings is in three groups - mapped fields, // unmapped source fields, and unmapped destination fields // Mapped fields // The migrate module automatically converts date/time strings to UNIX timestamps. $this->addFieldMapping('created', 'signup_date'); $this->addFieldMapping('pass', 'password'); $this->addFieldMapping('mail', 'email_address'); $this->addFieldMapping('name', 'username'); // Unmapped source fields $this->addFieldMapping(NULL, 'name') ->issueGroup(t('DNM')); $this->addFieldMapping(NULL, 'sex') ->issueGroup(t('DNM')); // Unmapped destination fields // This is a shortcut you can use to mark several destination fields as DNM // at once $this->addUnmigratedDestinations(array('theme', 'signature', 'access', 'login', 'timezone', 'language', 'picture')); } }

    Note that this is a "cross-database migration"[3]. The source data and the destination data are located on the same MySQL server, but in different databases.

    [1] https://drupal.org/project/migrate
    [2] https://drupal.org/node/415260
    [3] https://drupal.org/node/1014558

    posted at: 05:13 | path: /SW/business/Drupal | permanent link to this entry

    Sun, 18 Jul 2010

    /SW/business/Drupal: Youku & Tudou Videos in Drupal

    For websites targeting users in mainland China, one of the issues is that many common services like Youtube and Google Video are blocked / censored from within China. For this specific case of video, there are a number of similar local Chinese video services that can be used instead.

    Most ex-China video services seem to make it easy to embed their videos in other sites by prominently displaying a button which will generate the javascript code necessary for embedding a video in another site. For whatever reason, the Chinese sites do not seem to be so helpful.

    First of all, in Drupal, turn on the PHP module. Then select "Create Content" and some content type to get to the content creation page. Select "PHP code" in the "Input Format" sub-section. And finally, for a youku[1] video, paste the following code into the content area:

    <embed src="http://player.youku.com/player.php/sid/XNDg5MTMwMDQ=/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>

    This is the video generated by the above:

    Youku video links are of the form http://v.youku.com/v_show/id_XMTkwNDgzMjE2.html

    Note the part between the "id_" and the ".html", ie. XMTkwNDgzMjE2. This is the part of the link that must be swapped into the above code for XNDg5MTMwMDQ in order to make it work for a different video.

    Similarly, for tudou[2] videos, use this code:

    <iframe title="Video from TUDOU" style="WIDTH: 364px; HEIGHT: 320px" src="http://www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/108621208120033273647/ flash_container.xml&amp;up_File=http://www.tudou.com/v/rsOg3YPXjDg&amp;up_FlashWidth=364&amp;up_FlashHeight=320&amp;up_ContainerCol=%23ffffff" frameborder="0" scrolling="no">Use a Flash Player to play Video from TUDOU - http://sites.google.com/site/annuairevin/flash-reader</iframe>

    which produces this video:

    Tudou video links are of the form http://www.tudou.com/programs/view/eD1xQ0WTlI8/

    Swap "eD1xQ0WTlI8" in the latter link for "rsOg3YPXjDg" in the code above to make the code work for a different video.

    [1] http://www.youku.com/
    [2] http://www.tudou.com/

    posted at: 03:02 | path: /SW/business/Drupal | permanent link to this entry

    Sun, 10 Jan 2010

    /SW/business/Drupal: My Favorite Drupal Modules

    (As of Drupal version 6.x....)

    Drupal is a very mature piece of software, with a vast number of modules to choose from, often with multiple modules vying to provide the same piece of functionality. After some trial and error, here are my candidates for "best of", modules someone new to Drupal should look into early:

    First some easily overlooked core modules:

    Third-Party modules:

    Here is someone else's list of favorites[6].

    [1] http://drupal.org/project/cck
    [2] http://drupal.org/project/views
    [3] http://drupal.org/project/image
    [4] http://drupal.org/project/image_fupload
    [5] http://drupal.org/project/lightbox2
    [6] http://www.nicklewis.org/40-essential-drupal-6-modules
    [7] http://drupal.org/project/boost

    posted at: 22:40 | path: /SW/business/Drupal | permanent link to this entry

    Thu, 17 Dec 2009

    /SW/business/Drupal: Comparisons of Drupal and Joomla

    Back some time ago when I was trying to figure out which Content Management System to use for a couple of website development clients, I do not remember seeing any definitive reviews. In the end, I think I made the correct choice (Drupal) for the situation despite the limited amount of information, but I see now that there might be some situations (event calendaring? desire for a simpler admin interface?) where Joomla might be the right choice.

    Here are some references I would like to preserve for posterity:


    posted at: 08:16 | path: /SW/business/Drupal | permanent link to this entry

    Sun, 06 Dec 2009

    /SW/business/Drupal: Drupal User Manual: How to Edit Content

    This post aims to provide the basic knowledge required to begin editing Drupal content.

    First and most basically, you require an account on the Drupal website you wish to edit. After login, if you click on any menu item to navigate to that page, if you have the privileges to edit that page, you will see an edit (编辑) button or link (this depends on the theme being used) at the top of the page. Click on edit / 编辑, then edit and save the page.

    After you have logged in, if you have been given some admin privileges on the site, you will see an Admin (管理) link in your personal menu under "My account" (我的帐户). Another way to see and edit the pages on the site is to click on "My account" / 我的帐户, and then click on "Content management/Content" (内容管理/内容). You will then be presented with a list of all the content items on the site, which you may then choose to edit individually, or perform various bulk operations on (deleted large quantities of spam posts, for instance).

    To create new content, click on "Create content" (创建内容) and select a content type. For ordinary website page content, you probably want to choose "Page" content. After you click on "Page" and write your content, do not forget to expand the "Menu settings" (菜单设置) and enter a "Menu link title" (菜单链接名称) and select the menu position from the "Parent item" (上级菜单项) dropdown list. (You probably want to select "Primary Links" or one of the items under "Primary Links".)

    Finally, you will probably want to re-arrange the order of the "Primary Links" in the navigation menu at the top of the site. To do this, click on "Admin" --> "Site building/Menus" --> "Primary links" (管理 --> 站点构建/菜单 --> "Primary links"). To change the order or position of menu items, just grab the "+" with your mouse pointer and drag'n'drop. For dropdown menus it is also good practice to click the "Expanded" (展开) checkbox to enable submenus. And finally, click "Save Configuration".

    posted at: 23:17 | path: /SW/business/Drupal | permanent link to this entry

    Mon, 13 Jul 2009

    /SW/business/Drupal: The Relationship Between Content & Menus in Drupal

    If you edit a content or a menu item in drupal, you will see a "Menu link title" and a "Parent item" field in both of these editing windows. This is your first clue that the contents of menus come from at least two different places:

    1. A piece of content (a "page", for instance) created on the "Create Content" (node/add) page. If you create or edit a page, between the Title & Body fields there is a "Menu settings" section. If you click into that there is a "Menu link title" field where you specify the precise text of the menu item (what it is called) and a "Parent item" drop-down menu where you select the position in the menu structure. ("Primary Links", for instance.) After you create such content, specifying a position within the "Primary Links" menu, this page will also now be automatically listed when you edit the Primary Links menu at admin/build/menu-customize/primary-links. In other words, the same "thing" is both a piece of content ("page") and a menu item.

    2. "Pseudo" content. This is a Drupal convention of where to find certain kinds of content. If you click "Add Item" on admin/build/menu-customize/primary-links, you will be taken to a page that looks similar to the "Menu settings" section if you edit a content page, with the addition of a "Path" field. If you put "node/x" (where x is an integer referring to an already created page of content) the new menu item will point to an already existing page of content. If you put "blog" in the "Path" field, then the menu item will point to an aggregation of all blog posts on the site. "blog" is the path where Drupal developers have designated that such content is to be found.

    So to summarize, most normal "menu" items should probably be content that you create on node/add, and there specify a position in one of your pre-defined menus like "Primary Links". For certain things like the blogging function and the contact form function (where the path would be "contact") you need to create the menu item by clicking "add item" within admin/build/menu-customize/primary-links and filling out the "path" field appropriately.

    For sites fitted with dropdown menus, to get 2nd & 3rd level menu items, in the "Parent item" field you have to place the lower level menu items under the higher level items. And then click on all the "Expanded" check boxes on admin/build/menu-customize/primary-links.

    posted at: 07:36 | path: /SW/business/Drupal | permanent link to this entry

    Thu, 02 Jul 2009

    /SW/business/Drupal: Multi-Site Drupal: Trivial

    First install one site, say for domain1.com, just like it was a single-domain install. Settings for the first site will automatically be placed in the sites/default directory.

    Now configure Drupal for a second domain, domain2.com. Create a second MySQL database for domain2. Copy /sites/default to sites/domain2.com and edit sites/domain2.com/settings.php. In this file there is a line of this form:

    $db_url = 'mysql://username:password@hostname/databasename';

    Replace the username, password, and databasename with the values for the database you just created for domain2. hostname should not change because you are presumably using the same MySQL server.

    Then point your browser at:


    From here on everything should look very familiar.

    The result is each website installed under the sites directory in Drupal gets it's own completely separate database and file area. The only thing shared is stuff put in sites/all (some modules and themes can be shared, for instance) and the Drupal code. Separate databases mean that each site must be upgraded separately on Drupal upgrades.

    There is reportedly a way of putting all the sites in the same database, but this only simplifies upgrades, while perhaps complicating other aspects of management. I have seen mention of sharing data between sites in this latter case, but it is not yet clear to me how this might be done.

    posted at: 08:52 | path: /SW/business/Drupal | permanent link to this entry

    /SW/business/Drupal: Dropdown Menus in Drupal

    As of Drupal 6.12, they are not built-in....

    One possible solution is to install a third-party module: the "Nice Menus" module[1]. This will provide a block in the admin/build/block window, which can be positioned in any one of your themes' defined areas. The resulting menu is, however, extremely plain out-of-the-box, and needless to say is not integrated with your chosen theme.

    If you are looking for dropdown menus, a better solution is to search Drupal's many third party themes[2] for "dropdown". This results in four pages of results, many of which are quite elegant. When you first install one of these themes, however, the dropdown menus may *seem* not to work. Here is some house-keeping that must be done for a newly-installed dropdown-menu theme to get those menus working:

    [1] http://drupal.org/project/nice_menus
    [2] http://drupal.org/project/themes?text=dropdown

    posted at: 08:31 | path: /SW/business/Drupal | permanent link to this entry