mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-06-01 16:06:12 +02:00
Compare commits
421 Commits
CinekidRel
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
924285b51e | ||
|
d453818455 | ||
|
550e151153 | ||
|
2ee6b05e61 | ||
|
c3e4ec88a8 | ||
|
59c71a34ba | ||
|
e5de852087 | ||
|
02fc0ea91b | ||
|
634465fdd6 | ||
|
1bbb327178 | ||
|
fdbc07b377 | ||
|
c536fe3221 | ||
|
db259bbfc6 | ||
|
22b6abfd8b | ||
|
2883a066ef | ||
|
8adc74876e | ||
|
753672e164 | ||
|
0acc20f498 | ||
|
01cc6770f6 | ||
|
c15b1bd592 | ||
|
07d4316a7f | ||
|
18271618f7 | ||
|
a5f3ff92cf | ||
|
752bd144cf | ||
|
9b9513c278 | ||
|
d9e84308dd | ||
|
ae46535275 | ||
|
9571af19ac | ||
|
6729af7064 | ||
|
8eb83ac6a0 | ||
|
3b6b9618cc | ||
|
28e131f8de | ||
|
2b0f6287d7 | ||
|
a9c2f6096c | ||
|
a5bf23c95c | ||
|
ca3016bbe8 | ||
|
257d59b33e | ||
|
54cb428987 | ||
|
c1eb99b91b | ||
|
bafc05deb0 | ||
|
ade1b2793b | ||
|
3fe6ff3bfe | ||
|
1676ca5703 | ||
|
f2e77d9529 | ||
|
6b4e4e934c | ||
|
aec8343bc0 | ||
|
0d955b48ea | ||
|
97fb6609ea | ||
|
533988a409 | ||
|
211c2f1abb | ||
|
fbb536f4ad | ||
|
5607ab96ad | ||
|
b2590e4142 | ||
|
9c6bd6cdea | ||
|
2f91065ff7 | ||
|
82d4179bc3 | ||
|
02b198d773 | ||
|
25aba526b4 | ||
|
fe5b2ec306 | ||
|
a3468b85ce | ||
|
ff9b8f3077 | ||
|
909f6e89bd | ||
|
2c01bcbe07 | ||
|
624756cdcf | ||
|
25629a796c | ||
|
e808c33c7a | ||
|
32bf0db636 | ||
|
6f36b7f1ac | ||
|
29599f2da2 | ||
|
fa3a1b65c4 | ||
|
6d4793a67e | ||
|
3bdb9a4760 | ||
|
5b1b35c961 | ||
|
a1edf05bc7 | ||
|
ae036af172 | ||
|
dd5e3d1e37 | ||
|
edf1ed5577 | ||
|
6b8f2b4d42 | ||
|
89748e11aa | ||
|
1c88c17390 | ||
|
efd2b6aacb | ||
|
c666895842 | ||
|
0f822b99cd | ||
|
65dd10b43c | ||
|
64f1ab47ec | ||
|
7cc345d729 | ||
|
6a26cf3005 | ||
|
205fc7460d | ||
|
d3d8ebdeda | ||
|
2b097996e0 | ||
|
05ec47f8a5 | ||
|
777a6a01dc | ||
|
198a7024f9 | ||
|
a8bdd5c188 | ||
|
52650da0fe | ||
|
4160441a4b | ||
|
7397066ad9 | ||
|
05bb813f29 | ||
|
039fbbb4c3 | ||
|
0bdaca4971 | ||
|
40a25789e2 | ||
|
0d9684bfca | ||
|
c6b01a3cf7 | ||
|
ad048349b3 | ||
|
35bbac596b | ||
|
fa91ace160 | ||
|
8fb0eba9e6 | ||
|
0583dddbe3 | ||
|
ca45f15151 | ||
|
00d77c491d | ||
|
584a5bfce2 | ||
|
4165d3b46d | ||
|
19eef4a334 | ||
|
453ec4294f | ||
|
61fcb7ecb6 | ||
|
5d22267ae3 | ||
|
4db83c98c5 | ||
|
f06e3da46b | ||
|
eebd00c32f | ||
|
ae65e0841c | ||
|
589d2c705e | ||
|
260fac9cd4 | ||
|
f0c839ffdc | ||
|
7a346d6cf1 | ||
|
a9e17e5151 | ||
|
332d185b50 | ||
|
b27506d236 | ||
|
7f5e10eb80 | ||
|
540651c72f | ||
|
9f95b8c537 | ||
|
c8bea605f7 | ||
|
1db8bf3119 | ||
|
8a07d972dd | ||
|
fc026f1b38 | ||
|
9b88313506 | ||
|
2f53a5e8b0 | ||
|
7e0d5cabee | ||
|
7b88ca4489 | ||
|
1cb1309659 | ||
|
939cb66066 | ||
|
65062207ff | ||
|
b4aa1a9746 | ||
|
97612c8a74 | ||
|
03e34f2676 | ||
|
de16721b85 | ||
|
f3e9ebf26e | ||
|
4e1a7157ed | ||
|
b6ab64d1f2 | ||
|
6d001f4894 | ||
|
e384ac4782 | ||
|
bd5a304504 | ||
|
95ea3a1059 | ||
|
fd1a428aea | ||
|
37f833aec1 | ||
|
1c3f35c84f | ||
|
c3756f5348 | ||
|
9fd96740a3 | ||
|
af76720e54 | ||
|
4f84e1060b | ||
|
759c0a3007 | ||
|
52c9435534 | ||
|
bca5228b73 | ||
|
b29eb5289e | ||
|
1439bd0434 | ||
|
5f59e5e2c9 | ||
|
2459cda0ac | ||
|
3a3abb9c55 | ||
|
718e2a314d | ||
|
b70a008cdf | ||
|
210f17377f | ||
|
8a726552f7 | ||
|
f51e63e06a | ||
|
d66d976af1 | ||
|
0716fc22c9 | ||
|
860897d988 | ||
|
98c1ba6b8b | ||
|
09a6c6a928 | ||
|
5979eb841a | ||
|
b26b7376ca | ||
|
6038eac72a | ||
|
fd167ee11e | ||
|
eedc6d3c6b | ||
|
2d0254dc1e | ||
|
4c033a6215 | ||
|
cb6ddf9900 | ||
|
93e2ce1cb7 | ||
|
92ea5faceb | ||
|
4ca599e962 | ||
|
6a546bcca5 | ||
|
2ff4080ea4 | ||
|
067689d64b | ||
|
df4f1702a9 | ||
|
0b2eb5d230 | ||
|
798031f9cd | ||
|
d75d1402bc | ||
|
8318bd265c | ||
|
84f244b8d7 | ||
|
798f9bcf80 | ||
|
3e2cac9c62 | ||
|
d30dc8fe31 | ||
|
7f56af0dfc | ||
|
d9fc8a5d79 | ||
|
623f28f71a | ||
|
4a054f5d5f | ||
|
027f803d54 | ||
|
6e5eb097b8 | ||
|
54a0032a55 | ||
|
b840938cbc | ||
|
4b1476100a | ||
|
028459c321 | ||
|
036bf778c5 | ||
|
37bab25420 | ||
|
35556369ed | ||
|
2221cd00c0 | ||
|
27e5b89b2c | ||
|
3fd59d7866 | ||
|
75d4ccafaa | ||
|
2b98284357 | ||
|
20a2177c08 | ||
|
9c79899f63 | ||
|
9190665d1c | ||
|
da94c0a04e | ||
|
d032b85b61 | ||
|
6e6dd1a108 | ||
|
d1e35c1a69 | ||
|
2669ca2135 | ||
|
27d4f7eabf | ||
|
ca25ab0487 | ||
|
05b4f00a48 | ||
|
c79f48d3b5 | ||
|
e029e1b7df | ||
|
fe8b51686e | ||
|
0eb94d4a67 | ||
|
9f754876f0 | ||
|
c8e6a5b32d | ||
|
349210a3fc | ||
|
7b2a887449 | ||
|
bba1b887b5 | ||
|
e4b2e605ed | ||
|
09f653e3da | ||
|
6297984d68 | ||
|
0b6de9adba | ||
|
e94d238977 | ||
|
b6a3426b07 | ||
|
4a76f022e0 | ||
|
89cec5c989 | ||
|
5ee34873c3 | ||
|
c0a3747d00 | ||
|
9f50ec73b3 | ||
|
00340cb253 | ||
|
ef296218a2 | ||
|
a5f0492a13 | ||
|
8f6fc9dc99 | ||
|
d5f2ec85d3 | ||
|
19892f0917 | ||
|
39b5b756ec | ||
|
524ef027f5 | ||
|
264511f809 | ||
|
96065095ab | ||
|
8582f88e06 | ||
|
b6862c17cc | ||
|
d71d96b9ba | ||
|
781a4dc7a1 | ||
|
cdb7a12050 | ||
|
f152c6e3e3 | ||
|
64abe081e9 | ||
|
efe4ab766a | ||
|
81f450aaf6 | ||
|
689696c0bd | ||
|
541793715f | ||
|
a254772493 | ||
|
ce772010fb | ||
|
5a56780f89 | ||
|
b026ed1874 | ||
|
96e0ec99dd | ||
|
daabffd1ca | ||
|
11f8364e6e | ||
|
175f55f854 | ||
|
75e0d7efd9 | ||
|
06e46bee65 | ||
|
9d1f16d589 | ||
|
71326510e6 | ||
|
15f96c115b | ||
|
ac46c183ac | ||
|
60d07c9667 | ||
|
ab900533f3 | ||
|
165a6a5f8a | ||
|
c0901747b3 | ||
|
c621c618bd | ||
|
39621b215f | ||
|
4d782681df | ||
|
8e34f338c2 | ||
|
af00c17652 | ||
|
491e6021e9 | ||
|
cdcd76654a | ||
|
cdbb608f8d | ||
|
f50e752235 | ||
|
468af0e604 | ||
|
24ab7fa94e | ||
|
e056e4e936 | ||
|
7de2e2aed0 | ||
|
b56a0ed1a9 | ||
|
87a4c2a830 | ||
|
0a51cee8c9 | ||
|
e79902feeb | ||
|
1fe9da5985 | ||
|
8fda75664c | ||
|
bd1409b6a6 | ||
|
d254beb1ab | ||
|
fc9460fc82 | ||
|
1af6ad00cf | ||
|
1668cd446a | ||
|
b72c56e76b | ||
|
75fd335311 | ||
|
5c7b1dee10 | ||
|
7488c3a04c | ||
|
2a30cc2605 | ||
|
486d4eb6ef | ||
|
493728b3bb | ||
|
72d4e5c4c1 | ||
|
50d535a986 | ||
|
68f169be70 | ||
|
348c088cc9 | ||
|
8dc3be6199 | ||
|
f5bf9c279d | ||
|
134c741018 | ||
|
01e29b4b5a | ||
|
021ec46e79 | ||
|
c69420b5b3 | ||
|
5ccbf68362 | ||
|
f534b7cf91 | ||
|
0308ac4b5d | ||
|
ec79cb7c7a | ||
|
34491670b8 | ||
|
52a2d69bdd | ||
|
29faf69457 | ||
|
1e106da3d2 | ||
|
c33cc73b85 | ||
|
7ee1d9b47a | ||
|
0e601baf2a | ||
|
c4c9957cb5 | ||
|
d1c2b08a1f | ||
|
f9f34a42a7 | ||
|
4de647c9c7 | ||
|
051e70a32b | ||
|
7da2b05af8 | ||
|
69d9d2add8 | ||
|
ce043de28e | ||
|
25c0c1a1fa | ||
|
042f33c11a | ||
|
e160f5b94f | ||
|
462360712b | ||
|
c432325b89 | ||
|
b1bc8f5ded | ||
|
a94167ceca | ||
|
33e58e5379 | ||
|
c23c8d9e7c | ||
|
b633eb4d46 | ||
|
dc8be7ca12 | ||
|
d9afb1159e | ||
|
8d7eecc539 | ||
|
10cf3c35b1 | ||
|
48b9a4a8e1 | ||
|
6c15b2c220 | ||
|
0e5726ee04 | ||
|
97564de8fc | ||
|
beb7f39471 | ||
|
4279073fe0 | ||
|
f246252e53 | ||
|
90439649ab | ||
|
92628c660f | ||
|
6f05ea9ce0 | ||
|
0f59eb30d6 | ||
|
5a7a10066b | ||
|
de9570d166 | ||
|
0c79a51083 | ||
|
23d077c4ca | ||
|
88a779e8bf | ||
|
80dda36421 | ||
|
f8825896d8 | ||
|
f2c630a911 | ||
|
6db142eeaa | ||
|
556b587059 | ||
|
3e8fe104c9 | ||
|
2d686d94d2 | ||
|
628f05b682 | ||
|
9e0eab1f8d | ||
|
5c7df6da36 | ||
|
27609e8535 | ||
|
4ed3c02ea3 | ||
|
78a71ca625 | ||
|
8ab87312b3 | ||
|
c3bb0359bf | ||
|
d069dafb5c | ||
|
6ddd038495 | ||
|
5c199eca94 | ||
|
581ea273b2 | ||
|
b6528e4752 | ||
|
b6c983f446 | ||
|
e1dc7f47ed | ||
|
15aa89844e | ||
|
f5030d9069 | ||
|
4738f8bde1 | ||
|
d64fea4337 | ||
|
b5d980c52e | ||
|
b5465a43fd | ||
|
6225cd6062 | ||
|
e87641d76a | ||
|
72678ef1cc | ||
|
a85528e956 | ||
|
cd6754bfe1 | ||
|
1425d5ef90 | ||
|
f4babb5c20 | ||
|
94bcea894e | ||
|
cf7237547f | ||
|
ff4abc71c0 | ||
|
aeb29d488e | ||
|
b5d8f7895a | ||
|
2010c634c6 | ||
|
da020cd51e | ||
|
227ab3d7b8 |
6
.gitmodules
vendored
6
.gitmodules
vendored
|
@ -1,6 +0,0 @@
|
|||
[submodule "src/util/GPX.git"]
|
||||
path = src/util/GPX.git
|
||||
url = git://github.com/whpthomas/GPX.git
|
||||
[submodule "src/www"]
|
||||
path = src/www
|
||||
url = https://github.com/Doodle3D/doodle3d-client.git
|
2
.project
2
.project
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>d3d-box-wifi</name>
|
||||
<name>doodle3d-firmware</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
|
4
.settings/org.eclipse.koneki.ldt.prefs
Normal file
4
.settings/org.eclipse.koneki.ldt.prefs
Normal file
|
@ -0,0 +1,4 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.dltk.coretasks.case_sensitive=true
|
||||
org.eclipse.dltk.coretasks.enabled=true
|
||||
org.eclipse.dltk.coretasks.tags=FIXME;HIGH,TODO;NORMAL,XXX;NORMAL,@fixme;HIGH,@todo;NORMAL,@warning;NORMAL
|
339
LICENSE.txt
Normal file
339
LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
62
Makefile
62
Makefile
|
@ -15,8 +15,8 @@ IncludeWithNewlines = $(subst
|
|||
|
||||
# Name and release number of this package
|
||||
PKG_NAME := wifibox
|
||||
PKG_VERSION := 0.1.0
|
||||
PKG_RELEASE := 7
|
||||
PKG_VERSION := 0.1.1
|
||||
PKG_RELEASE := 8
|
||||
|
||||
# This specifies the directory where we're going to build the program.
|
||||
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
|
||||
|
@ -32,7 +32,7 @@ define Package/wifibox
|
|||
# DEFAULT:=y
|
||||
TITLE:=Doodle3D WifiBox firmware
|
||||
URL:=http://www.doodle3d.com/wifibox
|
||||
DEPENDS:=+lua +luafilesystem +libuci-lua +libiwinfo-lua +uhttpd +uhttpd-mod-lua +print3d
|
||||
DEPENDS:=+lua +luafilesystem +libuci-lua +libiwinfo-lua +uhttpd +uhttpd-mod-lua +doodle3d-client +print3d
|
||||
endef
|
||||
|
||||
define Package/wifibox/description
|
||||
|
@ -55,6 +55,7 @@ endef
|
|||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
$(CP) -r ./src/* $(PKG_BUILD_DIR)/
|
||||
$(CP) -r ./ReleaseNotes.md $(PKG_BUILD_DIR)/
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
|
@ -65,6 +66,13 @@ define Build/Compile directives
|
|||
# no compilation necessary (although possible with luac?)
|
||||
endef
|
||||
|
||||
# This information is contained within the ipk file and (at least) used by
|
||||
# sysupgrade to determine which files to keep (see `opkg list-changed-conffiles`).
|
||||
define Package/wifibox/conffiles
|
||||
/etc/config/wifibox
|
||||
/etc/logrotate.d/wifibox.conf
|
||||
endef
|
||||
|
||||
# The $(1) variable represents the root directory on the router running
|
||||
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
|
||||
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
|
||||
|
@ -72,7 +80,6 @@ endef
|
|||
# directory) to the install directory.
|
||||
|
||||
WIFIBOX_BASE_DIR := $(PKG_BUILD_DIR)
|
||||
GPX_BASE_DIR := $(PKG_BUILD_DIR)/util/GPX.git
|
||||
TGT_LUA_DIR_SUFFIX := usr/share/lua/wifibox
|
||||
|
||||
define Package/wifibox/install
|
||||
|
@ -84,10 +91,20 @@ define Package/wifibox/install
|
|||
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/rest/api
|
||||
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/util
|
||||
$(INSTALL_DIR) $(1)/bin
|
||||
#$(INSTALL_DIR) $(1)/etc
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DIR) $(1)/etc/logrotate.d
|
||||
$(INSTALL_DIR) $(1)/root/
|
||||
$(INSTALL_DIR) $(1)/root/sketches
|
||||
#$(INSTALL_DIR) $(1)/www
|
||||
$(INSTALL_DIR) $(1)/www/cgi-bin
|
||||
|
||||
#copy wps button script to procd folder
|
||||
$(INSTALL_DIR) $(1)/etc/rc.button/
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifi-switch-netconfig.sh $(1)/etc/rc.button/wps
|
||||
|
||||
### create all files in /usr/share/lua/autowifi (autowifi)
|
||||
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/opkg.conf $(1)/$(TGT_LUA_DIR_SUFFIX)/
|
||||
|
@ -97,32 +114,39 @@ define Package/wifibox/install
|
|||
$(CP) $(WIFIBOX_BASE_DIR)/rest/api/*.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/rest/api/
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/util/*.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/util/
|
||||
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox # copy directly to init dir (required for post-inst enabling)
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3d-updater.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3d-updater.lua $(1)/bin/d3d-updater
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/loglite-filters.lua $(1)/root/
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/loglite.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/loglite.lua $(1)/bin/loglite
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/dhcpcheck_init $(1)/etc/init.d/dhcpcheck
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3dapi $(1)/bin/d3dapi
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/logrotate-wifibox.conf $(1)/etc/logrotate.d/wifibox.conf
|
||||
|
||||
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/print-fetch.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/print-fetch.lua $(1)/bin/print-fetch
|
||||
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/FIRMWARE-VERSION $(1)/etc/wifibox-version
|
||||
|
||||
# $(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/www
|
||||
# $(CP) $(WIFIBOX_BASE_DIR)/www/* $(1)/$(TGT_LUA_DIR_SUFFIX)/www/
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/www/* $(1)/www/ #copy www files directly to /www
|
||||
|
||||
echo "<html><body><pre><code>" > $(1)/www/ReleaseNotes.html
|
||||
cat $(WIFIBOX_BASE_DIR)/ReleaseNotes.md >> $(1)/www/ReleaseNotes.html
|
||||
echo "</code></pre></body></html>" >> $(1)/www/ReleaseNotes.html
|
||||
|
||||
ifeq ($(CONFIG_WIFIBOX_DEVEL_PACKAGE),y)
|
||||
# $(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/misc
|
||||
# $(CP) $(WIFIBOX_BASE_DIR)/../misc/collect-code.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/misc/
|
||||
|
||||
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/test
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/test/* $(1)/$(TGT_LUA_DIR_SUFFIX)/test/
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/test $(1)/www/
|
||||
# $(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/test
|
||||
# $(CP) $(WIFIBOX_BASE_DIR)/test/* $(1)/$(TGT_LUA_DIR_SUFFIX)/test/
|
||||
# $(LN) -s /$(TGT_LUA_DIR_SUFFIX)/test $(1)/www/
|
||||
endif
|
||||
|
||||
|
||||
### create links elsewhere in the system (autowifi)
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3dapi $(1)/www/cgi-bin
|
||||
|
||||
### install gpx utility
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(GPX_BASE_DIR)/gpx $(1)/usr/bin
|
||||
$(LN) -s /root/sketches $(1)/www/
|
||||
endef
|
||||
|
||||
define Package/wifibox/postinst
|
||||
|
|
8
NOTICE.txt
Normal file
8
NOTICE.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
Doodle3D overrides the 802.11 regulatory domain such that channels 12 and 13 can be used. In most countries this is desired and accepted behaviour, with the notable exception being the USA.
|
||||
|
||||
Doodle3D uses the following external projects:
|
||||
|
||||
Lua - Copyright (c) 1994–2013 Lua.org, PUC-Rio. - MIT license
|
||||
Luafilesystem - Copyright (c) 2003 Kepler Project - MIT license
|
||||
JSON.lua (http://regex.info/blog/lua/json) - Copyright (c) 2010-2013 Jeffrey Friedl - Creative Commons CC BY 3 license
|
||||
urlcode.lua, part of CGILua - Copyright (c) 2003 Kepler Project - MIT license
|
29
README.md
29
README.md
|
@ -1,7 +1,8 @@
|
|||
WiFi box OpenWRT firmware package
|
||||
=================================
|
||||
|
||||
General documentation can be found on the wiki: <http://doodle3d.com/wiki>. Source code documentation can be generated, see below.
|
||||
General documentation can be found on the wiki: <http://doodle3d.com/help/wiki>. Source code documentation can be generated, see below.
|
||||
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
@ -10,3 +11,29 @@ The script 'doxify.sh' generates HTML documentation of the source code in the di
|
|||
Make sure the 'ldoc' program is installed on your machine and the LDOC variable in the script points there.
|
||||
|
||||
On OSX, this can be accomplished by installing it through luarocks (run `sudo luarocks install ldoc`). Luarocks can be installed using [MacPorts](http://www.macports.org/). After installing that, the command would be `sudo port install luarocks`.
|
||||
|
||||
Command line interface
|
||||
----------------------
|
||||
The Doodle3D API can be called using a terminal:
|
||||
|
||||
```d3dapi p=/network/scan r=GET```
|
||||
|
||||
Where the p parameter is the module you want to call and r is the method.
|
||||
Post request can be send using the same method:
|
||||
|
||||
```d3dapi p=/printer/print r=POST```
|
||||
|
||||
Parameters: TODO
|
||||
|
||||
Debugging Lua
|
||||
-------------
|
||||
|
||||
Syntax errors in Lua can lead to tricky issues since they might only surface when the faulty code is actually being run.
|
||||
|
||||
One countermeasure for this is to use [pcall](http://www.lua.org/pil/8.4.html) instead of regular calls in many cases. To let the error 'happen' (which in turn gives information in the form of stack traces), tell the code to use regular calls by setting 'M.DEBUG_PCALLS' to 'true' in `conf_defaults.lua`.
|
||||
|
||||
Additionally, when the pcall setting is not enough, a second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'.
|
||||
|
||||
Note that because stack traces are sent to `stderr`, this script redirects output streams to a separate log file: `/tmp/wifibox.stdout.log`; apart from these traces, the file should not contain any data.
|
||||
|
||||
Finally, the `CGI` gateway of uhttpd also uses this script, so the API can also be used to obtain stack traces by calling it as `<wifibox-ip>/cgi-bin/d3dapi/<endpoint>` (note the extra `cgi-bin`).
|
||||
|
|
233
ReleaseNotes.md
Normal file
233
ReleaseNotes.md
Normal file
|
@ -0,0 +1,233 @@
|
|||
Changelog
|
||||
|
||||
# 0.11.0 (12 jul 2017)
|
||||
# 0.11.0-c (10 jul 2017)
|
||||
- fix: Also closing file descriptor after removing current print file (commit 550e151)
|
||||
|
||||
# 0.11.0-b (6 jul 2017)
|
||||
- show id of current print in d3dapi/info/status when printing in 'fetch' mode.
|
||||
- code reuse and cleanup for control, kill and status
|
||||
|
||||
# 0.11.0-a (23 jun 2017)
|
||||
- Added 'fetch' functionality to let the WiFi-Box print from a remote server. This enables the WiFi-Box to print large g-code files. (yeah!)
|
||||
- Added support for the Renkforce RF100 printer.
|
||||
- Changed 'default startcode' to prevent Ultimaker 2 series to bump into platform [#21](https://github.com/Doodle3D/WiFi-Box/issues/21) when Ultimaker (original) is selected.
|
||||
- Changed default nozzle temperature from 230 to 210 °C.
|
||||
- Fixed corrupted endcode for delta printers.
|
||||
- Changed default endcode to cooldown to 0 after print instead of cooling down to preheat temperature.
|
||||
|
||||
# 0.10.12
|
||||
# 0.10.12-b (12 jan 2017)
|
||||
- Post install update to config for changes in 0.10.10 (fixes print3d logging)
|
||||
|
||||
# 0.10.12-a (26 jul 2016)
|
||||
- Added Ultimaker Original Plus (Thanks Remco)
|
||||
- Added extra usb drivers
|
||||
|
||||
# 0.10.11
|
||||
# 0.10.11-a (25 may 2016)
|
||||
- After pressing the reset button for about 4 seconds the WiFi-Box will go to access point mode. Useful for when you can't reach it.
|
||||
- Becomes access point when it can't connect to WiFi network.
|
||||
- Handles more clients by tweaking the uhttpd config.
|
||||
- Print3D isn't killed when there is no memory available.
|
||||
- New banner (shown after ssh login)
|
||||
- Ultimaker 2 type printers show status information on display.
|
||||
|
||||
# 0.10.10 (11 may 2016)
|
||||
- Logging client version info to console.
|
||||
- Logging less when printing to makerbot/wanhao
|
||||
- Logging API time info
|
||||
- Included version number file in logfiles
|
||||
- Fixed stopping while sending
|
||||
|
||||
# 0.10.10-e (21 apr 2016)
|
||||
- Fixed Makerbot end gcode that prevented prints or stopping prints to finish.
|
||||
|
||||
# 0.10.10-d (20 apr 2016)
|
||||
- Allow print part sequence numbers to be retrieved
|
||||
- Sequence numbers are send back when sending print parts
|
||||
- When WiFi-Box responds that print part was already received the client will send the next part.
|
||||
|
||||
# 0.10.10-c (1 apr 2016)
|
||||
- Quicker log rotation
|
||||
|
||||
# 0.10.10-b (21 mrt 2016)
|
||||
- Logrotation (making sure older logs are removed)
|
||||
- Improved logging.
|
||||
- Always log initial printer communication
|
||||
- loglite improvements, added readme
|
||||
|
||||
# 0.10.10-a (24 feb 2016)
|
||||
- Max buffer size check: the WiFi-Box can now indicate through the API that its buffer is full and it won't accept new gcode.
|
||||
- Buffer information is communicated through the API so all clients can handle this properly. The Doodle3D client will stop sending and waits until it drops below 75%. It will check this every 30 seconds.
|
||||
- Improved progress indication: when sending a print the total number of lines can be added, causing the total lines reported through the API to be correct, instead of being approximated to be total lines in buffer, which keeps increasing while a print is still being sent.
|
||||
- When sending print parts, sequence numbers can be added which will be checked for correctness.
|
||||
- The stop button now stays enabled while still sending a print.
|
||||
- Made firmware log format consistent with print3d's.
|
||||
- Fixed local IP parsing pattern in firmware.
|
||||
- Improved log messages and log messages formatting.
|
||||
- Added loglite utility which enables filtering and coloring of logs.
|
||||
- Won't attempt sign-in when in access point mode.
|
||||
- More consistent error reporting from API.
|
||||
- API d3dapi/printer/print's 'first' parameter has been deprecated in favor of a more descriptive 'clear' parameter.
|
||||
- Support for CraftBot PLUS printer.
|
||||
|
||||
# 0.10.9 (11 jan 2016)
|
||||
# 0.10.8 (11 jan 2016)
|
||||
# 0.10.8-b (7 jan 2016)
|
||||
Logging less by default, fixing some pretty serious memory issues, which could cause the WiFi-box to 'crash' while printing bigger files.
|
||||
Log level setting, enabling users to log more if they run into problems.
|
||||
For better adhesion we extruded even while traveling on the bottom layers, we now made it configurable and turned it off by default.
|
||||
Fixed month display of releases in settings screen.
|
||||
|
||||
# 0.10.8-a (11 nov 2015)
|
||||
Added ch341 and cp210x usb-serial drivers to diffconfig
|
||||
|
||||
# 0.10.7 (21 aug 2015)
|
||||
Added ColiDo printer profiles
|
||||
|
||||
# 0.10.6 (17 jun 2015)
|
||||
# 0.10.6-rc3 (17 jun 2015)
|
||||
# 0.10.6-rc2 (16 jun 2015)
|
||||
# 0.10.6-rc1 (16 jun 2015)
|
||||
This release sees several connectivity bugs resolved as we continue to look to
|
||||
create the most stable experience we can offer for Doodle3D users. A new
|
||||
addition that has been realized in that the filament thickness is now
|
||||
printer dependent. This is important for printers that use 1,75mm filament.
|
||||
When changing the printer type it switches automatically. Please contact us for
|
||||
better filament thickness defaults. For more details please review the notes below:
|
||||
|
||||
General:
|
||||
- Updated OpenWRT (the operating system) to 14.07.
|
||||
- Fixed several big issues around connecting to printers.
|
||||
- Big files for Marlin based printers are processed faster.
|
||||
- Target temperature retrieval is improved.
|
||||
- Changed the Accesspoint's settings to the default because of startup issues (country: NL to US, channel: 11 to 1).
|
||||
- Improved 404 page.
|
||||
|
||||
Additions
|
||||
- Filament thickness is now printer type dependent and automatically change when selecting a printer. (Please contact us for better filament thickness defaults.)
|
||||
|
||||
Support for more 3D printers:
|
||||
- DoodleDream
|
||||
- 3Dison
|
||||
- LulzBot TAZ 4
|
||||
- Wanhao Duplicator 4
|
||||
- Ultimaker 2 Go
|
||||
|
||||
Improvements for Makerbot based printers (like the Wanhao printer):
|
||||
- Prevent that the nozzle bumps into the bed when starting a new print.
|
||||
- Prevent that the nozzle moves though a print after printing.
|
||||
|
||||
# 0.10.5-a (2 Feb 2015)
|
||||
- Removed gray lines where printer needs to 'travel' (move without printing)
|
||||
- Enabled traveling also for first couple of layers. This prevents straight lines crossing your print
|
||||
- Added url parameter l=1 which disables parts of the user interface. The 'Print' button 'saves' the sketch instead of sending it to the printer. This is useful for public events where a moderator needs to start prints instead of the user.
|
||||
- Fixed a small bug where the last sketch was skipped when pressing the previous button for the first time.
|
||||
- changed WordArt font to a self-made single line handwritting font. This font prints faster and is more playful.
|
||||
|
||||
|
||||
# 0.10.5
|
||||
- Added the PhotoGuide feature which is kind of a manual Scan & Trace. Use a photo as a background image and create your doodle on top of it.
|
||||
- Added support for the '3Dison plus' printer.
|
||||
- Added a File Manager for downloading, uploading and deleting sketches (can be opened via the Settings Panel)
|
||||
- Improved the way sketches are loaded
|
||||
- Fixed scrolling issue in Settings Panel
|
||||
|
||||
# 0.10.4-photoguide3 (10th oct 2014)
|
||||
# 0.10.4-photoguide2 (9th oct 2014)
|
||||
# 0.10.4-photoguide (9th oct 2014)
|
||||
- Added the PhotoGuide feature which is kind of a manual Scan & Trace. Use a photo as a background image and create your doodle on top of it.
|
||||
- Added support for the '3Dison plus' printer.
|
||||
|
||||
# 0.10.4 (28th may 2014)
|
||||
- Pulled improvements by Ultimaker.
|
||||
- Fixed printing isues with gcode containing whitelines.
|
||||
- Added Builder3D to printer types
|
||||
- iOS captive portal fix
|
||||
|
||||
# 0.10.3 (9th apr 2014)
|
||||
- Fixed Makerbot issue where printer driver didn't get past connecting state
|
||||
|
||||
# 0.10.2-makerbotfix (27th mar 2014)
|
||||
- Fixed Makerbot issue where printer driver didn't get past connecting state
|
||||
|
||||
Changelog
|
||||
# 0.10.2 (14th mar 2014)
|
||||
- Fixed connection issues to networks with multiple routers sharing the same ssid
|
||||
- Option to update to beta releases (Beta testers are welcome)
|
||||
- Substituted wifiboxid retrievable through info api
|
||||
- Added a "connecting" printer state where it found a printer but couldn't communicate yet. (Not yet implemented for Makerbot's)
|
||||
- When connecting takes to long, we display a warning that the user might have selected the wrong printer type (Not yet implemented for Makerbot's)
|
||||
- API's printer/state doesn't return an error anymore when a printer is just connected
|
||||
- Allowing WiFi channels 12 & 13
|
||||
- Fixed issue that control access wasn't properly reset after print
|
||||
- Fixed another issue where the box in access point wouldn't give ip addresses
|
||||
|
||||
# 0.10.1 (12th feb 2014)
|
||||
- miniFactory support
|
||||
- Fixed most Makerbot display issues
|
||||
- Allowing wifi channels 12 and 13
|
||||
- Allow floats for retraction amount setting
|
||||
- Also preheating reconnected printer
|
||||
- Fixed network interface issues
|
||||
- added easter-eggs
|
||||
|
||||
# 0.10.0 (20th jan 2014)
|
||||
- WordArt
|
||||
- Adding basic shapes
|
||||
- 2D edit functionality: move, scale, rotate
|
||||
- Vertical shape buttons in foldable menu (creating more vertical space to draw)
|
||||
- Fixed issues connecting to networks
|
||||
- Doesn't switch to access point after firmware update anymore
|
||||
- Speed and flow rate settings for bottom layers
|
||||
- Improved Makerbot gcode for better adhesion
|
||||
- Traveling disabled in bottom layers (providing sort of a poor man's raft)
|
||||
- Feedback on 'restore settings to default'-button
|
||||
- Reimplemented layout, lots of improvements
|
||||
- Re-enabled regular browser keyboard shortcuts
|
||||
- Faster click responses on iOS
|
||||
- magnifying glass on iOS is now prevented from showing up
|
||||
|
||||
# 0.9.13 (23th dec 2013)
|
||||
- Links to release notes in settings update panel, both for current version and for updateable version.
|
||||
- On finishing the tour the status message, thermometer and progress indicators are only hidden when appropriate
|
||||
- Heated bed printer setting
|
||||
- Gcode {if heatedBed} variable
|
||||
- Enable / disable tour setting
|
||||
- Displaying send percentage in status message
|
||||
- Deltabot (Delta RostockMax, Deltamaker, Kossel) specific start- and endgcode
|
||||
- Deltabot now have 0 x and y dimentions to center the print
|
||||
- No more usb hub needed (OpenWRT full speed usb stability patch)
|
||||
- You can now update without preserving your personal data (sketches / settings)
|
||||
- Settings can be saved even if there are printer driver issues
|
||||
- Save and restore settings issues fixed
|
||||
|
||||
# 0.9.12 (18th dec 2013):
|
||||
- Refill wifibox uci settings after reset, preventing printer driver crash (#138)
|
||||
|
||||
# 0.9.11 (11th dec 2013):
|
||||
- keyboard shortcuts have been added
|
||||
- sketches can now be downloaded both as SVG and as GCODE files
|
||||
- much more data is included when downloading log files, making it easier to solve problems
|
||||
- printer profiles have been added, making it possible to differentiate settings per printer
|
||||
- added Ultimaker 2 and Makerbot Replicator 2x
|
||||
- specific gcode for ultimaker2 and makerbot have been added
|
||||
- loading and saving of sketches now works as it should
|
||||
- in access-point mode, the wifibox now always serves DHCP addresses properly
|
||||
- more network related logging
|
||||
- new API endpoint: /printer/listall
|
||||
- new API endpoint: /config/reset
|
||||
- traveling is now enabled by default
|
||||
|
||||
# 0.9.10 (22th nov 2013):
|
||||
- fixed a major issue with makerbots preventing to print anything but small prints
|
||||
- slightly improved usage of makerbot type profiles
|
||||
- added option to reset settings to defaults (important to use after updating to allow new defaults to be used)
|
||||
Note: there are known deficiencies in start/end gcode for makerbots
|
||||
|
||||
# 0.9.9 (7th nov 2013)
|
||||
- fixed issue sometimes causing ultimakers to reset continually
|
||||
|
||||
# 0.9.8 (30th oct 2013)
|
||||
- initial release
|
180
TODO.md
180
TODO.md
|
@ -1,180 +0,0 @@
|
|||
## te doen voor werkend prototype (beta testers)
|
||||
- (testen) server logging
|
||||
- (testen/verder implementeren) stopknop
|
||||
- volgorde chunks (en vaker voorkomen?): elke chunk naar los bestand en op het laatst samenvoegen
|
||||
- (client) autopreheat wanneer er een printer aanwezig is
|
||||
- (fw) temp gcode pad veranderen naar device-specifiek (i.e. /tmp/UltiFi/ttyACM?/combined.gc)
|
||||
- (fw) bij (her)initialisatie printer altijd alle state weggooien (i.e. /dev/UtliFi/ttyACM?)
|
||||
- client feedback
|
||||
* voor ontwikkeling: debugoverlay
|
||||
* vaker op 'print' drukken moet niet kunnen (knop disablen en op basis van polling (isPrinting?) status up-to-date houden)
|
||||
-> maar! de firmware moet geen nieuwe printopdrachten accepteren wanneer er al een print bezig is
|
||||
* temperatuurindicatie (alleen wanneer temperatuuruitlezing via api mogelijk is) -> dus ook indicatie van draaiende printserver
|
||||
- (misschien?) verticale shape aanpassen
|
||||
- preheaten voor het starten van een print
|
||||
* (fw) wachten op targettemperatuur - 20 graden (hoe om te gaan met afkoelen?)
|
||||
* (client) in config bij temperatuurinstelling: opmerking dat de printer gaat printen vanaf lagere temperatuur (bv. -20)
|
||||
|
||||
## te den voor final release
|
||||
- start/end-codes configureerbaar maken (via los endpoint) (duplicate)
|
||||
- printerlijst opvragen
|
||||
* data: per printer: {id, path, type}
|
||||
- gcode: printer busy rapporteren vanaf moment dat gcode wordt verzameld, niet pas bij begin printen (of gcode verzamelen per remote host?)
|
||||
- op wiki over openwrt/osx svn checkout veranderen naar git clone
|
||||
- image met alles erin
|
||||
* in postinst op kastje: ook wifibox start doen (enable doet dat niet) (ook voor ultifi)
|
||||
* firewall net wordt nog niet aangemaakt in 'Y'-mode
|
||||
- nadenken over loggen (procedure voor testers hoe ze problemen kunnen rapporteren zodat wij ze kunnen reproduceren)
|
||||
* verzamelen+zippen van logread output (of uci system.@system[0].log_file?) + /tmp/wifibox.conf + printserver log
|
||||
- na /network/disassociate is wifi uitgeschakeld -> kan geen macadres opvragen -> openap bv. 2x nodig om weer goed macadres te vinden
|
||||
- client: netwerkkeuze toevoegen?
|
||||
- herstart van uhttpd en reboot uitstellen tot na sturen van response (closure queue in response.lua)
|
||||
- consistentie REST API
|
||||
- code documenteren
|
||||
- codedocs uitwerken naar apidocs
|
||||
- optie voor loggen toevoegen aan printmanager
|
||||
- AP en client tegelijk (VAP / multi-ssid?)
|
||||
* toegang altijd via AP, clientmode alleen voor updaten en internet ook via kastje (dan moet wel de portalmodus uit)
|
||||
* dns forward: list 'dhcp_option' '6,10.0.0.1,192.168.178.1' (<http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq#configuring.dnsmasq.to.broadcast.external.dns.server.information>)
|
||||
- auto-update (zowel package als geheel image; <- kijken hoe luci dat doet)
|
||||
- serieel:
|
||||
* 115k2? -> Peter zei iets over instabiele connectie op 250k?
|
||||
* fallback lijkt niet te werken (zelfde probleem als bij poort opnieuw openen?)
|
||||
* mss helpt arduino reset triggeren om port opnieuw te kunnen openen?
|
||||
* 3e manier baudrate zetten? <http://stackoverflow.com/questions/4968529/how-to-set-baud-rate-to-307200-on-linux>
|
||||
- initscript testen (lijkt vaker dan eens te worden uitgevoerd)
|
||||
- printerExists: ook nagaan of basispad ultifi bestaat?
|
||||
|
||||
|
||||
## OOK MEE BEZIG
|
||||
- in AP mode, things like 'somewhere.org/asdsfd' still results in 'Not found'
|
||||
- behalve /dev/ttyACM* kan het voor FTDI dus ook /dev/ttyUSB* zijn
|
||||
- config API: anders inrichten (misschien toch 1 key per keer instellen zodat response 'fail' kan zijn?)
|
||||
|
||||
- auto-update
|
||||
- source-url in Makefile aanpassen (type aanpassen naar git en dan direct naar github repo)
|
||||
- toevoegen aan /etc/opkg.conf via files in image: `src/gz wifibox http://doodle3d.com/static/wifibox-packages`
|
||||
- of lokaal: `src/gz wifibox file:///tmp/wifibox-packages`
|
||||
- (info) feed update-script: <wifibox_git_root>/extra/create-packages-dir.sh
|
||||
uitvoeren vanuit pad waar wifibox_packages terecht moet komen (bv. ~/Sites)
|
||||
- (info) package-url: <http://doodle3d.com/static/wifibox/packages>
|
||||
- (info) image-url: <http://doodle3d.com/static/wifibox/images>
|
||||
- later: printerprofielen
|
||||
|
||||
- API:
|
||||
api/info/currentVersion
|
||||
api/info/latestVersion [beta=true]
|
||||
api/system/update
|
||||
api/system/flash
|
||||
* wat als wij een verkeerd package releasen waardoor de API niet meer werkt?
|
||||
|
||||
- (ref) <http://wiki.openwrt.org/doc/devel/packages/opkg>
|
||||
- (ref) <http://wiki.openwrt.org/doc/techref/opkg>
|
||||
- (ref) <http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/>
|
||||
- waar moeten debugvlaggen etc naartoe? (run_flags.lua?)
|
||||
- in package postinst: hostname van kastje instellen op wifibox (met mac?)
|
||||
|
||||
- tijdens openwrt make:
|
||||
'* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-ath9k-common:
|
||||
'* kmod-crypto-hash *
|
||||
- wiki bijwerken (links, structuur, API)
|
||||
- ook in wiki, luadoc installeren:
|
||||
* !! (beter vervangen door?) <http://stevedonovan.github.io/ldoc/topics/doc.md.html>
|
||||
* ongeveer volgens <http://www.hobsie.com/mark/archives/33>, maar! :
|
||||
* luasocket apart installeren met `sudo luarocks install https://raw.github.com/diegonehab/luasocket/master/luasocket-scm-0.rockspec`
|
||||
- Code documenteren <http://keplerproject.github.io/luadoc/>
|
||||
- Lua programmeerstijl? (enkele quotes gebruiken behalve voor i18n)
|
||||
- zoals het nu werkt wordt het lastig om een hiërarchische api te ondersteunen zoals dit: <http://www.restapitutorial.com/lessons/restfulresourcenaming.html>
|
||||
- uhttpd ondersteunt geen PUT en DELETE, wel status codes. Beschrijving CGI-antwoorden: <http://docstore.mik.ua/orelly/linux/cgi/ch03_03.htm>
|
||||
- voor captive portal: cgi 'Location' header voor redirect naar goede url?
|
||||
|
||||
- http statuscodes <https://blog.apigee.com/detail/restful_api_design_what_about_errors>; met relevante link in antwoord (meer: <https://blog.apigee.com/taglist/restful>)
|
||||
- proposed status handling in response.lua:
|
||||
fucntion setStatus(code, <msg>) -> sets http status+dfl msg and optional errmsg in data
|
||||
|
||||
# TODO (new functionality)
|
||||
- fix init script handling as described here: http://wiki.openwrt.org/doc/devel/packages#packaging.a.service
|
||||
- implement (automated) test code where possible
|
||||
* in 'test' dir next to 'src', with API tests under 'test/www/'
|
||||
* www tests check functionality of the test module
|
||||
* www tests also provide an interface to run arbitrary get/post requests
|
||||
* test path splitting as well
|
||||
- document REST API
|
||||
* fail/error difference: fail is a valid rq aka 'could not comply', while error is invalid rq _or_ system error
|
||||
* modules/functions prefixed with '_' are for internal use
|
||||
* rq IDs and endpoint information can be supplied (but it's probably not useful after all)
|
||||
* list endpoints+args+CRUD type
|
||||
* success/fail/error statuses are justified by drupal api
|
||||
* unknown values (e.g. in network info) are either empty or unmentioned fields
|
||||
- define a list of REST error codes to be more descriptive for clients (e.g. errortype=system/missing-arg/generic)
|
||||
- steps to take regarding versioning/updating
|
||||
* versioning scheme
|
||||
* create feed location (e.g. www.doodle3d.com/firmware/packages) (see here: http://wiki.openwrt.org/doc/packages#third.party.packages)
|
||||
* create opkg (already present in bin/ar71xx/packages as .ipk file)
|
||||
* create listing info for package list (checksum, size, etc. ...is this inside the .ipk file?)
|
||||
* find a way to add the feed url to opkg.conf (directly in files during image building?)
|
||||
* determine how opkg decides what is 'upgradeable'
|
||||
* at this point manual updating should be possible, now find out how to implement in lua (execve? or write a minimalistic binding to libopkg?)
|
||||
* expose through info API and/or system API; also provide a way (future) to flash a new image
|
||||
- generally, for configuration keys, it could be a good idea to use the concept of default values so it's always possible to return to a 'sane default config'
|
||||
* use a uci wifibox config to store configuration and a uci wifibox-defaults config as fallback-lookup (which contains a complete default configuration)
|
||||
* specify min/max/type/regex for each config key in separate lua file
|
||||
* perhaps defaults should be specified together with min/max/type/regex
|
||||
- dynamic AP name based on partial MAC (present in default config so it can be overridden and reverted again)
|
||||
- require api functions which change state to be invoked as post request
|
||||
* can this be modelled like java annotations or c function attributes?
|
||||
* otherwise maybe pair each function with <func>_attribs = {…}?
|
||||
- add API functions to test network connectivity in steps (any chance(e.g. ~ap)? ifup? hasip? resolve? ping?) to network or test
|
||||
- handling requests which need a restart of uhttpd (e.g. network/openap) will probably respond with some kind of 'please check back in a few seconds' response
|
||||
- add more config options to package, which should act as defaults for a config file on the system; candidates:
|
||||
reconf.WWW_RENAME_NAME, wifihelper.{AP_ADDRESS, AP_NETMASK, (NET)}
|
||||
<https://github.com/2ion/ini.lua>
|
||||
|
||||
|
||||
# Ideas / issues to work out
|
||||
- add system api module? for check-updates/do-update/etc
|
||||
- licensing (also for hardware and firmware) + credits for external code and used ideas (<http://www.codinghorror.com/blog/2007/04/pick-a-license-any-license.html>)
|
||||
- (this is an old todo item from network:available(), might still be relevant at some point)
|
||||
extend netconf interface to support function arguments (as tables) so wifihelper functionality can be integrated
|
||||
but how? idea: pass x_args={arg1="a",arg2="2342"} for component 'x'
|
||||
or: allow alternative for x="y" --> x={action="y", arg1="a", arg2="2342"}
|
||||
in any case, arguments should be put in a new table to pass to the function (since order is undefined it must be an assoc array)
|
||||
- perhaps opkg+safeboot could be useful in the update mechanism?
|
||||
- add config option to compile sources using luac _or_ add an option to minify the lua code
|
||||
|
||||
|
||||
# Bugs
|
||||
- (captive portal mode) https is not redirected
|
||||
- (captive portal mode) .local domains are not redirected
|
||||
- (captive portal mode) any urls with text after the root domain are not redirected
|
||||
- using iwinfo with interface name 'radio0' yields very little 'info' output while wlan0 works fine.
|
||||
However, sometimes wlan0 disappears (happened after trying to associate with non-existing network)...why?
|
||||
- protect dump function against reference loops (see <http://lua-users.org/wiki/TableSerialization>, json also handles this well)
|
||||
- relocatabilty of package (take root prefix into consideration everywhere)
|
||||
- disabling all wireless networks breaks the current method of obtaining the mac address, thus openap must be called twice before it is properly set up
|
||||
|
||||
|
||||
# Logos
|
||||
|
||||
Check <http://geon.github.io/Programming/2012/04/25/ascii-art-signatures-in-the-wild/> for inspiration.
|
||||
|
||||
|
||||
D o o d l e 3 D
|
||||
-------- ____ .--- v 1.0.1
|
||||
| | | | __ | __|.--.| ._| .---..-.-.
|
||||
| | | ||--|| _| |--|| . || . |\ /
|
||||
|________||__||__| |__||____||___|/_._\
|
||||
|
||||
|
||||
D o o d l e 3 D
|
||||
-------- ____ .---- v 1.0.1
|
||||
| | | |--.| __|-.| ._|---.-.-.
|
||||
| | | |--|| _|--|| . | . |_ _/
|
||||
|________|__||__||__||____|___|_._\
|
||||
|
||||
|
||||
....D o o d l e 3 D
|
||||
...________ _____ _____ v 1.0.1
|
||||
../ / / |__ / __/ / - /___ __
|
||||
./ ' ' /--// _|-// - | . /v /
|
||||
/________/__//__/__//____/___/_^_\
|
16
config.ld
Normal file
16
config.ld
Normal file
|
@ -0,0 +1,16 @@
|
|||
file = {
|
||||
'src',
|
||||
exclude = {'src/test'}
|
||||
}
|
||||
|
||||
dir = 'docs'
|
||||
format = 'markdown'
|
||||
|
||||
readme = 'README.md'
|
||||
title = "WiFibox firmware documentation"
|
||||
project = "Wifibox firmware"
|
||||
description = "This project provides the REST API which is part of the Doodle3D wifibox."
|
||||
|
||||
alias('p', 'param')
|
||||
|
||||
all = true
|
11
doxify.sh
11
doxify.sh
|
@ -10,7 +10,16 @@ HTML_PATH=$WIFIBOX_BASE_DIR/docs
|
|||
SRC_DIR=$WIFIBOX_BASE_DIR/src
|
||||
FILESPEC=$WIFIBOX_BASE_DIR/src #replace by config.ld so we can also specify README.md?
|
||||
|
||||
$LDOC -d $HTML_PATH $FILESPEC -a -f markdown $@
|
||||
LUA_VERSION=`lua -v 2>&1 | awk -F" " '{print $2}'`
|
||||
|
||||
echo $LUA_VERSION | grep -q "^5.2"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Lua 5.2 is needed to run this script (as well as luarocks), you have $LUA_VERSION."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#$LDOC -d $HTML_PATH $FILESPEC -a -f markdown $@
|
||||
$LDOC .
|
||||
|
||||
if [ $? -eq 127 ]; then
|
||||
echo "$0: It looks like the ldoc program could not be found, please configure the LDOC variable correctly and make sure ldoc is installed on your system."
|
||||
|
|
8
extra/license-headers/header-cstyle
Normal file
8
extra/license-headers/header-cstyle
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
*
|
||||
* Copyright (c) 2013-2014, Doodle3D
|
||||
* This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
*/
|
||||
|
8
extra/license-headers/header-lua
Normal file
8
extra/license-headers/header-lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013-2014, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
6
extra/license-headers/header-sh
Normal file
6
extra/license-headers/header-sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
# This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
#
|
||||
# Copyright (c) 2013-2014, Doodle3D
|
||||
# This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
# See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
3
extra/openwrt-build/feeds.conf.template
Normal file
3
extra/openwrt-build/feeds.conf.template
Normal file
|
@ -0,0 +1,3 @@
|
|||
src-git packages git://git.openwrt.org/packages.git^e5f758e0729d094441aad849bbab4117b816567d
|
||||
# Edit the path below to point to the directory of the Doodle3D feed.
|
||||
src-link wifibox /Users/USERNAME/xxxFiles/doodle3d_feed_path
|
125
extra/openwrt-build/gen-feeds-conf.sh
Executable file
125
extra/openwrt-build/gen-feeds-conf.sh
Executable file
|
@ -0,0 +1,125 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script generates a file feeds.conf and places it in the OpenWrt buildroot directory.
|
||||
# It deduces the location of your Doodle3D feed by looking at its own path and,
|
||||
# on OSX, tries to find the OpenWrt buildroot by looking for something mounted in a
|
||||
# directory containing the word 'openwrt'; specify the path with -p <path> if that fails.
|
||||
|
||||
SYSNAME=`uname -s`
|
||||
WRT_PATH=
|
||||
FEED_PATH=
|
||||
PACKAGES_FEED_SHA5=e5f758e0729d094441aad849bbab4117b816567d
|
||||
|
||||
nextIsWrtPath=0
|
||||
for arg in "$@"; do
|
||||
if [ $nextIsWrtPath -eq 1 ]; then
|
||||
WRT_PATH="$arg"
|
||||
nextIsWrtPath=0
|
||||
continue
|
||||
fi
|
||||
|
||||
case "$arg" in
|
||||
-p)
|
||||
nextIsWrtPath=1
|
||||
;;
|
||||
-h)
|
||||
echo "This script generates an OpenWrt feeds.conf file for building Doodle3D, it works automatically."
|
||||
echo "If the wrt buildroot path cannot be determined, specify it using '-p <path>'."
|
||||
echo "If you want the file contents to be shown instead of written out to a file, use '-c'."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "! Error: unknown argument '$arg' found"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ $nextIsWrtPath -eq 1 ]; then
|
||||
echo "! Error: missing argument for -p option"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "x$WRT_PATH" = "x" ]; then
|
||||
if [ "x$SYSNAME" != "xDarwin" ]; then
|
||||
echo "! Error: it looks like you are not using OSX, please specify the OpenWrt buildroot path with '-p <path>'."
|
||||
exit 1
|
||||
|
||||
elif [ "x$SYSNAME" = "xDarwin" ]; then
|
||||
mountPath=`mount | sed -n 's|^.* \([^ ]*[Oo][Pp][Ee][Nn][Ww][Rr][Tt][^ ]*\).*$|\1|p'`
|
||||
if [ -z "$mountPath" ]; then
|
||||
echo "! Error: could not find openwrt-like path in list of mount points."
|
||||
echo "! Please mount the image an rerun, or specify the path using '-p <path>'."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Looking for the word 'openwrt' in a README file in a direct subdir...is this a reasonable 'detect' approach?
|
||||
for i in $(ls -d $mountPath/*/); do
|
||||
dirname=${i%%/}
|
||||
grep -sqi openwrt "$dirname/README"
|
||||
if [ $? -eq 0 ]; then
|
||||
WRT_PATH="$dirname"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$WRT_PATH" ]; then
|
||||
echo "! Error: could not find buildroot path in what looks like an OpenWrt image ('$mountPath'), please rerun with '-p <path>'."
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo "===== Doodle3D OpenWrt feeds.conf generator"
|
||||
echo "* Using OpenWrt buildroot path: '$WRT_PATH'"
|
||||
|
||||
FEED_PATH="$0"
|
||||
FEED_PATH=`dirname "$FEED_PATH"` # Ok, so after this we've got a non-normalized path to the script dir
|
||||
FEED_PATH="$FEED_PATH/../../.." # go back to just outside the doodle3d-firmware repo, which should be the feed root
|
||||
|
||||
echo "$FEED_PATH" | grep -sq "^\/"
|
||||
if [ $? -ne 0 ]; then FEED_PATH="`pwd`/$FEED_PATH"; fi
|
||||
|
||||
#NOTE: and normalize the path...this method feels a bit fragile (spurious output, special user env conditions and whatnot)
|
||||
pushd "$FEED_PATH" > /dev/null 2>&1
|
||||
FEED_PATH="`pwd`"
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
echo "* Using Doodle3D feed path: '$FEED_PATH'"
|
||||
|
||||
echo "$FEED_PATH" | grep -sq ' '
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "! Error: the feed path contains spaces, which OpenWrt cannot handle. Exiting..."
|
||||
exit 4
|
||||
fi
|
||||
|
||||
FILE_CONTENTS=$( cat << EOT
|
||||
src-git packages git://git.openwrt.org/packages.git^$PACKAGES_FEED_SHA5
|
||||
src-link wifibox $FEED_PATH
|
||||
EOT
|
||||
)
|
||||
|
||||
echo "* Contents to be written:\n$FILE_CONTENTS\n"
|
||||
|
||||
while true; do
|
||||
read -p "? Proceed to write a new feeds.conf? " yn
|
||||
case $yn in
|
||||
[Yy]*) break;;
|
||||
[Nn]*)
|
||||
echo "* Ok, feeds.conf will not be generated. Exiting..."
|
||||
exit 0;;
|
||||
*) echo "! Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
|
||||
OUT_PATH="$WRT_PATH/feeds.conf"
|
||||
BKP_PATH="$WRT_PATH/feeds.conf.d3dbkp"
|
||||
if [ -f "$OUT_PATH" ]; then
|
||||
echo "* Backing up $OUT_PATH to $BKP_PATH"
|
||||
cp "$OUT_PATH" "$BKP_PATH"
|
||||
fi
|
||||
|
||||
echo "* Generating $OUT_PATH"
|
||||
echo "$FILE_CONTENTS" > "$OUT_PATH"
|
||||
|
||||
exit 0
|
44
extra/openwrt-build/openwrt-diffconfig-extramini
Normal file
44
extra/openwrt-build/openwrt-diffconfig-extramini
Normal file
|
@ -0,0 +1,44 @@
|
|||
CONFIG_TARGET_ar71xx=y
|
||||
CONFIG_TARGET_ar71xx_generic=y
|
||||
CONFIG_TARGET_ar71xx_generic_TLMR3020=y
|
||||
CONFIG_ATH_USER_REGD=y
|
||||
# CONFIG_BUSYBOX_CONFIG_FEATURE_IPV6 is not set
|
||||
CONFIG_BUSYBOX_CONFIG_INOTIFYD=y
|
||||
CONFIG_DOODLE3D_CLIENT_MINIFY_JS=y
|
||||
# CONFIG_IPV6 is not set
|
||||
# CONFIG_KERNEL_DEBUG_INFO is not set
|
||||
# CONFIG_KERNEL_DEBUG_KERNEL is not set
|
||||
# CONFIG_KERNEL_KALLSYMS is not set
|
||||
# CONFIG_KERNEL_MAGIC_SYSRQ is not set
|
||||
# CONFIG_PACKAGE_6relayd is not set
|
||||
CONFIG_PACKAGE_doodle3d-client=y
|
||||
# CONFIG_PACKAGE_kmod-ip6tables is not set
|
||||
# CONFIG_PACKAGE_kmod-ipv6 is not set
|
||||
# CONFIG_PACKAGE_kmod-ppp is not set
|
||||
CONFIG_PACKAGE_kmod-usb-acm=y
|
||||
CONFIG_PACKAGE_kmod-usb-ohci=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
||||
# CONFIG_PACKAGE_libip6tc is not set
|
||||
CONFIG_PACKAGE_libiwinfo=y
|
||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||
CONFIG_PACKAGE_libpopt=y
|
||||
CONFIG_PACKAGE_liblua=y
|
||||
CONFIG_PACKAGE_libuci-lua=y
|
||||
CONFIG_PACKAGE_logrotate=y
|
||||
CONFIG_PACKAGE_lua=y
|
||||
CONFIG_PACKAGE_luafilesystem=y
|
||||
# CONFIG_PACKAGE_odhcp6c is not set
|
||||
# CONFIG_PACKAGE_ppp is not set
|
||||
CONFIG_PACKAGE_print3d=y
|
||||
CONFIG_PACKAGE_uclibcxx=y
|
||||
CONFIG_PACKAGE_uhttpd=y
|
||||
CONFIG_PACKAGE_uhttpd-mod-lua=y
|
||||
CONFIG_PACKAGE_wifibox=y
|
||||
CONFIG_STRIP_KERNEL_EXPORTS=y
|
||||
# CONFIG_TARGET_ROOTFS_TARGZ is not set
|
||||
CONFIG_USE_MKLIBS=y
|
||||
CONFIG_WIFIBOX_AP_SSID="d3d-ap-%%MAC_TAIL%%"
|
||||
CONFIG_WIFIBOX_INIT_PRIORITY=18
|
||||
CONFIG_WIFIBOX_WIRELESS_DEVICE="radio0"
|
||||
CONFIG_PACKAGE_kmod-lib-crc-ccitt=y
|
40
extra/openwrt-build/openwrt-diffconfig-mini
Normal file
40
extra/openwrt-build/openwrt-diffconfig-mini
Normal file
|
@ -0,0 +1,40 @@
|
|||
CONFIG_TARGET_ar71xx=y
|
||||
CONFIG_TARGET_ar71xx_generic=y
|
||||
CONFIG_TARGET_ar71xx_generic_TLMR3020=y
|
||||
CONFIG_ATH_USER_REGD=y
|
||||
# CONFIG_BUSYBOX_CONFIG_FEATURE_IPV6 is not set
|
||||
CONFIG_DOODLE3D_CLIENT_MINIFY_JS=y
|
||||
# CONFIG_IPV6 is not set
|
||||
# CONFIG_KERNEL_DEBUG_INFO is not set
|
||||
# CONFIG_KERNEL_DEBUG_KERNEL is not set
|
||||
# CONFIG_KERNEL_KALLSYMS is not set
|
||||
# CONFIG_KERNEL_MAGIC_SYSRQ is not set
|
||||
# CONFIG_PACKAGE_6relayd is not set
|
||||
CONFIG_PACKAGE_doodle3d-client=y
|
||||
# CONFIG_PACKAGE_kmod-ip6tables is not set
|
||||
# CONFIG_PACKAGE_kmod-ipv6 is not set
|
||||
# CONFIG_PACKAGE_kmod-ppp is not set
|
||||
CONFIG_PACKAGE_kmod-usb-acm=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
||||
# CONFIG_PACKAGE_libip6tc is not set
|
||||
CONFIG_PACKAGE_libiwinfo=y
|
||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||
CONFIG_PACKAGE_libpopt=y
|
||||
CONFIG_PACKAGE_liblua=y
|
||||
CONFIG_PACKAGE_libuci-lua=y
|
||||
CONFIG_PACKAGE_logrotate=y
|
||||
CONFIG_PACKAGE_lua=y
|
||||
CONFIG_PACKAGE_luafilesystem=y
|
||||
# CONFIG_PACKAGE_odhcp6c is not set
|
||||
# CONFIG_PACKAGE_ppp is not set
|
||||
CONFIG_PACKAGE_print3d=y
|
||||
CONFIG_PACKAGE_uclibcxx=y
|
||||
CONFIG_PACKAGE_uhttpd=y
|
||||
CONFIG_PACKAGE_uhttpd-mod-lua=y
|
||||
CONFIG_PACKAGE_wifibox=y
|
||||
# CONFIG_TARGET_ROOTFS_TARGZ is not set
|
||||
CONFIG_WIFIBOX_AP_SSID="d3d-ap-%%MAC_TAIL%%"
|
||||
CONFIG_WIFIBOX_INIT_PRIORITY=18
|
||||
CONFIG_WIFIBOX_WIRELESS_DEVICE="radio0"
|
||||
CONFIG_PACKAGE_kmod-lib-crc-ccitt=y
|
25
extra/openwrt-build/openwrt-diffconfig-regular
Normal file
25
extra/openwrt-build/openwrt-diffconfig-regular
Normal file
|
@ -0,0 +1,25 @@
|
|||
CONFIG_TARGET_ar71xx=y
|
||||
CONFIG_TARGET_ar71xx_generic=y
|
||||
CONFIG_TARGET_ar71xx_generic_TLMR3020=y
|
||||
CONFIG_ATH_USER_REGD=y
|
||||
CONFIG_DOODLE3D_CLIENT_MINIFY_JS=y
|
||||
CONFIG_PACKAGE_doodle3d-client=y
|
||||
CONFIG_PACKAGE_kmod-usb-acm=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial=y
|
||||
CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
||||
CONFIG_PACKAGE_libiwinfo=y
|
||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||
CONFIG_PACKAGE_libpopt=y
|
||||
CONFIG_PACKAGE_liblua=y
|
||||
CONFIG_PACKAGE_libuci-lua=y
|
||||
CONFIG_PACKAGE_logrotate=y
|
||||
CONFIG_PACKAGE_lua=y
|
||||
CONFIG_PACKAGE_luafilesystem=y
|
||||
CONFIG_PACKAGE_print3d=y
|
||||
CONFIG_PACKAGE_uclibcxx=y
|
||||
CONFIG_PACKAGE_uhttpd=y
|
||||
CONFIG_PACKAGE_uhttpd-mod-lua=y
|
||||
CONFIG_PACKAGE_wifibox=y
|
||||
CONFIG_WIFIBOX_AP_SSID="d3d-ap-%%MAC_TAIL%%"
|
||||
CONFIG_WIFIBOX_INIT_PRIORITY=18
|
||||
CONFIG_WIFIBOX_WIRELESS_DEVICE="radio0"
|
|
@ -1,2 +0,0 @@
|
|||
alias d='ls -la --color=auto'
|
||||
alias wopkg='/usr/share/lua/wifibox/opkg.conf'
|
263
extra/scripts/attach-license.lua
Executable file
263
extra/scripts/attach-license.lua
Executable file
|
@ -0,0 +1,263 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
-- TODO:
|
||||
-- - cstyle comments with lines in them not starting with a '*' are not detected properly
|
||||
-- - cstyle comments a la '//' are ignored completely
|
||||
-- - lua block comments are not recognized
|
||||
-- - in replaceComments(), source files should only be replaced with temp file if it has actually been changed
|
||||
local lfs = require('lfs')
|
||||
|
||||
LICENSE_COMMENT_PREFIX = "This file is part of the Doodle3D project"
|
||||
|
||||
local specs = nil
|
||||
local headers = {}
|
||||
|
||||
|
||||
local function getFileList(path)
|
||||
local result = {}
|
||||
if not path or type(path) ~= 'string' then return result end
|
||||
for file in lfs.dir(path) do
|
||||
--local fileWithSubPath = subPath and subPath..'/'..file or file
|
||||
local subPath = path..'/'..file
|
||||
if lfs.attributes(subPath,'mode') == 'file' then
|
||||
table.insert(result, subPath)
|
||||
elseif lfs.attributes(subPath,'mode')== 'directory' and file ~= '.' and file ~= '..' then
|
||||
local rr = getFileList(subPath)
|
||||
for _,v in ipairs(rr) do table.insert(result, v) end
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
-- @returns indexed table with an entry for each line or nil if file could not be read
|
||||
local function readFileAsLines(file)
|
||||
local f,err = io.open(file, "r")
|
||||
if not f then return f,err end
|
||||
local result = {}
|
||||
for l in f:lines() do
|
||||
table.insert(result, l)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function findItemInList(haystack, needle)
|
||||
for _,v in pairs(haystack) do
|
||||
if v == needle then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function getGitChangedFiles(path)
|
||||
if not path then path = '' end
|
||||
os.execute('git update-index -q --refresh')
|
||||
local f,msg = io.popen('git diff-index --name-only HEAD -- ' .. path, "r")
|
||||
if not f then return f,msg end
|
||||
|
||||
local result = {}
|
||||
for l in f:lines() do
|
||||
table.insert(result, l)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
local function initHeaders(headersPath)
|
||||
-- if not firmwareRootPath then firmwareRootPath = '.' end
|
||||
-- local headersPath = firmwareRootPath .. '/' .. 'extra/license-headers'
|
||||
print("Reading headers from: " .. headersPath)
|
||||
headers['lua'] = readFileAsLines(headersPath .. '/header-lua')
|
||||
headers['sh'] = readFileAsLines(headersPath .. '/header-sh')
|
||||
headers['cstyle'] = readFileAsLines(headersPath .. '/header-cstyle')
|
||||
end
|
||||
|
||||
-- writes first through last lines from indexed string array 'lines' to f, with newlines in between
|
||||
-- if last is nil, everything from first on will be written; if first is nil, it is considered to be line 1
|
||||
local function emitLines(lines, f, first, last)
|
||||
if first == nil then first = 1 end
|
||||
if last == nil then last = #lines end
|
||||
if last - first < 0 then return end
|
||||
for i=first, last do f:write(lines[i] .. '\n') end
|
||||
end
|
||||
|
||||
function string:hashbang() return self:find('^#!') and true or false end
|
||||
function string:empty() return self:find('^[%s]*$') and true or false end
|
||||
|
||||
function string:comment(filetype)
|
||||
if filetype == 'lua' then return self:find('^%-%-.*') and true or false
|
||||
elseif filetype == 'sh' then return self:find('^#.*') and true or false
|
||||
elseif filetype == 'cstyle' then return self:find('^%s?/?%*.*') and true or false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- @returns false if explicitly excluded, type (as string) if matched or nil otherwise
|
||||
local function matchFileType(file)
|
||||
local len = file:len()
|
||||
for _,pat in ipairs(specs.EXCLUDE_FILES) do
|
||||
local s,e = file:find(pat)
|
||||
if s == 1 and e == len then return false end
|
||||
end
|
||||
|
||||
for pat,type in pairs(specs.PROCESS_FILES) do
|
||||
local s,e = file:find(pat)
|
||||
if s == 1 and e == len then return type end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
-- @returns first line nr or false if no comment found
|
||||
-- @returns last line nr if comment found
|
||||
local function findComment(lines, filetype)
|
||||
if not (filetype == 'lua' or filetype == 'sh' or filetype == 'cstyle') then return nil,'unrecognized file type' end
|
||||
|
||||
local first, last = false, nil
|
||||
|
||||
local justConsumeEmpty = false
|
||||
for i,l in ipairs(lines) do
|
||||
if i > 1 and l:hashbang() then
|
||||
break
|
||||
elseif l:hashbang() then
|
||||
--ignore this to simulate a continue
|
||||
elseif not l:comment(filetype) then
|
||||
if first and l:empty() then
|
||||
justConsumeEmpty = true
|
||||
elseif first then
|
||||
last = i - 1
|
||||
break
|
||||
elseif not l:empty() then
|
||||
break
|
||||
end
|
||||
else
|
||||
if justConsumeEmpty then
|
||||
last = i - 1
|
||||
break
|
||||
elseif not first then
|
||||
first = i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return first,last
|
||||
end
|
||||
|
||||
|
||||
local function detectLicenseComment(lines, filetype, first, last)
|
||||
local hasText = function(line, filetype)
|
||||
if filetype == 'lua' then return line:find('^[%s%-]*$') == nil and true or false
|
||||
elseif filetype == 'sh' then return line:find('^[%s#]*$') == nil and true or false
|
||||
elseif filetype == 'cstyle' then return line:find('^[%s%*/]*$') == nil and true or false
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
for i,l in ipairs(lines) do
|
||||
if i >= first and i <= last and hasText(l, filetype) then
|
||||
return l:find(LICENSE_COMMENT_PREFIX, 1, true) and true or false
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- replaces line range [first, last] with header for filetype
|
||||
-- if first and/or last are nil, header is inserted at line 1, or 2 if a hashbang is present
|
||||
-- returns true on success, nil+msg otherwise
|
||||
local function replaceComment(filepath, filetype, lines, first, last)
|
||||
-- local filesEqual = function(file1, file2) return os.execute('cmp -s ' .. file1 .. ' ' .. file2) end--and true or false end
|
||||
|
||||
if first == nil or last == nil then first = lines[1]:hashbang() and 2 or 1 end
|
||||
|
||||
local tmpFileName = os.tmpname()
|
||||
f,msg = io.open(tmpFileName, "w+")
|
||||
if not f then return f, "could not open temporary file '" .. tmpFileName .. "' (" .. msg .. ")" end
|
||||
|
||||
emitLines(lines, f, 1, first - 1)
|
||||
emitLines(headers[filetype], f)
|
||||
emitLines(lines, f, last and last + 1 or first, nil)
|
||||
|
||||
f:close()
|
||||
|
||||
-- if not filesEqual(tmpFileName, filepath) then
|
||||
-- print("actually replacing '" .. filepath .. "' with '" .. tmpFileName .. "' now...")
|
||||
local rv,msg = os.rename(tmpFileName, filepath)
|
||||
os.remove(tmpFileName) -- clean up
|
||||
if not rv then return rv,"could not replace file with '" .. tmpFileName .. "' (" .. msg .. ")" end
|
||||
-- else
|
||||
-- print("files are equal, not touching original")
|
||||
-- end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local function processFile(filepath, filetype, lines)
|
||||
local sLine,eLine = findComment(lines, filetype)
|
||||
if sLine then
|
||||
if detectLicenseComment(lines, filetype, sLine, eLine) then
|
||||
print("Replacing comment in file: '" .. filepath .. "' (type: " .. filetype .. ") head comment: " .. sLine .. "-" .. eLine)
|
||||
replaceComment(filepath, filetype, lines, sLine, eLine)
|
||||
else
|
||||
print("Adding comment to file: '" .. filepath .. "' (type: " .. filetype .. ") unrecognized head comment: " .. sLine .. "-" .. eLine)
|
||||
replaceComment(filepath, filetype, lines, nil, nil)
|
||||
end
|
||||
elseif sLine == false then
|
||||
print("Adding comment to file: '" .. filepath .. "' (type: " .. filetype .. ") no comment")
|
||||
replaceComment(filepath, filetype, lines, nil, nil)
|
||||
else
|
||||
return nil, "invalid type: '" .. filetype .. "'"
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local function main()
|
||||
if #arg ~= 1 then
|
||||
print("Please supply directory containing 'license-spec.lua' as argument")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local pwd = lfs.currentdir()
|
||||
local scriptPath = arg[0]:match('^(.*)/')
|
||||
local headersPath = pwd .. '/' .. scriptPath .. '/../license-headers'
|
||||
initHeaders(headersPath) -- NOTE: this must be precede the chdir below
|
||||
|
||||
print("Working directory: " .. arg[1])
|
||||
if not lfs.chdir(arg[1]) then
|
||||
print("error: could not change to directory '" .. arg[1] .. "', exiting")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
specs = require('license-spec')
|
||||
if not specs.BASE_PATH or specs.BASE_PATH:len() == 0 then specs.BASE_PATH = '.' end
|
||||
|
||||
local files = getFileList(specs.BASE_PATH)
|
||||
local changed = getGitChangedFiles(specs.BASE_PATH)
|
||||
-- for _,l in ipairs(changed) do print("changed: " .. l) end --TEMP
|
||||
|
||||
|
||||
for _,f in ipairs(files) do
|
||||
local processType = matchFileType(f)
|
||||
if processType then
|
||||
if specs.IGNORE_GIT_CHANGED or not findItemInList(changed, f) then
|
||||
local lines,err = readFileAsLines(f)
|
||||
if lines then
|
||||
local rv,msg = processFile(f, processType, lines)
|
||||
if not rv then print("error: could not process file '" .. f .. "' (" .. msg .. ")") end
|
||||
else
|
||||
print("error: could not open '" .. f .. "' (".. err .. ")")
|
||||
end
|
||||
else
|
||||
print("error: file '" .. f .. "' has uncommitted changes in git, refusing to process")
|
||||
end
|
||||
elseif processType == false then
|
||||
print("Skipping excluded file '" .. f .. "'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
|
@ -1,55 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
OPENWRT_BASE=/Volumes/openwrt-image-10gb/openwrt
|
||||
PKG_SRC_DIR=$OPENWRT_BASE/bin/ar71xx/packages
|
||||
PKG_DEST_DIR=wifibox-packages
|
||||
MAKE_INDEX_SCRIPT=$OPENWRT_BASE/scripts/ipkg-make-index.sh
|
||||
INDEX_FILE=Packages
|
||||
INDEX_GZ_FILE=Packages.gz
|
||||
|
||||
if [ "x$1" == "x-h" ]; then
|
||||
echo "This script creates a directory with wifibox and ultifi ipk files found in the openWrt build environment. The feed dir is called $PKG_DEST_DIR and will be created in the current directory. (currently `pwd`)"
|
||||
echo "If specified, the -z option also compresses the result for easier transfer to a webserver."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d $PKG_DEST_DIR ]; then mkdir $PKG_DEST_DIR; fi
|
||||
cp $PKG_SRC_DIR/wifibox*.ipk $PKG_DEST_DIR
|
||||
cp $PKG_SRC_DIR/ultifi*.ipk $PKG_DEST_DIR
|
||||
cp $PKG_SRC_DIR/print3d*.ipk $PKG_DEST_DIR
|
||||
cd $PKG_DEST_DIR
|
||||
rm -f $INDEX_FILE
|
||||
rm -f $INDEX_GZ_FILE
|
||||
|
||||
|
||||
# NOTE: the aliasing construct in the indexing script does not work (and even then, the md5 command defaults to a different output format), so we hack around it here.
|
||||
MD5_HACK_ENABLED=0
|
||||
which md5sum >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
MD5_HACK_ENABLED=1
|
||||
TEMPBIN_DIR=/tmp/tempbin23QQDBR
|
||||
mkdir $TEMPBIN_DIR
|
||||
|
||||
cat <<EOF > $TEMPBIN_DIR/md5sum
|
||||
`type -p md5` -q \$1
|
||||
EOF
|
||||
|
||||
chmod +x $TEMPBIN_DIR/md5sum
|
||||
PATH=$PATH:$TEMPBIN_DIR
|
||||
fi
|
||||
|
||||
$MAKE_INDEX_SCRIPT . > $INDEX_FILE
|
||||
|
||||
if [ $MD5_HACK_ENABLED -eq 1 ]; then
|
||||
rm $TEMPBIN_DIR/md5sum
|
||||
rmdir $TEMPBIN_DIR
|
||||
fi
|
||||
|
||||
|
||||
gzip -c $INDEX_FILE > $INDEX_GZ_FILE
|
||||
|
||||
if [ "x$1" == "x-z" ]; then
|
||||
cd ..
|
||||
echo "Compressing generated package directory..."
|
||||
tar czvf $PKG_DEST_DIR.tgz $PKG_DEST_DIR
|
||||
fi
|
531
extra/scripts/publish-wifibox-release.lua
Executable file
531
extra/scripts/publish-wifibox-release.lua
Executable file
|
@ -0,0 +1,531 @@
|
|||
#!/usr/bin/env lua
|
||||
--#!/usr/bin/env lua -l strict
|
||||
|
||||
-- This script creates a new release by copying openwrt image files and release notes to a local
|
||||
-- directory and updating the relevant index file with a new entry. This directory is
|
||||
-- then synchronized to the release repository online.
|
||||
--
|
||||
-- USAGE:
|
||||
-- The only dependency of this script are the penlight and luafilesystem libraries, which can be installed using
|
||||
-- LuaRocks (http://luarocks.org/) as follows:
|
||||
-- $ sudo luarocks install penlight
|
||||
-- If the penlight libary is not found you might need to add the following to /etc/launchd.conf
|
||||
-- setenv LUA_CPATH /opt/local/share/luarocks/lib/lua/5.2/?.so
|
||||
-- setenv LUA_PATH /opt/local/share/luarocks/share/lua/5.2/?.lua
|
||||
-- Reboot
|
||||
-- Also see: https://github.com/keplerproject/luarocks/wiki/Using-LuaRocks#rocks-trees-and-the-lua-libraries-path
|
||||
--
|
||||
-- Lua + Luarocks installation on Linux:
|
||||
-- $ sudo apt-get install lua5.2 liblua5.2-dev
|
||||
-- # Build Luarocks from source, configured for lua 5.2:
|
||||
-- $ wget http://luarocks.org/releases/luarocks-2.2.2.tar.gz
|
||||
-- $ tar zxpf luarocks-2.2.2.tar.gz
|
||||
-- $ cd luarocks-2.2.2
|
||||
-- $ ./configure --lua-version=5.2
|
||||
-- $ sudo make bootstrap
|
||||
-- This script will automatically locate the Doodle3D repo's.
|
||||
-- Index files are fetched from the online repository.
|
||||
-- For synchronizing, rsync must have passwordless SSH access to the server, for a
|
||||
-- guide, see: http://www.linuxproblem.org/art_9.html.
|
||||
-- The scrips expects a alias named 'doodle3d.com', you can add this editing the following file:
|
||||
-- .ssh/config
|
||||
-- and adding
|
||||
-- Host doodle3d.com
|
||||
-- User webmaster@doodle3d.com
|
||||
-- HostName ftp.greenhost.nl
|
||||
-- Some basic sanity checks are built in (unique version, updated release notes, 'clean' openwrt config)
|
||||
-- but lots others are still missing (mainly: clean git repo's, freshly built images).
|
||||
-- The script must be run from within the openwrt build root. So it's handy to create a symlink
|
||||
-- to this file. You could to something like from the build root:
|
||||
-- ln -s ~/wrt-wifibox-feed/doodle3d-firmware/extra/scripts/publish-wifibox-release.lua .
|
||||
-- Then you can start with:
|
||||
-- cd trunk ../publish-wifibox-release.lua
|
||||
-- Before anything is actually uploaded, you will be asked if that's really what you want to do.
|
||||
-- It might be wise to make a backup on the server before updating it, there's a script
|
||||
-- to do this on the server: '~/backup-updates-dir.sh'.
|
||||
--
|
||||
-- To play around with or improve on this script, use and modify the variables 'SERVER_HOST'
|
||||
-- and 'SERVER_PATH' below to point to your machine (assuming you have a webserver running there).
|
||||
-- Also uncomment and modify UPDATER_BASE_URL. You will have to init the local 'repo' with at
|
||||
-- least empty index files ('wifibox-image.index' and 'wifibox-image.beta.index'), or you
|
||||
-- could of course mirror the online repository.
|
||||
--
|
||||
-- TODO (in random order):
|
||||
-- * (feature) command-line arguments: overrides, verbosity, allow local mirroring, clear local cache dir, etc.
|
||||
-- * (feature) automatically create a backup of the online repo (there's already a script fir this, as mentioned above)
|
||||
-- * (feature) check whether git repo's are clean and on correct branch
|
||||
-- * (feature) allow local mirroring with a reverse rsync command and rebuilding the indexes
|
||||
-- - update manager 'cache' should then be enabled to prevent fetchIndexTable from downloading files
|
||||
-- * (feature) automatically (re)build openwrt to ensure it is up to date?
|
||||
-- * (feature) update package feed (requires a local mirror for the feed indexing script)
|
||||
-- - in this case sanity checks must also be run on package versions/revisions
|
||||
-- * (feature) automatically tag (and merge?) git commits?
|
||||
-- * (feature) execute as dry-run by default so changes can be reviewed?
|
||||
-- * (refactor) rename awkward vars/funcs regarding entries, versions and caches...
|
||||
-- * (refactor) replace function arguments 'includeBetas' with a set function like setUseCache to improve readability
|
||||
-- * (refactor) replace prints with D() function from update manager or other slightly smarter mechanisms?
|
||||
|
||||
local function ERR(msg) print(msg) end
|
||||
|
||||
local ok, pl = pcall(require, 'pl.import_into')
|
||||
if not ok then
|
||||
ERR('This script requires the Penlight library')
|
||||
os.exit(2)
|
||||
end
|
||||
pl = pl()
|
||||
local um --- update manager module, will be loaded later through @{loadUpdateManager}
|
||||
|
||||
local ok, lfs = pcall(require, 'lfs')
|
||||
if not ok then
|
||||
ERR('This script requires the LuaFileSystem library')
|
||||
os.exit(2)
|
||||
end
|
||||
|
||||
-----------------------------
|
||||
-- CONSTANTS AND VARIABLES --
|
||||
-----------------------------
|
||||
|
||||
--local SERVER_HOST = 'localhost'
|
||||
--local SERVER_PATH = '~USERDIR/public_html/wifibox/updates'
|
||||
--local UPDATER_BASE_URL = 'http://localhost/~USERDIR/wifibox/updates'
|
||||
local SERVER_HOST = 'doodle3d.com'
|
||||
local SERVER_PATH = 'doodle3d.com/DEFAULT/updates'
|
||||
--- SERVER_HOST and SERVER_PATH are used by rsync to merge the local working directory
|
||||
-- back into the online repository (requires functioning public key SSH access).
|
||||
-- UPDATER_BASE_URL is used by the d3d-updater script to download the index files
|
||||
-- (over HTTP), it defaults to the doodle3d.com online repo so it should only be
|
||||
-- used for development purposes.
|
||||
|
||||
local D3D_REPO_FIRMWARE_NAME = 'doodle3d-firmware'
|
||||
local D3D_REPO_CLIENT_NAME = 'doodle3d-client'
|
||||
local D3D_REPO_PRINT3D_NAME = 'print3d'
|
||||
local IMAGE_BASENAME = 'doodle3d-wifibox'
|
||||
local BACKUP_FILE_SUFFIX = 'bkp'
|
||||
local RELEASE_NOTES_FILE = "ReleaseNotes.md"
|
||||
local RSYNC_TIMEOUT = 20
|
||||
local MAX_VIABLE_IMAGE_SIZE = 3500000
|
||||
|
||||
local deviceType = 'tl-mr3020' -- or 'tl-wr703'
|
||||
local lock = nil
|
||||
local paths = {}
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
-- UTILITY FUNCTIONS --
|
||||
-----------------------
|
||||
|
||||
local function loadUpdateManager()
|
||||
package.path = package.path .. ';' .. pl.path.join(paths.firmware, 'src') .. '/?.lua'
|
||||
local argStash = arg
|
||||
arg = nil
|
||||
um = require('script.d3d-updater') -- arg must be nil for the update manager to load as module
|
||||
arg = argStash
|
||||
end
|
||||
|
||||
local function quit(ev)
|
||||
if lock then lock:free() end
|
||||
os.exit(ev or 0)
|
||||
end
|
||||
|
||||
local function md5sum(file)
|
||||
-- try OS X specific md5 utility
|
||||
local rv,_,sum = pl.utils.executeex('md5 -q "' .. file .. '"')
|
||||
if rv then
|
||||
return rv and sum:sub(1, -2) or nil
|
||||
end
|
||||
-- try Linux md5sum utility
|
||||
local rv,_,output = pl.utils.executeex('md5sum "' .. file .. '"')
|
||||
local md5 = string.match(output, "[^%s]+")
|
||||
return md5
|
||||
end
|
||||
|
||||
local function getYesNo(question)
|
||||
local answer
|
||||
repeat
|
||||
io.write(question)
|
||||
io.flush()
|
||||
answer = io.stdin:read('*line'):lower()
|
||||
until answer == 'yes' or answer == 'y' or answer == 'no' or answer == 'n'
|
||||
|
||||
return (answer:sub(1, 1) == 'y') and true or false
|
||||
end
|
||||
|
||||
local function detectRootPrivileges()
|
||||
local rv,_,userId = pl.utils.executeex('id -u')
|
||||
if not rv then return nil end
|
||||
|
||||
return tonumber(userId) == 0 and true or false
|
||||
end
|
||||
|
||||
local function findInFile(needle, file)
|
||||
local f = io.open(file, 'r')
|
||||
if not f then return nil,"could not open file" end
|
||||
|
||||
local t = f:read('*all')
|
||||
return not not t:find(needle, 1, true)
|
||||
end
|
||||
|
||||
local function fileExists(path)
|
||||
local attr = lfs.attributes (path)
|
||||
return attr ~= nil
|
||||
end
|
||||
|
||||
local function detectBuildroot()
|
||||
if not fileExists("customfeeds") or not fileExists("bin") then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- returns uri (file path) of the wifibox feed, nil if not found or nil+msg on error
|
||||
-- recognized feed names are 'wifibox' and 'doodle3d' (case-insensitive)
|
||||
local function getWifiboxFeedRoot(feedsFile)
|
||||
local typ, nam, uri = nil, nil, nil
|
||||
local lineNo = 1
|
||||
local f = io.open(feedsFile, 'r')
|
||||
|
||||
if not f then return nil, "could not open '" .. feedsFile .. '"' end
|
||||
|
||||
for line in f:lines() do
|
||||
typ, nam, uri = line:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)$')
|
||||
|
||||
if not (typ and nam and uri) then
|
||||
f:close()
|
||||
return uri or nil, "could not parse line " .. feedsFile .. "#" .. lineNo
|
||||
end
|
||||
|
||||
local commented = (typ:find('#') == 1)
|
||||
if not commented and (nam:lower() == 'wifibox' or nam:lower() == 'doodle3d') then
|
||||
break
|
||||
else
|
||||
typ, nam, uri = nil, nil, nil
|
||||
end
|
||||
|
||||
lineNo = lineNo + 1
|
||||
end
|
||||
|
||||
if uri and not (typ == 'src-link' or typ == 'src-cpy') then return nil, "d3d feed has wrong type '" .. typ .. "', use 'src-link' or 'src-cpy'" end
|
||||
|
||||
f:close()
|
||||
return uri
|
||||
end
|
||||
|
||||
-- TODO: pass table to functions to fill in? if they all return either true or nil+msg, that could be used for display of ok/msg
|
||||
-- returns true on success, false on error, and displays meaningful messages
|
||||
--local function runCheck(msg, processFunc)
|
||||
-- io.write(msg .. "... ")
|
||||
-- return processFunc(--[[ hmm ]]--)
|
||||
--end
|
||||
|
||||
local function runAction(actMsg, errMsg, ev, func)
|
||||
io.write("* " .. actMsg .. "...")
|
||||
local rv,err = func()
|
||||
if not rv then
|
||||
if err then print("Error: " .. errMsg .. " (" .. err .. ")")
|
||||
else print("Error: " .. errMsg)
|
||||
end
|
||||
quit(ev)
|
||||
else
|
||||
print("ok")
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local function constructImageName(version, devType, sysupOrFactory)
|
||||
return IMAGE_BASENAME .. '-' .. um.formatVersion(version) .. '-' .. devType .. '-' .. sysupOrFactory .. '.bin'
|
||||
end
|
||||
|
||||
local function imageCachePath()
|
||||
return pl.path.join(paths.cache, 'images')
|
||||
end
|
||||
|
||||
local function ensureFilePresent(src, tgt)
|
||||
-- print("About to copy '" .. src .. "' => '" .. tgt .. "'")
|
||||
local srcMd5, tgtMd5 = md5sum(src), md5sum(tgt)
|
||||
|
||||
if not srcMd5 then return nil,"source file does not exist" end
|
||||
if tgtMd5 and srcMd5 ~= tgtMd5 then return nil,"target file already exists but is different from source file" end
|
||||
|
||||
if not tgtMd5 then
|
||||
if not pl.file.copy(src, tgt, false) then return nil,"could not copy file" end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------
|
||||
-- MAIN FUNCTIONS --
|
||||
--------------------
|
||||
|
||||
local function prepare()
|
||||
local msg = nil
|
||||
|
||||
io.write("* Looking for Doodle3D feed path... ")
|
||||
-- local d3dFeed,msg = getWifiboxFeedRoot('feeds.conf')
|
||||
-- if d3dFeed then
|
||||
-- print("found " .. d3dFeed)
|
||||
-- else
|
||||
-- if msg then print("not found: " .. msg) else print("not found.") end
|
||||
-- return nil
|
||||
-- end
|
||||
local d3dFeed = "customfeeds"
|
||||
|
||||
paths.firmware = pl.path.join(d3dFeed, D3D_REPO_FIRMWARE_NAME)
|
||||
paths.client = pl.path.join(d3dFeed, D3D_REPO_CLIENT_NAME)
|
||||
paths.print3d = pl.path.join(d3dFeed, D3D_REPO_PRINT3D_NAME)
|
||||
|
||||
-- if empty, try to choose something sensible
|
||||
if not paths.cache or paths.cache == '' then
|
||||
--paths.cache = pl.app.appfile('')
|
||||
paths.cache = '/tmp/d3d-release-dir'
|
||||
end
|
||||
io.write("* Attempting to use " .. paths.cache .. " as cache dir... ")
|
||||
local rv,msg = pl.dir.makepath(paths.cache)
|
||||
if not rv then
|
||||
print("could not create path (" .. msg .. ").")
|
||||
return nil
|
||||
end
|
||||
|
||||
loadUpdateManager()
|
||||
|
||||
local rv,msg = pl.dir.makepath(imageCachePath())
|
||||
if not rv then
|
||||
print("could not create images dir (" .. msg .. ").")
|
||||
return nil
|
||||
end
|
||||
|
||||
lock,msg = lfs.lock_dir(paths.cache)
|
||||
if not lock then
|
||||
print("could not obtain directory lock (" .. msg .. ").")
|
||||
return nil
|
||||
else
|
||||
print("ok")
|
||||
end
|
||||
|
||||
-- initialize update manager script
|
||||
um.setUseCache(false)
|
||||
um.setVerbosity(1)
|
||||
um.setCachePath(imageCachePath())
|
||||
if type(UPDATER_BASE_URL) == 'string' and UPDATER_BASE_URL:len() > 0 then
|
||||
print("* Using updater base URL: '" .. UPDATER_BASE_URL .. "'")
|
||||
um.setBaseUrl(UPDATER_BASE_URL)
|
||||
else
|
||||
print("* Using updater base URL: d3d-updater default")
|
||||
end
|
||||
|
||||
print("* Using rsync server remote: '" .. SERVER_HOST .. "/" .. SERVER_PATH .. "'")
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function collectLocalInfo()
|
||||
local info = {}
|
||||
|
||||
-- temporary fields required for copying image files
|
||||
info.factoryImgPath = pl.path.join(paths.root, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-factory.bin')
|
||||
info.sysupgradeImgPath = pl.path.join(paths.root, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-sysupgrade.bin')
|
||||
|
||||
info.version = um.parseVersion(pl.file.read(pl.path.join(paths.firmware, 'src/FIRMWARE-VERSION')))
|
||||
if not info.version then return nil,"could not determine current firmware version" end
|
||||
|
||||
info.factoryFileSize = pl.path.getsize(info.factoryImgPath)
|
||||
if not info.factoryFileSize then return nil,"could not determine size for factory image" end
|
||||
|
||||
info.sysupgradeFileSize = pl.path.getsize(info.sysupgradeImgPath)
|
||||
if not info.sysupgradeFileSize then return nil,"could not determine size for sysupgrade image" end
|
||||
|
||||
info.factoryMD5 = md5sum(info.factoryImgPath)
|
||||
info.sysupgradeMD5 = md5sum(info.sysupgradeImgPath)
|
||||
if not info.factoryMD5 or not info.sysupgradeMD5 then return nil,"could not determine MD5 sum for image(s)" end
|
||||
|
||||
info.factoryFilename = constructImageName(info.version, deviceType, 'factory')
|
||||
info.sysupgradeFilename = constructImageName(info.version, deviceType, 'sysupgrade')
|
||||
info.timestamp = os.time()
|
||||
|
||||
return info
|
||||
end
|
||||
|
||||
local function fetchVersionInfo()
|
||||
local msg,stables,betas = nil,nil,nil
|
||||
|
||||
stables,msg = um.getAvailableVersions('stables')
|
||||
if not stables then return nil,msg end
|
||||
|
||||
betas,msg = um.getAvailableVersions('betas')
|
||||
if not betas then return nil,msg end
|
||||
|
||||
return stables, betas
|
||||
end
|
||||
|
||||
local function generateIndex(newVersion, versionTable, isStable)
|
||||
local indexFilename = isStable and um.IMAGE_STABLE_INDEX_FILE or um.IMAGE_BETA_INDEX_FILE
|
||||
versionTable[#versionTable+1] = newVersion
|
||||
local sortedVers = pl.List(versionTable)
|
||||
sortedVers:sort(function(a, b)
|
||||
return um.compareVersions(a.version, b.version, a.timestamp, b.timestamp) < 0
|
||||
end)
|
||||
|
||||
local indexPath = pl.path.join(imageCachePath(), indexFilename)
|
||||
local rv = pl.file.copy(indexPath, pl.path.join(paths.cache, indexFilename..'.'..BACKUP_FILE_SUFFIX))
|
||||
if not rv then return nil,"could not backup index file" end
|
||||
|
||||
local idxFile = io.open(pl.path.join(imageCachePath(), indexFilename), 'w')
|
||||
if not idxFile then return nil,"could not open index file for writing" end
|
||||
|
||||
sortedVers:foreach(function(el)
|
||||
idxFile:write("Version: " .. um.formatVersion(el.version) .. "\n")
|
||||
idxFile:write("Files: " .. el.sysupgradeFilename .. "; " .. el.factoryFilename .. "\n")
|
||||
idxFile:write("FileSize: " .. el.sysupgradeFileSize .. "; " .. el.factoryFileSize .. "\n")
|
||||
idxFile:write("MD5: " .. el.sysupgradeMD5 .. "; " .. el.factoryMD5 .. "\n")
|
||||
if el.timestamp then idxFile:write("ReleaseDate: " .. um.formatDate(el.timestamp) .. "\n") end
|
||||
end)
|
||||
|
||||
idxFile:close()
|
||||
return 0
|
||||
end
|
||||
|
||||
local function copyImages(newVersion)
|
||||
local rv,msg
|
||||
rv,msg = ensureFilePresent(newVersion.factoryImgPath, pl.path.join(imageCachePath(), newVersion.factoryFilename))
|
||||
if not rv then return nil,msg end
|
||||
|
||||
rv,msg = ensureFilePresent(newVersion.sysupgradeImgPath, pl.path.join(imageCachePath(), newVersion.sysupgradeFilename))
|
||||
if not rv then return nil,msg end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function copyReleaseNotes(newVersion)
|
||||
local srcReleaseNotesPath = pl.path.join(paths.firmware, RELEASE_NOTES_FILE)
|
||||
local tgtReleaseNotesPath = pl.path.join(imageCachePath(), RELEASE_NOTES_FILE)
|
||||
|
||||
if not findInFile(um.formatVersion(newVersion.version), srcReleaseNotesPath) then
|
||||
return nil,"version not mentioned in release notes file"
|
||||
end
|
||||
|
||||
if pl.path.isfile(tgtReleaseNotesPath) then
|
||||
local rv = pl.file.copy(tgtReleaseNotesPath, tgtReleaseNotesPath..'.'..BACKUP_FILE_SUFFIX)
|
||||
if not rv then return nil,"could not backup file" end
|
||||
end
|
||||
|
||||
local rv = pl.file.copy(srcReleaseNotesPath, tgtReleaseNotesPath)
|
||||
if not rv then return nil,"could not copy file" end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- TODO: the packages are not really used and the openwrt script to generate the
|
||||
-- package index requires all packages to be present so this has been skipped for now
|
||||
local function buildFeedDir()
|
||||
local scriptPath = pl.path.join(paths.root, 'scripts/ipkg-make-index.sh')
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local function uploadFiles()
|
||||
local serverUrl = SERVER_HOST..':'..SERVER_PATH
|
||||
-- rsync options are: recursive, preserve perms, symlinks and timestamps, be verbose and use compression
|
||||
local cmd = "rsync -rpltvz -e ssh --progress --timeout=" .. RSYNC_TIMEOUT .. " --exclude '*.bkp' --exclude 'lockfile.lfs' " .. paths.cache .. "/* " .. serverUrl
|
||||
print("Running command: '" .. cmd .. "'")
|
||||
local rv,ev = um.compatexecute(cmd)
|
||||
return rv and true or nil,("rsync failed, exit status: " .. ev)
|
||||
end
|
||||
|
||||
local function main()
|
||||
print("\nDoodle3D release script")
|
||||
if detectRootPrivileges() then
|
||||
print("Error: refusing to run script as root.")
|
||||
quit(99)
|
||||
end
|
||||
|
||||
-- local opts = parseOptions(arg)
|
||||
--
|
||||
-- if opts['wrt-root'] then changedir(opts['wrt-root']) end
|
||||
-- if opts['cache-dir'] then paths.cache = opts['cache-dir'] end
|
||||
-- more options: clear cache, rebuild (download all and generate index from actual files), dry-run, force
|
||||
|
||||
io.write("* Checking if working directory is the Buildroot... ")
|
||||
local isBuildroot = detectBuildroot()
|
||||
if isBuildroot then
|
||||
paths.root = pl.path.currentdir()
|
||||
print("found " .. paths.root)
|
||||
else
|
||||
print("unrecognized directory, try changing directories or using -wrt-root")
|
||||
return nil
|
||||
end
|
||||
|
||||
if not prepare() then quit(1) end
|
||||
|
||||
|
||||
local newVersion,msg = collectLocalInfo()
|
||||
if not newVersion then
|
||||
print("Error: could not collect local version information (" .. msg .. ")")
|
||||
quit(3)
|
||||
end
|
||||
|
||||
local stables,betas = fetchVersionInfo()
|
||||
if not stables then
|
||||
print("Error: could not get version information (" .. betas .. ")")
|
||||
quit(1)
|
||||
end
|
||||
|
||||
--TODO: if requested, fetch images and packages (i.e., mirror whole directory)
|
||||
|
||||
-- pl.pretty.dump(newVersion)
|
||||
-- print("stables: "); pl.pretty.dump(stables)
|
||||
-- print("===========================");
|
||||
-- print("betas: "); pl.pretty.dump(betas)
|
||||
|
||||
|
||||
print("\nRunning sanity checks")
|
||||
|
||||
runAction("Checking whether version is unique",
|
||||
"firmware version " .. um.formatVersion(newVersion.version) .. " already exists", 3, function()
|
||||
return not (um.findVersion(newVersion.version, nil, stables) or um.findVersion(newVersion.version, nil, betas)) and true or nil
|
||||
end)
|
||||
|
||||
--TODO: check git repos (`git log -n 1 --pretty=format:%ct` gives commit date of last commit (not author date))
|
||||
|
||||
local isStable = (newVersion.version.suffix == nil)
|
||||
print("\nRolling release for firmware version " .. um.formatVersion(newVersion.version) .. " (type: " .. (isStable and "stable" or "beta") .. ").")
|
||||
|
||||
if newVersion.sysupgradeFileSize > MAX_VIABLE_IMAGE_SIZE then
|
||||
print("Error: sysupgrade image file is too large, it will not run well (max. size: " .. MAX_VIABLE_IMAGE_SIZE .. " bytes)")
|
||||
quit(4)
|
||||
end
|
||||
|
||||
runAction("Copying release notes", "failed", 5, function()
|
||||
return copyReleaseNotes(newVersion)
|
||||
end)
|
||||
|
||||
runAction("Generating new index file", "could not generate index", 5, function()
|
||||
return generateIndex(newVersion, isStable and stables or betas, isStable)
|
||||
end)
|
||||
|
||||
runAction("Copying image files", "could not generate index", 5, function()
|
||||
return copyImages(newVersion)
|
||||
end)
|
||||
|
||||
io.write("* Building package feed directory...")
|
||||
print("skipped - not implemented")
|
||||
-- runAction("Building package feed directory", "failed", 5, buildFeedDir)
|
||||
|
||||
local answer = getYesNo("? Are you SURE you want to publish? (y/n) ")
|
||||
if answer ~= true then
|
||||
print("Did not get green light, quitting.")
|
||||
quit(5)
|
||||
end
|
||||
|
||||
runAction("About to sync files to server", "could not upload files", 6, uploadFiles)
|
||||
|
||||
print("Released version " .. um.formatVersion(newVersion.version) .. "!")
|
||||
quit()
|
||||
end
|
||||
|
||||
main()
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is merely for conveniently generating the packages feed directory in ~/Sites (e.g. for use with XAMPP or the like). Modify WIFIBOX_BASE_DIR to point to your wifibox directory tree.
|
||||
|
||||
WIFIBOX_BASE_DIR=~/Files/_devel/eclipse-workspace/wifibox
|
||||
|
||||
cd ~/Sites
|
||||
$WIFIBOX_BASE_DIR/extra/scripts/create-packages-feed-dir.sh
|
18
license-spec.lua
Normal file
18
license-spec.lua
Normal file
|
@ -0,0 +1,18 @@
|
|||
local M = {
|
||||
BASE_PATH = 'src',
|
||||
EXCLUDE_FILES = { 'src/util/JSON.lua', 'src/util/urlcode.lua', 'src/script/loglite%-filters.lua' },
|
||||
PROCESS_FILES = {
|
||||
['src/[^/]*%.lua'] = 'lua',
|
||||
['src/network/[^/]*%.lua'] = 'lua',
|
||||
['src/rest/[^/]*%.lua'] = 'lua',
|
||||
['src/rest/api/[^/]*%.lua'] = 'lua',
|
||||
['src/script/[^/]*%.lua'] = 'lua',
|
||||
['src/util/[^/]*%.lua'] = 'lua',
|
||||
['src/script/d3dapi'] = 'sh',
|
||||
['src/script/dhcpcheck_init'] = 'sh',
|
||||
['src/script/signin%.sh'] = 'sh',
|
||||
['src/script/wifibox_init'] = 'sh'
|
||||
},
|
||||
IGNORE_GIT_CHANGED = false
|
||||
}
|
||||
return M
|
101
post-install.sh
101
post-install.sh
|
@ -36,15 +36,18 @@ addFirewallNet() {
|
|||
### Replace the banner with a custom one
|
||||
if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
|
||||
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
||||
cat <<-'EOM' > $IPKG_INSTROOT/etc/banner
|
||||
........D o o d l e 3 D
|
||||
.......________ _____ _____ v \$(PACKAGE_VERSION)
|
||||
....../ / / |__ / __/ / - /___ __
|
||||
...../ / / /--// _|-// --| . /v /
|
||||
..../________/__//__/__//____/___/_^_\
|
||||
...
|
||||
..A cad in a box.
|
||||
.
|
||||
cat <<-\EOM > $IPKG_INSTROOT/etc/banner
|
||||
,------. ,--.,--. ,----. ,------.
|
||||
| .-. \ ,---. ,---. ,-| || | ,---. '.-. || .-. \
|
||||
| | \ :| .-. || .-. |' .-. || || .-. : .' < | | \ :
|
||||
| '--' /' '-' '' '-' '\ `-' || |\ --./'-' || '--' /
|
||||
`-------' `---' `---' `---' `--' `----'`----' `-------'
|
||||
__ ___ ______ _ ____
|
||||
\ \ / (_) ____(_) | _ \
|
||||
\ \ /\ / / _| |__ _ ______| |_) | _____ __
|
||||
\ \/ \/ / | | __| | |______| _ < / _ \ \/ /
|
||||
\ /\ / | | | | | | |_) | (_) > <
|
||||
\/ \/ |_|_| |_| |____/ \___/_/\_\
|
||||
EOM
|
||||
fi
|
||||
|
||||
|
@ -52,51 +55,111 @@ fi
|
|||
mkdir -p $IPKG_INSTROOT/root
|
||||
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
||||
if [ $? -gt 0 ]; then
|
||||
cat <<-EOM >> $IPKG_INSTROOT/root/.profile
|
||||
|
||||
cat <<-\EOM >> $IPKG_INSTROOT/root/.profile
|
||||
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
||||
alias d='ls -la'
|
||||
alias d3dapi='/usr/share/lua/wifibox/script/d3dapi'
|
||||
alias encore='ulimit -c unlimited'
|
||||
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
||||
|
||||
alias tailfw='loglite /tmp/wifibox.log firmware'
|
||||
tailp3d() {
|
||||
logfile=/tmp/print3d-ttyACM0.log
|
||||
if [ $# -gt 0 ]; then logfile=$1; fi
|
||||
loglite "$logfile" print3d
|
||||
}
|
||||
|
||||
loop() {
|
||||
if [ \$# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
||||
DELAY=\$1; shift; while true; do \$@; sleep \$DELAY; done
|
||||
if [ $# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
||||
DELAY=$1; shift; while true; do $@; sleep $DELAY; done
|
||||
}
|
||||
EOM
|
||||
fi
|
||||
|
||||
#preserve saved sketches during firmware update
|
||||
echo "/root/sketches" >> $IPKG_INSTROOT/etc/sysupgrade.conf
|
||||
|
||||
|
||||
|
||||
### Finally make sure basic configuration is set correctly
|
||||
|
||||
$IPKG_INSTROOT/etc/init.d/wifibox enable
|
||||
LOGROTATE_CRON_LINE="*/2 * * * * /usr/sbin/logrotate /etc/logrotate.conf"
|
||||
|
||||
if [ -z "$IPKG_INSTROOT" ]; then
|
||||
echo "Enabling wifi device..."
|
||||
uci set wireless.@wifi-device[0].disabled=0; uci commit wireless; wifi
|
||||
# No installation root, we are being installed on a live box so run uci commands directly.
|
||||
|
||||
echo "Enabling and configuring wifi device..."
|
||||
uci set wireless.@wifi-device[0].disabled=0
|
||||
uci delete wireless.radio0.channel
|
||||
uci commit wireless; wifi
|
||||
|
||||
echo "Disabling default route and DNS server for lan network interface..."
|
||||
uci set dhcp.lan.dhcp_option='3 6'
|
||||
uci commit dhcp; /etc/init.d/dnsmasq reload
|
||||
|
||||
addFirewallNet
|
||||
|
||||
echo "Adding network interface 'wlan'..."
|
||||
uci set network.wlan=interface; uci commit network; /etc/init.d/network reload
|
||||
uci set network.wlan=interface
|
||||
uci commit network; /etc/init.d/network reload
|
||||
|
||||
echo "Setting default wifibox log level..."
|
||||
uci set wifibox.general.system_log_level='info'
|
||||
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
||||
uci commit wifibox
|
||||
|
||||
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
# add line, method from http://askubuntu.com/a/58582
|
||||
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
||||
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
||||
fi
|
||||
|
||||
else
|
||||
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0
|
||||
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0.
|
||||
|
||||
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
||||
uci set system.@system[0].hostname=wifibox
|
||||
uci set system.@system[0].log_size=64
|
||||
uci set network.lan.ipaddr=192.168.5.1
|
||||
echo -e "beta\nbeta" | passwd root
|
||||
|
||||
# uhttpd config: https://wiki.openwrt.org/doc/uci/uhttpd#server_settings
|
||||
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
||||
uci set uhttpd.main.lua_prefix='/d3dapi'
|
||||
uci set uhttpd.main.max_requests='10'
|
||||
|
||||
uci set wireless.@wifi-device[0].disabled=0
|
||||
uci delete wireless.radio0.channel
|
||||
# TODO: add firewall net
|
||||
uci set network.wlan=interface
|
||||
|
||||
uci set dhcp.lan.dhcp_option='3 6'
|
||||
|
||||
uci set wifibox.general.system_log_level='info'
|
||||
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
||||
|
||||
# update wifibox's config for config changes in 0.10.10
|
||||
uci set wifibox.system.log_path='/tmp'
|
||||
uci set wifibox.system.api_log_filename='wifibox.log'
|
||||
uci set wifibox.system.p3d_log_basename='print3d'
|
||||
|
||||
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
# add line, method from http://askubuntu.com/a/58582
|
||||
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
||||
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
||||
fi
|
||||
|
||||
exit 0
|
||||
EOM
|
||||
|
||||
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
||||
fi
|
||||
|
||||
$IPKG_INSTROOT/etc/init.d/wifibox enable
|
||||
$IPKG_INSTROOT/etc/init.d/wifibox start
|
||||
$IPKG_INSTROOT/etc/init.d/dhcpcheck enable
|
||||
$IPKG_INSTROOT/etc/init.d/cron enable
|
||||
$IPKG_INSTROOT/etc/init.d/cron start
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -14,14 +14,7 @@ rmdir /usr/share/lua/wifibox/util
|
|||
rmdir /usr/share/lua/wifibox
|
||||
rmdir /usr/share/lua
|
||||
|
||||
# Try to remove all www directories used by the package, and intentionally leave anything non-empty alone
|
||||
rmdir /www/js/libs
|
||||
rmdir /www/js
|
||||
rmdir /www/img/buttons
|
||||
rmdir /www/img
|
||||
rmdir /www/css
|
||||
rm /www/test 2> /dev/null
|
||||
rmdir /www/cgi-bin
|
||||
#rm /www/test 2> /dev/null
|
||||
|
||||
echo "The wifibox banner has been removed. Changes to the root profile however, have"
|
||||
echo "not been reverted, as haven't the wlan firewall zone and the radio0 device state."
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
$IPKG_INSTROOT/etc/init.d/wifibox stop
|
||||
$IPKG_INSTROOT/etc/init.d/wifibox disable
|
||||
|
||||
exit 0
|
||||
|
|
1
src/FIRMWARE-VERSION
Normal file
1
src/FIRMWARE-VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
0.11.0
|
|
@ -1,9 +1,3 @@
|
|||
GPX_PATH := util/GPX.git
|
||||
|
||||
.PHONY: $(GPX_PATH)
|
||||
|
||||
all:
|
||||
$(MAKE) -C $(GPX_PATH)
|
||||
|
||||
clean:
|
||||
$(MAKE) -C $(GPX_PATH) clean
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
--- This file wraps handle_request(env) in main.lua for command-line or CGI usage.
|
||||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- This file wraps @{main.handle_request} in main.lua for command-line or CGI usage.
|
||||
-- It emulates the env table usually constructed by uhttpd-mod-lua.
|
||||
local main = require('main')
|
||||
|
||||
--- Create an environment table mimicking the table uhttpd-mod-lua passes into handle_request().
|
||||
-- The table is created using shell environment variables leaving out only 'DOCUMENT_ROOT',
|
||||
-- 'SCRIPT_PATH' and the regular shell variables (e.g. IFS, HOME and PS1).
|
||||
-- Fields present in the 'real' env table but not in this one are: 'HTTP_VERSION'
|
||||
-- and another table 'headers' which is mostly mirrored by the 'HTTP_*' fields.
|
||||
-- Note that the 'headers' table may contain extra fields (e.g. 'cache-control').
|
||||
--- Create an environment table mimicking the table uhttpd-mod-lua passes into @{main.handle_request}.
|
||||
--
|
||||
-- The table is created using shell environment variables leaving out only 'DOCUMENT\_ROOT',
|
||||
-- 'SCRIPT\_PATH' and the regular shell variables (e.g., IFS, HOME and PS1).
|
||||
--
|
||||
-- See [information on CGI environment variables](http://techpubs.sgi.com/library/dynaweb_docs/0530/SGI_Developer/books/NetscapeSrv_PG/sgi_html/ch01.html).
|
||||
--
|
||||
-- Fields present in the 'real' env table but not in this one are: 'HTTP\_VERSION'
|
||||
-- and another table 'headers' which is mostly mirrored by the 'HTTP\_*' fields.
|
||||
-- Note that the 'headers' table may contain extra fields (e.g., 'cache-control').
|
||||
-- @treturn table An environment table created from shell environment variables.
|
||||
local function createEnvTableFromShellEnvironment()
|
||||
local environ = {}
|
||||
|
||||
|
||||
environ['CONTENT_LENGTH'] = os.getenv('CONTENT_LENGTH') or ''
|
||||
environ['CONTENT_TYPE'] = os.getenv('CONTENT_TYPE') or ''
|
||||
environ['GATEWAY_INTERFACE'] = os.getenv('GATEWAY_INTERFACE') or ''
|
||||
|
@ -40,7 +53,7 @@ local function createEnvTableFromShellEnvironment()
|
|||
environ['SERVER_PORT'] = os.getenv('SERVER_PORT') or ''
|
||||
environ['SERVER_PROTOCOL'] = os.getenv('SERVER_PROTOCOL') or ''
|
||||
environ['SERVER_SOFTWARE'] = os.getenv('SERVER_SOFTWARE') or ''
|
||||
|
||||
|
||||
return environ
|
||||
end
|
||||
|
||||
|
|
|
@ -1,32 +1,66 @@
|
|||
--[[--
|
||||
TODO: finish documentation
|
||||
This file contains all valid configuration keys, their default values and optional constraints.
|
||||
The table names are used as configuration key names, where underscores ('_') may be used to denote semi-categories.
|
||||
The settings interface replaces periods ('.') by underscores so for instance 'network.ap.address' will
|
||||
be translated to 'network_ap_address'. Multi-word names should be notated as camelCase.
|
||||
Valid fields for the tables are:
|
||||
- default: the default value (used when the key is not set in UCI config)
|
||||
- type: used for basic type checking, one of bool, int, float or string
|
||||
- description: A descriptive text usable by API clients
|
||||
- min, max, regex: optional constraints (min and max constrain value for numbers, or length for strings)
|
||||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
NOTE that the all-caps definitions will be changed into configuration keys, or moved to a different location
|
||||
]]--
|
||||
|
||||
---
|
||||
-- This file contains all valid configuration keys, their default values and optional constraints.
|
||||
-- The table names are used as configuration key names, where underscores ('`_`') may be used to denote semi-categories.
|
||||
-- The settings interface replaces periods ('`.`') by underscores so for instance `network.ap.address` will
|
||||
-- be translated to `network_ap_address`. Multi-word names should be notated as camelCase.
|
||||
--
|
||||
-- Valid fields for the tables are:
|
||||
--
|
||||
-- - _default_: the default value (used when the key is not set in UCI config)
|
||||
-- - _type_: used for basic type checking, one of bool, int, float or string
|
||||
-- - _description_: A descriptive text usable by API clients
|
||||
-- - _min_, _max_, _regex_: optional constraints (min and max constrain value for numbers, or length for strings)
|
||||
-- - _isValid_: an optional function which should return true for valid values and false for invalid ones
|
||||
-- - _subSection: optional: setting name of which current value is used as the uci section where this setting should be loaded from. Otherwise it's retrieved from the generic section. Setting subsection also means it will first try to get a default from subconf_defaults, if that doesn't exsist it will use the regular default
|
||||
-- The configuration keys themselves document themselves rather well, hence they are not included in the generated documentation.
|
||||
--
|
||||
-- NOTE: the all-caps definitions should be changed into configuration keys, or moved to a better location.
|
||||
local printer = require('util.printer')
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
|
||||
local M = {}
|
||||
|
||||
--NOTE: pcall protects from invocation exceptions, which is what we need except
|
||||
--during debugging. This flag replaces them with a normal call so we can inspect stack traces.
|
||||
--- This constant should only be true during development. It replaces `pcall` by regular `call`.
|
||||
-- Pcall protects the script from invocation exceptions, which is what we need except during debugging.
|
||||
-- When this flag is true, normal calls will be used so we can inspect stack traces.
|
||||
M.DEBUG_PCALLS = false
|
||||
|
||||
--This enables debugging of the REST API from the command-line, specify the path and optionally the request method as follows: 'p=/mod/func rq=POST'
|
||||
--- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests.
|
||||
-- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`.
|
||||
-- Note that the command-line script redirects the output streams to '/tmp/wifibox.stdout.log',
|
||||
-- meaning that any stack traces can be found there.
|
||||
M.DEBUG_API = true
|
||||
|
||||
--REST responses will contain 'module' and 'function' keys describing what was requested
|
||||
--- If enabled, REST responses will contain 'module' and 'function' keys describing what was requested.
|
||||
M.API_INCLUDE_ENDPOINT_INFO = false
|
||||
|
||||
M.API_BASE_URL_PATH = 'doodle3d.com' -- includes any base path if necessary (e.g. 'localhost/~user')
|
||||
--- This base path is used in @{rest.response}. It includes any base path if necessary (e.g. 'localhost/~user').
|
||||
M.API_BASE_URL_PATH = 'doodle3d.com'
|
||||
|
||||
M.system_log_level = {
|
||||
default = 'info',
|
||||
type = 'string',
|
||||
description = 'Log level for firmware and print server',
|
||||
isValid = function(value)
|
||||
-- Note: level names mimic those in print3d
|
||||
levelNames = { 'quiet', 'error', 'warning', 'info', 'verbose', 'bulk' }
|
||||
for i,v in ipairs(levelNames) do
|
||||
if value == v then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false, 'not one of '..table.concat(levelNames, ',')
|
||||
end
|
||||
}
|
||||
|
||||
M.network_ap_ssid = {
|
||||
default = 'Doodle3D-%%MAC_ADDR_TAIL%%',
|
||||
|
@ -44,9 +78,20 @@ M.network_ap_address = {
|
|||
}
|
||||
|
||||
M.network_ap_key = {
|
||||
default = '',
|
||||
type = 'string',
|
||||
description = 'Access Point security key'
|
||||
default = '',
|
||||
type = 'string',
|
||||
description = 'Access Point security key',
|
||||
isValid = function(value)
|
||||
if value == "" then
|
||||
return true;
|
||||
elseif value:len() < 8 then
|
||||
return false, "too short"
|
||||
elseif value:len() > 63 then
|
||||
return false, "too long"
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
M.network_ap_netmask = {
|
||||
|
@ -74,6 +119,138 @@ M.printer_type = {
|
|||
end
|
||||
}
|
||||
|
||||
M.printer_dimensions_x = {
|
||||
default = 200,
|
||||
default_delta_rostockmax = 0,
|
||||
default__3Dison_plus = 227,
|
||||
default_deltamaker = 0,
|
||||
default_kossel = 0,
|
||||
default_minifactory = 150,
|
||||
default_lulzbot_taz_4 = 298,
|
||||
default_ultimaker2go = 120,
|
||||
default_renkforce_rf100 = 100,
|
||||
default_doodle_dream = 120,
|
||||
default_wanhao_duplicator4 = 210,
|
||||
default_colido_2_0_plus = 230,
|
||||
default_colido_x3045 = 300,
|
||||
default_colido_compact = 130,
|
||||
default_craftbot_plus = 250,
|
||||
subSection = 'printer_type',
|
||||
type = 'int',
|
||||
description = '',
|
||||
min = 0
|
||||
}
|
||||
M.printer_dimensions_y = {
|
||||
default = 200,
|
||||
default_delta_rostockmax = 0,
|
||||
default__3Dison_plus = 148,
|
||||
default_deltamaker = 0,
|
||||
default_kossel = 0,
|
||||
default_minifactory = 150,
|
||||
default_lulzbot_taz_4 = 275,
|
||||
default_ultimaker2go = 120,
|
||||
default_renkforce_rf100 = 100,
|
||||
default_doodle_dream = 120,
|
||||
default_wanhao_duplicator4 = 140,
|
||||
default_colido_2_0_plus = 150,
|
||||
default_colido_x3045 = 300,
|
||||
default_colido_compact = 130,
|
||||
subSection = 'printer_type',
|
||||
type = 'int',
|
||||
description = '',
|
||||
min = 0
|
||||
}
|
||||
M.printer_dimensions_z = {
|
||||
default = 200,
|
||||
default_minifactory = 155,
|
||||
default__3Dison_plus = 150,
|
||||
default_lulzbot_taz_4 = 250,
|
||||
default_ultimaker2go = 112,
|
||||
default_renkforce_rf100 = 100,
|
||||
default_doodle_dream = 80,
|
||||
default_wanhao_duplicator4 = 140,
|
||||
default_colido_2_0_plus = 140,
|
||||
default_colido_x3045 = 450,
|
||||
default_colido_compact = 115,
|
||||
default_colido_diy = 170,
|
||||
subSection = 'printer_type',
|
||||
type = 'int',
|
||||
description = '',
|
||||
min = 0
|
||||
}
|
||||
M.printer_heatedbed = {
|
||||
default = false,
|
||||
default_ultimaker2 = true,
|
||||
default_makerbot_replicator2x = true,
|
||||
default_minifactory = true,
|
||||
default_lulzbot_taz_4 = true,
|
||||
default_wanhao_duplicator4 = true,
|
||||
default_colido_2_0_plus = true,
|
||||
default_colido_m2020 = true,
|
||||
default_colido_x3045 = true,
|
||||
default_craftbot_plus = true,
|
||||
default_ultimaker_original_plus = true,
|
||||
subSection = 'printer_type',
|
||||
type = 'bool',
|
||||
description = 'Printer has heated bed',
|
||||
}
|
||||
M.printer_filamentThickness = {
|
||||
default = 2.89,
|
||||
default_doodle_dream = 1.75,
|
||||
default_renkforce_rf100 = 1.75,
|
||||
default_wanhao_duplicator4 = 1.75,
|
||||
default_craftbot_plus = 1.75,
|
||||
type = 'float',
|
||||
description = '',
|
||||
min = 0.0,
|
||||
subSection = 'printer_type'
|
||||
}
|
||||
|
||||
local default_makerbot_startcode = ';@printer {printerType}\nM136 (enable build)\nM73 P0 (Set build percentage to 0)\nG162 X Y F2000 (home XY axes to maximum)\nG161 Z F900 (home Z axis to minimum quick)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z5.0 F900 (move Z axis down)\nG161 Z F100 (home Z axis to minimum more precise)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z2.0 F900 (move Z axis to safety height)\nG1 X-264 Y-145 Z0 F3300.0 (move XY to start position)\nG92 X0 Y0 Z0 A0 B0 (set axis position to 0)\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\n{if heatedBed}M140 S{printingBedTemp} T0 (Set bed temp)\nM135 T0 (use first extruder)\nM104 S{printingTemp} T0 (set extruder temp)\nM133 T0 (Wait for extruder)\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG1 F100 A10 (extrude 10mm)\nG92 A0 (reset extruder)\nG0 Z20 (move up, to lose filament)'
|
||||
local default_deltabot_startcode = ';Generated with Doodle3D (deltabot)\nM109 S{printingTemp} ;set target temperature\n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 ; move to home\nG92 E0 ;zero the extruded length\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)'
|
||||
local default_ultimaker2_startcode = ';Generated with Doodle3D (ultimaker2)\nM10000\nM10000\nM10001 X8 Y28 SDoodle3D heat up...\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM10000\nM10000\nM10001 X8 Y28 SDoodle3D printing...\n'
|
||||
local default_ultimaker_original_plus_startcode = ';Generated with Doodle3D (Ultimaker Original Plus)\n{if heatedBed}M190 S{printingBedTemp}\nM109 S{printingTemp}\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)'
|
||||
M.printer_startcode = {
|
||||
default = ';Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG91 ;relative positioning\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)',
|
||||
default_ultimaker2 = default_ultimaker2_startcode,
|
||||
default_ultimaker2go = default_ultimaker2_startcode,
|
||||
default__3Dison_plus = ';@printer {printerType}\nM136 (enable build)\nM73 P0\nG21\nG90\nM103\n;M109 S50 T0\nM140 S50 T0\nM104 S{printingTemp} T0\n;M134 T0\nM135 T0\nM104 S{printingTemp} T0\nG162 X Y F2000(home XY axes maximum)\nG161 Z F900(home Z axis minimum)\nG92 X113.5 Y74 Z-5 A0 B0 (set Z to -5)\nG1 Z0.0 F900(move Z to 0)\nG161 Z F100(home Z axis minimum)\nM132 X Y Z A B (Recall stored home offsets for XYZAB axis)\nG1 Z50 F3300\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\nM133 T0\nM6 T0\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG0 Z0.2 F3000\nG1 Z0 F100 A10 ;extrude 10mm\nG92 X227 Y148 Z0 A0 ;reset again\nG1 X227 Y148 Z0',
|
||||
default_makerbot_generic = default_makerbot_startcode,
|
||||
default_makerbot_replicator2 = default_makerbot_startcode,
|
||||
default_makerbot_replicator2x = default_makerbot_startcode,
|
||||
default_makerbot_thingomatic = default_makerbot_startcode,
|
||||
default_wanhao_duplicator4 = default_makerbot_startcode,
|
||||
default_delta_rostockmax = default_deltabot_startcode,
|
||||
default_deltamaker = default_deltabot_startcode,
|
||||
default_kossel = default_deltabot_startcode,
|
||||
default_ultimaker_original_plus = default_ultimaker_original_plus_startcode,
|
||||
type = 'string',
|
||||
subSection = 'printer_type',
|
||||
description = ''
|
||||
}
|
||||
|
||||
local default_makerbot_endcode = 'G92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG162 Z F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\n{if heatedBed}M140 S0 T0\nM104 S0 T0\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)'
|
||||
local default_deltabot_endcode = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;move to home\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM109 S0 ; hot end off\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)'
|
||||
local default_ultimaker2_endcode = 'M10000\nM10000\nM10001 X20 Y28 SDoodle3D done!\nM107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S0\n{if heatedBed}M140 S0\n'
|
||||
M.printer_endcode = {
|
||||
default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S0\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)',
|
||||
default_ultimaker2 = default_ultimaker2_endcode,
|
||||
default_ultimaker2go = default_ultimaker2_endcode,
|
||||
default__3Dison_plus = 'M73 P100\nG92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG1 Z155 F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\nM140 S0 T0\nM104 S0 T0\nM73 P100 (end build progress )\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)\n',
|
||||
default_makerbot_generic = default_makerbot_endcode,
|
||||
default_makerbot_replicator2 = default_makerbot_endcode,
|
||||
default_makerbot_replicator2x = default_makerbot_endcode,
|
||||
default_makerbot_thingomatic = default_makerbot_endcode,
|
||||
default_wanhao_duplicator4 = default_makerbot_endcode,
|
||||
default_delta_rostockmax = default_deltabot_endcode,
|
||||
default_deltamaker = default_deltabot_endcode,
|
||||
default_kossel = default_deltabot_endcode,
|
||||
default_craftbot_plus = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM109 S0\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)',
|
||||
type = 'string',
|
||||
subSection = 'printer_type',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_baudrate = {
|
||||
default = '115200',
|
||||
type = 'int',
|
||||
|
@ -85,9 +262,16 @@ M.printer_baudrate = {
|
|||
}
|
||||
|
||||
M.printer_temperature = {
|
||||
default = 230,
|
||||
default = 210,
|
||||
type = 'int',
|
||||
description = '3D printer temperature',
|
||||
description = 'printing temperature',
|
||||
min = 0
|
||||
}
|
||||
|
||||
M.printer_bed_temperature = {
|
||||
default = 70,
|
||||
type = 'int',
|
||||
description = 'printing bed temperature',
|
||||
min = 0
|
||||
}
|
||||
|
||||
|
@ -119,13 +303,6 @@ M.printer_travelSpeed = {
|
|||
min = 0
|
||||
}
|
||||
|
||||
M.printer_filamentThickness = {
|
||||
default = 2.89,
|
||||
type = 'float',
|
||||
description = '',
|
||||
min = 0.0
|
||||
}
|
||||
|
||||
M.printer_useSubLayers = {
|
||||
default = true,
|
||||
type = 'bool',
|
||||
|
@ -138,14 +315,38 @@ M.printer_firstLayerSlow = {
|
|||
description = 'Print the first layer slowly to get a more stable start'
|
||||
}
|
||||
|
||||
M.printer_heatup_enabled = {
|
||||
M.printer_bottomLayerSpeed = {
|
||||
default = 35,
|
||||
type = 'int',
|
||||
description = 'If first layers are to be printed slowly, use this speed'
|
||||
}
|
||||
|
||||
M.printer_bottomFlowRate = {
|
||||
default = 2,
|
||||
type = 'float',
|
||||
description = 'Multiplication factor for filament flow rate in first few layers'
|
||||
}
|
||||
|
||||
M.printer_bottomEnableTraveling = {
|
||||
default = true,
|
||||
type = 'bool',
|
||||
description = 'Enable traveling on bottom layers, disabling this might improve adhesion on some printers'
|
||||
}
|
||||
|
||||
M.printer_heatup_enabled = {
|
||||
default = false,
|
||||
type = 'bool',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_heatup_temperature = {
|
||||
default = 180,
|
||||
default = 0,
|
||||
type = 'int',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_heatup_bed_temperature = {
|
||||
default = 0,
|
||||
type = 'int',
|
||||
description = ''
|
||||
}
|
||||
|
@ -172,35 +373,23 @@ M.printer_retraction_minDistance = {
|
|||
|
||||
M.printer_retraction_amount = {
|
||||
default = 3,
|
||||
type = 'int',
|
||||
type = 'float',
|
||||
description = '',
|
||||
min = 0
|
||||
}
|
||||
|
||||
M.printer_enableTraveling = {
|
||||
default = false,
|
||||
default = true,
|
||||
type = 'bool',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_startgcode = {
|
||||
default = ';Generated with Doodle3D\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)',
|
||||
type = 'string',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_endgcode = {
|
||||
default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S180\nM117 Done ;display message (20 characters to clear whole screen)',
|
||||
type = 'string',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.printer_maxObjectHeight = {
|
||||
default = 150,
|
||||
type = 'int',
|
||||
description = 'Maximum height that will be printed',
|
||||
min = 0
|
||||
}
|
||||
-- M.printer_maxObjectHeight = {
|
||||
-- default = 150,
|
||||
-- type = 'int',
|
||||
-- description = 'Maximum height that will be printed',
|
||||
-- min = 0
|
||||
-- }
|
||||
|
||||
M.printer_screenToMillimeterScale = {
|
||||
default = 0.3,
|
||||
|
@ -215,4 +404,28 @@ M.doodle3d_simplify_minDistance = {
|
|||
min = 0
|
||||
}
|
||||
|
||||
M.doodle3d_tour_enabled = {
|
||||
default = true,
|
||||
type = 'bool',
|
||||
description = 'Show tour to new users'
|
||||
}
|
||||
|
||||
M.doodle3d_update_includeBetas = {
|
||||
default = false,
|
||||
type = 'bool',
|
||||
description = 'Include beta releases when updating'
|
||||
}
|
||||
|
||||
M.doodle3d_update_baseUrl = {
|
||||
default = 'http://doodle3d.com/updates',
|
||||
type = 'string',
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.gcode_server = {
|
||||
default = 'http://gcodeserver.doodle3d.com',
|
||||
type = 'string',
|
||||
description =''
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
210
src/main.lua
210
src/main.lua
|
@ -1,3 +1,16 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
----
|
||||
-- Entry code of the REST API and secondary functionality.
|
||||
-- Primarily, this sets up the environment, processes a REST request and responds appropiately.
|
||||
-- Secondary functions are to auto-switch between access point and client (@{setupAutoWifiMode})
|
||||
-- and to signin to [connect.doodle3d.com](http://connect.doodle3d.com/) (@{network.signin}).
|
||||
package.path = package.path .. ';/usr/share/lua/wifibox/?.lua'
|
||||
|
||||
local confDefaults = require('conf_defaults')
|
||||
|
@ -9,10 +22,24 @@ local netconf = require('network.netconfig')
|
|||
local RequestClass = require('rest.request')
|
||||
local ResponseClass = require('rest.response')
|
||||
local Signin = require('network.signin')
|
||||
local osUtils = require('os_utils')
|
||||
|
||||
|
||||
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
||||
argStash = arg
|
||||
arg = nil
|
||||
local updater = require('script.d3d-updater')
|
||||
arg = argStash
|
||||
|
||||
local postData = nil
|
||||
local MOD_ABBR = "ENTR"
|
||||
|
||||
|
||||
--- Switches to wifi client mode or to access point mode based on availability of known wifi networks.
|
||||
--
|
||||
-- If the configuration has actively been set to access point mode, that will always be selected.
|
||||
-- If not, it will be attempted to connect to a known network (in order of recency) and only if
|
||||
-- that fails, access point mode will be selected as fall-back.
|
||||
local function setupAutoWifiMode()
|
||||
-- expects list with tables containing 'ssid' key as values and returns index key if found or nil if not found
|
||||
local function findSsidInList(list, name)
|
||||
|
@ -24,18 +51,19 @@ local function setupAutoWifiMode()
|
|||
|
||||
local wifiState = wifi.getDeviceState()
|
||||
local netName, netMode = wifiState.ssid, wifiState.mode
|
||||
log:info(MOD_ABBR, "current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode)
|
||||
|
||||
local apSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
local apMode = (apSsid == netName) and netMode == 'ap'
|
||||
local apMode = (apSsid == netName) and (netMode == 'ap')
|
||||
log:info(MOD_ABBR, "ssid of self: " .. apSsid)
|
||||
|
||||
local scanList,msg = wifi.getScanInfo()
|
||||
local knownSsids = wifi.getConfigs()
|
||||
|
||||
if not scanList then
|
||||
return nil, "autowifi: could not scan wifi networks (" .. msg .. ")"
|
||||
end
|
||||
|
||||
log:info("current wifi name/mode: " .. (netName or "<nil>") .. "/" .. netMode .. ", ssid of self: " .. apSsid)
|
||||
local knownSsids = wifi.getConfigs()
|
||||
-- log:info(MOD_ABBR, "current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid)
|
||||
local visNet, knownNet = {}, {}
|
||||
for _,sn in ipairs(scanList) do
|
||||
table.insert(visNet, sn.ssid)
|
||||
|
@ -43,26 +71,36 @@ local function setupAutoWifiMode()
|
|||
for _,kn in ipairs(knownSsids) do
|
||||
table.insert(knownNet, kn.ssid .. "/" .. kn.mode)
|
||||
end
|
||||
log:info("visible networks: " .. table.concat(visNet, ", "))
|
||||
log:info("known networks: " .. table.concat(knownNet, ", "))
|
||||
log:info(MOD_ABBR, "visible networks: " .. table.concat(visNet, ", "))
|
||||
log:info(MOD_ABBR, "known networks: " .. table.concat(knownNet, ", "))
|
||||
|
||||
-- if the currently active network is client mode and is also visible, do nothing since it will connect automatically further along the boot process
|
||||
if netMode == 'sta' and netName ~= nil and netName ~= "" and findSsidInList(scanList, netName) then
|
||||
-- signin to connect.doodle3d.com
|
||||
local success, output = Signin.signin()
|
||||
if success then
|
||||
log:info(MOD_ABBR, "Signed in")
|
||||
else
|
||||
log:info(MOD_ABBR, "Signing in failed")
|
||||
end
|
||||
-- report we are connected after signin attempt
|
||||
netconf.setStatus(netconf.CONNECTED,"Connected");
|
||||
return true, "autowifi: no action - existing configuration found for currently wifi visible network (" .. netName .. ")"
|
||||
end
|
||||
|
||||
-- try to find a known network which is also visible (ordered by known network definitions)
|
||||
-- when it finds a access point configuration first, it will use that
|
||||
local connectWith = nil
|
||||
for _,kn in ipairs(knownSsids) do
|
||||
if kn.mode == 'ap' and kn.ssid == apSsid then break end
|
||||
if findSsidInList(scanList, kn.ssid) then
|
||||
if kn.mode == 'ap' and kn.ssid == apSsid then break end
|
||||
if findSsidInList(scanList, kn.ssid) and kn.mode == 'sta' then
|
||||
connectWith = kn.ssid
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if connectWith then
|
||||
local rv,msg = netconf.associateSsid(connectWith)
|
||||
local rv,msg = netconf.associateSsid(connectWith,nil,nil)
|
||||
if rv then
|
||||
return true, "autowifi: associated -- client mode with ssid '" .. connectWith .. "'"
|
||||
else
|
||||
|
@ -76,32 +114,65 @@ local function setupAutoWifiMode()
|
|||
return nil, "autowifi: failed to configure as access point with ssid '" .. apSsid .. "' (" .. msg .. ")"
|
||||
end
|
||||
else
|
||||
netconf.setStatus(netconf.CREATED,"Access point created");
|
||||
return true, "autowifi: no action - no known networks found, already in access point mode"
|
||||
end
|
||||
|
||||
return nil, "autowifi: uh oh - bad situation in autowifi function"
|
||||
end
|
||||
|
||||
--- Initializes the logging system to use the file and level defined in the system settings.
|
||||
-- The settings used are `log_path`, `api_log_filename` from the system section and
|
||||
-- `system_log_level` from the general section. The filename may either be a regular filename
|
||||
-- (with an absolute log_path), or `<stdout>` or `<stderr>`.
|
||||
-- TODO: also support backticks (see Logger.cpp in print3d)--
|
||||
-- @see util.settings.getSystemKey
|
||||
-- @treturn bool True on success, false on error.
|
||||
local function setupLogger()
|
||||
local logStream = io.stderr -- use stderr as hard-coded default target
|
||||
local logLevel = log.LEVEL.debug -- use debug logging as hard-coded default level
|
||||
local logLevel = log.LEVEL.verbose -- use verbose logging as hard-coded default level
|
||||
|
||||
local logTargetSetting = settings.getSystemKey('logfile')
|
||||
local logLevelSetting = settings.getSystemKey('loglevel')
|
||||
local logPathSetting = settings.getSystemKey('log_path')
|
||||
local logTargetSetting = settings.getSystemKey('api_log_filename')
|
||||
local logLevelSetting = settings.get('system_log_level')
|
||||
local logTargetError, logLevelError = nil, nil
|
||||
|
||||
if type(logTargetSetting) == 'string' then
|
||||
local specialTarget = logTargetSetting:match('^<(.*)>$')
|
||||
if specialTarget then
|
||||
if specialTarget == 'stdout' then logStream = io.stdout
|
||||
elseif specialTarget == 'stderr' then logStream = io.stderr
|
||||
local streamTarget = logTargetSetting:match('^<(.*)>$')
|
||||
local popenTarget = logTargetSetting:match('^`(.*)`$')
|
||||
if streamTarget then
|
||||
if streamTarget:lower() == 'stdout' then logStream = io.stdout
|
||||
elseif streamTarget:lower() == 'stderr' then logStream = io.stderr
|
||||
end
|
||||
elseif logTargetSetting:sub(1, 1) == '/' then
|
||||
local f,msg = io.open(logTargetSetting, 'a+')
|
||||
elseif popenTarget then
|
||||
local f,msg = io.popen(popenTarget, 'w')
|
||||
|
||||
if f then logStream = f
|
||||
else logTargetError = msg
|
||||
end
|
||||
elseif logPathSetting:sub(1, 1) == '/' then
|
||||
local path = logPathSetting .. '/' .. logTargetSetting
|
||||
local f,msg = io.open(path, 'a+')
|
||||
|
||||
if f then
|
||||
logStream = f
|
||||
log:setLogFilePath(path)
|
||||
else
|
||||
logTargetError = msg
|
||||
end
|
||||
else
|
||||
logTargetError = "log file path is not absolute"
|
||||
end
|
||||
else
|
||||
-- if uci config not available, fallback to /tmp/wifibox.log
|
||||
local path = '/tmp/wifibox.log'
|
||||
local f,msg = io.open(path, 'a+')
|
||||
|
||||
if f then
|
||||
logStream = f
|
||||
log:setLogFilePath(path)
|
||||
else
|
||||
logTargetError = msg
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,30 +192,22 @@ local function setupLogger()
|
|||
|
||||
local rv = true
|
||||
if logTargetError then
|
||||
log:error("could not open logfile '" .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")")
|
||||
log:error(MOD_ABBR, "could not open logfile '" .. logPathSetting .. '/' .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")")
|
||||
rv = false
|
||||
end
|
||||
|
||||
if logLevelError then
|
||||
log:error("uci config specifies invalid log level '" .. logLevelSetting .. "', using debug level as fallback")
|
||||
log:error(MOD_ABBR, "uci config specifies invalid log level '" .. logLevelSetting .. "', using verbose level as fallback")
|
||||
rv = false
|
||||
end
|
||||
|
||||
return rv
|
||||
end
|
||||
|
||||
--- Initializes the environment.
|
||||
-- The logger is set up, any POST data is read and several other subsystems are initialized.
|
||||
-- @tparam table environment The 'shell' environment containing all CGI variables. Note that @{cmdmain} simulates this.
|
||||
local function init(environment)
|
||||
setupLogger()
|
||||
|
||||
local dbgText = ""
|
||||
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall+api"
|
||||
elseif confDefaults.DEBUG_API then dbgText = "api"
|
||||
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
||||
end
|
||||
|
||||
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
|
||||
log:info("=======rest api" .. dbgText .. "=======")
|
||||
|
||||
if (environment['REQUEST_METHOD'] == 'POST') then
|
||||
local n = tonumber(environment['CONTENT_LENGTH'])
|
||||
postData = io.read(n)
|
||||
|
@ -154,67 +217,88 @@ local function init(environment)
|
|||
s, msg = wifi.init()
|
||||
if not s then return s, msg end
|
||||
|
||||
s, msg = netconf.init(wifi, true)
|
||||
s, msg = netconf.init(wifi, false)
|
||||
if not s then return s, msg end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Decides what action to take based on shell/CGI parameters.
|
||||
-- Either executes a REST request, or calls @{setupAutoWifiMode} or @{network.signin}.
|
||||
-- @tparam table environment The CGI environment table.
|
||||
local function main(environment)
|
||||
local rq = RequestClass.new(environment, postData, confDefaults.DEBUG_API)
|
||||
|
||||
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
|
||||
log:info("running in autowifi mode")
|
||||
|
||||
local version = updater.formatVersion(updater.getCurrentVersion());
|
||||
log:info(MOD_ABBR, "Doodle3D version: "..util.dump(version))
|
||||
|
||||
log:info(MOD_ABBR, "Running in autowifi mode")
|
||||
local rv,msg = setupAutoWifiMode()
|
||||
|
||||
if rv then
|
||||
log:info("autowifi setup done (" .. msg .. ")")
|
||||
log:info(MOD_ABBR, "Autowifi setup done (" .. msg .. ")")
|
||||
else
|
||||
log:error("autowifi setup failed (" .. msg .. ")")
|
||||
log:error(MOD_ABBR, "Autowifi setup failed (" .. msg .. ")")
|
||||
end
|
||||
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
||||
log:info("running in signin mode")
|
||||
log:info(MOD_ABBR, "Running in signin mode")
|
||||
|
||||
local ds = wifi.getDeviceState()
|
||||
log:info(" ds.mode: "..util.dump(ds.mode))
|
||||
if ds.mode == "sta" then
|
||||
log:info(" attempting signin")
|
||||
local success,msg = Signin.signin()
|
||||
if success then
|
||||
log:info("Signin successful")
|
||||
else
|
||||
log:info("Signin failed: "..util.dump(msg))
|
||||
end
|
||||
log:info(MOD_ABBR, " attempting signin")
|
||||
local success,msg = Signin.signin()
|
||||
if success then
|
||||
log:info(MOD_ABBR, "Signin successful")
|
||||
else
|
||||
log:warning(MOD_ABBR, "Signin failed: "..util.dump(msg))
|
||||
end
|
||||
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
|
||||
-- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
|
||||
log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
||||
-- Note: the commented log message will print too many data if it's for instance dumping a gcode add request
|
||||
--logMessage = "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll())
|
||||
logMessage = rq:getRequestMethod() .. " request for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>")
|
||||
if rq:getRequestMethod() ~= 'CMDLINE' then
|
||||
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
||||
--log:debug("user agent: " .. rq:getUserAgent())
|
||||
logMessage = logMessage .. " (remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort() .. ")"
|
||||
--logMessage = logMessage .. " (user agent: " .. rq:getUserAgent() .. ")"
|
||||
end
|
||||
log:info(MOD_ABBR, logMessage)
|
||||
|
||||
local response, err = rq:handle()
|
||||
|
||||
if err ~= nil then log:error(err) end
|
||||
if err ~= nil then log:error(MOD_ABBR, err) end
|
||||
response:send()
|
||||
|
||||
response:executePostResponseQueue()
|
||||
response:executePostResponseQueue()
|
||||
else
|
||||
log:info("Nothing to do...bye.\n")
|
||||
log:info(MOD_ABBR, "Nothing to do...bye.\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Main firmware entry point.
|
||||
-- This is either used by uhttp-mod-lua directly, or by the d3dapi cgi-bin wrapper
|
||||
-- script which builds the env table from the shell environment. The wrapper script
|
||||
-- also handles command-line invocation.
|
||||
-- @tparam table The CGI environment table.
|
||||
--- Firmware entry point. Runs @{init} and calls @{main}.
|
||||
--
|
||||
-- This is either used by [uhttp-mod-lua](http://wiki.openwrt.org/doc/uci/uhttpd#embedded.lua)
|
||||
-- directly, or by the d3dapi cgi-bin wrapper script which builds the env table
|
||||
-- from the shell environment. The wrapper script also handles command-line invocation.
|
||||
-- @tparam table env The CGI environment table.
|
||||
-- @treturn number A Z+ return value suitable to return from wrapper script. Note that this value is ignored by uhttpd-mod-lua.
|
||||
function handle_request(env)
|
||||
local function constructDebugText()
|
||||
local dbgText = ""
|
||||
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall+api"
|
||||
elseif confDefaults.DEBUG_API then dbgText = "api"
|
||||
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
||||
end
|
||||
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
|
||||
return dbgText
|
||||
end
|
||||
|
||||
setupLogger()
|
||||
|
||||
local pid = osUtils.getPID()
|
||||
local beginSecs, beginUSecs = osUtils.getTime()
|
||||
|
||||
log:verbose(MOD_ABBR, "START-RQ with PID=" .. pid .. constructDebugText())
|
||||
local s, msg = init(env)
|
||||
|
||||
if s == false then
|
||||
|
@ -223,11 +307,13 @@ function handle_request(env)
|
|||
|
||||
resp:setError("initialization failed" .. errSuffix)
|
||||
resp:send()
|
||||
log:error("initialization failed" .. errSuffix) --NOTE: this assumes the logger has been initialized properly, despite init() having failed
|
||||
log:error(MOD_ABBR, "Initialization failed" .. errSuffix)
|
||||
|
||||
return 1
|
||||
else
|
||||
main(env)
|
||||
local elapsed,msg = osUtils.getElapsedTime(beginSecs, beginUSecs)
|
||||
log:bulk(MOD_ABBR, "END-RQ with PID=" .. pid .. " completed in " .. elapsed .. " msec")
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local utils = require('util.utils')
|
||||
local log = require('util.logger')
|
||||
local settings = require('util.settings')
|
||||
|
@ -10,6 +18,8 @@ local reconf = {}
|
|||
local wifi
|
||||
local reloadSilent
|
||||
|
||||
local MOD_ABBR = "NTCF"
|
||||
|
||||
M.WWW_CAPTIVE_PATH = '/usr/share/lua/wifibox/www'
|
||||
M.WWW_CAPTIVE_INDICATOR = '/www/.wifibox-inplace'
|
||||
M.WWW_RENAME_NAME = '/www-regular'
|
||||
|
@ -17,9 +27,9 @@ M.WWW_RENAME_NAME = '/www-regular'
|
|||
M.CONNECTING_FAILED = -1
|
||||
M.NOT_CONNECTED = 0
|
||||
M.CONNECTING = 1
|
||||
M.CONNECTED = 2
|
||||
M.CREATING = 3
|
||||
M.CREATED = 4
|
||||
M.CONNECTED = 2
|
||||
M.CREATING = 3
|
||||
M.CREATED = 4
|
||||
|
||||
local function reloadBit(dlist, itemname)
|
||||
if dlist[itemname] == nil then dlist[itemname] = '' end
|
||||
|
@ -45,7 +55,7 @@ function M.init(wifiInstance, reloadSilent)
|
|||
end
|
||||
|
||||
--- Switch configuration between AP and station modes
|
||||
-- @param components a table with components as keys with operations as values (add or remove)
|
||||
-- @param table components a table with components as keys with operations as values (add or remove)
|
||||
-- Valid components (each with add and rm operation) are: apnet, staticaddr, dhcppool, wwwredir, dnsredir, wwwcaptive, natreflect.
|
||||
-- and additionally: wifiiface/add, network/reload
|
||||
function M.switchConfiguration(components)
|
||||
|
@ -54,10 +64,10 @@ function M.switchConfiguration(components)
|
|||
for k,v in pairs(components) do
|
||||
local fname = k .. '_' .. v
|
||||
if type(reconf[fname]) == 'function' then
|
||||
log:debug("reconfiguring component '" .. k .. "' (" .. v .. ")")
|
||||
log:verbose(MOD_ABBR, "reconfiguring component '" .. k .. "' (" .. v .. ")")
|
||||
reconf[fname](dirtyList)
|
||||
else
|
||||
log:warn("unknown component or action '" .. fname .. "' skipped")
|
||||
log:warning(MOD_ABBR, "unknown component or action '" .. fname .. "' skipped")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,14 +81,21 @@ function M.switchConfiguration(components)
|
|||
end
|
||||
|
||||
function M.commitComponent(c)
|
||||
log:info("committing component '" .. c .. "'")
|
||||
log:verbose(MOD_ABBR, "committing component '" .. c .. "'")
|
||||
uci:commit(c)
|
||||
end
|
||||
|
||||
function M.reloadComponent(c, silent)
|
||||
log:info("reloading component '" .. c .. "'")
|
||||
if silent ~= nil and silent then os.execute('/etc/init.d/' .. c .. ' reload &> /dev/null')
|
||||
else os.execute('/etc/init.d/' .. c .. ' reload') end
|
||||
log:verbose(MOD_ABBR, "reloading component '" .. c .. "'")
|
||||
local command = 'reload'
|
||||
local cmd = '/etc/init.d/' .. c .. ' '..command
|
||||
if silent ~= nil and silent then
|
||||
cmd = cmd .. ' &> /dev/null'
|
||||
os.execute(cmd)
|
||||
else
|
||||
rv = utils.captureCommandOutput(cmd)
|
||||
log:verbose(MOD_ABBR, " result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
||||
end
|
||||
end
|
||||
|
||||
function M.uciTableSet(config, section, options)
|
||||
|
@ -132,7 +149,7 @@ function reconf.apnet_rm(dirtyList)
|
|||
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||
if s.ssid == wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then sname = s['.name']; return false end
|
||||
end)
|
||||
if sname == nil then return log:info("AP network configuration does not exist, nothing to remove") end
|
||||
if sname == nil then return log:info(MOD_ABBR, "AP network configuration does not exist, nothing to remove") end
|
||||
uci:delete('wireless', sname)
|
||||
reloadBit(dirtyList, 'network'); commitBit(dirtyList, 'wireless')
|
||||
end
|
||||
|
@ -197,15 +214,15 @@ end
|
|||
function reconf.dnsredir_add(dirtyList)
|
||||
local redirText = '/#/' .. settings.get('network.ap.address')
|
||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||
if uci:get('dhcp', sname, 'address') ~= nil then return log:debug("DNS address redirection already in place, not re-adding", false) end
|
||||
if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end
|
||||
if uci:get('dhcp', sname, 'address') ~= nil then return log:info(MOD_ABBR, "DNS address redirection already in place, not re-adding", false) end
|
||||
|
||||
uci:set('dhcp', sname, 'address', {redirText})
|
||||
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
||||
end
|
||||
function reconf.dnsredir_rm(dirtyList)
|
||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||
if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end
|
||||
|
||||
uci:delete('dhcp', sname, 'address')
|
||||
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
||||
|
@ -215,21 +232,21 @@ end
|
|||
--TODO: handle os.rename() return values (nil+msg on error)
|
||||
function reconf.wwwcaptive_add(dirtyList)
|
||||
if utils.exists(M.WWW_CAPTIVE_INDICATOR) then
|
||||
return log:debug("WWW captive directory already in place, not redoing", false)
|
||||
return log:info(MOD_ABBR, "WWW captive directory already in place, not redoing", false)
|
||||
end
|
||||
local rv,reason = os.rename('/www', M.WWW_RENAME_NAME)
|
||||
if rv == true then
|
||||
utils.symlink(M.WWW_CAPTIVE_PATH, '/www')
|
||||
return true
|
||||
else
|
||||
return log:error("Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")")
|
||||
return log:error(MOD_ABBR, "Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")")
|
||||
end
|
||||
end
|
||||
function reconf.wwwcaptive_rm(dirtyList)
|
||||
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:debug("WWW captive directory not in place, not undoing", false) end
|
||||
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:info(MOD_ABBR, "WWW captive directory not in place, not undoing", false) end
|
||||
os.remove('/www')
|
||||
if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then
|
||||
return log:error("Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
||||
return log:error(MOD_ABBR, "Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
@ -259,17 +276,53 @@ end
|
|||
-- @tparam string ssid The SSID to use for the access point.
|
||||
-- @return True on success or nil+msg on error.
|
||||
function M.setupAccessPoint(ssid)
|
||||
|
||||
M.setStatus(M.CREATING,"Creating access point...");
|
||||
|
||||
M.switchConfiguration{apnet="add_noreload"}
|
||||
M.setStatus(M.CREATING,"Creating access point '"..ssid.."'...");
|
||||
|
||||
-- add access point configuration
|
||||
M.switchConfiguration({apnet="add_noreload"})
|
||||
wifi.activateConfig(ssid)
|
||||
-- NOTE: dnsmasq must be reloaded after network or it will be unable to serve IP addresses
|
||||
M.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add_noreload", wwwredir="add", dnsredir="add" }
|
||||
M.switchConfiguration{dhcp="reload"}
|
||||
|
||||
M.switchConfiguration({ wifiiface="add", network="reload", staticaddr="add", dhcppool="add_noreload", wwwredir="add", dnsredir="add" })
|
||||
M.switchConfiguration({dhcp="reload"})
|
||||
|
||||
M.setStatus(M.CREATED,"Access point created");
|
||||
|
||||
local ds = wifi.getDeviceState()
|
||||
--log:info(MOD_ABBR, " network/status: ")
|
||||
log:info(MOD_ABBR, " ssid: ".. utils.dump(ds.ssid))
|
||||
--[[
|
||||
log:info(MOD_ABBR, " bssid: ".. utils.dump(ds.bssid))
|
||||
log:info(MOD_ABBR, " channel: ".. utils.dump(ds.channel))
|
||||
log:info(MOD_ABBR, " mode: ".. utils.dump(ds.mode))
|
||||
log:info(MOD_ABBR, " encryption: ".. utils.dump(ds.encryption))
|
||||
log:info(MOD_ABBR, " quality: ".. utils.dump(ds.quality))
|
||||
log:info(MOD_ABBR, " quality_max: ".. utils.dump(ds.quality_max))
|
||||
log:info(MOD_ABBR, " txpower: ".. utils.dump(ds.txpower))
|
||||
log:info(MOD_ABBR, " signal: ".. utils.dump(ds.signal))
|
||||
log:info(MOD_ABBR, " noise: ".. utils.dump(ds.noise))
|
||||
log:info(MOD_ABBR, " raw: ".. utils.dump(ds))
|
||||
|
||||
local localip = wifi.getLocalIP()
|
||||
log:info(MOD_ABBR, " localip: "..utils.dump(localip))
|
||||
--]]
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- set the network configuration to accesspoint, but don't reload (used before updating)
|
||||
-- Note: this function might belong in the wlanconfig module but that would introduce
|
||||
-- a circular dependency, easiest solution is to place the function here.
|
||||
-- @tparam string ssid The SSID to use for the access point.
|
||||
-- @return True on success or nil+msg on error.
|
||||
function M.enableAccessPoint(ssid)
|
||||
log:info(MOD_ABBR, "enableAccessPoint ssid: ".. utils.dump(ssid))
|
||||
|
||||
M.switchConfiguration{apnet="add_noreload"}
|
||||
wifi.activateConfig(ssid)
|
||||
|
||||
local ds = wifi.getDeviceState()
|
||||
log:info(MOD_ABBR, " deviceState.ssid: ".. utils.dump(ds.ssid))
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -281,10 +334,9 @@ end
|
|||
-- @tparam boolean recreate If true, a new UCI configuration based on scan data will always be created, otherwise an attempt will be made to use an existing configuration.
|
||||
-- @return True on success or nil+msg on error.
|
||||
function M.associateSsid(ssid, passphrase, recreate)
|
||||
log:info("netconfig:associateSsid: "..(ssid or "<nil>")..", "..(passphrase or "<nil>")..", "..(recreate or "<nil>"))
|
||||
|
||||
log:info(MOD_ABBR, "netconfig:associateSsid: "..(ssid or "<nil>")..", "..(recreate or "<nil>"))
|
||||
M.setStatus(M.CONNECTING,"Connecting...");
|
||||
|
||||
|
||||
-- see if previously configured network for given ssid exists
|
||||
local cfg = nil
|
||||
for _, net in ipairs(wifi.getConfigs()) do
|
||||
|
@ -293,12 +345,16 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- if not, or if newly created configuration is requested, create a new configuration
|
||||
if cfg == nil or recreate ~= nil then
|
||||
local scanResult = wifi.getScanInfo(ssid)
|
||||
local scanResult, msg = wifi.getScanInfo(ssid)
|
||||
if scanResult ~= nil then
|
||||
wifi.createConfigFromScanInfo(scanResult, passphrase)
|
||||
elseif scanResult == false then
|
||||
--check for error
|
||||
M.setStatus(M.CONNECTING_FAILED,msg);
|
||||
return nil,msg
|
||||
else
|
||||
--check for error
|
||||
local msg = "Wireless network "..ssid.." is not available"
|
||||
|
@ -311,28 +367,49 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||
wifi.activateConfig(ssid)
|
||||
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wwwcaptive="rm", wireless="reload" }
|
||||
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||
M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||
--M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||
M.switchConfiguration({ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm" })
|
||||
|
||||
-- check if we are actually associated
|
||||
local status = wifi.getDeviceState()
|
||||
if not status.ssid or status.ssid ~= ssid then
|
||||
local msg = "Could not associate with network (incorrect password?)"
|
||||
M.setStatus(M.CONNECTING_FAILED,msg);
|
||||
return nil,msg
|
||||
-- we check if we get a ssid and ip in max 5 seconds
|
||||
-- if not there is probably a issue
|
||||
local attemptInterval = 1
|
||||
local maxAttempts = 5
|
||||
local attempt = 0
|
||||
local nextAttemptTime = os.time()
|
||||
while true do
|
||||
if os.time() > nextAttemptTime then
|
||||
log:verbose(MOD_ABBR, "associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
|
||||
break
|
||||
else
|
||||
attempt = attempt+1
|
||||
if attempt >= maxAttempts then
|
||||
-- still no correct ssid; fail
|
||||
local msg = "Could not associate with network (incorrect password?)"
|
||||
M.setStatus(M.CONNECTING_FAILED,msg);
|
||||
return false, msg
|
||||
else
|
||||
nextAttemptTime = os.time() + attemptInterval
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.setStatus(M.CONNECTED,"Connected");
|
||||
|
||||
log:info(MOD_ABBR, "Network associated")
|
||||
|
||||
-- signin to connect.doodle3d.com
|
||||
local success, output = signin.signin()
|
||||
if success then
|
||||
log:info("Signed in")
|
||||
else
|
||||
log:info("Signing in failed")
|
||||
log:info(MOD_ABBR, "Signed in")
|
||||
else
|
||||
log:info(MOD_ABBR, "Signing in failed")
|
||||
end
|
||||
|
||||
-- report we are connected after signin attempt
|
||||
M.setStatus(M.CONNECTED,"Connected");
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Disassociate wlan device as client from all SSID's.
|
||||
-- Note: this function might belong in the wlanconfig module but that would introduce
|
||||
-- a circular dependency, easiest solution is to place the function here.
|
||||
|
@ -340,31 +417,28 @@ end
|
|||
function M.disassociate()
|
||||
|
||||
M.setStatus(M.NOT_CONNECTED,"Not connected");
|
||||
|
||||
|
||||
wifi.activateConfig()
|
||||
return wifi.restart()
|
||||
end
|
||||
|
||||
function M.getStatus()
|
||||
log:info("getStatus")
|
||||
log:verbose(MOD_ABBR, "network:getStatus")
|
||||
local file, error = io.open('/tmp/networkstatus.txt','r')
|
||||
if file == nil then
|
||||
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
||||
--log:error(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error)
|
||||
return "",""
|
||||
else
|
||||
local status = file:read('*a')
|
||||
--log:info(" status: "..utils.dump(status))
|
||||
file:close()
|
||||
local parts = {}
|
||||
local code, msg = string.match(status, "([^|]+)|+(.*)")
|
||||
--log:info(" code: "..utils.dump(code))
|
||||
--log:info(" msg: "..utils.dump(msg))
|
||||
local code, msg = string.match(status, '([^|]+)|+(.*)')
|
||||
log:verbose(MOD_ABBR, " raw status: "..utils.dump(status).." (code: "..utils.dump(code)..", msg: "..utils.dump(msg)..")")
|
||||
return code,msg
|
||||
end
|
||||
end
|
||||
|
||||
function M.setStatus(code,msg)
|
||||
log:info("setStatus: "..code.." | "..msg)
|
||||
log:info(MOD_ABBR, "network:setStatus: "..code.." | "..msg)
|
||||
local file = io.open('/tmp/networkstatus.txt','w')
|
||||
file:write(code.."|"..msg)
|
||||
file:flush()
|
||||
|
|
|
@ -1,30 +1,114 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- TODO: document
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local uci = require('uci').cursor()
|
||||
local iwinfo = require('iwinfo')
|
||||
local settings = require('util.settings')
|
||||
local wifi = require("network.wlanconfig")
|
||||
local urlcode = require('util.urlcode')
|
||||
local status = require('util.status')
|
||||
|
||||
local M = {}
|
||||
|
||||
local STATUS_FILE = "signinstatus"
|
||||
local MOD_ABBR = "NTSI"
|
||||
|
||||
local IDLE_STATUS = 1
|
||||
local SIGNING_IN_STATUS = 2
|
||||
|
||||
--- Signin to connect.doodle3d.com server
|
||||
--
|
||||
--
|
||||
function M.signin()
|
||||
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
||||
|
||||
local localip = wifi.getLocalIP();
|
||||
if localip == nil then
|
||||
log:error("signin failed no local ip found")
|
||||
return false
|
||||
log:verbose(MOD_ABBR, "signin:signin");
|
||||
|
||||
local code, msg = M.getStatus()
|
||||
--log:verbose(MOD_ABBR, " status: "..utils.dump(code).." "..utils.dump(msg));
|
||||
|
||||
-- if we are already signin in, skip
|
||||
if(code == SIGNING_IN_STATUS) then
|
||||
log:verbose(MOD_ABBR, " already signing in, skipping")
|
||||
return
|
||||
end
|
||||
|
||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||
|
||||
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||
local output = utils.captureCommandOutput(cmd);
|
||||
log:info("signin: "..output)
|
||||
|
||||
return string.len(output) > 0, output
|
||||
|
||||
local ds = wifi.getDeviceState()
|
||||
log:verbose(MOD_ABBR, " wifi deviceState.mode: "..utils.dump(ds.mode))
|
||||
if ds.mode ~= "sta" then
|
||||
log:verbose(MOD_ABBR, " wifi not in station mode, skipping signin")
|
||||
return
|
||||
end
|
||||
|
||||
M.setStatus(SIGNING_IN_STATUS,"signing in")
|
||||
|
||||
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
||||
|
||||
local attemptInterval = 1
|
||||
local maxAttempts = 20
|
||||
local attempt = 0
|
||||
|
||||
local nextAttemptTime = os.time()
|
||||
|
||||
local localip = ""
|
||||
local signinResponse = ""
|
||||
while true do
|
||||
if os.time() > nextAttemptTime then
|
||||
log:verbose(MOD_ABBR, " signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||
local signedin = false
|
||||
local localip = wifi.getLocalIP();
|
||||
--log:verbose(MOD_ABBR, " localip: "..utils.dump(localip))
|
||||
if localip ~= nil then
|
||||
|
||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||
wifiboxid = urlcode.escape(wifiboxid)
|
||||
|
||||
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||
signinResponse = utils.captureCommandOutput(cmd);
|
||||
log:verbose(MOD_ABBR, " signin response: \n"..utils.dump(signinResponse))
|
||||
local success = signinResponse:match('"status":"success"')
|
||||
log:verbose(MOD_ABBR, " success: "..utils.dump(success))
|
||||
if success ~= nil then
|
||||
signedin = true
|
||||
else
|
||||
log:warning(MOD_ABBR, "signin failed, request failed (response: "..utils.dump(signinResponse)..")")
|
||||
end
|
||||
else
|
||||
log:warning(MOD_ABBR, "signin failed, no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
||||
end
|
||||
|
||||
if signedin then
|
||||
break
|
||||
else
|
||||
attempt = attempt+1
|
||||
if attempt >= maxAttempts then
|
||||
-- still no localIP; fail
|
||||
M.setStatus(IDLE_STATUS,"idle")
|
||||
return false
|
||||
else
|
||||
nextAttemptTime = os.time() + attemptInterval
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.setStatus(IDLE_STATUS,"idle")
|
||||
return string.len(signinResponse) > 0, signinResponse
|
||||
end
|
||||
|
||||
return M
|
||||
function M.getStatus()
|
||||
return status.get(STATUS_FILE);
|
||||
end
|
||||
|
||||
function M.setStatus(code,msg)
|
||||
log:verbose(MOD_ABBR, "signin:setStatus: " .. code .. " (" .. msg .. ")")
|
||||
status.set(STATUS_FILE,code,msg);
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local uci = require('uci').cursor()
|
||||
|
@ -5,6 +13,8 @@ local iwinfo = require('iwinfo')
|
|||
|
||||
local M = {}
|
||||
|
||||
local MOD_ABBR = "NTWL"
|
||||
|
||||
-- NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
||||
M.DFL_DEVICE = 'wlan0'
|
||||
M.DFL_DEVICE_FALLBACK = 'radio0'
|
||||
|
@ -17,14 +27,14 @@ local deviceName, deviceApi
|
|||
local cachedApSsid, baseApSsid = nil, nil
|
||||
|
||||
function M.getSubstitutedSsid(unformattedSsid)
|
||||
log:verbose(MOD_ABBR, "getSubstitutedSsid unformattedSsid:'" .. (unformattedSsid or "nil") .. "' baseApSsid:'" .. (baseApSsid or "nil") .. "' cachedApSsid:'" .. (cachedApSsid or "nil"))
|
||||
if unformattedSsid == baseApSsid and cachedApSsid ~= nil then return cachedApSsid end
|
||||
if not unformattedSsid or type(unformattedSsid) ~= 'string' then return nil end
|
||||
|
||||
local macTail = M.getMacAddress():sub(7)
|
||||
|
||||
log:verbose(MOD_ABBR, " macTail:'" .. macTail)
|
||||
baseApSsid = unformattedSsid
|
||||
cachedApSsid = unformattedSsid:gsub('%%%%MAC_ADDR_TAIL%%%%', macTail)
|
||||
|
||||
return cachedApSsid
|
||||
end
|
||||
|
||||
|
@ -67,7 +77,7 @@ function M.init(device)
|
|||
deviceName = M.DFL_DEVICE_FALLBACK
|
||||
deviceApi = iwinfo.type(deviceName)
|
||||
|
||||
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
||||
log:info(MOD_ABBR, "wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
||||
|
||||
if not deviceApi then
|
||||
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
||||
|
@ -99,7 +109,9 @@ end
|
|||
--returns the wireless device's MAC address (as string, without colons)
|
||||
--(lua numbers on openWrt seem to be 32bit so they cannot represent a MAC address as one number)
|
||||
function M.getMacAddress()
|
||||
log:verbose(MOD_ABBR, "getMacAddress")
|
||||
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
||||
log:verbose(MOD_ABBR, " macText: '" .. (macText or "nil") .. "'")
|
||||
local out = ''
|
||||
|
||||
-- Hack to prevent failure in case the MAC address could not be obtained.
|
||||
|
@ -116,8 +128,10 @@ end
|
|||
--returns the wireless local ip address
|
||||
function M.getLocalIP()
|
||||
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
||||
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
||||
return localip;
|
||||
log:bulk(MOD_ABBR, " ifconfig: \n"..utils.dump(ifconfig));
|
||||
|
||||
local localip = ifconfig:match('inet addr:([%d%.]+)')
|
||||
return localip
|
||||
end
|
||||
|
||||
function M.getDeviceName()
|
||||
|
@ -128,9 +142,10 @@ end
|
|||
-- @param ssid return data for given SSID or for all networks if SSID not given
|
||||
-- @return data for all or requested network; false+error on failure or nil when requested network not found
|
||||
function M.getScanInfo(ssid)
|
||||
|
||||
local iw = iwinfo[deviceApi]
|
||||
log:info(MOD_ABBR, "start wifi scan")
|
||||
local sr = iw.scanlist(deviceName)
|
||||
log:info(MOD_ABBR, "wifi scan done")
|
||||
local si, se
|
||||
|
||||
if ssid == nil then
|
||||
|
@ -162,12 +177,13 @@ end
|
|||
function M.removeConfig(ssid)
|
||||
local rv = false
|
||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||
log:verbose(MOD_ABBR, utils.dump(s.ssid).."\n "..utils.dump(s))
|
||||
if s.ssid == ssid then
|
||||
uci:delete('wireless', s['.name'])
|
||||
rv = true
|
||||
return false
|
||||
log:verbose(MOD_ABBR, "deleting faulty ssid: "..utils.dump(s['.name']))
|
||||
rv = uci:delete('wireless', s['.name'])
|
||||
end
|
||||
end)
|
||||
uci:save('wireless')
|
||||
uci:commit('wireless')
|
||||
return rv
|
||||
end
|
||||
|
@ -175,12 +191,12 @@ end
|
|||
--- Activate wireless section for given SSID and disable all others
|
||||
-- @param ssid SSID of config to enable, or nil to disable all network configs
|
||||
function M.activateConfig(ssid)
|
||||
--log:info("wlanconfig.activateConfig: "..ssid);
|
||||
log:verbose(MOD_ABBR, "wlanconfig.activateConfig: "..ssid);
|
||||
|
||||
-- make sure only one is enabled
|
||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||
local disabled = s.ssid ~= ssid and '1' or '0'
|
||||
--log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
|
||||
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
|
||||
uci:set('wireless', s['.name'], 'disabled', disabled)
|
||||
end)
|
||||
|
||||
|
@ -198,11 +214,14 @@ function M.activateConfig(ssid)
|
|||
return false
|
||||
end
|
||||
end)
|
||||
--[[log:info(" result:");
|
||||
|
||||
--[[
|
||||
log:verbose(MOD_ABBR, " wifi reorder result:");
|
||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||
local disabled = s.ssid ~= ssid and '1' or '0'
|
||||
log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
|
||||
end)]]--
|
||||
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
|
||||
end)
|
||||
--]]
|
||||
|
||||
uci:commit('wireless')
|
||||
end
|
||||
|
@ -220,7 +239,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||
network = M.NET,
|
||||
device = 'radio0',
|
||||
ssid = info.ssid,
|
||||
bssid = info.bssid,
|
||||
--bssid = info.bssid,
|
||||
encryption = M.mapEncryptionType(info.encryption),
|
||||
mode = mode,
|
||||
}
|
||||
|
@ -228,8 +247,9 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||
apconfig.disabled = disabled ~= nil and disabled and 1 or 0
|
||||
|
||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||
if s.bssid == info.bssid then
|
||||
log:debug("removing old wireless config for net '" .. s.ssid .. "(bssid: " .. s.bssid .. ")'")
|
||||
--if s.bssid == info.bssid then
|
||||
if s.ssid == info.ssid then
|
||||
log:verbose(MOD_ABBR, "removing old wireless config for net '" .. s.ssid .. "'")
|
||||
uci:delete('wireless', s['.name'])
|
||||
-- return false --keep looking, just in case multiple entries with this bssid exist
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#src/gz wifibox http://doodle3d.com/static/wifibox-packages
|
||||
src/gz wifibox http://192.168.5.2/~wouter/wifibox-packages
|
||||
src/gz wifibox http://doodle3d.com/updates/feed
|
||||
#src/gz wifibox http://192.168.5.2/~USERNAME/wifibox/updates/feed
|
||||
dest root /
|
||||
dest ram /tmp
|
||||
lists_dir ext /var/opkg-lists
|
||||
|
|
|
@ -1,43 +1,147 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local settings = require('util.settings')
|
||||
local printer = require('util.printer')
|
||||
local signin = require('network.signin')
|
||||
--local signin = require('network.signin')
|
||||
local wifi = require('network.wlanconfig')
|
||||
local accessManager = require('util.access')
|
||||
local printerAPI = require('rest.api.api_printer')
|
||||
|
||||
local MOD_ABBR = "ACFG"
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
}
|
||||
|
||||
-- TODO: this function is also defined in 2 other places, combine them (and avoid require loops)
|
||||
local function operationsAccessOrFail(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return false
|
||||
end
|
||||
|
||||
local rv, printerState = printerAPI.state(request, response, true)
|
||||
-- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy'
|
||||
if rv == false then return true end
|
||||
|
||||
if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then
|
||||
response:setFail("Printer is busy, please wait")
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function M._global_GET(request, response)
|
||||
response:setSuccess()
|
||||
for k,v in pairs(request:getAll()) do
|
||||
local r,m = settings.get(k)
|
||||
|
||||
if r ~= nil then response:addData(k, r)
|
||||
else response:addData(k, "could not read key ('" .. m .. "')")
|
||||
|
||||
if r ~= nil then
|
||||
response:addData(k, r)
|
||||
else
|
||||
response:addData(k, "could not read key ('" .. m .. "')")
|
||||
response:setError(m)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- returns substituted_wifiboxid (since version 0.10.2)
|
||||
-- returns substituted_ssid (since version 0.9.1)
|
||||
function M._global_POST(request, response)
|
||||
log:verbose(MOD_ABBR, "API:config(set)")
|
||||
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
response:setSuccess()
|
||||
|
||||
local validation = {}
|
||||
for k,v in pairs(request:getAll()) do
|
||||
local r,m = settings.set(k, v)
|
||||
|
||||
if r then response:addData(k, "ok")
|
||||
else response:addData(k, "could not set key ('" .. m .. "')")
|
||||
log:verbose(MOD_ABBR, " about to set '"..k.."' -> '"..v.."'");
|
||||
local r,m = settings.set(k, v, true)
|
||||
|
||||
if r then
|
||||
validation[k] = "ok"
|
||||
elseif r == false then
|
||||
validation[k] = "could not save setting ('" .. m .. "')"
|
||||
log:info(MOD_ABBR, " failed to set '"..k.."' ("..utils.dump(m)..")")
|
||||
elseif r == nil then
|
||||
settings.commit()
|
||||
response:setError(m)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
log:info("API:Network:try signing in")
|
||||
if signin.signin() then
|
||||
log:info("API:Network:signin successfull")
|
||||
else
|
||||
log:info("API:Network:signin failed")
|
||||
end
|
||||
settings.commit()
|
||||
response:addData("validation",validation)
|
||||
|
||||
local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
response:addData("substituted_ssid",substitutedSsid)
|
||||
|
||||
local substitutedWiFiBoxID = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||
response:addData("substituted_wifiboxid",substitutedWiFiBoxID)
|
||||
end
|
||||
|
||||
function M.all_GET(request, response)
|
||||
local allSettings, msg = settings.getAll();
|
||||
if allSettings then
|
||||
response:setSuccess()
|
||||
for k,v in pairs(settings.getAll()) do
|
||||
response:addData(k,v)
|
||||
end
|
||||
else
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--- Reset specific setting to default value
|
||||
-- When an setting has a subSection only the setting in it's current subSection is reset.
|
||||
-- For example you want to reset setting _printer.startcode_
|
||||
-- and it has it's _subSection_ set to 'printer_type'
|
||||
-- and printer.type is set to 'ultimaker' then
|
||||
-- only the printer.startcode under the ultimaker subsection is removed.
|
||||
function M.reset_POST(request, response)
|
||||
--log:verbose(MOD_ABBR, "API:config/reset")
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
response:setSuccess()
|
||||
|
||||
for k,v in pairs(request:getAll()) do
|
||||
--log:info(MOD_ABBR, " "..k..": "..v);
|
||||
local r,m = settings.reset(k);
|
||||
if r ~= nil then
|
||||
response:addData(k, "ok")
|
||||
log:verbose(MOD_ABBR, " reset " .. k)
|
||||
else
|
||||
response:addData(k, "could not reset key ('" .. m .. "')")
|
||||
response:setError(m)
|
||||
log:verbose(MOD_ABBR, " could not reset key " .. k .. "(" .. m .. ")")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Reset all settings to default value
|
||||
function M.resetall_POST(request, response)
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
response:setSuccess()
|
||||
|
||||
local rv, msg = settings.resetAll()
|
||||
|
||||
if(rv == nil) then
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
|
||||
for k,v in pairs(settings.getAll()) do
|
||||
response:addData(k,v)
|
||||
end
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local lfs = require('lfs')
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
|
@ -5,15 +13,36 @@ local accessManager = require('util.access')
|
|||
local printDriver = require('print3d')
|
||||
local printerUtils = require('util.printer')
|
||||
local printerAPI = require('rest.api.api_printer')
|
||||
local wifi = require('network.wlanconfig')
|
||||
local settings = require('util.settings')
|
||||
|
||||
local MOD_ABBR = "AINF"
|
||||
|
||||
local TMP_DIR = '/tmp'
|
||||
local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
||||
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
|
||||
local WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
||||
local WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_LOG_FILENAME
|
||||
local DEFAULT_WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
||||
local DEFAULT_WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. DEFAULT_WIFIBOX_LOG_FILENAME
|
||||
local WIFIBOX_STDOUT_LOG_FILENAME = 'wifibox.stdout.log'
|
||||
local WIFIBOX_STDOUT_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME
|
||||
local WIFIBOX_VERSION_FILENAME = 'wifibox-version'
|
||||
local WIFIBOX_VERSION_FILE = '/etc/' .. WIFIBOX_VERSION_FILENAME
|
||||
local ROTATED_LOGS_DIRNAME = 'wifibox-rotated'
|
||||
local ROTATED_LOGS_DIR = TMP_DIR .. '/' .. ROTATED_LOGS_DIRNAME
|
||||
|
||||
local SYSLOG_FILENAME = 'syslog'
|
||||
local PROCESS_LIST_FILENAME = 'processes'
|
||||
local MEMINFO_FILENAME = 'meminfo'
|
||||
local MOUNTS_FILENAME = 'mounts'
|
||||
local DISKFREE_FILENAME = 'diskfree'
|
||||
|
||||
local UCI_CONFIG_FILES_TO_SAVE = { 'dhcp', 'firewall', 'network', 'system', 'wifibox', 'wireless' }
|
||||
|
||||
local USB_DIRTREE_COMMAND = "ls -R /sys/devices/platform/ehci-platform/usb1 | grep \":$\" | sed -e 's/:$//' -e 's/[^-][^\\/]*\\//--/g' -e 's/^/ /' -e 's/-/|/'"
|
||||
local USB_DIRTREE_FILENAME = 'sys_devices_platform_ehci-platform_usb1.tree'
|
||||
|
||||
local PRINT3D_BASEPATH = '/tmp'
|
||||
local PRINT3D_LOG_FILENAME_PREFIX = 'print3d-'
|
||||
local PRINT3D_LOG_FILENAME_PREFIX = 'print3d.'
|
||||
local PRINT3D_LOG_FILENAME_SUFFIX = '.log'
|
||||
local LOG_COLLECT_ARCHIVE_FILENAME = LOG_COLLECT_DIRNAME .. '.tgz'
|
||||
local LOG_COLLECT_ARCHIVE_FILE = TMP_DIR .. '/' .. LOG_COLLECT_ARCHIVE_FILENAME
|
||||
|
@ -26,45 +55,92 @@ local M = {
|
|||
isApi = true
|
||||
}
|
||||
|
||||
-- returns wifiboxid (since version 0.10.2)
|
||||
function M._global(request, response)
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
function M.firmware(request, response)
|
||||
--response:setSuccess()
|
||||
-- can return (essentially all wraps ipkg output):
|
||||
-- available (list)
|
||||
-- current
|
||||
-- latest
|
||||
-- upgradable
|
||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||
response:addData('wifiboxid', wifiboxid)
|
||||
|
||||
end
|
||||
|
||||
-- TODO: redirect stdout+stderr; handle errors
|
||||
function M.logfiles(request, response)
|
||||
local rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
||||
local rv,msg = lfs.chdir(TMP_DIR)
|
||||
local rv,sig,code,msg = nil,nil,nil,nil
|
||||
|
||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
||||
rv,msg = lfs.chdir(TMP_DIR)
|
||||
|
||||
local wifiboxLogFilePath = log:getLogFilePath()
|
||||
local wifiboxLogFileName = wifiboxLogFilePath and wifiboxLogFilePath:match('.*/(.*)')
|
||||
|
||||
|
||||
--[[ create temporary files ]]--
|
||||
|
||||
local rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
|
||||
-- copy wifibox API-script (firmware) log
|
||||
lfs.link(wifiboxLogFilePath, LOG_COLLECT_DIR .. '/' .. wifiboxLogFileName)
|
||||
|
||||
local rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||
-- copy d3dapi script stdout/stderr (fallback) log
|
||||
lfs.link(WIFIBOX_STDOUT_LOG_FILE, LOG_COLLECT_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME)
|
||||
|
||||
-- collect and copy print3d server logs
|
||||
for file in lfs.dir(PRINT3D_BASEPATH) do
|
||||
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
||||
local srcLogFile = PRINT3D_BASEPATH .. '/' .. file
|
||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
||||
local rv,sig,code = redirectedExecute('cp ' .. srcLogFile .. ' ' .. tgtLogFile)
|
||||
end
|
||||
lfs.link(srcLogFile, tgtLogFile)
|
||||
end
|
||||
end
|
||||
|
||||
local rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
||||
-- copy rotated firmware and print3d logs
|
||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME)
|
||||
for file in lfs.dir(ROTATED_LOGS_DIR) do
|
||||
local srcLogFile = ROTATED_LOGS_DIR .. '/' .. file
|
||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME .. '/' .. file
|
||||
lfs.link(srcLogFile, tgtLogFile)
|
||||
end
|
||||
|
||||
-- capture syslog
|
||||
rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||
|
||||
-- capture running processes
|
||||
rv,sig,code = os.execute('ps -w > ' .. LOG_COLLECT_DIR .. '/' .. PROCESS_LIST_FILENAME)
|
||||
|
||||
-- capture info on RAM memory
|
||||
rv,sig,code = os.execute('cat /proc/meminfo > ' .. LOG_COLLECT_DIR .. '/' .. MEMINFO_FILENAME)
|
||||
|
||||
-- capture info on mounted file systems
|
||||
rv,sig,code = os.execute('mount > ' .. LOG_COLLECT_DIR .. '/' .. MOUNTS_FILENAME)
|
||||
|
||||
-- capture info on free disk space
|
||||
rv,sig,code = os.execute('df -h > ' .. LOG_COLLECT_DIR .. '/' .. DISKFREE_FILENAME)
|
||||
|
||||
-- list directory structure for primary USB controller
|
||||
rv,sig,code = os.execute(USB_DIRTREE_COMMAND .. ' > ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
||||
|
||||
rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_VERSION_FILE .. ' ' .. LOG_COLLECT_DIR)
|
||||
|
||||
-- copy relevant openwrt configuration files
|
||||
-- Note: we cannot link them because that would require the link to span over filesystems
|
||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR .. '/config')
|
||||
for _,v in pairs(UCI_CONFIG_FILES_TO_SAVE) do
|
||||
local srcFile = '/etc/config/' .. v
|
||||
local tgtFile = LOG_COLLECT_DIR .. '/config/' .. v
|
||||
if v ~= 'wireless' then
|
||||
rv,sig,code = redirectedExecute('cp ' .. srcFile .. ' ' .. tgtFile)
|
||||
else
|
||||
-- replace WiFi passwords with '...'
|
||||
rv,sig,code = os.execute("sed \"s/option key '.*'/option key '...'/g\" " .. srcFile .. " > " .. tgtFile)
|
||||
end
|
||||
end
|
||||
|
||||
-- create tar.gz archive of the files/data we collected
|
||||
rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
||||
|
||||
|
||||
--[[ add response content ]]--
|
||||
|
||||
local rv,msg = response:setBinaryFileData(LOG_COLLECT_ARCHIVE_FILE, LOG_COLLECT_ARCHIVE_FILENAME, 'application/x-compressed')
|
||||
rv,msg = response:setBinaryFileData(LOG_COLLECT_ARCHIVE_FILE, LOG_COLLECT_ARCHIVE_FILENAME, 'application/x-compressed')
|
||||
if not rv then
|
||||
response:setError("could not set binary data from file '" .. LOG_COLLECT_ARCHIVE_FILE .. "' (" .. msg .. ")")
|
||||
else
|
||||
|
@ -77,55 +153,51 @@ function M.logfiles(request, response)
|
|||
for file in lfs.dir(LOG_COLLECT_DIR) do
|
||||
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
||||
local rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
|
||||
rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
|
||||
end
|
||||
end
|
||||
|
||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_LOG_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/config/*')
|
||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR .. '/config')
|
||||
|
||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||
-- Note: this assumes the rotated logs directory does not contain subdirectories
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME .. '/*')
|
||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME)
|
||||
|
||||
local rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_VERSION_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. DISKFREE_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MOUNTS_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MEMINFO_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. PROCESS_LIST_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME)
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. wifiboxLogFileName)
|
||||
|
||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_ARCHIVE_FILE)
|
||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
||||
|
||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_ARCHIVE_FILE)
|
||||
end
|
||||
|
||||
function M.access(request, response)
|
||||
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
||||
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
|
||||
|
||||
-- when there is a controller we check if the printer is idle,
|
||||
-- if so, it should be done printing and we can clear the controller
|
||||
if accessManager.getController() ~= "" then
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
local rv,msg = printer:getState()
|
||||
if rv then
|
||||
response:setSuccess()
|
||||
if(state == "idle") then -- TODO: define in constants somewhere
|
||||
accessManager.setController("") -- clear controller
|
||||
end
|
||||
else
|
||||
response:setError(msg)
|
||||
return false
|
||||
end
|
||||
end
|
||||
--log:info(MOD_ABBR, " remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
||||
--log:info(MOD_ABBR, " controller: |"..utils.dump(accessManager.getController()).."|");
|
||||
|
||||
local hasControl = accessManager.hasControl(request.remoteAddress)
|
||||
-- if hasControl then log:info(MOD_ABBR, " hasControl: true")
|
||||
-- else log:info(MOD_ABBR, " hasControl: false") end
|
||||
response:setSuccess()
|
||||
|
||||
response:addData('has_control', hasControl)
|
||||
|
||||
return true
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function M.status(request, response)
|
||||
|
||||
local rv
|
||||
rv, state = printerAPI.state(request, response)
|
||||
|
||||
local rv, state = printerAPI.state(request, response)
|
||||
if(rv == false) then return end
|
||||
|
||||
if(state ~= "disconnected") then
|
||||
|
||||
if state ~= "disconnected" and state ~= "connecting" then
|
||||
rv = printerAPI.temperature(request, response)
|
||||
if(rv == false) then return end
|
||||
rv = printerAPI.progress(request, response)
|
||||
|
@ -133,7 +205,6 @@ function M.status(request, response)
|
|||
rv = M.access(request, response)
|
||||
if(rv == false) then return end
|
||||
end
|
||||
response:addData('v', 10)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local settings = require('util.settings')
|
||||
local utils = require('util.utils')
|
||||
|
@ -5,12 +13,36 @@ local netconf = require('network.netconfig')
|
|||
local wifi = require('network.wlanconfig')
|
||||
local ResponseClass = require('rest.response')
|
||||
local signin = require('network.signin')
|
||||
local accessManager = require('util.access')
|
||||
local printerAPI = require('rest.api.api_printer')
|
||||
|
||||
local MOD_ABBR = "ANET"
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
}
|
||||
|
||||
|
||||
-- TODO: this function is also defined in 2 other places, combine them (and avoid require loops)
|
||||
local function operationsAccessOrFail(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return false
|
||||
end
|
||||
|
||||
local rv, printerState = printerAPI.state(request, response, true)
|
||||
-- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy'
|
||||
if rv == false then return true end
|
||||
|
||||
if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then
|
||||
response:setFail("Printer is busy, please wait")
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function M._global(request, response)
|
||||
response:setError("not implemented")
|
||||
end
|
||||
|
@ -82,7 +114,7 @@ function M.status(request, response)
|
|||
response:addData("status",statusCode)
|
||||
response:addData("statusMessage",statusMessage)
|
||||
response:setSuccess(statusMessage)
|
||||
|
||||
|
||||
response:addData("ssid", ds.ssid or "")
|
||||
response:addData("bssid", ds.bssid or "")
|
||||
response:addData("channel", ds.channel or "")
|
||||
|
@ -93,11 +125,11 @@ function M.status(request, response)
|
|||
response:addData("txpower", ds.txpower)
|
||||
response:addData("signal", ds.signal)
|
||||
response:addData("noise", ds.noise)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if withRaw then response:addData("_raw", utils.dump(ds)) end
|
||||
|
||||
|
||||
local localip = wifi.getLocalIP()
|
||||
response:addData("localip", localip)
|
||||
end
|
||||
|
@ -112,27 +144,37 @@ function M.associate_POST(request, response)
|
|||
response:setError("missing ssid argument")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
response:setSuccess("wlan is trying to associate")
|
||||
|
||||
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
|
||||
if rv then
|
||||
log:info("associated to wifi: "..utils.dump(argSsid))
|
||||
else
|
||||
log:info("failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")")
|
||||
log:info(MOD_ABBR, "associated to wifi: "..utils.dump(argSsid))
|
||||
else
|
||||
log:info(MOD_ABBR, "failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")")
|
||||
wifi.removeConfig(argSsid)
|
||||
local backupssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
netconf.setupAccessPoint(backupssid)
|
||||
netconf.enableAccessPoint(backupssid)
|
||||
wifi.removeConfig(argSsid)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
function M.disassociate_POST(request, response)
|
||||
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
local rv = netconf.disassociate()
|
||||
|
||||
|
||||
response:setSuccess("all wireless networks deactivated")
|
||||
response:addData("wifi_restart_result", rv)
|
||||
end
|
||||
|
||||
function M.openap_POST(request, response)
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
local rv,msg = netconf.setupAccessPoint(ssid)
|
||||
|
||||
|
@ -154,6 +196,8 @@ function M.remove_POST(request, response)
|
|||
return
|
||||
end
|
||||
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
if wifi.removeConfig(argSsid) then
|
||||
response:setSuccess("removed wireless network with requested SSID")
|
||||
response:addData("ssid", argSsid)
|
||||
|
@ -164,14 +208,13 @@ function M.remove_POST(request, response)
|
|||
end
|
||||
|
||||
function M.signin(request, response)
|
||||
log:info("API:Network:signin")
|
||||
local success, output = signin.signin()
|
||||
if success then
|
||||
log:info("API:Network:signed in")
|
||||
log:info(MOD_ABBR, "signed in")
|
||||
response:setSuccess("API:Network:signed in")
|
||||
response:addData("response", output)
|
||||
else
|
||||
log:info("API:Network:Signing in failed")
|
||||
else
|
||||
log:warning(MOD_ABBR, "signing in failed")
|
||||
response:setError("Signing in failed")
|
||||
end
|
||||
end
|
||||
|
@ -180,4 +223,17 @@ function M.alive(request, response)
|
|||
response:setSuccess("alive")
|
||||
end
|
||||
|
||||
function M.reset_POST(request, response)
|
||||
response:setSuccess("Resetting networks")
|
||||
|
||||
log:info(MOD_ABBR, "Resetting networks")
|
||||
for _, net in ipairs(wifi.getConfigs()) do
|
||||
wifi.removeConfig(net.ssid)
|
||||
end
|
||||
|
||||
local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
netconf.setupAccessPoint(ssid)
|
||||
netconf.enableAccessPoint(ssid)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
-- TODO: return errors like in print_POST (error message in a 'msg' key instead of directly in the response) if this does not break API compatibility
|
||||
|
||||
local lfs = require('lfs')
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local settings = require('util.settings')
|
||||
local printDriver = require('print3d')
|
||||
local printerUtils = require('util.printer')
|
||||
local accessManager = require('util.access')
|
||||
|
||||
local MOD_ABBR = "APRN"
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
}
|
||||
|
@ -19,7 +29,7 @@ end
|
|||
function M.temperature(request, response)
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then return false end
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
local temperatures,msg = printer:getTemperatures()
|
||||
|
||||
|
@ -30,62 +40,124 @@ function M.temperature(request, response)
|
|||
response:addData('hotend_target', temperatures.hotend_target)
|
||||
response:addData('bed', temperatures.bed)
|
||||
response:addData('bed_target', temperatures.bed_target)
|
||||
elseif temperatures == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not get temperature information (" .. msg .. ")")
|
||||
else
|
||||
response:setError(msg)
|
||||
return false;
|
||||
end
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
local function setCurrentPrint(id)
|
||||
local cpfileName = "/tmp/current-print"
|
||||
if id == nil then
|
||||
io.popen('rm ' .. cpfileName):close()
|
||||
return true
|
||||
end
|
||||
|
||||
local cpfile = io.open(cpfileName, 'w+')
|
||||
if cpfile == nil then
|
||||
return false
|
||||
end
|
||||
cpfile:write(id)
|
||||
cpfile:close()
|
||||
return true
|
||||
end
|
||||
|
||||
local function getCurrentPrint()
|
||||
local idfile = io.open('/tmp/current-print')
|
||||
if idfile ~= nil then
|
||||
return idfile:read('*a')
|
||||
end
|
||||
end
|
||||
|
||||
local function stopFetch()
|
||||
log:verbose(MOD_ABBR, "stopping print-fetch and removing start/endgcode")
|
||||
io.popen("killall print-fetch"):close()
|
||||
io.popen("rm /tmp/startcode /tmp/endcode"):close()
|
||||
setCurrentPrint(nil)
|
||||
end
|
||||
|
||||
function M.progress(request, response)
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then return false end
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
||||
local currentLine,bufferedLines,totalLines = printer:getProgress()
|
||||
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
|
||||
|
||||
local printId = getCurrentPrint()
|
||||
|
||||
|
||||
response:addData('id', argId)
|
||||
if printId ~= nil then
|
||||
response:addData('current_print', printId)
|
||||
end
|
||||
if currentLine then
|
||||
response:setSuccess()
|
||||
response:addData('current_line', currentLine)
|
||||
response:addData('buffered_lines', bufferedLines)
|
||||
response:addData('total_lines', totalLines)
|
||||
response:addData('buffer_size', bufferSize)
|
||||
response:addData('max_buffer_size', maxBufferSize)
|
||||
response:addData('seq_number', seqNumber)
|
||||
response:addData('seq_total', seqTotal)
|
||||
elseif progress == false then
|
||||
response:addData('status', bufferedLines)
|
||||
response:setFail("could not get progress information (" .. bufferedLines .. ")")
|
||||
else
|
||||
response:setError(bufferedLines)
|
||||
return false
|
||||
end
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
function M.state(request, response)
|
||||
-- Note: onlyReturnState is optional and prevents response from being modified, used when calling from within other api call
|
||||
-- Note: unlike regular API-functions, this one returns either true+state or false
|
||||
function M.state(request, response, onlyReturnState)
|
||||
local argId = request:get("id")
|
||||
response:addData('id', argId)
|
||||
|
||||
if not onlyReturnState then response:addData('id', argId) end
|
||||
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then
|
||||
response:setSuccess()
|
||||
if not printer then
|
||||
local printerState = "disconnected"
|
||||
response:addData('state', printerState)
|
||||
if not onlyReturnState then
|
||||
response:setSuccess()
|
||||
response:addData('state', printerState)
|
||||
end
|
||||
return true, printerState
|
||||
else
|
||||
elseif not printer:hasSocket() then
|
||||
-- while dev is present but no server is running yet, return 'fake' connecting state
|
||||
local printerState = "connecting"
|
||||
if not onlyReturnState then
|
||||
response:setSuccess()
|
||||
response:addData('state', printerState)
|
||||
end
|
||||
return true, printerState
|
||||
else
|
||||
local rv,msg = printer:getState()
|
||||
if rv then
|
||||
response:setSuccess()
|
||||
response:addData('state', rv)
|
||||
if not onlyReturnState then
|
||||
response:setSuccess()
|
||||
response:addData('state', rv)
|
||||
end
|
||||
return true, rv
|
||||
else
|
||||
response:setError(msg)
|
||||
else -- Note: do not differentiate between false and nil here, false should never be returned
|
||||
if not onlyReturnState then response:setError(msg) end
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true;
|
||||
|
||||
--this point cannot be reached, no return necessary
|
||||
end
|
||||
|
||||
function M.heatup_POST(request, response)
|
||||
-- retrieve a list of 3D printers currently supported
|
||||
function M.listall(request, response)
|
||||
response:setSuccess()
|
||||
response:addData('printers', printerUtils.supportedPrinters())
|
||||
end
|
||||
|
||||
|
||||
|
||||
function M.heatup_POST(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
|
@ -93,63 +165,174 @@ function M.heatup_POST(request, response)
|
|||
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then return false end
|
||||
if not printer or not printer:hasSocket() then return false end
|
||||
|
||||
local temperature = settings.get('printer.heatup.temperature')
|
||||
local rv,msg = printer:heatup(temperature)
|
||||
|
||||
response:addData('id', argId)
|
||||
if rv then response:setSuccess()
|
||||
else response:setFail(msg)
|
||||
if rv then
|
||||
response:setSuccess()
|
||||
elseif rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not start heatup (" .. msg .. ")")
|
||||
else
|
||||
response:setError(msg)
|
||||
end
|
||||
end
|
||||
|
||||
function M.stop_POST(request, response)
|
||||
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
end
|
||||
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then return end
|
||||
|
||||
local endGcode = settings.get('printer.endgcode')
|
||||
local rv,msg = printer:stopPrint(endGcode)
|
||||
|
||||
response:addData('id', argId)
|
||||
if rv then response:setSuccess()
|
||||
else response:setError(msg)
|
||||
end
|
||||
end
|
||||
|
||||
--accepts: first(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
||||
--accepts: start(bool) (only when this argument is true will printing be started)
|
||||
function M.print_POST(request, response)
|
||||
|
||||
local controllerIP = accessManager.getController()
|
||||
local hasControl = false
|
||||
if controllerIP == "" then
|
||||
accessManager.setController(request.remoteAddress)
|
||||
hasControl = true
|
||||
elseif controllerIP == request.remoteAddress then
|
||||
hasControl = true
|
||||
end
|
||||
|
||||
log:info(" hasControl: "..utils.dump(hasControl))
|
||||
if not hasControl then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
end
|
||||
|
||||
local argId = request:get("id")
|
||||
local argGcode = request:get("gcode")
|
||||
local argIsFirst = utils.toboolean(request:get("first"))
|
||||
local argStart = utils.toboolean(request:get("start"))
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
stopFetch()
|
||||
|
||||
if(argGcode == nil) then
|
||||
argGcode = ""
|
||||
end
|
||||
local rv,msg = printer:stopPrint(argGcode)
|
||||
|
||||
|
||||
response:addData('id', argId)
|
||||
if rv then
|
||||
response:setSuccess()
|
||||
elseif rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not stop print (" .. msg .. ")")
|
||||
else
|
||||
response:setError(msg)
|
||||
end
|
||||
end
|
||||
|
||||
-- Used only in print_POST(); not nested for performance reasons
|
||||
local function addSequenceNumbering(printer, response)
|
||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
||||
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
|
||||
if currentLine then
|
||||
response:addData('seq_number', seqNumber)
|
||||
response:addData('seq_total', seqTotal)
|
||||
--else
|
||||
--Note: getProgress failure is ignored (unlikely to happen if the other calls work, and also not really fatal here).
|
||||
-- Alternatively, we could still add the fields with a special value (NaN is not supported by json, so perhaps -2?)
|
||||
end
|
||||
end
|
||||
|
||||
function M.fetch_POST(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
else
|
||||
accessManager.setController(request.remoteAddress)
|
||||
end
|
||||
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer then return end
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
local state = printer:getState()
|
||||
if state ~= "idle" then
|
||||
response:setFail("printer is not idle")
|
||||
return
|
||||
end
|
||||
|
||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
||||
stopFetch()
|
||||
local rv,msg = printer:clearGcode()
|
||||
|
||||
if rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not clear gcode (" .. msg .. ")")
|
||||
elseif rv == nil then
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local gcodeFiles = " "
|
||||
local startCode = request:get("start_code")
|
||||
if startCode ~= nil then
|
||||
gcodeFiles = gcodeFiles .. '/tmp/startcode '
|
||||
local startCodeFile = io.open('/tmp/startcode', 'w+')
|
||||
if startCodeFile == nil then
|
||||
response:setError("could not open startCode file for writing")
|
||||
return
|
||||
end
|
||||
startCodeFile:write(startCode)
|
||||
end
|
||||
|
||||
local endCode = request:get("end_code")
|
||||
if endCode ~= nil then
|
||||
gcodeFiles = gcodeFiles .. '/tmp/endcode '
|
||||
local endCodeFile = io.open('/tmp/endcode', 'w+')
|
||||
if endCodeFile == nil then
|
||||
response:setError("could not open endcode file for writing")
|
||||
return
|
||||
end
|
||||
endCodeFile:write(endCode)
|
||||
end
|
||||
|
||||
local socket = printer:getId()
|
||||
if socket == nil then
|
||||
response:setError("no socket found")
|
||||
return
|
||||
end
|
||||
local gcodeServer = settings.get('gcode.server')
|
||||
if gcodeServer == nil then
|
||||
response:setError("no gcode server configured")
|
||||
return
|
||||
end
|
||||
local id = request:get("id")
|
||||
if id == nil then
|
||||
response:setError("no id supplied")
|
||||
return
|
||||
end
|
||||
setCurrentPrint(id)
|
||||
|
||||
log:info(MOD_ABBR, " starting fetch print. id: " .. id .. " server: " .. gcodeServer)
|
||||
io.popen("print-fetch " .. socket .. " " .. gcodeServer .. " " .. id .. gcodeFiles)
|
||||
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
--requires: gcode(string) (the gcode to be appended)
|
||||
--accepts: id(string) (the printer ID to append to)
|
||||
--accepts: clear(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
||||
--accepts: first(deprecated) (an alias for 'clear')
|
||||
--accepts: start(bool) (only when this argument is true will printing be started)
|
||||
--accepts: total_lines(int) (the total number of lines that is going to be sent, will be used only for reporting progress)
|
||||
--accepts: seq_number(int) (sequence number of the chunk, must be given until clear() after given once, and incremented each time)
|
||||
--accepts: seq_total(int) (total number of gcode chunks to be appended, must be given until clear() after given once, and stay the same)
|
||||
--returns: when the gcode buffer cannot accept the gcode, or the IPC transaction fails,
|
||||
-- a fail with a (formal, i.e., parseable) status argument will be returned;
|
||||
-- additionally, current sequence number and total will be returned (both are -1 if they have not been set)
|
||||
function M.print_POST(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
else
|
||||
accessManager.setController(request.remoteAddress)
|
||||
end
|
||||
local argId = request:get("id")
|
||||
local argGcode = request:get("gcode")
|
||||
local argClear = utils.toboolean(request:get("clear"))
|
||||
local argIsFirst = utils.toboolean(request:get("first")) -- deprecated
|
||||
local argStart = utils.toboolean(request:get("start"))
|
||||
local argTotalLines = request:get("total_lines") or -1
|
||||
local argSeqNumber = request:get("seq_number") or -1
|
||||
local argSeqTotal = request:get("seq_total") or -1
|
||||
local remoteHost = request:getRemoteHost()
|
||||
|
||||
log:info(MOD_ABBR, "print chunk metadata: total_lines=" .. argTotalLines .. ", seq_number=" .. argSeqNumber .. ", seq_total=" .. argSeqTotal)
|
||||
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
stopFetch()
|
||||
|
||||
response:addData('id', argId)
|
||||
|
||||
|
@ -158,12 +341,15 @@ function M.print_POST(request, response)
|
|||
return
|
||||
end
|
||||
|
||||
if argIsFirst == true then
|
||||
log:debug("clearing all gcode for " .. printer:getId())
|
||||
if argClear == true or argIsFirst == true then
|
||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
||||
response:addData('gcode_clear',true)
|
||||
local rv,msg = printer:clearGcode()
|
||||
|
||||
if not rv then
|
||||
if rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not clear gcode (" .. msg .. ")")
|
||||
elseif rv == nil then
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
|
@ -171,14 +357,20 @@ function M.print_POST(request, response)
|
|||
|
||||
local rv,msg
|
||||
|
||||
-- TODO: return errors with a separate argument like here in the rest of the code (this is how we designed the API right?)
|
||||
rv,msg = printer:appendGcode(argGcode)
|
||||
rv,msg = printer:appendGcode(argGcode, argTotalLines, { seq_number = argSeqNumber, seq_total = argSeqTotal, source = remoteHost })
|
||||
if rv then
|
||||
addSequenceNumbering(printer, response)
|
||||
--NOTE: this does not report the number of lines, but only the block which has just been added
|
||||
response:addData('gcode_append',argGcode:len())
|
||||
elseif rv == false then
|
||||
addSequenceNumbering(printer, response)
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not add gcode (" .. msg .. ")")
|
||||
return
|
||||
else
|
||||
response:setError("could not add gcode")
|
||||
addSequenceNumbering(printer, response)
|
||||
response:addData('msg', msg)
|
||||
response:setError("could not add gcode (" .. msg .. ")")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -188,9 +380,14 @@ function M.print_POST(request, response)
|
|||
if rv then
|
||||
response:setSuccess()
|
||||
response:addData('gcode_print',true)
|
||||
elseif rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not send gcode (" .. msg .. ")")
|
||||
return
|
||||
else
|
||||
response:setError("could not send gcode")
|
||||
response:addData('msg', msg)
|
||||
response:setError("could not send gcode (" .. msg .. ")")
|
||||
return
|
||||
end
|
||||
else
|
||||
response:setSuccess()
|
||||
|
|
226
src/rest/api/api_sketch.lua
Normal file
226
src/rest/api/api_sketch.lua
Normal file
|
@ -0,0 +1,226 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
--[[
|
||||
This module uses the Lua filesystem library to iterate over all sketches.
|
||||
A more flexible approach would be to use an index file (like the update module does).
|
||||
That way, we could also store arbitrary meta-data together with the sketches.
|
||||
]]--
|
||||
|
||||
local lfs = require('lfs')
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
|
||||
local MOD_ABBR = "ASKE"
|
||||
|
||||
local M = {
|
||||
isApi = true,
|
||||
SKETCH_DIR = '/root/sketches',
|
||||
MIN_FREE_SPACE = 1024 * 80
|
||||
}
|
||||
|
||||
local NUMBER_PAD_WIDTH = 5
|
||||
local SKETCH_FILE_EXTENSION = 'svg'
|
||||
|
||||
|
||||
-- creates sketch directory, and sets response to error state on failure
|
||||
local function createSketchDirectory()
|
||||
if os.execute('mkdir -p ' .. M.SKETCH_DIR) ~= 0 then
|
||||
log:error(MOD_ABBR, "could not create sketch directory '" .. M.SKETCH_DIR .. "'")
|
||||
response:setError("could not create sketch directory")
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function constructSketchFilename(idx)
|
||||
return string.format('%0' .. NUMBER_PAD_WIDTH .. '.0f.%s', idx, SKETCH_FILE_EXTENSION)
|
||||
end
|
||||
|
||||
--should this return 1k-blocks or bytes?
|
||||
local function getFreeDiskSpace()
|
||||
local kb = utils.captureCommandOutput('df / -k | awk \'$3 ~ /[0-9]+/ { print $4 }\'')
|
||||
return kb * 1024
|
||||
end
|
||||
|
||||
local function createSketchList()
|
||||
local result = {}
|
||||
|
||||
for item in lfs.dir(M.SKETCH_DIR) do
|
||||
if item ~= '.' and item ~= '..' then
|
||||
local idx = item:match('^(%d+)\.'..SKETCH_FILE_EXTENSION..'$')
|
||||
if idx and idx:len() == NUMBER_PAD_WIDTH then
|
||||
table.insert(result, tonumber(idx))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(result)
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-- retrieve sketches, requires id(int)
|
||||
function M._global_GET(request, response)
|
||||
local argId = request:getBlankArgument() -- try this one first
|
||||
if not argId then argId = request:get("id") end -- and fall back to this one
|
||||
|
||||
if not argId then
|
||||
response:setError("missing id argument")
|
||||
return
|
||||
end
|
||||
argId = tonumber(argId)
|
||||
|
||||
if not createSketchDirectory(request, response) then return end
|
||||
local sketches = createSketchList()
|
||||
|
||||
local exists = false
|
||||
for _,sketchId in ipairs(sketches) do
|
||||
if sketchId == argId then
|
||||
exists = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
response:addData('id', argId)
|
||||
if exists then
|
||||
local loadFile,msg = io.open(M.SKETCH_DIR .. '/' .. constructSketchFilename(argId))
|
||||
|
||||
if not loadFile then
|
||||
response:setError("could not open sketch file for reading (" .. msg .. ")")
|
||||
return
|
||||
end
|
||||
|
||||
local data = loadFile:read('*a')
|
||||
if not data then data = '' end
|
||||
response:addData('data', data)
|
||||
|
||||
loadFile:close()
|
||||
response:setSuccess()
|
||||
else
|
||||
response:setFail("sketch not found")
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: do we need locking?
|
||||
-- save sketches, requires data(string)
|
||||
function M._global_POST(request, response)
|
||||
local argData = request:get("data")
|
||||
|
||||
if not argData then
|
||||
response:setFail("missing data argument")
|
||||
return
|
||||
elseif argData:len() == 0 then
|
||||
response:setFail("data argument must be non-empty")
|
||||
return
|
||||
end
|
||||
|
||||
if getFreeDiskSpace() - M.MIN_FREE_SPACE < argData:len() then
|
||||
response:setFail("not enough free space")
|
||||
response:addData('available', getFreeDiskSpace())
|
||||
response:addData('reserved', M.MIN_FREE_SPACE)
|
||||
response:addData('sketch_size', argData:len())
|
||||
return
|
||||
end
|
||||
|
||||
if not createSketchDirectory(request, response) then return end
|
||||
local sketches = createSketchList()
|
||||
|
||||
local listSize = table.getn(sketches)
|
||||
local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1
|
||||
local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx)
|
||||
|
||||
log:verbose(MOD_ABBR, "saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)")
|
||||
local saveFile,msg = io.open(sketchFile, 'w')
|
||||
|
||||
if not saveFile then
|
||||
response:setError("error opening sketch file for writing (".. msg .. ")")
|
||||
return
|
||||
end
|
||||
|
||||
saveFile:write(argData)
|
||||
saveFile:close()
|
||||
|
||||
response:addData('id', sketchIdx)
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- TODO: return total space used by sketches? (createSketchList() could just as well collect size info too...see lfs.attributes)
|
||||
function M.status(request, response)
|
||||
if not createSketchDirectory(request, response) then return end
|
||||
local sketches = createSketchList()
|
||||
|
||||
local listSize = table.getn(sketches)
|
||||
response:addData('number_of_sketches', table.getn(sketches))
|
||||
response:addData('available', getFreeDiskSpace())
|
||||
response:addData('reserved', M.MIN_FREE_SPACE)
|
||||
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- remove all sketches
|
||||
function M.clear_POST(request, response)
|
||||
local rv = os.execute("rm -f " .. M.SKETCH_DIR .. '/*')
|
||||
if rv == 0 then response:setSuccess()
|
||||
else response:setFail("could not remove contents of sketch directory")
|
||||
end
|
||||
end
|
||||
|
||||
-- remove single sketch
|
||||
-- function M.delete_POST(request, response)
|
||||
-- local argId = tonumber(request:get("id")) --to number will raise exception in case of illegal input
|
||||
-- local filename = M.SKETCH_DIR .. '/' .. constructSketchFilename(argId)
|
||||
-- local rv = os.execute("rm -f " .. filename)
|
||||
-- if rv == 0 then response:setSuccess()
|
||||
-- else response:setFail("could not remove " .. filename)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- recreate directory sequence by renaming files
|
||||
function M.index_POST(request, response)
|
||||
local list = {}
|
||||
local index = 1
|
||||
for item in lfs.dir(M.SKETCH_DIR) do
|
||||
if item ~= '.' and item ~= '..' then
|
||||
local idx = item:match('^(%d+)\.'..SKETCH_FILE_EXTENSION..'$')
|
||||
if idx and idx:len() == NUMBER_PAD_WIDTH then
|
||||
local src = M.SKETCH_DIR .. '/' .. item
|
||||
local dst = M.SKETCH_DIR .. '/' .. constructSketchFilename(index)
|
||||
|
||||
if src ~= dst then
|
||||
table.insert(list, src .. ' ' .. dst)
|
||||
local rv = os.execute("mv " .. src .. ' ' .. dst)
|
||||
end
|
||||
|
||||
index = index + 1
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
response:addData('list',list)
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- list files by fileID (not by index)
|
||||
function M.list_GET(request, response)
|
||||
response:addData("list",createSketchList())
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- remove single sketch by fileID (not by index)
|
||||
function M.delete_POST(request, response)
|
||||
local argId = tonumber(request:get("id")) --to number will raise exception in case of illegal input
|
||||
local filename = M.SKETCH_DIR .. '/' .. constructSketchFilename(argId)
|
||||
local rv = os.execute("rm -f " .. filename)
|
||||
if rv == 0 then response:setSuccess()
|
||||
else response:setFail("could not remove " .. filename)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local utils = require('util.utils')
|
||||
|
||||
local M = {
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local l = require("util.logger")
|
||||
local ResponseClass = require("rest.response")
|
||||
|
||||
|
|
218
src/rest/api/api_update.lua
Normal file
218
src/rest/api/api_update.lua
Normal file
|
@ -0,0 +1,218 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local wifi = require('network.wlanconfig')
|
||||
local netconf = require('network.netconfig')
|
||||
local settings = require('util.settings')
|
||||
|
||||
local MOD_ABBR = "AUPD"
|
||||
|
||||
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
||||
argStash = arg
|
||||
arg = nil
|
||||
local updater = require('script.d3d-updater')
|
||||
arg = argStash
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local accessManager = require('util.access')
|
||||
local printerAPI = require('rest.api.api_printer')
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
}
|
||||
|
||||
|
||||
-- TODO: this function is also defined in 2 other places, combine them (and avoid require loops)
|
||||
local function operationsAccessOrFail(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return false
|
||||
end
|
||||
|
||||
local rv, printerState = printerAPI.state(request, response, true)
|
||||
-- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy'
|
||||
if rv == false then return true end
|
||||
|
||||
if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then
|
||||
response:setFail("Printer is busy, please wait")
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function M.status(request, response)
|
||||
local includeBetas = settings.get('doodle3d.update.includeBetas')
|
||||
local baseUrl = settings.get('doodle3d.update.baseUrl')
|
||||
updater.setLogger(log)
|
||||
updater.setBaseUrl(baseUrl)
|
||||
updater.setUseCache(false)
|
||||
local success,status,msg = updater.getStatus(includeBetas)
|
||||
|
||||
response:addData('current_version', updater.formatVersion(status.currentVersion))
|
||||
|
||||
response:addData('state_code', status.stateCode)
|
||||
response:addData('state_text', status.stateText)
|
||||
|
||||
if not success then
|
||||
response:setFail(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local canUpdate = updater.compareVersions(status.newestVersion, status.currentVersion, status.newestReleaseTimestamp, status.currentReleaseTimestamp) > 0
|
||||
if (status.currentVersion.suffix ~= nil) and not includeBetas then canUpdate = true end -- always allow downgrade from beta to stable if !includeBetas
|
||||
|
||||
response:addData('newest_version', updater.formatVersion(status.newestVersion))
|
||||
if status.currentReleaseTimestamp then response:addData('current_release_date', updater.formatDate(status.currentReleaseTimestamp)) end
|
||||
if status.newestReleaseTimestamp then response:addData('newest_release_date', updater.formatDate(status.newestReleaseTimestamp)) end
|
||||
response:addData('can_update', canUpdate)
|
||||
|
||||
if status.progress then response:addData('progress', status.progress) end
|
||||
if status.imageSize then response:addData('image_size', status.imageSize) end
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- accepts: version(string) (major.minor.patch)
|
||||
-- accepts: clear_gcode(bool, defaults to true) (this is to lower the chance on out-of-memory crashes, but still allows overriding this behaviour)
|
||||
-- accepts: clear_images(bool, defaults to true) (same rationale as with clear_gcode)
|
||||
-- note: call this with a long timeout - downloading may take a while (e.g. ~3.3MB with slow internet...)
|
||||
function M.download_POST(request, response)
|
||||
local argVersion = request:get("version")
|
||||
local argClearGcode = utils.toboolean(request:get("clear_gcode"))
|
||||
local argClearImages = utils.toboolean(request:get("clear_images"))
|
||||
if argClearGcode == nil then argClearGcode = true end
|
||||
if argClearImages == nil then argClearImages = true end
|
||||
|
||||
-- block access to prevent potential issues with printing (e.g. out of memory)
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
local includeBetas = settings.get('doodle3d.update.includeBetas')
|
||||
local baseUrl = settings.get('doodle3d.update.baseUrl')
|
||||
updater.setLogger(log)
|
||||
updater.setBaseUrl(baseUrl)
|
||||
|
||||
updater.setState(updater.STATE.DOWNLOADING,"")
|
||||
|
||||
local vEnt, rv, msg
|
||||
|
||||
if not argVersion then
|
||||
local success,status,msg = updater.getStatus(includeBetas)
|
||||
if not success then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, msg)
|
||||
response:setFail(msg)
|
||||
return
|
||||
else
|
||||
argVersion = updater.formatVersion(status.newestVersion)
|
||||
end
|
||||
end
|
||||
|
||||
if argClearImages then
|
||||
rv,msg = updater.clear()
|
||||
if not rv then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, msg)
|
||||
response:setFail(msg)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if argClearGcode then
|
||||
response:addData('gcode_clear',true)
|
||||
local rv,msg = printer:clearGcode()
|
||||
|
||||
if not rv then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, msg)
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
vEnt,msg = updater.findVersion(argVersion, includeBetas)
|
||||
if vEnt == nil then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, "error searching version index (" .. msg .. ")")
|
||||
response:setFail("error searching version index (" .. msg .. ")")
|
||||
return
|
||||
elseif vEnt == false then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, "no such version")
|
||||
response:setFail("no such version")
|
||||
return
|
||||
end
|
||||
|
||||
rv,msg = updater.downloadImageFile(vEnt)
|
||||
if not rv then
|
||||
updater.setState(updater.STATE.DOWNLOAD_FAILED, msg)
|
||||
response:setFail(msg)
|
||||
return
|
||||
end
|
||||
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
-- if successful, this call won't return since the device will flash its memory and reboot
|
||||
-- accepts: version (string, will try to use most recent if not specified)
|
||||
-- accepts: no_retain (bool, device will be completely cleaned if true (aka '-n' flag to sysupgrade))
|
||||
function M.install_POST(request, response)
|
||||
local argVersion = request:get("version")
|
||||
local argNoRetain = request:get("no_retain")
|
||||
log:info(MOD_ABBR, "API:update/install (noRetain: "..utils.dump(argNoRetain)..")")
|
||||
local noRetain = argNoRetain == 'true'
|
||||
|
||||
if not operationsAccessOrFail(request, response) then return end
|
||||
|
||||
local includeBetas = settings.get('doodle3d.update.includeBetas')
|
||||
local baseUrl = settings.get('doodle3d.update.baseUrl')
|
||||
updater.setBaseUrl(baseUrl)
|
||||
updater.setLogger(log)
|
||||
updater.setState(updater.STATE.INSTALLING,"")
|
||||
|
||||
--local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||
--local rv,msg = netconf.enableAccessPoint(ssid)
|
||||
|
||||
if not argVersion then
|
||||
local success,status,msg = updater.getStatus(includeBetas)
|
||||
if not success then
|
||||
updater.setState(updater.STATE.INSTALL_FAILED, msg)
|
||||
response:setFail(msg)
|
||||
return
|
||||
else
|
||||
argVersion = updater.formatVersion(status.newestVersion)
|
||||
end
|
||||
end
|
||||
|
||||
vEnt,msg = updater.findVersion(argVersion, includeBetas)
|
||||
if vEnt == nil then
|
||||
updater.setState(updater.STATE.INSTALL_FAILED, "error searching version index (" .. msg .. ")")
|
||||
response:setFail("error searching version index (" .. msg .. ")")
|
||||
return
|
||||
elseif vEnt == false then
|
||||
updater.setState(updater.STATE.INSTALL_FAILED, "no such version")
|
||||
response:setFail("no such version")
|
||||
return
|
||||
end
|
||||
|
||||
local rv,msg = updater.flashImageVersion(vEnt, noRetain)
|
||||
|
||||
if not rv then
|
||||
updater.setState(updater.STATE.INSTALL_FAILED, "installation failed (" .. msg .. ")")
|
||||
response:setFail("installation failed (" .. msg .. ")")
|
||||
else
|
||||
response:setSuccess()
|
||||
end
|
||||
end
|
||||
|
||||
function M.clear_POST(request, response)
|
||||
updater.setLogger(log)
|
||||
local rv,msg = updater.clear()
|
||||
|
||||
if rv then response:setSuccess()
|
||||
else response:setFail(msg)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,3 +1,13 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- This object represents an HTTP request object, part of the REST API.
|
||||
local util = require('util.utils') -- required for string:split()
|
||||
local urlcode = require('util.urlcode')
|
||||
local confDefaults = require('conf_defaults')
|
||||
|
@ -70,6 +80,7 @@ local function resolveApiModule(modname)
|
|||
local reqModName = 'rest.api.api_' .. modname
|
||||
local ok, modObj
|
||||
|
||||
-- NOTE: with some errors, execution just seems to stop in require() (nothing is logged anymore, not even errors)
|
||||
if confDefaults.DEBUG_PCALLS then ok, modObj = true, require(reqModName)
|
||||
else ok, modObj = pcall(require, reqModName)
|
||||
end
|
||||
|
@ -156,7 +167,8 @@ setmetatable(M, {
|
|||
})
|
||||
|
||||
--This function initializes itself using various environment variables, the arg array and the given postData
|
||||
--NOTE: if debugging is enabled, commandline arguments 'm' and 'f' override requested module and function
|
||||
--NOTE: if debugging is enabled, commandline argument 'p' (path) overrides requested module and function and
|
||||
-- 'r' (rqType) overrides request method
|
||||
function M.new(environment, postData, debugEnabled)
|
||||
local self = setmetatable({}, M)
|
||||
|
||||
|
@ -169,6 +181,10 @@ function M.new(environment, postData, debugEnabled)
|
|||
self.remoteAddress = environment['REMOTE_ADDR']
|
||||
else
|
||||
self.requestMethod = 'CMDLINE'
|
||||
self.remoteHost = "cmdline"
|
||||
self.remotePort = "0"
|
||||
self.userAgent = "shell"
|
||||
self.remoteAddress = "0.0.0.0"
|
||||
end
|
||||
|
||||
self.cmdLineArgs = kvTableFromArray(arg)
|
||||
|
@ -192,7 +208,6 @@ function M.new(environment, postData, debugEnabled)
|
|||
end
|
||||
table.remove(self.pathArgs, 1) --drop the first 'empty' field caused by the opening slash of the query string
|
||||
|
||||
|
||||
if #self.pathArgs >= 1 then self.requestedApiModule = self.pathArgs[1] end
|
||||
if #self.pathArgs >= 2 then self.requestedApiFunction = self.pathArgs[2] end
|
||||
|
||||
|
|
|
@ -1,15 +1,33 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- The REST response object handles all operations necessary to generate a HTTP response.
|
||||
-- It knows about the request, ensures the correct HTTP headers are present and
|
||||
-- allows to set a status (one of `success`, `fail` or `error`) and addtional data.
|
||||
local JSON = require('util/JSON')
|
||||
local settings = require('util.settings')
|
||||
local defaults = require('conf_defaults')
|
||||
local utils = require('util.utils')
|
||||
local log = require('util.logger')
|
||||
|
||||
local M = {}
|
||||
M.__index = M
|
||||
|
||||
local REQUEST_ID_ARGUMENT = 'rq_id'
|
||||
local MOD_ABBR = "HRSP"
|
||||
|
||||
M.httpStatusCode, M.httpStatusText, M.contentType = nil, nil, nil
|
||||
M.binaryData, M.binarySavename = nil, nil
|
||||
|
||||
--- Print a HTTP header line with the given type and value.
|
||||
-- @string headerType
|
||||
-- @string headerValue
|
||||
local function printHeaderLine(headerType, headerValue)
|
||||
io.write(headerType .. ": " .. headerValue .. "\r\n")
|
||||
end
|
||||
|
@ -21,17 +39,20 @@ setmetatable(M, {
|
|||
end
|
||||
})
|
||||
|
||||
--requestObject should always be passed (except on init failure, when it is not yet available)
|
||||
--- Instantiates a new response object initialized with the given @{request} object.
|
||||
-- The request object should always be passed, except on init failure, when it is not yet available.
|
||||
-- @tparam request requestObject The object representing the HTTP request.
|
||||
-- @treturn response A newly instantiated response object.
|
||||
function M.new(requestObject)
|
||||
local self = setmetatable({}, M)
|
||||
self.body = { status = nil, data = {} }
|
||||
self:setHttpStatus(200, 'OK')
|
||||
self:setContentType('text/plain;charset=UTF-8')
|
||||
self:setContentType('application/json;charset=UTF-8')
|
||||
--self:setContentType('application/json;charset=UTF-8')
|
||||
|
||||
-- a queue for functions to be executed when the response has bin given
|
||||
-- needed for api calls like network/associate, which requires a restart of the webserver
|
||||
self.postResponseQueue = {}
|
||||
-- A queue for functions to be executed when the response has been given.
|
||||
-- Needed for api calls like network/associate, which requires a restart of the webserver.
|
||||
self.postResponseQueue = {}
|
||||
|
||||
if requestObject ~= nil then
|
||||
local rqId = requestObject:get(REQUEST_ID_ARGUMENT)
|
||||
|
@ -46,65 +67,98 @@ function M.new(requestObject)
|
|||
return self
|
||||
end
|
||||
|
||||
--- Set HTTP status (the default is `200 OK`).
|
||||
-- @number code The status code.
|
||||
-- @string text The status text, this should of course correspond to the given code.
|
||||
function M:setHttpStatus(code, text)
|
||||
if code ~= nil then self.httpStatusCode = code end
|
||||
if text ~= nil then self.httpStatusText = text end
|
||||
end
|
||||
|
||||
--- Set the HTTP content type (the default is `text/plain;charset=UTF-8`).
|
||||
-- @string contentType The content type to set.
|
||||
function M:setContentType(contentType)
|
||||
if contentType ~= nil then self.contentType = contentType end
|
||||
end
|
||||
|
||||
--- Set REST status to success.
|
||||
-- @string[opt] msg An optional human-readable message to include with the status.
|
||||
function M:setSuccess(msg)
|
||||
self.body.status = 'success'
|
||||
if msg ~= '' then self.body.msg = msg end
|
||||
end
|
||||
|
||||
--- Set REST status to failure.
|
||||
-- @string[opt] msg An optional human-readable message to include with the status.
|
||||
function M:setFail(msg)
|
||||
self.body.status = 'fail'
|
||||
if msg ~= '' then self.body.msg = msg end
|
||||
end
|
||||
|
||||
--- Set REST status to error.
|
||||
-- A reference to the API documentation will also be included.
|
||||
-- @string[opt] msg An optional human-readable message to include with the status.
|
||||
function M:setError(msg)
|
||||
self.body.status = 'error'
|
||||
if msg ~= '' then self.body.msg = msg end
|
||||
|
||||
self:addData('more_info', 'http://' .. defaults.API_BASE_URL_PATH .. '/wiki/wiki/communication-api')
|
||||
self:addData('more_info', 'http://' .. defaults.API_BASE_URL_PATH .. '/api')
|
||||
end
|
||||
|
||||
--NOTE: with this method, to add nested data, it is necessary to precreate the table and add it with its root key
|
||||
--(e.g.: response:addData('data', {f1=3, f2='x'}))
|
||||
--- Adds a data item to the response, this will be included under the `data` item of the json text.
|
||||
--
|
||||
-- NOTE: To add nested data with this method, it is necessary to precreate the table
|
||||
-- and then add that with its root key (see usage).
|
||||
--
|
||||
-- After calling this, any binary data set by @{M:setBinaryFileData} will not be sent anymore.
|
||||
--
|
||||
-- @string k The key of the item to set.
|
||||
-- @param v The value to set.
|
||||
-- @usage response:addData('f_values', {f1=3, f2='x'})
|
||||
function M:addData(k, v)
|
||||
self.body.data[k] = v
|
||||
self.binaryData = nil
|
||||
end
|
||||
|
||||
--- Queue a function for execution after the response has been passed back to the webserver.
|
||||
--
|
||||
-- Note that this is not useful in many cases since the webserver will not actually send
|
||||
-- the response until this script finishes. So for instance if the queue contains code
|
||||
-- to restart the webserver, the response will never be sent out.
|
||||
-- @func fn The function to queue.
|
||||
function M:addPostResponseFunction(fn)
|
||||
table.insert(self.postResponseQueue, fn)
|
||||
end
|
||||
|
||||
--- Call all functions on the post-response queue, see @{M:addPostResponseFunction} for details and a side-note.
|
||||
function M:executePostResponseQueue()
|
||||
--local utils = require('util.utils')
|
||||
--local log = require('util.logger')
|
||||
--log:info("Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue))
|
||||
if #self.postResponseQueue > 0 then log:verbose(MOD_ABBR, "Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue)) end
|
||||
|
||||
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
||||
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
||||
end
|
||||
|
||||
--- Returns an API url pointing to @{conf_defaults.API_BASE_URL_PATH}, which is quite useless.
|
||||
-- @string mod
|
||||
-- @string func
|
||||
-- @treturn string A not-so-useful URL.
|
||||
function M:apiURL(mod, func)
|
||||
if not mod then return nil end
|
||||
if func then func = '/' .. func else func = "" end
|
||||
return 'http://' .. defaults.API_BASE_URL_PATH .. '/cgi-bin/d3dapi/' .. mod .. func
|
||||
end
|
||||
|
||||
--- Returns the body data contained in this object as [JSON](http://www.json.org/).
|
||||
-- @treturn string The JSON data.
|
||||
function M:serializeAsJson()
|
||||
return JSON:encode(self.body)
|
||||
end
|
||||
|
||||
--- Writes HTTP headers to stdout, followed by an HTTP body containing either JSON data or a file attachment.
|
||||
function M:send()
|
||||
printHeaderLine("Status", self.httpStatusCode .. " " .. self.httpStatusText)
|
||||
printHeaderLine("Content-Type", self.contentType)
|
||||
printHeaderLine("Access-Control-Allow-Origin", "*")
|
||||
printHeaderLine("Expires", "-1")
|
||||
|
||||
if self.binaryData == nil then
|
||||
io.write("\r\n")
|
||||
|
@ -114,8 +168,20 @@ function M:send()
|
|||
io.write("\r\n")
|
||||
io.write(self.binaryData)
|
||||
end
|
||||
|
||||
if self.body.status ~= "success" then
|
||||
log:warning(MOD_ABBR, "Response status: "..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
|
||||
end
|
||||
end
|
||||
|
||||
--- Sets the response object to return binary data instead of JSON as its body.
|
||||
--
|
||||
-- After calling this, REST data and status will not be sent anymore.
|
||||
-- @string rFile The file on the local file system to read the data from.
|
||||
-- @string saveName The file name to suggest the user to save the data in.
|
||||
-- @string contentType The content type of the data.
|
||||
-- @treturn bool|nil True, or nil in which case the second argument will be set.
|
||||
-- @treturn ?string An error message if the first argument is nil.
|
||||
function M:setBinaryFileData(rFile, saveName, contentType)
|
||||
if type(rFile) ~= 'string' or rFile:len() == 0 then return false end
|
||||
|
||||
|
|
92
src/script/README-loglite.md
Normal file
92
src/script/README-loglite.md
Normal file
|
@ -0,0 +1,92 @@
|
|||
## Loglite
|
||||
|
||||
The loglite script allows coloring and filtering of log files by specifying certain patterns and associating directives to them. These mainly specify colors but additionally, (non-)matched lines can be deleted from output and also all output lines can be numbered.
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
The script can follow an existing log file (comparable to `tail -f`), or it can follow its standard input. A file to follow is always specified as the first argument and a filter set name as the second (use '-' as file name to read from standard input). Details on filter sets can be found below. If no filter set is mentioned on the command-line, the script will attempt to use one named 'default'.
|
||||
|
||||
* Example following an existing log file using a filter set named 'example':
|
||||
`./loglite.lua print3d.log example`.
|
||||
* Example using standard input, to filter/view a whole log file, with a filter set named 'serial' (note the '-' as file name):
|
||||
`cat print3d-ttyACM0.log | ./loglite.lua - serial`
|
||||
* Example using standard input, to capture both output streams from `print3d`, with a filter set named 'example' (note the '-' as file name):
|
||||
`./print3d -V 2>&1 | ./loglite.lua - example`.
|
||||
|
||||
#### On WiFi-Box
|
||||
Loglite is already installed since version 0.10.10 as `loglite`.
|
||||
Check `/root/.profile` for handy aliases like `tailfw` and `tailp3d`.
|
||||
|
||||
### Filter sets
|
||||
|
||||
The script looks for filter sets in the file '$HOME/loglite-filters.lua'. It looks like this:
|
||||
|
||||
``` lua
|
||||
local M = {}
|
||||
|
||||
M.default = {
|
||||
['options'] = { mode = 'keep', count = 'none' },
|
||||
['patterns'] = {
|
||||
['%(error%)'] = 'red',
|
||||
['%(warning%)'] = 'yellow',
|
||||
['%(bulk%)'] = 'bold,black'
|
||||
}
|
||||
}
|
||||
|
||||
M.specialization = {
|
||||
['parent'] = 'default',
|
||||
['options'] = { mode = 'delete' }
|
||||
['patterns'] = {
|
||||
['setState%(%)'] = 'bblue,_nodelete'
|
||||
}
|
||||
}
|
||||
|
||||
return M
|
||||
```
|
||||
|
||||
Here, the declaration and returning of `M` is required for the loglite script to be able to cleanly import the file. In `M.default`, 'default' is the name of a filter set being defined (similar for 'specialization'). Definitions can contain three so-called keys: 'parent' specifies a filter set to inherit from in order to reduce code duplication, 'options' and 'patterns' are described below.
|
||||
|
||||
Inheritance can be used to set new keys or to override keys from the parent set. Previously set keys cannot be removed, but they can be set to a non-existing directive (e.g., Lua's 'false' keyword) to achieve the same effect. Note that directives in inheriting sets are currently not combined with previous ones, so for instance overriding `['test'] = 'red, _delete'` with `['test'] = 'blue'` will result in only the directive 'blue' to be applied.
|
||||
|
||||
#### Options
|
||||
|
||||
Two options are currently available:
|
||||
|
||||
* `mode`, which specifies whether to keep log lines (`keep`, the default) or to drop them (`delete`). For specific lines this can then be overridden, see 'Patterns' below.
|
||||
* `count`, which can be set to `all` to prefix log lines with a counter, or `none` (default) to leave them as is.
|
||||
|
||||
#### Patterns
|
||||
|
||||
Pattern specifications are patterns as used in Lua: [Lua documentation on patterns](http://www.lua.org/pil/20.2.html).
|
||||
The following directives can be associated with a pattern:
|
||||
|
||||
* A foreground color, one of: black, red, green, yellow, blue, magenta, cyan or white.
|
||||
* A background color, like foreground colors but prefixed with 'b'.
|
||||
* `bold`, which usually has the effect of rendering a bright variant of the foreground color (note that `bold,black` renders as dark gray).
|
||||
* `reverse` will reverse fore- and background colors.
|
||||
* Also available are `blink` and `underscore` but they do currently not work in all terminal programs or might need to be enabled in the preferences.
|
||||
* `_delete` or `_nodelete` to override the active mode specified in the 'options' above.
|
||||
|
||||
Directives can be combined with ',' (e.g.: `'red,_nodelete'`). Finally, in any filter set, pattern rules are matched from top to bottom, the last one encountered overriding any previous conflicting directive.
|
||||
|
||||
### Installation
|
||||
Note: Loglite is already installed on the WiFi-Box since version 0.10.10.
|
||||
|
||||
Install Lua. See:
|
||||
http://lua-users.org/wiki/LuaBinaries
|
||||
It's tested in Lua 5.1 and Lua 5.2.
|
||||
|
||||
Loglite will check for a `loglite-filters.lua` file in your home directory. It's recommended to create a symbolic link to the latest version.
|
||||
On OS X / Linux:
|
||||
```
|
||||
cd
|
||||
ln -s [absolute path to file]/loglite-filters.lua loglite-filters.lua
|
||||
```
|
||||
|
||||
It's recommended to create a symbolic link in one of your PATH directories (`echo $PATH`) to the loglite.lua file. This allows you to run `loglite` from any directory.
|
||||
On OS X / Linux:
|
||||
```
|
||||
cd /usr/local/bin
|
||||
ln -s [absolute path to file]/loglite.lua loglite.lua
|
||||
```
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
BASE_NAME=d3d-wifibox-backup
|
||||
SRC_PATHS="/etc /root /www/ /usr/share/lua"
|
||||
TEMP_DIR=/tmp
|
||||
TGT_FILE=$BASE_NAME.tar.gz
|
||||
|
||||
if [ -e /www-external ]; then
|
||||
echo "ERROR: switch back /www-regular to /www before running this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $TEMP_DIR
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: could not cd to temporary directory ($TEMP_DIR)"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
TGT_DIR=$TEMP_DIR/$BASE_NAME
|
||||
rm -rf $TGT_DIR
|
||||
mkdir -p $TGT_DIR
|
||||
|
||||
for path in $SRC_PATHS; do
|
||||
echo "copying $path -> $TGT_DIR..."
|
||||
cp -a $path $TGT_DIR
|
||||
done
|
||||
|
||||
echo "compressing $TGT_DIR into $BASE_NAME.tar.gz..."
|
||||
tar czf $BASE_NAME.tar.gz $BASE_NAME
|
||||
|
||||
echo "removing staging dir..."
|
||||
rm -rf $TGT_DIR
|
||||
|
||||
echo "done."
|
1032
src/script/d3d-updater.lua
Normal file
1032
src/script/d3d-updater.lua
Normal file
File diff suppressed because it is too large
Load Diff
10
src/script/d3dapi
Executable file → Normal file
10
src/script/d3dapi
Executable file → Normal file
|
@ -1,19 +1,25 @@
|
|||
#!/bin/sh
|
||||
# This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
#
|
||||
# Copyright (c) 2013, Doodle3D
|
||||
# This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
# See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
# NOTE: redirection to $LOG_FILE is not required anymore, it is configurable now.
|
||||
# It is left in just as a precaution for a badly configured firmware invocation.
|
||||
|
||||
LUA=lua
|
||||
SCRIPT_PATH=/usr/share/lua/wifibox
|
||||
LOG_FILE=/tmp/wifibox.log
|
||||
LOG_FILE=/tmp/wifibox.stdout.log
|
||||
|
||||
cd $SCRIPT_PATH
|
||||
echo "CGI invocation" >> $LOG_FILE
|
||||
#echo "CGI invocation" >> $LOG_FILE
|
||||
#strace -o /tmp/trace-$$.log -ff $LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
||||
$LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
||||
|
||||
exit $?
|
||||
|
||||
|
||||
# Code below is for debugging incoming CGI data
|
||||
read -n $CONTENT_LENGTH POSTDATA
|
||||
echo -e "Content-type: text/plain\r\n\r\n"
|
||||
|
|
21
src/script/dhcpcheck_init
Normal file
21
src/script/dhcpcheck_init
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
# This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
#
|
||||
# Copyright (c) 2013, Doodle3D
|
||||
# This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
# See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
# start after all other scripts
|
||||
START=99
|
||||
|
||||
LOGGER="logger -t dhcpcheck -p 6"
|
||||
|
||||
boot() {
|
||||
logread | grep "192.168.10.249, lease time 12h"
|
||||
if [ $? -ne 0 ]; then
|
||||
$LOGGER "Applying workaround for dhcp/dnsmasq issue. See: https://github.com/Doodle3D/doodle3d-client/issues/66"
|
||||
/etc/init.d/dnsmasq reload
|
||||
else
|
||||
$LOGGER "DHCP configuration is in order, not doing anything"
|
||||
fi
|
||||
}
|
63
src/script/loglite-filters.lua
Normal file
63
src/script/loglite-filters.lua
Normal file
|
@ -0,0 +1,63 @@
|
|||
local M = {}
|
||||
|
||||
M.default = {
|
||||
['options'] = { mode = 'keep', count = 'none' },
|
||||
['patterns'] = {
|
||||
['%(error%)'] = 'red',
|
||||
['%(warning%)'] = 'yellow',
|
||||
['%(bulk%)'] = 'gray',
|
||||
['setState%(%)'] = 'bblue'
|
||||
}
|
||||
}
|
||||
|
||||
-- filter rules for firmware log (/tmp/wifibox.log)
|
||||
M.firmware = {
|
||||
['parent'] = 'default',
|
||||
['patterns'] = {
|
||||
['START%-RQ'] = 'bblue',
|
||||
['END%-RQ'] = 'blue'
|
||||
}
|
||||
}
|
||||
|
||||
-- filter rules for print3d log (/tmp/print3d-*.log)
|
||||
M.print3d = {
|
||||
['parent'] = 'default',
|
||||
['patterns'] = {
|
||||
['Print 3D server'] = 'byellow',
|
||||
['sendCode%(%)'] = 'green',
|
||||
['readCode%(%)'] = 'blue',
|
||||
['readResponseCode%(%)'] = 'blue'
|
||||
}
|
||||
}
|
||||
|
||||
-- filter rules for serial communcation of print3d
|
||||
M.serial = {
|
||||
['options'] = { mode = 'delete', count = 'none' },
|
||||
['patterns'] = {
|
||||
['Print 3D server'] = 'byellow,_nodelete',
|
||||
['sendCode%(%)'] = 'green,_nodelete',
|
||||
['readCode%(%)'] = 'blue,_nodelete',
|
||||
['readResponseCode%(%)'] = 'blue,_nodelete',
|
||||
['setState%(%)'] = 'bblue,_nodelete',
|
||||
['%[ABSD%]'] = 'gray,_nodelete', -- 0.10.10
|
||||
['%[ABD%]'] = 'gray,_nodelete', -- 0.10.9
|
||||
['%(info%)'] = 'gray,_nodelete' -- 0.10.10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
M.test = { -- TEST set
|
||||
['options'] = { mode = 'keep', count = 'all' },
|
||||
['patterns'] = {
|
||||
['%(info%)'] = 'yellow'
|
||||
}
|
||||
}
|
||||
|
||||
M.printstart = {
|
||||
['options'] = { mode = 'delete' },
|
||||
['patterns'] = {
|
||||
['print started'] = '_uppercase,bwhite'
|
||||
}
|
||||
}
|
||||
|
||||
return M
|
275
src/script/loglite.lua
Executable file
275
src/script/loglite.lua
Executable file
|
@ -0,0 +1,275 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
--[[
|
||||
For documentation on this script, see README-loglite.md.
|
||||
|
||||
Ideas for improvement:
|
||||
* add more directives like uppercase, prefix/suffix?
|
||||
* create separate package for this script: a) since it is useful for any log file, b) this file is getting somewhat long
|
||||
* for broader terminal support: detect `tput` and use it if available (http://wiki.bash-hackers.org/scripting/terminalcodes)
|
||||
* pre-split keyword lists for efficiency instead of redoing this at every new line?
|
||||
|
||||
FIXME:
|
||||
* with deleteMode enabled, multiple matches and _nodelete in a later match, previous directives are ignored
|
||||
]]--
|
||||
|
||||
|
||||
--[[========================================================================]]--
|
||||
|
||||
--Note: overview of ANSI escape codes: http://ascii-table.com/ansi-escape-sequences.php (support varies per terminal/termtype)
|
||||
local ANSI_COLORS = {
|
||||
['bold'] = 1,
|
||||
['underscore'] = 4,
|
||||
['blink'] = 5, -- on osx/iterm2, this has to be enabled in preferences
|
||||
['reverse'] = 7,
|
||||
['black'] = 30,
|
||||
['red'] = 31,
|
||||
['green'] = 32,
|
||||
['yellow'] = 33,
|
||||
['blue'] = 34,
|
||||
['magenta'] = 35,
|
||||
['cyan'] = 36,
|
||||
['white'] = 37,
|
||||
['bblack'] = 40,
|
||||
['bred'] = 41,
|
||||
['bgreen'] = 42,
|
||||
['byellow'] = 43,
|
||||
['bblue'] = 44,
|
||||
['bmagenta'] = 45,
|
||||
['bcyan'] = 46,
|
||||
['bwhite'] = 47
|
||||
}
|
||||
|
||||
local ESCAPE_STR = string.char(27) .. "["
|
||||
local RESET_CODE = ESCAPE_STR .. "m"
|
||||
|
||||
local DFL_FILTERSET_FILE = "loglite-filters.lua"
|
||||
|
||||
|
||||
|
||||
--[[========================================================================]]--
|
||||
|
||||
--- Stringifies the given object.
|
||||
-- From util/utils.lua
|
||||
-- Note that self-referencing objects will cause an endless loop with the current implementation.
|
||||
-- @param o The object to convert.
|
||||
-- @treturn string Stringified version of o.
|
||||
local function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
--- Splits a string on a given divider character.
|
||||
-- From util/utils.lua
|
||||
-- @string[opt=':'] div The divider character to use.
|
||||
-- @return An array containing the resultant substrings.
|
||||
-- @usage local str = "a,b,c"; local parts = str:split(',')
|
||||
function string:split(div)
|
||||
local div, pos, arr = div or ':', 0, {}
|
||||
for st,sp in function() return self:find(div, pos, true) end do
|
||||
table.insert(arr, self:sub(pos, st - 1))
|
||||
pos = sp + 1
|
||||
end
|
||||
table.insert(arr, self:sub(pos))
|
||||
return arr
|
||||
end
|
||||
|
||||
--- Determines if filename exists and can be opened for reading.
|
||||
-- From http://stackoverflow.com/a/4991602
|
||||
-- @string filename The file to test.
|
||||
-- @return True if the file exists and is readable, false otherwise.
|
||||
function fileExists(filename)
|
||||
local f = io.open(filename, "r")
|
||||
if f ~= nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
--- Converts keys of a table into a string.
|
||||
-- Adapted from http://stackoverflow.com/a/12674376.
|
||||
-- @string tbl A key/value table.
|
||||
-- @string[opt=','] sep Separator to use between items.
|
||||
-- @boolean[opt=false] sort Whether or not to sort the resulting list.
|
||||
-- @return A string with all keys from the given table.
|
||||
local function keysToString(tbl, sep, sort)
|
||||
local sep, sort = sep or ',', sort or false
|
||||
local keyset, n = {}, 0
|
||||
for k,_ in pairs(tbl) do
|
||||
n = n + 1
|
||||
keyset[n] = k
|
||||
end
|
||||
if sort then table.sort(keyset) end
|
||||
return table.concat(keyset, sep)
|
||||
end
|
||||
|
||||
--- Merge two tables recursively (i.e., subtables also get merged).
|
||||
-- from: http://stackoverflow.com/a/1283608
|
||||
-- @table t1 Table to merge into.
|
||||
-- @table t2 Table to merge into t1.
|
||||
-- @return The combined table (actually t1).
|
||||
function mergeTables(t1, t2)
|
||||
for k,v in pairs(t2) do
|
||||
if type(v) == "table" then
|
||||
if type(t1[k] or false) == "table" then
|
||||
mergeTables(t1[k] or {}, t2[k] or {})
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
end
|
||||
|
||||
local function hasValue(t, needle)
|
||||
for k,v in pairs(t) do
|
||||
if needle == v then return k end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function makeAnsiCode(key)
|
||||
if not ANSI_COLORS[key] then return nil end
|
||||
return ESCAPE_STR .. ANSI_COLORS[key] .. 'm'
|
||||
end
|
||||
|
||||
|
||||
|
||||
--[[========================================================================]]--
|
||||
|
||||
local function tailStream(stream, filterSet)
|
||||
patterns = filterSet and filterSet.patterns or {}
|
||||
options = filterSet and filterSet.options or { ['mode'] = 'keep' }
|
||||
local c = 0
|
||||
|
||||
for line in stream:lines() do
|
||||
--c = c + 1 -- Note: this would also count deleted lines
|
||||
local embellished = line
|
||||
local keepLine = (options.mode == 'keep')
|
||||
local keepLineOverridden = false
|
||||
|
||||
-- look for a pattern matching this line
|
||||
for p,c in pairs(patterns) do
|
||||
if line:match(p) then
|
||||
-- print("[DEBUG] +matched rule '" .. p .. "'/'" .. c .. "' against '" .. line .. "'")
|
||||
local kws = c:split(',')
|
||||
|
||||
if hasValue(kws, '_delete') then keepLine = false; keepLineOverridden = true
|
||||
elseif hasValue(kws, '_nodelete') then keepLine = true; keepLineOverridden = true
|
||||
end
|
||||
|
||||
if keepLine then
|
||||
-- first collect formatting sequences
|
||||
local fmt = ''
|
||||
for _,kw in ipairs(kws) do
|
||||
local code = makeAnsiCode(kw)
|
||||
if code then fmt = fmt .. code end
|
||||
end
|
||||
|
||||
-- then wrap the line in formatting, if any
|
||||
if fmt:len() > 0 then embellished = fmt .. embellished .. RESET_CODE end
|
||||
else
|
||||
-- Note: break out of loop and stop processing when line should be deleted _if_ the default has been overridden to do so
|
||||
if keepLineOverridden then
|
||||
embellished = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
--break -- Note: don't break, allow multiple matches per line, e.g. to mix and match fg and bg colors
|
||||
end
|
||||
end
|
||||
|
||||
if embellished and keepLine then
|
||||
c = c + 1
|
||||
|
||||
if options.count == 'all' then print(c, embellished)
|
||||
else print(embellished) end
|
||||
else
|
||||
-- print("[DEBUG] -skipped '"..line.."'")
|
||||
end
|
||||
|
||||
--c = line:match 'truncated' and 0 or c -- from tail on stderr apparently
|
||||
end
|
||||
end
|
||||
|
||||
--TODO: could be extended to look for multiple filenames in multiple paths
|
||||
local function readConfigFile(filename, searchPath)
|
||||
fullPath = searchPath .. '/' .. filename
|
||||
if not fileExists(fullPath) then
|
||||
--print("[DEBUG] config file '" .. fullPath .. "' not found")
|
||||
return nil
|
||||
end
|
||||
|
||||
--print("[DEBUG] using config file '" .. fullPath .. "'")
|
||||
-- require does not accept full paths? also, pcall does not help with dofile
|
||||
return dofile(fullPath)
|
||||
end
|
||||
|
||||
--- Load filter set with given name from configSets, with inheritance as specified.
|
||||
local function readFilterSet(configSets, setName)
|
||||
local result = {}
|
||||
for k,_ in pairs(configSets) do
|
||||
if k == setName then
|
||||
parent = configSets[setName]['parent']
|
||||
if parent ~= nil then
|
||||
--print("[DEBUG] recursing for filter set '" .. parent .. "' from config")
|
||||
result = mergeTables(result, readFilterSet(configSets, parent))
|
||||
end
|
||||
--print("[DEBUG] using/merging filter set '" .. setName .. "' from config")
|
||||
result = mergeTables(result, configSets[setName])
|
||||
break
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--NOTE: if command-line options get any more complex, switch to a lightweight
|
||||
-- getopt like this one? https://attractivechaos.wordpress.com/2011/04/07/getopt-for-lua/
|
||||
local function main()
|
||||
-- handle command-line arguments
|
||||
local showHelp, followFile, filterSetName = false, nil, 'default'
|
||||
if #arg > 0 and arg[1] == "-h" or arg[1] == "--help" then
|
||||
showHelp = true
|
||||
else
|
||||
if #arg > 0 and arg[1] ~= '-' then followFile = arg[1] end
|
||||
if #arg > 1 then filterSetName = arg[2] end
|
||||
end
|
||||
|
||||
-- read filter set file if available
|
||||
local configSets = readConfigFile(DFL_FILTERSET_FILE, os.getenv('HOME')) or {}
|
||||
local filterSet = readFilterSet(configSets, filterSetName)
|
||||
-- print("[DEBUG] final filter set for '" .. filterSetName .. "' from config: " .. dump(filterSet))
|
||||
|
||||
-- if requested, display help and exit
|
||||
if showHelp and showHelp == true then
|
||||
print("Usage: loglite.lua [file-to-tail] [filter-set]")
|
||||
print(" If no arguments are supplied, or if the first one is `-', stdin is used as input.")
|
||||
print(" If no filter set is supplied, a set named `default' will be looked for.")
|
||||
print(" Filter sets can be defined in a file `loglite-filters.lua' in your home directory.")
|
||||
print()
|
||||
print(" Available filter sets in " .. os.getenv('HOME') .. "/" .. DFL_FILTERSET_FILE .. ": " .. keysToString(configSets, ', ', true))
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
|
||||
-------------------------
|
||||
|
||||
--print("[DEBUG] following file: '" .. (followFile and followFile or "<stdin>") .. "', with filter set '" .. filterSetName .. "'.")
|
||||
|
||||
--Info on tailing a file: https://stackoverflow.com/questions/17363973/how-can-i-tail-f-a-log-filetruncate-aware-in-lua
|
||||
--local tailin = io.popen('tail -F '..(...)..' 2>&1', 'r')
|
||||
local tailin = followFile and io.popen('tail -f ' .. followFile, 'r') or io.stdin
|
||||
|
||||
pcall(tailStream, tailin, filterSet) -- Note: protected call to suppress interrupt error thrown by lines iterator
|
||||
end
|
||||
|
||||
main()
|
||||
os.exit(0)
|
36
src/script/logrotate-wifibox.conf
Normal file
36
src/script/logrotate-wifibox.conf
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Doodle3D logrotate configuration
|
||||
|
||||
compress
|
||||
su
|
||||
create
|
||||
|
||||
/tmp/wifibox.log /tmp/print3d-*.log {
|
||||
rotate 2
|
||||
size 1000k
|
||||
missingok
|
||||
olddir /tmp/wifibox-rotated
|
||||
|
||||
# as alternative to copytruncate (which *might* miss lines) we could implement
|
||||
# SIGUSR1 in print3d and firmware to reopen their logs
|
||||
copytruncate # 'create' is ignored with copytruncate, as the file stays in place
|
||||
|
||||
prerotate
|
||||
FIRST_N_LINES=500
|
||||
PRINT3D_LOGHEAD_FILE=print3d-loghead
|
||||
WIFIBOX_LOGHEAD_FILE=wifibox-loghead
|
||||
ROTATED_FILES_PATH=/tmp/wifibox-rotated
|
||||
|
||||
#Note: by looking at creation date of the print3d socket and comparing against that
|
||||
# of print3d-loghead we could detect a server restart (e.g. due to reconnected printer)
|
||||
|
||||
echo "$1" | grep -q "print3d-.*\.log"
|
||||
if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE" ]; then
|
||||
head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE"
|
||||
fi
|
||||
|
||||
echo "$1" | grep -q "wifibox.log"
|
||||
if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE" ]; then
|
||||
head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE"
|
||||
fi
|
||||
endscript
|
||||
}
|
112
src/script/print-fetch.lua
Executable file
112
src/script/print-fetch.lua
Executable file
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/lua
|
||||
|
||||
local function log(message)
|
||||
os.execute("logger " .. message)
|
||||
print(message)
|
||||
end
|
||||
|
||||
if (table.getn(arg) == 0) then
|
||||
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
||||
return
|
||||
end
|
||||
|
||||
log("starting gcode fetch program")
|
||||
|
||||
package.cpath = package.cpath .. '/usr/lib/lua/?.so'
|
||||
JSON = (loadfile "/usr/share/lua/wifibox/util/JSON.lua")()
|
||||
|
||||
local p3d = require("print3d")
|
||||
|
||||
local printer = p3d.getPrinter(arg[1])
|
||||
if printer == nil then
|
||||
log("error connecting to printer")
|
||||
return
|
||||
end
|
||||
|
||||
local gcodeServer = arg[2]
|
||||
|
||||
local finished = false
|
||||
|
||||
local id = arg[3]
|
||||
|
||||
log("gcode file id: " .. id)
|
||||
log("gcode server: " .. gcodeServer)
|
||||
|
||||
local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a"))
|
||||
|
||||
if info == nil then
|
||||
log("could not retrieve file info")
|
||||
return
|
||||
end
|
||||
|
||||
local current_line = 0
|
||||
local total_lines = tonumber(info["lines"])
|
||||
local started = false
|
||||
|
||||
log("total lines: " .. total_lines)
|
||||
|
||||
local startCode = nil
|
||||
local endCode = nil
|
||||
|
||||
function countlines(file)
|
||||
return tonumber(io.popen("wc -l < " .. file):read('*a'))
|
||||
end
|
||||
|
||||
function readGCodeArg(argi)
|
||||
local gcodeFile = arg[argi]
|
||||
return io.open(gcodeFile):read('*a')
|
||||
end
|
||||
|
||||
if table.getn(arg) >= 5 then
|
||||
startCode = readGCodeArg(4)
|
||||
endCode = readGCodeArg(5)
|
||||
end
|
||||
|
||||
if startCode ~= nil then
|
||||
log("appending start gcode")
|
||||
printer:appendGcode(startCode)
|
||||
end
|
||||
|
||||
while(not finished)
|
||||
do
|
||||
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
|
||||
local line = f:read()
|
||||
while line ~= nil do
|
||||
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||
current_line = current_line + 1
|
||||
line = f:read()
|
||||
end
|
||||
|
||||
if not started then
|
||||
started = true
|
||||
print("send print start command")
|
||||
printer:startPrint()
|
||||
end
|
||||
|
||||
if current_line >= total_lines then
|
||||
log("finished fetching gcode")
|
||||
if endCode ~= nil then
|
||||
log("appending end gcode")
|
||||
printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||
end
|
||||
finished = true
|
||||
break
|
||||
end
|
||||
|
||||
|
||||
local accepts_new_gcode = false
|
||||
|
||||
while (not accepts_new_gcode)
|
||||
do
|
||||
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
|
||||
local percentageBufferSize = bufferSize / maxBufferSize
|
||||
|
||||
if percentageBufferSize < 0.8 then
|
||||
print("buffer below 80% capacity, sending new gcode")
|
||||
accepts_new_gcode = true
|
||||
else
|
||||
print("buffer above 80% capacity")
|
||||
os.execute("sleep 10")
|
||||
end
|
||||
end
|
||||
end
|
9
src/script/signin.sh
Executable file → Normal file
9
src/script/signin.sh
Executable file → Normal file
|
@ -1,8 +1,13 @@
|
|||
#!/bin/sh
|
||||
# This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
#
|
||||
# Copyright (c) 2013, Doodle3D
|
||||
# This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
# See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
sleep 5s
|
||||
sleep 15m
|
||||
while true; do
|
||||
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null
|
||||
|
||||
sleep 1h
|
||||
sleep 15m
|
||||
done
|
||||
|
|
12
src/script/wifi-switch-netconfig.sh
Executable file
12
src/script/wifi-switch-netconfig.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "released" ] || exit 0
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
logger "$BUTTON pressed for $SEEN seconds"
|
||||
if [ "$SEEN" -gt 4 ]
|
||||
then
|
||||
logger "Resetting Wireless"
|
||||
d3dapi p=/network/reset r=POST
|
||||
fi
|
|
@ -1,3 +1,13 @@
|
|||
config settings 'system'
|
||||
option logfile '/tmp/wifibox.log'
|
||||
option loglevel 'debug'
|
||||
#In addition to regular text, api_log_filename and p3d_log_basename may also be
|
||||
#a stream enclose in angle brackets (e.g. '<stderr>') or
|
||||
#a command to send output to in back quotes (e.g. '`ssh USER@HOST "cat > /tmp/test.log"`').
|
||||
#Note that using an SSH tunnel without public key auth will need interaction
|
||||
|
||||
option log_path '/tmp'
|
||||
option api_log_filename 'wifibox.log'
|
||||
option p3d_log_basename 'print3d'
|
||||
|
||||
config settings 'general'
|
||||
option printer_type 'ultimaker'
|
||||
option gcode_server 'http://gcodeserver.doodle3d.com'
|
||||
|
|
32
src/script/wifibox_init
Executable file → Normal file
32
src/script/wifibox_init
Executable file → Normal file
|
@ -1,24 +1,38 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
# This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
#
|
||||
# Copyright (c) 2013, Doodle3D
|
||||
# This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
# See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
# start after networking
|
||||
START=22
|
||||
#START=22
|
||||
START=61
|
||||
|
||||
LOGGER="logger -s -t autowifi -p 6"
|
||||
LOGGER="logger -t autowifi -p 6"
|
||||
|
||||
boot() {
|
||||
sleep 1
|
||||
sleep 5
|
||||
|
||||
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
|
||||
/usr/share/lua/wifibox/script/d3dapi autowifi
|
||||
|
||||
$LOGGER "Start signing in..."
|
||||
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
||||
|
||||
mkdir -p /var/lib # required by logrotate for logrotate.status
|
||||
mkdir -p /tmp/wifibox-rotated # this is where rotated wifibox logs are placed
|
||||
}
|
||||
|
||||
#start() {
|
||||
# $LOGGER "dummy start"
|
||||
#}
|
||||
start() {
|
||||
ps | awk '{print $5}' | grep '{signin.sh}'
|
||||
if [ $? -eq 1 ]; then
|
||||
$LOGGER "Start signing in..."
|
||||
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
||||
fi
|
||||
}
|
||||
|
||||
#stop() {
|
||||
# $LOGGER "dummy stop"
|
||||
#}
|
||||
stop() {
|
||||
$LOGGER "Stop signing in..."
|
||||
killall signin.sh
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit bbca5831055e25fc312e5ff8b31f32771925bb9f
|
|
@ -1,21 +1,55 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local printerUtils = require('util.printer')
|
||||
|
||||
local MOD_ABBR = "UACS"
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.hasControl(ip)
|
||||
local controllerIP = M.getController()
|
||||
return (controllerIP == "" or (controllerIP ~= "" and controllerIP == ip))
|
||||
|
||||
-- no controller stored? we have control
|
||||
if controllerIP == "" then return true end;
|
||||
|
||||
-- controller stored is same as our (requesting) ip? we have control
|
||||
if(controllerIP == ip) then return true end;
|
||||
|
||||
-- no printer connected? we have control
|
||||
local printer,msg = printerUtils.createPrinterOrFail()
|
||||
if not printer or not printer:hasSocket() then
|
||||
M.setController("") -- clear the controller
|
||||
return true
|
||||
end
|
||||
|
||||
-- printer is idle (done printing)? we have control
|
||||
local state = printer:getState()
|
||||
if state == "idle" then -- TODO: define in constants somewhere
|
||||
M.setController("") -- clear controller
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function M.getController()
|
||||
local file, error = io.open('/tmp/controller.txt','r')
|
||||
if file == nil then
|
||||
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
||||
--log:error(MOD_ABBR, "Util:Access: Can't read controller file. Error: "..error)
|
||||
return ""
|
||||
else
|
||||
controllerIP = file:read('*a')
|
||||
file:close()
|
||||
--strip trailing newline (useful when manually editing controller.txt)
|
||||
if controllerIP:find('\n') == controllerIP:len() then controllerIP = controllerIP:sub(0, -2) end
|
||||
return controllerIP
|
||||
end
|
||||
end
|
||||
|
@ -27,4 +61,4 @@ function M.setController(ip)
|
|||
file:close()
|
||||
end
|
||||
|
||||
return M
|
||||
return M
|
||||
|
|
|
@ -1,43 +1,64 @@
|
|||
--[[--
|
||||
TODO: ldoc: @{} ref in init() tformat
|
||||
TODO: use macros/type definitions to document rest modules (to auto-match things like 'M.<func>_NAME%')?
|
||||
TODO: finish documentation
|
||||
]]
|
||||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- Logging facilities.
|
||||
|
||||
local utils = require('util.utils')
|
||||
|
||||
local M = {}
|
||||
|
||||
local logLevel, logVerbose, logStream
|
||||
local logLevel, logVerboseFmt, logStream
|
||||
local logFilePath = nil -- only used for reference
|
||||
|
||||
--- Available log levels.
|
||||
local LONGEST_LEVEL_NAME = -1
|
||||
|
||||
--- Available log levels (starting at 1)
|
||||
-- @table LEVEL
|
||||
M.LEVEL = {
|
||||
'debug', -- for debug messages
|
||||
'info', -- for informational messages
|
||||
'warn', -- for warnings (something is wrong/fishy but not neccesarily problematic)
|
||||
'error', -- for recoverable errors
|
||||
'fatal' -- for unrecoverable errors
|
||||
'quiet', -- not used for logging, only for setting levels
|
||||
'error', -- fatal or non-fatal error condition
|
||||
'warning', -- possibly troublesome situation
|
||||
'info', -- information about what the application is doing
|
||||
'verbose', -- extra trail information on what the application is doing
|
||||
'bulk' -- debug information (in large amounts)
|
||||
}
|
||||
|
||||
-- M.LEVEL already has idx=>name entries, now create name=>idx entries
|
||||
|
||||
--[[== module initialization code ==]]--
|
||||
|
||||
-- M.LEVEL already has idx=>name entries, now create name=>idx entries so it can be indexed both ways, and init LONGEST_LEVEL_NAME
|
||||
for i,v in ipairs(M.LEVEL) do
|
||||
M.LEVEL[v] = i
|
||||
if v:len() > LONGEST_LEVEL_NAME then LONGEST_LEVEL_NAME = v:len() end
|
||||
end
|
||||
|
||||
|
||||
local function log(level, msg, verbose)
|
||||
if level >= logLevel then
|
||||
local now = os.date('%m-%d %H:%M:%S')
|
||||
--[[================================]]--
|
||||
|
||||
|
||||
local function log(level, module, msg, verboseFmt)
|
||||
if level <= logLevel then
|
||||
local now = os.date('%d-%m %H:%M:%S')
|
||||
local i = debug.getinfo(3) --the stack frame just above the logger call
|
||||
local v = verbose
|
||||
if v == nil then v = logVerbose end
|
||||
local v = verboseFmt
|
||||
if v == nil then v = logVerboseFmt end
|
||||
local name = i.name or "(nil)"
|
||||
local vVal = 'nil'
|
||||
local m = (type(msg) == 'string') and msg or utils.dump(msg)
|
||||
|
||||
if v then logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
|
||||
else logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. "\n") end
|
||||
|
||||
if module == nil then module = "LUA " end
|
||||
|
||||
local levelName = M.LEVEL[level]
|
||||
local padding = string.rep(' ', LONGEST_LEVEL_NAME - levelName:len())
|
||||
|
||||
if v then logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
|
||||
else logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. "\n") end
|
||||
|
||||
logStream:flush()
|
||||
end
|
||||
end
|
||||
|
@ -45,11 +66,16 @@ end
|
|||
|
||||
--- Initializes the logger.
|
||||
-- @tparam @{util.logger.LEVEL} level Minimum level of messages to log.
|
||||
-- @tparam bool verbose Write verbose log messages (include file/line inforomation).
|
||||
function M:init(level, verbose)
|
||||
logLevel = level or M.LEVEL.warn
|
||||
logVerbose = verbose or false
|
||||
logStream = stream or io.stdout
|
||||
-- @tparam bool verbose Write verbose log messages (include file/line information).
|
||||
function M:init(level, verboseFmt)
|
||||
logLevel = level or M.LEVEL.warning
|
||||
logVerboseFmt = verboseFmt or false
|
||||
--logStream = stream or io.stdout
|
||||
end
|
||||
|
||||
function M:setLevel(level, verboseFmt)
|
||||
logLevel = level or M.LEVEL.warning
|
||||
logVerboseFmt = verboseFmt or false
|
||||
end
|
||||
|
||||
-- pass nil as stream to reset to stdout
|
||||
|
@ -57,10 +83,21 @@ function M:setStream(stream)
|
|||
logStream = stream or io.stdout
|
||||
end
|
||||
|
||||
function M:debug(msg, verbose) log(M.LEVEL.debug, msg, verbose); return true end
|
||||
function M:info(msg, verbose) log(M.LEVEL.info, msg, verbose); return true end
|
||||
function M:warn(msg, verbose) log(M.LEVEL.warn, msg, verbose); return true end
|
||||
function M:error(msg, verbose) log(M.LEVEL.error, msg, verbose); return false end
|
||||
function M:fatal(msg, verbose) log(M.LEVEL.fatal, msg, verbose); return false end
|
||||
function M:getLevel()
|
||||
return logLevel, logVerboseFmt
|
||||
end
|
||||
|
||||
function M:getStream()
|
||||
return logStream
|
||||
end
|
||||
|
||||
function M:setLogFilePath(path) logFilePath = path end
|
||||
function M:getLogFilePath() return logFilePath end
|
||||
|
||||
function M:error(module, msg, verboseFmt) log(M.LEVEL.error, module, msg, verboseFmt); return false end
|
||||
function M:warning(module, msg, verboseFmt) log(M.LEVEL.warning, module, msg, verboseFmt); return true end
|
||||
function M:info(module, msg, verboseFmt) log(M.LEVEL.info, module, msg, verboseFmt); return true end
|
||||
function M:verbose(module, msg, verboseFmt) log(M.LEVEL.verbose, module, msg, verboseFmt); return true end
|
||||
function M:bulk(module, msg, verboseFmt) log(M.LEVEL.bulk, module, msg, verboseFmt); return true end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,12 +1,27 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local printDriver = require('print3d')
|
||||
|
||||
local MOD_ABBR = "UPRN"
|
||||
|
||||
local SUPPORTED_PRINTERS = {
|
||||
rigidbot = "Rigidbot",
|
||||
ultimaker = "Ultimaker",
|
||||
ultimaker2 = "Ultimaker 2",
|
||||
ultimaker2go = "Ultimaker 2 Go",
|
||||
ultimaker_original_plus = "Ultimaker Original Plus",
|
||||
makerbot_replicator2 = "MakerBot Replicator2",
|
||||
makerbot_replicator2x = "MakerBot Replicator2x",
|
||||
makerbot_thingomatic = "MakerBot Thing-o-matic",
|
||||
wanhao_duplicator4 = "Wanhao Duplicator 4",
|
||||
printrbot = "Printrbot",
|
||||
bukobot = "Bukobot",
|
||||
cartesio = "Cartesio",
|
||||
|
@ -19,6 +34,7 @@ local SUPPORTED_PRINTERS = {
|
|||
kossel = "Kossel",
|
||||
leapfrog_creatr = "LeapFrog Creatr",
|
||||
lulzbot_aO_101 = "LulzBot AO-101",
|
||||
lulzbot_taz_4 = "LulzBot TAZ 4",
|
||||
makergear_m2 = "MakerGear M2",
|
||||
makergear_prusa = "MakerGear Prusa",
|
||||
makibox = "Makibox",
|
||||
|
@ -33,7 +49,22 @@ local SUPPORTED_PRINTERS = {
|
|||
robo_3d_printer = "RoBo 3D Printer",
|
||||
shapercube = "ShaperCube",
|
||||
tantillus = "Tantillus",
|
||||
vision_3d_printer = "Vision 3D Printer"
|
||||
vision_3d_printer = "Vision 3D Printer",
|
||||
minifactory = "miniFactory",
|
||||
builder3d = "Builder 3D",
|
||||
bigbuilder3d = "Big Builder 3D",
|
||||
mamba3d = "Mamba3D",
|
||||
_3Dison_plus = "3Dison plus",
|
||||
marlin_generic = "Generic Marlin Printer",
|
||||
makerbot_generic = "Generic Makerbot Printer",
|
||||
doodle_dream = "Doodle Dream",
|
||||
colido_2_0_plus = "ColiDo 2.0 Plus",
|
||||
colido_m2020 = "ColiDo M2020",
|
||||
colido_x3045 = "ColiDo X3045",
|
||||
colido_compact = "ColiDo Compact",
|
||||
colido_diy = "ColiDo DIY",
|
||||
craftbot_plus = "CraftBot PLUS",
|
||||
renkforce_rf100 = "Renkforce RF100"
|
||||
}
|
||||
local SUPPORTED_BAUDRATES = {
|
||||
["115200"] = "115200 bps",
|
||||
|
@ -55,8 +86,8 @@ end
|
|||
--returns a printer instance or nil (and sets error state on response in the latter case)
|
||||
function M.createPrinterOrFail(deviceId, response)
|
||||
|
||||
--log:debug("API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
||||
local msg,printer = nil, nil
|
||||
--log:info(MOD_ABBR, "API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
||||
local rv,msg,printer = nil, nil, nil
|
||||
|
||||
if deviceId == nil or deviceId == "" then
|
||||
printer,msg = printDriver.getPrinter()
|
||||
|
@ -65,11 +96,25 @@ function M.createPrinterOrFail(deviceId, response)
|
|||
end
|
||||
|
||||
if not printer then
|
||||
response:setError("could not open printer driver (" .. msg .. ")")
|
||||
response:addData('id', deviceId)
|
||||
if response ~= nil then
|
||||
response:setError("could not open printer driver (" .. msg .. ")")
|
||||
response:addData('id', deviceId)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- only log these log setup errors, do not let them prevent further request handling
|
||||
|
||||
rv,msg = printer:setLocalLogStream(log:getStream())
|
||||
if not rv then
|
||||
log:error(MOD_ABBR, "could not set log stream in Lua binding (" .. msg .. ")")
|
||||
end
|
||||
|
||||
rv,msg = printer:setLocalLogLevel(log:getLevel())
|
||||
if not rv then
|
||||
log:error(MOD_ABBR, "could not set log level '" .. log:getLevel() .. "' in Lua binding (" .. msg .. ")")
|
||||
end
|
||||
|
||||
return printer
|
||||
end
|
||||
|
||||
|
|
|
@ -1,41 +1,48 @@
|
|||
--[[--
|
||||
The settings interface reads and writes configuration keys using UCI.
|
||||
All keys have pre-defined defaults in @{conf_defaults} which will be used
|
||||
if no value is stored in the UCI config. The UCI config file is
|
||||
'/etc/config/wifibox'.
|
||||
The default values guarantee there will always be a set of reasonable settings
|
||||
to use and provide a clear overview of all existing configuration keys as well.
|
||||
|
||||
By the way, returning correct values in get()/fromUciValue() for booleans has
|
||||
been fixed at a relatively convenient time purely thanks to the unit tests...
|
||||
just to indicate how useful they are. :)
|
||||
]]
|
||||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- The settings interface reads and writes configuration keys using [UCI](http://wiki.openwrt.org/doc/uci).
|
||||
-- All keys have pre-defined defaults in @{conf_defaults} which will be used
|
||||
-- if no value is stored in the UCI config. The UCI config file is `/etc/config/wifibox`.
|
||||
-- The default values guarantee there will always be a set of reasonable settings
|
||||
-- to use and provide a clear overview of all existing configuration keys as well.
|
||||
-- uci api: http://wiki.openwrt.org/doc/techref/uci, http://luci.subsignal.org/api/luci/modules/luci.model.uci.html
|
||||
local uci = require('uci').cursor()
|
||||
local utils = require('util.utils')
|
||||
local baseconfig = require('conf_defaults')
|
||||
local utils = require('util.utils')
|
||||
local log = require('util.logger')
|
||||
|
||||
local MOD_ABBR = "USET"
|
||||
|
||||
local M = {}
|
||||
|
||||
--- UCI config name (i.e. file under /etc/config)
|
||||
--- UCI config name (i.e., file under `/etc/config`)
|
||||
local UCI_CONFIG_NAME = 'wifibox'
|
||||
|
||||
--- Absolute path to the UCI config file
|
||||
local UCI_CONFIG_FILE = '/etc/config/' .. UCI_CONFIG_NAME
|
||||
|
||||
--- Section type that will be used in UCI\_CONFIG\_FILE
|
||||
--- [Section type](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used in @{UCI_CONFIG_FILE}
|
||||
local UCI_CONFIG_TYPE = 'settings'
|
||||
|
||||
--- Section name that will be used for 'public' settings (as predefined in conf_defaults.lua) in UCI\_CONFIG\_FILE
|
||||
--- [Section name](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used for 'public' settings (as predefined in conf_defaults.lua) in @{UCI_CONFIG_FILE}
|
||||
local UCI_CONFIG_SECTION = 'general'
|
||||
|
||||
--- Section name that will be used for 'firmware-local' settings in UCI\_CONFIG\_FILE
|
||||
--- [Section name](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used for 'firmware-local' settings in @{UCI_CONFIG_FILE}
|
||||
local UCI_CONFIG_SYSTEM_SECTION = 'system'
|
||||
|
||||
local ERR_NO_SUCH_KEY = "key does not exist"
|
||||
|
||||
|
||||
--- Returns a key with all periods ('.') replaced by underscores ('_').
|
||||
-- @tparam string key The key for which to substitute dots.
|
||||
-- @string key The key for which to substitute dots.
|
||||
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
|
||||
local function replaceDots(key)
|
||||
if type(key) ~= 'string' then return key end
|
||||
|
@ -44,7 +51,7 @@ local function replaceDots(key)
|
|||
end
|
||||
|
||||
--- Returns a key with all underscores ('_') replaced by periods ('.').
|
||||
-- @tparam string key The key for which to substitute underscores.
|
||||
-- @string key The key for which to substitute underscores.
|
||||
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
|
||||
local function replaceUnderscores(key)
|
||||
if type(key) ~= 'string' then return key end
|
||||
|
@ -55,13 +62,13 @@ end
|
|||
--- Converts a lua value to equivalent representation for UCI.
|
||||
-- Boolean values are converted to '1' and '0', everything else is converted to a string.
|
||||
--
|
||||
-- @param v The value to convert.
|
||||
-- @param vType The type of the given value.
|
||||
-- @p v The value to convert.
|
||||
-- @p vType The type of the given value.
|
||||
-- @return A value usable to write to UCI.
|
||||
local function toUciValue(v, vType)
|
||||
if vType == 'bool' then return v and '1' or '0' end
|
||||
if(vType == 'string') then
|
||||
v = v:gsub('[\n\r]', '\\n')
|
||||
if(vType == 'string') then
|
||||
v = v:gsub('[\n\r]', '\\n')
|
||||
end
|
||||
|
||||
return tostring(v)
|
||||
|
@ -71,101 +78,148 @@ end
|
|||
-- For boolean, '1' is converted to true and everything else to false. Floats
|
||||
-- and ints are converted to numbers and everything else will be returned as is.
|
||||
--
|
||||
-- @param v The value to convert.
|
||||
-- @param vType The type of the given value.
|
||||
-- @p v The value to convert.
|
||||
-- @p vType The type of the given value.
|
||||
-- @return A lua value typed correctly with regard to the vType parameter.
|
||||
local function fromUciValue(v, vType)
|
||||
if v == nil then return nil end
|
||||
|
||||
|
||||
if vType == 'bool' then
|
||||
return (v == '1') and true or false
|
||||
elseif vType == 'float' or vType == 'int' then
|
||||
return tonumber(v)
|
||||
elseif vType == 'string' then
|
||||
v = v:gsub('\\n', '\n')
|
||||
v = v:gsub('\\n', '\n')
|
||||
return v
|
||||
else
|
||||
return v
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--- Reports whether a value is valid given the constraints specified in a base table.
|
||||
-- @param value The value to test.
|
||||
-- @tparam table baseTable The base table to use constraint data from (min,max,regex).
|
||||
-- @p value The value to test.
|
||||
-- @tab baseTable The base table to use constraint data from (min,max,regex,isValid).
|
||||
-- @treturn bool Returns true if the value is valid, false if it is not.
|
||||
local function isValid(value, baseTable)
|
||||
local varType, min, max, regex, isValid = baseTable.type, baseTable.min, baseTable.max, baseTable.regex, baseTable.isValid
|
||||
|
||||
if isValid then
|
||||
local ok = isValid(value)
|
||||
return ok or nil,"invalid value"
|
||||
if isValid then
|
||||
local ok,msg = isValid(value)
|
||||
if msg == nil then msg = "invalid value" end
|
||||
return ok or nil,msg
|
||||
end
|
||||
|
||||
if varType == 'bool' then
|
||||
return type(value) == 'boolean' or nil,"invalid bool value"
|
||||
|
||||
|
||||
elseif varType == 'int' or varType == 'float' then
|
||||
local numValue = tonumber(value)
|
||||
local ok = numValue and true or false
|
||||
ok = ok and (varType == 'float' or math.floor(numValue) == numValue)
|
||||
if min then ok = ok and numValue >= min end
|
||||
if max then ok = ok and numValue <= max end
|
||||
return ok or nil,"invalid int/float value or out of range"
|
||||
|
||||
if numValue == nil then
|
||||
return nil, "invalid number"
|
||||
elseif varType == 'int' and math.floor(numValue) ~= numValue then
|
||||
return nil, "invalid int"
|
||||
elseif min and numValue < min then
|
||||
return nil, "too low"
|
||||
elseif max and numValue > max then
|
||||
return nil, "too high"
|
||||
end
|
||||
|
||||
elseif varType == 'string' then
|
||||
local ok = true
|
||||
if min then ok = ok and value:len() >= min end
|
||||
if max then ok = ok and value:len() <= max end
|
||||
if regex then ok = ok and value:match(regex) ~= nil end
|
||||
return ok or nil,"invalid string value"
|
||||
if min and value:len() < min then
|
||||
return nil,"too short"
|
||||
elseif max and value:len() > max then
|
||||
return nil,"too long"
|
||||
elseif regex and value:match(regex) == nil then
|
||||
return nil,"invalid value"
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Looks up the table in conf_defaults.lua corresponding to a key.
|
||||
-- @tparam string key The key for which to return the base table.
|
||||
--- Looks up the table in @{conf_defaults}.lua corresponding to a key.
|
||||
-- @string key The key for which to return the base table.
|
||||
-- @treturn table The base table for key, or nil if it does not exist.
|
||||
local function getBaseKeyTable(key)
|
||||
local base = baseconfig[key]
|
||||
return type(base) == 'table' and base.default ~= nil and base or nil
|
||||
end
|
||||
|
||||
--- Looks up the table in @{subconf_defaults}.lua corresponding to a key.
|
||||
-- @string key The key for which to return the base table.
|
||||
-- @treturn table The base table for key, or nil if it does not exist.
|
||||
--[[local function getSubBaseKeyTable(key)
|
||||
local base = subconfig[key]
|
||||
return type(base) == 'table' and base.default ~= nil and base or nil
|
||||
end]]--
|
||||
|
||||
|
||||
--- Returns the value of the requested key if it exists.
|
||||
-- @param key The key to return the associated value for.
|
||||
-- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type.
|
||||
-- @p key The key to return the associated value for.
|
||||
-- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type, or nil if the key could not be read because of a UCI error.
|
||||
-- @treturn string Message in case of error.
|
||||
function M.get(key)
|
||||
--log:info(MOD_ABBR, "settings:get: "..utils.dump(key))
|
||||
key = replaceDots(key)
|
||||
|
||||
-- retrieve settings's base settings from conf_defaults.lua
|
||||
local base = getBaseKeyTable(key)
|
||||
|
||||
if not base then return nil,ERR_NO_SUCH_KEY end
|
||||
|
||||
local v = base.default
|
||||
local uciV = fromUciValue(uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key), base.type)
|
||||
|
||||
local actualV = v
|
||||
if uciV ~= nil then actualV = uciV end
|
||||
-- check which uci section to read.
|
||||
-- By default it will read from the general section, but if a base setting contains a subSection it will check that subSection
|
||||
local section = UCI_CONFIG_SECTION;
|
||||
if base.subSection ~= nil then
|
||||
section = M.get(base.subSection)
|
||||
end
|
||||
|
||||
return actualV
|
||||
-- get setting from uci
|
||||
local uciV,msg = uci:get(UCI_CONFIG_NAME, section, key)
|
||||
if not uciV and msg ~= nil then
|
||||
local errorMSG = "Issue reading setting '"..utils.dump(key).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
|
||||
-- convert uci value into proper lua value
|
||||
local uciV = fromUciValue(uciV, base.type)
|
||||
if uciV ~= nil then
|
||||
-- returning value from uci
|
||||
return uciV
|
||||
elseif base.subSection ~= nil then
|
||||
local subDefault = base["default_"..section]
|
||||
if subDefault ~= nil then
|
||||
-- returning subsection default value
|
||||
return subDefault
|
||||
end
|
||||
end
|
||||
-- returning default value
|
||||
return base.default
|
||||
end
|
||||
|
||||
--- Returns all configuration keys with their current values.
|
||||
-- @treturn table A table containing a key/value pair for each configuration key.
|
||||
-- @return A table containing a key/value pair for each configuration key, or nil if a UCI error occured.
|
||||
-- @return string Message in case of error.
|
||||
function M.getAll()
|
||||
local result = {}
|
||||
for k,_ in pairs(baseconfig) do
|
||||
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||
local key = replaceUnderscores(k)
|
||||
result[key] = M.get(key)
|
||||
local v, msg = M.get(key)
|
||||
if not v and msg ~= nil then
|
||||
return nil, msg
|
||||
else
|
||||
result[key] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--- Reports whether or not a key exists.
|
||||
-- @tparam string key The key to find.
|
||||
-- @string key The key to find.
|
||||
-- @treturn bool True if the key exists, false if not.
|
||||
function M.exists(key)
|
||||
key = replaceDots(key)
|
||||
|
@ -177,7 +231,7 @@ end
|
|||
-- if for instance, the default is 'abc', and UCI contains a configured value of
|
||||
-- 'abc' as well, that key is _not_ a default value.
|
||||
--
|
||||
-- @tparam string key The key to report about.
|
||||
-- @string key The key to report about.
|
||||
-- @treturn bool True if the key is currently at its default value, false if not.
|
||||
function M.isDefault(key)
|
||||
key = replaceDots(key)
|
||||
|
@ -186,23 +240,27 @@ function M.isDefault(key)
|
|||
end
|
||||
|
||||
--- Sets a key to a new value or reverts it to the default value.
|
||||
-- @tparam string key The key to set.
|
||||
-- @param value The value or set, or nil to revert key to its default value.
|
||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||
-- @string key The key to set.
|
||||
-- @p[opt=nil] value The value or set, or nil to revert key to its default value.
|
||||
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when setting multiple values
|
||||
-- @treturn bool|nil True if everything went well, false if validation error, nil in case of error.
|
||||
-- @treturn ?string Error message in case first return value is nil (invalid key).
|
||||
function M.set(key, value)
|
||||
function M.set(key, value, noCommit)
|
||||
--log:info(MOD_ABBR, "settings:set: "..utils.dump(key).." to: "..utils.dump(value))
|
||||
key = replaceDots(key)
|
||||
|
||||
local r = utils.create(UCI_CONFIG_FILE)
|
||||
uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, UCI_CONFIG_TYPE)
|
||||
|
||||
local base = getBaseKeyTable(key)
|
||||
if not base then return nil,ERR_NO_SUCH_KEY end
|
||||
local rv, msg = uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, UCI_CONFIG_TYPE)
|
||||
if not rv and msg ~= nil then
|
||||
local errorMSG = "Issue creating section '"..utils.dump(UCI_CONFIG_SECTION).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
|
||||
if M.isDefault(key) and value == nil then return true end -- key is default already
|
||||
|
||||
local current = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
|
||||
|
||||
local base = getBaseKeyTable(key)
|
||||
if not base then return false,ERR_NO_SUCH_KEY end
|
||||
|
||||
--log:info(MOD_ABBR, " base.type: "..utils.dump(base.type))
|
||||
if base.type == 'bool' then
|
||||
if value ~= "" then
|
||||
value = utils.toboolean(value)
|
||||
|
@ -211,52 +269,151 @@ function M.set(key, value)
|
|||
end
|
||||
elseif base.type == 'int' or base.type == 'float' then
|
||||
value = tonumber(value)
|
||||
if(value == nil) then
|
||||
return nil,"Value isn't a valid int or float"
|
||||
if(value == nil) then
|
||||
return false,"Value isn't a valid int or float"
|
||||
end
|
||||
end
|
||||
|
||||
if fromUciValue(current, base.type) == value then return true end
|
||||
local valid,m = isValid(value, base)
|
||||
if not valid then
|
||||
return false,m
|
||||
end
|
||||
|
||||
local section = UCI_CONFIG_SECTION;
|
||||
if base.subSection ~= nil then
|
||||
section = M.get(base.subSection)
|
||||
local rv, msg = uci:set(UCI_CONFIG_NAME, section, UCI_CONFIG_TYPE)
|
||||
if not rv and msg ~= nil then
|
||||
local errorMSG = "Issue getting subsection '"..utils.dump(base.subSection).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
end
|
||||
|
||||
if value ~= nil then
|
||||
local valid,m = isValid(value, base)
|
||||
if (valid) then
|
||||
uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key, toUciValue(value, base.type))
|
||||
else
|
||||
return nil,m
|
||||
local rv, msg = uci:set(UCI_CONFIG_NAME, section, key, toUciValue(value, base.type))
|
||||
if not rv and msg ~= nil then
|
||||
local errorMSG = "Issue setting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
else
|
||||
uci:delete(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
|
||||
local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key)
|
||||
if not rv and msg ~= nil then
|
||||
local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
end
|
||||
|
||||
uci:commit(UCI_CONFIG_NAME)
|
||||
|
||||
if noCommit ~= true then uci:commit(UCI_CONFIG_NAME) end
|
||||
return true
|
||||
end
|
||||
|
||||
--- Commit the UCI configuration, this can be used after making multiple changes
|
||||
-- which have not been committed yet.
|
||||
function M.commit()
|
||||
uci:commit(UCI_CONFIG_NAME)
|
||||
end
|
||||
|
||||
--- Reset all settings to their default values
|
||||
-- @string key The key to set.
|
||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||
function M.resetAll()
|
||||
log:info(MOD_ABBR, "settings:resetAll")
|
||||
|
||||
-- find all sections
|
||||
local allSections, msg = uci:get_all(UCI_CONFIG_NAME)
|
||||
if not allSections and msg ~= nil then
|
||||
local errorMSG = "Issue reading all settings: "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
|
||||
-- delete all uci sections but system
|
||||
for key,value in pairs(allSections) do
|
||||
if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||
local rv, msg = uci:delete(UCI_CONFIG_NAME,key)
|
||||
if not rv and msg ~= nil then
|
||||
local errorMSG = "Issue deleting setting '"..utils.dump(key).."': "..utils.dump(msg);
|
||||
log:warning(MOD_ABBR, errorMSG)
|
||||
return nil, errorMSG;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- reset all to defaults
|
||||
for k,_ in pairs(baseconfig) do
|
||||
if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway
|
||||
M.reset(k,true)
|
||||
end
|
||||
end
|
||||
|
||||
M.commit()
|
||||
return true
|
||||
end
|
||||
|
||||
--- Reset setting to default value
|
||||
-- @string key The key to reset.
|
||||
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values
|
||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||
function M.reset(key, noCommit)
|
||||
log:info(MOD_ABBR, "settings:reset: "..utils.dump(key))
|
||||
|
||||
-- delete
|
||||
key = replaceDots(key)
|
||||
local base = getBaseKeyTable(key)
|
||||
if not base then return nil,ERR_NO_SUCH_KEY end
|
||||
local section = UCI_CONFIG_SECTION;
|
||||
if base.subSection ~= nil then
|
||||
section = M.get(base.subSection)
|
||||
end
|
||||
local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key)
|
||||
-- we can't respond to errors in general here because when a key isn't found
|
||||
-- (which always happens when reset is used in resetall) it will also generate a error
|
||||
--if not rv and msg ~= nil then
|
||||
-- local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..section.."': "..utils.dump(msg);
|
||||
-- log:warning(MOD_ABBR, errorMSG)
|
||||
-- return nil, errorMSG;
|
||||
--end
|
||||
|
||||
-- reuse get logic to retrieve default and set it.
|
||||
M.set(key,M.get(key),true)
|
||||
|
||||
if noCommit ~= true then uci:commit(UCI_CONFIG_NAME) end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--- Returns a UCI configuration key from the system section.
|
||||
-- @tparam string key The key for which to return the value, must be non-empty.
|
||||
-- @return Requested value or false if it does not exist or nil on invalid key.
|
||||
-- @string key The key for which to return the value, must be non-empty.
|
||||
-- @return Requested value or false if it does not exist or nil on UCI error.
|
||||
function M.getSystemKey(key)
|
||||
if type(key) ~= 'string' or key:len() == 0 then return nil end
|
||||
local v = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SYSTEM_SECTION, key)
|
||||
local v,msg = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SYSTEM_SECTION, key)
|
||||
if not v and msg ~= nil then
|
||||
local errorMSG = "Issue getting system setting '"..utils.dump(key).."' in section '"..UCI_CONFIG_SYSTEM_SECTION.."': "..utils.dump(msg);
|
||||
return nil, errorMSG;
|
||||
end
|
||||
|
||||
return v or false
|
||||
end
|
||||
|
||||
--- Sets the given key to the given value.
|
||||
--- Sets the value of a UCI key in the system section.
|
||||
-- Note that unlike the public settings, system keys are untyped and value must
|
||||
-- be of type string; UCI generally uses '1' and '0' for boolean values.
|
||||
-- @tparam string key The key to set, must be non-empty.
|
||||
-- @tparam string value The value to set key to.
|
||||
-- @return True on success or false if key or value arguments are invalid.
|
||||
-- @string key The key to set, must be non-empty.
|
||||
-- @string value The value to set key to.
|
||||
-- @return True on success or nil if key or value arguments are invalid.
|
||||
function M.setSystemKey(key, value)
|
||||
if type(key) ~= 'string' or key:len() == 0 then return nil end
|
||||
if type(value) ~= 'string' then return nil end
|
||||
|
||||
|
||||
local r = utils.create(UCI_CONFIG_FILE) -- make sure the file exists for uci to write to
|
||||
uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SYSTEM_SECTION, UCI_CONFIG_TYPE)
|
||||
uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SYSTEM_SECTION, key, value)
|
||||
uci:commit(UCI_CONFIG_NAME)
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
48
src/util/status.lua
Normal file
48
src/util/status.lua
Normal file
|
@ -0,0 +1,48 @@
|
|||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
|
||||
local MOD_ABBR = "USTS"
|
||||
|
||||
local M = {}
|
||||
|
||||
local FOLDER = "/tmp/"
|
||||
local FILE_PREFIX = "d3d-"
|
||||
local FILE_EXTENSION = ".txt"
|
||||
|
||||
function getPath(fileName)
|
||||
return FOLDER..FILE_PREFIX..fileName..FILE_EXTENSION
|
||||
end
|
||||
|
||||
function M.get(fileName)
|
||||
local path = getPath(fileName)
|
||||
local file, error = io.open(path,'r')
|
||||
if file == nil then
|
||||
--log:warning(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error)
|
||||
return "",""
|
||||
else
|
||||
local status = file:read('*a')
|
||||
file:close()
|
||||
local code, msg = string.match(status, '([^|]+)|+(.*)')
|
||||
code = tonumber(code)
|
||||
return code,msg
|
||||
end
|
||||
end
|
||||
|
||||
function M.set(fileName,code,msg)
|
||||
--log:info(MOD_ABBR, "setStatus: "..code.." | "..msg)
|
||||
local path = getPath(fileName)
|
||||
local file = io.open(path,'w')
|
||||
file:write(code.."|"..msg)
|
||||
file:flush()
|
||||
file:close()
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,11 +1,24 @@
|
|||
--[[--
|
||||
TODO: finish documentation
|
||||
The unavoidable collection of utility functions.
|
||||
]]
|
||||
--
|
||||
-- This file is part of the Doodle3D project (http://doodle3d.com).
|
||||
--
|
||||
-- @copyright 2013, Doodle3D
|
||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||
|
||||
|
||||
---
|
||||
-- The unavoidable collection of utility functions.
|
||||
--
|
||||
-- Functions in this file are accompanied by unit tests, please study those
|
||||
-- to see how utility functions are expected to behave.
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
--- Splits a string on a given divider character.
|
||||
-- @string[opt=':'] div The divider character to use.
|
||||
-- @return An array containing the resultant substrings.
|
||||
-- @usage local str = "a,b,c"; local parts = str:split(',')
|
||||
function string:split(div)
|
||||
local div, pos, arr = div or ':', 0, {}
|
||||
for st,sp in function() return self:find(div, pos, true) end do
|
||||
|
@ -16,6 +29,9 @@ function string:split(div)
|
|||
return arr
|
||||
end
|
||||
|
||||
--- Returns the size of an open file handle.
|
||||
-- @param file File handle to report about.
|
||||
-- @treturn number Size of the file, determined by seeking to the end.
|
||||
function M.fileSize(file)
|
||||
local current = file:seek()
|
||||
local size = file:seek('end')
|
||||
|
@ -23,9 +39,14 @@ function M.fileSize(file)
|
|||
return size
|
||||
end
|
||||
|
||||
--- Convert an object to boolean.
|
||||
-- String values which will yield true are (case insensitive): '1', 't' and 'true'.
|
||||
-- Boolean true and numbers other than 0 also yield true, everything else yields false.
|
||||
-- @param s The object to convert.
|
||||
-- @treturn bool The converted value.
|
||||
function M.toboolean(s)
|
||||
if not s then return false end
|
||||
|
||||
|
||||
local b = type(s) == 'string' and s:lower() or s
|
||||
local textTrue = (b == '1' or b == 't' or b == 'true')
|
||||
local boolTrue = (type(b) == 'boolean' and b == true)
|
||||
|
@ -33,6 +54,10 @@ function M.toboolean(s)
|
|||
return textTrue or boolTrue or numTrue
|
||||
end
|
||||
|
||||
--- Stringifies the given object.
|
||||
-- Note that self-referencing objects will cause an endless loop with the current implementation.
|
||||
-- @param o The object to convert.
|
||||
-- @treturn string Stringified version of o.
|
||||
function M.dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
|
@ -59,34 +84,46 @@ function M.getUciSectionName(config, type)
|
|||
return sname
|
||||
end
|
||||
|
||||
--- Reports whether or not a file exists. This is done by trying to open it.
|
||||
-- @tparam string file Filename to report about.
|
||||
-- @treturn bool|nil True if the file exists, false otherwise or nil on invalid argument.
|
||||
-- @treturn ?string Descriptive message on error.
|
||||
function M.exists(file)
|
||||
if not file or type(file) ~= 'string' or file:len() == 0 then
|
||||
return nil, "file must be a non-empty string"
|
||||
end
|
||||
|
||||
|
||||
local r = io.open(file, 'r') -- ignore returned message
|
||||
if r then r:close() end
|
||||
return r ~= nil
|
||||
end
|
||||
|
||||
--creates and returns true if not exists, returns false it does, nil+msg on error
|
||||
--- Creates a file if it does not exist yet.
|
||||
-- @string file Path and name of the file to create.
|
||||
-- @treturn bool|nil True if the file has been created, false if it already existed or nil on error
|
||||
-- @treturn ?string Descriptive message on error
|
||||
function M.create(file)
|
||||
local r,m = M.exists(file)
|
||||
|
||||
|
||||
if r == nil then
|
||||
return r,m
|
||||
elseif r == true then
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
r,m = io.open(file, 'a') -- append mode is probably safer in case the file does exist after all
|
||||
if not r then return r,m end
|
||||
|
||||
|
||||
r:close()
|
||||
return true
|
||||
end
|
||||
|
||||
--FIXME: somehow protect this function from running arbitrary commands
|
||||
--- Create a symlink on the file system.
|
||||
-- _Note_ that this function contains a potential security leak as it uses os.execute with given parameters.
|
||||
-- @string from Source path for the symlink.
|
||||
-- @string to Target path for the symlink.
|
||||
-- @return The return value from @{os.execute}, or -1 on invalid parameter(s).
|
||||
-- @fixme: somehow protect this function from running arbitrary commands
|
||||
function M.symlink(from, to)
|
||||
if from == nil or from == '' or to == nil or to == '' then return -1 end
|
||||
local x = 'ln -s ' .. from .. ' ' .. to
|
||||
|
@ -96,19 +133,22 @@ end
|
|||
function M.readFile(filePath)
|
||||
local f, msg, nr = io.open(filePath, 'r')
|
||||
if not f then return nil,msg,nr end
|
||||
|
||||
|
||||
local res = f:read('*all')
|
||||
f:close()
|
||||
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- TODO: this function has been duplicated from rest/api/api_system.lua
|
||||
--- Runs a command and captures its output using @{io.popen}.
|
||||
-- @string cmd The command to run.
|
||||
-- @treturn string Output of the command that was run.
|
||||
-- @todo: this function has been duplicated from rest/api/api_system.lua
|
||||
function M.captureCommandOutput(cmd)
|
||||
local f = assert(io.popen(cmd, 'r'))
|
||||
local f = assert(io.popen(cmd..' 2>&1', 'r'))
|
||||
local output = assert(f:read('*all'))
|
||||
f:close()
|
||||
return output;
|
||||
return output
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
1
src/www
1
src/www
|
@ -1 +0,0 @@
|
|||
Subproject commit 51e43944918793711da037bab8eb76d40ee5b42c
|
58
test/test-d3d-updater.lua
Normal file
58
test/test-d3d-updater.lua
Normal file
|
@ -0,0 +1,58 @@
|
|||
-- This script contains a number of impromptu tests to check version comparisons, kept around in case real unit tests will be created one day.
|
||||
argStash = arg
|
||||
arg = nil
|
||||
local upd = require('d3d-updater')
|
||||
arg = argStash
|
||||
|
||||
local function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
local input = '19990213'
|
||||
local ts = upd.parseDate(input)
|
||||
print("parse " .. input .. ": " .. ts)
|
||||
print("format " .. ts .. ": " .. upd.formatDate(ts))
|
||||
|
||||
local vertex1 = '0.2.3'
|
||||
local vertab1 = upd.parseVersion(vertex1)
|
||||
print("parse " .. vertex1 .. ": " .. dump(vertab1))
|
||||
print("formatted: " .. upd.formatVersion(vertab1))
|
||||
|
||||
local vertex2 = '0.2.3-text'
|
||||
local vertab2 = upd.parseVersion(vertex2)
|
||||
print("parse " .. vertex2 .. ": " .. dump(vertab2))
|
||||
print("formatted: " .. upd.formatVersion(vertab2))
|
||||
|
||||
local vA, vB = upd.parseVersion("1.4.5-alpha"), upd.parseVersion("1.4.4-rc1")
|
||||
local tsA, tsB = 100000, 100005
|
||||
|
||||
local cmp1,cmp2 = upd.compareVersions(vA, vB)
|
||||
print("vA <=> vB: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
cmp1,cmp2 = upd.compareVersions(vA, vB, tsA, tsB)
|
||||
print("vA/tsA <=> vB/tsB: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
cmp1,cmp2 = upd.compareVersions(vB, vA, tsA, tsB)
|
||||
print("vB/tsA <=> vA/tsB: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
cmp1,cmp2 = upd.compareVersions(vA, vB, tsB, tsA)
|
||||
print("vA/tsB <=> vB/tsA: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
|
||||
local vWithout,vWith = upd.parseVersion('1.2.3'), upd.parseVersion('1.2.3-sfx')
|
||||
--print("vWithout: " .. dump(vWithout) .. "; vWith: " .. dump(vWith))
|
||||
cmp1,cmp2 = upd.compareVersions(vWithout, vWithout)
|
||||
print("1.2.3 <=> 1.2.3: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
cmp1,cmp2 = upd.compareVersions(vWithout, vWith)
|
||||
print("1.2.3 <=> 1.2.3-sfx: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
cmp1,cmp2 = upd.compareVersions(vWith, vWith)
|
||||
print("1.2.3-sfx <=> 1.2.3-sfx: " .. cmp1 .. " / " .. dump(cmp2))
|
||||
|
||||
print("nn equal? " .. dump(upd.versionsEqual(vWithout, vWithout)))
|
||||
print("ny equal? " .. dump(upd.versionsEqual(vWithout, vWith)))
|
||||
print("yy equal? " .. dump(upd.versionsEqual(vWith, vWith)))
|
Loading…
Reference in New Issue
Block a user