Lua - Waiting for Http Response - api

Note: This is Roblox's version of Lua.
I am working on figuring out how to upload a JSONEncoded table to pastebin. It says I need to acquire a login session key by sending a PostAsync with my dev key, username, and password, and waiting for a response from pastebin with my login session key. Here is my code so far:
h = game:GetService'HttpService'
pasteData = h:UrlEncode(h:JSONEncode(ImgScript))
username = 'USERNAMEHERE'
password = 'PASSWORDHERE'
h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=DEVKEYHERE&api_user_name=' .. h:UrlEncode(username) .. '&api_user_password=' .. h:UrlEncode(password),
2
)
api_user_key = GeneratedUserKeyHere --THIS is what I am after; I don't know how to wait for a response from Pastebin to get this key!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_dev_key=' .. api_dev_key .. 'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=1&api_paste_expire_date=N&api_paste_format=lua&api_paste_code=' .. h:UrlEncode(h:JSONEncode(ImgScript)) --ImgScript is the table,
2
)

Ok so I figured it out.
PostAsync not only sends data, but also receives the returned user key, so here is the working script.
h = game:GetService'HttpService'
api_dev_key = 'YourDevKeyHere'
api_paste_code = 'The text of your upload content here'
api_paste_private = '1' --0 public; 1 unlisted; 2 private
api_paste_name = 'The name of your paste here'
api_paste_expire_date = 'N' --N for never, 10M for 10 minutes, etc.
api_paste_format = 'lua' --The syntax highlighting
api_user_key = ''
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = 'YourUsernameHere'
password = 'YourPasswordHere'
api_user_key = h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
2
)
print(api_user_key) --DON'T DELETE THIS! IT IS ESSENTIAL FOR THE USER KEY TO BE GENERATED!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
2
)

Related

Redis Lua script problems only when many calls with different params

I have script that works fine when I simply call it by hands, or when I call it using my API.
The same script works fine when I create 5 threads and each of them calls this script 10000 times with the same parameters.
But when I run performance testing of my API with tester-written script, I see wrong information in Redis and this information simply can't appear in Redis if script works correcty, so I'm assuming there is some problem in it.
Script:
-- ARGV[1] createdAt
-- ARGV[2] storyId
-- ARGV[3] storyType (image or video)
-- ARGV[4] storyFilename (original filename)
-- ARGV[5] storyThumbnail (thumbnail filename)
-- ARGV[6] storyTags
-- ARGV[7] authorId
-- ARGV[8] authorUsername
-- ARGV[9] authorName
-- ARGV[10] authorAvatarThumb
-- ARGV[11] PHP_INT_MAX
-- ARGV[12] timestamp = followers will see stories younger then this
-- ARGV[13..N] followerId
-- Init variables
local createdAt = ARGV[1]
local storyId = ARGV[2]
local storyType = ARGV[3]
local storyFilename = ARGV[4]
local storyThumbnail = ARGV[5]
local storyTags = cjson.decode(ARGV[6])
local authorId = tonumber(ARGV[7])
local authorUsername = ARGV[8]
local authorName = ARGV[9]
local authorAvatarThumb = ARGV[10]
local maxScore = ARGV[11]
local storyAuthorData = {
id = authorId,
username = authorUsername,
name = authorName,
avatarThumb = authorAvatarThumb,
storyCount = redis.call('ZCARD', 'user:' .. authorId .. ':storyIds') + 1,
lastStory = {
id = storyId,
thumbnail = storyThumbnail,
isViewed = false
}
}
local storyData = {
id = storyId,
thumbnail = storyThumbnail,
tags = storyTags,
viewerCount = 0,
isViewed = false
}
if storyType == 'image' then
storyAuthorData.lastStory.image = storyFilename
storyData.image = storyFilename
else
storyAuthorData.lastStory.video = storyFilename
storyData.video = storyFilename
end
local packedStoryData = cmsgpack.pack(storyData);
local packedAuthorData = cmsgpack.pack(storyAuthorData);
local authorStoryCountForFollower = redis.call('ZCOUNT', 'user:' .. authorId .. ':storyIds', '(' .. ARGV[12], '+inf')
storyAuthorData.storyCount = authorStoryCountForFollower
local packedAuthorDataForFollower = cmsgpack.pack(storyAuthorData);
redis.call('ZADD', 'storyIds', createdAt, storyId)
-- Iterate through followerIds
local followerId, followerAuthorsKey, followerAuthors, followerAuthor
for i = 13, #ARGV do
followerId = ARGV[i]
redis.call('SADD', 'story:' .. storyId .. ':projections', followerId)
redis.call('ZADD', 'forUser:' .. followerId .. ':storiesByUser:' .. authorId, createdAt, packedStoryData)
-- Iterate through follower' story authors and update current author
followerAuthorsKey = 'forUser:' .. followerId .. ':storyAuthors'
followerAuthors = redis.call('ZRANGE', followerAuthorsKey, 0, -1)
for j = 1, #followerAuthors do
followerAuthor = followerAuthors[j]
if cmsgpack.unpack(followerAuthor).id == authorId then
redis.call('ZREM', followerAuthorsKey, followerAuthor)
break
end
end
redis.call('ZADD', followerAuthorsKey, createdAt, packedAuthorDataForFollower)
end
-- Process author as follower of himself
redis.call('ZADD', 'user:' .. authorId .. ':storyIds', createdAt, storyId)
redis.call('ZADD', 'forUser:' .. authorId .. ':storiesByUser:' .. authorId, createdAt, packedStoryData)
followerAuthorsKey = 'forUser:' .. authorId .. ':storyAuthors'
followerAuthor = redis.call('ZREVRANGE', followerAuthorsKey, 0, 0, 'WITHSCORES')
if followerAuthor[2] == maxScore then
redis.call('ZREM', followerAuthorsKey, followerAuthor[1])
end
redis.call('ZADD', followerAuthorsKey, maxScore, packedAuthorData)
As you can see in this part:
-- Iterate through follower' story authors and update current author
followerAuthorsKey = 'forUser:' .. followerId .. ':storyAuthors'
followerAuthors = redis.call('ZRANGE', followerAuthorsKey, 0, -1)
for j = 1, #followerAuthors do
followerAuthor = followerAuthors[j]
if cmsgpack.unpack(followerAuthor).id == authorId then
redis.call('ZREM', followerAuthorsKey, followerAuthor)
break
end
end
redis.call('ZADD', followerAuthorsKey, createdAt, packedAuthorDataForFollower)
there is no possibility that for any key forUser:*:storyAuthors the same author would appear twice.
But in Redis I can see:
zrange forUser:5870:storyAuthors 0 -1 WITHSCORES
1) "\x86\xa8username\xaee8dccb3501913e\xa4name\xactaylor evans\xabavatarThumb\xd9+d083e43ff8dbec76904f09abb8be7dab_thumb.jpeg\xa2id\xcd\x14S\xaastoryCount\x0f\xa9lastStory\x84\xa2id\xd9 00001453abe86ec44260d64111619a76\xa9thumbnail\xd9%59810b11537769.89801964_thumbnail.jpg\xa8isViewed\xc3\xa5video\xbb59810b11537769.89801964.mp4"
2) "1501629201.733"
3) "\x86\xa8username\xaee8dccb3501913e\xa4name\xactaylor evans\xabavatarThumb\xd9+d083e43ff8dbec76904f09abb8be7dab_thumb.jpeg\xa2id\xcd\x14S\xa9lastStory\x84\xa2id\xd9 00001453a77458044360d641bc47c73c\xa5image\xbb59810c1122b659.53121588.jpg\xa9thumbnail\xd9%59810c1122b659.53121588_thumbnail.jpg\xa8isViewed\xc2\xaastoryCount\x1c"
4) "1501629457.3821001"
5) "\x86\xa8username\xaee8dccb3501913e\xa4name\xactaylor evans\xabavatarThumb\xd9+d083e43ff8dbec76904f09abb8be7dab_thumb.jpeg\xa2id\xcd\x14S\xa9lastStory\x84\xa2id\xd9 000014539c8c70044360d6417e07a91d\xa8isViewed\xc2\xa9thumbnail\xd9%59810c11637f43.19889868_thumbnail.jpg\xa5video\xbb59810c11637f43.19889868.mp4\xaastoryCount\x1d"
6) "1501629457.7586"
7) "\x86\xa8username\xaea2d4fb6a25ec2a\xa4name\xabjean brewer\xabavatarThumb\xd9+0cd3514371aa7f5ca53b1859b950f92e_thumb.jpeg\xa2id\xcd\x16\xee\xa9lastStory\x83\xa2id\xd9 000016ee38daa80f4360d641f61949da\xa8isViewed\xc3\xa5video\xbb59810c3e432b80.55025328.mp4\xaastoryCount\x04"
8) "1501629502.6382999"
9) "\x86\xa8username\xaea2d4fb6a25ec2a\xa4name\xabjean brewer\xabavatarThumb\xd9+0cd3514371aa7f5ca53b1859b950f92e_thumb.jpeg\xa2id\xcd\x16\xee\xa9lastStory\x83\xa2id\xd9 000016ee5e109c1f4360d6412826f135\xa8isViewed\xc3\xa5video\xbb59810c7e0b7e92.12898014.mp4\xaastoryCount\x1c"
10) "1501629566.4384999"
11) "\x86\xa8username\xae87163046b74033\xa4name\xaadianne kim\xabavatarThumb\xd9+5d59c5cfefd028e9042bff975f92a94e_thumb.jpeg\xa2id\xcd\x04\xf4\xa9lastStory\x83\xa2id\xd9 000004f4c590065f4360d641f56be683\xa8isViewed\xc3\xa5video\xbb59810d7ba433b2.90198935.mp4\xaastoryCount\x1a"
12) "1501629820.1026001"
13) "\x86\xa8username\xae87163046b74033\xa4name\xaadianne kim\xabavatarThumb\xd9+5d59c5cfefd028e9042bff975f92a94e_thumb.jpeg\xa2id\xcd\x04\xf4\xa9lastStory\x83\xa2id\xd9 000004f488d6bc714360d6418e77ad61\xa8isViewed\xc3\xa5video\xbb59810dc68ad4c6.78917372.mp4\xaastoryCount:"
14) "1501629894.9505999"
15) "\x86\xa8username\xae87163046b74033\xa4name\xaadianne kim\xabavatarThumb\xd9+5d59c5cfefd028e9042bff975f92a94e_thumb.jpeg\xa2id\xcd\x04\xf4\xa9lastStory\x83\xa2id\xd9 000004f402baf07e4360d641f1430d08\xa8isViewed\xc3\xa5video\xbb59810dfb69d323.13796483.mp4\xaastoryCountB"
16) "1501629947.7614"
17) "\x86\xa8username\xaea2d4fb6a25ec2a\xa4name\xabjean brewer\xabavatarThumb\xd9+0cd3514371aa7f5ca53b1859b950f92e_thumb.jpeg\xa2id\xcd\x16\xee\xaastoryCount\x1d\xa9lastStory\x84\xa2id\xd9 000016ee4815e74c4360d641c7cb3dfc\xa9thumbnail\xd9%59810d333d9445.06755396_thumbnail.jpg\xa8isViewed\xc3\xa5video\xbb59810d333d9445.06755396.mp4"
18) "4503599627370496"
There are also another problems showing that the data is not consistent.
I've increased RAM size from 2.8Gb to 16Gb and it did not help.
For KEYS params of lua script - number of params depends on how many followers does a user have. Users we use for testing have thousands of followers, so KEYS array can contain up to several thousands of elements.

