How to use Apis to view lines in Xtream code 2.9.2? - api

How to view Lines from Xtream Code CMS?
I am using some APIs but not able view lines it always shows me 'Access Denied'.
How to allow API access? I have Xtream code 2.9.2 version.
I know To use APIs, we have to import our IP address into the whitelist from General Settings -> API Settings. It was an option in Xtream code 2.3.x but in later versions, they have changed things. And by default, they have disabled the access of APIs. There is no such type of option in the current version of Xtream code we have.
Any solution? How to allow API access in xtream code 2.9.2?
<?php
$panel_url = 'https://cms.xtream-codes.com/xxxx/'; //i am giving my cms xtream code panel link here
$username = "xxxx"; //i am giving my xtream code cms username here
$password = "xxxx"; //i am giving my xtream code cms password here
##############################################################################
$post_data = array( 'username' => $username, 'password' => $password );
$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );
$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=info", false, $context ), true );
echo implode( ',', $api_result);
?>
Access denied

Pretty sure the $panel_url refers to the URL to your main server rather than your cms panel

My solution for checking active subscription info using xtream-codes V2 API
create an Index.php page for your form
<form class="form-inline" action="submit.php" method="post">
<div class="form-group">
<input type="text" class="form-control" id="username" placeholder="Enter Lines Username" name="username">
<input type="text" class="form-control" id="password" placeholder="Enter Lines Password" name="password">
<button type="submit" id="submit" class="btn btn-primary" name="submit">GET STREAM IDS</button>
</form>
Create submit.php and point your form action to it
<?php
$surname = $_POST['surname'];
$username = $_POST['username'];
$password = $_POST['password'];
$exp_date = date("d-m-Y",$json['user_info']["exp_date"]);
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/panel_api.php?username=$username&password=$password"), true);
?>
<?php echo $json['user_info']["username"];?></a>
<?php echo $json['user_info']["password"];?></a>
<?php echo $json['user_info']["status"];?></a>
<?php echo $exp_date;?></a>
and create a line download button like this
DOWNLOAD PLAYLIST
The below code will generate a table of active channels and their TS numbers dependant to the entered line subscription packages
<table>
<thead>
<tr>
<th width="50%"><center>STREAM NAME</center></th>
<th width="50%"><center>STREAM TS NUMBER</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/player_api.php?username=$username&password=$password&action=get_live_streams"), true);
for ($x = 0; $x < count($json); $x++)
{ ?>
<td><center><strong><?php echo $json[$x]['name'];?></strong></center></td>
<td><center><strong><?php echo $json[$x]['stream_id'];?></strong></center></td>
</tr>
<?php } ?>
these may not be the best methods but they work and I actually use myself

Related

Implementing Google Recaptcha V3 - Methods to implement

