'How to send a binary mask file from C++ CGI

I'm trying to send a mask file from CGI get request.

I have no compilation errors. But have a error 500 error with Apache2. i'm not shure how to send the data and co-pilot do not help a lot.

But if i can receive the mask SHA512 sum as string variable (it is the mask final filename) (how to get stdout ouput from system in a variable) (execl dont support pipe) maybe i can put an php header() like function in c++ to send the file ?

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <typeinfo>
#include <unistd.h>
using namespace std;
string gen_random(int len)
{
    string s;
    static const char alphanum[] =
        "0123456789"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < len; ++i)
    {
        s += alphanum[rand() % (sizeof(alphanum) - 1)];
    }

    return s;
}
std::string get_env_var(std::string const &key)
{
    char *val;
    val = getenv(key.c_str());
    std::string retval = "";
    if (val != NULL)
    {
        retval = val;
    }
    return retval;
}
int main()
{
    string a, b, name, value, action;
    int i = 0;
    int j = 0;
    string v;
    int v2;
    string line;
    string val = get_env_var("REQUEST_METHOD");
    if (val == "GET")
    {
        string q = get_env_var("QUERY_STRING");
        stringstream ss2(q);
        while (getline(ss2, line, '&'))
        {
            stringstream ss(line);
            string token2;
            while (getline(ss, token2, '='))
            {
                if (i == 0)
                {
                    name = token2;
                }
                else if (i == 1)
                {
                    value = token;
                }
                i++;
            }
            i = 0;
            if (name == "action")
            {
                action = value;
            }
            else if (name == "value")
            {
                v = value;
                v2 = stoi(v.c_str());
            }
        }
        if (action == "getRandomFile")
        {
            stringstream ss;
            ss << "Content-Type: application/octet-stream" << endl << endl; 
            ss << "Content-Length: " << v2 << endl << endl;;
            int error = 0;
            char mychar[1];
            char mychar2[1];
            fstream fout2;
            fout2.open("temp.bin", ios::out | ios::app);
            ifstream urandom;
            urandom.open("/dev/urandom", ios::in | ios::binary);
            // ss << getline(urandom, byte, length);
            string s;
            const string maskName = "temp.bin";
            while (error != 1)
            {
                while (!(cin.get(mychar[0]) && i < v2))
                {
                    error = 1;
                    i = 0;
                    break;
                }
                if (error == 0)
                {
                    fout2 << (char)mychar2[0];
                    ss << (char)mychar2[0];
                    i++;
                }
            }
            fout2.close();
            const string s2 = "mv temp.bin $(shasum temp.bin | awk '{print $1}')";
            // rename (maskName.c_str(), s3.c_str());
            system(s2.c_str());
            cout << ss.c_str();
        }
    }
}


Solution 1:[1]

In the first case, whenever a bot tries to modify the:

  • Nickname
  • Role

Or tries to:

  • Kick
  • Ban
  • Timeout

a user, Discord will check if the user is allowed to do so. This is checked by Discord looking if the bot has a role higher, then the highest role the user it tries to effect has..

In JDA, there should be a util for this. PermissionUtil.canInteract(Member, Member). However, as far as I could find. This is something JDA internal, and should not be used.

In your case, you are either above the bot, or you're the owner. (Whom is always the highest and always has admin)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 stefano