pondersource / nc-sciencemesh

ScienceMesh application for NextCloud
MIT License
0 stars 5 forks source link

Undefined index: resourceId at addReceivedShare #333

Closed MahdiBaghbani closed 1 year ago

MahdiBaghbani commented 1 year ago

when receiving a share from Reva we get this error:

{
  "reqId": "ryDAnPwFwkcnT0KqWFOK",
  "level": 3,
  "time": "2023-05-26T19:51:07+00:00",
  "remoteAddr": "172.19.0.8",
  "user": "--",
  "app": "PHP",
  "method": "POST",
  "url": "/index.php/apps/sciencemesh/~marie/api/ocm/addReceivedShare",
  "message": "Undefined index: resourceId at /var/www/html/apps/sciencemesh/lib/Controller/RevaController.php#957"
}

code on the Nextcloud app: https://github.com/pondersource/nc-sciencemesh/blob/298602146718caa4c06956c4ab401cbbd2e7c277/lib/Controller/OcmController.php#L491 code on the ownCloud app: https://github.com/pondersource/nc-sciencemesh/blob/04fdbf343dbf05d591c58d86b3a98f159c9bf188/lib/Controller/RevaController.php#L957

sender side revanc1: Sending OCM /shares POST to https://revaoc2.docker/ocm/shares:

{
  "shareWith": "marie@revaoc2.docker",
  "name": "sdfs",
  "description": "",
  "providerId": "\"3\"",
  "owner": "einstein@revanc1.docker",
  "sender": "einstein@revanc1.docker",
  "ownerDisplayName": "",
  "senderDisplayName": "einstein",
  "shareType": "user",
  "expiration": 0,
  "resourceType": "folder",
  "protocol": {
    "name": "multi",
    "options": {},
    "webapp": {
      "uriTemplate": "https://cernbox.cern.ch/external/sciencemesh/fcpink78dF4u9inYchtpKOyUk5KhZiRi{relative-path-to-shared-resource}",
      "viewMode": ""
    },
    "webdav": {
      "sharedSecret": "fcpink78dF4u9inYchtpKOyUk5KhZiRi",
      "permissions": [
        "read"
      ],
      "url": "https://nc1.docker/remote.php/dav/ocm/fcpink78dF4u9inYchtpKOyUk5KhZiRi"
    }
  }
}

receiver side revanc2: am.do https://oc2.docker/index.php/apps/sciencemesh/~marie/api/ocm/addReceivedShare

{
  "name": "sdfs",
  "remoteShareId": "\"3\"",
  "grantee": {
    "type": "GRANTEE_TYPE_USER",
    "userId": {
      "idp": "https://revaoc2.docker/",
      "opaqueId": "marie"
    }
  },
  "owner": {
    "idp": "revanc1.docker",
    "opaqueId": "einstein",
    "type": "USER_TYPE_FEDERATED"
  },
  "creator": {
    "idp": "revanc1.docker",
    "opaqueId": "einstein",
    "type": "USER_TYPE_FEDERATED"
  },
  "ctime": {
    "seconds": "1685130667"
  },
  "mtime": {
    "seconds": "1685130667"
  },
  "shareType": "SHARE_TYPE_USER",
  "protocols": [
    {
      "webappOptions": {
        "uriTemplate": "https://cernbox.cern.ch/external/sciencemesh/fcpink78dF4u9inYchtpKOyUk5KhZiRi{relative-path-to-shared-resource}"
      }
    },
    {
      "webdavOptions": {
        "sharedSecret": "fcpink78dF4u9inYchtpKOyUk5KhZiRi",
        "permissions": {
          "permissions": {
            "getPath": true,
            "initiateFileDownload": true,
            "listContainer": true,
            "stat": true
          }
        },
        "uri": "https://nc1.docker/remote.php/dav/ocm/fcpink78dF4u9inYchtpKOyUk5KhZiRi"
      }
    }
  ],
  "state": "SHARE_STATE_PENDING",
  "resourceType": "RESOURCE_TYPE_CONTAINER"
}

we have 3 opaqueId, which is unclear which one should go on remote_id.

well, we already are using owner opaqueId in owner section, so only 2 are left. https://github.com/pondersource/nc-sciencemesh/blob/298602146718caa4c06956c4ab401cbbd2e7c277/lib/Controller/OcmController.php#L495

@michielbdejong I don't see any providerId 😞

however, my guess is we should use "remoteShareId" as a value for remote_id".

because it is consistent with the ids of share in oc_share table on the remote side. nc1 mariadb entries as sender:

MariaDB [efss]> select * from oc_share;
+----+------------+----------------------+----------+-----------+---------------+--------+-----------+-------------+-------------+-------------+-------------+-------------+------------+----------+------------+----------------------------------+-----------+------------+------------------+------+---------------+-------+------------+--------------------------+
| id | share_type | share_with           | password | uid_owner | uid_initiator | parent | item_type | item_source | item_target | file_source | file_target | permissions | stime      | accepted | expiration | token                            | mail_send | share_name | password_by_talk | note | hide_download | label | attributes | password_expiration_time |
+----+------------+----------------------+----------+-----------+---------------+--------+-----------+-------------+-------------+-------------+-------------+-------------+------------+----------+------------+----------------------------------+-----------+------------+------------------+------+---------------+-------+------------+--------------------------+
|  1 |          6 | marie@revaoc2.docker | NULL     | einstein  | einstein      |   NULL | folder    | 36          | NULL        |          36 |             |           1 | 1685128941 |        0 | NULL       | am1cZJCl7zLvtI3dVoXfsj844J8TgEQj |         0 | NULL       |                0 | NULL |             0 | NULL  | NULL       | NULL                     |
|  2 |          6 | marie@revaoc2.docker | NULL     | einstein  | einstein      |   NULL | folder    | 38          | NULL        |          38 |             |           1 | 1685130410 |        0 | NULL       | amJM7Fu1bsvnm7TG0YkcA8AEh6bXCkKC |         0 | NULL       |                0 | NULL |             0 | NULL  | NULL       | NULL                     |
|  3 |          6 | marie@revaoc2.docker | NULL     | einstein  | einstein      |   NULL | folder    | 40          | NULL        |          40 |             |           1 | 1685130667 |        0 | NULL       | fcpink78dF4u9inYchtpKOyUk5KhZiRi |         0 | NULL       |                0 | NULL |             0 | NULL  | NULL       | NULL                     |
+----+------------+----------------------+----------+-----------+---------------+--------+-----------+-------------+-------------+-------------+-------------+-------------+------------+----------+------------+----------------------------------+-----------+------------+------------------+------+---------------+-------+------------+--------------------------+

oc2 mariadb entries as a receiver:

MariaDB [efss]> select * from oc_share_external;
+----+--------------------+-----------+----------------------------------+----------+--------+----------+-------+------------+----------------------------------+----------+----------+
| id | remote             | remote_id | share_token                      | password | name   | owner    | user  | mountpoint | mountpoint_hash                  | accepted | lastscan |
+----+--------------------+-----------+----------------------------------+----------+--------+----------+-------+------------+----------------------------------+----------+----------+
|  1 | https://nc1.docker |           | am1cZJCl7zLvtI3dVoXfsj844J8TgEQj |          | maryam | einstein | marie | /maryam    | 179672a56e485d0b57217f23f071c49c |        1 |     NULL |
|  2 | https://nc1.docker |           | amJM7Fu1bsvnm7TG0YkcA8AEh6bXCkKC |          | bingo  | einstein | marie | /bingo     | 4c1a5dccb8fee4f8026508aa5366337c |        1 |     NULL |
|  3 | https://nc1.docker |           | fcpink78dF4u9inYchtpKOyUk5KhZiRi |          | sdfs   | einstein | marie | /sdfs      | a0f5ce002b7bd2986de6d4fd2c78e1ba |        1 |     NULL |
+----+--------------------+-----------+----------------------------------+----------+--------+----------+-------+------------+----------------------------------+----------+----------+
3 rows in set (0.000 sec)

@mrvahedi68 @michielbdejong @parhamin2010 any ideas?

MahdiBaghbani commented 1 year ago

Possibly a continuation of https://github.com/pondersource/nc-sciencemesh/issues/293 https://github.com/pondersource/nc-sciencemesh/issues/318

MahdiBaghbani commented 1 year ago

With changing the resourceId to 'remoteShareId' the error goes away and we can correctly store the id of the remote share in out database.

MariaDB [efss]> select * from oc_share_external;
+----+--------------------+-----------+----------------------------------+----------+------+----------+-------+------------+----------------------------------+----------+----------+
| id | remote             | remote_id | share_token                      | password | name | owner    | user  | mountpoint | mountpoint_hash                  | accepted | lastscan |
+----+--------------------+-----------+----------------------------------+----------+------+----------+-------+------------+----------------------------------+----------+----------+
|  1 | https://nc1.docker | 1         | O6686bx2Fg8dVDjC22A2pJEPUdxcxhLJ |          | test | einstein | marie | /test      | 4539330648b80f94ef3bf911f6d77ac9 |        1 |     NULL |
+----+--------------------+-----------+----------------------------------+----------+------+----------+-------+------------+----------------------------------+----------+----------+
1 row in set (0.000 sec)
MahdiBaghbani commented 1 year ago

We have another error related to our remote shares, password filed is problematic.

The error we get when accepting a sciencemesh share on ownCloud.

{
  "reqId": "c13nTCjl8qnva6pvaLuk",
  "level": 3,
  "time": "2023-05-28T09:28:24+00:00",
  "remoteAddr": "172.18.0.3",
  "user": "marie",
  "app": "PHP",
  "method": "POST",
  "url": "/index.php/apps/files_sharing/api/externalShares",
  "message": "Undefined index: password at /var/www/html/apps/files_sharing/lib/External/Storage.php#92"
}
MahdiBaghbani commented 1 year ago

The error doesn't happen on Nextcloud, only on ownCloud. it is strange because both of them use the same piece of code to access the password field.

Nextcloud: https://github.com/nextcloud/server/blob/fa23698c23a7ef9380f13c4fe439ff3aa6a9b9b0/apps/files_sharing/lib/External/Storage.php#L99

ownCloud: https://github.com/owncloud/core/blob/c15e21ac72bee56a7062aa77a45c8bf757c72cde/apps/files_sharing/lib/External/Storage.php#L92