Skip to content
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

Internal Upgrader + Latest PHPMyAdmin #1139

Merged
merged 12 commits into from
Jan 6, 2024
Merged

Internal Upgrader + Latest PHPMyAdmin #1139

merged 12 commits into from
Jan 6, 2024

Conversation

master3395
Copy link
Contributor

One step closer.

So far, it doesn't seem to upgrade, but it has the option to find all branches, and it does say it starts the upgrade.
@master3395 master3395 marked this pull request as draft October 23, 2023 22:04
@usmannasir
Copy link
Owner

I am sorry I didnt see your pull request yesterday. i've made some changes and installation is working but the upgrade via ui still does not work.

@usmannasir
Copy link
Owner

See last three commits: https://github.com/usmannasir/cyberpanel/commits/v2.3.5-dev

@master3395 master3395 changed the base branch from stable to v2.3.5-dev November 10, 2023 22:23
@master3395 master3395 changed the title V2.3.5 dev Internal Upgrader + Latest PHPMyAdmin Nov 10, 2023
Still not finished.
Fixed theme for the buttons and dropdown.
@master3395
Copy link
Contributor Author

For some reason, the upgrade button don't have access to this file location: /usr/local/CyberCP/cyberpanel_upgrade.sh
Same if I try to use the command, to do it through shell from the web.
Any suggestions?

sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

@master3395
Copy link
Contributor Author

I made good buttons and branch chooser, but it seems to be refused future access :/

image
image

@usmannasir
Copy link
Owner

For some reason, the upgrade button don't have access to this file location: /usr/local/CyberCP/cyberpanel_upgrade.sh Same if I try to use the command, to do it through shell from the web. Any suggestions?

sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

I am sorry, I did not understand exactly?

@master3395
Copy link
Contributor Author

For some reason, the upgrade button doesn't have access to this file location: /usr/local/CyberCP/cyberpanel_upgrade.sh Same if I try to use the command, to do it through shell from the web. Any suggestions?
sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

I am sorry, I did not understand exactly?

What I mean is.
I am trying to implement the same setup that is for installing Mailscanner, to try and upgrade CyberPanel, with the cmd window, showing the progress.
But for some reason, when I click upgrade, the server refuses me from accessing this location, if I try upgrading from here: /usr/local/CyberCP/cyberpanel_upgrade.sh

Using this location gives me an error if I let the script change the branch from /stable/ to something else.
sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

What if i put it as a script in the CPScripts, will CyberPanel accept that path easier?
https://github.com/usmannasir/cyberpanel/tree/v2.3.5-dev/CPScripts

Added Upgrade Progress Log that works.
But upgrader does still not fully work.
@master3395
Copy link
Contributor Author

image

@usmannasir
Copy link
Owner

For some reason, the upgrade button doesn't have access to this file location: /usr/local/CyberCP/cyberpanel_upgrade.sh Same if I try to use the command, to do it through shell from the web. Any suggestions?
sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

I am sorry, I did not understand exactly?

What I mean is. I am trying to implement the same setup that is for installing Mailscanner, to try and upgrade CyberPanel, with the cmd window, showing the progress. But for some reason, when I click upgrade, the server refuses me from accessing this location, if I try upgrading from here: /usr/local/CyberCP/cyberpanel_upgrade.sh

Using this location gives me an error if I let the script change the branch from /stable/ to something else. sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh

What if i put it as a script in the CPScripts, will CyberPanel accept that path easier? https://github.com/usmannasir/cyberpanel/tree/v2.3.5-dev/CPScripts

Can you tell me exactly how are you running it? Also installing mailscanner is different, reason is upgrading CyberPanel itself disconnect it from the CyberPanel.

Which might be causing issue in your case?

@master3395
Copy link
Contributor Author

I am trying to run the upgrader through the shell setup, like the live shell we had in 2.3.2 if I remember the number right.
Idk why it was removed, but using https://raw.githubusercontent.com/usmannasir/cyberpanel/${selectedBranch}/preUpgrade.sh
To run it in Shell, with the desired branch from the dropdown menu.

This is the upgrade function:
image

Then when it is installing, I only wanted the log window (The shell view) to show the progress of the upgrade, just like normal SSH is showing the upgrade of CyberPanel.

But the most important part is to be notified once the upgrade is done, or that it is still doing it's thing.
Perhaps even run in the background, in case you close the browser etc.

So we continue to see the status if we return to the versionManagment.html

My main issue is the branch checking seems to be failing, because of invalid character.
I have been trying to fix that.

