<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  
  <title>Marcel&#39;s IT blog</title>
  <subtitle>Marcel&#39;s IT tips and tricks about things not quite straightforward.</subtitle>
  <link href="https://it.marcelgerber.ch/feed.xml" rel="self" />
  <link href="https://it.marcelgerber.ch/" />
  <updated>2023-10-12T18:00:00Z</updated>
  <id>https://it.marcelgerber.ch/</id>
  <author>
    <name>Marcel Gerber</name>
    <email>me@marcelgerber.ch</email>
  </author>
  <entry>
    <title>Configure pCloud OAuth2</title>
    <link href="https://it.marcelgerber.ch/posts/configure-pcloud-oauth2/" />
    <updated>2023-10-12T10:00:00Z</updated>
    <id>https://it.marcelgerber.ch/posts/configure-pcloud-oauth2/</id>
    <content type="html">&lt;h2 id=&quot;configure-pcloud-oauth2&quot;&gt;Configure pCloud OAuth2&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Open the OAuth2 app page:
&lt;a href=&quot;https://docs.pcloud.com/my_apps/&quot;&gt;https://docs.pcloud.com/my_apps/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Create a new app.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_013.png&quot; alt=&quot;Selection_013.png&quot;&gt;&lt;/li&gt;
&lt;li&gt;Open the settings.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_014.png&quot; alt=&quot;Selection_014.png&quot;&gt;&lt;/li&gt;
&lt;li&gt;Configure the redirect URI.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_017.png&quot; alt=&quot;Selection_017.png&quot;&gt;&lt;/li&gt;
&lt;li&gt;Create the root folder in my.pcloud.com.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_015.png&quot; alt=&quot;Selection_015.png&quot;&gt;&lt;/li&gt;
&lt;li&gt;Copy new folder&#39;s ID from the URL.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_018.png&quot; alt=&quot;Selection_018.png&quot;&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;configure-rclone&quot;&gt;Configure rclone&lt;/h2&gt;
&lt;p&gt;On a machine with a web browser, install rclone and launch &lt;code&gt;rclone config&lt;/code&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new remote.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q&amp;gt; n
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Name the new remote.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;name&amp;gt; pcloud_backup
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Select 25 for pCloud storage.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Type of storage to configure.
Enter a string value. Press Enter for the default (&amp;quot;&amp;quot;).
Choose a number from below, or type in your own value
 1 / 1Fichier
   &#92; &amp;quot;fichier&amp;quot;
 2 / Alias for an existing remote
   &#92; &amp;quot;alias&amp;quot;
 3 / Amazon Drive
   &#92; &amp;quot;amazon cloud drive&amp;quot;
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, Tencent COS, etc)
   &#92; &amp;quot;s3&amp;quot;
 5 / Backblaze B2
   &#92; &amp;quot;b2&amp;quot;
 6 / Box
   &#92; &amp;quot;box&amp;quot;
 7 / Cache a remote
   &#92; &amp;quot;cache&amp;quot;
 8 / Citrix Sharefile
   &#92; &amp;quot;sharefile&amp;quot;
 9 / Dropbox
   &#92; &amp;quot;dropbox&amp;quot;
10 / Encrypt/Decrypt a remote
   &#92; &amp;quot;crypt&amp;quot;
11 / FTP Connection
   &#92; &amp;quot;ftp&amp;quot;
12 / Google Cloud Storage (this is not Google Drive)
   &#92; &amp;quot;google cloud storage&amp;quot;
13 / Google Drive
   &#92; &amp;quot;drive&amp;quot;
14 / Google Photos
   &#92; &amp;quot;google photos&amp;quot;
15 / Hubic
   &#92; &amp;quot;hubic&amp;quot;
16 / In memory object storage system.
   &#92; &amp;quot;memory&amp;quot;
17 / Jottacloud
   &#92; &amp;quot;jottacloud&amp;quot;
18 / Koofr
   &#92; &amp;quot;koofr&amp;quot;
19 / Local Disk
   &#92; &amp;quot;local&amp;quot;
20 / Mail.ru Cloud
   &#92; &amp;quot;mailru&amp;quot;
21 / Microsoft Azure Blob Storage
   &#92; &amp;quot;azureblob&amp;quot;
22 / Microsoft OneDrive
   &#92; &amp;quot;onedrive&amp;quot;
23 / OpenDrive
   &#92; &amp;quot;opendrive&amp;quot;
24 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   &#92; &amp;quot;swift&amp;quot;
25 / Pcloud
   &#92; &amp;quot;pcloud&amp;quot;
26 / Put.io
   &#92; &amp;quot;putio&amp;quot;
