The history of creating a home cloud. Part 3. Creating a personal cloud - installing and configuring Nextcloud

    On the way to creating our own cloud service, we have mastered the Debian system and created a web server . Now it's time for the final step - creating and configuring a personal cloud based on Nextcloud server.





    Table of contents


    Part 1. Setting up a Debian environment for everyday use.
    Part 2. Creating a server — configuring LAMP on Debian.
    Part 3. Creating a personal cloud — installing and configuring Nextcloud. Part 4. Updating
    2018 — Debian 9 and Nextcloud. 13



    Quick chapter navigation


    Preface
    Preparing the server for the Nextcloud
    installation Installing Nextcloud
    Organization of the Nextcloud storage location
    Setting up access to the Nextcloud virtual machine from the local network
    Setting up Nextcloud
    Additional “fine-tuning” Nextcloud
    Protection for Nextcloud
    Synchronization with the cloud of smartphones
    Synchronization with the personal computer cloud
    Afterword



    Foreword


    Here we come to the very thing for which everything was started and why we did not move quickly. This part will describe the installation and some points in setting up a Nextcloud server in a VMWare virtual machine, as well as some experience with it in the form of synchronizing the contents of a pair of smartphones and folders on a Windows desktop computer. The following instructions for installing Nextcloud imply that the service is deployed on a server that was created according to the instructions in the previous part of my story.

    Initially, this chapter was planned for a short one, since I wanted to confine myself to a description of the installation and configuration of Nextcloud, essentially completing this story about “just entering Linux for a specific task”. But, thinking that it might seem interesting to someone, then I decided to show how I decided to synchronize the folders of my home computer, so this final chapter smoothly flowed from clear instructions on what to do and, in fact, programming. This explains some "vinaigrette" in this part - it begins with the work and settings in Linux, flowing to the level of network settings and virtual software, and ends with the planning of crutches in Windows. On the other hand, this series of articles has the title “History of creation ...” and I nevertheless decided to tell it to the end.

    Note
    Upon further reading in constructions of the form http: // 127.0.0.1 (https: // 127.0.0.1), the space after http: // (https: //) must be removed when entering into the address bar of the browser. A space is inserted when publishing this article in order to prevent the text engine from automatically converting text into links.



    Preparing the server for the installation of Nextcloud


    Nextcloud is a web application that has a set of files and works with the MySQL database. The web application is installed as a regular site, for installation of which you need to upload the “engine” files to the server, run the installation file and specify the details of access to the database previously created for this site during the installation.

    Create a directory where Nextcloud files will be placed:
    # mkdir / var / www / nextcloud

    I decided to refuse HTTP, leaving access only via HTTPS. To do this, you need to configure apache.

    Open the file:
    # nano /etc/apache2/sites-available/default-ssl.conf
    And before the tag add the following content:

    <Directory /var/www/nextcloud>Options FollowSymLinks
      AllowOverrideAllRequireall granted
    </Directory>


    Disable HTTP configuration:
    # a2dissite 000-default.conf

    Close port 80:
    # ufw delete allow 80

    And restart the web server:
    # service apache2 restart

    Now we need to create a database for nextcloud. Enter mysql by entering the password from the mysql superuser:
    # mysql -u root -p

    Create a database called nextcloud:
    mysql> CREATE DATABASE `nextcloud`;

    Create a user with the name nextcloud and the trivial password nc123:
    mysql> CREATE USER 'nextcloud' @ 'localhost' IDENTIFIED BY 'nc123';

    We give the nextcloud user full access to the nextcloud database:
    mysql> GRANT ALL PRIVILEGES ON `nextcloud`. * TO 'nextcloud' @ 'localhost';


    mysql> FLUSH PRIVILEGES;

    Exit mysql:
    mysql: mysql> exit

    In addition, you need to install additional modules for PHP:
    # apt-get install curl libcurl3 libcurl3-dev php5-curl
    # a2enmod rewrite


    In the first part of this story we opened ports for network and mail interaction, but under our target task they are not required and it is better to close them. Delete the rules:
    # ufw delete allow 138 / udp
    # ufw delete allow 139 / udp
    # ufw delete allow 139 / tcp
    # ufw delete allow 445 / tcp
    # ufw delete allow 25
    # ufw delete allow 465
    # ufw delete allow 110
    # ufw delete allow 143
    # ufw delete allow 993




    Install Nextcloud


    Download files and unpack them into the intended directory:
    # wget download.nextcloud.com/server/releases/nextcloud-11.0.2.tar.bz2
    # tar xjf nextcloud-11.0.2.tar.bz2 -C / var / www


    Change the rights to the folder:
    # chmod 755 / var / www / nextcloud

    And we assign the web server as the owner of this folder so that there are no problems with writing to it:
    # chown -R www-data: www-data / var / www / nextcloud

    That's it! The service is installed, if you type in the browser https: // 127.0.0.1/nextcloud, the installation wizard will open. But let's wait with this, having previously prepared a place to store user data.

    It is worth mentioning that the version of Nextcloud 11.0.2 is currently rather outdated and contains vulnerabilities that are not found in newer and current versions, so if you install the 11.x branch, it is better to install a more recent version (at the beginning of 2018 it’s version 11.0.7).



    Organization of Nextcloud storage


    This part is optional and can be skipped without problems - everything will work without it. However, if you go to make a directory with data outside of the virtual machine, I recommend to get acquainted with it.

    By default, synchronized content will be stored in the / var / www / nextcloud / nxcdata directory. This option did not suit me at once for several reasons. On the one hand, I would not want a permanent increase in the size of a virtual disk file. On the other hand, I would like to have a separate and independent of the virtual machine storage solution. The simplest thing that immediately comes to mind is the use of a USB drive. In case of insufficient space, the disc can be simply replaced. If necessary, you can connect it to another computer and download the necessary files. Mobile and convenient. However, I didn’t want to use USB 2.0 due to the relatively small bandwidth by modern standards, and with USB 3.0 I didn’t succeed - virtualization software (WMVare and VirtualBox) didn’t want to properly forward devices,

    My appetites, in the process of creating the cloud, increased and I didn’t have at least one terabyte, so, in the end, I decided to connect a regular two-terabyte hard drive that was already located and connected inside the computer to the virtual machine. If necessary, it is easily pulled out and connected via the existing SATA <-> USB 3.0 adapter.

    So, the main idea is to organize a fixed point for connecting a directory with user content outside the / var / www / nextcloud directory, in which a symbolic link is created with the name nxcdata, referring to the real data directory that can be connected in various ways on various media.

    Create a directory:
    # mkdir / mnt / nxcdata Change the

    permissions:
    # chmod 770 / mnt / nxcdata

    Making the owner of a web server:
    # chown www-data: www-data / mnt / nxcdata

    I can locate data anywhere and anywhere, the main thing is to place the symbolic link to this directory in the / mnt / nxcdata directory and call it nxcdata, i.e. the full path will look like / mnt / nxcdata / nxcdata.

    First, I tested the solution for the local folder I created in my home directory.

    Created a folder in the right place:
    $ mkdir / home / user / nxcdata

    Changed permissions:
    # chmod 755 / home / user / nxcdata Owned

    the web server:
    # chown -R www-data: www-data / home / user / nxcdata

    Created symbolic link:
    # ln -s / home / user / nxcdata / mnt / nxcdata / nxcdata

    This solution was workable, so you can move on. The external data directory can be connected in two ways - through the VMWare Shared service or directly as a physical disk or partition. It is necessary to understand that the first solution is possible only if there are installed vmware tools, which are easily installed only if there is a graphical interface of the operating system (otherwise, you will have to edit the installation scripts of vmware tools). If we abandon the graphical interface, then there remains only the option of connecting the disk directly to the virtual machine, but with this decision I had to suffer a lot. After a while, I nevertheless found a stably working version, taking into account which a universal script was invented, incorporating both connection options.

    For the folder that is connected via VMWare Shared Folders in the Shared Folders section of the virtual machine settings, you need to connect the necessary folder from the host system and name it vmw-nxcdata. This folder can refer to a directory on the hard disk or directly to the root directory of a disk on the host system.

    The connected folder will automatically appear in the virtual system along the path / mnt / hgfs / vmw-nxcdata. However, the problem is that the web server will not have enough rights to write files along this path and it will not be possible to reassign the rights for this directory using standard system tools. So I had to figure out how to manually mount these resources.

    Create a folder:
    # mkdir / mnt / vmw-nxcdata

    Perform the mount using the vmhgfs module, which was installed with the vmware-tools:
    # mount -t vmhgfs -o uid = www-data, gid = www-data, fmask = 007, dmask = 007 .host: / vmw-nxcdata / mnt / vmw-nxcdata

    Mounting should be done with exactly these parameters in order to ensure smooth operation of the web server in the future. Initially, I mounted without specifying uid / gid and masks, but this didn’t lead to anything good, since I could no longer change the permissions after mounting. After the mount has been completed, the following can be issued: “Could not add entry to mtab, continuing” - however, it will be mounted and work.

    Great, we have mounted the directory. Now you can place a symbolic link to this directory in / mnt / nxcdata. But I would not like to do this manually every time you start or restart the server. The easiest way is to enter the above command in the /etc/rc.local file for mounting to the “exit 0” line. However, I wanted to ensure that when the virtual machine was turned off, automatic guaranteed unmounting occurred for reliable data integrity. And I decided to do everything at the level of services and deal a little with the mechanisms of init / update-rc, the more I was curious and it turned out to be quite interesting.

    The meaning of the following steps is to create a system service that would be called and executed predefined commands when the system is turned on or off. The service is described by a script compiled according to certain rules and is located in /etc/init.d. The INIT INFO block is located at the very beginning of the script and contains service information in which I would like to note the Default-Start and Default-Stop directives - they set the execution levels at which the script should be started or stopped by default.

    Fulfillment levels:

    0 - script execution when the system is turned off
    1 - script execution when the system is started in single user mode
    2 - script execution when the system is started in multiuser mode
    3 - 5 - reserved
    6 - script execution when the system is rebooted.

    After writing the script, it is activated using the update-rc mechanism, which, in fact, creates links to the script in the necessary directories /etc/rc0.d - /etc/rc6.d, the contents of which correspond to the tasks performed launch levels. Links can be created independently, but, in contrast to enabling or disabling apache web server configurations, many nuances need to be taken into account here, so you need to enable or disable the service through update-rc.

    So, create a file:
    # nano /etc/init.d/nxcdata_automount.sh

    And write the following contents into it:

    #!/bin/sh# nxcdata_automount.sh 1.0### BEGIN INIT INFO# Provides: myscript# Required-Start:# Required-Stop:# Default-Start: 1 2 3 4 5# Default-Stop: 0 6# Short-Description: nxcdata_automount.sh 1.0# Description: nxcdata_automount.sh 1.0### END INIT INFO
    . /lib/lsb/init-functions
    # Start actionsperform_start()
    {
      log_daemon_msg «Start nxcdata_automount»
      sleep 30
      mount -t vmhgfs -o uid=www-data,gid=www-data,fmask=007,dmask=007 .host:/vmw-nxcdata /mnt/vmw-nxcdata
      #mount -t ntfs-3g -o uid=www-data,gid=www-data,fmask=007,dmask=007 /dev/sdb1 /mnt/sdb1#mount -t ext4 /dev/sdb1 /mnt/sdb1
      sleep 5
      service fail2ban restart
      log_end_msg 0
      return 0
    }
    # Stop actionsperform_stop()
    {
      log_daemon_msg «Stop nxcdata_automount»
      umount /mnt/nxcdata
      log_end_msg 0
      return 0
    }
    case$1in
      start)
        perform_start
        ;;
      stop)
        perform_stop
        ;;
      *)
        echo “Usage: /etc/init.d/myscript {start|stop}”
        exit 3
        ;;
    esac


    Pay attention to a couple of commented commands in the perform_start section - this is our reserve for the future. Also, after the mount is completed, the fail2ban service is restarted.

    The paradox is that after a year I don’t remember why I did it, but I strongly doubt that this was done just like that. Obviously, after the mount was completed, for some unknown reason, the service crashed or failed to start up initially and had to be restarted manually.

    After such a distraction, we continue tuning further. Create a symbolic link:
    # ln -s / mnt / vmw-nxcdata / mnt / nxcdata / nxcdata

    Make our script executable:
    # chmod + x /etc/init.d/nxcdata_automount.sh

    Add the script to the autoload:
    # update-rc.d nxcdata_automount.sh defaults

    Reboot the system and make sure that the automount is successful and everything is available along the necessary paths.

    To remove the script, you will need to execute a couple of commands:
    # update-rc.d -f nxcdata_automount.sh remove
    # rm -f /etc/init.d/nxcdata_automount.sh


    If you are mounting the disk not through VMWare Shared Folders, you should directly perform similar as when mounted via VMWare Shared Folders, but considering that a full-fledged second disk appears in the system. How to recognize the drive letter?

    Most Linux block devices are connected via the SCSI interface, so in most cases the disks will start with the letters sd. The third letter in the disk name means its ordinal number in the system and is alphabetically designated: sda - the first disk, sdb - the second disk, sdc - the third one, and so on. Next comes the number that identifies the partition number on the disk: sda1, sda2, and so on. The easiest way to see all mounted disks is to look at the contents of the / dev / directory and filter the sd devices:

    $ ls -l / dev / | grep sd

    For example, we need to connect the sdb1 drive with the NTFS file system.

    Create a directory and mount the disk into it:
    # mkdir / mnt / sdb1
    # mount -t ext4 / dev / sdb1 / mnt / sdb1


    Create a directory for the data, set its permissions and user:
    # mkdir / mnt / sdb1 / nxcdata & chmod 770 / mnt / sdb1 / nxcdata & chown -R www-data: www-data / mnt / sdb1 / nxcdata

    Next, you also need to create a script for automounting and correct the mount command in the script (examples Connecting a disk with NTFS and EXT4 in the script is already there and commented out) and add the script to autoload.

    B create a symbolic link to the data directory:
    # ln -s / mnt / sdb1 / nxcdata / mnt / nxcdata / nxcdata

    In fact, this whole mess with a bunch of nxcdata directories is designed for one thing: to ensure a simple transfer of the data directory in the future - you will not need to edit the configuration in the Nextcloud engine and generally go into it - all you need to do is plug in a new disk, copy it to data from it and re-create the symbolic link leading to the new data directory. In this case, all actions do not go beyond the directory / mnt. So everything turned out to be complicated evolutionarily, I just did not want to lose the solutions I had worked out.

    What is the best way to take out data outside the virtual machine? I will share my experience on which version I stopped and why.

    USB drives were automatically captured when the virtual machine was loaded, they were correctly and fully forwarded inside and everything always worked, but only until the drive was disconnected from the system for some reason. It helped reboot or physically disconnect and connect the drive. The solution turned out to be unreliable. There was no such problem with flash drives, but I was absolutely not satisfied with their volume and speed of work. Perhaps it was worth trying an external drive with autonomous power.

    Forwarding directories through VMWare Shared Folders worked stably and perfectly. This solution fully satisfied the task of synchronizing two smartphones. Everything worked for several days, tens of gigabytes of data were downloaded. However, when I decided to add data from a computer to the cloud, then suddenly a problem was discovered related to long paths and file names. In theory, the limit on the length of a file or folder name in NTFS is 255 characters, but in practice the Windows API limits it to 244 characters. In theory, the limit on the path to a file or folder in NTFS is 32,767 characters, but in practice the Windows API limits it to 245 characters. Considering that I am a big fan of structuring information, the length of the path I can have is very long. The unabridged title of books can also easily be 100-150 characters, taking into account the spaces. This limitation is a well-known VMWare Shared Folders problem that did not cure even when using Windows 10 with all sorts of clever keys in the registry to remove the 255-character limit. Possible reason for the limitations of vmhgfs. From this convenient method of connection had to be abandoned. The reason is established exactly - a problem in the virtual file system that is used in the VMWare Shared Folders mechanism.

    The next solution is to connect the hard disk directly to the virtual machine. Here, too, everything did not go smoothly. The data structure (or file system, and this manifested itself for both NTFS and EXT2 / 3/4) constantly broke down either by “capturing” the disk or its partition with software of the virtual machine, or by returning it to the host system even if I translated disk offline on the host system. In some modes, I don’t have to write or read data - I couldn’t even properly format the forwarded hard disk or partition. However, it was possible to find a workable mode: a physical hard disk with a single partition, formatted in NTFS, in a particular connection mode was connected to the virtual machine: SATA / Independent / Persistent / Use individual partition. The nxcdata folder containing the data must be located on the hard disk.



    Setting up access to the Nextcloud virtual machine from the local network


    We have no problems opening sites within a virtual machine or from a host system. But how to open the created site from another computer on the local network? Let's look at the structure of our network, shown below.



    The picture shows that the router is connected to the Internet directly and configured so that it automatically distributes IP addresses to connected devices in the range 192.168.0.2-192.168.0.254. The address 192.168.0.2 was received by our computer, and 192.168.0.3 - the second computer on which we make the server. However, virtualization software is installed on the second computer, which created its virtual router and configured its DHCP on the subnet 192.168.233.0/24. Our virtual server received an IP of 192.168.133.138.

    I can easily open the site inside the virtual machine 192.168.233.138. I can easily open the site from the 192.168.0.3 machine by simply entering the desired IP address in the browser - the virtualization software has already taken care of correctly configuring the network environment on the host machine. But how can I get to the site from a computer 192.168.0.2? If I enter the IP address 192.168.233.138, then nothing will open to me, since neither my computer nor the real router knows anything about this subnet. If I enter the address 192.168.0.3, then nothing will open to me either, since there really is no site on this computer - it is inside its virtual machine.

    To resolve this issue, you need to configure the virtual router of the computer 192.168.0.3. We already know that accessing sites goes through ports 80 and 443. When accessing these ports to machine 192.168.0.3, you need to build routing so that requests are forwarded to the virtual machine 192.168.233.138. Fortunately for this we have available tools. VMWare Workstation has the Virtual Network Editor tool, which can be opened from the virtual machine menu (Edit -> Virtual Network Editor).



    This tool allows quite flexible management of network parameters. We need to select the VMNet8 virtual network card and click on the “NAT Settings ...” button that has become available. In the window that opens, you need to add rules to create the desired routing.



    Specify the port of the host system and then write the IP address and port of the virtual machine where the requests should be redirected. For forwarding HTTPS traffic, you must specify the port 443 of the host system and port 443 and the address 192.168.233.138 of the virtual machine. After creating the rules, click "OK" in all windows - the virtual network environment is automatically reconfigured.

    After these changes, our sites will begin to open from the machine 192.168.0.2 when accessing the address 192.168.0.3.

    Such settings for port forwarding are available not only for VMWare, but also for VirtualBox (Settings → Network → select the required adapter → Advanced → Port forwarding). However, in the process of experimenting to connect a hard disk to this stage, I found a free VMWare Player installed, in which the Virtual Network Editor was not. I found nothing on the Internet about port forwarding for VMWare Player and I had to use the trial version of VMWare Workstation - when installing the product, it is given 30 days of its free use. After 30 days, you can remove the product, clean the registry and reinstall it, but such attention to the server is somehow redundant and clearly undesirable. And then I went for a little (or big) trick. There is a vmnetcfg utility in the VMWare Workstation fileset, which essentially runs through the Virtual Network Editor. However, it was not in the VMWare Player fileset. But when installing VMWare Player, how does it configure its network environment? I just took this utility and copied it into the folder with VMWare Player, and then launched it. Surprisingly, everything turned out. It is possible that fine network settings in the VMWare Player environment will not work, but port forwarding is provided, but I don’t need more.

    To access our server from the Internet, you need to similarly forward ports on a router that is connected to the Internet. In the firmware of the overwhelming majority of routers there is a Port Forwarding section in which you can configure routing by specifying the external port and port and the IP address of the internal machine. However, there is a small nuance. If the provider gave us a real IP address or we bought it from him, then there will be no problems - from a computer from anywhere in the world enter this IP address, the real router will redirect traffic to a computer with a virtual machine, on which the virtual router will redirect traffic directly to a virtual the car. But what to do to someone who does not have the opportunity to get a real IP address and he gets dynamic addresses or turns out to be for NATprovider, getting "gray" IP addresses? I did not have to solve this problem, since I have a static "white" IP. The one who will have to solve such a problem in one way or another will have to deal with this problem. I would advise to look in the direction of dyndns or freedns.afraid.org in the case of dynamic addresses, or to buy a cheap VDS, try to come up with some kind of routing yourself, because in any case, without a external server with a static IP address, this problem cannot be solved.

    After configuring the routing, I fixed the IP addresses of computers 192.168.0.3 and 192.168.233.138, setting them in the settings of the network cards of the specified machines manually in order to exclude their automatic reassignment.



    Setting up Nextcloud


    Now it's time to open in the browser https: // 127.0.0.1/nextcloud inside the virtual machine, https: // 192.168.233.138/nextcloud from the host system or, based on the above configured routing, https: // 192.168.0.3/nextcloud computer on the local network.

    Next, we set the login / password for the administrator, access to the previously created database, and specify the full path to the nxcdata directory as the storage location: / mnt / nxcdata / nxcdata. This configuration step is no different from installing any site.

    In the admin settings I made the following simple changes:

    - Personal → chose Russian and specified the e-mail for the administrator user @ localhost
    - Administration → Sharing → turned off all items
    - Administration → Usage survey → turned off all items
    - Administration → Advanced settings → File management: “Set maximum upload file size” set to 25 GB
    - Users → created users group and added new user to it

    After setting, you need to enable caching.

    Open the file:
    # nano /var/www/nextcloud/config/config.php

    And at the very end, before “);” we add the following: Now we need to allow external access to the site at the level of its “engine”. Open the file: # nano /var/www/nextcloud/config/config.php In the trusted_domains section, add the server’s IP address to the array, add the address where Nexcloud is installed. In our case, the trusted_domains section will look like this:

    'memcache.local' => '\OC\Memcache\Memcached',
    'memcache.distributed' => '\OC\Memcache\Memcached',
    'memcached_servers' => array(
    array('localhost', 11211),
    ),









    'trusted_domains' =>
    array (
    0 => '127.0.0.1',
    1 => '192.168.233.138',
    ),


    Now you can check the serviceability of the service - we open the site and log in using the user user. If the authorization was successful, then the service is ready for battle - you can install the synchronization application on computers and smartphones, for access enter the IP address 192.168.0.3 and account access details created for each device.
    Fortunately or unfortunately, I did not have to use all the potential of the created service, since I initially needed a backup system with verification and I generally only wanted to do with subversion, but the speed of commits of a particularly large number of small files saddened me greatly. I did everything for growth, but I never got to use it, and then it was somehow not at all up to the cloud.

    A more detailed overview of the use of the service was made by the user wtigga at the end of 2017 in his article “How to download a VPS: your Nextcloud cloud” . The article, from the user's point of view, gives an overview of the newer Nextcloud server, version 12.



    Additional "fine" setting Nextcloud


    During the operation of the cloud during the first month of operation, some problems surfaced, which I had to solve with the help of the community or independently. I must say that I used the service very hard and essentially checked it for stress resistance. Synchronizing several gigabytes of data from the phones and up to a million small files from a computer in the evening was a common thing. In general, the service made a very positive impression on me.

    I would not say that the solutions below are correct and beautiful, but these crutches work at least for version 11.0.2, otherwise it would be impossible to use the service. In version 12.x, perhaps something has been improved and corrected, so I would not recommend setting these settings immediately as part of the initial setting, while for the 11.x line you can apply them immediately.

    Problem 1

    When synchronizing, an error like “file is locked” occurs. Synchronization stops. The problem is known - it is necessary to clear the contents of the oc_file_locks table by running the following query from the mysql console (when authorizing the nextcloud user) to it:
    mysql> DELETE FROM oc_file_locks WHERE 1

    Since such errors are not uncommon, I didn’t think of anything better than to create a script and put it directly in the root folder:
    # nano / root / empty_oc_file_locks Script

    content:

    #!/bin/bash
    mysql -unextcloud > -pnc123 -D nextcloud  <<MY_QUERY
    DELETE FROM oc_file_locks WHERE 1
    MY_QUERY
    


    The script can be executed manually, but this is not our method. I decided to run it automatically every 15 minutes using cron (https://ru.wikipedia.org/wiki/Cron).
    To do this, create a file:
    # nano / root / crontab

    With the following contents: Now you need to make changes to the scheduler: # crontab / root / crontab You can check for any changes like this: # crontab -l Problem 2 When synchronizing via webDAV in logs (see administration panels, having been authorized by the administrator), the following errors may appear:

    */15 * * * * root bash /root/empty_oc_file_locks












    Error PHP reset() expects parameter 1 to be array, null given at /var/www/nextcloud/apps/files_versions/lib/Storage.php#783
    Error PHP ksort() expects parameter 1 to be array, null given at /var/www/nextcloud/apps/files_versions/lib/Storage.php#782
    Error PHP Invalid argument supplied for foreach() at /var/www/nextcloud/apps/files_versions/lib/Storage.php#759
    Error PHP Undefined index: by_file at /var/www/nextcloud/apps/files_versions/lib/Storage.php#759
    Error PHP Undefined index: all at /var/www/nextcloud/apps/files_versions/lib/Storage.php#757


    This time the community did nothing and had to be investigated alone. The reason was the error "Undefined index ... Storage.php # 757", which cascadingly pulls a few more errors. We look at the code of this file. The whole problem was in quota. On this line in the code (Storage.php # 757) the free space is calculated taking into account the volume of archive files. Something goes wrong in the calculation, although the quota is set to "unlimited". To fix an error in the administration panel, I set an “infinite but numeric” quota for each user, for example, 100TB.

    Problem 3

    The problem with synchronizing .htaccess files - they just do not sync! And I was not alone, in some forums asked similar questions. However, I did not meet the ready solution. I had to think again myself. As a result of googling, viewing logs, analyzing the code, I did not think of anything better than how to correct the nextcloud engine file.
    In the /var/www/nextcloud/lib/private/Files/filesystem.php file, we are looking for the following line: And we bring it to the following form:

    $blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', array('.htaccess'));




    $blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', array(''));




    Protection for Nextcloud


    You can protect our service from password selection to the admin panel using fail2ban. To do this, describe the characteristic expression that occurs in the nextcloud logs in case of unsuccessful authorization, according to which the corresponding trigger will be triggered.

    Create a file:
    # nano /etc/fail2ban/filter.d/nextcloud.conf

    With the following content:

    [Definition]
    failregex = {"reqId": ". *", "RemoteAddr": ". *", "App": " core "," message ":" Login failed: '. *' \ (Remote IP: '' \) "," level ": 2," time ":". * "}
    ignoreregex =

    Open the file:
    # nano / etc /fail2ban/jail.local

    And at the end of the file we add the following: Restart the service: # service fail2ban restart Check for the presence of an active filter:

    # выявляем неудачные попытки ввода пароля к nextcloud
    [nextcloud]
    enabled = true
    port = http,https
    protocol = tcp
    filter = nextcloud
    logpath = /var/log/nextcloud.log






    # fail2ban-client status nextcloud

    Do not forget that, in accordance with the fail2ban settings from the previous part, if the password is unsuccessful six times in a row for 12 hours, your IP will be blocked for 30 days. I somehow spent two evenings because of the wrong password entry on one of the phones, until I found out this simple fact in the system logs.



    Synchronization with the cloud of smartphones


    To synchronize the contents of phones running Android, there is a wonderful application FolderSync. The program fully justifies its small price.

    First, you need to create a new account in which the address of the server is https: // 192.168.0.3/nextcloud, enter the login and password of the previously created account and allow the self-signed certificate. Press the "Test" button and make sure that the connection to the server is in order.

    Next you need to create a task. In the task, specify the previously created account and select the type of synchronization - "To a remote folder." Specify the remote folder (you can create it directly from the application ”and select the local folder for synchronization. I set the schedule at 2 am every day. In the synchronization settings I had“ Synchronization of subfolders ”and“ Synchronization of included folders ”, I also chose the option to always replace old files and in case of conflicts I allowed to use the local file by default.In the "Connections" section, I disabled all connections except Wi-Fi, and I registered the SSID of my home Wi-Fi network in the "Allowed WiFi SSIDs" section - application wake Do not synchronize only in my home network and do not try to search for a server in other networks. I left the rest of the default settings. Here you can add filtering. I created a new “Folder Name Contains” filter and set it to [nosync]. Thus, I can exclude from synchronization some folders in the specified local folder, simply adding at the end of their name "[nosync]".

    This setting was made for local folders such as DCIM, Download, Telegram, viber, WhatsApp. Plus a couple of my user folders of several gigabytes. Once a day, the contents of these folders are synchronized with the server, and the old versions of the files on the server are not deleted, but renamed and moved to the archive. This allowed me to quickly restore an accidentally deleted file or roll back changes to some other files.



    Synchronization with the personal computer cloud


    I do not consider myself a real programmer. For the last ten years, I have been programming in programming languages ​​that are used except in the development of processors or chipsets. Due to the fact that I have not done anything in C / C ++ for about 15 years, but I needed to automate something on the computer, I rather actively used scripting languages ​​like BAT / CMD or such software as Sign 0f Mistery or xStarter. I once learned and tried AutoIt and this was a new era in my PC automation.

    After I was convinced of the stability and reliability of the synchronization system on smartphones, I thought that it would be nice to synchronize data on my home computer. Nextcloud has its own client for Windows and, of course, it has become the first candidate for testing. Synchronize I was going to a terabyte order data volume, consisting of hundreds of thousands of files of different sizes. The data was different: music, pictures, documents, e-books, distributions, backup copies of sites and so on and so forth. It would be reasonable to reduce all this to synchronization of more critical data, such as documents, for example, but I was excited about excitement and wanted to check the service for strength.

    A dozen hours after the start of synchronization, and in fact the first download of content to the server, the client stumbled over a file with a long name. At that time, on the server, I also used the connection of external storage through VMWare Shared Folders and I had to try a dozen clients and then run simple experiments on manually copying files to the server in order to understand that the problem is on the server side. So, after a week of successful launch of the service, I had to roll back to the backup virtual machine and abandon the VMWare Shared Folders mechanism, starting all over again. In the end, I removed this bottleneck on the server side, tested the reliability of the solution for the synchronization of smartphones weeks and decided to return to the home computer again. This time, the client did not stumble over the ill-fated file and I was already glad, However, after half a day of synchronization of small files, the client again hung up. Now it turned out that the path is too long on the side of the home computer and the client of Nextcloud cannot handle it correctly. Unfortunately, the work with the native client of Nextcloud did not work, and its information content was not quite high, so I had to give it up.

    For a while I spent on finding a convenient synchronization program that supports management via the command line. I wanted to do my job for every large folder on my computer and run them in batch mode. Earlier, I had already made and worked out a set of BAT files for synchronization, using scripts and managing FreeFileSync via the command line. The problem of long paths or file names was solved by specifying local folders of the form "\\? \ D: \ Info", i.e. essentially referring to a local folder as a network. However, what webdav FreeFileSync does not know. Unfortunately, there were no complete FolderSync analogues for Windows, but GoodSync recommended it more than once on the forums instead of it, and after casting a dozen other programs, I decided to try it. Unfortunately, GoodSync is much more expensive, but one-time waste of $ 15 for the safety of their precious data, in principle, feasible. The program has a test mode, so you can first verify its performance and stability.

    GoodSync was pretty friendly software. There is a special portable version called GoodSync2Go. Here she is and interested me. When installing, you need to select the drive letter and the program is installed on it in the GoodSync folder. I created the Sync folder in the root directory of the disk, say D, and moved the created GoodSync folder with all its contents to it.

    [ This text was written specifically for the site geektimes.ru by AlexanderS .
    Reference to the source is optional, but its mention is highly desirable! ]


    After installation, the program needs to create tasks: specify a local folder and a remote folder for synchronization. In the parameters of the task, I chose synchronization from left to right with the choice of options "Synchronous deletion" and "Save previous versions of deleted / replaced files." In the settings of the left side, I chose "Safe Copy" and "Do not create the _gsdata_ folder", the right side - "Safe Copy" and "Fast Predalizatsii on timestamps." Thus, jobs are created for each desired folder. Suppose I set up a task for the Info folder and called it “bck_Info”.
    Next, in the D: \ Sync folder, the bck_Info.bat file is created with the following contents:

    @set dir=%~dp0
    @%dir%GoodSync\GoodSync2Go-v10.exe /miniwin /exit sync "%~n0"


    This is the BAT scripting language. In the first line of the code, the current path for the running script is set in the variable. The second line launches the GoodSync2Go-v10.exe file along this path from the GoodSync folder, where the task with the name of this file (bck_Info) should be executed, the task execution window is minimized, and the program should automatically close upon completion of the task. I can copy this script several times, each time changing only its name to the name of a previously created task in GoodSync. Thus, just by clicking the Enter button on the BAT file, I can start synchronizing the folders I need individually.

    To add a new task to FreeFileSync, I could simply copy the xml script file and manually correct it, i.e. running the graphical shell of the program was not required at all. In GoodSync, however, all tasks are written in the file D: \ Sync \ GoodSync \ GoodSync \ Profile \ jobs.tic and to add a new task you will need to open the program and create it, because to edit this file is somewhat problematic and it is not known where it may lead.
    To synchronize all folders, you can now write a simple bck_all.bat script:

    @set dir=%~dp0
    call %dir%bck_Info.bat
    call %dir%bck_Info2.bat
    call %dir%bck_Info3.bat
    call %dir%bck_Info4.bat
    

    Each line of the script simply causes the execution of a separate script that starts the synchronization.

    This is all very good and works comfortably, but there is no error control during synchronization. For example, if the server is not turned on, then all tasks will be promptly completed, and I, returning after an hour, will think that the synchronization has already been completed. At the same time, logs of all tasks are created using the path D: \ Sync \ GoodSync \ GoodSync \ Profile \ *. Log. It is enough just to view the log of each synchronization for the presence of the word “ERROR” - for some reason, this is how the synchronization failures are reported in the log. Therefore, it was decided to write a small program to analyze these logs after all the synchronizations, which will be launched automatically after the synchronization of all folders. The program received the proud name log_analayser and is written in the semi-script language AutoIt . If you are interested in someone, then download its full version.You can on the official site AutoIt, which contains the necessary libraries, compiler and SciTE - a cross-platform editor for the code from which you can and compile the program.

    What time I spent on developing and debugging the code, the result was a file log_analayser.au3 with the following contents:

    ; LOG Analyser 1.0
    ; Программа предназначена для анализа текстовых лог-файлов
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Res_Field=ProductName|LOG Analyser#AutoIt3Wrapper_Res_Fileversion=1.0.0.0#AutoIt3Wrapper_Res_Field=OriginalFilename|log_analyser.exe#AutoIt3Wrapper_Res_Comment=Программа предназначена для анализа текстовых лог-файлов#AutoIt3Wrapper_Res_Description=Анализ лог-файлов
    ;****
    #AutoIt3Wrapper_Res_Language=1049#AutoIt3Wrapper_Res_ProductVersion=1.0#AutoIt3Wrapper_Compile_Both=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    ;AutoItSetOption ("WinTitleMatchMode", 2) ; сопоставление заголовка окна с произвольным фрагментом
    ;#NoTrayIcon ; скрыть иконку из трея во время выполнения программы
    If WinExists('[CLASS:AutoIt v3;TITLE:' & @ScriptName & ']') Then
    	MsgBox(48, @ScriptName, "Позволено запускать только одну копию программы!");
    	;Раскоментируйте следующую строчку если нужно активировать окно вашей программы при повторном её запуске
        ;WinActivate('Имя вашей программы')
        Exit
    EndIf
    AutoItWinSetTitle(@ScriptName)
    #include <Array.au3>#include <_FileDirList.au3>
    ; настройки
    Local $msg_title = "LOG Analyser 1.0"
    Local $path = @ScriptDir
    Local $soft_open_log = "notepad.exe"
    Local $path, $dir_mode, $word, $file_analyse_name, $file_analyse_ext, $log_path, $log_msg_on
    Local $file_log, $word_detect, $file_analyse, $cnt_files, $i
    ;проверка и загрузка параметров
    if ($CmdLine[0] < 6) then
      MsgBox(0x10, $msg_title, "Отсутствуют или недостаточно параметров!" & @CRLF & @CRLF & "Работа программы прекращена")
      Exit
    elseif (StringCompare($CmdLine[1], "file") = 0) then
        $dir_mode = 0
      elseif (StringCompare($CmdLine[1], "dir") = 0) then
        $dir_mode = 1else
        MsgBox(0x10, $msg_title, "Первый параметр должен принимать значения 'file' или 'dir'!" & @CRLF & @CRLF & "Работа программы прекращена")
        Exit
      endif
      $word = $CmdLine[2]
      if ($dir_mode = 0) then
        $file_analyse_name = $CmdLine[3]
      else
        $dir_analyse = $CmdLine[3]
      endif
      $file_analyse_ext = $CmdLine[4]
      $log_path = $CmdLine[5]
      if (StringCompare($CmdLine[6], "err_msg_on") = 0) then
        $log_msg_on = 1
      elseif (StringCompare($CmdLine[6], "err_msg_off") = 0) then
        $log_msg_on = 0else
        MsgBox(0x10, $msg_title, "Шестой параметр должен принимать значения 'log_msg_on' или 'log_msg_off'!" & @CRLF & @CRLF & "Работа программы прекращена")
        Exit
      endif
    endIf
    ; инициализация переменных
    $file_log = $log_path & "\" & "log_analyser" & "-" & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & ".log"
    $word_detect = 0
    ; основной код программы
    if ($dir_mode = 0) then
      $file_analyse = $file_analyse_name & "." & $file_analyse_ext
      if (_file_analyser($file_analyse, $msg_title, $word, $file_log, $word_detect) = 1) then
        $word_detect = 1
      endif
    else
      ; сканирование файлов для анализа
      $dir_arr = _FileDirList($dir_analyse, "*."&$file_analyse_ext, 1, 1, 0)
      ;_ArrayDisplay($dir_arr)
      ; проверка после сканирования - проверка на наличие файлов для анализа
      if ($dir_arr = 0) then
        MsgBox(0x10, $msg_title, "Неверный путь или не обнаружены файлы для анализа!" & @CRLF & @CRLF & "Работа программы прекращена")
        Exit
      endif
      $cnt_files = $dir_arr[0]
      ; перебор анализируемых файлов
      $i = 0
      While $i <> $cnt_files
        $i = $i + 1
        $file_analyse = $dir_arr[$i]
        if (_file_analyser($file_analyse, $msg_title, $word, $file_log, $word_detect) = 1) then
          $word_detect = 1
        endif
      WEnd
    endif
    ; обработка результатов анализа
    if ($word_detect = 1) and ($log_msg_on = 1) then
      if (MsgBox (0x41034, $msg_title, "Обнаружены ошибки!" & @CRLF & "Все строки с ошибками записаны в файл: " & $file_log  & @CRLF & @CRLF & "Открыть файл с ошибками?")) = 6 then
        ShellExecuteWait($soft_open_log, $file_log)
      endif
    endif
    Exit
    ; функция выполняет построчный поиск слова в файле и возвращает переменную информирующую о наличии слова хотя бы в одной строке
    ; все обнаруженные строки, содержащие указанное слово, пишутся в файл лога
    Func _file_analyser($file_analyse, $msg_title, $word, $file_log, $word_detect)
      Local $file1, $file2, $file_line, $write_once
      $word_detect = 0
      $write_once = 0
      $file1 = FileOpen($file_analyse, 0)
      ; проверка наличия анализируемого файла
      If $file1 = -1 Then
        FileClose($file1)
        MsgBox(0x10, $msg_title, "Отсутствует файл для анализа!" & @CRLF & @CRLF & "Работа программы прекращена")
        Exit
      EndIf
      ; построчный поиск слова в анализируемом файле
      While 1
        $file_line = FileReadLine($file1)
        If @error = -1 Then ExitLoop
        if (StringInStr($file_line, $word) <> 0) then
          $word_detect = 1
          ; проверка наличия файла для лога и его создание в случае отсутствия
          if (FileExists($file_log) = 0) then
            $file2 = FileOpen($file_log, 1)
            FileClose($file2)
          endif
          ; однакоратная запись в файл имени анализируемого файла
          if ($write_once = 0) then
            $write_once = 1
            $file2 = FileOpen($file_log, 1)
            FileWriteLine($file2, "Анализ файла: " & $file_analyse)
            FileClose($file2)
          endif
          ; вывод в лог строки с ошибкой
          $file2 = FileOpen($file_log, 1)
          FileWriteLine($file2, $file_line)
          FileClose($file2)
        endif
      WEnd
      ; если были записи в файл, то отделяем их пустой строкой от следующего массива записей
      if ($word_detect = 1) then
        $file2 = FileOpen($file_log, 1)
        FileWriteLine($file2, @CRLF)
        FileClose($file2)
      endif
      FileClose($file1)
    	Return $word_detect
    EndFunc
    

    After dialing the code, press the F7 button in the SciTE editor and get the log_analayser.exe file on output.

    The program analyzes the file for the presence of any word. When it is found, a log file is created, into which the found string containing this word is copied.

    The program can work in two modes:

    - analysis of a specific file
    - analysis of the folder containing files for analysis (all subfolders are analyzed as well).

    When using a console call, you must set six parameters for the program:

    1 - operation mode [file = file analysis; dir = analyze folder containing files]
    2 - search keyword
    3 - file name or full path to folder
    4 - file extensions or files for analysis in the folder
    5 - full path to the folder where the program log will be located
    6 - window display after analyzing all files in case a specified word is found [err_msg_on = display; err_msg_off = do not display]

    Thus, we have a new bck_auto.bat script:

    @echo Start Backup
    @set dir=%~dp0
    call %dir%bck_all.bat
    log_analyser.exe dir ОШИБКА %dir%GoodSync\Profile log %dir%LOG err_msg_on
    exit

    The script launches a file, from which tasks for synchronization of all necessary folders are called individually one after another, and then the synchronization log analyzer is called, upon completion of which, in case of errors, a message is displayed offering to view the log lines, where these errors are detected and it is possible to understand with what task there were problems. These lines are written in a separate log file in the folder D: \ Sync \ LOG.
    And then I suffered a terrible failure. Log analyzer did not work. No, he worked perfectly on test files, but he stubbornly did not want to see errors in the logs. For a long time I couldn’t understand what the reason was, until I found out one terrible thing: not only was the failure of the English-language log to be outputted by the only Russian word “ERROR”, so also the Cyrillic encoding is Macintosh! I don’t know why Siber Systems programmers did this, most likely it is the result of some awful crutch inside the software. Well, who said programming should be boring?

    Nothing to do but to support one crutch with another and as a result a working construction appeared:

    @echo Start Backup
    @set dir=%~dp0
    call %dir%bck_all.bat
    log_analyser.exe dir Ћ˜€ЃЉЂ %dir%GoodSync\Profile log %dir%LOG err_msg_on
    exit

    However, the following problem appeared: GoodSync itself does not delete log files, with each new task execution new files appeared. And if some kind of synchronization ended with an error, then our analyzer will always find this file and boldly report an error. Therefore, before starting the synchronization, it was decided to automatically clean the D: \ Sync folder from any files with logs. An elegant clean_logs.bat script was created for this:

    @echo off
    set dir=%~dp0
    For /R %dir% %%i in (*.log) Do (
    Del /q "%%i")
    @echo on
    

    The script turns off the output of any messages, finds out the script launch directory, scans all files (including in subfolders) until they run out and deletes all files with the log extension. At the end of the work, the display of messages is turned on.
    The bck_auto.bat script has changed:

    @echo Start Backup
    @set dir=%~dp0
    @call clean_logs.bat
    call %dir%bck_all.bat
    log_analyser.exe dir Ћ˜€ЃЉЂ %dir%GoodSync\Profile log %dir%LOG err_msg_on
    exit

    Everything works very well, but the point is in automating routine actions. Why not just turn off the computer at night and go to sleep, but he synchronizes the path of a bunch of files, analyzes and turns off?

    Let's refine our bck_auto.bat script:

    @echo Start Backup & PCOFF
    @set dir=%~dp0
    start MonitorOnOff.exe 0
    @call clean_logs.bat
    call %dir%bck_all.bat
    log_analyser.exe dir Ћ˜€ЃЉЂ %dir%GoodSync\Profile log %dir%LOG err_msg_off
    shutdown /s /t 0
    exit

    The script has two new lines. The MonitorOnOff application simply turns off the monitor (so that it does not light up the room, but I manually turn it off every evening and turn on every morning is very lazy), and the shutdown command turns off the computer. In log_analyser, the parameter responsible for displaying messages when an error has been changed - after all, after synchronization, it is not necessary to slow down the execution of the script with this message, but to enable it to turn off the computer.

    The MonitorOnOff program is also written in AutoIt.

    ; Monitor On Off 1.0
    ; Программа для включения/отключения монитора
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Res_Field=ProductName|Monitor On Off#AutoIt3Wrapper_Res_Fileversion=1.0.0.0#AutoIt3Wrapper_Res_Field=OriginalFilename|MonitorOnOff.exe#AutoIt3Wrapper_Res_Comment=Программа для включения/отключения монитора#AutoIt3Wrapper_Res_Description=Программа для включения/отключения монитора
    ;****
    #AutoIt3Wrapper_Res_Language=1049#AutoIt3Wrapper_Res_ProductVersion=1.0#AutoIt3Wrapper_Compile_Both=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    ;AutoItSetOption ("WinTitleMatchMode", 2) ; сопоставление заголовка окна с произвольным фрагментом
    ;#NoTrayIcon ; скрыть иконку из трея во время выполнения программыIf WinExists('[CLASS:AutoIt v3;TITLE:' & @ScriptName & ']') Then
      MsgBox(48, @ScriptName, "Позволено запускать только одну копию программы!");
      ;Раскоментируйте следующую строчку если нужно активировать окно вашей программы при повторном её запуске
      ;WinActivate('Имя вашей программы')
      ExitEndIf
    AutoItWinSetTitle(@ScriptName)
    HotKeySet("{F10}", "_Monitor_ON")
    HotKeySet("{F11}", "_Monitor_OFF")
    HotKeySet("{Esc}", "_Quit")
    GlobalConst $lciWM_SYSCommand = 274GlobalConst $lciSC_MonitorPower = 61808GlobalConst $lciPower_Off = 2GlobalConst $lciPower_On = -1Global $MonitorIsOff = Falseif ($CmdLine[0] <> 0) then
      _Monitor_OFF()
    endifWhile1
      Sleep(10)
    WEnd
    Func _Monitor_ON()
      $MonitorIsOff = False
      Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
      DllCall('user32.dll', 'int', 'SendMessage', _
                                                  'hwnd', $Progman_hwnd, _
                                                  'int', $lciWM_SYSCommand, _
                                                  'int', $lciSC_MonitorPower, _
                                                  'int', $lciPower_On)
    EndFunc
    Func _Monitor_OFF()
      $MonitorIsOff = True
      Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
      While $MonitorIsOff = True
        DllCall('user32.dll', 'int', 'SendMessage', _
                                                    'hwnd', $Progman_hwnd, _
                                                    'int', $lciWM_SYSCommand, _
                                                    'int', $lciSC_MonitorPower, _
                                                    'int', $lciPower_Off)
        _IdleWaitCommit(0)
        Sleep(20)
      WEnd
    EndFunc
    Func _IdleWaitCommit($idlesec)
      Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
      DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
      DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
      Do
        $iSave = DllStructGetData ($LastInputInfo, 2)
        Sleep(60)
        DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
      Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = FalseReturn DllStructGetData ($LastInputInfo, 2)-$iSave
    EndFunc
    Func _Quit()
      _Monitor_ON()
      Exit
    EndFunc
    

    The started program is controlled by three keys: F10 turns on the monitor, F11 turns it off, and the ESC button ends the program and unloads it from memory. If you set any parameter when the program starts, the program that is running will immediately turn off the screen.

    Now everything was fine - before going to sleep, I just ran bck_all.bat, instead of “Turn off computer” and went to sleep. The monitor did not illuminate the entire room, synchronization was performed automatically and its success was automatically analyzed. In the morning, it was necessary only to look at the contents of the folder D: \ Sync \ GoodSync \ LOG \ for at least some files. But this is also not the case - why waste time if everything is fine? It is necessary to make a log analyzer log analyzer and hang it in autoload of the system so that it will work the next day when the computer is booted and disturbed my attention only when synchronization fails. This is how the check_file_exist program appeared.

    ; Check File Exist 1.0
    ; Программа предназначена для проверки наличия указанного файла
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Res_Field=ProductName|Check File Exist#AutoIt3Wrapper_Res_Fileversion=1.0.0.0#AutoIt3Wrapper_Res_Field=OriginalFilename|check_file_exist.exe#AutoIt3Wrapper_Res_Comment=Программа предназначена для проверки наличия указанного файла#AutoIt3Wrapper_Res_Description=Провека существования файла
    ;****
    #AutoIt3Wrapper_Res_Language=1049#AutoIt3Wrapper_Res_ProductVersion=1.0#AutoIt3Wrapper_Compile_Both=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    ;AutoItSetOption ("WinTitleMatchMode", 2) ; сопоставление заголовка окна с произвольным фрагментом
    ;#NoTrayIcon ; скрыть иконку из трея во время выполнения программы
    If WinExists('[CLASS:AutoIt v3;TITLE:' & @ScriptName & ']') Then
    	MsgBox(48, @ScriptName, "Позволено запускать только одну копию программы!");
    	;Раскоментируйте следующую строчку если нужно активировать окно вашей программы при повторном её запуске
        ;WinActivate('Имя вашей программы')
        Exit
    EndIf
    AutoItWinSetTitle(@ScriptName)
    #include <Array.au3>#include <_FileDirList.au3>
    ; настройки
    Local $msg_title = "Check File Exist 1.0"
    Local $path = @ScriptDir
    Local $soft_open_dir = "explorer.exe"
    Local $path, $dir_analyse, $words, $msg_open
    ;проверка и загрузка параметров
    if ($CmdLine[0] < 5) then
      MsgBox(0x10, $msg_title, "Отсутствуют или недостаточно параметров!" & @CRLF & @CRLF & "Работа программы прекращена")
      Exit
    else
      $dir_analyse = $CmdLine[1]
      $file = $CmdLine[2]
      $words0 = $CmdLine[3]
      $words1 = $CmdLine[4]
      if (StringCompare($CmdLine[5], "msg_on") = 0) then
        $msg_open = 1
      elseif (StringCompare($CmdLine[5], "msg_off") = 0) then
        $msg_open = 0else
        MsgBox(0x10, $msg_title, "Пятый параметр должен принимать значения 'msg_on' или 'msg_off'!" & @CRLF & @CRLF & "Работа программы прекращена")
        Exit
      endif
    endIf
    ; сканирование директории на наличие файлов
    $dir_arr = _FileDirList($dir_analyse, "*"&$file&"*", 1, 0, 0)
    ;_ArrayDisplay($dir_arr)
    ; проверка наличия файла и действия
    if ($dir_arr = 0) thenif (StringCompare($words0, "0") <> 0) thenif ($msg_open = 0) then
          MsgBox(0x41030, $msg_title, $words0)
        elseif (MsgBox(0x41034, $msg_title, $words0 & @CRLF & @CRLF & "Открыть папку с не обнаруженными файлами?")) = 6then
            ShellExecuteWait($soft_open_dir, $dir_analyse)
          endif
        endif
      endif
    elseif (StringCompare($words1, "0") <> 0) thenif ($msg_open = 0) then
          MsgBox(0x41030, $msg_title, $words1)
        elseif (MsgBox(0x41034, $msg_title, $words1 & @CRLF & @CRLF & "Открыть папку с обнаруженными файлами?")) = 6then
            ShellExecuteWait($soft_open_dir, $dir_analyse)
          endif
        endif
      endif
    endif
    Exit
    

    In essence, this program is a slightly trimmed log_analyser functionality. The program analyzes the specified folder (excluding subfolders) for the presence of files and names that at least partially coincide with the specified search word and displays a message about the result of the scan.

    Program parameters:

    1 - the full path to the folder (without the slash symbol - /)
    2 - the keyword to search for in the file names, or the full file name
    3 - a text string, the file output when the file is not found, if = 0 - do not display the message
    4 - text line displayed when a file is found, if = 0 - do not display message
    5 - message output: msg_off - only a message about the presence / absence of files is displayed, msg_on - in the displayed window it is also proposed to open the folder in which files are found or not detected

    Now, for this program, I created the Check_LOG_from_log_analyser.bat script, the link of which I placed in the usual Windows startup:

    @set dir=%~dp0LOG
    start check_file_exist.exe %dir% .log 0 "Во время последней синхронизации были проблемы!" msg_on
    exit

    Thus, in the final, we received a completely autonomous solution that does not depend on the location of the Sync folder and will work correctly from anywhere on our computer. The solution is not only efficient, but also stable - on Windows 7 x64 this set of scripts worked for a year and there were absolutely no problems with it.

    Perhaps now all this seems somewhat monstrous, but nothing complicated about it. If you take a close look at the AutoIt code, then the basic design is the usual if-then-else-end cycles of the same type for any programming language in which some repetitive AutoIt operators and functions are built, which are studied in just a couple of evenings. The BAT scripting language can not even be taught, since most of the solutions are typical and have long been described on the Internet. Being able to use programming is not only interesting, but it can be quite useful.

    Ode to the code from Dark Dragon




    Afterword


    To be honest, I assumed, but did not expect such a volume of articles for which I had to spend up to fifty hours. As a rule, on the Internet, installing your own cloud is reduced to sayings like: “Yes, there you have to execute several commands”. This is true - the installation is trivial. When you know what commands to enter into the console and what they mean. When you understand the essence of network routing. When you already have a working server and when you understand how to add a host to it. When you know how to install the site. That is, to use these several commands you need to have a certain amount of knowledge and experience. The purpose of these three articles is an attempt to create such baggage, having collected the necessary sufficient information in one place and to explain how to use it correctly. I sincerely hope



    Return to the beginning, to the table of contents .



    The history of creating a home cloud. Part 3. Creating a personal cloud - installing and configuring Nextcloud.
    Text version: 1.2.0.
    Date of first publication: 08.02.2018.
    Last edited on: February 08, 2018.

    Update log
    1.2.0 [08-02-2018]
    Коррекция текста.

    1.1.0 [08-02-2018]
    Коррекция текста.

    1.0.0 [08-02-2018]
    Первая версия.
    Описывается установка и настройка Nextcloud 11.0.2 в виртуальной машине VMWare, конфигурация сетевого окружения VMWare и освещаются некоторые моменты настройки, проявившиеся в процессе эксплуатации Nextcloud.



    Information for the administration of the resource (suspicion of a bug)
    Если в какой-то тег (например, code или blockquote) в вышеприведённом тексте обернуть следующую конструкцию:
    [Definition]
    failregex={«reqId»:".*",«remoteAddr»:".*",«app»:«core»,«message»:«Login failed: '.*' \(Remote IP: ''\)»,«level»:2,«time»:".*"}
    ignoreregex =

    То закрывающий тег фильтруется и оформление применяется до конца статьи! Подобный эффект проявляется именно в этом тексте, т.к. отдельно воспроизвести эффект мне не удалось. Парную корректность тегов (открыто/закрыто) проверил — вроде бы всё нормально. Методика повторения:
    — создать черновик
    — скопировать исходное форматирование этой статьи и разместить в черновике
    — в тексте, в разделе «Защита для Nextcloud» обернуть вышеуказанную конструкцию, например, цитатой
    — эффект проявляется, в цитату попадёт весь текст до конца статьи




    Also popular now: