torrentstorm 1.3

Transcription

torrentstorm 1.3
!" #!$"!
%!&#&
' ""() ")*'
%
)! '#(+ ,&*)$&!#
-.- #!$"$&#
!)#('#
(0000000000)
!$*, ,2 4810114
__________________________________________________________________
P2P File Sharing on OpenWRT
i
*))*-7
%
P2P File Sharing on Openwrt " &#(IJ#& &#&
2#!.-J J
'!KL! +& .
JJ M # "
J !N22! $ O+!+%
!'
+
2".- ,#.-..& J J 7.. *2! P*7 7. 7
, P*7 .JN .O## .- Mr.Robert Elz O+&'
+.-
.-)#M '
*,W%
,"'%',W%
#
,-
J* '* '
.- + .-J,!'
%
""
JJ#,, , .-J# J#&'
.-, *I.-''
,W%
"%!)
.-J!" J'
"' J#!*&#(+ O+#2#!
'%
"!
!$*, ,2 4810114
__________________________________________________________________
P2P File Sharing on OpenWRT
ii
!#
XJ # -* I) Y !# !* 2# ' +&!+ %!)*.%&%!
#!)*)#'
* (Server) %!) #!)*)#'**& '*XY
(''*&#('*&)#&& '*&#(
'*& #'
#!"!#&#(% &
. bittorrent .!#+ . P2P 2#!.XY
# %!
#!(.! -#&%!)%!&#)#'*
'%
(! +"
. bittorrent )'2'%.-#)# ,
+'2J Wireless Router ).
,*) %!,*%. client-bit torrent
' Wireless Router ,'('% . bittorrent & .-,*#
Web interface )*)"&J Wireless Router ,!'2.-
J%. client-bit torrent
%!&#))*)"%. interface ,*)O+- Firmware *) ''2
-!* +"
__________________________________________________________________ iii
P2P File Sharing on OpenWRT
Abstract
Nowadays, data communication on the internet was necessary for transmit
data from server to destination. Usually downloading was transferring data from
server to client. If users have exceeding calls to server that make communication
crowded problem, users can not accessible service. P2P (Peer-to-Peer) was choice to
solve problems. That can transmit and shared data between nodes to nodes. It make
stable for downloading.
So, this project aim for improve the system with using wireless router instead
of a computer. And design new system for web interface. I developed web interface to
control client-bit torrent program, for users easily to use.
__________________________________________________________________ iv
P2P File Sharing on OpenWRT
Y
..............................................................................................i
*))*-7.................................................................................................................ii
!# ...................................................................................................................... iii
Abstract ......................................................................................................................iv
Y
.......................................................................................................................v
YP, ................................................................................................................. viii
Y) .....................................................................................................................ix
1
................................................................................................................1
1.1
1.2
)(J-
%
....................................................................................2
1.3
) %
...........................................................................................2
1.4
.*%
.......................................................................................2
2
,"b......................................................................................................4
2.1
J .............................................................................................................4
2.2
Firmware ........................................................................................................5
2.3
. P2P(Peer-to-Peer) .....................................................................5
2.4
BitTorrent ................................................................................10
2.5
%. Ctorrent ..........................................................................................12
2.6
UNIX Command .........................................................................................13
2.7
! Shell Script ,"b ...........................................................................16
2.8
,"b Web interface OpenWrt...............................................................18
3
.- ..............................................................................................20
3.1
P, - ............................................................................................20
......................................................................................................1
__________________________________________________________________
P2P File Sharing on OpenWRT
v
3.2
-
3.3
. web interface ) .............................................................21
…..………………………………………………....20
3.3.1 About…………………………………………………………………22
3.3.2 Download……………………………………………………………. 23
3.3.3 Status………………………………………………………………....24
3.3.4 Storage………………………………………………………………. 25
55
3.4
Memory ........................................................................................26
4
!-! ..........................................................................................28
.XY%. Client-Bittorrent
4.1
..........................................................28
4.1.1 )*)".-'2%. Ctorrent ...………………………………………. 29
4.2
,W Web interface Wrieless router..……………………………....31
4.2
.XY'2 Memory……………….....……………………………....37
5
J.- .- .......................................................................................39
5.1
J
5.2
XY.-J
5.3
..........................................................................................................39
.-
..........................................................................................39
...................................................................................................40
J..........................................................................................................................................................41
P
...............................................................................................................................................................42
1
Firmware
2
%..- kernal module .................................................................45
3
Partition ..........................................................................................46
...........................................................................................43
3.1 Partition I …………………………………………….46
3.1 Swap……………………………………………………………….46
__________________________________________________________________ vi
P2P File Sharing on OpenWRT
4
Samba .- configuration
5
Code ............................................................................................................51
...................................................................47
__________________________________________________________________ vii
P2P File Sharing on OpenWRT
YP,
2-1 Wireless Router J# ASUS WL-500g Premium ………………………………… .…….4
2-2 .P,N*! %. Bittorrent ……..…………………………. …11
2-3 )!# Form Summit #…………………….………….………………....19
3-1 '2-%! User…………………….……..………………………….…20
3-2 P, -)..……………...………………………….....21
3-3 .P*. About………………...…..……………………………22
3-4 .P*. Download……………………………… ………… …. 23
3-5 .P*. Status…………………………………………….……24
3-6 .P*. Storage …………………………………………..……25
3-7 .P*. Memory……………………………………………………26
4-1 CPU -#0000000000...0000000000000000000 0028
4-2 CPU -%.00000...0000000000000000000000 0028
4-3 Process %. Ctorrent …………………………………………………..…….30
4-4 . %..- .……………………………………………….31
4-5 !% 00000…..…………………………………………..32
4-6 )&#2&o00……………………………………………….32
4-7 )2&o&#()0.……………………………………………….33
4-8 !()0000000.……………………………………………….33
4-9 %0000000.……………………………………… …………..34
4-10 )!&#() ...0000.……………………………………...…34
4-11 Status 000000000...0000.…… ……………………………….…35
4-12 .!-! &o.torrent..000. ………………………………………36
4-13 Storage 00000000.....0000.…………… …………………………36
4-14
free Memory0..0000.....0000.…………… …………………………37
__________________________________________________________________ viii
P2P File Sharing on OpenWRT
Y)
) 1-1 *%
'2# 1…………………………………….………….……2
) 1-2 *%
'2# 2…………………………………….………….……3
) 2-1 . P2P '2.-%.-!J)…………..………….……7
__________________________________________________________________ ix
P2P File Sharing on OpenWRT
1
1.1
P2P !
"#$%$&'
"("#) *)'+$,( Wireless Router 7*
8
+,
"'
$!!
'(9!'
P2P
)'9'%)
$&'
"("#) :8%"!'9$
;
Web interface 8"'#)+$,( Wireless Router
'#'"
Wireless Router :8 P2P )' 8'
8%"!' Software 8!8
P2P ;
"'#8$C Interface )
"( !)
',88
"()
"'#9$
8$C Interface 8# *)'E!
9'%; :8%9$
9'%; Web Interface Wireless Router )'89'%)
"'# 9$
"
"(
F* G:* $HI!'"
' :8% 8 9$
!%J9$
'8%# "'$HI!'!%
! Wireless
Router K( *)'$HI!'9'%"
!%
; USB Port
F*G:*$HI! Software P2P '#'"
;;" 7*
)'$HI!8% ,88'(9!'
%)
N"''%
)OOP' "
'(9!'!
"'$HI!N)O($C ,8)O(
8%!%)' !+8#*)'E9'%$8% Software !
9'%)'9$
Ctorrent F*G
9$
Ctorrent "'$HI!'%
__________________________________________________________________
P2P File Sharing on OpenWRT
1
1.2
- E
9$
!
P2P
- E web interface !'+
P2P
- $HI!'!%
Wireless router
1.3
- E9$
!
:'(9!'
)')
5 )O('8%
- E Web interface Wireless Router !;
:+
9$
!
P2P
- E Web interface !
:8%)O(!'(9!'N"#
1.4
1
2
3
4
5
6
8 1-1 '"981
#8 1 F*G P2P 9$
ctorrent
#8 2 F*G Web interface wireless router
#8 3 Web interface
#8 4 F*G8% Shell Script 8% Shell Script +
#8 5 ')$HI!J8"'*#
#8 6 "!($HI!+$;
__________________________________________________________________
P2P File Sharing on OpenWRT
2
1
2
3
4
5
8 1-2 '"982
#8 1 F*G Form J Submit ; Web interface
#8 2 F*G 8% Web interface Submit Job
#8 3 8% Web interface ':+
9$
#8 4 ')$HI!J8"'*#
#8 5 "!(+$;%
__________________________________________________________________
P2P File Sharing on OpenWRT
3
2
2.1
"
+$,(8
$C +$,( Wireless Router + ASUS WL-500g Premium 7*$C 8
+,
"'8#
- 125 High-Speed Mode
- WL-169gE, WL-138gE WL-100gE
- USB2.0 Port
- G
$'h% 64/128 bit WEP, WPA/WPA2/WPA-PSK/WPA2-PSK
- $C+$,(
lH (Embedded Devices) Microprocessor +
%h%
- Firmware 8$C Openwrt
- ")O+' 12.5W
+,
"'!
$ "'#9$
!'(9!'
Bittorrent )'+,
"%h Wireless Router 7*$C+$,(N"(
7*
:
(data communications) Wireless Router $C+$,(
8
lH
(Embedded Devices) 7*
8
:$
; :8#*!
:8
8%9$
)$"'# Wireless Router )'
$8 2-1 Wireless Router + ASUS WL-500g Premium
$8 2-1 $C+$,( Wireless Router + ASUS WL-500g Premium 8% 12.5W
7*!
P2P 7*
!$!%'
"( 7*
"($
, 250W +$,( Wireless Router *!$!%' 20 ! 95% "(
__________________________________________________________________
P2P File Sharing on OpenWRT
4
2.2
Firmware
Firmware 8$C7O((+$,(8$CK('( !
%
+$,(K('(
#
8 Microprocessor/micro-controller +
%h% *
87O(('
'% 7*+$,(
8 Firmware )' Hard disk, CD-ROM, Modem, Wireless Router
$C
Openwrt $C Linux distribution 8
Wireless Router #%
h%!)'
8$$+!+$,()'!!%
*# ADSL Modem, ADSL
Router, Wireless Hard disk )$:*
"( X86 $H+;E Openwrt )'
$F! Openwrt $C Distribution 8+$,(
lH 8+$,(+#8
Openwrt 7*%+$,(8
: Openwrt Wireless Router $C! 7*88#
ASUS(wl500g, wl500g-Deluxe, wl500g-Premium) +$,(!%"G ASUS $v"""+7($&';% source code
2.3
P2P (Peer-to-Peer)
P2P "' *#
!8!8 $ '(9 !''"
J 8 8$H I!
$ P2P "(8%"(N
!99%88# $C;;'8%
$H+99%8% P2P )'
8
Internet *# 99%88#%!;
:$8%
" %J
"( 8%%)''
%"*# ' Napster, Gnutella, Bittorrent Freenet 7*$C9$
$%+(8%
!; Internet ! $8%)O(
J!
"(7*)' 9'%)
$C
8
"(
% (Central Server) 7*
Client-Server 7*
8
"(
% (Server) %!"
% (Client) " )O(
'%8!N9'%)$ World Wide Web ( WWW )
)$8
8%9'%; Internet 7*$8%)'
% (Client) N7(
';
8
% (Web Server) 9'% 9$9 HTTP $C
z
8$';$C HTML 7*!$8%)$99%8%
Peer-to-Peer 8G,8$C Decentralization Client-Server 8
$C Centralization # P2P :)'$C 3 Pure P2P, Hybrid P2P,
Super Peer
__________________________________________________________________
P2P File Sharing on OpenWRT
5
Pure Peer-to-peer
9
' Pure P2P 8G,8
9
'F%(8+J8%(
:
"'$8%
)'9'%9'%)
;7"(O( +''9
'8#
:%%'%, (fault tolerant) 9'%:
88%(8%!)$
N)
;9'%
9
'8#N
8'8+
)!
)'%!
8$HI!'("}"#$ 9
'8#
8
$'h%8 8%(
:%)'9'%)
8 Authentication (9
'8# Authentication )'
%) :8
8%%)'9'%% 8%8
9
'
8#!9
'8#)
$C8"%
8
Hybrid Peer-to-Peer
9
' Hybrid P2P 8#
87"(O( 8!8+
%8%'
8%
h%%
$C'8%9
' Pure P2P (:*9'%) 9
'8#
%'$HI!'
8 )'%9
' Pure P2P 9'%7"(O( !8
%:+J8%( +
)!
%%
7"(O(%'#:7"(O( 8%)$N8%+
)$8%( N
%
:$8%
)'% 8+
8'8'#9
'8#*
8
:
%%'%)''89
' Pure P2P 88''%%%8
7"(O( 8)' 9
'8#
8 $"}" h8)$ $"J )
:)$$"8
8'$HI!!IJ)'
Super-Peer
9
' Super-Peer $C9
'!
8"'*#)
9'%$CF%()$
%% 9
' Super-Peer %'$"
,'7"(O( 8#
%"
:%%'
% '$HI!J8
"'*#9
' Pure P2P Hybrid P2P Super Peer 8%( 8!8!
$C7"(O(
!+
)(+
)(;}(#
Super Peer ,8 Super Peer 8%( N
:*'%% Pure P2P 9'% Super
Peer !8$C+
(controller),$ (configuration), ' (administration) G
$'h% (security) !)( 8%+
'# Super Peer 899
"'% 2 99 99"'! Super Peer )(
99"'! Super Peer Super Peer 9
' Super Peer 8
+''%''("}8!, !%
8
$C", :
+
')'%, : load balancing )'$C
__________________________________________________________________
P2P File Sharing on OpenWRT
6
2-1 78
9: P2P ;<8:
=
Network or
Protocol
Use
Applications
ANts P2P
File sharing/Software
distribution/Media distribution
ANts P2P
Ares
File sharing
Ares Galaxy, Warez P2P, KCeasy
BitTorrent
File sharing/Software
distribution/Media distribution
ABC, AllPeers, Vuze (formerly Azureus),
BitComet, BitLord, BitTornado, BitTorrent,
Burst!, Deluge, FlashGet, G3 Torrent, Halite,
KTorrent, LimeWire, MLDonkey, Opera,
Panthera, Ctorrent, QTorrent, rTorrent, Shareaza,
TorrentFlux, Transmission, Tribler, µTorrent,
Thunder
cGRID
Service-oriented peer
computing/Peer-based cloud
computing/Distributed data store/File Red Lambda cGRID
sharing/Software distribution/Media
distribution
Direct Connect
File sharing, chat
DC++, NeoModus Direct Connect, SababaDC,
BCDC++, RevConnect, fulDC, LDC++, CzDC,
McDC++, DCDM++, DDC++, iDC++, IceDC++,
Zion++, R2++, rmDC++, LinuxDC++, LanDC++,
ApexDC++, StrongDC++
eDonkey
File sharing
aMule, eDonkey2000 (discontinued), eMule,
eMule Plus, FlashGet, iMesh, Jubster, lMule,
__________________________________________________________________
P2P File Sharing on OpenWRT
7
MLDonkey, Morpheus, Panthera, Pruna, Shareaza,
FastTrack
File sharing
giFT, Grokster, iMesh (and its variants stripped of
adware including iMesh Light), Kazaa (and its
variants stripped of adware such as Kazaa Lite),
KCeasy, Mammoth, MLDonkey, Poisoned
Freenet
Distributed data store
Entropy (on its own network), Freenet
GNUnet
File sharing, chat
GNUnet, (GNUnet-gtk)
Gnutella
File sharing
Acquisition, BearShare, Cabos, FrostWire,
Gnucleus, Grokster, gtk-gnutella, iMesh, Kiwi
Alpha, LimeWire, MLDonkey, Morpheus, MP3
Rocket, Panthera, Poisoned, Shareaza, Swapper,
XoloX
Gnutella2
File sharing
Adagio, Gnucleus, Kiwi Alpha, MLDonkey,
Morpheus, Panthera, Shareaza, TrustyFiles
JXTA
Peer applications
Collanos Workplace (Teamwork software),
Sixearch
Kad Network
File sharing
aMule, eMule, MLDonkey
KDP and SDDP
File Distribution
Kontiki
Krawler
Social network
Krawler[x]
MANOLITO/MP2P File sharing
Blubster, Piolet
__________________________________________________________________
P2P File Sharing on OpenWRT
8
MFPnet
File sharing
amiciPhone (no longer available)
Napster
File sharing
Napigator, Napster
NeoEdge
File sharing
MostFun Game Player, NeoARM game delivery
OpenNap
File sharing
WinMX, Utatane, XNap, Napster
P2PTV
Video stream or file sharing
TVUPlayer, Joost, CoolStreaming, Cybersky-TV,
TVants, PPLive, LiveStation
PDTP
Streaming media or file sharing
PDTP
Peercasting
Multicasting streams
PeerCast, IceShare, FreeCast, Rawflow
Pichat
Chat, Collaboration
a peer-to-peer chat platform
Usenet
Distributed discussion
See list of news clients
WPNP
File sharing
WinMX
__________________________________________________________________
P2P File Sharing on OpenWRT
9
2.4
Bittorrent
Bittorrent "'$C#;! ;'8% 9'%)O(:
$CJ -)O(N8 7*)
"#8N)'
)'"# N''(9!')O(N
,(
!'(9!'"#)O( !"9!'"#8)'
!;
'% !'(9!')O(8#"
'%"')$%N$)7( 8!8$C
tracker 7*% tracker 8#N
)87"(O( torrent N$)7(8#
8%)O(
J )
% %N+ tracker )O(# 8
:
Bittorrent )' "'#9$
!')O( 8%9$
Torrent Client 7*
$H+
8!%9$
8!%hG :!%O(
)' $H+
8E
:+$,(8
8+$,( lH)'
Bittorrent
1.Torrent client $C9$
! bittorrent Bitcomet, BitTornado,
Azureus, Ctorrent, TorrentStorm ‡‡ 9$
#N
8
:8
;8%8%"
)$ 9'%#zN% Protocol Bittorrent '8% 7* Program
!8# '(9!' )O(9'% Protocol Torrent
2.Tracker server ! Tracker !8$C
%! Torrent client '%9'%
$"!8 N)O( .torrent
3.Torrent file)O(8#$C)O(8I !8N
!%%'(9!'
)O( '% Protocol torrent 8#)O(8#:9'% Torrent client 8+% 8%
Tracker, Check sum )O(8N)
__________________________________________________________________ 10
P2P File Sharing on OpenWRT
$8 2-2 ;h}"%9$
Bittorrent
$8 2-2 Tracker !8!8%(9'%$" Tracker )
8)O(
8ˆ)O(.torrent 8%(8%(! :$8%
)' 9'%
8#:+
8%(
NN%$C78''(%%"#)O()$%8%(
J)$
GH98;<8I78
9: Bittorrent
- Seeder
- Seed
- Leecher
-
Peer
Swamp
Tracker
Passkey
- Peer
- Ratio
!
%:* ;8)O($C !
!
%:* ; 8
8)O(
,(100% !;9!'
!
%:* ;9 !' :9!' 100% %)
$&' Nz%$C
Seeder )$8
!
%:* ;8
8"',#
!
%:* peer #!
' 8' (9!'%,#
!
%:* 8!8
)O(
!
%:* !$ )$9!' torrent !N tracker 8#
$C '')! $%)! !' Ratio
!
%:* ;8
8"',#
!
%:* 9!''(9!'
__________________________________________________________________ 11
P2P File Sharing on OpenWRT
2.5
Ctorrent
9$
Ctorrent , Enhanced-Ctorrent ($C8E
Ctorrent 7*)$8%
$C9$
Ctorrent) $C Torrent client !8''(9!')O( Bittorrent
E9'%hG C++ $C9$
'N Wireless Router )''
Wireless Router 8
8+,
"8' %
"(%
Memory CPU
Options Ctorrent
General Options
-x
'
)O( .torrent 8%%'8%)
'(9!'
-c
N"#)O(8%%'8%)
'(9!'
-v
!'(+(! debugging)
Downloading Options
-e int
$&'
seed 9
8!' (default 72 hours)
-E num
$&'!:* ratio 8!')
-i ip
!' IP ˆ8'(9!' (default all/any)
-p port
Port 8$C8 (default 2706 -> 2106)
-I ip
!' public/external IP address ! peer 8"'
-u num or URL $C announce (tracker) URL
-s filename
!'8N)O(8'(9!'
)' (save as)
-C cache_size ' cache, !%$C MB (default 16MB)
-b filename
+%8%' bitfield (default is torrent+".bf")
-M max_peers !' peers +' (default 100)
-m min_peers !' peers +' (default 1)
-z slice_size
!' block !%$C KB (default 16, max 128)
-n file_list
+%8%' )O(8'(9!'
-D rate
!' bandwidth '(9!' (unit KB/s)
-U rate
!' bandwidth 9!' (unit KB/s)
-P peer_id
7 Peer ID prefix. (default "-CD0301-")
-S host:port
CTCS server 9'%+ host:port 8 CTCS $&')
-d
Daemon mode ! background
-dd
Daemon mode ! background )
kill process $&'
(! +$,( Wireless Router)
__________________________________________________________________ 12
P2P File Sharing on OpenWRT
Creating a New Torrent Options
-t
)O( .torrent !
-s filename
!'%8%'!)O(
-u URL
Tracker's URL
-l piece_len
!'
%"# (default 262144)
-p
!' Private (disable peer exchange)
-c comment
$C comment/description !)O(
=P;<8
!' bandwidth down-up load !' ratio :* 1.5 N$&'
ctorrent -D 100 -U 10 -E 1.5 example.torrent
)O( .torrent
ctorrent -t -u "http://tracker.example.com:6969/announce" -s example.torrent file_or_dir_to_upload
2.6 Unix Command
$v"" (Operating System) +
8
+
Hardware software Application J "( OS G,
$C 2 1.Single-User $C OS 8,',!*!";8%'8% $C$v""
'N '+
DOS Windows95/98 ‡‡
2.Multi-User $C OS 8!;
!*)'
J 9'%$C
terminal %%J '!I $C OS 8)
%*'"''!* $C OS 8
$C Multi-user Multi-tasking Unix , Novell , Linux , SunOS ‡‡
I8 OS Multi User
I/O 'N
+$,(
"( * disk !
'; h! "#( '
'N
$C)O( (files) !
$C directory
Command 8!;"
(! "($
;
Time Sharing "!!
!%J !!%J 9$
8%E9$
Complier 8
8% OS linux N
8
hGJ C, C++ J8!%hG
__________________________________________________________________ 13
P2P File Sharing on OpenWRT
Unix Command S
cat
!'
8 %)O(
$ cat filename
head
!'
8%''
Option -n Num '
'8 1 :* n
-c Num ')()(8 1 :* n
$ head -[option] filename
pipe ( | )
;<8 pipe <7
= 2 P
% cat head ( | )
')O(8N:9$
Ctorrent
$ cat *.torrent | head -n 2 *.torrent
==> Alien_Arizona.torrent <==
- 3/2/14 [455/924/924] 443MB,31MB | 10,0K/s | 16,0K E:0,17
==> COMING_SOON.torrent <==
STOP
==> EagleEye.torrent <==
| 7/1/22 [285/2427/2427] 13MB,87MB | 15,12K/s | 16,15K E:0,1
==> IP_MAN_VCD.torrent <==
| 4/64/101 [144/2108/2108] 10MB,3MB | 3,2K/s | 0,0K E:0,1 Checking: 19%
==> SB_PeeThang2.torrent <==
STOP
ps
'%8%' Process PID ,UID, Command
$ ps
__________________________________________________________________ 14
P2P File Sharing on OpenWRT
grep
!
8)O(
$ grep file
% ps grep ( | ) ' PID 9$
Ctorrent 8%
$ ps | grep ctorrent
1559 root 4904 S
1765 root 4984 S
1919 root 4436 S
ctorrent /mnt/usbdrive/HDD/FT/Alien_Arizona.torrent
ctorrent /mnt/usbdrive/HDD/FT/COMING_SOON.torrent
ctorrent /mnt/usbdrive/HDD/FT/EagleEye.torrent
df
'+'8 mount '#8!%
$ df –h
Filesystem
tmpfs
tmpfs
/dev/mtdblock3
mini_fo:/jffs
/dev/sda1
Size
14.6M
512.0k
5.8M
1.3M
106.9G
Used Available Use% Mounted on
164.0k
14.5M
1% /tmp
0
512.0k
0% /dev
2.9M
2.9M 49% /jffs
1.3M
0 100% /
11.3G
90.0G 11% /mnt/usbdrive
free
'#8!%
!
$ free
Mem:
Swap:
Total:
total
29936
1502068
1532004
used
21076
0
21076
free
8860
1502068
1510928
shared
0
buffers
6656
__________________________________________________________________ 15
P2P File Sharing on OpenWRT
2.7
Shell Script !8#z Shell 9'%)$# User OS ! Load
Run Program J %)N
)'
8E! Shell 8
:$
;
J !G, Batch )' #8#99$
J ! Shell #
$'%$ ! h'
(Environment) 7*
8!9$
J
$
; $9%)J Profile !'$
;9$
J User Defined Function
!,8 Shell UNIX # 8% '%'!
! !
% semi-colon ;‘ ,88
8
%
()
h% 1 ') !
''%!
% ‘ "
(':')$ echo "Test"; ls;
echo "Hello world"
8% Comment Shell Script !
% #‘
#8#8%9$
8$ChG Script J Unix,Linux # '
+9$
8$
; Script #J )'%
#! /bin/ksh
#!/usr/bin/haserl
#!/usr/bin/webif-page
#! /usr/bin/perl
S
$* $8N("
(9$
#!
' 7*!
%:* $1 ... $9
$# N("
(#!
'
$$ N 979$
88%%$H+
$! N979$
!8%#!+'
$? N8:
9$
!8"N (Return Code)
$@ % $* N("
(9$
#!
'
== (Expression) =WX
int1 -eq int2 $C"
int1 int2
int1 -ge int2 $C"
int1 ! int2
int1 -gt int2 $C"
int1 int2
int1 -le int2 $C"
int1 %! int2
__________________________________________________________________ 16
P2P File Sharing on OpenWRT
int1 -lt int2 $C"
int1 % int2
int1 -ne int2 $C"
int1 )
int2
= String
str1 = str2 $C"
str1 !
str2
str1 != str2 $C"
str1 )
!
str2
str $C"
str )
$C null
-n str $C"
str 8
%
0
-z str $C"
str 8
%$C 0
= file
-d filename $C"
filename $C directory
-f filename $C"
filename $C file
-r filename $C"
filename )'9'%9$
-s filename $C"
filename 8')
$C 0
-w filename $C"
filename 8%)'9'%9$
-x filename $C"
filename run )'9'%9$
= Logical 7Z
! expr $C"
exp $CN
exp1 && exp2 $C"
exp1 exp2 $C"
exp1 || exp2 $C"
exp1 ! exp2 $C"
= Function
+'!% J !
shell script OH(!
$C shell script 8%
shell script 88!* OH( : ,88' J 7#%% J 8 8%#% J N!#
$C OH( 8%OH( #88
9
[function] fname {
(shell commands)
}
__________________________________________________________________ 17
P2P File Sharing on OpenWRT
2.8
Web interface OpenWrt
Web interface Openwrt $C interface +$,( Wireless Router !;"'
' !"'# Firmware :"
Web interface 7*)O(%8 www/cgibin/webif/ )O( .categories $C)O(!"
menu :)"
"
)'
##WEBIF:category:Info
##WEBIF:category:Graphs
##WEBIF:category:Status
##WEBIF:category:Log
##WEBIF:category:##WEBIF:category:System
##WEBIF:category:Network
##WEBIF:category:VPN
##WEBIF:category:##WEBIF:category:P2P
##WEBIF:category:##WEBIF:category:Logout
"
%%
9'%)O( .sh J
9)O( .sh %%
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh ## Import )O( webfi.sh !8%":*
header "
" "
%% " "@TR<< TEXT >>" ''
## ",88% Script
footer
?>
<!-##WEBIF:name:
:'
:
%%
-->
__________________________________________________________________ 18
P2P File Sharing on OpenWRT
E9'% webif 7*$C Shell script HTML )$:* java script shell script :8%)$ )O( .sh ",88% Script )':$C HTML $&' tax
HTML 9'%
8$ '8#
cat<<EOF
<HTML>
.
.
",8%hG HTML
.
<HTML>
EOF
Form 8 Summit 88)'
8 1 %8
2 $C"
% Form
empty "$FORM_submit" || {
SAVED=1
validate <<EOF
string|FORM_cre-del|@TR<<Create-Del>>|required min=1|$FORM_cre
string|FORM_user|@TR<<User>>|required min=3|$FORM_user
string|FORM_pw1|@TR<<Password>>|required min=3|$FORM_pw1
EOF
}
display_form <<EOF
start_form|@TR<<Create-Del User Password>>
field|@TR<<Create-Del>>:
select|cre
option|1|@TR<<Create>>
option|2|@TR<<Delete>>
field|@TR<<User>>:
text|user
field|@TR<<Password>>:
password|pw1
end_form
EOF
$8 2-3 % Form ! Summit $ 2-3 $C Form Summit ! User Password
__________________________________________________________________ 19
P2P File Sharing on OpenWRT
3
3.1
E web interface wireless router )$HI!'"
wireless router
'"
;$C"'#9$
"
8$C interface 8!"'
9$
client bittorrent router 7*
;:*9$
client bittorrent
"(J8)
)'"'#9$
interface 8#!)
::*)'
"'
)
'*#
$HI!')'
8E Web interface ) router !"'
'
8%9$
client bittorrent "()!N)'
$8 3-1 9'% user
$8 3-1 User P2P Wireless Router 9'%; Web interface 8
"'# Router 9'% 9'%)
"'#9$
"
3.2
;8$C admin :8%9$
bittorrent +
'9$
!'J ,9$
:9$
admin :
!'"}"ž)O( user, password ()O(9'% samba server
;8$C user )$ 8"}"ž8)O(# 9'% user, password 8
)' admin %%)O(
"}"ž8 admin !')
__________________________________________________________________ 20
P2P File Sharing on OpenWRT
$8 3-2 h
(
$8 3-2 ;
8$h N admin User ;)$ 9'% admin !89$
bittorrent '"}"ž:* User :
()O(#
3.3
Web interface *:*
'; 7*$C+
#z
bittorrent !'"
'(9!' +
'
9$
:9$
')O(
"I
:()' +,
"(
8' CPU Memory 8
8'N ';O&
8;( '#
*:* 8;%)'
Web interface )'!')#!
' 4 !%% $'%
! About, Download, Status, Storage 7*
8%8%''8#
__________________________________________________________________ 21
P2P File Sharing on OpenWRT
3.3.1 I8 About
! About $C!!'%8%'8% 9$
;'9'%
8
"()$% web site ! account !:*)O(8()'%
samba server
$8 3-3 ;h
" '! About
$8 3-3 ! About !'%8%' ;' 9$
9'% link )$% web site 8 function !
Account ! Samba Server 9'%;8$C Admin 8
:8#)'
__________________________________________________________________ 22
P2P File Sharing on OpenWRT
3.3.2 I8 Download
! Download !!'"
!9$
Ctorrent "
'(9!'
$8 3-4 ;h
"'! Download
$8 3-4 !!'(9!'! !'"
'(9!')O( 8N)O(
N
( !%+'
:*9 !8!' :
:!9$
Ctorrent )' 9$
8(+ 2 %
)O(: 7*$C
:)O(8'(9!' %8 2 )O(
9'%N)O('
8)'!'"
__________________________________________________________________ 23
P2P File Sharing on OpenWRT
3.3.3 I8 Status
! Status ! 8!':9$
+
)O(
$8 3-5 ;h
"'! Status
$8 3-5 ! Status !':9$
+
)O( 8 function !I 3 function $'% 1 !%+' !!)O(
8!%+'9'%)$ kill process 9$
Ctorrent 9$
)'II, kill
process "')$% web tracker %%!%+'" !#)O(8
!%+'N:)$8)O(:';!N$)$ function 8 2 "
!
!!)O(8
8:!%+'!"
!
8"
!
8%O&)O()O(.torrent 8 7*O&)O(#$C
!'
"
"
'(9!'!9$
Ctorrent 9$
*#7*N:
'8%"
'(9!'# function 8 3 7*
:)O(%)'
)O(
)O(.torrent !#% !%'%!* !#N)$ update )O(
:
__________________________________________________________________ 24
P2P File Sharing on OpenWRT
3.3.4 I8 Storage
! Storage !8'
Hard disk ')O(
$8 3-6 ;h
"'! Storage
$8 3-6 $C;h
"'! Storage $C'
Hard disk '
+ $(7N(! mount )$$C
')O( 7*$'%%% 4 1 $&')O(!)'8 2
))O( ,88)O('
:))' txt )O($C )$'(9!')O(
7*
:'(9!')$N)
"( +'%$C)O()'8
__________________________________________________________________ 25
P2P File Sharing on OpenWRT
3.4
Memory
Memory '#'"
Firmware ;;""'$HI! Memory
'% wireless router 8 Memory 'N
9$
!%J9$
'8%
"'$HI!' Memory 7*)
8%
8;! router K()
:+J)' Firmware ;;")
$C Open source !)
:)
$HI!')' *)'"'# Firmware 8$C Open source 8
:E)
)'
)$HI!8"'*#9'% Linux swap $C Memory '
Memory (!9$
!
'!!
' swap !8$8%
Memory !( 7*
:'!9$
)'%8%
$8 3-7 ;h
"'' Memory
$8 3-7 9$
!%9$
!9$
Memory $C"FG,8N
:)O( ' Memory !
(!
'!!
' 8% Swap 7*$C Memory !
9$
8 7*$HI!' Memory )'
__________________________________________________________________ 26
P2P File Sharing on OpenWRT
Swap 9'% Partitions Hard disk !$C Linux swap !#"'#
Package !' Swap $&' Swap 9'% swapon‘
%8%'"'#%h;
__________________________________________________________________ 27
P2P File Sharing on OpenWRT
4 8#'8#
4.1 8bSI
Client Bittorrent
'%9$
Client bittorrent 8"'#
Wireless router ;;"
8'%
!%$ 9'%
$HI!8%$)$'% $HI!';;"'' N'(9!' )O(8'(9!')'8%!%)
:)' :"#)O( :"'8%(
$HI!'*)'$8%9$
Client bittorrent Wireless router !
)
:$8%9$
)'8'"
)
$C Open Source '#$C
$8% Firmware !
9'% Openwrt 7* Wireless router + wl-500gp
9$
Enhanced Ctorrent $C9$
88%'%hG C++ 8'N
:)' router +,
"9$
8#8'"
8%!%8"'
)O( :"'8%('"
!9$
"(
9$
N'(9!' :"#)O(
% '9$
)O(' 2 GB 9$
Ctorrent $
, 15-20 8 9$
'"
$
, 30-40 8
9$
Ctorrent 8%'%hG C++ 8'N)
77*$C
;'8
7* Wireless router +8#
8 CPU 8% 266 MHz *)
;
router
$8 4-1 CPU ,
$8 4-2 CPU ,9$
__________________________________________________________________ 28
P2P File Sharing on OpenWRT
$8 4-1 'O CPU ,9'%ˆ8% CPU $
,
13% 9$
Ctorrent ,'(9!')O( 9 )O('8% O $8 4-2 ˆ8% CPU $
, 22% 7*"
'"
N%*)
8;9'%
4.1.1 c:;<8
Ctorrent
"'#9$
"
'%'(9!' Package ,88 Wireless Router )
:
! Package )' *$C! Package 7*
:!
http://downloads.x-wrt.org/xwrt/kamikaze/snapshots/brcm47xx-2.6/packages/ctorrent_dnh3.3.2-1_mipsel.ipk
!'(9!'9!')$% Wireless Router
% (,8#%8 Terminal "()
rcp File_name.xxx root@IP_router:/Part_to_Save
:~# rcp ctorrent_dnh3.3.2-1_mipsel.ipk [email protected]:/mnt/usbdrive/HDD
9$
Enhanced Ctorrent 8#F% library openssl uclbcxx 9$
7*
:!)'
http://downloads.x-wrt.org/xwrt/kamikaze/snapshots/brcm47xx-2.6/packages/ctorrent-openssl_dnh3.3-1_mipsel.ipk
http://downloads.x-wrt.org/xwrt/kamikaze/snapshots/brcm47xx-2.6/packages/uclibcxx_0.2.2-1_mipsel.ipk
"'# package
ipkg install [package_name]
:~# ipkg install uclibcxx_0.2.2-1_mipsel.ipk
:~# ipkg install ctorrent-openssl_dnh3.3-1_mipsel.ipk
:~# ipkg install ctorrent_dnh3.3.2-1_mipsel.ipk
9'%$"9$
8"'# router %8 /usr/bin/ "'#9$
Ctorrent N ! )
9 '%')O(9 '% )$8# : : ' '
9$
# ls -la -h /usr/bin/ctorrent
-rwxr-xr-x
1 root
root
235.1k Sep 10 2008 /usr/bin/ctorrent
9$
Ctorrent Wireless Router # Background
)
Terminate !$&' Terminal (,8; Command line) $" __________________________________________________________________ 29
P2P File Sharing on OpenWRT
ctorrent file.torrent
$&' Terminal 8 signal (hang-up) )$ kill process 8%!)
:%
)' 9$
Enhanced Ctorrent 8 Option ' background 9'%
9$
'8#
ctorrent –dd
file.torrent
'!9$
:)' !9$
)
Signal (hang-up) 'N$&' Terminal !%+'
;)$ 10
9
Process 9$
ctorrent %%!
'"
$8 4-3 Process 9$
ctorrent
option dd '$8 4-3 9$
ctorrent ! background %:
9'%)
signal (hang-up) $C$9$
)
!%+'9$
N
__________________________________________________________________ 30
P2P File Sharing on OpenWRT
4.2 Hd Web interface Wireless router
'"
Router !'(9!' bittorrent "'#9$
download
master "($C interface "'9$
bittorrent 7*)
'
,8
"(8)
)'"'#9$
download master E Web interface Wireless router "
' ;
:
"('N)'8
::* router )'9'% Web
browser $&'7*)' Web interface 8#!
' 4 !$'%
I8 1 About‘
$C!!'%8%'J)$8 ;' %8%'
9$
Enhanced Ctorrent web interface admin :8 User Password ! User )$!:*)O(8()9'% samba server
$8 4-4 !'
9$
;' $8 4-4 Form 8 Summit $C option "
G Password G, Password $&'G '$C
link )$%
9$
Ctorrent Web interface
__________________________________________________________________ 31
P2P File Sharing on OpenWRT
I8 2 eDownloadf
Interface "
$C8!"
!9$
Ctorrent
9'%)'!
8'8#
- '%)O(.torrent 9'% list % directory 8
N)O(.torrent ( !;(
8)O()%
- submit J )O()O(OP
,*OP
8 (save as) ,
#!' ratio seed ,(,
N
$8 4-5 !%'(9!'
$ 4-5 !!'"
"
9$
'(9!' 9'%;
!:
"ˆ#)
:'(9!')' 7*"}8J%
*"
'(9!'
$8 4-6 )
8)O(
__________________________________________________________________ 32
P2P File Sharing on OpenWRT
$8 4-6 ,88$%! )O(OP
%‘ $C
$P)
!"'
;"''"
) 9'%)'!'
$C'
Error! +,%)
)')O( +,)O(% ‘
!!%+'#:')$
$8 4-7 )O()
:
$8 4-7 ,88)O()
: )
8)O(% '
Error ! +,)O()
: : )
8)O(% ‘ $P
"!9$
;"'')
8)O()
:'(9!')'
$8 4-8 %:
$8 4-8 )O(%)': !'"
!9$
'$+¡
Save Changes ‘ '
+,)')O()': !‘ Script )!'(9!' ''' command '$+¡
"( Download‘
"
__________________________________________________________________ 33
P2P File Sharing on OpenWRT
$8 4-9 !'(9!'
$8 4-9 %)': 9$
N
:)' '
%8%'J)O(8'(9!' ;"
8N'$+¡
)$%!
%8#!*
%)
: N)
'(9!' '
Error! +,%)
:!‘ ;)$%!
'$+¡
)$%
!%8#!*
$8 4-10 %)
:
"'*#
;
;"'' )
!$P
;"''8"'*#)' '$8 4-10 $C
;"''!
'(9!' )$!!''(9!'%8#
__________________________________________________________________ 34
P2P File Sharing on OpenWRT
I8 3 Status‘
$C!!':)O( .torrent )O( %
!!%+' )O(8
8
8% Seed ,Peer 8%,Peer
#!
' "#)O(8'(9!'
)' "##!
' N'(9!',
9!' $C ;
:'8%)O( .torrent 8#!
' 6 !%+' "
8 # )O(.torrent )O(.torrent
% '8% '
%8%')O(.torrent
$8 4-11 ! Status
$8 4-11 '%8%')O( 7*)O(8'%'(9!'#
;!'"
'(9!'
)O(%
)O(8!
8$C)O('8%%OP
7*
;)O(%
'(9!' )O(N)O(#)$'% $P;"''8%
)O(8;"'
)O( .torrent !'%8%' 8%9$
ctorrent )O(8) 9'%'%8%')O(8IJ '
)O(
)O( %)O( $C
__________________________________________________________________ 35
P2P File Sharing on OpenWRT
$8 4-12 !'%8%')O( .torrent
)O(.torrent )O($)$'%%8%'J8)'+) 8'
#)'9$
bittorrent $&')' '$8 4-12 $C$&'9'%
9$
Ctorrent '(+
%
% Web interface
I8 4 File Storage‘
File Storage $C!)!8%'
:*) '(9!')$N
"(! )O(
8)'
9!' torrent 9'%$'"
Firmware File Editor $$+"
"
9'% script ! '%8%' Hard
disk ' 8 8!
$8 4-13 ! File Storage
$8 4-13 )'"
function !': hard disk 7*$C
O&7*$CO&'N*)
8;
__________________________________________________________________ 36
P2P File Sharing on OpenWRT
4.3 8bSI;<8 Memory
Wireless router 8
8' Memory 32MB 9$
!%9$
;!' Memory )
8%$HI!8"'*# "'K( (7*
'"
)
:$HI!8#)' ;+
"!9$
8
J
!!
:"#)O(
"!" 1 )O($P
Memory "'8
8 router
$HI!
)
:8% *)'
8"'"
Memory '%'"
)
$C Open source *$8%
$C Open source :8'+
')'
$HI!8
8+'8! Memory )
8% ,9$
Ctorrent :"#)O( ;
! (
"(
')O( Hard disk (
N
"( !
"()$%
(
Openwrt $C Firmware "' Linux 7*
:+,
" Swap
$C Memory 8+'!*)'9'% Partition Hard disk 8 Mount )(
! Linux Swap 7*')
% 512MB )
:)'8
()
8
:' Swap '# Package "
' Swap
!#$&' Swap 9'% swapon :9'%
free ' Memory ::'' Swap *#
' Swap 9'%!9$
Ctorrent N)O(
# 2
)O(*#)$!9$
Memory " 32 MB (: Swap )' 9'%
free !N' Swap 8
$8 4-14 free ' Memory
__________________________________________________________________ 37
P2P File Sharing on OpenWRT
$8 4-14 free !N' Swap 8 8% Swap 8$C Memory (!
'!!
' !N)''
Memory $
, 30 MB !$
, 1MB Swap $¢
8)$ 208
Bytes
;' Swap Memory $v
8 Memory ' Memory Swap '#$HI!8"''
Memory N!
')$ )''9'%9$
Ctorrent N)O( 5 )O(
'8%$v : )'N
,(+ )O( 9'%)
"'K(
N
__________________________________________________________________ 38
P2P File Sharing on OpenWRT
5 5.1 :
• "'# 9$
Enhanced ctorrent :"'#; Web
interface )'%
,(
• "
!9$
Enhanced ctorrent ; web interface : !'"
!9$
!9$
)'%:
• ''(9!' 9 )O('8% $8%8%
CPU $v "
*#'"
N%*)
;9'%
+$,( Wireless router
• ')O(8%%'(9!' :
+
#!
' 6 $'% !%+' "
!
)O(.torrent %'(9!' )O( .torrent 8 % % '8 % '%8 % ' )O(.torrent 7*"
'
'"
• $HI!' Memory 9'% Linux Swap $C Memory "
8
8%
router ;!' Memory 8$"}"h
*# $HI!' Memory ;
+$,( Wireless )
"'K(
8 Memory 8"'
5.2 bSI:
• $HI! Firmware : Firmware 8
+'!$HI!
Package Package 8)
: "}8)9'% Firmware 8
8
Package • 8#!I Shell Script '#
;'
!
;" ' ')' ! 9 $
% )
;!
Wireless Router K()'
• $HI!8I+$,( Wireless Router ,"'# Firmware !
:"')O
!)O'! Hard ware +$,(8%!%)' "}8$HI!'9'%
)O+#
__________________________________________________________________ 39
P2P File Sharing on OpenWRT
5.3 8
• Web interface #
Shell Script '#;8E
F*G Shell Script • Package 8
8 8 Stable Unstable 8 Stable 7*
!
8
:8%
*#
• "'# Firmware !
; "' # Version Firmware Firmware !
#
:)'+$,( :"'
;"''8%!%:* Hare ware )'
__________________________________________________________________ 40
P2P File Sharing on OpenWRT
,+
Internet Resources:
[1]
BuildingPackagesHowTo ,http://wiki.openwrt.org/BuildingPackagesHowTo,
2006-08-26
[2]
Html And Shell Embedded Report Language, http://haserl.sourceforge. net/
haserl.html , 2006-07-13
[3]
Kitipong tota, http://www.jobpub.com/articles/showarticle.asp?id=89,
unknown,unknown
[4]
OpenTLE wiki, http://wiki.opentle.org, unknown, 2007-6-19.
[5]
OpenWrtBuildroot,http://downloads.openwrt.org/docs/buildrootdocume
ntation.html ,2006-07-12
[6]
Peoplebu,http://people.bu.edu/ebishop/openwrt-programming,unknown,20081-5
[7]
Radvd , http://www.linuxcommand.org/man_pages/radvd8.html , 2006-06-26
[8]
Ruhul, http://www.rahul.net/dholmes/ctorrent/ctcs.html, unknown, 2007-1125.
[9]
Sourceforge, http://ctorrent.sourceforge.net/, 2006-06-07, 2007-11-29.
[10]
TableOfHardware , http://wiki.openwrt.org/TableOfHardware , 2005-06-20
[11]
Wigi,http://wiki.x-wrt.org/index.php/Programmer's_Guide_to_the_Webif,
unknown,2008-1-9
__________________________________________________________________ 41
P2P File Sharing on OpenWRT
h;
__________________________________________________________________ 42
P2P File Sharing on OpenWRT
1. Firmware
#8; Openwrt firmware !
9'% firmware
8
:)'
8%!%( 98# Openwrt + OpenWrt Kamikaze With X-Wrt (7.09) 9'%( 8#( 2.6.23.17 ! firmware 8*#%
+)
99$77(8 %h%+$,( "}8 firmware +
:')'
http://toh.openwrt.org 9'%"}8 firmware :)' 5 "}8 1. firmware 9'% web interface 8
+$,(
2. firmware 9'%9$
8
;;"
3. firmware 9'% tftp
4. firmware 9'%; Bootloader(serial port)
5. firmware 9'% JTAG(hardware debugger)
9'%! Firmware 9'%"}88 3 tftp '$C"}88
)';
8+' + firmware 8)
firmware ;;" '%"}88 1
2 )
:)' "}88 4 ;N$C$&'+$,(
hardware "
7*)
'!;"
9'%88#;8%:*ˆ%
firmware wireless router + wl500gp 7*
8#'8#
1. 9!
' Failure 9'%:'%)O8#%,88)O8#%%
2. '$+¡
Reset ($+¡
8%J%)O8#%) ) 8%%)O8#%,8$+¡
reset
:'%
3. ' Reset )$
, 3 "8 !)O': PWR "
"J
4. Ping )$8 IP address wireless router ')'9!
' Failure "
: ping )
)' !!
##
5. Firmware )$8 wireless router 9'%7*
8#'8#
,8$v"" Linux
-
tftp 192.168.1.1 (,8I
8 P address wireless router $C
192.168.1.1 )
binary
trace
put openwrt-brcm47xx-2.6-squashfs.trx
9'%
:'(9!'
http://downloads.openwrt.org/kamikaze/7.09/brcm47xx-2.6/openwrt-brcm47xx-2.6squashfs.trx
__________________________________________________________________ 43
P2P File Sharing on OpenWRT
firmware N wireless router 8£9
" : wireless router
)
8£!$
, 5 8 %:')O8#%8%!
:)
8);"'';
:+$,($%)'9'% telnet 8#)$8 IP address +$,($%
( firmware !I!#!
'$&' telnet )) 7* IP address !"
+$,( 7*%
!8+$,( $C 192.168.1.1 telnet "}88) ;)'! terminal +$,(
:) IP
address $C%)'! IP address default +$,(
$8 1 ! OpenWrt ; SSH
!"'# Firmware 8%% :9$
Secure Shell '$8 1
$'h%9'%;9$
telnet
7*8#;
:$$8%9$
J+$,()' :
telnet %)
$'h% 9'% telnet )
8 authentication )
8
!
!;:*+$,(;)' ;8%*!$8%
telnet $C secure shell(SSH) 7*
8 authentication !
7*)'
9'%# password 9'% passwd !# password ;)
:"'
+$,(; telnet )'8 secure shell 7*
:
)'9'% ssh 8#)$8 IP address +$,( $v!!"
( user password 9'% user !$C root password ! password 8!'9'% passwd $PNN)'! terminal %8 telnet 8#;
:
)$$$8%J+$,(; browser Mozilla Firefox ! Internet
__________________________________________________________________ 44
P2P File Sharing on OpenWRT
Explorer )' IP address +$,(8 URL browser $v web interface
*#
$8 2 ! OpenWrt ; Web interface
$8 2 firm ware ,(
: router 9'%; Web interface
)'
2. 9$
! kernel module (package)
9$
! kernel module "
"
! Openwrt 8%
apt-get 9'% ipkg 7*:+$,(% internet % :)'9'%
ipkg install '% package 8 :9$
vsftpd N"
(
ipkg install vsftpd 9'%)89$
ipkg N9$
ipkg )$8%9$
wget !)$9!')O(7"(O(8 http://openwrt.org 88!* 9$
$(9$
!$C(+' 9'% ipkg update ;
:' package 8
: download )'9'% ipkg list ,88+$,()
)'%
% internet ! ipkg install ./ '% package 9'%,88#;
$C download package http://downloads.x-wrt.org/xwrt/kamikaze/snapshots/brcm47xx/packages 8
"( 7* package 8 suffix $C .ipk !#* package '
)$8+$,($%9'% ftp 88!*
% ipkg package
ipkg install package_name.ipk
__________________________________________________________________ 45
P2P File Sharing on OpenWRT
3. Partition
'(9!'
'!I9'% Wireless router $C
88N
* USB Hard disk $C8N9'%
8# Partition '8#
Partition $C 2 Linux Ext3 !N
8$C)O( Linux
Swap $C8 Memory ,89$
PartitionMagic 8.0 )'G,')$8#
$8 3 Partition Ext3 Swap
$8 3 )! Wireless router $C Openwrt 2
Partitions !N
$C Memory 3.1 Partition !N
storage N
# Partition 8$C Linux Ext3 9'%;
package "
"
!
: Openwrt ; USP Port )'
"'# package ! storage
ipkg install kmod-usb-storage kmod-usb-core kmod-usb2 kmod-fsvfat kmod-fs-ext3
! package N"# reboot router start *#8# mount
storage 9'%9
"
3.2 Swap
9$
memory memory 8
8% wireless router 9'% Swap
8#$CI$C8 Memory Hard disk
"'# Swap
ipkg install swap-utils
!"'#NN%)
:)'8*$&' Swap 9'%')$8#
swapon /dev/sda2 (,88 sda2 $C partition swap)
__________________________________________________________________ 46
P2P File Sharing on OpenWRT
swap :)'!)
9'%')$8#
:~# free
Mem:
Swap:
Total:
total
29936
1502068
1532004
used
28816
120
28936
free
1120
1501948
1503068
shared
0
buffers
912
$8 4 free 8%' Memory
$8 4 : Swap $v'#!
' 8!'
:
)'''
4. Samba configuration
Samba $C 7O( ( 8 %! :( ) O( " ( " + 7( ! $v"""9'( 95, 98, 2000, NT # smbclient Linux, UNIX J )' Samba $)$'%$!J '8#
• smbd $C daemon 8%()O("
(! smbclient J 9'%
8
)O( configuration 8I /etc/samba/smb.conf 7*!8+
Smbd
• nmbd ;"'88% name resolution browsing service 7*
8% NetBIOS name
• smbclient $C9$
8!8
)$% Samba server ! Microsoft Windows
8)'()O() 9'%
8G,!
ftp
• smbmount ! mount )$% shared directory
• testparm $C9$
8 configuration )O( /etc/samba/smb.conf :!)
• smbstatus !' status Smbd
$8 5 ()O( Samba server
$8 5 Samba Server :!"()O("
( 9'%
:)' 9'%$"#
__________________________________________________________________ 47
P2P File Sharing on OpenWRT
: samba Openwrt
samba Openwrt !
"'#9$
! package 9'%)$ 9'%
98#)' samba version 3 9'% :'(9!')'
http://downloads.openwrt.org/snapshots/brcm47xx/packages
"'# samba
ipkg install samba3
9'%)$)O( Configuration samba :N)8 /etc/samba/smb.conf )O(8#
$C+
# !
' samba '#)'J *'%
' !"'
;"''!"')!
)' +I
!;
:)'9'%)
username password
Authentication Security
Samba ()O(!"
(!;)
+I! guest ;
%% Samba 7* Samba 8"}8%%;$
security 7*
:)' 4 '8#
1. security = share : samba client !!;%'8%# '#!
;!;;'!*N
N
:)'
2. security = user : samba client ! username !;
; 7*,88#!
!;8$v"""9'( NT/2000
$C client username !;$C+''8%8 Samba server
3. security = server : 8$% user 8% Samba server SMB server $C!8 username !;
4. security = domain : Samba :$C
" Windows Domain )' '#
;
%% primary domain controller (PDC) N
:(8
% Samba server )' ($C+,
"%!*9'
)
Passwords
8;
::*)'8!"
(8())'# ;
8 Unix
account 7"(O(8!" Samba 8% 9'%$" Samba +
;#8
8! (Encrypted) )
8! (Non-encrypted) 9'%
#
encrypt passwords = [yes|no]
__________________________________________________________________ 48
P2P File Sharing on OpenWRT
9'%!
8$C no Samba !;( username) )O(
/etc/passwd !
8$C yes Samba !;( username) )O(
/etc/samba/smbpasswd #8#!)O( /etc/samba/smbpasswd )
8%" N!)
8;
%'
:(#!
')'
% Configuration samba
[global]
netbios name = openwrt
workgroup = openwrt
server string = openwrt
syslog = 10
encrypt passwords = true
passdb backend = smbpasswd
obey pam restrictions = yes
socket options = TCP_NODELAY
unix charset = UTF-8
display charset = UTF-8
dos charset = 866
preferred master = yes
os level = 20
security = user
guest account = nobody
invalid users = root
smb passwd file = /etc/samba/smbpasswd
[P2P]
comment = P2P FileSharing on OpenWRT
path = /mnt/usbdrive/HDD/
read only = no
guest ok = no
create mask = 0750
directory mask = 0750
writable = yes
[homes]
comment = Home Directories
browseable = no
read only = no
create mode = 0750
[tmp]
path = /tmp
read only = no
guest ok = no
create mask = 0700
directory mask = 0700
8% samba
samba
start
stop
restart
reload
enable
disable
Start the service
Stop the service
Restart the service
Reload configuration files
Enable service autostart
Disable service autostart
__________________________________________________________________ 49
P2P File Sharing on OpenWRT
=;<8jk:W samba sharing
$8 6 8% director 8( samba
$8 6 ;
::*()O( 9'%#$&'
"( 9'%
"
( IP router 8% User name Password #:')$
$8 7 User name Password
$8 7 :+$,(8!"()O(%"N*# Interface ! User
name Password 9'% account $F9'%;'
$8 8 ' directory 8(9'% samba
Account :;
::*()O()' '$8 8 :*
)O()'ˆ"}"ž:*#
__________________________________________________________________ 50
P2P File Sharing on OpenWRT
5. Code
Code ! About
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "P2P" "About" "<img src=\"/images/abt.jpg\" alt=\"@TR<<P2P File Sharing On
OpenWRT>>\" />@TR<<P2P File Sharing On OpenWRT>>" '' "$SCRIPT_NAME" ?>
<?
##########################################################################
empty "$FORM_submit" || {
SAVED=1
validate <<EOF
string|FORM_cre-del|@TR<<Create-Del>>|required min=1|$FORM_cre
string|FORM_user|@TR<<User>>|required min=3|$FORM_user
string|FORM_pw1|@TR<<Password>>|required min=3|$FORM_pw1
EOF
}
display_form <<EOF
start_form|@TR<<Create-Del User Password>>
field|@TR<<Create-Del>>:
select|cre
option|1|@TR<<Create>>
option|2|@TR<<Delete>>
field|@TR<<User>>:
text|user
field|@TR<<Password>>:
password|pw1
end_form
EOF
if test $FORM_cre -eq 1;
then
echo "$FORM_user:*:65534:65534:$FORM_user:/var:/bin/false">>/etc/passwd
echo "$FORM_user:*:65534:65534:$FORM_user:/var:/bin/false">>/etc/passwdsmbpasswd $FORM_user $FORM_pw1
echo "Creating User $FORM_user successfully"
fi
if test $FORM_cre -eq 2;
then
smbpasswd -del $FORM_user
fi
##########################################################################
?>
<script src="/js/scrollbox.js" type="text/javascript"></script>
<h2><a
href="http://www.x-wrt.org">@TR<<X-Wrt
Extensions>></a>
webif&sup2;</h2>
<div
id="outerscrollBox"
onMouseOut="copyspeed=marqueespeed">
&ndash;
onMouseOver="copyspeed=pausespeed"
<div id="scrollBox">
<h1>@TR<<Web Interface for Enhanced Ctorrent>></h1>
<h2>@TR<<Contributing Developers>></h2>
<ul>
<li><a href="mailto:[email protected]">CHALOEMPON PATMANEE</a></li>
<h2>@TR<<About Enhanced Ctorrent>></h2>
<li><a
href="http://www.rahul.net/dholmes/ctorrent/">About
Enhanced
Ctorrent</a></li>
<li><a
href="http://www.rahul.net/dholmes/ctorrent/userguide.html">Enhanced
Ctorrent User's Guide </a></li>
__________________________________________________________________ 51
P2P File Sharing on OpenWRT
</ul>
</div></div> <!-- End scrollBox -->
<? footer ?>
<!-##WEBIF:name:P2P:1:About
-->
Code ! Download
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "P2P" "Download" "<img src=\"/images/bkup.jpg\" alt=\"@TR<< Download>>\"
/>@TR<< Download>>" '' "$SCRIPT_NAME" ?>
<?
cd ~
cd ..
cd /mnt/usbdrive/HDD/FT
ls *.torrent > /tmp/list_file.txt
rm /www/cgi-bin/webif/p2p-Download2.sh
rm /www/cgi-bin/webif/p2p-make_dir.sh
rm /www/cgi-bin/webif/info_bit.sh
display_form <<EOF
start_form|@TR<<'(9!'>>
end_form
EOF
?>
<html>
</TABLE>
<table border="2" cellpadding="1" bordercolor="#008000" width="37%" height="30">
<TR > <TH ><pre ><b> OP
% </b></pre></TR>
<table border="1" cellpadding="1" bordercolor="#008000" width="37%" height="50">
<TR > <TH ><pre ><? cat /tmp/list_file.txt ?></pre></TR>
</TABLE>
<br>
</html>
<?
empty "$FORM_submit" || {
SAVED=1
validate <<EOF
string|FORM_file_torrent|@TR<<File.torrent>>|required min=1|$FORM_file_torrent
string|FORM_stor|@TR<<stor>>|required min=1|$FORM_stor
string|FORM_Exit_while_Seed_hours|@TR<<Exit_while_Seed_hours>>|required
min=1|$FORM_Exit_while_Seed_hours
string|FORM_Exit_while_Seed_ratio|@TR<<Exit_while_Seed_ratio>>|required
min=1|$FORM_Exit_while_Seed_ratio
string|FORM_Exit_Port|@TR<<Exit_Port>>|required min=1|$FORM_Port
string|FORM_Rate_down|@TR<<Rate_down>>|required min=1|$FORM_Rate_down
string|FORM_Rate_up|@TR<<Rate_up>>|required min=1|$FORM_Rate_up
EOF
if test -z $FORM_file_torrent;
then
cat<<EOF
<html>
<b><FONT COLOR="RED">Error! +,%)
)')O( +,)O(%</b></FONT></br>
</html>
EOF
else
test -s /mnt/usbdrive/HDD/FT/$FORM_file_torrent;a=$?
if test $a -eq 0 ;
then
echo "+,)')O("
echo $FORM_file_torrent ":!"
__________________________________________________________________ 52
P2P File Sharing on OpenWRT
echo "ctorrent /mnt/usbdrive/HDD/FT/$FORM_file_torrent "'\'>/www/cgi-bin/webif/p2pDownload2.sh
echo "CONFIG INFO">/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
echo
"FILE
:
$FORM_file_torrent
">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
chmod 775 /www/cgi-bin/webif/p2p-Download2.sh
echo "mkdir $FORM_stor/$FORM_file_torrent">/www/cgi-bin/webif/p2p-make_dir.sh
chmod 775 /www/cgi-bin/webif/p2p-make_dir.sh
chmod 775 /mnt/usbdrive/control_torrent/tmp/config/*
cd /www/cgi-bin/webif/
./p2p-make_dir.sh
cd /mnt/usbdrive/HDD/FT
echo
"SAVE
AS
:
$FORM_stor">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
if test -z $FORM_Exit_while_Seed_hours;
then echo;
else echo "-e $FORM_Exit_while_Seed_hours "'\'>>/www/cgi-bin/webif/p2pDownload2.sh
echo
"SEED
EXIT
:
$FORM_Exit_while_Seed_hours
hr.">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
fi
if test -z $FORM_Exit_while_Seed_ratio;
then echo;
else echo "-E $FORM_Exit_while_Seed_ratio "'\'>>/www/cgi-bin/webif/p2pDownload2.sh
echo
"SEED
EXIT
RATIO
:
$FORM_Exit_while_Seed_ratio
">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
fi
if test -z $FORM_Port;
then echo;
else echo "-p $FORM_Port "'\'>>/www/cgi-bin/webif/p2p-Download2.sh
echo "PORT : $FORM_Port ">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
fi
if test -z $FORM_Rate_down;
then echo;
else echo "-D $FORM_Rate_down "'\'>>/www/cgi-bin/webif/p2p-Download2.sh
echo
"RATE
DOWNL
:
$FORM_Rate_down
KB/s">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
fi
if test -z $FORM_Rate_up;
then echo;
else echo "-U $FORM_Rate_up "'\'>>/www/cgi-bin/webif/p2p-Download2.sh
echo
"RATE
UPL
:
$FORM_Rate_up
KB/s">>/mnt/usbdrive/control_torrent/tmp/config/$FORM_file_torrent
fi
echo "-s $FORM_stor/$FORM_file_torrent -dd">>/www/cgi-bin/webif/p2p-Download2.sh
echo 'b=$(($$ + 3))'>>/www/cgi-bin/webif/p2p-Download2.sh
echo
'echo
$b>/mnt/usbdrive/control_torrent/tmp/kill/'"$FORM_file_torrent">>/www/cgibin/webif/p2p-Download2.sh
kill
cp
/www/cgi-bin/webif/p2p-Download2.sh
/mnt/usbdrive/control_torrent/tmp/script/$FORM_file_torrent
####################################################################
####################################################################
echo
"ps
|
grep
$FORM_file_torrent
|
wc
l>/mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent">/www/cgibin/webif/bit_clear.sh
-
echo
"grep
-v
2
/mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent;p_$$="'$?'>>/www/c
gi-bin/webif/bit_clear.sh
echo "while(test "'$'"p_$$ -eq 0)">>/www/cgi-bin/webif/bit_clear.sh
echo "do">>/www/cgi-bin/webif/bit_clear.sh
echo
">/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/www/cgibin/webif/bit_clear.sh
echo
"ps
|
grep
$FORM_file_torrent
|
wc
l>/mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent">>/www/cgibin/webif/bit_clear.sh
__________________________________________________________________ 53
P2P File Sharing on OpenWRT
echo
"grep
-v
2
/mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent;p_$$="'$?'>>/www/c
gi-bin/webif/bit_clear.sh
echo
">/mnt/usbdrive/control_torrent/status_bit/jank.txt">>/www/cgibin/webif/bit_clear.sh
echo "sleep 20s;">>/www/cgi-bin/webif/bit_clear.sh
echo "done">>/www/cgi-bin/webif/bit_clear.sh
echo
"echo
STOP>/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/www/cgibin/webif/bit_clear.sh
cp
/mnt/usbdrive/control_torrent/tmp/$FORM_file_torrent
/www/cgi-bin/webif/bit_clear.sh
####################################################################
echo
"option|$FORM_file_torrent|@TR<<$FORM_file_torrent>>">/mnt/usbdrive/control_torrent/tm
p/option/$FORM_file_torrent
##################################################################
cat /www/cgi-bin/webif/bit_sec1.txt>/www/cgi-bin/webif/bit2.sh
echo "cd /www/cgi-bin/webif/">>/www/cgi-bin/webif/bit2.sh
echo
"rm
/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/www/cgibin/webif/bit2.sh
echo
"./p2pDownload2.sh>/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/www/cgibin/webif/bit2.sh
echo
"cd
/mnt/usbdrive/control_torrent/tmp/script">/mnt/usbdrive/control_torrent/tmp/run_pro/$F
ORM_file_torrent
echo
"rm
/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/mnt/usbdrive/control_to
rrent/tmp/run_pro/$FORM_file_torrent
echo
"./$FORM_file_torrent>/mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent">>/m
nt/usbdrive/control_torrent/tmp/run_pro/$FORM_file_torrent
echo "sleep 3s">>/www/cgi-bin/webif/bit2.sh
echo "sleep 3s">>/mnt/usbdrive/control_torrent/tmp/run_pro/$FORM_file_torrent
echo "cd /mnt/usbdrive/control_torrent/tmp/">>/www/cgi-bin/webif/bit2.sh
echo
"cd
/mnt/usbdrive/control_torrent/tmp/">>/mnt/usbdrive/control_torrent/tmp/run_pro/$FORM_f
ile_torrent
echo
"./$FORM_file_torrent>/mnt/usbdrive/control_torrent/status_bit/junk.txt
&">>/www/cgi-bin/webif/bit2.sh
echo
"./$FORM_file_torrent>/mnt/usbdrive/control_torrent/status_bit/junk.txt
&">>/mnt/usbdrive/control_torrent/tmp/run_pro/$FORM_file_torrent
cat /www/cgi-bin/webif/bit_sec2.txt>>/www/cgi-bin/webif/bit2.sh
cd /www/cgi-bin/webif/>>/www/cgi-bin/webif/bit2.sh
./bitsta.sh>>/www/cgi-bin/webif/bit2.sh
chmod 775 /www/cgi-bin/webif/bit2.sh
chmod 775 /mnt/usbdrive/control_torrent/tmp/run_pro/*
chmod 775 /mnt/usbdrive/control_torrent/tmp/kill/*
else
cat<<EOF
<html>
<b><FONT COLOR="RED">Error! +,)O()
:! :)
8)O(%</b></FONT></br>
</html>
EOF
fi
fi
}
__________________________________________________________________ 54
P2P File Sharing on OpenWRT
display_form <<EOF
start_form|@TR<<"
OP
!
:>>
field|@TR<<)O(OP
% :>>
text|file_torrent
field|@TR<<*OP
8. .. :>>
select|stor
option|/mnt/usbdrive/HDD/storage0|@TR<<storage0>>
option|/mnt/usbdrive/HDD/storage0|@TR<<storage1>>
option|/mnt/usbdrive/HDD/storage2|@TR<<storage2>>
option|/mnt/usbdrive/HDD/my_documents|@TR<<My Documents>>
option|/mnt/usbdrive/HDD/Shared_documents|@TR<<Shared Documents>>
field|@TR<<!%+' seed !...9
(default 72 hours) :>>
text|Exit_while_Seed_hours
field|@TR<<!%+' seed !...ratio :>>
text|Exit_while_Seed_ratio
field|@TR<<((default 2706 -> 2106) :>>
text|Port
field|@TR<<'
N
:>>
select|Rate_down
option||@TR<<)
'>>
option|25|@TR<<25 kB/s>>
option|40|@TR<<40 kB/s>>
option|45|@TR<<45 kB/s>>
option|50|@TR<<50 kB/s>>
option|55|@TR<<55 kB/s>>
option|60|@TR<<60 kB/s>>
option|75|@TR<<75 kB/s>>
option|100|@TR<<100kB/s>>
option|150|@TR<<150kB/s>>
option|200|@TR<<200kB/s>>
option|500|@TR<<500kB/s>>
option|750|@TR<<750kB/s>>
option|1000|@TR<<1000kB/s>>
field|@TR<<'
N
:>>
select|Rate_up
option||@TR<<)
'>>
option|25|@TR<<25 kB/s>>
option|40|@TR<<40 kB/s>>
option|45|@TR<<45 kB/s>>
option|50|@TR<<50 kB/s>>
option|55|@TR<<55 kB/s>>
option|60|@TR<<60 kB/s>>
option|75|@TR<<75 kB/s>>
option|100|@TR<<100kB/s>>
option|150|@TR<<150kB/s>>
option|200|@TR<<200kB/s>>
option|500|@TR<<500kB/s>>
option|750|@TR<<750kB/s>>
option|1000|@TR<<1000kB/s>>
helpitem|"}8
helptext|HelpText "}8# +,
:)O(% !'"
:)
!'¤"
!$%) *9'%'$+¡
"Save Changes" "
'(9!'
end_form
EOF
?>
<html>
Starting to <a href="bit2.sh"><b>Download</b></a></p>
<br>
</html>
<?
echo "Command: "
cat /www/cgi-bin/webif/p2p-Download2.sh
?>
<? footer ?>
<!-##WEBIF:name:P2P:3:Download
-->
__________________________________________________________________ 55
P2P File Sharing on OpenWRT
Code ! Status
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header
"P2P"
"Status"
"<img
/>@TR<<Status>>" '' "$SCRIPT_NAME" ?>
src=\"/images/upd.jpg\"
alt=\"@TR<<Status>>\"
<?
rm /www/cgi-bin/webif/info_bit.sh
rm /mnt/usbdrive/control_torrent/tmp/info/*
echo "<meta http-equiv=\"refresh\" content=\"20\" />"
cd /mnt/usbdrive/control_torrent/status_bit
cat *.torrent | head -n 2 *.torrent>show_status.txt
?>
<html>
</TABLE>
<table border="2" cellpadding="1" bordercolor="#008000" width="70%" height="30">
<TR > <TH ><pre ><b> OP
</b></pre></TR>
<table border="1" cellpadding="1" bordercolor="#008000" width="70%" height="50">
<TR > <TH ><pre ><? cat /mnt/usbdrive/control_torrent/status_bit/show_status.txt
?></pre></TR>
</TABLE>
<br>
</html>
<?
######################################################################
empty "$FORM_submit" || {
SAVED=1
validate <<EOF
string|FORM_file_torrent|@TR<<File.torrent>>|required min=1|$FORM_file_torrent
string|FORM_options|@TR<<options>>|required min=1|$FORM_options
EOF
#######################################################################
if test -z $FORM_file_torrent;
then
cat<<EOF
<html>
<b><FONT COLOR="RED">Error! +,%)
)')O( +,)O(%</b></FONT></br>
</html>
EOF
else {
test -s /mnt/usbdrive/control_torrent/tmp/kill/$FORM_file_torrent;x=$?
if test $x -eq 0 ;
then
{
if test $FORM_options -eq 1;
then
chmod 775 /mnt/usbdrive/control_torrent/tmp/kill/*
cd /mnt/usbdrive/control_torrent/tmp/kill/
./$FORM_file_torrent
echo "+,)'!%+''(9!' $FORM_file_torrent +,..."
sleep 2s
cat<<EOF
<html>
<meta http-equiv="refresh" content="0; URL=p2p-status.sh" />
</html>
EOF
fi
###############################################################run
if test $FORM_options -eq 2;
then
echo "+,)' "
$FORM_file_torrent +,..."
cd /mnt/usbdrive/control_torrent/tmp/run_pro/
sleep 3s
./$FORM_file_torrent*
sleep 3s
__________________________________________________________________ 56
P2P File Sharing on OpenWRT
fi
################################################################
if test $FORM_options -eq 3;
then
rm /mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/run_pro/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/script/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/kill/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/info/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/option/$FORM_file_torrent
echo "+,)' $FORM_file_torrent +,..."
cd /www/cgi-bin/webif/
./bitsta.sh
sleep 2s
cat<<EOF
<html>
<meta http-equiv="refresh" content="0; URL=p2p-status.sh" />
</html>
EOF
fi
if test $FORM_options -eq 4;
then
rm /mnt/usbdrive/control_torrent/status_bit/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/status_bit/pst/pst_$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/run_pro/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/script/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/kill/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/info/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/option/$FORM_file_torrent
rm -R /mnt/usbdrive/HDD/Shared*/$FORM_file_torrent
rm -R /mnt/usbdrive/HDD/my*/$FORM_file_torrent
rm -R /mnt/usbdrive/HDD/storage*/$FORM_file_torrent
echo "+,)' $FORM_file_torrent+
+,..."
cd /www/cgi-bin/webif/
./bitsta.sh
sleep 2s
cat<<EOF
<html>
<meta http-equiv="refresh" content="0; URL=p2p-status.sh" />
</html>
EOF
fi
if test $FORM_options -eq 5;
then
rm -R /mnt/usbdrive/HDD/Shared*/$FORM_file_torrent
rm -R /mnt/usbdrive/HDD/my*/$FORM_file_torrent
rm -R /mnt/usbdrive/HDD/storage*/$FORM_file_torrent
rm /mnt/usbdrive/control_torrent/tmp/option/$FORM_file_torrent
echo "+,)' $FORM_file_torrent +,..."
sleep 2s
cat<<EOF
<html>
<meta http-equiv="refresh" content="0; URL=p2p-status.sh" />
</html>
EOF
fi
if test $FORM_options -eq 6;
then
rm /mnt/usbdrive/control_torrent/tmp/info/$FORM_file_torrent
cd /mnt/usbdrive/HDD/FT
ctorrent
-x
$FORM_file_torrent>/mnt/usbdrive/control_torrent/tmp/info/$FORM_file_torrent
cat /www/cgi-bin/webif/info_sec1.txt>/www/cgi-bin/webif/info_bit.sh
echo
"cat
/mnt/usbdrive/control_torrent/tmp/info/$FORM_file_torrent">>/www/cgibin/webif/info_bit.sh
__________________________________________________________________ 57
P2P File Sharing on OpenWRT
cat /www/cgi-bin/webif/info_sec2.txt>>/www/cgi-bin/webif/info_bit.sh
chmod 775 /www/cgi-bin/webif/info_bit.sh
echo "+,)' '%¤8%' $FORM_file_torrent +,..."
sleep 2s
cat<<EOF
<html>
<meta http-equiv="refresh" content="0; URL=info_bit.sh" />
</html>
EOF
fi
}
else
cat<<EOF
<html>
<b><FONT COLOR="RED">Error! +,)O()
:! :)
8)O(%'(9!'</b></FONT></br>
</html>
EOF
fi
}
fi
#######################################################################
}
display_form <<EOF
start_form|@TR<<+
:>>
#field|@TR<<)O(OP
% :>>
#text|file_torrent
field|@TR<<)O(OP
% :>>
select|file_torrent
option|x|@TR<<)O(>>
option|Alien_Arizona.torrent|@TR<<Alien_Arizona.torrent>>
option|COMING_SOON.torrent|@TR<<COMING_SOON.torrent>>
option|EagleEye.torrent|@TR<<EagleEye.torrent>>
option|IP_MAN_VCD.torrent|@TR<<IP_MAN_VCD.torrent>>
option|SB_PeeThang2.torrent|@TR<<SB_PeeThang2.torrent>>
option|Un_Evolution_2.torrent|@TR<<Un_Evolution_2.torrent>>
field|@TR<<Options :>>
select|options
option|1|@TR<<!%+'>>
option|2|@TR<<"
>>
option|3|@TR<<.torrent>>
option|4|@TR<<.torrent+
>>
option|5|@TR<<
>>
option|6|@TR<<%8%'>>
helpitem|"}8
helptext|HelpText "}8# +,
:)O(%'(9!' Option 8'$+¡
"Save Changes"
end_form
EOF
######################################################################
?>
<? footer ?>
<!-##WEBIF:name:P2P:4:Status
-->
Code ! Storage
#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header_inject_head=$(cat <<EOF
__________________________________________________________________ 58
P2P File Sharing on OpenWRT
<script type="text/javascript">
<!-function webif_entityDecode(s) {
var e = document.createElement("div");
e.innerHTML = s;
return e.firstChild.nodeValue;
}
var webif_printf=function() {
var num = arguments.length;
var output = arguments[0];
for (var i = 1; i < num; i++) {
var pattern = "\\\\{" + (i-1) + "\\\\}";
var re = new RegExp(pattern, "g");
output = output.replace(re, arguments[i]);
}
return output;
}
function confirm_deldir(path,file) {
if
(window.confirm(webif_entityDecode(webif_printf("@TR<<big_warning#WARNING>>!\\n\\n@TR<
<system_editor_ask_dir_deletition#Do
you
really
want
to
delete
the
'{0}'
directory>>?", file)))) {
window.location="$SCRIPT_NAME?path=" + escape(path) + "&amp;delpath=" +
escape(file);
}
}
function confirm_delfile(path,file) {
if
(window.confirm(webif_entityDecode(webif_printf("@TR<<big_warning#WARNING>>!\\n\\n@TR<
<system_editor_ask_file_deletition#Do you really want to delete the '{0}/{1}'
file>>?", path, file)))) {
window.location="$SCRIPT_NAME?path=" + escape(path) + "&amp;delfile=" +
escape(file);
}
}
-->
</script>
<style type="text/css">
<!-#filebrowser table {
margin-left: 1em;
margin-right: 1em;
margin-bottom: 2.2em;
text-align: left;
font-size: 0.8em;
border-style: none;
border-spacing: 0;
}
#filebrowser td {
padding-left: 0.1em;
padding-right: 0.1em;
}
#filebrowser td.number {
text-align: right;
}
#filebrowser td.leftimage {
padding-left: 0em;
}
#filebrowser td.image {
text-align: center;
}
#filebrowser td.rightimage {
padding-right: 0em;
}
#filebrowser a.tooltip {
z-index: 3;
}
#filebrowser span.tooltip {
display: none;
}
#filebrowser a:hover.tooltip {
position: relative;
}
__________________________________________________________________ 59
P2P File Sharing on OpenWRT
#filebrowser a:hover.tooltip span.tooltip {
z-index: 5;
display: block;
position: absolute;
top: 1.1em;
left: 1.8em;
width: 20em;
text-decoration: none;
padding: 3px;
border: 1px solid;
color: Black;
background-color: White;
}
-->
</style>
EOF
)
! empty "$FORM_delpath" && {
cd / 2>/dev/null
ERROR=$(rmdir "$FORM_delpath" 2>&1)
equal "$?" "0" && {
SUCCESS=$(cat <<EOF
@TR<<system_editor_info_dir_deleted#Directory was deleted successfully>>:<br/>
<strong>$FORM_delpath</strong><br/><br/>
EOF
)
}
}
! empty "$FORM_delfile" && {
ERROR=$(rm "$FORM_path/$FORM_delfile" 2>&1)
equal "$?" "0" && {
SUCCESS=$(cat <<EOF
@TR<<system_editor_info_file_deleted#File was deleted successfully>>:<br/>
<strong>$FORM_path/$FORM_delfile</strong><br/><br/>
EOF
)
}
}
! equal "$ERROR" "" && ERROR="$ERROR<br />"
FORM_path="${FORM_path:-/}"
ERROR="$ERROR$(cd "$FORM_path" 2>&1)"
cd "$FORM_path" 2>/dev/null
while [ "$?" != "0" ]; do
FORM_path="${FORM_path%/*}"
FORM_path="${FORM_path:-/}"
cd "$FORM_path" 2>/dev/null
done
FORM_path="$(pwd)"
# return to the cgi dir
cd "${SCRIPT_NAME%/*}" 2>/dev/null
header "P2P" " " "<img src=\"/images/pkg.jpg\" alt=\"@TR<<File Storage>>\" />@TR<<File
Storage>>" ''
! empty "$SUCCESS" && echo "$SUCCESS"
edit_pathname="$FORM_path/$FORM_edit"
saved_filename="/tmp/.webif/edited-files/$edit_pathname"
! empty "$FORM_save" && {
SAVED=1
mkdir -p "/tmp/.webif/edited-files/$FORM_path"
echo "$FORM_filecontent" > "$saved_filename"
}
empty "$FORM_cancel" || FORM_edit=""
if empty "$FORM_edit"; then
(ls -alLe "$FORM_path" 2>/dev/null | sed '/^[^d]/d';
ls -alLe "$FORM_path" 2>/dev/null | sed '/^[d]/d') 2>/dev/null | awk \
-v url="$SCRIPT_NAME" \
__________________________________________________________________ 60
P2P File Sharing on OpenWRT
-v path="$FORM_path" \
-f /usr/lib/webif/common.awk \
-f /usr/lib/webif/browser.awk
else
exists "$saved_filename" && {
edit_filename="$saved_filename"
} || {
edit_filename="$edit_pathname"
}
cat "$edit_filename" 2>/dev/null | awk \
-v url="$SCRIPT_NAME" \
-v path="$FORM_path" \
-v file="$FORM_edit" \
-f /usr/lib/webif/common.awk \
-f /usr/lib/webif/editor.awk
fi
?>
<?
####################################################################
mounts_form=$(
df -h /dev/sda1 | uniq | awk 'BEGIN { mcount=0 };
/\// {
filled_caption=$5;
print
"string|<tr><td><strong>"$6"</strong><br
/><em>"$1"</em></td><td>"
print "progressbar|mount_" mcount "|" $3 "@TR<<B>> @TR<<mount_of#of>> "
$2 "@TR<<B>>|200|" $5 "|" filled_caption "|"; mcount+=1
print "</td></tr>"
}'
)
display_form <<EOF
start_form|@TR<<Mount Usage>>
$mounts_form
helpitem|Mount Usage
helptext|Helptext Mount Usage#This is the amount of space total and used on the
filesystems mounted to your router.
end_form|
EOF
################################################################
?>
<? footer ?>
<!-##WEBIF:name:P2P:6:
-->
__________________________________________________________________ 61
P2P File Sharing on OpenWRT

Similar documents

Internet

Internet Teoria e Tecnica dei Nuovi Media - Prof.Pescatore a/a

More information