├── .gitignore ├── .img ├── add_mount_point.gif ├── poster.png ├── remove_mount_point.gif └── start_server.gif ├── .travis.yml ├── LICENSE ├── README.md ├── ShareMyHost.desktop ├── ShareMyHost.pro ├── include ├── Clipper.hpp ├── Helpers.hpp ├── MongooseBackend.hpp ├── MongooseBackendPrivate.hpp └── mongoose.h ├── qml ├── Components │ ├── AboutPage.qml │ ├── ErrorDialog.qml │ ├── MainMenu.qml │ ├── MainPage.qml │ ├── MountPage.qml │ ├── MountPointDialog.qml │ └── Server.qml ├── index_a.html ├── index_b.html ├── logo.png ├── main.qml ├── qml.qrc ├── server_off.png └── server_on.png └── src ├── Clipper.cc ├── Helpers.cc ├── MongooseBackend.cc ├── MongooseBackendPrivate.cc ├── main.cc └── mongoose.c /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /.img/add_mount_point.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/.img/add_mount_point.gif -------------------------------------------------------------------------------- /.img/poster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/.img/poster.png -------------------------------------------------------------------------------- /.img/remove_mount_point.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/.img/remove_mount_point.gif -------------------------------------------------------------------------------- /.img/start_server.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/.img/start_server.gif -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: gcc 3 | sudo: require 4 | dist: xenial 5 | 6 | before_install: 7 | - sudo add-apt-repository ppa:beineri/opt-qt-5.12.3-xenial -y 8 | - sudo apt-get update -qq 9 | 10 | install: 11 | - sudo apt-get -y install build-essential libgl1-mesa-dev qt512base qt512quickcontrols2 qt512quickcontrols qt512declarative 12 | - source /opt/qt*/bin/qt*-env.sh 13 | 14 | script: 15 | - qmake . 16 | - make -j$(nproc) 17 | - mkdir -p appdir/usr/bin ; strip ShareMyHost ; cp ShareMyHost appdir/usr/bin/ 18 | - mkdir -p appdir/usr/share/applications ; cp ShareMyHost.desktop appdir/usr/share/applications/ 19 | - mkdir -p appdir/usr/share/icons/hicolor/256x256/apps/ ; cp qml/logo.png appdir/usr/share/icons/hicolor/256x256/apps/ShareMyHost.png 20 | - wget -c -nv "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" 21 | - chmod a+x linuxdeployqt-continuous-x86_64.AppImage 22 | - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH 23 | - export VERSION=$(git rev-parse --short HEAD) 24 | - ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -qmldir=$(qmake -query QT_INSTALL_QML) -bundle-non-qt-libs 25 | - wget -c -nv "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" 26 | - chmod +x appimagetool-x86_64.AppImage 27 | - ./appimagetool-x86_64.AppImage -u "gh-releases-zsync|antony-jr|ShareMyHost|continuous|ShareMyHost*-x86_64.AppImage.zsync" appdir 28 | 29 | 30 | after_success: 31 | - wget "https://github.com/probonopd/uploadtool/raw/master/upload.sh" 32 | - bash upload.sh ShareMyHost*.AppImage *zsync 33 | 34 | branches: 35 | except: 36 | - # Do not build tags that we create when we upload to GitHub Releases 37 | - /^(?i:continuous)/ 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Share My Host

2 |

3 | issues 4 | stars 5 | stars 6 | license 7 | 8 |

9 | 10 |

11 | 12 | 13 | 14 | 15 | 16 | 17 | 22 | 23 | 24 |
Download
Execute
18 | 19 | Download 20 | 21 | chmod +x ShareMyHost*-x86_64.AppImage && ./ShareMyHost*-x86_64.AppImage
25 |

26 | 27 | 28 |

29 | Share My Host
30 |

31 | 32 | 33 | **ShareMyHost** is a simple and powerful program written in C++/QML using Google's material 34 | design guidelines. It gives a *very simple http server for sharing file(s) within your 35 | local network*. It uses **mount points** which are sort of like http endpoints with directory 36 | listing to specific directories in your file system. 37 | 38 | For example, You create a **Mount Point**(say /Animes to /home/user/Anime) then you can access 39 | the directory listing and all its files at ```http://ip:port/Animes``` (Ex: http://192.168.1.3:8080/Animes). 40 | 41 | ## Features 42 | 43 | * *Easy to Use* - This program is specifically built for ease of use. 44 | 45 | * *Support for Kodi HTTP Client* - The best of my knowledge, this is the only application which supports listing of files in kodi 46 | from the mount points. 47 | 48 | * *Directory Listing by Default* - No need to fight with permissions in linux. 49 | 50 | * *Automatic Permission Managemnt* - No need to worry about who owns what. 51 | 52 | * *Mongoose Server as Backend* - Uses a trusted Web Server. 53 | 54 | * *Material Design* - Built using QML with Material Style. 55 | 56 | 57 | See down below for the usage. 58 | 59 | # Usage 60 | 61 | ### Starting the server 62 | 63 |

64 | Starting the Server 65 |
66 |

67 | 68 | ### Adding Mount Point 69 | 70 | 71 |

72 | Add Mount Point 73 |
74 |

75 | 76 | ### Removing Mount Point 77 | 78 |

79 | Remove Mount Point 80 |
81 |

