Skip to content

Commit

Permalink
Merge branch 'main' of github.com:chemage/it.marcelgerber.ch
Browse files Browse the repository at this point in the history
  • Loading branch information
bncmge committed Oct 13, 2023
2 parents 5458626 + e165439 commit fb3d2c5
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 29 deletions.
27 changes: 27 additions & 0 deletions _drafts/2023-10-12-create-jekyll-blog-on-github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Create a blog with Jekyll on GitHub
date: 2023-10-12 18:00:00 +0200
categories: howto
tags: website jekyll github
---

# {{ title }}

## Short Steps

1. Install Ruby on your development platform.
https://www.ruby-lang.org/en/documentation/installation/
1. Install RubyGems and Jekyll as normal user.
https://jekyllrb.com/docs/installation/
```bash
gem install jekyll bundler
```
1. Create a repository on GitHub.
Consider browsing and choosing a theme, as it's easiest to use a theme repository as template for your web site.
1. Create CNAME file for the repository.
1. Configure Jekyll action for the repository.
1. Configure your DNS records if using a custom domain name.
1. Bundle your repository.
```bash
bundle
```
53 changes: 53 additions & 0 deletions _posts/2023-10-12-ask-chatgpt-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Ask ChatGPT 4
date: 2023-10-12 20:00:00 +0200
categories: story
tags: python programming ai machine-learning automation
---

# How to build a script with ChatGPT 4

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's request to his team member Rosy to build a script which could push Checkpoint firewall policies.

The goal of the script is to push all firewall policies to sometimes multiple targets per policy without overloading the management server.

I started by stating a simple query.

```
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.
```

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 `main.py`. The policies to be pushed had to be specified in the script.

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 `.env` file. I had to provide the link to the `cp-mgmt-api-sdk` library so it would use it.

I needed to tell Chat that I didn't want to list my policies, but that he should read the list from the API.

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.

Another thing which was not quite good enough was the policy push itself.
1. It did all the policy push one after another.
1. No target was specified for the policy installation.

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.

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.

On and on it went for over an hour. All in all, it'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's almost human in behaviour.

It's very impressive to build up a small project like that from scratch. In the end, it'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.

I didn't test it yet. It might not even work at all. But the global structure is there.

It's a new way of programming.

-

for this to work, you need ChatGPT 4 and enable the `browsing with Bing` beta setting.

## Reference

