Drag and Drop files to upload attachments

Before a few days, I wrote a plugin for the opensource webmail, roundcube. I consider roundcube api very well documented and it gives you the opportunity to extend its features. I wanted to upgrade roundcube webmail from version 0.4.2 to 0.8.0 and after this process I wonder what kind of plugins I could add to this fantastic webmail? I went to the repository of the roundcube plugins and I saw with surprise a plugin Drag Upload. I consider this feature very useful. I tried to install this plugin but it was not compatible with roundcubemail 0.8.0.

I thought that I have the source code from this plugin and the documentation of the roundcubemail, why not to try to create a plugin with this feature for the new api of the roundcubemail. I gave it a try and I created the dragndrop_attachments plugin that you can find at github: https://github.com/strimpak/dragndrop_attachments

or at the roundcube plugin repository: http://trac.roundcube.net/wiki/Plugin_Repository

 

This plugin uses the file api of the html 5 that gives you a lot of space to create beautiful things!

You can send me bugs or advices using the contact form or comments to this post.

Backup and restore MySQL – mysqldump a database – Grant Privileges

Back up a MySQL database

If you want to backup a MySQL database and you have access to shell, then you can easily do your job.

You can use mysqldump to create a simple backup of your database using the following syntax. 

mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]

after executing this command the result will be the backupfile.sql which is the backup file for your database. I shouldn’t pass the password argument [password] in the command because it would be available to other users of the system. If you leave it blank mysql client will ask you to enter your password. If you want to connect to a remote host to make a backup then the only thing you should do is to add -h [hostname | ip address] parameters like the syntax below.

mysqldump -h [hostname] -u [username] -p [password] [databasename] > [backupfile.sql]

This will work supposing you have privileges as the user you want to connect from the remote site.

There are a lot of combinations to dump a MySQL database and you can explore all of them here.

Restore a MySQL database from a dump

To restore a database from a file produced by mysqldump there is an easy walkthrough. Its the reverse way you resulted the dump file. Get a look at the following syntax.

mysql -u [username] -p [password] [databasename ] < [backupfile.sql]

you can restore the dump to a different database  or to a different database server and this is a good option if you want to make a replica of your data to make some tests.

Grant Privileges on a user in MySQL

To grant the privileges to user you have to connect to mysql as user that have privileges to grant privileges to other user as root user do.

As you may already know, to connect to the MySQL server as root you have to execute this command:

mysql -u root -p

once again do not provide your password to the command line. Now to grant privileges to a user you must keep in mind that you should give privileges to user from a host to some database table(s). Keeping this in mind is easy to remember the syntax of the command.

GRANT ALL PRIVILEGES ON 'databasename'.'databasetable'  TO 'username'@'host';
and then do
FLUSH PRIVILEGES

If you want to grant privileges on all tables or all databases just use the asterisk (* ) as follows:

GRANT ALL PRIVILEGES ON 'databasename'.* TO 'username'@'host';

If you want this user to have access from every host / ip address then:

GRANT ALL PRIVILEGES ON 'databasename'.* TO 'username'@'%';

and after each statement that affects the privileges of a user on a database you have to FLUSH PRIVILEGES.

In case you want to give this user the privilege to grant privileges then you have to use on of the above, using extra: “with GRANT option” . For example use:

  GRANT ALL PRIVILEGES ON 'databasename'.* TO 'username'@'%' WITH GRANT OPTION;

this will result a super user on this database and this user can connect from every site and he is able to grant privileges to other users for this database. Do not forget to FLUSH PRIVILEGES.

Horde Pear Horde_Memcache

I wanted to add the Memcache feature that horde offers, but at the apache logs appeared that Horde_Memcache class not found. This is already a known situation. The onlything you have to do is to install with pear the class of horde project needed.

In order to do this, just type at command promt:

pear install horde/Horde_Memcache

 

Horde Pear Horde_Datatree class

If you have enabled the datatree backend at horde main settings then you have to install the Horde_Datatree package from pear.

pear install horde/Horde_Datatree

After this procedure I was able to configure the backend of the datatree.

PEAR Net_SMTP class