Lua - Uploading to Pastebin

Note that this is Roblox's version of lua.
I want to upload a table to Pastebin. Here is what I have for Pastebin.
h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript is a table formatted like {{x,y,z}, {x,y,z}, {x,y,z}, etc.}
h:PostAsync('http://pastebin.com/api/api_post.php','&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)
This doesn't work, and I can't seem to figure out why.
EDIT:
I also tried this and it didn't work.
h = game:GetService'HttpService'
api_params = {
["api_dev_key"] = "CensoredDevKey",
["api_option"] = "paste",
["api_paste_code"] = ImgScript
}
api_params = h:JSONEncode(api_params)
h:PostAsync('http://www.pastebin.com/api/api_post.php', api_params)
EDIT:
I also tried this and it didn't work:
h = game:GetService'HttpService'
JSON = h:JSONEncode(ImgScript) --ImgScript is a table formatted like {{x,y,z}, {x,y,z}, {x,y,z}, etc.}
data = h:UrlEncode('&api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. JSON)
h:PostAsync('http://pastebin.com/api/api_post.php', data)
Try the following:
h = game:GetService'HttpService'
pasteData = h:UrlEncode( h:JSONEncode(ImgScript) )
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_dev_key=CensoredDevKey&api_option=paste&api_paste_code=' .. pasteData,
2
)
The last parameter, 2 specifies that the data being sent is Application/Url-Encoded.
I think that this should do the trick. Do inform here if it doesn't.
PS: Where are you receiving the result from this POST request?
So I've finished the code, but sadly, Roblox limits the PostAsync size to 256 bytes so any upload larger than that will be GZIPed (up to 1024kb), which Pastebin doesn't know what to do with.
Anyhow, I've released the code here:
http://www.roblox.com/Pastebin-Upload-item?id=302297532
It is:
--Created by GShocked. PM me if you have questions!
h = game:GetService'HttpService'
api_dev_key = '' --Your Pastebin developer key goes here. Log in first, and then you can find it at pastebin.com/api
api_paste_code = '' --The content of your new paste
api_paste_private = '1' --0 public; 1 unlisted; 2 private
api_paste_name = '' --Name your new paste
api_paste_expire_date = 'N' --N for never expire, 10M for 10 minutes, etc.
api_paste_format = 'lua' --The syntax highlighting
api_user_key = '' --This is generated using the login info
api_paste_name = h:UrlEncode(api_paste_name)
api_paste_code = h:UrlEncode(api_paste_code)
username = '' --Your Pastebin username goes here
password = '' --Your Pastebin password goes here
api_user_key = h:PostAsync(
'http://pastebin.com/api/api_login.php',
'api_dev_key=' .. api_dev_key .. '&api_user_name=' .. username .. '&api_user_password=' .. password,
2
)
print(api_user_key) --DON'T DELETE THIS! IT IS ESSENTIAL FOR THE USER KEY TO BE GENERATED!
h:PostAsync(
'http://pastebin.com/api/api_post.php',
'api_option=paste&api_user_key=' .. api_user_key .. '&api_paste_private=' .. api_paste_private .. '&api_paste_name=' .. api_paste_name .. '&api_paste_expire_date=' .. api_paste_expire_date .. '&api_paste_format=' .. api_paste_format .. '&api_dev_key=' .. api_dev_key .. '&api_paste_code=' .. api_paste_code,
2
)

How to modify admin password on vtiger?

I have to modify the password of an account on a vtiger crm. The problem is that I don't know the location of the database.
Anyone know the path of the database containing the credential of the users?
If your username starts with 'ad' like 'admin'. use the following mysql query
UPDATE vtiger_users SET user_password = '$1$ad000000$mnnPAFfqzJOuoYY7aB.mR0' WHERE user_name='admin';
This query will reset the password for user with admin username. The password will be set to password.
Vtiger use encrypt_password function in Users.php on line 264 to encrypt user password.
modules/Users/Users.php
It use crypt_type and username for encrypt new passwords. so Mysql query only work if your username starts with ad for example 'admin' , 'adam' and etc.
function encrypt_password($user_password, $crypt_type='') {
// encrypt the password.
$salt = substr($this->column_fields["user_name"], 0, 2);
// Fix for: http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/4923
if($crypt_type == '') {
// Try to get the crypt_type which is in database for the user
$crypt_type = $this->get_user_crypt_type();
}
// For more details on salt format look at: http://in.php.net/crypt
if($crypt_type == 'MD5') {
$salt = '$1$' . $salt . '$';
} elseif($crypt_type == 'BLOWFISH') {
$salt = '$2$' . $salt . '$';
} elseif($crypt_type == 'PHP5.3MD5') {
//only change salt for php 5.3 or higher version for backward
//compactibility.
//crypt API is lot stricter in taking the value for salt.
$salt = '$1$' . str_pad($salt, 9, '0');
}
$encrypted_password = crypt($user_password, $salt);
return $encrypted_password;
}
You can use the following tools on Github. it can change all users password without login into crm and phpmyadmin and update vtiger user privileges file.
https://github.com/spadana2004/Vtiger-CRM-Reset-Password-Tools
Go to My preferences(right top of the browser). There you can change the password of the user.
In database you can't change bcoz there it will be converted to MD5. Then also for your kind information in database check the table vtiger_users for user detail.
update vtiger_users set user_password = 'adpexzg3FUZAk', crypt_type = '' where id = '1';
Login: admin
Password:admin
To make this really easy for admins I created a simple gist that will generate the sql query you need to run to reset a password with any username. Just put in the username and temp password, then run the script and use the SQL it provides. After that just login with that username and password. It is tested with and working on VTiger 7.2.
https://gist.github.com/mav2287/59d5587c7efabdbb105b739c4bc27cb5
<?php
// Put in your username as found in the "vtiger_users" table under the "username" column
$user_name = "";
// Set your TEMPORARY password. You NEED to reset your password after using this to reset it.
$user_password = "password";
// return the approiate stamtent
echo "Run the following SQL query to reset your password: \n";
echo "\"UPDATE vtiger_users SET user_password='".crypt($user_password, substr($user_name, 0, 2))."',crypt_type=''WHERE user_name='".$user_name."'\"";

Two-way authentication with google authentication app

Can someone guide me on what I've done wrong with implementing Google authentication app?
Here is what I've tried without success:
1# Create secret key
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; // allowed characters in Base32
$secret = '';
for ( $i = 0; $i < 16; $i++ )
{ $secret .= substr( $chars, mt_rand( 0, strlen( $chars ) - 1 ), 1 ); }
2# Create QR code via google service (description+secret key)and scan by smart phone and 6 digit is generating in every 30sec by Google-authentication app
3#. Now I'm trying to verify it ...([use base32 algo][1])
$tm = floor( time() / 30 ); // for time purpose
$secretkey=Base32::decode($secretkey); // return blank
$time=chr(0).chr(0).chr(0).chr(0).pack('N*',$tm+$i);
// Hash it with users secret key
$hm = hash_hmac( 'SHA1', $time, $secretkey, true );
// Use last nipple of result as index/offset
$offset = ord(substr($hm,-1)) & 0x0F;
// grab 4 bytes of the result
$hashpart=substr($hm,$offset,4);
// Unpak binary value
$value=unpack("N",$hashpart);
$value=$value[1];
// Only 32 bits
$value = $value & 0x7FFFFFFF;
$value = $value % 1000000;
The above code is based on other sources(wordpress google authentication app)...but it's not working.
$secretkey=Base32::decode($secretkey);
always returns blank (empty)
Is there another way how to verify or implement time-based algo? Or a link where I can read about how to code for 2-way authentication for site?
Thanks for advance and appreciable effort. (I think its a security purpose question so I have put here instead of stackoverflow.. :) )
Implemented by using github.com/chregu/GoogleAuthenticator.php

Custom Wordpress user which was created directly through SQL does not work for Wordpress login

I used the following code to hash the password:
$password = $_POST['user_pass'];
$hash = wp_hash_password('$password');
What am I missing? The error I get is
ERROR: The password you entered for the username willshatner is incorrect.
This code will not input the password you have sent, because of the single quotes:
$hash = wp_hash_password('$password'); // here the password is set to the string $password
use this code instead:
$hash = wp_hash_password($password); // here the password is set to the value of the variable $password
Since the password is MD5 encrypted, you'd prob have to encrypt the POST to match the db
$password = MD5($_POST['user_pass']);