Compare commits
4 Commits
2d1eed4289
...
1b44dd10db
| Author | SHA1 | Date | |
|---|---|---|---|
| 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,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);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <set>
|
#include <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)
|
||||||
@@ -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 (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("__groupfolder/" + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (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