dlandon / unassigned.devices

Unassigned Devices plugin for unRAID
Other
85 stars 40 forks source link

Add port settings for smb mount #95

Closed zxrobin01 closed 1 year ago

zxrobin01 commented 1 year ago

For the current version, we can not set port for smb mounts. We can add port entry in samba-mount.cfg

[//xxxx/xxx]
protocol = "SMB"
ip = "xxx"
path = "xxx"
user = "xxx"
domain = ""
port = xxxx
pass = "xxxxx"
share = "xxxx"
mountpoint = "xxxx"
smb_share = "yes"
automount = "yes"

Modify function "do_mount_samba" from "unassigned.devices/include/lib.php" file.


$params = sprintf(get_mount_params($fs, $dev), $ver);
if ($info["port"]) $params .= ",port=" . $info["port"];                    //**<=====Add this line**
dlandon commented 1 year ago

Why do you want to do this? What is the use case?

zxrobin01 commented 1 year ago

Why do you want to do this? What is the use case?

In some situation the global firewall blocked port 445, so I need to use another port for SMB share.

dlandon commented 1 year ago

I assume this is for remote shares. Would this be globally, or on a per share basis?

zxrobin01 commented 1 year ago

I assume this is for remote shares. Would this be globally, or on a per share basis?

In my country almost all network vendors block port 445 for security reason.

dlandon commented 1 year ago

So you are trying to mount a remote share on a server that is at a remote site?

zxrobin01 commented 1 year ago

So you are trying to mount a remote share on a server that is at a remote site?

I'm tring to mount a remote share from my home to my parents home. The two places all have IPV6 access and can reach each other through IPV6. The only problem is that 445 port is blocked.

xlsgs commented 1 year ago

I need Add port settings for smb mount too. can you help me

dlandon commented 1 year ago

You best option is to do port forwarding in your router.

xlsgs commented 1 year ago

The telecom service provider has blocked port 445 and must use other ports to forward, so you need to customize the port.Custom ports increase flexibility in using the software

dlandon commented 1 year ago

You can do port forwarding in your router and get around this problem.

xlsgs commented 1 year ago

Port 445 is disabled on the Internet and can only be used on a local network. Now that the router mapping has been used, the remote SMB after the mapping is need to mounted, so you need to configure a port another not 445. Your plugin cannot configure ports, only mount remote SMB using the 445 default port. Understand?

dlandon commented 1 year ago

I fully understand what you are saying, but it is not a feature I will be adding for the following reasons:

xlsgs commented 1 year ago

ok,thank you! I now modify the lib file each time to mount it, and modify it again after restarting.

/ Get the mount parameters based on the file system. / function get_mount_params($fs, $dev, $ro = false) { global $paths;

$rc             = "";
if (($fs != "cifs") && ($fs != "nfs") && ($fs != "root")) {
    $config_file    = $paths['config_file'];
    $config         = (file_exists($config_file)) ? @parse_ini_file($config_file, true, INI_SCANNER_RAW) : array();
    $discard    = ((isset($config['Config']['discard'])) && ($config['Config']['discard'] == "yes") && is_disk_ssd($dev)) ? ",discard" : "";
}
$rw             = $ro ? "ro" : "rw";
switch ($fs) {
    case 'hfsplus':
        $rc = "force,{$rw},users,umask=000";
        break;

    case 'btrfs':
        $rc = "{$rw},noatime,nodiratime,space_cache=v2{$discard}";
        break;

    case 'xfs':
        $rc = "{$rw},noatime,nodiratime{$discard}";
        break;

    case 'zfs':
        $rc = "{$rw},noatime,nodiratime";
        break;

    case 'exfat':
        $rc = "{$rw},noatime,nodiratime,nodev,nosuid,umask=000";
        break;

    case 'vfat':
        $rc = "{$rw},noatime,nodiratime,nodev,nosuid,iocharset=utf8,umask=000";
        break;

    case 'ntfs':
        $rc = "{$rw},noatime,nodiratime,nodev,nosuid,nls=utf8,umask=000";
        break;

    case 'ext4':
        $rc = "{$rw},noatime,nodiratime,nodev,nosuid{$discard}";
        break;

    case 'cifs':
        $credentials_file = "{$paths['credentials']}_".basename($dev);
        $rc = "{$rw},**port=8889(add port here),**noserverino,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=99,gid=100%s,credentials=".escapeshellarg($credentials_file);
        break;

    case 'nfs':
        $rc = "{$rw},soft,noac,noatime,nodiratime,retrans=4,timeo=300";
        break;

    case 'root':
        $rc = "{$rw},bind,noatime,nodiratime";
        break;

    default:
        $rc = "{$rw},noatime,nodiratime";
        break;
}

return $rc;

}