Compare commits
6 Commits
2d1eed4289
...
v2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| a2eefe411c | |||
| f1b94cbfd8 | |||
| 1b44dd10db | |||
| 1fef08bc55 | |||
| 4dc9ea3acb | |||
| 3db83f14fe |
58
README.md
58
README.md
@@ -1,3 +1,57 @@
|
|||||||
# nextcloud-samba-sync
|
# Nextcloud-Samba Sync
|
||||||
|
|
||||||
A Nextcloud-Samba File scanner system
|
## Pre installation
|
||||||
|
|
||||||
|
- Install `samba` and `vfs-modules`
|
||||||
|
```
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install samba samba-vfs-modules
|
||||||
|
```
|
||||||
|
- Create shares. The example is in `configs` folder
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Download a `ncsambawatcher.zip` file from a release above 2.0
|
||||||
|
2. Extract somewhere on your server (I recommend your user folder)
|
||||||
|
3. Make sure the samba configuration file is correct (See `configs/smb.24.04.conf`)
|
||||||
|
4. Configurate the `ncsambawatcher.config` file
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>Name</td>
|
||||||
|
<td>Required</td>
|
||||||
|
<td>Description</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><code>NEXTCLOUD_CONTAINER_NAME</code></td>
|
||||||
|
<td>Yes</td>
|
||||||
|
<td>The nextcloud's docker container name</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>NEXTCLOUD_USERS</code></td>
|
||||||
|
<td>No</td>
|
||||||
|
<td>Usernames separated with spaces</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>NEXTCLOUD_GROUPFOLDER_IDS</code></td>
|
||||||
|
<td>No</td>
|
||||||
|
<td>Groupfolder ids separated with spaces (only the number)</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
Example 1:
|
||||||
|
```
|
||||||
|
NEXTCLOUD_CONTAINER_NAME=nextcloud
|
||||||
|
```
|
||||||
|
Example 2: (See `configs/ncsambawatcher.config.default`)
|
||||||
|
|
||||||
|
5. Run the `init.sh` script
|
||||||
|
6. You're done :)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- You don't need to add users and groupfolders to the configfile because the program add automaticly from the logfile
|
||||||
|
- For a user (not groupfolder): The username and the samba share name **MUST BE THE SAME**
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
NEXTCLOUD_CONTAINER_NAME=nextcloud
|
NEXTCLOUD_CONTAINER_NAME=nextcloud
|
||||||
|
NEXTCLOUD_USERS=username1 username2 username3
|
||||||
|
NEXTCLOUD_GROUPFOLDER_IDS=1 2 3 4
|
||||||
@@ -43,6 +43,12 @@ public:
|
|||||||
configs.insert(std::make_pair(splited.at(0), splited.at(1)));
|
configs.insert(std::make_pair(splited.at(0), splited.at(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (configs.count("NEXTCLOUD_CONTAINER_NAME") == 0)
|
||||||
|
{
|
||||||
|
std::cerr << "The container's name not added" << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Config file loaded successfuly" << std::endl;
|
std::cout << "Config file loaded successfuly" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <unordered_set>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -68,7 +69,7 @@ void scannerThreadFunc()
|
|||||||
cv.wait(lock, []
|
cv.wait(lock, []
|
||||||
{ return manager.isAnybodyFlagged(); });
|
{ return manager.isAnybodyFlagged(); });
|
||||||
|
|
||||||
std::set<std::string> scanUsers = manager.getFlaggedUsers();
|
std::unordered_set<std::string> scanUsers = manager.getFlaggedUsers();
|
||||||
manager.unflagAllUsers();
|
manager.unflagAllUsers();
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@@ -85,6 +86,7 @@ void scannerThreadFunc()
|
|||||||
else if (child == 0) // child
|
else if (child == 0) // child
|
||||||
{
|
{
|
||||||
std::string cmd = userManager::getScanCommandFromUser(user, cfm);
|
std::string cmd = userManager::getScanCommandFromUser(user, cfm);
|
||||||
|
std::cout << "Run command: " << cmd << std::endl;
|
||||||
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
|
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char *>(nullptr));
|
||||||
std::cerr << "Scan failed" << std::endl;
|
std::cerr << "Scan failed" << std::endl;
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
@@ -106,6 +108,9 @@ void scannerThreadFunc()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
manager.tryAddUsersFromConfig(cfm);
|
||||||
|
manager.tryAddGroupIDsFromConfig(cfm);
|
||||||
|
|
||||||
std::thread readingThread(readingThreadFunc);
|
std::thread readingThread(readingThreadFunc);
|
||||||
std::thread scannerThread(scannerThreadFunc);
|
std::thread scannerThread(scannerThreadFunc);
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <unordered_set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <stdexcept>
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "configfilemanager.h"
|
#include "configfilemanager.h"
|
||||||
|
|
||||||
@@ -25,28 +26,30 @@ public:
|
|||||||
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
|
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUser(std::string &user)
|
void addUser(const std::string &user)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
if (users.count(user) == 0)
|
if (users.count(user) == 0)
|
||||||
{
|
{
|
||||||
users[user] = false;
|
users[user] = false;
|
||||||
|
std::cout << "User added the list: " << user << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeUser(std::string &user)
|
void removeUser(const std::string &user)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
users.erase(user);
|
users.erase(user);
|
||||||
|
std::cout << "User removed the list: " << user << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isContains(std::string &user)
|
bool isContains(const std::string &user)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
return users.count(user) == 1;
|
return users.count(user) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUserFlagged(std::string &user)
|
void setUserFlagged(const std::string &user)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
if (users.count(user) == 1)
|
if (users.count(user) == 1)
|
||||||
@@ -55,7 +58,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUserUnflagged(std::string &user)
|
void setUserUnflagged(const std::string &user)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
if (users.count(user) == 1)
|
if (users.count(user) == 1)
|
||||||
@@ -73,9 +76,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> getUsers()
|
std::unordered_set<std::string> getUsers()
|
||||||
{
|
{
|
||||||
std::set<std::string> ret;
|
std::unordered_set<std::string> ret;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
|
|
||||||
@@ -87,9 +90,9 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> getFlaggedUsers()
|
std::unordered_set<std::string> getFlaggedUsers()
|
||||||
{
|
{
|
||||||
std::set<std::string> ret;
|
std::unordered_set<std::string> ret;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mtx);
|
std::lock_guard<std::mutex> lock(mtx);
|
||||||
|
|
||||||
@@ -116,6 +119,40 @@ public:
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tryAddUsersFromConfig(configfilemanager &cfm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::vector<std::string> alluser = splitString(cfm.at("NEXTCLOUD_USERS"), ' ');
|
||||||
|
|
||||||
|
for (const std::string& user : alluser)
|
||||||
|
{
|
||||||
|
addUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << "No user added from configuration file" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tryAddGroupIDsFromConfig(configfilemanager &cfm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::vector<std::string> allids = splitString(cfm.at("NEXTCLOUD_GROUPFOLDER_IDS"), ' ');
|
||||||
|
|
||||||
|
for (const std::string& id : allids)
|
||||||
|
{
|
||||||
|
addUser("__groupfolders/" + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << "No groupfolder added from configuration file" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _USERMAN_H
|
#endif // _USERMAN_H
|
||||||
Reference in New Issue
Block a user