-
-
Notifications
You must be signed in to change notification settings - Fork 0
make-screenshots script #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| config.php | ||
| public/components | ||
| public/screenshots | ||
| vendor |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||||||||
| #!/usr/bin/env php | ||||||||||||||
| <?php | ||||||||||||||
|
|
||||||||||||||
| use | ||||||||||||||
| amateur\model\cache, | ||||||||||||||
| amateur\model\db, | ||||||||||||||
| amateur\model\runtime, | ||||||||||||||
| amateur\model\table; | ||||||||||||||
|
|
||||||||||||||
| require_once dirname(__DIR__) . '/bootstrap.php'; | ||||||||||||||
|
|
||||||||||||||
| replaceable('request_host', function () { return 'localhost:8002'; }); | ||||||||||||||
|
|
||||||||||||||
| $screenshot_extension = 'png'; | ||||||||||||||
| $screenshot_base_dir = root_dir . '/public/screenshots/'; | ||||||||||||||
| $screenshot_base_url = absolute_url('/screenshots/'); | ||||||||||||||
|
|
||||||||||||||
| $user = table('users')->get_one('login', 'znarf'); | ||||||||||||||
| $marks = model('marks')->from_user($user, ['limit' => 1000]); | ||||||||||||||
|
|
||||||||||||||
| foreach ($marks['items'] as $mark) { | ||||||||||||||
| error_log("Checking {$mark->url}"); | ||||||||||||||
|
|
||||||||||||||
| $screenshot = table('screenshots')->for_mark($mark); | ||||||||||||||
| if (!empty($screenshot['url'])) { | ||||||||||||||
| error_log("Existing {$screenshot['url']}"); | ||||||||||||||
| continue; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $parsed_url = parse_url($mark->url); | ||||||||||||||
| if (empty($parsed_url['host'])) { | ||||||||||||||
| continue; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $folder = date("Y/m/d/" , time() - date('Z') ); | ||||||||||||||
| $relative = $folder . md5($mark->url) . '.' . $bm_screenshot_extension; | ||||||||||||||
| $screenshot_absolute_path = $screenshot_base_dir . $relative; | ||||||||||||||
| $screenshot_absolute_url = $screenshot_base_url . $relative; | ||||||||||||||
|
|
||||||||||||||
| if (!file_exists($screenshot_absolute_path)) { | ||||||||||||||
| $parameters = [ | ||||||||||||||
| 'url' => $parsed_url['host'], | ||||||||||||||
|
||||||||||||||
| 'url' => $parsed_url['host'], | |
| 'url' => $mark->url, |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers for suspicious file sizes should be defined as named constants or documented with comments explaining what these specific sizes represent.
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable $screenshot_dir is undefined. It should be $screenshot_base_dir which is defined on line 15.
| if (!is_dir($screenshot_dir . $folder)) { | |
| error_log("Creating {$folder}"); | |
| mkdir($screenshot_dir . $folder, 0777, true); | |
| if (!is_dir($screenshot_base_dir . $folder)) { | |
| error_log("Creating {$folder}"); | |
| mkdir($screenshot_base_dir . $folder, 0777, true); |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting file permissions to 0777 makes the file world-writable, which is a security risk. Consider using more restrictive permissions like 0644 or 0755.
| chmod($screenshot_absolute_path, 0777); | |
| chmod($screenshot_absolute_path, 0644); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable
$bm_screenshot_extensionis undefined. It should be$screenshot_extensionwhich is defined on line 14.