Good to know

Check if certificate is valid in cli

# openssl s_client -connect petcare365.orangocloud.com:7048 | openssl x509 -noout -dates
# openssl s_client -connect sweclockers.se:443 | openssl x509 -noout -dates
# openssl s_client -connect “domain.se”:”portnumber” | openssl x509 -noout -dates

Puppeteer

Code for running a basic puppeteer app

const puppeteer = require(‘puppeteer’);

(async () => {
// Launch browser in headless mode
const browser = await puppeteer.launch({ headless: true });

// Open a new page
const page = await browser.newPage();

// Navigate to a website
await page.goto(‘https://www.aftonbladet.se/’);

// Get the title of the page
const pageTitle = await page.title();
console.log(‘Page title:’, pageTitle);

// Close the browser
await browser.close();
})();

Before make sure that

  • npm init (empty folder)
  • create index.js (or a specified in the previous step)
  • Add the above code
  • npm i puppeteer
  • node ./index.js

Now it should work. The console should output something like

Page title: Nyheter från Sveriges största nyhetssajt

iFrame element boiler code

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <!– <link rel=”stylesheet” href=”css/style_main.css”> –>
    <title>iFrame playtime</title>
</head>
<body>
    <h1>The iframe element</h1>
<iframe src=”https://wikipedia.org” width=”800″ height=”400″ name=”myiframe” title=”sportnerd”>Iframe is NOT supported by your browser
</iframe>
<hr>
<a href=”https://www.nhl.com” target=”myiframe”>NHL</a><br>
<a href=”https://www.nba.com” target=”myiframe”>NBA</a><br>
<a href=”https://mlb.com” target=”myiframe”>Major Leage</a><br>
</body>
</html>

FAll-in-One WP Migration – Limits

How to Increase Maximum Upload File Size in WordPress

Edit .htaccess file

php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300
or

Edit wp-config.php file

@ini_set( 'upload_max_filesize' , '128M' );
@ini_set( 'post_max_size', '128M');
@ini_set( 'memory_limit', '256M' );
@ini_set( 'max_execution_time', '300' );
@ini_set( 'max_input_time', '300' );

upload_max_filesize – set this to a value > than your backup
post_max_size – set this to a value > than your backup
memory_limit – set this to a value > than your backup
max_execution_time – set this to 0 (infinite)

BC Call with M2M – node.js 18 or higher

const o = require('odata').o;

// OAuth2.0 details
const tokenUrl = 'https://login.microsofxxxxxxx.com/xxxxx-xxxx-xxxx-xxxx-xxxxxx/oauth2/v2.0/token';
const clientId = 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy';
const clientSecret = 'xxxyyyxxxxyyyyxxxxxx';
const scope = 'https://api.busixxxxxxx.yyyyyyy.zzzzz/.default';

async function getOAuthToken() {
    const params = new URLSearchParams({
      client_id: clientId,
      client_secret: clientSecret,
      scope: scope,
      grant_type: 'client_credentials'  // Use client_credentials flow
    });
  
    const response = await fetch(tokenUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: params.toString()
    });
  
    const tokenData = await response.json();
  
    if (!response.ok) {
      throw new Error(`Error fetching token: ${tokenData.error_description}`);
    }
  
    console.log(tokenData.access_token)
  
    return tokenData.access_token;
  }

  //Only one time
//getOAuthToken();


const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyIsImtpZCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyJ9.eyJhdWQiOiJodHRwczovL2FwaS5idXNpbmVzc2NlbnRyYWwuZHluYW1pY3MuY29tIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvNjk4NWM0MzYtNmI2MS00NzdkLWJhN2QtMzRkMjY3N2Q5NDQxLyIsImlhdCI6MTcyNzAzMzc5OSwibmJmIjoxNzI3MDMzNzk5LCJleHAiOjE3MjcwMzc2OTksImFpbyI6IkUyZGdZT2pMWVNtT1B4dlM4Y3RsQjd2SytVY2lBQT09IiwiYXBwaWQiOiIxYWZiMDQ3Zi1iYTM1LTQwYTItOGI5MC0wZmI0NDI1N2FmY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token
const oHandler = o(BC_URL, {
  headers: {
    Authorization: `Bearer ${accessToken}`,  // Use the OAuth 2.0 token
    'Content-type': 'application/json;odata=verbose'
  }
});


