How to retrieve the mikrotik PPPoE server service name list by using the mikrotik API? - hotspot

I want to retrieve the mikrotik PPPoE server service name list by using the mikrotik API and loop through all of the service names over a select menu. I have done the code myself. The code looks like below:
$ctype =$this->uri->segment('3');
if($ctype=='PPP')
{
if ($this->routerosapi->connect('1.1.1.1', 'xxx', 'xxx'))
{
$this->routerosapi->write('/interface/pppoe-server/getall');
$READ = $this->routerosapi->read(false);
$mktserver= $this->routerosapi->parseResponse($READ);
$this->routerosapi->disconnect();
}
}
elseif($ctype=='HSP')
{
if ($this->routerosapi->connect('xxx', 'xxx', 'xxx'))
{
$this->routerosapi->write('/ip/hotspot/server/getall');
$READ = $this->routerosapi->read(false);
$mktserver= $this->routerosapi->parseResponse($READ);
$this->routerosapi->disconnect();
}
}
<p>
<label for="simple-required">Server</label>
<select name="server" id="server" class="full-width">
<?php foreach($mktserver as $item):?>
<option value="<?php echo $item['service-name'];?>"><?php echo $item['service-name'];?></option>
<?php endforeach;?>
</select>
</p>
What am I doing wrong?
Note:
Please be specific on your answer. I don't want any basic answer. I want you to read the code very carefully and understand it and finally answer it. For your concern I want both list iteration of PPPoE and Hotspot of Mikrotik.

At the risk of giving a "basic" answer, please see this mikrotik cli command:
:put [/interface get [find type=pppoe-out]]
I suggest getting the command you want to work to work fine in the cli before attempting to do it in the api..

Related

How do I protect my backend from receiving requests that do not come from the frontend?

I'm using Strapi API for my CMS/backend which has a path localhost:1337/products.
I have a Vue frontend that makes a graphql POST to the backend whenever the user accesses localhost:3000/products and uses the information to render the products page and, if the user is logged in, the prices of said products.
In order for this method to work I must grant access to the /products path to the user, which means they can also directly access localhost:1337/products.
How do I restrict access to the backend while still allowing the frontend to make requests to it?
This is how my frontend looks:
<template>
<div>
<div v-for="product in filteredList" v-bind:key="product">
<router-link :to="{ name: 'product-id', params: { id: product.id }}" tag="a">
<h3>{{ product.name }}</h3>
</router-link>
<div v-if="username">{{ product.price.toFixed(2) }}</div>
<div v-else>
Sign in to see price!
</div>
</div>
</div>
</template>
<script>
import productsQuery from '~/apollo/queries/product/products'
export default {
data() {
return {
products: [],
query: ''
}
},
apollo: {
products: {
prefetch: true,
query: productsQuery
}
},
computed: {
// Search system
filteredList() {
return this.product.filter(product => {
return product.name.toLowerCase().includes(this.query.toLowerCase())
})
},
username() {
return this.$store.getters['auth/username'] ||this.$store.getters['auth/email']
},
}
}
</script>
I assume users do not actually access localhost:3000 from their browser but use the IP address or hostname of your server. If so, then either:
Configure the CMS to accept only connections from within the server. Often a service accepts connections on all network interfaces (all IP addresses) by default but you can normally configure it to listen only on the localhost interface (IP address 127.0.0.1).
Configure the firewall on the server to only allow access on port 3000.
You really can't. Any API calls your client makes to your backend can be made by any computer on the Internet if they have the endpoint, credentials, etc.. Backends are agnostic to the source making the call. Even though the backend can determine the origin of the call, any hacker can still fake it to look like your own client app.

Apps script does not send email containing links to Google Drive files on a given G Suite domain, no error message

