2014年12月22日 星期一

tp link router flash rom (For tp link 940N v2.1)

For tp link 940N v2.1

1. Download openwrt-ar71xx-generic-tl-wr841n-v8-squashfs-factory.bin or find in openwrt download page.
link: https://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/

2. Open it in a hex editor. Look at offset 0x40. There should be the following bytes: 08 41 00 08. Modify to: 09 41 00 05
link: http://mh-nexus.de/en/hxd/

3. Get mktplinkfw.c, md5.c and md5.h.
Compile the tool: gcc -Os mktplinkfw.c md5.c -o mktplinkfw.
Run: ./mktplinkfw -i *-factory.bin

4. Look for the expected MD5Sum1: expected : e5 67 34 4d 04 99 20 60 f5 76 c6 04 15 81 ab f8

5. Open the hex editor again, go to offset 0x4c, and copy the MD5 above (it should span from offset 0x4c to offset 0x5b).

6. Go and upload the resulting file to firmware upgrade (in TP-Link web-interface). Good luck.
Many thanks to LOM from DD-WRT and to cable007 for reporting this approach worked with DD-WRT

:)



Reference
https://forum.openwrt.org/viewtopic.php?pid=206667#p206667

I have just put a TL-WR941ND v5.0 router on production with OpenWrt. You can use the same firmware file as TL-WR841N v8, but you need to modify the header in order for the TP-Link web-interface to recognize it as a valid firmware for WR941ND v5.0 hardware.
For the impatient, I have put my modified firmware online: tl-wr941nd_v5.0.bin. MD5 is: db062f1699c760775c5046cc303cba91. It worked perfectly with my router (I did not need to open it at all), but no warranties it will not brick your router, though.
If you want to modify the firmware yourself, do as follows:
Download openwrt-ar71xx-generic-tl-wr841n-v8-squashfs-factory.bin
Open it in a hex editor. Look at offset 0x40. There should be the following bytes: 08 41 00 08. Modify to: 09 41 00 05
Get mktplinkfw.c, md5.c and md5.h. Compile the tool: gcc -Os mktplinkfw.c md5.c -o mktplinkfw.
Run: ./mktplinkfw -i *-factory.bin
Look for the expected MD5Sum1: expected : e5 67 34 4d 04 99 20 60 f5 76 c6 04 15 81 ab f8
Open the hex editor again, go to offset 0x4c, and copy the MD5 above (it should span from offset 0x4c to offset 0x5b).
Go and upload the resulting file to firmware upgrade (in TP-Link web-interface). Good luck.
Many thanks to LOM from DD-WRT and to cable007 for reporting this approach worked with DD-WRT



File name              : wr940nv2_en_3_15_9_up_boot(140627).bin
File size              : 0x003c0000 /  3932160 bytes
Version 1 Header size  : 0x00000200 /      512 bytes
Header MD5Sum1         : f1 66 0b a3 c1 42 34 5d 57 60 81 7e 8d 17 27 88 (*ERROR*)
          --> expected : e5 67 34 4d 04 99 20 60 f5 76 c6 04 15 81 ab f8 
Header MD5Sum2         : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (purpose yet unknown, unchecked here)

Vendor name            : OpenWrt
Firmware version       : r36088
Hardware ID            : 0x09410005 (unknown)
Hardware Revision      : 0x00000001

Kernel data offset     : 0x00000200 /      512 bytes
Kernel data length     : 0x000e9a7c /   957052 bytes
Kernel load address    : 0x80060000
Kernel entry point     : 0x80060000
Rootfs data offset     : 0x00100000 /  1048576 bytes
Rootfs data length     : 0x001c7f05 /  1867525 bytes
Boot loader data offset: 0x00000000 /        0 bytes
Boot loader data length: 0x00000000 /        0 bytes
Total firmware length  : 0x003c0000 /  3932160 bytes

2014年9月4日 星期四

PHP Doctrine 2.4 reverse engineering mysql database, use xml driver, don't use annotation driver

PHP Doctrine 2.4 reverse engineering mysql database, use xml driver, don't use annotation driver
- generate entities from database


assume your bootstrap.php is located in your application folder
-app/
    -bootstrap.php
    -src/                        - store the xml mapping files (database to entities mapping)
    -entities/                 - store the entities generated by doctrine
    -vender/
         -doctrine-cli.php

0. bootstrap.php

<?php
require_once 'vendor/autoload.php';

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = array(__DIR__ . "/entities");
$isDevMode = true;

// the connection configuration
$dbParams = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'root',
    'password' => 'testpwd',
    'dbname'   => 'databasename',
    'host'     => 'localhost',
    'port'     => '3306',
);

//$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);  won;t work!
$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);


Please use XMLMetadataConfiguration instead of AnnotationMetadata for reverse engineering! THIS IS VERY IMPORTANT! Especially when you see the

Search Results

This No Metadata Class to process means that the annotation cannot be recognized in the entity class or there are no entity class.



  1. 1. create config file in vendor/doctrine-cli.php 

<?php
// vendor/doctrine-cli.php
use Symfony\Component\Console\Helper\HelperSet,
    Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper,
    Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper,
    Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . '/../bootstrap.php';

$helperSet = new HelperSet(array(
    'em' => new EntityManagerHelper($entityManager),
    'conn' => new ConnectionHelper($entityManager->getConnection())
));
ConsoleRunner::run($helperSet);


2. reverse engineering - generate xml from database
in the shell or command prompt:
> cd vendor

> php doctrine-cli.php orm:convert-mapping --from-database xml ../src
Now you can see *.dcm.xml are generated in your app/src/ folder

> php doctrine-cli.php orm:generate:entities ../entities --generate-annotations=true
this will generate the entities to the app/entities files

Done!

Doctrine will cache your those. It is important to clear them especially when you relocated your folders of entities or src folder. this is VERT IMPORTANT!
> php doctrine-cli.php orm:clear-cache:metadata


After the reverse engineering, you you may need to change the database schema. It is not advised to change in the database directly! If you change in the database directly, you will end up changing the schema AND reverse engineering AGAIN which will OVERWRITE your entities files!

My approach is to change the xml mapping file, then use doctrine to change the database schema. In this way, everything are synchronized and save your life.
1. change the schema xml file in src/. e.g add <field name = 'newfield' ...... />
go to vendor folder
> cd vendor
> php doctrine-cli.php orm:schema-tool:update --dump-sql
This allows you to see the sql statement of the "alter table ......". If you find those sql dump are correct,
> php doctrine-cli.php orm:schema-tool:update --dump-sql --force
this will send the sql to database.
That's it!

Should you experience any problem, try to clear cache first:
> php doctrine-cli.php orm:clear-cache:metadata

reference:
http://marco-pivetta.com/doctrine2-orm-tutorial
http://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started.html
http://christoph-burmeister.eu/?p=2268
http://stackoverflow.com/questions/8795338/create-tables-and-entities-with-doctrine2-based-on-schema-declaration

2014年1月22日 星期三

Centos 6.X upgrade php 5.3 to 5.5

Please read
http://www.aliencoders.com/content/how-fix-rpmfusion-nonfree-repo-error-centos-64

then
http://www.webtatic.com/packages/php55/


2014年1月6日 星期一

搵HK Freelance

話時話, 香港要搵IT Freelance programmer, 要求都一d都唔低. 冇返門强項真係未必搵到. 搵到都未必夠有肉食. 以我所知JAVA/ASPX/Object C 需求好大, PHP 都唔少, 當然還需要配合(backend) database (e.g. mysql, sql server, nosql ...), 以及frontend 即html5, javascript, css.

其實有些很穏陣又快又强的framework 可以用的. 我最愛用PHP, framework 包括Yii, codeigniter(deprecated). javascript 可以用jquery, zapto, 介面可以用twitter bootstrap.

現時手機 app 好流行, mobile development framework 都好多. 如果只係web developer 又唔係太識Java / iOS, 或者唔想學太難既language, 可以試一試用 intel app frameworkCordova (phonegap).

不過搵freelance programmer, 真係一d 都唔易. 最怕就係收左錢走左去. 不過我相信香港人唔係咁差的!!!

咁點會月以上的問題或project 爛尾? 其實有好多可能既...
1. 俾job 你果位咩都唔識, 成日話要加野或改, 又唔加錢
2. 佢低估了這project 的複雜性, 出錢太低, 時間太短
3. 你高估了這project 的複雜性, 唔夠時間做
4. 你 d 程式未test 過, (唔係就咁試一試果種), 點知有bug, 客係咁狂打給你, 你唔彩佢.


如果係programmer 的技術問題, 有咩好方法呢?
針對第4點, 你可以用TDD (Test-Driven Development).
有機會再談~

2014年1月4日 星期六

Yii remove the index.php

1. create a file .htaccess and put it in your project root folder
.htaccess
-------------------------------------------------
RewriteEngine On
RewriteBase /project123                    //change this to your folder e.g. localhost/project123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

config/main.php

//urlManager rules
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array( // customize rules for your application
//'<controller:\w+>/<id:\d+>'=>'<controller>/view',    // comment this
//'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
//'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',    // comment this
),
),

Example:

for further examples please read
http://www.yiiframework.com/doc/blog/1.1/en/final.url





開電腦公司

小弟自家制電腦程式公司, 專門做PHP, javascript 相關的程式. 我這類人, 巿場多的是. 要突圍而出, 真係唔易.

現在分享我一年幾的心得:
1. 先有門專業技能 (Java/C++/ASPX/PHP/javascript/Ruby/Django/Sql server/mysql/Oracle...)
2. 要識點樣去test 你的程式. 否則你的生涯很快會完!
3. 做好第一份JOB. 記住係要做好!!!
4. 開頭唔好同客咁計交. 之後自然會你識計
5. 識多D朋友

當你能做好以上5點, 際遇很奇妙地降到你身上!

之後, 你就會面對究竟自己做同打工有咩分別. 原因係你個客會成日搵你. 你會長期做佢生意.
你計一計邊數, 其實你在做什麼?!

好多人話, home office 正啦~. 其實唔係大家想像中咁.
1. 工作時間 同打工唔同, 放假同打工有時分唔開, 反之亦然
2. 一個人又未必敢接得多project. 事實接到幾多個呢?!
3. 個客一叫你俾個budget, 你左計又計, 又怕叫得貴, 冇左個客, 又怕叫得低, 冇肉食. 問佢budget, 佢又話睇你.
4. 一定會遇到收唔到錢的情況. 拖數客最多.
5. 為將來的發展摸不著頭腦.

創業的路真係唔容易. 特別係我呢D凡夫俗子.

PHP Codeigniter and Yii

According to www.codeigniter.com, there is an article written on 9th July 2013 and the title is "EllisLab Seeking New Owner for CodeIgniter". WHAT! well, I can totally comprehend you feeling. I wrote a code generation (CRUD) based on codeigniter. What should I do? Should I switch to another framework?

The dilemma is that if you keep on using codeigniter, there are not more support, bug fix, improvements on the framework. If you switch to another framework, you have to learn and development your tools again which might take you some time~

For me, I switched to Yii. The reason is as follows:
1. Yii has Gii (code generator)
2. The structure is very similar to Codeigniter
3. Yii has more support and the developer community is large!
4. It is better that Codeigniter as well like namespace, cms, performance and Yii is unit-tested~

Yii keeps up-to-date development on the latest php version. Start Yii today and u won't experience this dilemma twice!