Wednesday, November 27, 2013

GNS3: Windows 8, wireshark – ”dumpcap has stopped working”

 

dumpcap has stopped

Specs: Windows 8, GNS3 0.8.6, Wireshark 1.10.3

This is the error I kept receiving today. I was trying to capture traffic off a network link on my GNS3 topology.

I wanted to see what kind of traffic passes through that point of the network. But, this became impossible as I kept getting the above error as soon as I tried to open wireshark from within GNS3 to view the captured traffic:

“Dumpcap has stopped working”

subsequently I received this error as well:

“child dumpcap process died. access violation”

Google searches did not reveal much help but suggested running both GNS3 and Wireshark as ‘administrator’. So I tried that, but without much luck.

Then the thought occurred to me that I might be having all this trouble because of Windows 8! So why not try running Wireshark with Windows 7 compatible mode?..

compatibility mode

And that fixed the problem for me Ok-icon

looks like some others were having similar issues: http://ask.wireshark.org/questions/26517/winpcap-seems-to-crash-on-win81

So I posted my solution there as well in case it’ll save someone else the trouble.

Back to networking..

Read More

Sunday, October 27, 2013

Basic NTP setup with Ubuntu and GNS3

In this post I am going to write about how I setup a NTP (Network Timing Protocol) daemon (server) so that my GNS3 routers can use it to set their time.

I will be setting this up on the same Ubuntu machine that I use to set-up my free TACACS+ server as explained on a previous post [ref 2].

Okay basically the reason why we want to setup a NTP server is so that all our network devices(routers, switches etc) can synchronize their time correctly. So we want the time source to be reliable. There are a few public ntp servers out there that you can use. A simple google search such as “nsw public ntp servers” reveals some of the closest public NTP servers for the state I live in (NSW, Australia)

If you are want to familiarize yourself with the whole NTP concept and public NTP servers, I highly recommend this video by the Cisco master ‘Jimmy Ray Purser’: http://www.youtube.com/watch?v=xJEIIMe55d0

NTP wikipedia diagram

Initial Setup for Internet Connection

Let’s get started.. My Ubuntu machine is currently assigned a static IP address which it uses through the “Host Only” VMware network configuration. While this successfully connects the Ubuntu virtual machine with my GNS3 routers, this means I will not have a internet connection. We need an internet connection so we can get the correct time from our selected public NTP server.

There are a few ways which you can provide an internet connection to this VMware Ubuntu machine. The way I selected is to add a second network interface through VMware settings [ref 4]:

add new network to vmware

for this new Network Adaptor make sure you select NAT on the next screen as shown below:

select NAT

Okay, now power on your machine. Your new network adaptor will appear as ‘eth1’ when you type ‘ifconfig’ on your terminal:

user@ubuntu:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:25:0d:12
inet addr:10.3.0.20 Bcast:10.3.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe25:d12/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:951 errors:0 dropped:0 overruns:0 frame:0
TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:89787 (89.7 KB) TX bytes:23108 (23.1 KB)
Interrupt:17 Base address:0x1080

eth1 Link encap:Ethernet HWaddr 00:0c:29:25:0d:1c
inet addr:192.168.206.136 Bcast:192.168.206.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe25:d1c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:877 errors:0 dropped:0 overruns:0 frame:0
TX packets:127 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:86622 (86.6 KB) TX bytes:18095 (18.0 KB)
Interrupt:16 Base address:0x1480

‘eth0’ is the interface that I am using to talk with my GNS3 routers. And the new ‘eth1’ interface its the one that should provide me with internet access as required.

Now remember, eth0 is still considered as your default  network connection. So we must change it to use eth1. This can be done quite easily using the GUI.

Click on the Network Connection icon on the top-right hand corner of the screen image

And select ‘Edit connections’ from the menu:

edit connection

It will show you your two network interfaces. We want to edit ‘eth0’ which was ‘Wired Connection 1’ . Select it and click ‘Edit’

wc-edit1

On the next menu, switch over to the ‘IPV4 Settings’ tab. The IP address we see here is the one that I statically assigned to talk with GNS3. Click on the ‘Routes..’ button below:

wc-edit2

On the next screen, we want to tick the ‘Use this connection only for resources on this Network’ checkbox:

wc-edit3

Apply the settings and close the menus. Now restart your machine for the changes to take effect.

Now when you login to your machine again you will have internet connection. This is because now ‘eth1’ is considered as you default network.

root@ubuntu:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.206.2 0.0.0.0 UG 0 0 0 eth1
10.3.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.206.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1

So you can open up a browser and access a web page. Mind you pings to internet such as google.com should not be used to confirm connectivity. This is because I found that my host OS firewall and Security suit is blocking them anyway.

The cool thing is that now you have both an internet connection(through eth1) and a connection to GNS3 routers(through eth0).

You can confirm this by pinging your Router. And also on the router I made sure I can still access this host and especially confirm my TACACS+ server is still working

R1#ping 10.3.0.20                               

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.0.20, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/17/40 ms
R1#test aaa group tacacs+ admin cisco123 legacy
Attempting authentication test to server-group tacacs+ using tacacs+
User was successfully authenticated.

Perfect! It still works Smile


NTP Server Setup

Now that we have the much needed internet connection setup, we can move onto setting up our NTP server.

For this I will use this valuable guide here as reference [ref 1]: http://askubuntu.com/questions/14558/how-do-i-setup-a-local-ntp-server

first let’s check a bit of info. about the NTP daemon we are about to install:

root@ubuntu:~# aptitude show ntp
Package: ntp
State: not installed
Version: 1:4.2.6.p3+dfsg-1ubuntu3.1

-- omitted --

Description: Network Time Protocol daemon and utility programs
NTP, the Network Time Protocol, is used to keep computer clocks accurate by
synchronizing them over the Internet or a local network, or by following an
accurate hardware receiver that interprets GPS, DCF-77, NIST or similar time
signals.

This package contains the NTP daemon and utility programs. An NTP daemon needs
to be running on each host that is to have its clock accuracy controlled by
NTP. The same NTP daemon is also used to provide NTP service to other hosts
.

For more information about the NTP protocol and NTP server configuration and
operation, install the package "ntp-doc".
Homepage: http://support.ntp.org/

Looks like the package we’re looking for. Let’s go ahead and install it

root@ubuntu:~# aptitude install ntp

once it’s installed, let’s configure it by editing the ‘ntp.conf’ file

root@ubuntu:~# gedit /etc/ntp.conf

Inside this file we are going to specify our public NTP servers where we will be retrieving the time from. As I mentioned earlier, I found a few public NTP servers that are close to me through a google search.

I think the closest one I can have is the NTP server provided by my ISP. So I will be marking it as my ‘most promising one’ as mentioned in the article[ref 1]. To mark the most promising one we use the ‘iburst’ keyword. In the configuration file. You will find a few sample servers already mentioned in it. I replaced them with the my selected public NTP server list:

server time.iinet.net.au iburst
server 0.au.pool.ntp.org
server 1.au.pool.ntp.org
server 2.au.pool.ntp.org
server 3.au.pool.ntp.org

I enabled the stats logging so I can have a look at NTP stats. I can disable that later once I confirm everything is working well

# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

The author of the above mentioned guide advises that we put the local machine as a default fall back server so the local time can be used when we have lost connection with the  public NTP servers.

To do this we add a local loopback IP address at end of server list:

# Use Ubuntu's ntp server as a fallback. 
# --> (I'll add When no other connection use the local-time)
server ntp.ubuntu.com
server 127.127.1.0
fudge 127.127.1.0 stratum 10

Now we restart the NTP daemon

root@ubuntu:~# /etc/init.d/ntp restart
* Stopping NTP server ntpd [ OK ]
* Starting NTP server ntpd [ OK ]

Now the ref. 1 guide says that if you tail the /var/log/syslog you will eventually see something like:

Jul 17 16:50:22 hostname ntpd[22402]: synchronized to 140.221.9.20, stratum 2

but I nothing like that happened with me. There was a user comment in the guide that mentioned