//Fetching all products
async function unitSizes() {
    try {
      const queryParams =
      {
        $top: 3 //Limit to 3 result elements  
      };
  
      const response = await oHandler.get('itemUnitofMeasures').query(queryParams);
      console.log(response);
    }
    catch (error) {
      console.error('Error units sizes products:', error);
    }
  }
  
  unitSizes();


BC Call with M2M – node.js 16. When using a static oauth token 2.0

const o = require('odata').o;
//For polyfill, v16.20.2
const fetch = require('node-fetch');
global.Request = fetch.Request;       // Polyfill for Request
global.Headers = fetch.Headers;       // Polyfill for Headers
global.Response = fetch.Response;     // Polyfill for Response
global.fetch = fetch;                 // Polyfill for Fetch

// OAuth2.0 details
const tokenUrl = 'https://login.microsofxxxxxxx.com/xxxxx-xxxx-xxxx-xxxx-xxxxxx/oauth2/v2.0/token';
const clientId = 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy';
const clientSecret = 'xxxyyyxxxxyyyyxxxxxx';
const scope = 'https://api.busixxxxxxx.yyyyyyy.zzzzz/.default';
//Not used here in static token
async function getOAuthToken() {
    const params = new URLSearchParams({
      client_id: clientId,
      client_secret: clientSecret,
      scope: scope,
      grant_type: 'client_credentials'  // Use client_credentials flow
    });
  
    const response = await fetch(tokenUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: params.toString()
    });
  
    const tokenData = await response.json();
  
    if (!response.ok) {
      throw new Error(`Error fetching token: ${tokenData.error_description}`);
    }
  
    console.log(tokenData.access_token)
  
    return tokenData.access_token;
  }

  //Only one time
//getOAuthToken();


const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyIsImtpZCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyJ9.eyJhdWQiOiJodHRwczov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_YpAXJiEr0yt5gKczIb1ZnccF8EjvZ0PctybiRy3GZtv8HjSikmDnanzddAUsJfJ5C6Z9ZDqgunBUZFmWhEZQ1u6_0UvnMAFWVLicVNqWV4_gMvIiG9GH6waoGcQ6DFT3GN4vcnus5_758VFaqpey2B7L1_e94ODC29BRROg';

BC_URL = 'https://api.businesscexxxxx.zzzzzzzz.com/v2.0/aaaaaaaa-bbbb-bbbb-bbbb-bbbbbbbbbbbb/Dev/api/updateAB/pcws/v2.0/companies(vvvvvvvv-gggg-gggg-gggg-gggggggggggg)/';


// Create an OData handler using OAuth 2.0 Bearer STATIC token
const oHandler = o(BC_URL, {
  headers: {
    Authorization: `Bearer ${accessToken}`,  // Use the OAuth 2.0 token
    'Content-type': 'application/json;odata=verbose'
  }
});


//Fetching all products
async function unitSizes() {
    try {
      const queryParams =
      {
        $top: 3 //Limit to 3 result elements  
      };
  
      const response = await oHandler.get('itemUnitofMeasures').query(queryParams);
      console.log(response);
    }
    catch (error) {
      console.error('Error units sizes products:', error);
    }
  }
  
  unitSizes();


BC Call with M2M – node.js 16 or higher. Dynamic token

const o = require('odata').o;
//For polyfill, v16.20.2
const fetch = require('node-fetch');
global.Request = fetch.Request;       // Polyfill for Request
global.Headers = fetch.Headers;       // Polyfill for Headers
global.Response = fetch.Response;     // Polyfill for Response
global.fetch = fetch;                 // Polyfill for Fetch

// OAuth2.0 details
const tokenUrl = 'https://login.microsofxxxxxxx.com/xxxxx-xxxx-xxxx-xxxx-xxxxxx/oauth2/v2.0/token';
const clientId = 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy';
const clientSecret = 'xxxyyyxxxxyyyyxxxxxx';
const scope = 'https://api.busixxxxxxx.yyyyyyy.zzzzz/.default';

//Base URL
BC_URL = 'https://api.businesscexxxxx.zzzzzzzz.com/v2.0/aaaaaaaa-bbbb-bbbb-bbbb-bbbbbbbbbbbb/Dev/api/updateAB/pcws/v2.0/companies(vvvvvvvv-gggg-gggg-gggg-gggggggggggg)/';

//Token data for OAuth2.0
let tokenCreatedDateTime = null;
let tokenExpirationInSeconds = null;
let accessToken = null;
let tokenExpiryDateTime = null;

