Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GalaxeTV/mc-pterocopy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.1
Choose a base ref
...
head repository: GalaxeTV/mc-pterocopy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 168 additions and 11 deletions.
  1. +76 −0 .github/workflows/codeql.yml
  2. +20 −0 .github/workflows/dependency-review.yml
  3. +1 −1 .github/workflows/pylint.yml
  4. +18 −0 .github/workflows/qodana.yml
  5. +28 −8 README.md
  6. +1 −0 qodana.yaml
  7. +2 −2 requirements.txt
  8. +22 −0 sync.py
76 changes: 76 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '0 0 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
18 changes: 18 additions & 0 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Qodana
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
qodana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.2.6
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
# mcserver-ftp-sync
# mc-pterocopy

Syncs Minecraft servers with staging and production
Copies a production Minecraft server to a developer Minecraft server

> **Note**
>
> This is now archived as of 09/18/2023. The script _should_ still work, however there will be no more maintenance done to this project.
## Prerequisites

* A Minecraft server running on a hosted provider (e.g. Apex Hosting, etc.) [Production Server]
* A Minecraft server running on a Pterodactyl Panel [Staging Server]
* wget (for downloading from the FTP server)
* This is already installed on most Linux distributions
* On Windows, you can install it with [chocolatey](https://chocolatey.org/) by running `choco install wget`
* On Windows, you can install it with [chocolatey](https://chocolatey.org/) by running `choco install wget`, *however it is untested*
* Python 3.8+
* API Credentials to access the FTP server and the Pterodactyl Panel
* API keys and FTP Credentials to access the FTP server and the Pterodactyl Panel
* Specific permissions needed are all files permissions and the ability to stop and start the server

## How to use
## Setting up an API access key

> **Note**
>
> This can be run as any user on the panel, but it is recommended to create a new subuser that only has full `power` and `file` permissions access for this purpose. **This is NOT the same as the Application API key.**
1. Log into the panel
2. Click on the user icon in the top right corner
3. Click on "API Credentials"
4. Click on "Create New API Key"
5. Give the key a name and click "Create Key"
6. Copy the key and save it to the `.env` file as the `STAGING_API_KEY` value (see [Example configuration](#example-configuration))

## How to use script

1. Clone repository
2. `cp .env.example .env` to create the `.env` file
3. Modify `.env` to your specified settings
4. `pip install -r requirements.txt` to install the required Python dependencies
5. `python3 sync.py` to run the sync script
5. `python3 .\sync.py` to run the sync script

The sync script will automatically detect if the server is running or not and will stop it if it is running.

> **Note**
> Depending on the size of the server, it may take a while to sync.
>
> Depending on the size of the server, it may take a while to sync. The script will print out the progress of the sync. It will also **delete any files that are on the staging server** but NOT on the production server.
## Example configuration

```env
# Production server related settings
PRODUCTION_SERVER="" # The IP address of the server without the ftp:// prefix
PRODUCTION_SERVER="" # The URL of the FTP server without the ftp:// prefix
PRODUCTION_USERNAME="" # The username to access the FTP server
PRODUCTION_PASSWORD="" # The password to access the FTP server
1 change: 1 addition & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bootstrap: pip install -r requirements.txt
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
py_dactyl==2.0.0
py_dactyl==2.0.3
python-dotenv==1.0.0
requests==2.28.2
requests==2.31.0
22 changes: 22 additions & 0 deletions sync.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
"""

import os
import shutil
import sys
import time
import requests
@@ -28,8 +29,10 @@ def main():
"""
download_ftp()
stop_server()
delete_remote_files()
upload_files()
start_server()
delete_local_files()


def download_ftp():
@@ -92,6 +95,25 @@ def start_server():
api.client.servers.send_power_action(server, "start")
print("Server started")

def delete_remote_files():
"""_summary_ Deletes files from the files directory
"""
print("Deleting files on mirrored instance...")
dict_files = api.client.servers.files.list_files(server, "/")
file_names = []
for file in dict_files["data"]:
file_names.append(file["attributes"]["name"])

api.client.servers.files.delete_files(server, file_names, "/")

print("Files deleted")

def delete_local_files():
"""_summary_ Deletes files from the files directory
"""
print("Deleting local files...")
shutil.rmtree("./files")
print("Local files deleted")

if __name__ == "__main__":
main()