“..ntpd no longer reports synchronization in syslog, or anywhere else. This was relayed to me on the mailing list. Apparently, it was considered too "noisy". So, you should no longer use the "tail -f /var/log/syslog" command to look for entries of the type..”

I had to dig around the web a lot to find how I can confirm that NTP is working fine and talking with the specified servers.. obviously there is no straight forward way but I found a few suggestions:

root@ubuntu:/var/log/ntpstats# ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
*203.0.178.191 216.218.254.202 2 u 43 64 377 17.671 64.526 30.717
-203.26.72.7 203.192.179.99 3 u 18 64 377 29.185 26.600 23.687
+128.184.34.53 169.254.0.1 3 u 17 64 377 32.807 65.414 31.841
+202.191.108.73 47.187.174.51 2 u 13 64 377 38.822 47.019 24.448
-27.50.90.253 74.189.58.78 2 u 15 64 377 21.007 26.764 28.117
+91.189.89.199 193.79.237.14 2 u 4 64 377 304.509 65.568 46.936
127.127.1.0 .LOCL. 10 l 1455 64 0 0.000 0.000 0.000

note: you can also run ‘ntpq –c lpeer’ to view the names of remote hosts

[ref 3] suggests that if the ‘reach’ column is greater than ‘0’ then NTP is working fine.

Also remember that we allowed logging to /var/log/ntpstats/ ? If we go to that folder and view the files there you will see that there are constant updates.

For records I will also mention this article that lists a summary of the methods to test if NTP is working: http://informationsecuritytips.com/2010/04/commands-for-testing-ntp-connection-in-linux/

I’m pretty sure NTP is now working on my ubuntu machine. you can view the process by:

root@ubuntu:/var/log/ntpstats# ps aux | grep ntpd
ntp 3162 0.0 0.0 5752 2040 ? Ss 15:25 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 117:127
root 3996 0.0 0.0 4380 832 pts/0 S+ 15:58 0:00 grep --color=auto ntpd

Configure Cisco devices to use NTP Server

Okay, now let’s move on to configure our Cisco devices to use this new NTP server. I will use the Cisco Configuration Professional (CCP) for this but I’ll show the configuration commands as well.

Open up CCP and connect to your router. Then go to Configure >  Router > Time > NTP and SNTP and click on 'Add’ to add our new NTP server to the list. You will get the following screen. Here I’ll type in the details to connect to my NTP server

CCp add new ntp

It will ask for confirmation of the config. commands to be delivered to Router. Click deliver to send the commands.

Here are the commands that it will send to the router. Instead of using CCP you can use those commands at the global configuration mode:

ntp update-calendar
ntp server 10.3.0.20 source FastEthernet3/0 prefer

We are almost done.. Now the moment of truth to confirm that our router is synchronizing with our new NTP server:

R1#sh ntp status 
Clock is synchronized, stratum 4, reference is 10.3.0.20
nominal freq is 250.0000 Hz, actual freq is 250.0003 Hz, precision is 2**18
reference time is D61729B7.4539EC51 (05:57:11.270 UTC Sun Oct 27 2013)
clock offset is 29.0361 msec, root delay is 60.13 msec
root dispersion is 188.57 msec, peer dispersion is 40.04 msec

Hooray! Smile It’s working.

You can view a bit more details similar to what we saw with ‘ntpq –pn’ earlier on our Ubuntu NTP server, with this command:

R1#sh ntp associations 

address ref clock st when poll reach delay offset disp
~10.3.0.20 127.127.1.0 11 235 256 175 28.0 -2.47 381.0
* master (synced), # master (unsynced), + selected, - candidate, ~ configured

Restrictions (optional)

As an optional step I went ahead and restricted the NTP clients just to 10.0.0./24 subnet (my GNS3 subnet). I did this by modifying the /etc/ntp.conf file:

# By default, exchange time with everybody, but don't allow configuration.
# restrict -4 default kod notrap nomodify nopeer noquery
# restrict -6 default kod notrap nomodify nopeer noquery
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap

All done. I had to put quite a lot of effort first of all to get CCP running and then write this while I go setup the NTP server. But feels great now that it’s working..!

