Posts with the name or tag of emran;

by emran

JCow’s Events Join Modification

4:32 pm in Elgg, JCow by emran

I love jcow script.it is very nice and faster. It is very simple to implement in production website though some modification is required.

I found that in the Event module,  “i want to join” button always keep front even user already clicked the join button.it should not show if user already join on the event.

It can be changed easily.Please follow the steps to modify:

1. Go to modues/events/events.php

2. go to line no 70. where u will find hook_viewstory() function.

then you place code as following.

Events join modification

Events join modification

3. Now refresh the events page and check that it will not show if you already join the event.

That’s all

by emran

Shoutbox Module for JCow

9:45 am in JCow by emran

I have written another module for JCow.It is shoutbox.

The Shoutbox module provides a block where visitors can quickly post short messages.

  • Post messages instantly via AJAX
  • Optionally have messages auto-refresh via AJAX
  • A cron option allows the administrator to have old shouts deleted.[not implemented yet]

Let me know if you have any issues.

JCow Shoutbox

JCow Shoutbox

How to setup:

1. Download the Modules shoutbox.

2.  Copy and paste the modules to the directory modules/shoutbox

3. Go to Admin CP and Install shoubox module

4. Then edit dashboard script from modules/dashboard.php and put the following code in the index() function

//after this code
block(
friends_birthday()
);

//Add this Code

include_once ‘modules/shoutbox/shoutbox.php’;

$sb=new shoutbox();
block(
$sb->shout_box()
);

by emran

Jcow Social Script Admin Add User

3:48 pm in Elgg, JCow by emran

I saw some request in JCow forum about user add from admin panel.
So i gave sometimes and it works.

Here is the code:

1. First you have to edit modules/admin/admin.php

and put these two function.

function useradd(){
nav(t(‘Users/Add User’));
section_content(‘
<fieldset>
<form action=”‘.url(‘admin/useraddpost’).’” method=”post”>
‘);

section_content(‘
<p>
‘.label(‘Full Name’).’
<input type=”text” name=”fullname” size=30 />
</p>

<p>
‘.label(‘Username’).’
<input type=”text” name=”username” size=30 />
</p>
<p>
‘.label(‘Password’).’
<input type=”text” name=”password” size=30 />
</p>
<p>
‘.label(‘E-mail’).’
<input type=”text” name=”email” size=30 />
</p>
<p>
‘.label(t(‘Gender’)).’
<input type=”radio” name=”gender” value=1 checked/> Male
<input type=”radio” name=”gender” value=0 /> Female
<input type=”radio” name=”gender” value=2 /> Hide<br />
</p>

<p>
‘.label(t(‘Status’)).’
<input type=”radio” name=”disabled” value=0 checked/> Active
<input type=”radio” name=”disabled” value=1 /> Pending
<input type=”radio” name=”disabled” value=2 /> Suspended<br />
</p>

<p>
<input type=”submit” value=”‘.t(‘Add User’).’” />
</p>
</form>
</fieldset>’);
}

the above function will show form to add user.

function useraddpost(){

$_POST['username'] = strtolower($_POST['username']);

if (strlen($_POST['username']) < 4 || strlen($_POST['username']) > 18 || !ereg(“^[0-9a-z]+$”,$_POST['username'])) {
$errors[] = t(‘Username’).’: ‘.t(‘from 4 to 18 characters, only 0-9,a-z’);
}

if (!$_POST['email'] || !$_POST['fullname'] || !$_POST['username'] || !$_POST['password']) {
$errors[] = t(‘Please fill in all the required blanks’);
}

if(!eregi(“^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”, $_POST['email'])) {
$errors[] = t(‘Unavailable email address’);
}

$password = md5($_POST['password'].’jcow’);
$timeline = time();
$res = sql_query(“select * from `”.tb().”accounts` where email=’{$_POST['email']}’”);
if (sql_counts($res)) {
$errors[] = t(‘You have registered with this email address before.’);
}
$res = sql_query(“select * from `”.tb().”accounts` where username=’{$_POST['username']}’”);
if (sql_counts($res)) {
$errors[] = t(‘The Username has already been used’);
}

if(!is_array($errors)){

sql_query(“insert into `”.tb().”accounts` (hide_age,gender,disabled,password,email,username,fullname,created) values
(’1′,”.$_POST['gender'].”,”.$_POST['disabled'].”,’$password’,'”.$_POST['email'].”‘,’”.$_POST['username'].”‘,’”.$_POST['fullname'].”‘,’”.$timeline.”‘)”);
$uid = insert_id();
sql_query(“insert into `”.tb().”profiles` (id,style_ids) values($uid,’3|3|3′)”);
stream_publish(t(‘Signed Up’),”,”,$uid);
t(‘Congratulations! You have successfully created user.’);
redirect(“admin/users”);
}else {
foreach ($errors as $error) {
$error_msg .= ‘<li>’.$error.’</li>’;
}
sys_notice(t(‘Errors’).’:<ul>’.$error_msg.’</ul>’);
}

}

The above function will add user after submitting.

2. Now add this line to users() function of admin.php files.

c(“<p><a href=”.url(“admin/useradd”).”>Add User</a></p>”);

Jcow Admin Add user

Jcow Admin Add user Link

3. That’s all. Go to admin panel->members->add user. i hope rest of work you can do:P..

Download the source code.

Jcow Admin Add user Source

by emran

SMTP Module at JCow Social Script

1:28 pm in Elgg, JCow by emran

This is my first module for JCow Social script. Sometimes we need remote SMTP server to send out email.This script will help you to send out email from remote SMTP server even gmail or yahoo.It supports SSL connection too.

First, You need to download class.smtp.php and class.phpgmailer.php scripts and place into  includes/libs/ folder under JCow directory.

Now add these files to boot.inc.php from includes/ folder.

//loading SMTP Library
require_once ‘./includes/libs/class.phpgmailer.php’;
require_once ‘./includes/libs/class.smtp.php’;

Now edit my/config.php files and put smtp parameters as like follows:

$config['smtp_host']=’127.0.0.1′;
$config['smtp_port']=25;
$config['smtp_auth']=true;
$config['smtp_user']=’YOUR USERNAME’;
$config['smtp_pass']=’YOUR PASSWORD’;
$config['smtp_html']=true;
$config['smtp_from']=’noreply@YOURDOMAIN’;

Now the final step. Edit includes/libs/common.inc.php and write mailer function :

function jcow_user_mail($to,$subject,$message,$reply=”){
global $config;
$mail = new PHPGMailer();
$mail->Username = $config['smtp_user'];
$mail->Password = $config['smtp_pass'];
$mail->From = $config['smtp_from'];
$mail->FromName = get_gvar(‘site_name’);
$mail->Host=$config['smtp_host'];
$mail->Port=$config['smtp_port'];
$mail->Subject = $subject;
$mail->AddAddress($to);
$mail->Body = $message;
$mail->IsHTML=$config['smtp_html'];;

return $mail->Send();

}

Now all email will send out via SMTP server.This is tested script.

Download SMTP Module for JCow

by emran

Use wget with Squid Proxy Server

1:01 pm in Linux by emran

you can pass the proxy username and password as follows:
wget –proxy-user=YOUR-USERNAME-HERE –proxy-password=YOUR-PASSWORD-HERE http://nixcraft.com/file.tar.gz

by emran

Use Jquery with Smarty Template Engine

4:11 pm in Jquery, PHP by emran

Smarty is the template engine which is fast and nicely design for php programmers. Smarty makes your PHP code cleaner and promotes the V in MVC.

Jquery is the another lightweight JavaScript Library for rapid web development.

Anyway, do you see the problem that might arise when you try to embed your jQuery code or any other javascript library (like Prototype, MooTools, Extjs, etc.) that uses $ as a function name in the ?

The solution:
Use Smarty’s {literal}…{/literal} directives to tell Smarty parsing engine that it should not interpret the code within the block. Smarty will not parse the code which is inside of literal block.

Example:

User
<script type=”text/javascript”>// <![CDATA[
{literal}
$(document).ready(function(){
$(".clazz").css("color", "red");
});
{/literal}
// ]]></script>

User Information:

Name: {$name}

by emran

How to disable SELinux in CentOS?

2:32 pm in CentOS, Fedora by emran

In Fedora Core and RedHat Enterprise or CentOS, edit /etc/selinux/config and change the SELINUX line to SELINUX=disabled

That’s all.

by emran

Block DDoS attack on SIP Server

2:29 pm in Asterisk, FreeSWITCH, Kamailio, OpenSIPS, PJSIP, Yate by emran

Sometimes SIP Server attacked by hacker with huge number of SIP Registration.Which make mad the SIP Server.Full service can be get down. It can be blocked easily by IPTables. IPTables will work as Session Border Controller(SBC) for SIP Server. This script will work only with SIP.it will not work for TLS or SIPS.

#!/bin/sh
#
# INVITE rate, per host. Remember a successful (authenticated) call requires 2 INVITEs-
# Initial INVITE, 407 auth required (w/ nonce), INVITE with nonce and authentication.
IRATE=4/minute

# REGISTER rate, per host.
RRATE=2/minute

# All other SIP methods rate, per host. Be careful with SUBSCRIBEs, OPTIONS, CANCELs, etc.
ORATE=10/minute

# Methods for this script to ignore. These SIP methods are always allowed.
IGMETH=”OPTIONS”

# Burst
BURST=1

# Interface(s) to protect on INPUT. Seperate multiple interfaces with spaces.
# This will protect SIP services on THIS HOST.
IFACE=”eth0″

# Reject/drop action – usually something like DROP or REJECT.
# Use ACCEPT to use this script to not filter traffic but still collect statistics.
DACTION=DROP

# Protocol(s) to filter – can be either tcp or udp or both. Seperate multiples with spaces.
PROTOCOLS=”udp tcp”

# Enable logging.
#LOG=YES

# Block tel: URIs completely?
# P.S. – tel: sucks!
BLOCKTEL=yes

# Interface(s) to protect on FORWARD. Seperate multiple interfaces with spaces.
# The same hashtable will protect the entire network from the same host(s).
# Destination IP is NOT taken into consideration.
# This will protect any SIP services running on the network that uses this machine
# as a router (as long as you get the interfaces right).
#FIFACE=”eth0″

# Location of iptables binary.
IPTABLES=`which iptables`

# Search packet to this location. A larger offset looks further into the packet
# and takes more time but could catch more attacks (and false alarms).
# Remember, the method to match on is always in the beginning of the packet.
OFFSET=65

# SIP port
SPORT=5060

if [ ! "$1" ]
then
echo “SIP DoS/DDoS mitigation script for iptables
See top of script for configuration

Usage:
$0 [start|stop|status]”
exit 1
fi

if [ "$1" = "status" ]
then
$IPTABLES -L -v -n
exit
fi

# Setup iptables
$IPTABLES -F sipdos 2> /dev/null
$IPTABLES -X sipdos 2> /dev/null
$IPTABLES -N sipdos 2> /dev/null

if [ "$1" = "stop" ]
then
echo “Clearing iptables rules…”
if [ "$FIFACE" ]
then
$IPTABLES -F FORWARD 2> /dev/null
fi
$IPTABLES -F INPUT 2> /dev/null
exit
fi

# Send the right traffic through our chain
for i in $IFACE
do
for l in $PROTOCOLS
do
$IPTABLES -A INPUT -i $i -m $l -p $l –dport $SPORT -j sipdos
done
done

# Send the right forwarded traffic through our chain
if [ "$FIFACE" ]
then
for j in $FIFACE
do
for l in $PROTOCOLS
do
$IPTABLES -A FORWARD -i $j -m $l -p $l –dport $SPORT -j sipdos
done
done
fi

# “Handle” tel: URIs
if [ "$BLOCKTEL" ]
then
$IPTABLES -A sipdos -m string –string “tel:” –algo bm –to $OFFSET -j $DACTION
fi

# Ignore certain (configured) methods
if [ "$IGMETH" ]
then
for k in $IGMETH
do
$IPTABLES -A sipdos -m string –string “$k sip:” –algo bm –to $OFFSET -j ACCEPT
done
fi

# Finally set some limits…

# INVITE limit
$IPTABLES -A sipdos -m string –string “INVITE sip:” –algo bm –to $OFFSET \
-m hashlimit –hashlimit $IRATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_i_limit -j ACCEPT

# REGISTER limit
$IPTABLES -A sipdos -m string –string “REGISTER sip:” –algo bm –to $OFFSET \
-m hashlimit –hashlimit $RRATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_r_limit -j ACCEPT

# All other SIP packets…
$IPTABLES -A sipdos -m hashlimit –hashlimit $ORATE –hashlimit-burst $BURST \
–hashlimit-mode srcip,dstport –hashlimit-name sip_o_limit -j ACCEPT

# Take action on everything else
if [ $LOG ]
then
$IPTABLES -A sipdos -j LOG
fi

$IPTABLES -A sipdos -j $DACTION

by emran

Freebsd: Install wget Utility To Download Files From The Internet

11:08 am in FreeBSD, Unix by emran

Install wget Using FreeBSD Ports Collection

Type the following command as root user to upgrade ports tree, enter:

# portsnap fetch update

Now, install the wget, enter:

# cd /usr/ports/ftp/wget
# make install clean
# rehash

by emran

Git Tutorial

10:19 am in CentOS, Linux by emran

You have to download your project and place to a folder.

$ tar xzf project.tar.gz
$ cd project
$ git init-db

This will initialize your project on git.now you have to add files which will monitored via git.

$ git add .

these means git will monitor all files.

$ git commit -a

This will prompt a message to commit.
Try modifying some files, then run

$git diff

to review your changes.