Context
We are currently working on a short Apps script that sends links to Google Drive files (shared with anyone with the link) through the MailApp.sendEmail(options) function.
The script works well on our test G Suite domain but on the production domain, it just does not send the emails. There are no error messages.
Some code
The issue can be reproduced through the following pieces of code:
Code.gs file
function test_sendEmail() {
const template = HtmlService.createTemplateFromFile('template.html');
template.link = "https://drive.google.com";
template.title = "This is a link";
const mailBody = template.evaluate().getContent();
console.log("Quota: " + MailApp.getRemainingDailyQuota()); /* Quota is not exceeded. */
try {
const options = {
to: "myEmail#Address.com", /* Replace this with your email address */
subject: "LINK",
htmlBody: mailBody,
noReply: true
};
MailApp.sendEmail(options);
} catch(e) {
console.log(e.message);
}
}
template.html file
Link: <a href='<?= link ?>'><?= title ?></a>
What we tried
Emails are properly sent when the link does not contain the drive.google.com part. For example, emails with links to google.com are sent properly.
We are able to send an email from the Gmail account the script is executed as and this email is sent properly with the Drive links.
As opposite as this question, I do not get "Message blocked" email and using GmailApp.sendEmail instead of MailApp.sendEmail does not seem to change anything.
Finally, the script above works well in the test G Suite domains and in some others we tried.
Thus, I believe that it comes from the G Suite domain configuration that have specific restrictions on Apps script. Is it possible? Where can I change it in the G Suite admin console? What other points should I check to make it work?
More details on the issue:
The script fail to send email both with G Suite, gmail and other
email addresses.
We tried in both Apps script runtime (V8 and legacy). Both doesn't
work properly.
I believe that SPF/DKIM/DMARC are not setup in the domain.
We use the same test recipients in both G Suite environments.
The code after the sendEmail method call is executed properly.
The provided template was just an example to reproduce the issue.
The real template looks like a typical email, with a list of links. It is not link-only.
In the future, the script is supposed to send less than 100 emails per day. Right now, it is just sending a few test emails (not more than in test environment).
We use the default cloud project associated with the script.
The script is bound to a Google Sheets file.
Below is the real template that we use.
Dear Customers,<br/><br/>
We inform you that new documents are available. Please find them below:
<ul>
<? for(let i = 0; i < docs.length; i++) { ?>
<li>Document <a href='<?= docs[i].link ?>'><?= docs[i].title ?></a>, <i><?= docs[i].documentType ?></i> is available</li>
<? } ?>
</ul>
<br/>
Regards,<br/>
Your customer service.
Instead of MailApp use GmailApp (you might have to change the sendEmail parameters, check the docs)
The above because others have being reported similar problems, actually something similar happened recently to me while working on client's project.
Related
MailApp.sendEmail method doesn't get through to accounts with URL in the body - Message Blocked

how so synchronize GET API call in Angular Component?

I just started with Angular and I have an issue with its components and an API call. I have the following content in these files
user.component.html:
<div>
<p>
{{user.name}}
</p>
</div>
user.component.ts:
getUser() {
this.user = this.postService.getPosts();
console.log('TWO');
console.log(this.user);
return false;
}
user.service.ts:
getPosts(){
this.http.get('https://XXXXX/yyy').subscribe(data => {
this.str = data[0];
console.log('ONE');
});
return this.str;
}
The Get response is done correctly and I am able to display the data in the html file ONLY if user is loaded, but the first time that I try to do the request to the API the component.ts finishes its execution before the service, and user is not populated correctly, making the html render empty, so with above code I get this printed in console:
TWO
undefined
ONE
I think if it would be synchronized, it would print:
ONE
John
Two
I found this post but I wasn't able to understand it: Angular - Wait until I receive data before loading template
Can someone please try to help me with this?

issue capturing the hashed URI parameters in Coldfusion [duplicate]