- [Chat history](https://chat.openai.com/share/af1c3afc-0cbe-4a23-94d5-fb00837f453c)<br>
The complete history of what I asked and what was returned by ChatGPT4.
- [Code rendered](https://github.com/chemage/cp_policy_push)<br>
All the files in here have been rendered by ChatGPT4.
57 changes: 28 additions & 29 deletions _posts/2023-10-12-configure-pcloud-oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags: automation backup pCloud oauth2
## Configure pCloud OAuth2
1. Open the OAuth2 app page:
https://docs.pcloud.com/my_apps/
2. Create a new app.
1. Create a new app.
![Selection_013.png](/assets/img/blog/2023/10/12/Selection_013.png)
3. Open the settings.
1. Open the settings.
![Selection_014.png](/assets/img/blog/2023/10/12/Selection_014.png)
4. Configure the redirect URI.
1. Configure the redirect URI.
![Selection_017.png](/assets/img/blog/2023/10/12/Selection_017.png)
5. Create the root folder in my.pcloud.com.
1. Create the root folder in my.pcloud.com.
![Selection_015.png](/assets/img/blog/2023/10/12/Selection_015.png)
6. Copy new folder's ID from the URL.
1. Copy new folder's ID from the URL.
![Selection_018.png](/assets/img/blog/2023/10/12/Selection_018.png)

## Configure rclone
Expand All @@ -34,12 +34,12 @@ q) Quit config
e/n/d/r/c/s/q> n
```

2. Name the new remote.
1. Name the new remote.
```
name> pcloud_backup
```

3. Select 25 for pCloud storage.
1. Select 25 for pCloud storage.
```
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Expand Down Expand Up @@ -118,32 +118,32 @@ Storage> 25
** See help for pcloud backend at: https://rclone.org/pcloud/ **
```

4. Copy the client ID of your new pCloud app.
1. Copy the client ID of your new pCloud app.
```
Auth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> zQg0smNw8tp
```

5. Copy the client secret of your new pCloud app.
1. Copy the client secret of your new pCloud app.
```
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> 2OSmU2xW6gYaLLCaPPIUg5T5EvX7
```

6. Edit the advanced settings.
1. Edit the advanced settings.
```
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> y
```

7. Press `Enter` until you get to the `root_folder_id`. Copy your folder ID from the pCloud folder which will serve as root for the application.
```
1. Press `Enter` until you get to the `root_folder_id`. Copy your folder ID from the pCloud folder which will serve as root for the application.
```text
OAuth Access Token as a JSON blob.
Enter a string value. Press Enter for the default ("").
token>
Expand All @@ -156,7 +156,7 @@ Leave blank to use the provider defaults.
Enter a string value. Press Enter for the default ("").
token_url>
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 ("Slash,BackSlash,Del,Ctl,InvalidUtf8,Dot").
encoding>
Expand All @@ -165,25 +165,24 @@ Enter a string value. Press Enter for the default ("d0").
root_folder_id> 19066333043
```

7. Choose your region.
1. Choose your region.
```
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 ("api.pcloud.com").
Choose a number from below, or type in your own value
1 / Original/US region
\ "api.pcloud.com"
2 / EU region
\ "eapi.pcloud.com"
hostname> 1
```

8. On the pCloud API, set the redirect URI to `http://localhost:53682/`.
1. On the pCloud API, set the redirect URI to `http://localhost:53682/`.
```
Remote config
Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config.
Expand All @@ -198,16 +197,16 @@ Log in and authorize rclone for access
Waiting for code...
```

9. Your default browser should open, connect to your account.
![Selection_019.png](https://marcels-it.ghost.io/content/img/2023/10/Selection_019.png)
1. Your default browser should open, connect to your account.
![Selection_019.png](/assets/img/blog/2023/10/12/Selection_019.png)

10. Allow the app to access.
![Selection_020.png](https://marcels-it.ghost.io/content/img/2023/10/Selection_020.png)
1. Allow the app to access.
![Selection_020.png](/assets/img/blog/2023/10/12/Selection_020.png)

11. The redirection should show you a simple success page.
![Selection_021.png](https://marcels-it.ghost.io/content/img/2023/10/Selection_021.png)
1. The redirection should show you a simple success page.
![Selection_021.png](/assets/img/blog/2023/10/12/Selection_021.png)

12. Close the browser window and return to rclone config.
1. Close the browser window and return to rclone config.
```
Got code
--------------------
Expand All @@ -229,9 +228,9 @@ y/e/d> y
1. Open pCloud "Settings -> Linked Accounts".
https://my.pcloud.com/#page=settings&settings=tab-apps

2. In the __Linked Apps__ section you will find your application and you can see it's limited to a specific folder.
![Selection_022.png](https://marcels-it.ghost.io/content/img/2023/10/Selection_022.png)
1. In the __Linked Apps__ section you will find your application and you can see it's limited to a specific folder.
![Selection_022.png](/assets/img/blog/2023/10/12/Selection_022.png)

## References
- https://docs.pcloud.com/methods/oauth_2.0/
- https://pypi.org/project/pcloud/
- [pCloud OAuth2 documentation](https://docs.pcloud.com/methods/oauth_2.0/)
- [Python Pi pCloud package](https://pypi.org/project/pcloud/)
3 changes: 3 additions & 0 deletions _tabs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ After about ten years of experience as a Windows systems engineer (including a f

For hobbies, Marcel loves a quiet evening with a book or netflixing, a round of craft beers with friends, traveling to remote places, scuba diving, motorcycling, photography, mountain hiking and more.

![Albania 2023](/assets/img/about/albania-2023.jpg)<br>
"Fier" means proud in French. So I was being proud in Albania on my recent motorcycle trip through the Balkans.

Binary file added assets/img/about/albania-2023.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/blog/2023/10/12/Selection_019.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/blog/2023/10/12/Selection_020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/blog/2023/10/12/Selection_021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/blog/2023/10/12/Selection_022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions comment-guidelines.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
layout: page
title: Comments Guidelines
---

# {{ site.title }}
Expand Down

0 comments on commit fb3d2c5

Please sign in to comment.