21:31:58.056 versionManagment:1813 Upgrade response: ObjecterrorMessage: "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >."error_message: "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >."[[Prototype]]: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()__proto__: (...)get __proto__: ƒ __proto__()length: 0name: "get __proto__"arguments: (...)caller: (...)[[Prototype]]: ƒ ()[[Scopes]]: Scopes[0]set __proto__: ƒ __proto__()length: 1name: "set __proto__"arguments: (...)caller: (...)[[Prototype]]: ƒ ()[[Scopes]]: Scopes[0]
21:31:58.056 versionManagment:1821  Invalid progress value received from the server: undefined
(anonymous) @ versionManagment:1821
Promise.then (async)
upgradeCyberPanel @ versionManagment:1811
onclick @ versionManagment:1710

versionManagment.html

{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Version Management - CyberPanel" %}{% endblock %}

{% block content %}

{% load static %}

<style>
    /* Add these styles for the buttons and select dropdown */
    .button-style,
    #branchSelect {
        background-color: rgb(62, 72, 85);
        color: #fff;
        padding: 10px 20px;
        border: none;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    /* Apply these styles when hovering over the buttons or select dropdown */
    .button-style:hover,
    #branchSelect:hover {
        background-color: darken(rgb(62, 72, 85), 10%);
    }

    /* Add these styles for the textarea */
    textarea {
        background-color: rgb(62, 72, 85);
        color: #fff;
    }
</style>

<div class="container">
    <div id="page-title">
        <h2>{% trans "Version Management" %}</h2>
        <p>{% trans "Here you can manage versions and check for updates to CyberPanel" %}</p>
    </div>
    {% if Notecheck %}
        <div class="alert alert-info">
            <p style="color:red; font-weight: bold;">{% trans "Note: Latest commit does not match, please upgrade CyberPanel." %}</p>
        </div>
    {% endif %}

    <div class="panel">
        <div class="panel-body">
            <h3 class="title-hero">
                CyberPanel
            </h3>
            <div ng-controller="versionManagment" class="example-box-wrapper">
                <div class="form-group">
                    <label for="branchSelect">{% trans "Select Branch:" %}</label>
                    <select id="branchSelect" class="button-style"></select>
                </div>
                <div class="form-group">
                    <button type="submit" onclick="upgradeCyberPanel()" class="button-style">{% trans "Upgrade CyberPanel to selected branch" %}</button>
                    <button type="submit" onclick="refreshPage()" class="button-style line-over">{% trans "Refresh page" %}</button>
                </div>

                <form action="/" class="form-horizontal bordered-row">
                    <!-- Existing Commit Information -->
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Current Version:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ currentVersion }}</div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Build:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ build }}</div>
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Current Commit:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ Currentcomt }}</div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Latest Version:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ latestVersion }}</div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Latest Build:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ latestBuild }}</div>
                       <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Latest Commit:" %}&nbsp&nbsp</label>
                        <div class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;">{{ latestcomit }}</div>
                    </div>

                    <!-- New Upgrade Progress Log Section -->
                    <div class="form-group">
                        <label class="col-sm-3 control-label" style="margin: 0px!important; padding: 0px!important;">{% trans "Upgrade Progress Log:" %}</label>
                        <div id="upgradeProgressLog" class="current-pack col-sm-9" style="margin: 0px!important; padding: 0px!important;"></div>
                    </div>
                </form>

                <div ng-hide="upgradelogBox" class="form-group">
                    <div class="col-sm-12">
                        <textarea ng-model="upgradeLog" rows="30" class="form-control">{{ logs }}</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // Function to populate the branch dropdown
    function populateBranches(branches) {
        var branchSelect = document.getElementById("branchSelect");
        branches.forEach((branch) => {
            var option = document.createElement("option");
            option.value = branch;
            option.text = branch;
            branchSelect.appendChild(option);
        });
    }

    function getBranches(url, branches, page) {
        if (!page) page = 1;
        fetch(url + '?page=' + page)
            .then((response) => response.json())
            .then((data) => {
                if (data.length === 0) {
                    populateBranches(branches);
                } else {
                    const branchNames = data.map(branch => branch.name);
                    branches = branches.concat(branchNames);
                    getBranches(url, branches, page + 1);
                }
            })
            .catch((error) => {
                console.error('Error fetching branches: ' + error);
            });
    }

    // Call the function to get all branches
    getBranches('https://api.github.com/repos/usmannasir/cyberpanel/branches', [], 1);

    function upgradeCyberPanel() {
        try {
            var selectedBranch = document.getElementById("branchSelect").value;

            // Use the shell script URL based on the selected branch
            var shellScriptUrl = `https://raw.githubusercontent.com/usmannasir/cyberpanel/${selectedBranch}/cyberpanel_upgrade.sh`;

            if (confirm("Are you sure you want to upgrade to the selected branch from the remote script?")) {
                // Use fetch to trigger a server-side action (execute shell script)
                fetch('/upgrade', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        scriptUrl: shellScriptUrl,
                    }),
                })
                    .then(response => {
                        if (!response.ok) {
                            throw new Error(`Failed to start upgrade. HTTP status ${response.status}`);
                        }
                        return response.json();
                    })
                    .then(data => {
                        // Log the response from the server
                        console.log('Upgrade response:', data);

                        // Check if the progress value is a finite number before setting it on the progress bar
                        if (isFinite(data.progress)) {
                            var upgradeProgressLog = document.getElementById("upgradeProgressLog");
                            upgradeProgressLog.innerText = 'Upgrade Progress: ' + data.progress + '%';
                            // You may also update other UI elements based on the response data
                        } else {
                            console.error('Invalid progress value received from the server:', data.progress);
                            var upgradeProgressLog = document.getElementById("upgradeProgressLog");
                            upgradeProgressLog.innerText = 'Upgrade failed. Invalid progress value received from the server.';
                        }
                    })
                    .catch(error => {
                        console.error('Upgrade failed. Error starting upgrade:', error);
                        alert('Upgrade failed. Error starting upgrade. Check the console for details.');
                    });

                // Download and execute the upgrade script using wget
                fetch(shellScriptUrl)
                    .then(response => response.text())
                    .then(scriptContent => {
                        // Create a Blob from the script content
                        var blob = new Blob([scriptContent], { type: 'text/plain' });

                        // Create a temporary URL for the Blob
                        var scriptUrl = URL.createObjectURL(blob);

                        // Create an invisible iframe to trigger the download
                        var iframe = document.createElement('iframe');
                        iframe.style.display = 'none';
                        iframe.src = scriptUrl;
                        document.body.appendChild(iframe);
                    })
                    .catch(error => {
                        console.error('Failed to download upgrade script:', error);
                        alert('Failed to download upgrade script. Check the console for details.');
                    });
            }
        } catch (error) {
            console.error('An unexpected error occurred:', error);

            // Additional error handling
            alert('An unexpected error occurred during the upgrade. Check the console for details.');

            // Log detailed error information
            console.error('Detailed error information:', error);
        }
    }

    function refreshPage() {
        location.reload();
    }