82 | 83 | 84 | 85 | # Support 86 | 87 | If you think that this project is **cool** then you can give it a :star: or :fork_and_knife: it if you want to improve it with me. I really :heart: stars though! 88 | 89 | You can also tweet about me on twitter , get connected with me [@antonyjr0](https://twitter.com/antonyjr0) 90 | 91 | Thank You! :smiley_cat: 92 | 93 | # Icons 94 | 95 | All icons used in this program has been made by [Icons8](https://icons8.com). 96 | 97 | # Mongoose Server Usage 98 | 99 | This program uses the mongoose server for serving contents, Since it's in GPLV2 this program is also under 100 | GPLV2 to comply with the license. 101 | 102 | The source of mongoose server has been heavily modified to our specific use case, such as the usage with 103 | mount points. Therefore for updating the mongoose server code, we must be careful not to remove the 104 | modified code. *All modification to the code is mentioned in the top of source files.* 105 | 106 | 107 | # License 108 | 109 | The GNU General Public License V2. 110 | 111 | Copyright (C) Antony Jr. 112 | -------------------------------------------------------------------------------- /ShareMyHost.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=ShareMyHost 3 | Type=Application 4 | Exec=ShareMyHost 5 | Icon=ShareMyHost 6 | Terminal=false 7 | Categories=Utility; 8 | Comment=One click to share your files in your local network. 9 | -------------------------------------------------------------------------------- /ShareMyHost.pro: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += . include 2 | TEMPLATE = app 3 | CONFIG += release static 4 | TARGET = ShareMyHost 5 | QT += core network gui widgets qml quickcontrols2 6 | 7 | DEFINES += QT_DEPRECATED_WARNINGS 8 | 9 | HEADERS += include/mongoose.h \ 10 | include/MongooseBackend.hpp \ 11 | include/MongooseBackendPrivate.hpp \ 12 | include/Helpers.hpp \ 13 | include/Clipper.hpp 14 | 15 | SOURCES += src/main.cc \ 16 | src/mongoose.c \ 17 | src/MongooseBackend.cc \ 18 | src/MongooseBackendPrivate.cc \ 19 | src/Helpers.cc \ 20 | src/Clipper.cc 21 | 22 | RESOURCES += qml/qml.qrc 23 | -------------------------------------------------------------------------------- /include/Clipper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLIPPER_HPP_INCLUDED 2 | #define CLIPPER_HPP_INCLUDED 3 | #include 4 | #include 5 | 6 | class Clipper : public QObject { 7 | Q_OBJECT 8 | Q_PROPERTY(NOTIFY clipped) 9 | public: 10 | explicit Clipper(QObject *parent = nullptr); 11 | ~Clipper(); 12 | Q_INVOKABLE void clip(QString); 13 | signals: 14 | void clipped(); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/Helpers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HELPERS_PRIVATE_HPP_INCLUDED 2 | #define HELPERS_PRIVATE_HPP_INCLUDED 3 | #include 4 | #include 5 | #include 6 | QMetaMethod getMethod(QObject*,const char*); 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /include/MongooseBackend.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MONGOOSE_BACKEND_HPP_INCLUDED 2 | #define MONGOOSE_BACKEND_HPP_INCLUDED 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | class MongooseBackendPrivate; 11 | 12 | class MongooseBackend : public QObject { 13 | Q_OBJECT 14 | Q_PROPERTY(NOTIFY serverStarted 15 | NOTIFY serverStopped 16 | NOTIFY error 17 | NOTIFY mountPointAddError 18 | NOTIFY mountPoint 19 | NOTIFY mountPointAdded 20 | NOTIFY mountPointRemoved) 21 | 22 | QThread m_Thread; 23 | MongooseBackendPrivate *m_Private; 24 | public: 25 | explicit MongooseBackend(QObject *parent = nullptr); 26 | ~MongooseBackend(); 27 | Q_INVOKABLE void toggleServer(); 28 | Q_INVOKABLE void addMountPoint(QString, QUrl); 29 | Q_INVOKABLE void removeMountPoint(QString); 30 | Q_INVOKABLE void getAllMountPoints(); 31 | 32 | signals: 33 | void serverStarted(QString serverAddress); 34 | void serverStopped(); 35 | void error(QString errorMessage); 36 | void mountPointAddError(); 37 | void mountPoint(QString mountPoint); 38 | void mountPointAdded(QString mountPoint); 39 | void mountPointRemoved(QString mountPoint); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/MongooseBackendPrivate.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MONGOOSE_BACKEND_PRIVATE_HPP_INCLUDED 2 | #define MONGOOSE_BACKEND_PRIVATE_HPP_INCLUDED 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class MongooseBackendPrivate : public QObject { 13 | Q_OBJECT 14 | bool b_StopRequested; 15 | bool b_Running; 16 | QString m_Address; 17 | QSettings m_Settings; 18 | public: 19 | QJsonObject m_MountPoints; // This must be accessible by mongoose callbacks. 20 | 21 | explicit MongooseBackendPrivate(QObject *parent = nullptr); 22 | ~MongooseBackendPrivate(); 23 | 24 | public slots: 25 | void toggleServer(); 26 | void addMountPoint(QString, QUrl); 27 | void removeMountPoint(QString); 28 | void getAllMountPoints(); 29 | 30 | private slots: 31 | void startServer(); 32 | void stopServer(); 33 | signals: 34 | void serverStarted(QString); 35 | void serverStopped(); 36 | void error(QString); 37 | void mountPointAddError(); 38 | void mntPoint(QString); 39 | void mountPointAdded(QString); 40 | void mountPointRemoved(QString); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /qml/Components/AboutPage.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Dialogs 1.3 3 | import QtQuick.Layouts 1.12 4 | import QtQuick.Controls.Styles 1.4 5 | import QtQuick.Controls 2.12 6 | import QtQuick.Controls.Material 2.12 7 | 8 | 9 | GridLayout { 10 | property ApplicationWindow mainWindow; 11 | 12 | visible: mainWindow.showAboutPage 13 | anchors.fill: parent 14 | anchors.top: parent.top 15 | anchors.left: parent.left 16 | anchors.right: parent.right 17 | anchors.bottom: parent.bottom 18 | columns: 1 19 | rows: 1 20 | 21 | 22 | ColumnLayout { 23 | Layout.preferredWidth: parent.width - 100 24 | Layout.preferredHeight: parent.height - 50 25 | Layout.row: 0 26 | Layout.alignment: Qt.AlignHCenter | Qt.AlignTop 27 | Layout.topMargin: 10 28 | 29 | RowLayout{ 30 | Layout.alignment: Qt.AlignHCenter 31 | Image { 32 | cache: true 33 | fillMode: Image.PreserveAspectFit 34 | Layout.preferredWidth: 175 35 | Layout.preferredHeight: 175 36 | source: "qrc:/logo.png" 37 | } 38 | 39 | } 40 | 41 | Label { 42 | Layout.alignment: Qt.AlignHCenter | Qt.AlignTop 43 | Layout.preferredWidth: parent.width - 100 44 | horizontalAlignment: Qt.AlignHCenter 45 | verticalAlignment: Qt.AlignTop 46 | text: qsTr("This program is licensed under GNU General Public License V2.
") + 47 | qsTr("Copyright \u00A9 Antony Jr.
") + 48 | qsTr("All Icons by Icons8.
") 49 | font.pixelSize: 18 50 | wrapMode: Text.WordWrap 51 | textFormat: Text.RichText 52 | onLinkActivated: Qt.openUrlExternally(link) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qml/Components/ErrorDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Dialogs 1.3 3 | import QtQuick.Layouts 1.12 4 | import QtQuick.Controls.Styles 1.4 5 | import QtQuick.Controls 2.12 6 | import QtQuick.Controls.Material 2.12 7 | 8 | Dialog { 9 | property ApplicationWindow mainWindow; 10 | 11 | x: (mainWindow.width - width) / 2 12 | y: (mainWindow.height - height) / 2 13 | title: mainWindow.errorTitle 14 | visible: mainWindow.showErrorDialog 15 | contentItem: GridLayout { 16 | anchors.fill: parent 17 | ColumnLayout { 18 | Layout.alignment: Qt.AlignHCenter 19 | Text { 20 | text: mainWindow.errorMessage 21 | font.pixelSize: 14 22 | } 23 | } 24 | } 25 | standardButtons: StandardButton.Ok | StandardButton.Cancel 26 | onAccepted: { 27 | mainWindow.showErrorDialog = false 28 | } 29 | onRejected: { 30 | mainWindow.showErrorDialog = false 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /qml/Components/MainMenu.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Controls 2.12 3 | 4 | MenuBar { 5 | property ApplicationWindow mainWindow; 6 | Menu { 7 | title: qsTr("File") 8 | MenuItem { 9 | text: qsTr("Dashboard") 10 | onTriggered: { 11 | mainWindow.showMainPage = true; 12 | mainWindow.showMountPage = false; 13 | mainWindow.showAboutPage = false; 14 | } 15 | } 16 | 17 | MenuItem { 18 | text: qsTr("Mount Points") 19 | onTriggered: { 20 | mainWindow.showMainPage = false; 21 | mainWindow.showMountPage = true; 22 | mainWindow.showAboutPage = false; 23 | } 24 | } 25 | 26 | MenuItem { 27 | text: qsTr("Exit") 28 | onTriggered: Qt.quit(); 29 | } 30 | } 31 | Menu { 32 | title: qsTr("Help") 33 | MenuItem { 34 | text: qsTr("About") 35 | onTriggered: { 36 | mainWindow.showMainPage = false; 37 | mainWindow.showMountPage = false; 38 | mainWindow.showAboutPage = true; 39 | } 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /qml/Components/MainPage.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Layouts 1.12 3 | import QtQuick.Controls.Styles 1.4 4 | import QtQuick.Controls 2.12 5 | import QtQuick.Controls.Material 2.12 6 | 7 | import Core.Clipper 1.0 8 | 9 | GridLayout { 10 | property ApplicationWindow mainWindow; 11 | property Button controlButton : startStopBtn; 12 | 13 | visible: mainWindow.showMainPage 14 | anchors.fill: parent 15 | columns: 2 16 | ColumnLayout { 17 | Layout.column: 0 18 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 19 | Image { 20 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 21 | cache: true 22 | fillMode: Image.PreserveAspectFit 23 | Layout.preferredWidth: 100 24 | Layout.preferredHeight: 100 25 | source: mainWindow.serverStatusImg 26 | } 27 | 28 | TextField { 29 | id: infoLbl 30 | objectName: "ipInfoLbl" 31 | text: mainWindow.serverIp 32 | Layout.preferredWidth: 240 33 | Layout.alignment: Qt.AlignHCenter 34 | horizontalAlignment: TextInput.AlignHCenter 35 | font.pixelSize: 20 36 | readOnly: true 37 | selectByMouse: true 38 | } 39 | Text { 40 | text: 41 | qsTr("We are currently using the above address to host your file(s).") 42 | font.pixelSize: 12 43 | Layout.alignment: Qt.AlignHCenter 44 | } 45 | RowLayout { 46 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 47 | spacing: 10 48 | 49 | Button { 50 | id: copyIpBtn 51 | property string beforeText: qsTr("Copy Address") 52 | 53 | Layout.alignment: Qt.AlignHCenter 54 | text: beforeText 55 | Material.background: Material.Green 56 | highlighted: true 57 | 58 | onClicked: { 59 | clipper.clip(mainWindow.serverIp) 60 | } 61 | } 62 | 63 | Button { 64 | text: qsTr("Open in Browser") 65 | onClicked: { 66 | if(infoLbl.text == qsTr("START THE SERVER FIRST")){ 67 | return 68 | } 69 | Qt.openUrlExternally(infoLbl.text) 70 | } 71 | } 72 | } 73 | Button { 74 | id: startStopBtn 75 | objectName: "startStopBtn" 76 | highlighted: true 77 | property string loadText: qsTr("Processing... ") 78 | property string beforeText: qsTr("Start Sharing") 79 | 80 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 81 | Layout.preferredWidth: 200 82 | Layout.preferredHeight: 80 83 | text: beforeText 84 | Material.background: Material.Teal 85 | onClicked: { 86 | startStopBtn.text = loadText 87 | mainServer.toggleServer(); 88 | } 89 | } 90 | } // Close ColumnLayout 91 | 92 | Timer { 93 | id: copyTimer 94 | interval: 1000 95 | repeat: false 96 | onTriggered: { 97 | copyIpBtn.text = copyIpBtn.beforeText; 98 | } 99 | } 100 | 101 | Clipper { 102 | id: clipper 103 | onClipped: { 104 | copyIpBtn.text = qsTr("Copied") 105 | copyTimer.start(); 106 | } 107 | } 108 | } 109 | 110 | -------------------------------------------------------------------------------- /qml/Components/MountPage.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Dialogs 1.3 3 | import QtQuick.Layouts 1.12 4 | import QtQuick.Controls.Styles 1.4 5 | import QtQuick.Controls 2.12 6 | import QtQuick.Controls.Material 2.12 7 | 8 | import Core.MongooseBackend 1.0 9 | 10 | GridLayout { 11 | property ApplicationWindow mainWindow; 12 | property ListModel listModel; 13 | property MongooseBackend server; 14 | property Dialog dialog; 15 | 16 | visible: mainWindow.showMountPage 17 | anchors.fill: parent 18 | anchors.top: parent.top 19 | anchors.left: parent.left 20 | anchors.right: parent.right 21 | anchors.bottom: parent.bottom 22 | columns: 1 23 | rows: 2 24 | 25 | Pane { 26 | Material.elevation: 4 27 | Layout.preferredWidth: parent.width - 100 28 | Layout.preferredHeight: parent.height - controls.height - 50 29 | Layout.row: 0 30 | Layout.alignment: Qt.AlignHCenter | Qt.AlignTop 31 | Layout.topMargin: 10 32 | 33 | ScrollView { 34 | width: parent.width - 10 35 | height: parent.height - 60 36 | ScrollBar.vertical.policy: ScrollBar.AlwaysOn 37 | 38 | ListView { 39 | id: mountPointList 40 | width: parent.width 41 | height: parent.height 42 | 43 | model: listModel 44 | 45 | delegate: RowLayout { 46 | width: parent.width - 10 47 | Text { 48 | Layout.alignment: Qt.AlignLeft 49 | text: name 50 | font.pixelSize: 16 51 | } 52 | 53 | RowLayout { 54 | Layout.rightMargin: 10 55 | Layout.alignment: Qt.AlignRight 56 | RoundButton { 57 | Material.background: Material.Red 58 | text: "\u00D7" 59 | onClicked: { 60 | server.removeMountPoint(name) 61 | } 62 | } 63 | } 64 | } // Close delegate property 65 | } // Close ListView 66 | } // Close ScrollView 67 | } // Close Pane 68 | 69 | ColumnLayout { 70 | id: controls 71 | Layout.preferredWidth: parent.width - 50 72 | Layout.row: 1 73 | Layout.bottomMargin: 20 74 | Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom 75 | ToolSeparator { 76 | Layout.preferredWidth: parent.width / 2 77 | Layout.alignment: Qt.AlignHCenter 78 | orientation: Qt.Horizontal 79 | } 80 | 81 | Button { 82 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 83 | id: addMountBtn 84 | objectName: "addMountBtn" 85 | text: qsTr("Add Mount Point") 86 | onClicked: { 87 | dialog.location = ""; 88 | dialog.mountPointTextField.text = ""; 89 | dialog.visible = true; 90 | } 91 | } 92 | } // Close ColumnLayout 93 | } // Close main GridLayout 94 | -------------------------------------------------------------------------------- /qml/Components/MountPointDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Dialogs 1.3 3 | import QtQuick.Layouts 1.12 4 | import QtQuick.Controls.Styles 1.4 5 | import QtQuick.Controls 2.12 6 | import QtQuick.Controls.Material 2.12 7 | 8 | import Core.MongooseBackend 1.0 9 | 10 | Dialog { 11 | property FileDialog fileDialog; 12 | property string location: ""; 13 | property TextField mountPointTextField: mountPointTxt; 14 | property MongooseBackend server; 15 | 16 | visible: false; 17 | x: (parent.width - width) / 2 18 | y: (parent.height - height) / 2 19 | title: "Add Mount Point" 20 | contentItem: GridLayout { 21 | id: addMountPointDialogContent 22 | anchors.fill: parent 23 | ColumnLayout { 24 | Layout.alignment: Qt.AlignHCenter 25 | TextField { 26 | validator: RegExpValidator { regExp: /^\w+$/ } 27 | id: mountPointTxt 28 | Layout.preferredWidth: 300 29 | horizontalAlignment: Qt.AlignHCenter 30 | placeholderText: qsTr("Mount Point") 31 | } 32 | TextField { 33 | id: locationTxt 34 | Layout.preferredWidth: 300 35 | horizontalAlignment: Qt.AlignHCenter 36 | text: location 37 | placeholderText: qsTr("Location") 38 | readOnly: true 39 | } 40 | 41 | Button { 42 | Layout.alignment: Qt.AlignHCenter 43 | id: browseLocationBtn 44 | text: qsTr("Browse Location") 45 | onClicked: fileDialog.open() 46 | } 47 | } 48 | } 49 | standardButtons: StandardButton.Ok | StandardButton.Cancel 50 | onAccepted: { 51 | visible = false; 52 | if(locationTxt.text != "" && 53 | mountPointTxt.text != ""){ 54 | server.addMountPoint(mountPointTxt.text, locationTxt.text); 55 | } 56 | 57 | } 58 | onRejected: { 59 | visible = false; 60 | } 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /qml/Components/Server.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Controls 2.12 3 | import QtQuick.Controls.Material 2.12 4 | import QtQuick.Dialogs 1.1 5 | 6 | import Core.MongooseBackend 1.0 7 | 8 | MongooseBackend { 9 | property ApplicationWindow mainWindow; 10 | property Button controlButton; 11 | property ListModel listModel; 12 | 13 | onServerStarted: { 14 | // Set server address 15 | mainWindow.serverIp = "http://" + serverAddress 16 | 17 | controlButton.text = qsTr("Stop Sharing") 18 | controlButton.Material.background = Material.Red 19 | 20 | // Change picture status 21 | mainWindow.serverStatusImg = "qrc:/server_on.png" 22 | } 23 | 24 | onServerStopped: { 25 | controlButton.text = controlButton.beforeText 26 | controlButton.Material.background = Material.Teal 27 | 28 | mainWindow.serverStatusImg = "qrc:/server_off.png" 29 | } 30 | 31 | onMountPoint: { 32 | listModel.append({ "name": mountPoint}) 33 | } 34 | 35 | onMountPointAdded: { 36 | listModel.append({ "name": mountPoint }) 37 | } 38 | 39 | onMountPointRemoved: { 40 | var iter = 0; 41 | while(iter < listModel.count){ 42 | if(listModel.get(iter).name == mountPoint){ 43 | listModel.remove(iter) 44 | } 45 | ++iter; 46 | } 47 | } 48 | 49 | onError: { 50 | controlButton.text = controlButton.beforeText 51 | controlButton.Material.background = Material.Teal 52 | mainWindow.serverStatusImg = "qrc:/server_off.png" 53 | mainWindow.errorTitle = "Server Error" 54 | mainWindow.errorMessage = "The server could not start because: " + errorMessage + "." 55 | mainWindow.showErrorDialog= true 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /qml/index_b.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 |