27 / SSH/SFTP Connection
   &#92; &amp;quot;sftp&amp;quot;
28 / Sugarsync
   &#92; &amp;quot;sugarsync&amp;quot;
29 / Transparently chunk/split large files
   &#92; &amp;quot;chunker&amp;quot;
30 / Union merges the contents of several upstream fs
   &#92; &amp;quot;union&amp;quot;
31 / Webdav
   &#92; &amp;quot;webdav&amp;quot;
32 / Yandex Disk
   &#92; &amp;quot;yandex&amp;quot;
33 / http Connection
   &#92; &amp;quot;http&amp;quot;
34 / premiumize.me
   &#92; &amp;quot;premiumizeme&amp;quot;
35 / seafile
   &#92; &amp;quot;seafile&amp;quot;
Storage&amp;gt; 25
** See help for pcloud backend at: https://rclone.org/pcloud/ **
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Copy the client ID of your new pCloud app.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Auth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default (&amp;quot;&amp;quot;).
client_id&amp;gt; zQg0smNw8tp
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Copy the client secret of your new pCloud app.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default (&amp;quot;&amp;quot;).
client_secret&amp;gt; 2OSmU2xW6gYaLLCaPPIUg5T5EvX7
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Edit the advanced settings.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n&amp;gt; y
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;Enter&lt;/code&gt; until you get to the &lt;code&gt;root_folder_id&lt;/code&gt;. Copy your folder ID from the pCloud folder which will serve as root for the application.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;OAuth Access Token as a JSON blob.
Enter a string value. Press Enter for the default (&quot;&quot;).
token&gt; 
Auth server URL.
Leave blank to use the provider defaults.
Enter a string value. Press Enter for the default (&quot;&quot;).
auth_url&gt; 
Token server url.
Leave blank to use the provider defaults.
Enter a string value. Press Enter for the default (&quot;&quot;).
token_url&gt; 
This sets the encoding for the backend.
-
See: the [encoding section in the overview](/overview/#encoding) for more info.
Enter a encoder.MultiEncoder value. Press Enter for the default (&quot;Slash,BackSlash,Del,Ctl,InvalidUtf8,Dot&quot;).
encoding&gt; 
Fill in for rclone to use a non root folder as its starting point.
Enter a string value. Press Enter for the default (&quot;d0&quot;).
root_folder_id&gt; 19066333043&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Choose your region.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Hostname to connect to.
-
This is normally set when rclone initially does the oauth connection,
however you will need to set it by hand if you are using remote config
with rclone authorize.
-
Enter a string value. Press Enter for the default (&amp;quot;api.pcloud.com&amp;quot;).
Choose a number from below, or type in your own value
 1 / Original/US region
   &#92; &amp;quot;api.pcloud.com&amp;quot;
 2 / EU region
   &#92; &amp;quot;eapi.pcloud.com&amp;quot;
hostname&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;On the pCloud API, set the redirect URI to &lt;code&gt;http://localhost:53682/&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Remote config
Make sure your Redirect URL is set to &amp;quot;http://localhost:53682/&amp;quot; in your custom config.
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n&amp;gt; 
If your browser doesn&#39;t open automatically go to the following link: http://127.0.0.1:53682/auth?state=-9WXa5fWne_0d-1IQYvwbQ
Log in and authorize rclone for access
Waiting for code...
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Your default browser should open, connect to your account.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_019.png&quot; alt=&quot;Selection_019.png&quot;&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Allow the app to access.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_020.png&quot; alt=&quot;Selection_020.png&quot;&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The redirection should show you a simple success page.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_021.png&quot; alt=&quot;Selection_021.png&quot;&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Close the browser window and return to rclone config.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;Got code
--------------------
[pcloud_backup]
client_id = zQg0smNw8tp
client_secret = 2OSmU2xW6gYaLLCaPPIUg5T5EvX7
root_folder_id = 19066333043
hostname = api.pcloud.com
token = {&amp;quot;access_token&amp;quot;:&amp;quot;AxavZzQg0smNw8tpZcyLMykZYw84XRDMtlJWkrQrRiMBc8V9dJc7&amp;quot;,&amp;quot;token_type&amp;quot;:&amp;quot;bearer&amp;quot;,&amp;quot;expiry&amp;quot;:&amp;quot;0001-01-01T00:00:00Z&amp;quot;}
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d&amp;gt; y
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;verify-your-settings-in-pcloud&quot;&gt;Verify your settings in pCloud&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Open pCloud &amp;quot;Settings -&amp;gt; Linked Accounts&amp;quot;.
&lt;a href=&quot;https://my.pcloud.com/#page=settings&amp;amp;settings=tab-apps&quot;&gt;https://my.pcloud.com/#page=settings&amp;amp;settings=tab-apps&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;Linked Apps&lt;/strong&gt; section you will find your application and you can see it&#39;s limited to a specific folder.
&lt;img src=&quot;https://it.marcelgerber.ch/assets/img/blog/2023/10/12/Selection_022.png&quot; alt=&quot;Selection_022.png&quot;&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Temporarily unencrypt rclone configuration file&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy configuration file to Synology NAS under &lt;code&gt;/docker/NAS1_rclone/config&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Encrypt configuration file again.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.pcloud.com/methods/oauth_2.0/&quot;&gt;pCloud OAuth2 documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://pypi.org/project/pcloud/&quot;&gt;Python Pi pCloud package&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Ask ChatGPT 4</title>
    <link href="https://it.marcelgerber.ch/posts/ask-chatgpt-4/" />
    <updated>2023-10-12T18:00:00Z</updated>
    <id>https://it.marcelgerber.ch/posts/ask-chatgpt-4/</id>
    <content type="html">&lt;h1 id=&quot;how-to-build-a-script-with-chatgpt-4&quot;&gt;How to build a script with ChatGPT 4&lt;/h1&gt;
&lt;p&gt;For a few days now, after talking to my friend Frédéric about ChatGPT 4 and its web browsing capabilities, I have been thinking about how to put it to use in my work. Yesterday, I finally remembered my colleague Steve&#39;s request to his team member Rosy to build a script which could push Checkpoint firewall policies.&lt;/p&gt;
&lt;p&gt;The goal of the script is to push all firewall policies to sometimes multiple targets per policy without overloading the management server.&lt;/p&gt;
&lt;p&gt;I started by stating a simple query.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Python script to push all policies using checkpoint smart console api with a list of exceptions. Logging should be done and keep 4 log files as history. 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With that, I got a simple and effective result of a single file with all the script inside. The Checkpoint query was made using cpapi. Everything was done in a single script file &lt;code&gt;main.py&lt;/code&gt;. The policies to be pushed had to be specified in the script.&lt;/p&gt;
&lt;p&gt;So I continued by telling the script to add a configuration file for the SMS connection details. Chat extended the use of the configuration file to the SMTP settings and to read secrets from a &lt;code&gt;.env&lt;/code&gt; file. I had to provide the link to the &lt;code&gt;cp-mgmt-api-sdk&lt;/code&gt; library so it would use it.&lt;/p&gt;
&lt;p&gt;I needed to tell Chat that I didn&#39;t want to list my policies, but that he should read the list from the API.&lt;/p&gt;
&lt;p&gt;Then I asked Chat to create an HTML report. First it just created a dumb record of some data. So I gave it more precision and told it to report on the status of the query.&lt;/p&gt;
&lt;p&gt;Another thing which was not quite good enough was the policy push itself.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It did all the policy push one after another.&lt;/li&gt;
&lt;li&gt;No target was specified for the policy installation.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So I had to request that a maximum of 5 policies would be pushed concurrently and informed Chat that in some cases, the policies could be pushed on multiple targets.&lt;/p&gt;
&lt;p&gt;Being thorough, I asked Chat to write the documentation and to build a Makefile to manage the virtual environment, which it did, and quite well on top of that.&lt;/p&gt;
&lt;p&gt;On and on it went for over an hour. All in all, it&#39;s really quite good. Except that with the iterations, it started forgetting things I requested earlier. So I reminded it of the omissions which it corrected rightaway. It&#39;s almost human in behaviour.&lt;/p&gt;
&lt;p&gt;It&#39;s very impressive to build up a small project like that from scratch. In the end, it&#39;s much quicker to do it like this than write everything yourself. And the code and the library choice looks also very good. The code is probably a fifth of the length of what I would have done for the same task.&lt;/p&gt;
&lt;p&gt;I didn&#39;t test it yet. It might not even work at all. But the global structure is there.&lt;/p&gt;
&lt;p&gt;It&#39;s a new way of programming.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;for this to work, you need ChatGPT 4 and enable the &lt;code&gt;browsing with Bing&lt;/code&gt; beta setting.&lt;/p&gt;
&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://chat.openai.com/share/af1c3afc-0cbe-4a23-94d5-fb00837f453c&quot;&gt;Chat history&lt;/a&gt;&lt;br&gt;
The complete history of what I asked and what was returned by ChatGPT4.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/chemage/cp_policy_push&quot;&gt;Code rendered&lt;/a&gt;&lt;br&gt;
All the files in here have been rendered by ChatGPT4.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
</feed>