Hope this helps someone and if anyone reading this is also hoping to give this a try, please do let me know how you go.

My Resources & References:

Read More

Sunday, October 20, 2013

free TACACS+ with GNS3 routers

I wanted to setup a TACACS+ server to provide AAA(Authentication, Authorization, Accounting) for my Cisco routers running under GNS3.

Bit of searching found me the "Free TACACS+ Server" software offered here: http://www.tacacs.net/

So I decided that I would set this on a Ubuntu machine running on VMWare. My Ubuntu box was already set up on VMWare as I was using it for other purposes. Before I connected it to GNS3 I wanted to install TACACS+. This is because I am going to connect it with GNS3 using the "(Host Only)" method in VMware and give it a static IP address to talk with the router. In doing this I will loose my internet connection for this Ubuntu box running on VMWare. As I plan to create a clone of this machine and keep it separately as my TACACS+ server for future labs/studies, here's how I did it..

fist I checked this package tacacs+ to make sure what I am going to install:

root@ubuntu:~# aptitude show tacacs+
Package: tacacs+
State: not installed
Version: 4.0.4.19-11build1
Priority: extra
Section: universe/net
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: i386
Uncompressed Size: 233 k
Depends: libc6 (>= 2.7), libpam0g (>= 0.99.7.1), libtacacs+1, libwrap0 (>=
7.6-4~), adduser, python
Description: TACACS+ authentication daemon
TACACS+ is a protocol (not TACACS or XTACACS) for authentication, authorization
and accounting (AAA) services for routers and network devices.
Homepage: http://www.shrubbery.net/tac_plus/

Yup, looks good. I went ahead and installed it

root@ubuntu:~# aptitude install tacacs+

Now that I am done installing TACACS+ on this machine I am going to go ahead and clone this as mentioned earlier. You can easily use the tools in VMWare to do this

tacacs clone step1

Okay now I have got my clone which I’d be using from now on as my TACACS+ server. To connect this with GNS3, I need to set up the network interface properly.

I selected the new clone and I can see it’s properties on the left-side panel:

image

Double click on the “Network Adaptor” show above and you’ll get the screen to customize the network adaptor settings. We need to set “Network Connection” to a “(Host Only)” connection. And that’s what I did:

image

You can find more information on how to connect your VMWare hosts with GNS3 on this article:  http://blog.skufel.net/2011/12/vmware-workstation-8-and-gns3-integration/

Basically when you  do the above, VMware will create a virtual network adaptor for you. And that virtual adapter will appear on your adaptors list. Mine appears as “VMware Network Adapter VMNet1” :

network adapters

So now on GNS3 you can simply add a host and configure it to use this Virtual adapter as it’s Ethernet interface:

image

After that your VMware host is connected to GNS3. Make you you set the static IP address and default gateway on your Virtual host so it can talk with the router. I want to set the static IP of 10.3.0.20 with the default gateway of 10.3.0.1.

You can do this by editing the "/etc/networking/interface" file on your virtual host. But I had ran into some problems where it seems to neglect the default gateway I specified. So instead I used the GUI to set my static IP address:

static ip setting

Perfect! We are ready to test connectivity. Here’s my GNS3 topology:

image

The ‘vmware_TACACS_ubuntu’ host you see at the top is the one we just configured. Great.. now fingers crossed and let’s test connectivity between this host and router R1:

root@ubuntu:/etc/network# ping 10.3.0.1
PING 10.3.0.1 (10.3.0.1) 56(84) bytes of data.
64 bytes from 10.3.0.1: icmp_req=1 ttl=255 time=14.1 ms
64 bytes from 10.3.0.1: icmp_req=2 ttl=255 time=12.0 ms
64 bytes from 10.3.0.1: icmp_req=3 ttl=255 time=22.1 ms
64 bytes from 10.3.0.1: icmp_req=4 ttl=255 time=22.5 ms
64 bytes from 10.3.0.1: icmp_req=5 ttl=255 time=21.0 ms
Yay! we have connectivity. Smile

Now to the next step. There is just a few simply things that are important to configure on your tacacs+ server. To do this, we go to our ubuntu VMware image running our tacacs+ server and edit the ‘/etc/tacacs+/tac_plus.conf’ file.

We can edit it to set our options:

sudo gedit tac_plus.conf
One of the items we want to set is the secret(password) that the router can use to communicate with this tacacs+ server.

# This is the key that clients have to use to access Tacacs+
key = testing123
..And where the accounting file is so that it can record(store) data of what users have been up to:
# Define where to log accounting data, this is the default.
accounting file = /var/log/tac_plus.acct
As I wanted to make sure the above file was available, I went into the '/var/log' folder and created the blank file with:
sudo touch tac_plus.acct
then I made sure that anyone can write to it(ok for a test but not a good idea for a production environment!):
sudo chmod a+rw tac_plus.acct
Again inside the ‘tac_plus.conf’ file, I commented out the part where it says use PAM for user authentication and I manually added my test user. Who is "admin" with the password "cisco123". Of Couse this is not a good security measure for a production environment but we are just doing to for a test here.

user = admin {
 default service = permit
 login = cleartext cisco123
 
 # the following will provide 'admin' user with an exec  
 # shell(mode) with privilege  level '15'. (Activated by 
 # the 'aaa authorization exec..' command on router)
 service = exec {
  priv-lvl = 15
 }
}
Okay.. all the necessary configs seem to be done. Let's go ahead and restart the tacacs+ server for the changes to take affect:
root@ubuntu:/etc/tacacs+# /etc/init.d/tacacs_plus restart
* Restarting TACACS+ authentication daemon tacacs+
 Quick check confirms that our new TACACS+ server baby is running:
root@ubuntu:/etc/tacacs+# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1411/apache2
tcp 0 0 0.0.0.0:49 0.0.0.0:* LISTEN 3194/tac_plus
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1191/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1130/cupsd
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1320/mysqld
tcp6 0 0 ::1:631 :::* LISTEN 1130/cupsd