If you have enabled the smtp server at horde mailer settings then you have to install the Net_SMTP package from pear.

You can check your conf.php file under config folder

One way to do this is to cat this file and grep mailer

cat conf.php | grep mailer
$conf['mailer']['params']['host'] = 'mail.example.com';
$conf['mailer']['params']['port'] = 25;
$conf['mailer']['params']['auth'] = true;
$conf['mailer']['type'] = 'smtp';

I was not able to send mail from the webmail, and I check the logs from apache. I saw these logs:

tail -f apache_error.log
[error]  PHP Fatal error: Class 'Net_SMTP' not found in .../php5/lib/php/Horde/Mail/Transport/Smtp.php on line 271, referer: http://webmail.example.com/imp/compose-dimp.php?type=new&ajaxui=1&uniq=13123591417264

So I checked the Smtp.php file and I saw that the Net_SMTP class is required

/**
 * SMTP implementation.
 * Requires the Net_SMTP class.
 **/

To install the Net_SMTP with PEAR you have to

pear install Net_SMTP

After this procedure I was able to send mail through my smtp server.

How do naming conventions for controllers, actions, and views work in the Zend Framework?

The Zend Framework uses “camel-casing” for controller and action names. Controller names are specified using upper camel-case and are suffixed with the word Controller (examples: IndexController, StaticContentController, FunkyChickenController), while action names are specified using lower camel-case and suffixed with the word Action (examples: indexAction, displayPostAction, redButtonAction). For modules other than the “default” module, controller names must be additionally prefixed with the module name (examples: News_IndexController,Catalog_EntryController).

View scripts take their name from the corresponding controller and action. Typically, the view script is stored in a directory corresponding to the controller name (without the Controller suffix), in a file whose name corresponds to the action name (without the Action suffix). Therefore, the view script for the clickAction in the ExampleController would be located at /views/scripts/example/click.phtml.

Multiple words in the controller or action name are represented by hyphens or periods in the corresponding view script file path. Therefore, the view script for the displayItemAction in the ShoppingCartController would be located at

/views/scripts/shopping-cart/display-item.phtml.

To prevent name collisions, the Zend Framework also allows the use of custom namespaces, which can be prefixed to object or class names. These namespaces can be registered with the Zend Framework autoloader, to have the corresponding definitions automatically loaded on demand, as needed.

Zend Framework – Using a Modular Directory Layout

Considering that you already try to build an application with Zend Framework you already use the default module. If you want to expand your application to use more than one modules then you have to define the default module and  use a modular directory layout. A modular directory layout enforces consistency and produces a more manageable code tree.

How to Create the Default Module

The first step is to create the $APP_DIR/application/modules/ directory, and then create a set of subdirectories within that for the default module and its controllers, models and views. The zf command line tool does not create these directories, and so it is necessary to perform this task manually. In your application’s directory under the htdocs directory, there is a directory that is named application where you have to create a directory named modules and in this directory, a directory named default.

shell> cd /usr/local/apache/htdocs/square/application

shell> mkdir modules

shell> mkdir modules/default

 