</script>

{% endblock %}

@usmannasir
Copy link
Owner

I am trying to run the upgrader through the shell setup, like the live shell we had in 2.3.2 if I remember the number right. Idk why it was removed, but using https://raw.githubusercontent.com/usmannasir/cyberpanel/${selectedBranch}/preUpgrade.sh To run it in Shell, with the desired branch from the dropdown menu.

This is the upgrade function: image

Then when it is installing, I only wanted the log window (The shell view) to show the progress of the upgrade, just like normal SSH is showing the upgrade of CyberPanel.

But the most important part is to be notified once the upgrade is done, or that it is still doing it's thing. Perhaps even run in the background, in case you close the browser etc.

So we continue to see the status if we return to the versionManagment.html

My main issue is the branch checking seems to be failing, because of invalid character. I have been trying to fix that.

21:31:58.056 versionManagment:1813 Upgrade response: ObjecterrorMessage: "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >."error_message: "Data supplied is not accepted, following characters are not allowed in the input ` $ & ( ) [ ] { } ; : ‘ < >."[[Prototype]]: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()__proto__: (...)get __proto__: ƒ __proto__()length: 0name: "get __proto__"arguments: (...)caller: (...)[[Prototype]]: ƒ ()[[Scopes]]: Scopes[0]set __proto__: ƒ __proto__()length: 1name: "set __proto__"arguments: (...)caller: (...)[[Prototype]]: ƒ ()[[Scopes]]: Scopes[0]
21:31:58.056 versionManagment:1821  Invalid progress value received from the server: undefined
(anonymous) @ versionManagment:1821
Promise.then (async)
upgradeCyberPanel @ versionManagment:1811
onclick @ versionManagment:1710

versionManagment.html

This function checks the variables passed via javascript for malicious data, so if you think you need to bypass any variable you can use this

https://github.com/usmannasir/cyberpanel/blob/1ac841449eb3aabac68a4a2548b07a6cd502df2f/CyberCP/secMiddleware.py#L22C11-L22C11

Or let me know which variables are you passing from js side, so i can adjust this function accordingly.

Equal to latest version in the repository.
This removes the old .bak file, drafted 2 years ago, when we were changing from rainloop to snappymail.
secMiddleware.py This needs testing, if this change will mess up anything else.
@usmannasir Can you try this?
@master3395 master3395 marked this pull request as ready for review January 4, 2024 21:54
@usmannasir usmannasir self-assigned this Jan 6, 2024
@usmannasir usmannasir merged commit 0e59955 into usmannasir:v2.3.5-dev Jan 6, 2024
1 check passed
@usmannasir
Copy link
Owner

Merged and testing.

@usmannasir
Copy link
Owner

@master3395 which view are you calling for uri /upgrade ?

hassanhashmey pushed a commit that referenced this pull request Jan 9, 2024
hassanhashmey pushed a commit that referenced this pull request Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants