Tuesday, August 4, 2009

Friday, July 31, 2009

Make FckEditor Plugin In Codeigniter

I just try how to use Fckeditor as a Library in CI.It’s indeed simple but in the wiki ( http://codeigniter.com/wiki/FCKeditor/ ) it’s hard to understand witch updates to do for the last CI version (1.7.1). Here what I do step by step.



  1. Download Fckeditor.

  2. Extract the folder "fckeditor" in "system/plugins/"

  3. Open the "fckeditor" folder and copy the file "fckeditor.php"

  4. Past the file in "system/application/libraries"

  5. Edit the file you just past and add this line to the top

    if (!defined('BASEPATH')) exit('No direct script access allowed');



  6. In the same file now change the path of the include to have something like

    if ( !function_exists('version_compare') || version_compare( phpversion(), '5',
    '<' ) )
    include_once( 'system/plugins/fckeditor/fckeditor_php4.php' ) ;
    else
    include_once( 'system/plugins/fckeditor/fckeditor_php5.php' ) ;


  7. Open the file "system/plugins/fckeditor/fckeditor_php5.php" and add this line to the top


    if (!defined('BASEPATH')) exit('No direct script access allowed');


  8. Change this part of the class

    class FCKeditor

    {

    public $InstanceName ;


    public $BasePath ;

    public $Width ;

    public $Height ;

    public $ToolbarSet ;

    public $Value ;


    public $Config ;

    public function __construct( $instanceName )

    {

    $this->InstanceName = $instanceName ;


    $this->BasePath = '/fckeditor/' ;

    $this->Width = '100%' ;

    $this->Height = '200' ;


    $this->ToolbarSet = 'Default' ;

    $this->Value = '' ;

    $this->Config = array() ;


    }

    ...

    into this




    class Fckeditor
    {
    var $InstanceName ;
    var $BasePath ;
    var $Width ;
    var $Height ;
    var $ToolbarSet ;
    var $Value ;
    var $Config ;
    public function __construct( $array )
    {
    $this->InstanceName = $array['instanceName'] ;
    $this->BasePath = $array['BasePath'] ;
    $this->Width = $array['Width'] ;
    $this->Height = $array['Height'] ;
    $this->ToolbarSet = $array['ToolbarSet'] ;
    $this->Value = $array['Value'] ;
    $this->Config = array() ;
    }


    ...

    open the fckeditor_php4.php and add the same line to the top and rename the class name into "class Fckeditor"

  9. In your controller you should have something like

    function fckeditorform(){
    $fckeditorConfig = array(
    'instanceName' => 'content',
    'BasePath' => base_url().'system/plugins/fckeditor/',
    'ToolbarSet' => 'Basic',
    'Width' => '100%',
    'Height' => '200',
    'Value' => ''
    );
    $this->load->library('fckeditor', $fckeditorConfig);
    $this->load->view('fckeditorView');
    }
    function fckeditorshowpost(){
    echo $this->input->post('content');
    }



  10. In your view you should have something like

    $this->load->helper('form');
    echo '<h1>FckEditor</h1>';
    echo form_open('yourcontroller/fckeditorshowpost');
    echo $this->fckeditor->Create() ;
    echo form_submit(array('value'=>'submit'));
    echo form_close();




That's it


referensi http://codeigniter.com/wiki/FCKeditor/

Simple Queue Separate Bandwidth International And Lokal IIX(Indonesia)

Assumed that:

1. Mikrotik Router do Masquerading / src-nat to the client. Client using a private IP.
2. Gateway used only one, both for international traffic and IIX.
3. You can use the web-proxy or without internal web-proxy. If you use the web-proxy, then there are some additional rule that needs to be done. Note the NAT and MANGLE in the example below.


If there are parameters on which you differ with the conditions in the field, the configuration on this article you must be modified in accordance with your network configuration.

Basic Settings

Here is a network diagram and the assumption of IP Address that will be used in this example.

To simplify the example, we change the name of each interface in accordance with the duties of each.


[admin @ Mikrotik]> / interface pr

Flags: X - disabled, D - dynamic, R - running # NAME TYPE RX-RATE TX-RATE MTU

0 R public ether-ether 0 0 1500 1 R Local ether-ether 0 0 1500

For the client, will use the IP block 192.168.0.0/24, and enabled IP Address 192.168.0.1 as the gateway and the router is installed, local-ether interface. Clients can use the IP Address 192.168.0-2 to 192.168.0.254 with subnet mask 255.255.255.0.


[admin @ Mikrotik]> / ip ad pr

Flags: X - disabled, I - invalid, D - dynamic # ADDRESS NETWORK Broadcast Interface

0 202.0.0.1/24 202.0.0.0 202.0.0.255 ether-public

1 192.168.0.1/24 192.168.0.0 192.168.0.255 local-ether

Do not forget to set DNS server on the router, and enable the feature "allow remote requests."

Because the client uses private IP, then we must make the src-nat such as the following example.


[admin @ Mikrotik]> / ip nat pr fi

Flags: X - disabled, I - invalid, D - dynamic

0 chain = srcnat out-interface = ether-public action = Masquerade

If you use transparent web-proxy, you need to add nat redirect rule, as shown in the example below (the rule that is printed bold).


[admin @ Mikrotik]> / ip nat fi

pr Flags: X - disabled, I - invalid, D - dynamic

0 chain = srcnat out-interface = ether-public action = Masquerade

1 chain = dstnat in-interface = ether-local protocol = tcp dst-port = 80 action = redirect to-ports = 8080

Do not forget to activate the feature web-proxy, and set port web-services proxynya, and adjusted to the port redirect in the above example.

CHECK: Make sure all the configuration has been working well. Do ping (from both the router and from the client) to the outside of your network switch.

Setting IP Address List

Start Mikrotik RouterOS version 2.9, with a known feature called IP Address List. This feature is a grouping IP Address and IP Address of each can we Rename. This group can be used as a parameter in the mangle, the firewall filter, nat, or queue.

Mikrotik Indonesia has provided a list of IP Address diadvertise in OpenIXP and IIX, which can be downloaded freely at the URL: http://www.mikrotik.co.id/getfile.php?nf=nice.rsc

Nice.rsc this file is created automatically on the server Mikrotik Indonesia pk every morning around 05.30, and is the data that has been in the optimization to eliminate duplicate entry and overlapping subnet. When this number of lines in the script is around 430 lines.

Example file contents nice.rsc:


# Script created by: Valens Riyadi@www.mikrotik.co.id # Generated at 26 April 2007 05:30:02 WIB ... 431 lines

/ ip firewall address-list add list = nice address = "1.2.3.4" rem [find nice list =]

add list = nice address = "125.162.0.0/16" add list = nice address = "125.163.0.0/16"

add list = nice address = "152.118.0.0/16" add list = nice address = "125.160.0.0/16"

add list = nice address = "125.161.0.0/16" add list = nice address = "125.164.0.0/16"

. . dst ...

Save the file to your computer with the name nice.rsc, and do FTP to Mikrotik routers, and uploadlah file in the router. The example below is using the upload Console on Linux.


bagoes jasmine @: ~ $ wget http://www.mikrotik.co.id/getfile.php?nf=nice.rsc
- 2009-07-31 10:33:56 - http://www.mikrotik.co.id/getfile.php?nf=nice.rsc
Resolving www.mikrotik.co.id ... 202.65.113.16
Connecting to www.mikrotik.co.id|202.65.113.16|:80 ... connected.
HTTP request sent, Awaiting response ... 302 Found
Location: http://ixp.mikrotik.co.id/download/nice.rsc [following]
- 2009-07-31 10:33:56 - http://ixp.mikrotik.co.id/download/nice.rsc
Resolving ixp.mikrotik.co.id ... 202.65.113.115
Connecting to ixp.mikrotik.co.id | 202.65.113.115 |: 80 ... connected.
HTTP request sent, Awaiting response ... 200 OK
Length: 28,718 (28K) [text / plain]
Saving to: `nice.rsc.1 '

100 %[======================================>] 28.718 --.- K / s in 0.01s

2009-07-31 10:33:56 (2.46 MB / s) - `nice.rsc.1 'saved [28718/28718]

Once uploaded the file, just import the file.

[admin @ Mikrotik]> import nice.rsc Opening script file nice.rsc Script file loaded and executed successfully




Make sure that the import process has been held successfully, with the check-Address List on the menu IP - Firewall

The upload process can also be done automatically if you have any knowledge of scripting. For example, you create a shell script on Linux to do the download and automatically upload a file automatically each pk 06.00 am. Then you create a scheduler on the router to do the import file.

If you use RouterOS version 3.x, the update can also be done automatically. Details can be seen in this article.

Setting Mangle

The next step is to create a mangle. We need to make the connection 1 mark and 2 mark the packet, each for international and local traffic.


[admin @ Mikrotik]> / ip firewall mangle pr

Flags: X - disabled, I - invalid, D - dynamic

0 chain = prerouting in-ether-interface = local dst-address-list = nice action = mark-connection new-connection-mark = conn-IIX passthrough = yes

1 chain = prerouting connection-mark = conn-IIX action = mark-packet new-packet-mark = packet-IIX passthrough = no

2 = prerouting chain action = mark-packet new-packet-mark = packet-intl passthrough = no

To rule # 0, sure you choose the interface that leads to the client. For the chain, we use prerouting, and for both packet-mark, we use the passthrough = no.

If you use the internal web-proxy and redirecting trafic, then you make 2 additional rule such as the example below (the rule that is printed bold).


[admin @ Mikrotik]> / ip firewall mangle pr

Flags: X - disabled, I - invalid, D - dynamic

0 chain = prerouting in-ether-interface = local dst-address-list = nice action = mark-connection new-connection-mark = conn-IIX passthrough = yes

1 chain = prerouting connection-mark = conn-IIX action = mark-packet new-packet-mark = packet-IIX passthrough = no

2 = output chain connection-mark = conn-IIX action = mark-packet new-packet-mark = packet-IIX passthrough = no

3 chain = prerouting action = mark-packet new-packet-mark = packet-intl passthrough = no 4 chain = output action = mark-packet new-packet-mark = packet-intl passthrough = no

Simple queue settings

For each client, we need to make 2 pieces rule simple queue. In the example below, we will be doing the limitation for the 192.168.0.2/32 IP client, and we will give the limitation IIX (up / down) of 64k/256k, and as for international (up / down) 32k/128k.


[admin @ Mikrotik]> / queue simple pr

Flags: X - disabled, I - invalid, D - dynamic

0 name = "client02-IIX" target-addresses = 192.168.0.2/32 dst-address = 0.0.0.0 / 0 interface = all parent = none packet-marks = packet-IIX direction = both priority = 8 queue = default-small / default-small limit-at = 0 / 0 max-limit = 64000/256000 total-queue = default-small

1 name = "client02-In" target-addresses = 192.168.0.2/32 dst-address = 0.0.0.0 / 0 interface = all parent = none packet-marks = packet-intl direction = both priority = 8 queue = default-small / default-small limit-at = 0 / 0 max-limit = 32000/128000 total-queue = default-small





In this article, we assume that:

End checks

When done, do check the site to make access to local and international sites, and see the counter at both the firewall and mangle the simple queue.

You can also use the queue type pcq on traffic so that each client can be spread evenly.

reference: http://ojiex.blogspot.com/2009/02/tutorial-mikrotik-simple-queue-memisah.html

Use Join Table

Why we need query join? Query join use to join some table become one table. Technic to join is plus value from (RDBMS: Relational Database Management System), where data can keep in some little different table, not one big table with many column. In Programing, query join almost always use, cause that is the key to produce more valuable information than one query in one table.

How it works is to join a match with the search for a particular column in a table with a column in another table, and displays the results as a set of aggregate data. In general, there are 3 types of join, the inner JOIN, LEFT JOIN and RIGHT JOIN. However, the addition of 3 kinds, there are several additional variants depending on the RDBMS used.

For example, we will join the table that store patient information Bios patients, the symptom that the table data store symptom suffered by patients. Both tables will be based on a join-column containing the patient's identity number (id) that is located on the second table.


CREATE TABLE pasien (id int(10), nama char(30));
INSERT INTO pasien (id,nama) VALUES ('1','John');
INSERT INTO pasien (id,nama) VALUES ('2','Jane');
INSERT INTO pasien (id,nama) VALUES ('3','Mike');
INSERT INTO pasien (id,nama) VALUES ('4','Doel');

CREATE TABLE symptom (id int(10), symptom char(30));
INSERT INTO symptom (id,symptom) VALUES ('1','Demam');
INSERT INTO symptom (id,symptom) VALUES ('2','Pusing');
INSERT INTO symptom (id,symptom) VALUES ('3','Mual');

INNER JOIN

With INNER JOIN

only
shown that these lines to one another have a match.


Sample:

SELECT a.nama, b.symptom
FROM pasien a
INNER JOIN symptom b
ON b.id = a.id;
+------+---------+
| nama | symptom |
+------+---------+
| John | Demam |
| Jane | Pusing |
| Mike | Mual |
+------+---------+

LEFT JOIN

A query with LEFT JOIN akan show
all line

from the left side of the table (first / main or patient) combined with the right side of the table (second or symptom).



Sample:

SELECT a.nama, b.symptom
FROM pasien a
LEFT JOIN symptom b
ON b.id = a.id;
+------+---------+
| nama | symptom |
+------+---------+
| John | Demam |
| Jane | Pusing |
| Mike | Mual |
| Doel | NULL |
+------+---------+

The difference with the inner JOIN is on LEFT JOIN - the entire first row of the table will be displayed even if no matching rows in both tables. See the above example, the patient did not have data Doel symptom so shown NULL (NULL here states that there is no data in the column). In addition, the position of the table so have the meaning, the first table or the left (before the table is' LEFT JOIN ') will be the main table that quering first, then finding matches with the right table or the second (after the table is' LEFT JOIN') .




RIGHT JOIN

RIGHT JOIN query is almost the same as the LEFT JOIN, just reversed its position, which will display all rows from the right table (the second) although there is no match on the left of the table (the first).


Sample:

SELECT a.nama, b.symptom
FROM pasien a
RIGHT JOIN symptom b
ON b.id = a.id;
+------+---------+
| nama | symptom |
+------+---------+
| John | Demam |
| Jane | Pusing |
| Mike | Mual |
+------+---------+


Mikrotik redirect Transparent Proxy to another machine

Condition :

Mikrotik : 192.168.0.1

Internet : eth1

Lan : eth2

Proxy : 192.168.0.254

port : 3128

———–

asumed transparent proxy is run normal on your Proxy Server

1. Table NAT ( IP > Firewall > NAT )

dst-nat, src-address = !192.168.0.254 protocol=tcp dst-port=80 in-interface=ether2 action=dstnat to-addresses=192.168.0.254 to-port=3128

src-nat, src-address=192.168.0.0/24 out-interface=ether2 action=srcnat to-addresses=192.168.0.1 to-port=0-65535

2. Table Filter Rules

chain=forward src-address=192.168.0.0/24 dst-address=192.168.0.254 dst-port=3128 in-interface=ether2 out-interface=ether1 action=accept

with this script transparent proxy with proxy on different machine run perfectly.

SyntaxHighlighter

1.download SyntaxHighlighter_1.5.1.rar
2.unrar SyntaxHighlighter_1.5.1.rar
3.rename dp.SyntaxHighlighter dp
4.make your file test.htm

<html>
<head>

<link type="text/css" rel="stylesheet" href="http://yourpath/Styles/SyntaxHighlighter.css"></link>
<script language="javascript" src="http://yourpath/Scripts/shCore.js"></script>
<script language="javascript" src="http://yourpath/Scripts/shBrushCSharp.js"></script>
<script language="javascript" src="http://yourpath/Scripts/shBrushXml.js"></script>

<script language="javascript">
function start() {
dp.SyntaxHighlighter.ClipboardSwf= 'http://yourpath/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code', true, true, false, 1, false);
}
window.onload = start;
</script>

</head>
<body>
<pre name="code" class="c-sharp">
echo "line 1";
echo "line 2";
</pre>

</body>
</html>


save in your dp folder then open on Browser

look like this


echo "line 1";
echo "line 2";



Note:
add
dp.SyntaxHighlighter.BloggerMode();
in function start to use on blogspot.com


Gammu SMS Gateway

Writer Using

  1. HP SE K790i
  2. OS Ubuntu 9.04

Install Step By step

1.Install gammu

$sudo apt-get install gammu

$locate smsdrc

$cp /usr/share/doc/gammu/examples/config/* .

$gunzip smsdrc .gz gammurc.gz

$sudo cp smsdrc gammurc /etc

$sudo vim /etc/gammurc

#change this line

[gammu]

port = /dev/ttyACM0
connection = at19200

; Do not use model configuration unless you really need it
;model = 6110
;synchronizetime = yes
;logfile = gammulog
;logformat = textall
;use_locking = yes
;gammuloc = locfile
;startinfo = yes
;gammucoding = utf8
;usephonedb = yes

#save

$gammu --configure

Manufacturer : Sony Ericsson
Model : K790i/K790c (AAF-1022011-BV)
Firmware : R8BF003 080130 2133 CXC1250481_CHINA_EV
IMEI : 352206010781695
Product code : AAF-1022011-BV
SIM IMSI : 510219160664064

$echo "tes sms server" | gammu --sendsms TEXT 085691662771

If you want break, press Ctrl+C...
Sending SMS 1/1....waiting for network answer..OK, message reference=203

test sms server will send to destination number.

2.Connect to Database mysql

$gunzip mysql.gz

$mysql -uroot -pyourpassword

Your MySQL connection id is 81
Server version: 5.0.75-0ubuntu10.2 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database smsserver;
Query OK, 1 row affected (0.03 sec)

mysql> exit
Bye

$mysql -uroot -pyourpassword smsserver <>

SMS Database has been imported now.

$sudo vim /etc/smsdrc

# ----------------- SETTINGS FOR --smsd MYSQL or --smsd PGSQL -------------------
user = root
password = yourpassword
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
database = smsserver

$wget http://www.syednetworks.com/gammu-sms-gateway.zip

$unzip gammu-sms-gateway.zip

$sudo mv gammu-sms-gateway/* /var/www/gammu

$sudo chmod -R 777 /var/www/sms

Edit your sms.php on /var/www/sms

mysql_connect("localhost", "root", "yourpassword") or die(mysql_error()); //connect to mysql
mysql_select_db("smsserver") or die(mysql_error()); //select database

Run SMS gateway and it will take all of your inbox(all inbox will remove to database).

$gammu –smsd MYSQL smsdrc

Note:

Untuk mengirim sms dari aplikasi anda harus:

menambah permission /dev/ttyACM0

$sudo chmod o+rw /dev/ttyACM0

change this line on send-sms.php

        $destination = getPostVariable( 'destination' );
$message = getPostVariable( 'message' );
exec( '/usr/bin/gammu --sendsms EMS ' . escapeshellarg( $destination ) . ' -text ' . escapeshellarg( $message ) ); // try this one
//system( sprintf( '/usr/local/bin/gammu --sendsms EMS %s -text %s', escapeshellarg( $destination ), escapeshellarg( $message ) ) );
header( 'Location: ' . $_SERVER[ 'PHP_SELF' ] . '?accepted=yes' );
exit();

then send sms by aplication

3.Make SMS AutoRespond

run gammu sms-gateway

$gammu –smsd MYSQL smsdrc

make trigger in database smsserver

create trigger
smsserver.autorespond1
AFTER
INSERT
on
smsserver.inbox
for each row begin
if(New.TextDecoded = "REG COBA")
THEN
insert into outbox(DestinationNumber,
TextDecoded,Coding,CreatorID)values(New.SenderNumber,"Terima Kasih",'Default_No_Compression','1');
end if;
end

Send REG COBA to your phone no,
then you'll retreive sms

"Terima Kasih"

End Of the Game