Now let's head back to our R1 console in GNS3 to see if the router can actually access our TACACS+ server
R1(config)#tacacs-server ?
administration Start tacacs+ daemon handling administrative messages
directed-request Allow user to specify tacacs server to use with `@server'
dns-alias-lookup Enable IP Domain Name System Alias lookup for TACACS
servers
domain-stripping Strip the domain from the username
host Specify a TACACS server
key Set TACACS+ encryption key.
packet Modify TACACS+ packet options
timeout Time to wait for a TACACS server to reply
 
We set the TACACS+ server host location with:
R1(config)#tacacs-server host 10.3.0.20 
R1(config)#
And the password key to encrypt communication between routers and server. This is the one we set earlier inside the /etc/tacacs+/tac_plus.conf file
R1(config)#tacacs-server key testing123

Alrighty.. Now the moment of truth. Let's authenticate a user against our TACAC+ server. Remember we set up a test user with username: admin, password: cisco123 earlier inside the tac_plus.conf file. Let’s test if we can authenticate that user:

R1#test aaa group tacacs+ admin cisco123 legacy 
Attempting authentication test to server-group tacacs+ using tacacs+
User was successfully authenticated.

Hooray! we did it. The user "admin" is successfully authenticated. Just for a quick test, if we give the wrong password, it will not work:

R1#test aaa group tacacs+ admin somewrongPass  legacy 
Attempting authentication test to server-group tacacs+ using tacacs+
User authentication request was rejected by server.

Done.. Now our TACACS+ server is ready for use. Smile 

My Resources & References:

Read More

Wednesday, October 16, 2013

syntax highlighting for outlook emails

php_code_snippet

 

 

 

 

 

There are times at work where you need to send your colleague a piece of code. It can be that they are using this cool snippet of code to perform some function on their web app and you’d like to use it for your own. Or you just want to show a sample code to someone via email.

Whatever the need might be there have been more than one time that I had to send code via outlook email. But I think we all know that copy-pasting code into an email doesn’t look “pretty”. It can even make a good piece of code look quite boring!

Digging around the web for a bit can find you some simple yet cool solutions. I found ‘http://tohtml.com’ to do exactly what I wanted. It let’s you syntax highlight various types of code including html, CSS, JavaScript, PHP, Ruby etc.

All you have to do it copy paste the code into it, select the syntax type you want and click on the ‘highlight’ button as show below. It will then convert your code to nice formatted text that you can simply copy paste into your outlook email!
step1 

It doesn’t just work for outlook emails. I quickly checked and it works on gmail and yahoo mail as well.

Yes, you can attach it as text to your email but usually I just want to quickly look at the email and copy the parts of code I want. This is why I’ve found the syntax highlighted code ideal to be used in emails.

So there is one neat little tool you can use for your day to day code pasting needs. I sure will be using this a lot.

Tool web-link: http://tohtml.com

Token: GVQW3US2Y9TY

Read More

Friday, November 2, 2012

session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)



I was working on a CakePHP application that was deployed on a Debian machine when I met this error. Bit of googling told me this error is more common to any app using php on a Debian/Ubuntu machine. So here goes..
 

Problem
If you are seeing this error:

session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) [CORE/Cake/Model/Datasource/CakeSession.php, line 605]

detailed error:


Notice (8): session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) [CORE/Cake/Model/Datasource/CakeSession.php, line 605]
Code
            }
        } else {
            session_start();
session_start - [internal], line ??
CakeSession::_startSession() - CORE/Cake/Model/Datasource/CakeSession.php, line 605
CakeSession::start() - CORE/Cake/Model/Datasource/CakeSession.php, line 187
CakeSession::check() - CORE/Cake/Model/Datasource/CakeSession.php, line 213
SessionComponent::check() - CORE/Cake/Controller/Component/SessionComponent.php, line 96
 



Reason

According to online resources it because some package on your Debian/Ubuntu machine is trying to do "Session garbage collection" where it shouldn't.
The session data is stored in /var/lib/php5 and it has the permission of "drwx-wx-wt 2 root root". So those packages cannot read into them.

Solution

The fix is simple: In your php.ini set session.gc_probability to 0 and restart apache

Detailed steps:
  • Find your php.ini usually its at:
    /etc/php5/apache2/php.ini

  • Edit it and find this setting
    session.gc_probability
  • Now set that value to 0
  • Restart apache
    sudo /etc/init.d/apache2 restart

Resources
For more information, read:
Read More

Wednesday, October 31, 2012

Restore deleted PANEL Ubuntu/Debian(Top or Bottom)

I was trying to remove some icon off my Debian desktop's top panel when this happened. I right clicked on that top panel and clicked 'Delete this panel' without thinking much and wooosh.. my panel is no more! :)

The following link outlined these few tips for me to recover my panel

1. gconftool-2 – -shutdown

2. rm -rf ~/.gconf/apps/panel

3. pkill gnome-panel

Reboot


source: http://aftami.wordpress.com/2010/02/13/restore-deleted-panel-ubuntudebiantop-or-bottom/
Read More

Wednesday, October 17, 2012

CakeEmail Error: Call to a member function subject() on a non-object

I was trying this on CakePHP version 2.2.3 Stable. CakePHP has introduced the new CakeEmail replacing the email component. So in order to use it i put this in my controller.

-------------------------------------------------------------
App::uses('CakeEmail', 'Network/Email'); //at the top of page

class MyController extends AppController {

public function test(){
$email = new CakeEmail('smtp');

$result = $email->from('sender@example.com')
->to('you@example.com')
->message('message')
->subject('About')
->send('my message');
->send();

debug($result);
}
-------------------------------------------------------------
When I ran it, it just wouldn't work! As it turns out the problem is with the 'message' function. Some bug is preventing from using it. Just uncomment that and put you message inside send() like this:
        
-------------------------------------------------------------
$email = new CakeEmail('smtp');

$result = $email->from('sender@example.com')
->to('you@example.com')
->message('message')
->subject('About')
//->send('my message'); --> commented out
->send('my message'); --> message was put here
-------------------------------------------------------------
And it works. So here I'm blogging it hoping it would help save someone's day. Cheers
Read More

About Me

Popular Posts

Designed By Seo Blogger Templates