Use separate arguments for a remote root and do not use dav or webdav in the server...
authorallexzander <blackslayer4@gmail.com>
Mon, 2 Aug 2021 12:08:30 +0000 (15:08 +0300)
committerallexzander <blackslayer4@gmail.com>
Fri, 20 Aug 2021 10:30:35 +0000 (13:30 +0300)
Signed-off-by: allexzander <blackslayer4@gmail.com>
src/cmd/cmd.cpp
src/libsync/account.cpp
src/libsync/account.h

index 39f4533de536bb34c391a3ed2d86c1e4de4c0e7f..5b1de5e64806ce27bb21aeb41bae6fe710cec267 100644 (file)
@@ -66,6 +66,7 @@ struct CmdOptions
 {
     QString source_dir;
     QString target_url;
+    QString remotePath = QStringLiteral("/");
     QString config_directory;
     QString user;
     QString password;
@@ -193,6 +194,7 @@ void help()
     std::cout << "  -h                     Sync hidden files, do not ignore them" << std::endl;
     std::cout << "  --version, -v          Display version and exit" << std::endl;
     std::cout << "  --logdebug             More verbose logging" << std::endl;
+    std::cout << "  --path                 Path to a folder on a remote server" << std::endl;
     std::cout << "" << std::endl;
     exit(0);
 }
@@ -269,7 +271,10 @@ void parseOptions(const QStringList &app_args, CmdOptions *options)
         } else if (option == "--logdebug") {
             Logger::instance()->setLogFile("-");
             Logger::instance()->setLogDebug(true);
-        } else {
+        } else if (option == "--path" && !it.peekNext().startsWith("-")) {
+            options->remotePath = it.next();
+        }
+        else {
             help();
         }
     }
@@ -339,16 +344,20 @@ int main(int argc, char **argv)
         qFatal("Could not initialize account!");
         return EXIT_FAILURE;
     }
-    // check if the webDAV path was added to the url and append if not.
-    if (!options.target_url.endsWith("/")) {
-        options.target_url.append("/");
+
+    if (options.target_url.contains("/webdav", Qt::CaseInsensitive) || options.target_url.contains("/dav", Qt::CaseInsensitive)) {
+        qWarning("Dav or webdav in server URL.");
+        std::cerr << "Error! Please specify only the base URL of your host with username and password. Example:" << std::endl
+                  << "http(s)://username:password@cloud.example.com" << std::endl;
+        return EXIT_FAILURE;
     }
 
-    if (!options.target_url.contains(account->davPath())) {
-        options.target_url.append(account->davPath());
+    // check if the dav path was added to the url and append if not.
+    if (!options.target_url.endsWith("/")) {
+        options.target_url.append("/");
     }
 
-    QUrl url = QUrl::fromUserInput(options.target_url);
+    QUrl hostUrl = QUrl::fromUserInput(options.target_url);
 
     // Order of retrieval attempt (later attempts override earlier ones):
     // 1. From URL
@@ -356,8 +365,8 @@ int main(int argc, char **argv)
     // 3. From netrc (if enabled)
     // 4. From prompt (if interactive)
 
-    QString user = url.userName();
-    QString password = url.password();
+    QString user = hostUrl.userName();
+    QString password = hostUrl.password();
 
     if (!options.user.isEmpty()) {
         user = options.user;
@@ -370,7 +379,7 @@ int main(int argc, char **argv)
     if (options.useNetrc) {
         NetrcParser parser;
         if (parser.parse()) {
-            NetrcParser::LoginPair pair = parser.find(url.host());
+            NetrcParser::LoginPair pair = parser.find(hostUrl.host());
             user = pair.first;
             password = pair.second;
         }
@@ -388,24 +397,15 @@ int main(int argc, char **argv)
         }
     }
 
-    // take the unmodified url to pass to csync_create()
-    QByteArray remUrl = options.target_url.toUtf8();
-
     // Find the folder and the original owncloud url
-    QStringList splitted = url.path().split("/" + account->davPath());
-    url.setPath(splitted.value(0));
 
-    url.setScheme(url.scheme().replace("owncloud", "http"));
+    hostUrl.setScheme(hostUrl.scheme().replace("owncloud", "http"));
 
-    QUrl credentialFreeUrl = url;
+    QUrl credentialFreeUrl = hostUrl;
     credentialFreeUrl.setUserName(QString());
     credentialFreeUrl.setPassword(QString());
 
-    // Remote folders typically start with a / and don't end with one
-    QString folder = "/" + splitted.value(1);
-    if (folder.endsWith("/") && folder != "/") {
-        folder.chop(1);
-    }
+    const QString folder = options.remotePath;
 
     if (!options.proxy.isNull()) {
         QString host;
@@ -442,7 +442,7 @@ int main(int argc, char **argv)
     }
 #endif
 
-    account->setUrl(url);
+    account->setUrl(hostUrl);
     account->setSslErrorHandler(sslErrorHandler);
 
     QEventLoop loop;
index 52a8c1c4d52ca94eb808ccfcc2f980b8234d02b6..02bcbb39a83e0bb8039ea5cb46e2327436ecc300 100644 (file)
@@ -86,7 +86,7 @@ Account::~Account() = default;
 
 QString Account::davPath() const
 {
-    return QLatin1String("/remote.php/dav/files/") + davUser() + QLatin1Char('/');
+    return davPathBase() + QLatin1Char('/') + davUser() + QLatin1Char('/');
 }
 
 void Account::setSharedThis(AccountPtr sharedThis)
@@ -94,6 +94,11 @@ void Account::setSharedThis(AccountPtr sharedThis)
     _sharedThis = sharedThis.toWeakRef();
 }
 
+QString Account::davPathBase()
+{
+    return QStringLiteral("/remote.php/dav/files");
+}
+
 AccountPtr Account::sharedFromThis()
 {
     return _sharedThis.toStrongRef();
index 1b4e2d2e447700b3e73be35e1d7ab416d3c5edb2..803774685677928212e3f4ed0a4fd92cdbf49c7a 100644 (file)
@@ -296,6 +296,8 @@ private:
     Account(QObject *parent = nullptr);
     void setSharedThis(AccountPtr sharedThis);
 
+    static QString davPathBase();
+
     QWeakPointer<Account> _sharedThis;
     QString _id;
     QString _davUser;