I am planning to use Google invisible Recaptcha V3 in my application. I want the suggestion by which method I can go. In the developer document, I could see 2 ways,
Automatically bind the challenge to a button (https://developers.google.com/recaptcha/docs/v3)
Programmatically invoke the challenge
for the 2nd option, I know we are doing the server-side validation to check the token from my site and we are getting the scores.
I want to know if I am going to use the 1st option, and how it gets validated from the ReCaptcha server.
If you want to use the 1st option, you just include a submit button inside your form, and you will receive the reCaptcha token in the 'g-recaptcha-response' key from the POST field (e.g.: $_POST['g-recaptcha-response'], if you're using php).
<script src="https://www.google.com/recaptcha/api.js"></script>
<form method="post" action="login" id="loginForm">
<label for="password">Password:</label>
<input type="password" name="password" value="">
<!--Recaptcha button-->
<button class="g-recaptcha"
data-sitekey="#your_site_key"
data-callback='onSubmit'
data-action='submit'>Submit</button>
</form>
<script>
function onSubmit(token)
{
document.getElementById("loginForm").submit();
}
</script>
Then, validate the token submiting it to "https://www.google.com/recaptcha/api/siteverify" as you would do with the 2nd option.
If you are on php, login page from the form's action attribute, would look like this:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query([
"secret"=>"#yourSecretKey"
, "response"=>$_POST['g-recaptcha-response']
, "remoteip"=>$_SERVER['REMOTE_ADDR']
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$recaptcha = json_decode(curl_exec($ch), true);
/** $recaptcha:
Array
(
[success] => 1 // or 0
[challenge_ts] => 2022-07-16T12:34:38Z
[hostname] => host // hostname
[score] => 0.9 // 0.0 to 1.0
[action] => submit // data-action attribute from reCaptcha button
)
*/
if ($recaptcha["score"] >= 0.5 && $recaptcha["action"] === 'submit')
{
// action on success
} else {
// action on false
}
?>
About which one to use, I don't know how to answer that... But I guess that both options work similarly, so go with the one that is easier for you to implement.

Upload mp3 file not working in codeigniter

I am trying to upload mp3 file into folder using codeigniter V3.1.8 but i get error when i trying to upload any .mp3 file. I got "The filetype you are attempting to upload is not allowed." error.
Here is my controller, view code.
CommonController.php
public function uploadSong( $ref_id ) {
$status = $url = "";
$data['user_info'] = $this->data;
if ($status != "error") {
$config['upload_path'] = './assets/songs/';
$url = 'assets/songs/';
}
$config['allowed_types'] = 'mp3';
$config['max_size'] = 99999;
//$config['encrypt_name'] = TRUE;
//chmod('assets/', 0777);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file_name')) {
$status = 'error';
$msg = $this->upload->display_errors('', '');
echo $msg;
} else {
// Go ahead
}
}
upload.php
<?php echo form_open_multipart(base_url() . 'upload-song/'.$song[0]['id']);?>
<div class="form-group">
<label>Select Song</label>
<input type="file" name="file_name" size="20" required="true" />
</div>
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Upload" />
<?php echo form_close(); ?>
config/mimes.php
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Same process do with images upload and its working fine but am not getting what's going wrong with mp3 upload. Any idea whats going wrong with my code ?
Thanks in Advance.
You just need to replace in config/mimes.php from,
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
to,
'mp3' => array('video/mp3', 'application/octet-stream', 'audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Now it's working fine.

how to post login array error within the originating page

Hi how do you post the login error message within the originating page where the user was attempting to login ?
Below I was able to stay on the current page if user login successfully but for login error it will obviously just go to the logonprocess page and display the error message.
Sorry that I remove a lot of validation below as the codes can really be very long.
Index.php
<?php
//set the session cookie parameter
ini_set("session.save_path", "sessionData");
session_start();
?>
<?php
if (!isset($_SESSION['uName'])) { ?>
<form method="post" action="logonProcess.php">
<div>Username <input type="text" name="userName" placeholder="Username"></div>
<div>Password <input type="password" name="pwd" placeholder="Password"></div>
<div><input type="submit" value="Logon"></div>
</form>
<?php } else { }?>
<?php
if (isset($_SESSION['uName'])) {
$username = $_SESSION['uName'];
echo "<p>Welcome $username</p>\n";
?>
Logout</br></br>
LogonProcess.php
$loginerror = array();
if (empty($username)) {
$loginerror[] = "You have not entered all of the required fields";
}
elseif (strlen($passWD) < 8) {
$loginerror[] = "You have not entered all of the required fields";
}
if (!empty($loginerror))
for ($a=0;$a<count($loginerror);$a++)
{
echo "$loginerror[$a] <br />\n";
}
else
if (mysqli_stmt_fetch($stmt))
{
if (password_verify($passWD, $passWDHash))
{
$_SESSION['uName'] = $username;
echo "<p>Login successful</p>";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
else
{
echo "<p>Please try to login again</p>";
}
why dont you put ur login error in $_SESSION["login_error"] and check in ur origin page if the session exits show the error then destroy the session after it.

Invalid Request YII when delete model via POST

I want delete my model via post , but I always get Invalid Request
this is my view
<?php
echo CHtml::link(CHtml::encode('Delete image'), array('gambar/delete', 'id' => $data->id), array(
'submit' => array('data/delete', 'id' => $data->id),
'class' => 'delete', 'confirm' => 'This will remove the image. Are you sure?'
)
);
?>
and this is my action in GambarController
public function actionDelete() {
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel()->delete();
if (!isset($_GET['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
But I always get Invalid Request, I have read some forums, but I cannot get it. Anyone can help me ?
In most cases you can not use link (<a>) to POST. Instead, use the <form> like this
<form action="<?php echo $this->createUrl('/gambar/delete/'.$model->id);?>" method="post">
<button
type="submit"
name="id"
value="<?php echo $model->id?>"
onclick="if (!confirm('Are you sure to delete this image?')) return false;">
<i class="icon-white icon-trash"></i> Delete
</button>
</form>
You are using CHtml::link, this will generate an html <a> tag. When you click on a <a>, your browser send HTTP GET request(not POST request) to the server. So if(Yii::app()->request->isPostRequest) is always false and therefore you see Invalid request error. You should remove this condition from the action. Also, $this->loadModel()->delete() is invalid, because loadModel get an id as parameter. So $this->loadModel($_GET['id'])->delete() is correct.
Use the below code
$this->loadModel(primarykey, 'TableName')->delete();
Should work!

Google AdSense API asking for log in each time

I've put together the Google AdSense API for earnings which works. However, I want it to run in the background without me logging in. It asks me to log in each time it's ran. I have the offline set as well as store the token. I'm not sure why it keeps asking me to log in. I have this running on a nightly cron job on GoDaddy. Code is below:
<?php
include('config.php');
require_once 'templates/base.php';
session_start();
set_include_path('/path/to/clientlib' . PATH_SEPARATOR . get_include_path());
set_include_path('/path/to/clientlib' . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/AdSense.php';
require_once 'Google/Service/AdSense.php';
// Autoload example classes.
include 'examples/GetAllAccounts.php';
include 'examples/GetAccountTree.php';
include 'examples/GetAllAdClients.php';
include 'examples/GetAllAdUnits.php';
include 'examples/GetAllCustomChannelsForAdUnit.php';
include 'examples/GetAllCustomChannels.php';
include 'examples/GetAllAdUnitsForCustomChannel.php';
include 'examples/GetAllUrlChannels.php';//GetAllUrlChannels
include 'examples/GenerateReport.php';//GenerateReport
include 'examples/GenerateReportWithPaging.php';//GenerateReportWithPaging
include 'examples/FillMissingDatesInReport.php';//FillMissingDatesInReport
include 'examples/CollateReportData.php';//CollateReportData
include 'examples/GetAllSavedReports.php';//GetAllSavedReports
include 'examples/GenerateSavedReport.php';//GenerateSavedReport
include 'examples/GetAllSavedAdStyles.php';//GetAllSavedAdStyles
include 'examples/GetAllAlerts.php';//GetAllAlerts
include 'examples/GetAllDimensions.php';//GetAllDimensions
include 'examples/GetAllMetrics.php';//GetAllMetrics
// Max results per page.
define('MAX_LIST_PAGE_SIZE', 50, true);
define('MAX_REPORT_PAGE_SIZE', 50, true);
// Configure token storage on disk.
// If you want to store refresh tokens in a local disk file, set this to true.
define('STORE_ON_DISK', false, true);
define('TOKEN_FILENAME', 'tokens.dat', true);
// Set up authentication.
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');
// Be sure to replace the contents of client_secrets.json with your developer
// credentials.
$client->setAuthConfigFile('client_secrets.json');
// Create service.
$service = new Google_Service_AdSense($client);
// If we're logging out we just need to clear our local access token.
// Note that this only logs you out of the session. If STORE_ON_DISK is
// enabled and you want to remove stored data, delete the file.
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
// If we have a code back from the OAuth 2.0 flow, we need to exchange that
// with the authenticate() function. We store the resultant access token
// bundle in the session (and disk, if enabled), and redirect to this page.
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
// Note that "getAccessToken" actually retrieves both the access and refresh
// tokens, assuming both are available.
$_SESSION['access_token'] = $client->getAccessToken();
if (STORE_ON_DISK) {
file_put_contents(TOKEN_FILENAME, $_SESSION['access_token']);
}
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
exit;
}
// If we have an access token, we can make requests, else we generate an
// authentication URL.
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else if (STORE_ON_DISK && file_exists(TOKEN_FILENAME) &&
filesize(TOKEN_FILENAME) > 0) {
// Note that "setAccessToken" actually sets both the access and refresh token,
// assuming both were saved.
$client->setAccessToken(file_get_contents(TOKEN_FILENAME));
$_SESSION['access_token'] = $client->getAccessToken();
} else {
// If we're doing disk storage, generate a URL that forces user approval.
// This is the only way to guarantee we get back a refresh token.
if (STORE_ON_DISK) {
$client->setApprovalPrompt('force');
}
$authUrl = $client->createAuthUrl();
}
//echo pageHeader('Get Final Report');
//echo "stre on disk = " . STORE_ON_DISK . "<br />";
echo '<div><div class="request">';
if (isset($authUrl)) {
echo '<a class="login" href="' . $authUrl . '">Login !</a>';
} else {
echo '<a class="logout" href="?logout">Logout</a>';
};
echo '</div>';
if ($client->getAccessToken()) {
echo '<pre class="result">';
// Now we're signed in, we can make our requests.
$adsense = makeRequests($service);
/* Note that we re-store the access_token bundle, just in case anything
changed during the request - the main thing that might happen here is the
access token itself is refreshed if the application has offline access. */
$_SESSION['access_token'] = $client->getAccessToken();
echo '</pre>';
}
echo '</div>';
echo pageFooter(__FILE__);
// Makes all the API requests.
function makeRequests($service) {
print "\n";
$accounts = GetAllAccounts::run($service, MAX_LIST_PAGE_SIZE);
echo '<div class="Account">Account No. '.$accounts[0]["id"].' Details</div>';
if (isset($accounts) && !empty($accounts)) {
// Get an example account ID, so we can run the following sample.
$exampleAccountId = $accounts[0]['id'];
GetAccountTree::run($service, $exampleAccountId);
$adClients =
GetAllAdClients::run($service, $exampleAccountId, MAX_LIST_PAGE_SIZE);
;
?>
<table id="myTable" class="tablesorter" border="1px solid">
<thead>
<tr>
<th>AdClient ID</th>
<th>AdClient Code</th>
</tr>
</thead>
<tbody>
<?php
foreach($adClients as $adClients){
?>
<tr><td><?php echo $adClients['id']; ?></td><td><?php echo $adClients['productCode']; ?></td></tr>
<?php
}
?>
</tbody>
</table>
<?php
if (isset($adClients) && !empty($adClients)) {
// Get an ad client ID, so we can run the rest of the samples.
$exampleAdClient = end($adClients);
$exampleAdClientId = $adClients['id'];
$adUnits = GetAllAdUnits::run($service, $exampleAccountId,
$exampleAdClientId, MAX_LIST_PAGE_SIZE);
?>
<table id="myTable_1" class="tablesorter" border="1px solid">
<thead>
<tr>
<th>AdUnit name</th>
<th>AdUnit Code</th>
<th>AdUnit ID</th>
<th>Status</th>
<th>Detail</th>
</tr>
</thead>
<tbody>
<?php
foreach($adUnits as $adUnits){
if($adUnits['status']=='ACTIVE' ||$adUnits['status']=='NEW'){ ?>
<tr>
<td><?php echo $adUnits['name']; ?></td>
<td><?php echo $adUnits['code']; ?></td>
<td><?php echo $adUnits['id']; ?></td>
<td><?php echo $adUnits['status']; ?></td>
<td class="link">Get detail</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
if (isset($_REQUEST['ad_name'])) {
//die('function shoul be calle dhere ');
$Get_reports=GenerateReport::run($service, $exampleAccountId, $exampleAdClientId,$_REQUEST['ad_name']);
}
else {
$Get_reports=GenerateReport::run($service, $exampleAccountId, $exampleAdClientId);
}
//print_r($Get_reports);
?>
<table id="myTable_2" class="tablesorter" border="1px solid">
<thead>
<tr>
<?php foreach($Get_reports['headers'] as $headers){
?>
<th><?php printf('%25s', $headers['name']); ?></th>
<?php
}
?>
</tr>
</thead>
<?php
foreach($Get_reports['rows'] as $rows) {
?>
<tr>
<?php
foreach($rows as $col) {
?>
<td><?php echo $col; $adsense = $col; ?></td>
<?php
} ?>
</tr>
<?php
}
?>
</table>
<table id="myTable_3" class="tablesorter" border="1px solid">
<thead>
<tr>
<?php
foreach($Get_reports['headers'] as $headers){
?>
<th><?php echo 'Total '.$headers['name']; ?></th>
<?php
}
?>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($Get_reports['totals'] as $totals){
?>
<td><?php echo $totals; ?></td>
<?php
}
?>
</tr>
</tbody>
</table>
<?php
//die('Report Generated For Last 7 Days');
}
}
//echo "adsense = " . $adsense . "<br />";
return $adsense;
}
Run the manual log in once and store the refresh token, subsequent auth requests would use that stored token and won't prompt you again.
It should be as simple as changing this to true and then hitting the page once using the right account.
// If you want to store refresh tokens in a local disk file, set this to true.
define('STORE_ON_DISK', true, true);