Share My Host is Maintained and Developed by Antony Jr.

9 |
10 |
11 | 12 | 13 | 14 | 21 | 22 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /qml/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/qml/logo.png -------------------------------------------------------------------------------- /qml/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.12 2 | import QtQuick.Window 2.0 3 | import QtQuick.Dialogs 1.3 4 | import QtQuick.Layouts 1.12 5 | import QtQuick.Controls.Styles 1.4 6 | import QtQuick.Controls 2.12 7 | import QtQuick.Controls.Material 2.12 8 | 9 | import "./Components" as Components 10 | 11 | ApplicationWindow { 12 | id: root 13 | title: qsTr("Share My Host") 14 | width: 800 15 | height: 500 16 | minimumWidth: 400 17 | minimumHeight: 400 18 | visible: true 19 | Material.theme: Material.Light // Use google material design 20 | 21 | Component.onCompleted: { 22 | setX(Screen.width / 2 - width / 2); 23 | setY(Screen.height / 2 - height / 2); 24 | 25 | // Also add all mount points from settings 26 | mainServer.getAllMountPoints(); 27 | } 28 | 29 | 30 | /* Components.MainMenu is a MenuBar QML Object. 31 | * This is a Customized Object which takes a ApplicationWindow. 32 | * This expects all the properties on changing pages to be 33 | * present. */ 34 | menuBar: Components.MainMenu { 35 | id: mainMenu 36 | mainWindow: root 37 | } 38 | 39 | /* 40 | * These properties are used by some other 41 | * components to navigate through different 42 | * screens in the Application. 43 | */ 44 | property bool showMainPage: true // Default page 45 | property bool showMountPage: false 46 | property bool showAboutPage: false 47 | property bool showErrorDialog: false; 48 | property string locationStr: qsTr("") 49 | property string serverStatusImg: "qrc:/server_off.png" 50 | property string serverIp: qsTr("START THE SERVER FIRST") 51 | property string errorTitle; 52 | property string errorMessage; 53 | 54 | /* 55 | * Folder select dialog box which is used by 56 | * the 'Add Mount Point' Dialog. 57 | * 58 | * The 'Browse Location' triggers this dialog. 59 | */ 60 | FileDialog { 61 | id: localFolderDialog; 62 | title: "Select Mount Point"; 63 | folder: shortcuts.home; 64 | selectFolder: true 65 | onAccepted: { 66 | // Change location to reflect the selection in the 67 | // mountPointDialog. 68 | mountPointDialog.location = localFolderDialog.folder.toString() 69 | } 70 | } 71 | /* -- FileDialog -- */ 72 | 73 | /* 74 | * This is a Modal Dialog which will be shown when 75 | * required to Add a new Mount Point. 76 | * 77 | * This requires the about FileDialog. 78 | * 79 | * The 'location' is a string property which modifies the 80 | * text of the Location TextField inside the Dialog. 81 | */ 82 | Components.MountPointDialog { 83 | id: mountPointDialog 84 | fileDialog: localFolderDialog 85 | server: mainServer 86 | } 87 | /* -- MountPointDialog -- */ 88 | 89 | Components.ErrorDialog { 90 | id: errorDialog 91 | mainWindow: root 92 | } 93 | 94 | /* All the Pages. */ 95 | Components.AboutPage { 96 | id: aboutPage 97 | mainWindow: root 98 | } 99 | 100 | Components.MountPage { 101 | id: mountPage 102 | mainWindow: root 103 | listModel: mountPageListModel 104 | server: mainServer 105 | dialog: mountPointDialog 106 | } 107 | 108 | Components.MainPage { 109 | id: mainPage 110 | mainWindow: root 111 | } 112 | // -- End All Pages -- 113 | 114 | ListModel { 115 | id: mountPageListModel 116 | objectName: "mountPageListModel" 117 | } 118 | 119 | /* 120 | * The main Mongoose Server QML bindings. This QML Object is just a wrapper 121 | * but it has deep connection to C++ code. 122 | * 123 | * Properties: 124 | * controlButton -> The id of the button which controls the server, 125 | * we just change the text and other stuff when 126 | * the server starts and closes. 127 | */ 128 | Components.Server { 129 | id: mainServer 130 | controlButton: mainPage.controlButton 131 | mainWindow: root 132 | listModel: mountPageListModel 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /qml/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Components/Server.qml 5 | Components/MainMenu.qml 6 | Components/AboutPage.qml 7 | Components/MountPage.qml 8 | Components/MainPage.qml 9 | Components/MountPointDialog.qml 10 | Components/ErrorDialog.qml 11 | logo.png 12 | server_on.png 13 | server_off.png 14 | index_a.html 15 | index_b.html 16 | 17 | 18 | -------------------------------------------------------------------------------- /qml/server_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/qml/server_off.png -------------------------------------------------------------------------------- /qml/server_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antony-jr/ShareMyHost/a0fb13bb5da69f39263bc00abb4cb0523be2d9ba/qml/server_on.png -------------------------------------------------------------------------------- /src/Clipper.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | Clipper::Clipper(QObject *parent) : 6 | QObject(parent) { 7 | } 8 | 9 | Clipper::~Clipper() { 10 | } 11 | 12 | void Clipper::clip(QString content) { 13 | QClipboard *clipboard = QApplication::clipboard(); 14 | if(!clipboard) { 15 | return; 16 | } 17 | clipboard->setText(content); 18 | emit clipped(); 19 | } 20 | -------------------------------------------------------------------------------- /src/Helpers.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | QMetaMethod getMethod(QObject *object, const char *function) { 4 | auto metaObject = object->metaObject(); 5 | return metaObject->method(metaObject->indexOfMethod(QMetaObject::normalizedSignature(function))); 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/MongooseBackend.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | MongooseBackend::MongooseBackend(QObject *parent) : 7 | QObject(parent), 8 | m_Private(new MongooseBackendPrivate) { 9 | m_Private->moveToThread(&m_Thread); 10 | m_Thread.start(); 11 | 12 | connect(m_Private, &MongooseBackendPrivate::serverStarted, 13 | this, &MongooseBackend::serverStarted); 14 | connect(m_Private, &MongooseBackendPrivate::serverStopped, 15 | this, &MongooseBackend::serverStopped); 16 | connect(m_Private, &MongooseBackendPrivate::error, 17 | this, &MongooseBackend::error); 18 | connect(m_Private, &MongooseBackendPrivate::mntPoint, 19 | this, &MongooseBackend::mountPoint); 20 | connect(m_Private, &MongooseBackendPrivate::mountPointAdded, 21 | this, &MongooseBackend::mountPointAdded); 22 | connect(m_Private, &MongooseBackendPrivate::mountPointRemoved, 23 | this, &MongooseBackend::mountPointRemoved); 24 | connect(m_Private, &MongooseBackendPrivate::mountPointAddError, 25 | this, &MongooseBackend::mountPointAddError); 26 | 27 | } 28 | 29 | MongooseBackend::~MongooseBackend() { 30 | m_Private->deleteLater(); 31 | m_Thread.quit(); 32 | m_Thread.wait(); 33 | } 34 | 35 | void MongooseBackend::toggleServer() { 36 | getMethod(m_Private, "toggleServer(void)").invoke(m_Private, Qt::QueuedConnection); 37 | } 38 | 39 | void MongooseBackend::addMountPoint(QString mountPoint, QUrl loc) { 40 | getMethod(m_Private, "addMountPoint(QString,QUrl)") 41 | .invoke(m_Private, Qt::QueuedConnection, Q_ARG(QString, mountPoint), 42 | Q_ARG(QUrl, loc)); 43 | } 44 | 45 | void MongooseBackend::removeMountPoint(QString mountPoint) { 46 | getMethod(m_Private, "removeMountPoint(QString)") 47 | .invoke(m_Private, Qt::QueuedConnection, Q_ARG(QString, mountPoint)); 48 | } 49 | 50 | void MongooseBackend::getAllMountPoints() { 51 | getMethod(m_Private, "getAllMountPoints(void)").invoke(m_Private, Qt::QueuedConnection); 52 | } 53 | -------------------------------------------------------------------------------- /src/MongooseBackendPrivate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #include 15 | #include 16 | 17 | static void ev_handler(struct mg_connection *c, int ev, void *p) { 18 | if (ev == MG_EV_HTTP_REQUEST) { 19 | struct http_message *hm = (struct http_message *) p; 20 | char *uri = (char*)calloc(hm->uri.len + 1, sizeof *uri); 21 | MongooseBackendPrivate *obj = qobject_cast((QObject*)c->user_data); 22 | if(!uri || !obj) { 23 | // send internal server error in case 24 | // we have some trouble allocating space or 25 | // the user data is not our backend object 26 | mg_http_send_error(c, 500, NULL); 27 | return; 28 | } 29 | strncpy(uri, hm->uri.p, hm->uri.len); 30 | 31 | struct mg_serve_http_opts opts; 32 | memset(&opts, 0, sizeof(opts)); // Reset all options to defaults 33 | 34 | 35 | // Set original uri length to zero for default behaviour of 36 | // http serve 37 | c->orig_uri = NULL; 38 | 39 | // Now go through the mount points and 40 | // redirect. 41 | QStringList mountPoints = (obj->m_MountPoints).keys(); 42 | bool mountPointServed = false; 43 | for(QString mountPoint : mountPoints) { 44 | QByteArray bArray = mountPoint.toLatin1(); 45 | const char *mnt = bArray.constData(); 46 | auto len = bArray.size(); 47 | 48 | if(!qstrncmp(uri, mnt, len)) { 49 | // Now we want to change the uri in the http message 50 | // avoiding the mount point name because its 51 | // just a pesudo 52 | 53 | // Before we override the original uri we need to 54 | // store it in the connection struct for later use. 55 | 56 | // We also need to avoid this step for KODI HTTP clients. 57 | // Kodi seems to avoid listing of stuff which have absolute links. 58 | // Don't know why, so we have to check if the user agent is Kodi, 59 | // if so then we avoid making a absolute link. 60 | // Obviously, this will not work when Kodi is not sending user-agents 61 | // but I've never seen a request from Kodi without a user-agent so 62 | // it's our best bet. 63 | // Side Note: 64 | // if c->orig_uri is NULL then the directory listing href simply list the contents 65 | // without the mount point. 66 | // (i.e) /Anime/Erased becomes /Erased 67 | // 68 | // This makes it impossible for browsers to go through but strangely, Kodi seems to go through 69 | // only when the link is in the above mentioned format. 70 | bool isKodi = false; 71 | for(int i = 0; i < MG_MAX_HTTP_HEADERS ; ++i) { 72 | mg_str name = hm->header_names[i]; 73 | mg_str value = hm->header_values[i]; 74 | if(name.len == 0) { /* indicates the last header in the list(citation needed). */ 75 | break; 76 | } 77 | 78 | if(!qstrncmp(name.p, "User-Agent", name.len)) { // Only look for User-Agent 79 | if(strstr(value.p, "Kodi")) { // We just need Kodi in the user-agent 80 | isKodi = true; 81 | } else { 82 | break; // We have no business anymore. 83 | } 84 | } 85 | } 86 | 87 | // if(isKodi){ 88 | // qDebug() << "Kodi client detected, will be avoid using absolute href."; 89 | // } 90 | 91 | if(!isKodi) { 92 | c->orig_uri = (char *)calloc(hm->uri.len + 1, sizeof(char)); 93 | if(!c->orig_uri) { 94 | mg_http_send_error(c, 500, NULL); 95 | free(uri); 96 | return; 97 | } 98 | strncpy(c->orig_uri, hm->uri.p, hm->uri.len); 99 | } 100 | if(hm->uri.len == len) { // No files directly requested 101 | memset(&hm->uri.p + 1, 0, hm->uri.len - 1); 102 | hm->uri.len = 1; 103 | } else if(hm->uri.len > len) { 104 | char *past_mnt_point = (char*) 105 | calloc(hm->uri.len - len + 1, sizeof(char)); 106 | if(!past_mnt_point) { 107 | mg_http_send_error(c, 500, NULL); 108 | free(c->orig_uri); 109 | free(uri); 110 | c->orig_uri = NULL; 111 | return; 112 | } 113 | strncpy(past_mnt_point, hm->uri.p + len, hm->uri.len - len); 114 | char *p = past_mnt_point; 115 | for(int iter = 0; iter < hm->uri.len ; ++iter) { 116 | if(iter > hm->uri.len - len) { 117 | *(((char*)hm->uri.p) + iter) = '\0'; 118 | continue; 119 | } 120 | *(((char*)hm->uri.p) + iter) = *p++; 121 | } 122 | hm->uri.len = strlen(past_mnt_point); 123 | free(past_mnt_point); 124 | } 125 | 126 | QString localFile = (obj->m_MountPoints).value(mountPoint).toString(); 127 | 128 | QByteArray localFileByteArray = localFile.toLatin1(); 129 | char *root = (char*)calloc(localFileByteArray.size() + 1, sizeof *root); 130 | strncpy(root, localFileByteArray.constData(), localFileByteArray.size()); 131 | 132 | opts.document_root = root; 133 | 134 | // qDebug() << "Serving Mount Point: " << root; 135 | mg_serve_http(c, hm, opts); 136 | mountPointServed = true; 137 | if(c->orig_uri) { 138 | free(c->orig_uri); 139 | c->orig_uri = NULL; 140 | } 141 | free(root); 142 | break; 143 | } 144 | 145 | } 146 | 147 | free(uri); 148 | if(!mountPointServed) { 149 | QFile file; 150 | file.setFileName(":/index_a.html"); 151 | if(!file.open(QIODevice::ReadOnly)) { 152 | mg_http_send_error(c, 500, NULL); 153 | return; 154 | } 155 | 156 | mg_printf(c, "HTTP/1.1 200 OK\r\n\r\n"); 157 | 158 | while(!file.atEnd()) { 159 | QByteArray data = file.read(1024); 160 | mg_printf(c, "%.*s", data.size(), data.constData()); 161 | } 162 | file.close(); 163 | 164 | for(QString mountPoint : mountPoints) { 165 | mg_printf(c, 166 | "", 168 | mountPoint.toStdString().c_str(), 169 | mountPoint.toStdString().c_str()); 170 | } 171 | 172 | file.setFileName(":/index_b.html"); 173 | if(!file.open(QIODevice::ReadOnly)) { 174 | mg_http_send_error(c, 500, NULL); 175 | return; 176 | } 177 | 178 | while(!file.atEnd()) { 179 | QByteArray data = file.read(1024); 180 | mg_printf(c, "%.*s", data.size(), data.constData()); 181 | } 182 | file.close(); 183 | c->flags |= MG_F_SEND_AND_CLOSE; 184 | } 185 | } 186 | } 187 | 188 | MongooseBackendPrivate::MongooseBackendPrivate(QObject *parent) : 189 | QObject(parent), 190 | b_StopRequested(false), 191 | b_Running(false) { 192 | // Get all mount points from settings 193 | // Workaround for https://bugreports.qt.io/browse/QTBUG-48313 194 | QByteArray json = m_Settings.value("MountPoints").toByteArray(); 195 | if(!json.isEmpty()) { 196 | m_MountPoints = (QJsonDocument::fromJson(json)).object(); 197 | } 198 | } 199 | 200 | MongooseBackendPrivate::~MongooseBackendPrivate() { 201 | if(b_Running) 202 | stopServer(); 203 | } 204 | 205 | void MongooseBackendPrivate::toggleServer() { 206 | if(b_Running) { 207 | stopServer(); 208 | return; 209 | } 210 | startServer(); 211 | } 212 | 213 | void MongooseBackendPrivate::addMountPoint(QString mountPoint, QUrl local) { 214 | mountPoint.prepend("/"); 215 | if(!m_MountPoints.contains(mountPoint)) { 216 | m_MountPoints.insert(mountPoint, local.toLocalFile()); 217 | QJsonDocument doc(m_MountPoints); 218 | m_Settings.setValue("MountPoints", doc.toJson()); 219 | emit mountPointAdded(mountPoint); 220 | } 221 | } 222 | 223 | void MongooseBackendPrivate::removeMountPoint(QString mountPoint) { 224 | if(m_MountPoints.contains(mountPoint)) { 225 | m_MountPoints.remove(mountPoint); 226 | QJsonDocument doc(m_MountPoints); 227 | m_Settings.setValue("MountPoints", doc.toJson()); 228 | emit mountPointRemoved(mountPoint); 229 | } 230 | } 231 | 232 | 233 | void MongooseBackendPrivate::startServer() { 234 | struct mg_mgr mgr; 235 | if(b_Running) { 236 | emit serverStarted(m_Address); 237 | return; 238 | } 239 | 240 | // Get local ip address 241 | QList list = QNetworkInterface::allAddresses(); 242 | for(int nIter=0; nIteruser_data = (void*)this; 270 | mg_set_protocol_http_websocket(c); 271 | 272 | m_Address = address; 273 | b_Running = true; 274 | emit serverStarted(m_Address); 275 | 276 | for(;;) { 277 | mg_mgr_poll(&mgr, 200); 278 | QCoreApplication::processEvents(); 279 | if(b_StopRequested) { 280 | b_StopRequested = b_Running = false; 281 | break; 282 | } 283 | } 284 | 285 | emit serverStopped(); 286 | mg_mgr_free(&mgr); 287 | } 288 | 289 | void MongooseBackendPrivate::stopServer() { 290 | b_StopRequested = true; 291 | } 292 | 293 | void MongooseBackendPrivate::getAllMountPoints() { 294 | QStringList mountPoints = m_MountPoints.keys(); 295 | for(QString mountPoint : mountPoints) { 296 | emit mntPoint(mountPoint); 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) { 10 | QApplication app(argc, argv); 11 | QApplication::setOrganizationName("ShareMyHost"); 12 | QApplication::setApplicationName("ShareMyHost"); 13 | 14 | qmlRegisterType("Core.MongooseBackend", 1, 0, "MongooseBackend"); 15 | qmlRegisterType("Core.Clipper", 1, 0, "Clipper"); 16 | 17 | app.setWindowIcon(QIcon(QString::fromUtf8(":/logo.png"))); 18 | QQuickStyle::setStyle("Material"); // Use Google Material Design 19 | QQmlApplicationEngine engine; 20 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 21 | return app.exec(); 22 | } 23 | --------------------------------------------------------------------------------