// Oauth2.0 handler, setting the Authorization when fetching the oauth2.0 token 
let oHandler = o(BC_URL, {
  headers: {
    //Authorization: `Bearer ${currentOathToken}`,  
    Authorization: ``,  
    'Content-type': 'application/json;odata=verbose'
  }
});


//Creates a new valid oauth2.0 token
async function getOAuthToken() {
    const params = new URLSearchParams({
      client_id: clientId,
      client_secret: clientSecret,
      scope: scope,
      grant_type: 'client_credentials'  // Use client_credentials flow
    });
  
    const response = await fetch(tokenUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: params.toString()
    });
  
    const tokenData = await response.json();
    tokenCreatedDateTime = new Date();

  
    if (!response.ok) {
      throw new Error(`Error fetching token: ${tokenData.error_description}`);
    }
  
    //set access token = 
    accessToken = tokenData.access_token; 
    //get expiration time in seconds
    tokenExpirationInSeconds = tokenData.expires_in;

    //Time for token created
    tokenCreatedDateTime = new Date();  
    //set expiration time for access token (in seconds)
    tokenExpiryDateTime = new Date(tokenCreatedDateTime.getTime() + tokenExpirationInSeconds * 1000);// getTime return time in miliseconds


    //Create the handler here
    //oHandler = await createOHandler();

    //Print all values
    console.log("Token created at time: " + tokenCreatedDateTime)
    console.log("Token expires in: " + tokenExpiryDateTime);
    console.log();
    console.log("The new Token created is:");
    console.log(accessToken);


    //The return token
    return tokenData.access_token;
  }

    //Returns a bool 
    function isTokenExpired(){
      letCurrentDate = new Date();
      return !accessToken || letCurrentDate >= tokenExpiryDateTime;
    }

    //Returna valid oauth2.0 token
    async function getValidToken(){
      console.log();
      console.log();
      console.log('Token validyCheck made at time: ' + new Date());
      console.log();
      
      if (isTokenExpired()){ 
        console.log('Token is expired or not present. Fetching a new one from API...');
        return await getOAuthToken();        
      }
      
      console.log('Using existing token that expiras at - ' + tokenExpiryDateTime + ' - Current active token is');
      console.log(accessToken);
      return accessToken;
    }
    
    //Creates a new OHandler
    async function createOHandler() {
      //Gets a new OR existing token
      let currentOathToken = await getValidToken();

      //This section creates a new hander      
      let oHandlerTemp = o(BC_URL, {
        headers: {
          Authorization: `Bearer ${currentOathToken}`,  // Use the OAuth 2.0 token
          //Authorization: `Bearer ${accessToken}`,  // Use the OAuth 2.0 token
          'Content-type': 'application/json;odata=verbose'
        }
      });

      //oHandler = oHandlerTemp;
    
      return oHandlerTemp;            
    }

    
    async function getOHandler(){
      //Gets a new OR existing token
      let currentOathToken = await getValidToken();

      //This section updates the handler with token
      oHandler.headers.Authorization = `Bearer ${currentOathToken}`;

      return oHandler;
    }



//Fetching all products
async function unitSizes() {
    try {
      const queryParams =
      {
        $top: 3 //Limit to 3 result elements  
      };
  
      let oHandlerTemp = await createOHandler();
      console.log(oHandlerTemp);

      //let response = await oHandlerTemp.get('itemUnitofMeasures').query(queryParams);   
      //const response = await oHandler.get('itemUnitofMeasures').query(queryParams);      
      //const response = oHandler.get('itemUnitofMeasures').query(queryParams);
      //console.log(response);
    }
    catch (error) {
      console.error('Error units sizes products:', error);
    }
  }


  async function runEveryMinute() {
    //console.log("This runs every minute.");
    
    //Fectes the valid token correctly every time
    //await getValidToken(); // Await the async function

    await unitSizes();
}

// Run the function immediately and then set an interval
runEveryMinute(); // Call it once immediately

//setInterval(runEveryMinute, 10000); // Set interval to run every 10 seconds
setInterval(runEveryMinute, 60000); // Set interval to run every minute
//setInterval(runEveryMinute, 300000); // Set interval to run every 5 minute
//setInterval(runEveryMinute, 600000); // Set interval to run every 10 minute


Shop
Wishlist
0 items Cart
My account