matrix utility apps: initial version
[keystone-demos/matrix-apps.git] / utility_filesystem / cgi-bin / filesystemwrite.cgi
1 #!/bin/sh
2 echo Content-type: text/html
3 echo 
4 echo 
6 display_footer()
7 {
8 cat << EOM2
9 <div style='clear: both;'>&nbsp;</div>
10 </div>
11 <div id='footer'><p id='legal'>( c ) 2013 Texas Instruments Incorporated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></div>
12 </body>
13 </html>
14 EOM2
15 }
17 cat << EOM
18 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'>
19 <head><meta http-equiv='Pragma' CONTENT='no-cache' /> <meta http-equiv='content-type' content='text/html; charset=utf-8' /> <title>C6x Linux Web Control Panel</title>
20 </head>
21 <body>
22 <div id='wrapper'>
23 <div id='logo'><h1>Add File</h1></div>
24 <div id='header'>
25 <div id='menu'>
26 </div>
27 </div>
28 </div>
29 <div id='page'>
30 EOM
31 TMPFILE=`mktemp`
32 cat > $TMPFILE
33 #get_params()
34 #{
35 file=$(cat $TMPFILE | sed -n '4p'| sed 's/.$//')
36 soffset=$(head -8 $TMPFILE | wc -c)
37 eoffset=$(tail -1 $TMPFILE | wc -c)
38 fsize=$(cat $TMPFILE | wc -c)
39 osize=$(((($fsize-$eoffset)-$soffset)-2))
40 #}
42 #write_file()
43 #{
44 cat << EOM1
45 <div id='content'>
46 <p>Writing <i>$osize</i> bytes to <i>$file</i> ...</p>
47 </div>
48 EOM1
49 dd if=$TMPFILE of=$file skip=$soffset bs=1 count=$osize 2>/dev/null
50 sync
51 cat << EOM2
52 <div id='content'>
53 <p>Write to <i>$file</i> complete</p>
54 </div>
55 EOM2
56 rm -f $TMPFILE
57 #}
59 check_params()
60 {
61 #check for 0 size file
62 if [ $osize -eq 0 ] ; then
63 cat << EOM1
64 <div id='content'>
65 <p>Bad Input file ...</p>
66 </div>
67 EOM1
68 display_footer
69 rm -f $TMPFILE
70 exit
71 fi
73 #check for the dirname
74 if [ -z "$file" ] ; then
75 cat << EOM1
76 <div id='content'>
77 <p>Remote file not specified ...</p>
78 <br>
79 </div>
80 EOM1
81 display_footer
82 rm -f $TMPFILE
83 exit
84 fi
86 directory=$(dirname $file)
87 if [ -d $directory ] ; then
88 else
89 cat << EOM1
90 <div id='content'>
91 <p>Could not find the path  <i>$directory</i> ...</p>
92 <br>
93 </div>
94 EOM1
95 display_footer
96 rm -f $TMPFILE
97 exit
98 fi
99 }
101 #get_params
102 #check_params
103 #write_file
105 cat << EOM1
106 <div id='content'>
107 <p>Write to <i>$file</i> complete</p>
108 </div>
109 EOM1
111 #display_footer
113 #display_footer()
114 #{
115 cat << EOM1
116 <div style='clear: both;'>&nbsp;</div>
117 </div>
118 <div id='footer'><p id='legal'>( c ) 2013 Texas Instruments Incorporated&nbsp;&n
119 </body>
120 </html>
121 EOM1
122 #}