Next, move the existing models, controllers, and views from $APP_DIR/application/* to

$APP_DIR/application/modules/default/*:

shell> mv controllers modules/default/

shell> mv views modules/default/

shell> mv models modules/default/

Updating the Application Configuration File

The next step is to update the global application configuration file, located at $APP_DIR/

application/configs/application.ini, with the location of the modules directory. This tells the

Zend Framework’s routing subsystem how to resolve module-specific entities.

To perform this update, open the application configuration file in a text editor and add the

following lines to the [production] section:

resources.frontController.moduleDirectory = APPLICATION_PATH “/modules”

resources.modules = “”

 

*info Regardless of whether or not you organize your application into modules, remember

that you can always redirect URL requests to specific modules, controllers, and actions

through the use of custom routes.

Linux ps command tutorial

If you want to see a full description of the Linux ps command view this article

A common way to use the ps command is:

ps ux

which shows all the processes currently running under your username in an easy to read table format. The “u” specifies the format, and the “x” makes sure all processes under your user name are included.

The displayed table has the following colomns:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

which includes the user name, the process ID, percent of CPU used, percent of memory used, virtual and resident memory size, start time and accumulated time, and finally the command line used to start the process.

To include all processes of all users you would add the “-a” flag:

ps -aux

To see the processes running under another user name you would use the “U” flag. For example

ps U jjones

will list all processes run by user “jjones”.

Adding the “u” flag will list the processes in the user friendly format:

ps uU jjones

If you want to see a full description of the Linux ps command view this article

Linux ps command

If you want to see a simple linux ps command tutorial visit this article

 

NAME

ps – report process status

SYNOPSIS

ps [options]

DESCRIPTION

ps gives a snapshot of the current processes. If you want a repetitive update of this status, use top. This man page documents the /proc-based version of ps, or tries to.

COMMAND-LINE OPTIONS

This version of ps accepts several kinds of options.

Unix98 options may be grouped and must be preceeded by a dash.
BSD options may be grouped and must not be used with a dash.
GNU long options are preceeded by two dashes.

Options of different types may be freely mixed.

Set the I_WANT_A_BROKEN_PS environment variable to force BSD syntax even when options are preceeded by a dash. The PS_PERSONALITY environment variable (described below) provides more detailed control of ps behavior.

 

SIMPLE PROCESS SELECTION

Switch            Description

-A        select all processes

-N        negate selection

-a         select all with a tty except session leaders

-d         select all, but omit session leaders

-e         select all processes

T          select all processes on this terminal

a          select all processes on a terminal, including those of other users

g          really all, even group leaders (does nothing w/o SunOS settings)

r           restrict output to running processes

x          select processes without controlling ttys

–deselect        negate selection

 

PROCESS SELECTION BY LIST

Switch            Description

-C        select by command name

-G        select by RGID (supports names)

-U        select by RUID (supports names)

-g         select by session leader OR by group name

-p         select by PID

-s         select processes belonging to the sessions given

-t          select by tty

-u         select by effective user ID (supports names)

U         select processes for specified users

p          select by process ID

t           select by tty

–Group           select by real group name or ID

–User  select by real user name or ID

–group            select by effective group name or ID

–pid     select by process ID

–sid     select by session ID

–tty      select by terminal

–user   select by effective user name or ID

-123     implied –sid

123      implied –pid

 

OUTPUT FORMAT CONTROL

Switch            Description

-O        is preloaded “-o”

-c         different scheduler info for -l option

-f          does full listing

-j          jobs format

-l          long format

-o         user-defined format

-y         do not show flags; show rss in place of addr

O         is preloaded “o” (overloaded)

X          old Linux i386 register format

j           job control format

l           display long format

o          specify user-defined format

s          display signal format

u          display user-oriented format

v          display virtual memory format

–format           user-defined format

 

OUTPUT MODIFIERS

Switch            Description

-H        show process hierarchy (forest)

-m        show all threads

-n         set namelist file

-w        wide output

C         use raw CPU time for %CPU instead of decaying average

N         specify namelist file

O         sorting order (overloaded)

S          include some dead child process data (as a sum with the parent)

c          true command name

e          show environment after the command

f           ASCII-art process hierarchy (forest)

h          do not print header lines (repeat header lines in BSD personality)

m         all threads

n          numeric output for WCHAN and USER

w         wide output

–cols   set screen width

–columns        set screen width

–cumulative    include some dead child process data (as a sum with the parent)

–forest            ASCII art process tree

–html   HTML escaped output

–headers         repeat header lines

–no-headers   print no header line at all

–lines  set screen height

–nul     unjustified output with NULs

–null    unjustified output with NULs

–rows  set screen height

–sort    specify sorting order

–width set screen width

–zero   unjustified output with NULs

 

INFORMATION

Switch            Description

-V        print version

L          list all format specifiers

V          show version info

–help   print help message

–info    print debugging info

–version          print version

 

OBSOLETE

Switch            Description

A          increase the argument space (DecUnix)

M         use alternate core (try -n or N instead)

W         get swap info from … not /dev/drum (try -n or N instead)

k          use /vmcore as c-dumpfile (try -n or N instead)

If you want to see a simple linux ps command tutorial visit this article