University of Oregon

Reset a password on a Parallels VM

I forgot the password to a RedHat 6 Parallels VM recently.

It’s a VM that we use to test changes to Aegir prior to working on the live hub.

Max Bronsema created and shared this VM a few years ago.
Unfortunately for me, I changed the original password at some point and now I’m locked out. But not to fret; the good news comes in the form of parallels control commands:

$ prlctl set ... --userpasswd ...

Here were my steps to reset the two user passwords (Note: names and ID’s have been changed to protect the some-such or another); Ref:

  • Open the Red Hat Enterprise Linux 6 (1) VM
  • Open Terminal
  • Reset the password for Admin and then AegirUser
    # prlctl = parallels control
    # list all running vm’s
    $ prlctl list –all | grep running
  • You may see something like this:
    {3e21f02b-9d52-4ebe-a079-675dc822d723} running - Red Hat Enterprise Linux 6 (1)
  • Use that machine ID to reset the passwords for your user accounts:
    $ prlctl set INSERT_MACHINE_ID –userpasswd Admin:tempPassWord
    authentication tokens updated successfully.
    $ prlctl set INSERT_MACHINE_ID –userpasswd AegirUser:tempPassWord
    authentication tokens updated successfully.
  • Then login as each user and reset their password

That’s a handy tool. Thanks Parallels!

Drupal – adding debug messages to your custom module – Improved

As a follow up to ‘Drupal – adding debug messages to your custom module‘. I improved the code and wanted to share.
Now you can drop in a few functions and add one line to your hook_admin_settings function to get debugging functionality.
If you want to start with a baseline of functionality you can also update each of your functions to declare themselves in the debug messages. Which is handy for tracking down issues.

In the end you get the same addition to your GUI with control over how and when debug messages are used.
Screen Shot of the new checkboxes
You also get the same reporting output, to the screen, watchdog, or both:
Here’s a quick look at my watchdog log gui with both types of error reporting enabled:
Screen Shot of watchdog screen

All done with cleaner code.

Drupal – adding debug messages to your custom module

Note: There is a follow up post here: Drupal – adding debug messages to your custom module – Improved

I work with a few custom modules and lately I’ve been migrating one from PHP 5.2 to 5.3 & Webform 2 to 3.

It’s been a challenge to sort out where some of the the errors are being generated from so I added a grip of debugging statements. In fact, I used a regex replace to log the name of each function that’s run in hopes that I could track down errors in chronological order.

That worked OK but I though I may want to turn it off or switch from drupal_set_message() to watchdog() calls when it’s ready to go to production. So I wrapped each log item in an if statement and tested for two new module variables:

  • Enable debugging message feedback
  • Enable watchdog debugging feedback

So now I have some GUI control over how and when debug messages are used.
Screen Shot of the new checkboxes

Drupal – Leveraging built in string functions in custom modules

Drupal includes native versions of a few common php string functions; strlen() for example is called with drupal_strlen().
drupal_strlen counts the amount of characters in a UTF-8 string vs. counting the bytes of a string. Not a huge difference perhaps but according to the brief documentation: This is less than or equal to the byte count. So if you want better accuracy then user the drupal_str function

I was introduced to these functions a few years ago, when using the Drupal coder module:

I wanted to quickly prepare a custom module to use the drupal flavored functions today and thought I’d share the regex I used in to find & replace:
(DreamWeaver regex)

([ (.]+)(substr|strlen|strtolower|strtoupper|ucfirst)



A quick replace and you’re Drupal friendly.

Drupal hide/show a sidebar with jQuery

I’ve hid the right sidebar on the HR website today.
I used jQuery so that it degrades gracefully when users don’t have JS enabled.

The sidebar-right region is used for ancillary information; links, the audience for the node content, etc… So it was determined that we could hide it but make the information available if people wanted more. (more…)

Drupal – Add a datestamp to your custom modules

I have several custom Drupal modules and when ever I make revisions & create a new version I update the datestamp.
Here’s a bookmarklet I use in Firefox to generate a datestamp.
Just drag that to your bookmark bar and you’re good to go.

Here are my steps to use it:

  1. Click Datestamp bookmarklet;
  2. Select all;
  3. Copy;
  4. and then paste into your file:
    datestamp = "1354564856"

Here’s the code: (more…)

Drupal 7: jQuery and Subtotaling Views Calc Tables

As a follow up to Drupal 6: Using jQuery to pick up where views_calc falls short, I worked on a project this week that used views_calc in D7 and we wanted to leverage the same subtotaling that I demonstrated in D6.

There are a lot of similarities in the code so it didn’t take much tweaking. (more…)

Custom Drupal 6 Module (Hack) to filter TableWizard Data by Dates in Views 2

I use Drupal to do some reporting on non-Drupal data using Views and TableWizard. It works pretty well but there are some serious limitations with relationships and filters.
I use a number of work-arounds for these limitations including referencing Views within Views, custom PHP and jQuery hacks via Views Customfield php fields and now a custom module that allows me to filter on dates.

My recent goal was to filter some external data by a date range. I can filter by my external datetime columns (as text) but Views doesn’t recognize them as valid date fields so Views date filters are unavailable.
So rather than rebuild the entire report in custom php I choose to manipulate the views query and filters. The result is a module/hack that converts the external datetime data to the Drupal friendly date format and then updates the query to filter by those dates.

I’ve been using the module for about a month and it works great. In its current state, the module uses some static code that specifies a view and display to act on and some where clauses to replace.

To work correctly, it requires that the Views display include two date filters (start and end date) both exposed and set to ‘contains’.
The date variable is formatted and then the matching ‘datetime contains’ where clauses (ex:

(datetime.dt_end_date) LIKE ('%%%s%%')

) are replaced with ‘date greater / less than’ clauses (ex:

(datetime.dt_end_date) < = ('%s')

I need to check and validate the format of date data several times in the module. So to keep the code clean and non-redundant I added couple of functions: strIsDate($string), dateValidates($dateVal), which you'll see below.
Finally the existing filter fields are changed to make them date_popup fields.

Drupal 6: Using jQuery to pick up where views_calc falls short

Views Calc is a great Drupal module but there are a few things it doesn’t do.
It doesn’t:

  1. Accommodate totals by group
  2. Total CCK viewfield field values
  3. Total Views Customfield PHP values

I wanted to fix all three of those issue in a views report I’m using.
To be clear: My solution is uses jQuery as a hack/fix, specifically addressing the fields I want to count and sum. It does not address the inherent issue in views_calc. (more…)

Branching with Git – Follow up on keeping remote and local sync’d

I saw a follow up comment on the article that I built my git-create-branch function on and so I updated the code. *Thanks goes to Olivier Clavel.
Here’s the update:
Here’s my original post:

In addition to updating the git functions used I improved the function itself by adding more feedback to the user.
Here are the new functions: git-create-branch() and git-delete-branch();