I have such url - http://www.coolsite.com/daily-plan/#id=1
What the easiest way to parse that string and read a hash value (the value after #id=)?
Thank you
On client side (i.e. from JavaScript) you can check window.location.hash to get hash. On server side, general answer is 'it is impossible' since hash is not sent in request to server.
Upd: I maybe misunderstood the question. My answer is about how to get hash part of url either in browser or in server side code during request processing, not about string processing.
Upd2: Answer to comment here because it doesn't fit in comment.
How does it work when user clicks on your navigational links?
I assume hash is changed and corresponding content is downloaded via AJAX request from web service or REST.
For example if your user has URL www.example.com in his browser and this page shows a list of product categories. User clicks one category and URL changes to www.example.com/#id=5 and products from that category(with ID=5) are downloaded via AJAX and shown on the page. No postback, only partial page refresh.
Is this close to your scenario?
Now you want user to paste/enter www.example.com/#id=5 directly in the browser address bar and go directly to list of products in that category.
But /#id=5 is not sent to server with request by the browser, so there is no way to get that value on server side, and you can do nothing about it since it is the browser decided not to send this data and you don't have it on server side.
In our project we use solution when server returns only common page code/html, i.e. header, footer, without main/center part of the page. Then there is a JavaScript code which executes right after this common HTML loaded. It takes window.location.hash and sends it to web service via AJAX and web service returns content (HTML) for the main part of the page.
new URI("http://.../abc#xyz").getFragment();
See the Javadocs for URI
Here is how to capture anchor links. Works across all web frameworks.
I'll use an example scenario to illustrate: let's say we need to capture a deep URL http://server.com/#/xyz requested by an unauthenticated user so that they can be redirected to that deep URL post-login.
The unauthenticated user requests http://server.com/#/xyz (everything from the '#' onwards is not sent to the server).
All the server knows is that the user wants http://server.com/ and that they are unauthenticated. Server redirects the user to a login form.
Here's the clever bit: the client is still waiting on their original request so if the server includes a hidden element in the login form with some JS that references window.location.href, it can capture the full URL of the original request complete with the anchor portion:
<form action="/login" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/><br/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<!-- XXXXXXXXX CLEVER BIT XXXXXXXXXX-->
<script>
document.write('<input type="hidden" name="from" value="'+document.location.href+'"/>');
</script>
<!-- XXXXXXXXXX-->
<div>
<input class="submit-button" type="submit" value="Submit"/>
</div>
</form>
The user authenticates themself and the original URL is sent with the POST. The server can then relay the user to the original deep URL.
String url = " http://www.coolsite.com/daily-plan/#id=1";
int sharpPos = url.indexOf('#');
String q = null;
if (sharpPos >= 0) {
q = url.substring(sharpPos);
}
Surely you can use various methods of string manipulation including regular expressions.
But actually your example is strange. Typically parameters of URL are passed after question mark. In this case you can just use standard class URL:
String q = new URL(" http://www.coolsite.com/daily-plan?id=1").getQuery();
what you are using to do this ?
If you are using jsp or servlet following will be useful to you
if (request.getParameter("#id") == null) {
out.println("Please enter your name.");
} else {
out.println("Hello <b>"+request.getParameter(i)+"</b>!");
}
If you are using javascript for it following function will be useful to you
function getURLParameters()
{
var sURL = window.document.URL.toString();
if (sURL.indexOf("?") > 0)
{
var arrParams = sURL.split("?");
var arrURLParams = arrParams[1].split("&");
var arrParamNames = new Array(arrURLParams.length);
var arrParamValues = new Array(arrURLParams.length);
var i = 0;
for (i=0;i<arrURLParams.length;i++)
{
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1] != "")
arrParamValues[i] = unescape(sParam[1]);
else
arrParamValues[i] = "No Value";
}
for (i=0;i<arrURLParams.length;i++)
{
alert(arrParamNames[i]+" = "+ arrParamValues[i]);
}
}
else
{
alert("No parameters.");
}
}
REPLACE the '#' with '?' when parsing the url. Check the code below
String url = "http://www.coolsite.com/daily-plan/#id=1";
String urlNew = url.replace("#", "?");
String id = Uri.parse(urlNew).getQueryParameter("id");
If you URL will the same as you write and doesn't contains anythins else then whis code on Java will help you
String val = "http://www.coolsite.com/daily-plan/#id=1";
System.out.println(val.split("#id")[1]);
Don't forget check to null value.
P.S. If you use servlet you can get this parameter from request.getAttribute("id").
With best regards,
Psycho
if your url get from OAuth callback,then you can't!
because the full url won't send to service because of hash(#)

How do I connect to external API from Magento

I am looking for some assistance in creating an API based module to push customer information out of Magento into a Third party loyalty program.
So far I have created a basic module but cannot find any good information on creating API based modules in Magento and could really do with some advice please...
I need to somehow hook into the Checkout success page in Magneto and add a form the will POST the customers information (name, address etc) to a third party loyalty program. I also need to be able to login to complete the billing information etc...
Does anyone know of any handy tutorials or documentation for such an implementation?
So far I have setup an API user with the appropriate roles. I have also created a very basic module for test purpses but browsing to the file I get a 404 error
apitest.php
<?php
$proxy = new SoapClient('http://mysite.com/api/?wsdl'); //edit the address and put the url to your magento here
$sessionId = $proxy->login('######', '#######'); // put in the info for your user here
echo "Login ID : $sessionId";
$result = $proxy->call($sessionId, 'Mymodule.testConnection', array('param1' => ' This string was sent from soap client'));
echo $result;
Objectmodel/api.php
<?php
class MyModule_MyModule_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
public function testConnection($arg)
{
return "Hello World! My argument is : " . $arg;
}
}
I followed the example from here for getting a basic 'Hello world' module up and running if anyone could assist me with getting the correct setup I would be grateful
Instead of connect magento API you can create customer like this.
define('INCLUDE_PATH', '/var/www/QA/mojostage/app/');
define('INCLUDE_FILE', 'Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($wesite_id);
$customer->loadByEmail($customer_email);
/*
* Check if the email exist on the system.
* If YES, it will not create a user account.
*/
if (!$customer->getId()) {
//setting data such as email, firstname, lastname, and password
$customer->setEmail($customer_email);
$customer->setTaxvat($value['cus_vatnumber'])
->setCreatedAt($date1)
->setDob($value['date_of_birth'])
->setGroupId($cus_group_id)
->setConfirmation($is_active)
->setCreatedIn('Admin')
->setStoreId($store_id)
->setWebsiteId($wesite_id)
->setEntityId($value['cus_id']);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword($value['password']);
$subscriber = Mage::getModel('newsletter/subscriber');
$subscriber->setStoreId($store_id)
->setCustomerId($value['cus_id'])
->setSubscriberEmail($customer_email)
->setSubscriberStatus($value['cus_spam'])
->setSubscriberConfirmCode($subscriber->randomSequence());
}
//the save the data and send the new account email.
$customer->save();
$subscriber->save();