14 #include <Wt/WFileResource>
16 #include <gdwtcore/gdToolbar.h>
25 void* hndl = dlopen(
"libarchive.so", RTLD_NOW | RTLD_GLOBAL);
27 fprintf(stderr,
"cannot load libarchive.so shared library! %s\n", dlerror());
43 string path = WApplication::instance()->internalPath();
46 m_cb =
new WCheckBox(
"Allow in zip ? ");
47 if ( prop ==
"true" ) {
49 m_cb->setCheckState(Wt::Checked);
52 m_cb->setCheckState(Wt::Unchecked);
59 string path = WApplication::instance()->internalPath();
69 m_errmsg =
"Could not create archive";
107 gdToolbarItem* pTbItem =
contentButtonsBar()->addToolbarItem(wApp->theme()->resourcesUrl() +
"wittyshare/Icons/compress.png",
"",
"Compress this directory");
115 m_dialog->setTitleBarEnabled(
false);
116 m_dialog->rejectWhenEscapePressed();
120 m_zip =
new WRadioButton(
"Zip", m_container);
121 m_tar =
new WRadioButton(
"Tar", m_container);
128 m_fileType->addButton(m_all);
129 m_fileType->addButton(
m_fonly);
130 m_fileType->setCheckedButton(
m_fonly);
131 new Wt::WBreak(
m_dialog->contents());
158 m_label =
new WLabel(
"Creating archive...\n Please Wait",
m_dialog->contents());
159 m_loading =
new WLabel(
new WImage(WApplication::instance()->resourcesUrl() +
"loading.gif"),
m_dialog->contents());
169 StandardButton result = WMessageBox::show(
"Error",
m_errmsg, Ok );
184 if (!accessTree.get()) {
185 LOG(
ERROR) <<
"WsModZip::handleFiles() AccessRoot is NULL";
189 string path = WApplication::instance()->internalPath();
192 NodePtr tmp = accessTree.get()->eatPath(path);
195 vector<NodePtr> contents = tmp.get()->getAll();
196 vector<NodePtr>::iterator it;
197 int size = contents.size();
200 for (it = contents.begin(); it != contents.end(); ++it) {
202 if ((*it).get()->isRegularFile()) {
204 if ((*it).get()->getProperties().get()->get(
WSMODZIP,
ALLOW_ZIP,
"true") ==
"true")
205 if ((*it).get()->getSize() > 0)
218 if (!accessTree.get()) {
222 string path = WApplication::instance()->internalPath();
225 NodePtr tmp = accessTree.get()->eatPath(path);
228 vector<NodePtr> contents = tmp.get()->getAll();
229 vector<NodePtr>::iterator it;
230 int size = contents.size();
233 for (it = contents.begin(); it != contents.end(); ++it) {
235 if ((*it)->isRegularFile()) {
237 if ((*it).get()->getProperties().get()->get(
WSMODZIP,
ALLOW_ZIP,
"true") ==
"true")
239 if ((*it).get()->getSize() > 0)
257 if (!accessTree.get()) {
258 LOG(
ERROR) <<
"WsModZip::handleFiles() AccessRoot is NULL";
263 NodePtr tmp = accessTree.get()->eatPath(path);
266 vector<NodePtr> contents = tmp.get()->getAll();
268 vector<NodePtr>::iterator it;
270 for (it = contents.begin(); it != contents.end(); ++it) {
283 return "WsModZip wittyShare module";
291 struct archive* disk;
292 struct archive_entry* entry;
297 char* currentDir = get_current_dir_name();
299 const char* temp = rootPath.c_str();
300 char* newDir =
new char[rootPath.size() + 1]();
301 strncpy(newDir, temp, rootPath.size());
302 newDir[rootPath.size()] =
'\0';
304 if (chdir(newDir) != 0) {
305 LOG(
ERROR) <<
"WsModZip :: Could not chdir to " << newDir;
310 a = archive_write_new();
314 archive_write_set_compression_compress(a);
315 archive_write_set_compression_bzip2(a);
316 archive_write_set_format_ustar(a);
318 }
else if (format ==
ZIP) {
320 archive_write_set_compression_compress(a);
321 archive_write_set_format_zip(a);
324 LOG(
ERROR) <<
"WsModZip :: Unknown file format ";
328 string filenameTmp = wsApp->getUserTmpPath() + string(basename(tmpnam(NULL))) + ext;
330 archive_write_open_file(a, filenameTmp.c_str());
331 disk = archive_read_disk_new();
332 archive_read_disk_set_standard_lookup(disk);
339 for (
int i = 0; i <
m_paths.size(); ++i) {
340 struct archive* disk = archive_read_disk_new();
347 r = archive_read_disk_open(disk, str.c_str());
348 if (r != ARCHIVE_OK) {
349 LOG(
ERROR) <<
"WsModZip :: Cannot read file";
355 entry = archive_entry_new();
356 r = archive_read_next_header2(disk, entry);
357 if (r == ARCHIVE_EOF)
359 if (r != ARCHIVE_OK) {
360 LOG(
ERROR) <<
"WsModZip :: Archive error";
363 archive_read_disk_descend(disk);
364 LOG(
DEBUG) <<
"WsModZip :: Writing archive header";
365 r = archive_write_header(a, entry);
366 if (r < ARCHIVE_OK) {
369 if (r == ARCHIVE_FATAL) {
370 LOG(
ERROR) <<
"WsModZip :: Archive fatal";
373 if (r > ARCHIVE_FAILED) {
374 fd = open(archive_entry_sourcepath(entry), O_RDONLY);
375 len = read(fd, buff,
sizeof(buff));
377 archive_write_data(a, buff, len);
378 len = read(fd, buff,
sizeof(buff));
382 LOG(
ERROR) <<
"WsModZip :: Archive failed";
383 archive_entry_free(entry);
385 archive_read_close(disk);
386 archive_read_free(disk);
388 archive_write_close(a);
389 archive_write_free(a);
390 if (chdir(currentDir) != 0)
391 LOG(
DEBUG) <<
"WsModZip :: Could not chdir to " << currentDir;
392 boost::replace_all(filenameTmp, wsApp->docRoot(),
"");
393 WApplication::instance()->redirect(filenameTmp);
WsModulesLoader & WsModules()
boost::shared_ptr< WsAbstractNode > NodePtr
std::string pathWithoutPrefix(const std::string &path)
int saveProperty(const std::string &path, const std::string §ion, const std::string &attr, const std::string &val)
sets one property of the node and save it on disk.
std::string getProperty(const std::string &path, const std::string §ion, const string &attr, const std::string &def)
returns one property of a node If the property does not exist, a empty string is returned.
Wt::WButtonGroup * m_archiveType
static WsApplication * wsInstance()
Facility function to access the application object.
Reprensents a File on disk.
Wt::WPushButton * m_cancel
void appendToZip(const string &path)
Append the file to the zip.
Wt::WWidget * buildMenuBar()
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
Wt::WGroupBox * m_container
WsContentButtonsBar * contentButtonsBar()
WittyShare provide a container to add some buttons like export page in pdf, ..., This function allow ...
Interface that provides differents methods for accessing the FsTree as well as other features...
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
virtual void destroyContentsMenuBar()
std::string description() const
Return the description of the module.
void appendSubDir(const string &path)
A.
Wt::WRadioButton * m_fonly
virtual void destroyContentsMenuBar()
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.
int writeAndCloseZip(int format)
Wt::WButtonGroup * m_fileType
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Wt::WGroupBox * m_container2